AngleSharp by Florian Rappl

<PackageReference Include="AngleSharp" Version="0.9.0" />

.NET API 1,206,784 bytes

 HtmlInputElement

Represents an HTML input element.
using AngleSharp.Dom.Css; using AngleSharp.Dom.Io; using AngleSharp.Extensions; using AngleSharp.Html; using AngleSharp.Html.InputTypes; using System; namespace AngleSharp.Dom.Html { internal sealed class HtmlInputElement : HtmlTextFormControlElement, IHtmlInputElement, IHtmlElement, IElement, INode, IEventTarget, IMarkupFormattable, IParentNode, IChildNode, INonDocumentTypeChildNode, IElementCssInlineStyle, IValidation { private BaseInputType _type; private bool? _checked; public override string DefaultValue { get { return GetOwnAttribute(AttributeNames.Value) ?? string.Empty; } set { SetOwnAttribute(AttributeNames.Value, value); } } public bool IsDefaultChecked { get { return HasOwnAttribute(AttributeNames.Checked); } set { SetOwnAttribute(AttributeNames.Checked, value ? string.Empty : null); } } public bool IsChecked { get { if (!_checked.HasValue) return IsDefaultChecked; return _checked.Value; } set { _checked = value; } } public string Type { get { return _type.Name; } set { SetOwnAttribute(AttributeNames.Type, value); } } public bool IsIndeterminate { get; set; } public bool IsMultiple { get { return HasOwnAttribute(AttributeNames.Multiple); } set { SetOwnAttribute(AttributeNames.Multiple, value ? string.Empty : null); } } public DateTime? ValueAsDate { get { return _type.ConvertToDate(base.Value); } set { if (!value.HasValue) base.Value = string.Empty; else base.Value = _type.ConvertFromDate(value.Value); } } public double ValueAsNumber { get { return _type.ConvertToNumber(base.Value) ?? NaN; } set { if (double.IsInfinity(value)) throw new DomException(DomError.TypeMismatch); if (double.IsNaN(value)) base.Value = string.Empty; else base.Value = _type.ConvertFromNumber(value); } } public string FormAction { get { if (base.Form == null) return string.Empty; return base.Form.Action; } set { if (base.Form != null) base.Form.Action = value; } } public string FormEncType { get { if (base.Form == null) return string.Empty; return base.Form.Enctype; } set { if (base.Form != null) base.Form.Enctype = value; } } public string FormMethod { get { if (base.Form == null) return string.Empty; return base.Form.Method; } set { if (base.Form != null) base.Form.Method = value; } } public bool FormNoValidate { get { if (base.Form == null) return false; return base.Form.NoValidate; } set { if (base.Form != null) base.Form.NoValidate = value; } } public string FormTarget { get { if (base.Form == null) return string.Empty; return base.Form.Target; } set { if (base.Form != null) base.Form.Target = value; } } public string Accept { get { return GetOwnAttribute(AttributeNames.Accept); } set { SetOwnAttribute(AttributeNames.Accept, value); } } public Alignment Align { get { return GetOwnAttribute(AttributeNames.Align).ToEnum(Alignment.Left); } set { SetOwnAttribute(AttributeNames.Align, value.ToString()); } } public string AlternativeText { get { return GetOwnAttribute(AttributeNames.Alt); } set { SetOwnAttribute(AttributeNames.Alt, value); } } public string Autocomplete { get { return GetOwnAttribute(AttributeNames.AutoComplete); } set { SetOwnAttribute(AttributeNames.AutoComplete, value); } } public IFileList Files => (_type as FileInputType)?.Files; public IHtmlDataListElement List { get { Document owner = base.Owner; if (owner != null) return owner.GetElementById(GetOwnAttribute(AttributeNames.List)) as IHtmlDataListElement; return null; } } public string Maximum { get { return GetOwnAttribute(AttributeNames.Max); } set { SetOwnAttribute(AttributeNames.Max, value); } } public string Minimum { get { return GetOwnAttribute(AttributeNames.Min); } set { SetOwnAttribute(AttributeNames.Min, value); } } public string Pattern { get { return GetOwnAttribute(AttributeNames.Pattern); } set { SetOwnAttribute(AttributeNames.Pattern, value); } } public int Size { get { return GetOwnAttribute(AttributeNames.Size).ToInteger(20); } set { SetOwnAttribute(AttributeNames.Size, value.ToString()); } } public string Source { get { return GetOwnAttribute(AttributeNames.Src); } set { SetOwnAttribute(AttributeNames.Src, value); } } public string Step { get { return GetOwnAttribute(AttributeNames.Step); } set { SetOwnAttribute(AttributeNames.Step, value); } } public string UseMap { get { return GetOwnAttribute(AttributeNames.UseMap); } set { SetOwnAttribute(AttributeNames.UseMap, value); } } public int DisplayWidth { get { return GetOwnAttribute(AttributeNames.Width).ToInteger(OriginalWidth); } set { SetOwnAttribute(AttributeNames.Width, value.ToString()); } } public int DisplayHeight { get { return GetOwnAttribute(AttributeNames.Height).ToInteger(OriginalHeight); } set { SetOwnAttribute(AttributeNames.Height, value.ToString()); } } public int OriginalWidth => (_type as ImageInputType)?.Width ?? 0; public int OriginalHeight => (_type as ImageInputType)?.Height ?? 0; internal bool IsVisited { get; set; } internal bool IsActive { get; set; } internal bool IsMutable { get { if (!base.IsDisabled) return !base.IsReadOnly; return false; } } public HtmlInputElement(Document owner, string prefix = null) : base(owner, Tags.Input, prefix, NodeFlags.SelfClosing) { RegisterAttributeObserver(AttributeNames.Type, UpdateType); UpdateType(null); } public override void DoClick() { if (!IsClickedCancelled()) { string type = Type; IHtmlFormElement form = base.Form; if (type == InputTypeNames.Submit && form != null) form.Submit(); else if (type == InputTypeNames.Reset) { form?.Reset(); } } } public sealed override INode Clone(bool deep = true) { HtmlInputElement htmlInputElement = (HtmlInputElement)base.Clone(deep); htmlInputElement._checked = _checked; htmlInputElement.UpdateType(_type.Name); return htmlInputElement; } internal override FormControlState SaveControlState() { return new FormControlState(base.Name, Type, base.Value); } internal override void RestoreFormControlState(FormControlState state) { if (state.Type == Type && state.Name == base.Name) base.Value = state.Value; } public void StepUp(int n = 1) { _type.DoStep(n); } public void StepDown(int n = 1) { _type.DoStep(-n); } private void UpdateType(string type) { _type = Factory.InputTypes.Create(this, type); } internal override void ConstructDataSet(FormDataSet dataSet, IHtmlElement submitter) { if (_type.IsAppendingData(submitter)) _type.ConstructDataSet(dataSet); } internal override void Reset() { base.Reset(); _checked = null; UpdateType(Type); } protected override void Check(ValidityState state) { base.Check(state); _type.Check(state); } protected override bool CanBeValidated() { if (_type.CanBeValidated) return base.CanBeValidated(); return false; } } }