AngleSharp by Florian Rappl

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

.NET API 1,172,480 bytes

 HtmlElement

Represents a standard HTML element in the node tree.
using AngleSharp.Dom.Collections; using AngleSharp.Dom.Css; using AngleSharp.Extensions; using AngleSharp.Html; using System; namespace AngleSharp.Dom.Html { internal class HtmlElement : Element, IHtmlElement, IElement, INode, IEventTarget, IParentNode, IChildNode, INonDocumentTypeChildNode, IElementCssInlineStyle { private CssStyleDeclaration _style; private StringMap _dataset; private IHtmlMenuElement _menu; private SettableTokenList _dropZone; public bool IsHidden { get { return GetAttribute(AttributeNames.Hidden) != null; } set { SetAttribute(AttributeNames.Hidden, value ? string.Empty : null); } } public IHtmlMenuElement ContextMenu { get { if (_menu == null) { string attribute = GetAttribute(AttributeNames.ContextMenu); if (!string.IsNullOrEmpty(attribute)) return base.Owner.GetElementById(attribute) as IHtmlMenuElement; } return _menu; } set { _menu = value; } } public ISettableTokenList DropZone { get { if (_dropZone == null) { _dropZone = new SettableTokenList(GetAttribute(AttributeNames.DropZone)); _dropZone.Changed += delegate { UpdateAttribute(AttributeNames.DropZone, _dropZone.Value); }; } return _dropZone; } } public bool IsDraggable { get { return GetAttribute(AttributeNames.Draggable).ToBoolean(false); } set { SetAttribute(AttributeNames.Draggable, value.ToString()); } } public string AccessKey { get { return GetAttribute(AttributeNames.AccessKey) ?? string.Empty; } set { SetAttribute(AttributeNames.AccessKey, value); } } public string AccessKeyLabel => AccessKey; public string Language { get { object text = GetAttribute(AttributeNames.Lang); if (text == null) { if (!(base.ParentElement is IHtmlElement)) return base.Owner.Options.GetLanguage(); text = (base.ParentElement as IHtmlElement).Language; } return (string)text; } set { SetAttribute(AttributeNames.Lang, value); } } public string Title { get { return GetAttribute(AttributeNames.Title); } set { SetAttribute(AttributeNames.Title, value); } } public string Direction { get { return GetAttribute(AttributeNames.Dir); } set { SetAttribute(AttributeNames.Dir, value); } } public bool IsSpellChecked { get { return GetAttribute(AttributeNames.Spellcheck).ToBoolean(false); } set { SetAttribute(AttributeNames.Spellcheck, value.ToString()); } } public int TabIndex { get { return GetAttribute(AttributeNames.TabIndex).ToInteger(0); } set { SetAttribute(AttributeNames.TabIndex, value.ToString()); } } public IStringMap Dataset => _dataset ?? (_dataset = new StringMap("data-", this)); public CssStyleDeclaration Style => _style ?? (_style = CreateStyle()); ICssStyleDeclaration IElementCssInlineStyle.Style { get { return Style; } } public string ContentEditable { get { return GetAttribute(AttributeNames.ContentEditable); } set { SetAttribute(AttributeNames.ContentEditable, value); } } public bool IsContentEditable { get { ContentEditableMode contentEditableMode = ContentEditable.ToEnum(ContentEditableMode.Inherited); if (contentEditableMode == ContentEditableMode.True) return true; IHtmlElement htmlElement = base.ParentElement as IHtmlElement; if (contentEditableMode == ContentEditableMode.Inherited && htmlElement != null) return htmlElement.IsContentEditable; return false; } } public bool IsTranslated { get { return GetAttribute(AttributeNames.Translate).ToEnum(SimpleChoice.Yes) == SimpleChoice.Yes; } set { SetAttribute(AttributeNames.Translate, value ? Keywords.Yes : Keywords.No); } } public HtmlElement(Document owner, string name, NodeFlags flags = NodeFlags.None) : base(owner, name, flags | NodeFlags.HtmlMember) { base.NamespaceUri = Namespaces.HtmlUri; RegisterAttributeObserver(AttributeNames.Style, UpdateStyle); } public void DoSpellCheck() { base.Owner.Options.GetSpellCheck(Language); } public void DoClick() { } public virtual void DoFocus() { } public void DoBlur() { } public override INode Clone(bool deep = true) { HtmlElement htmlElement = Factory.HtmlElements.Create(base.NodeName, base.Owner); Node.CopyProperties(this, htmlElement, deep); Element.CopyAttributes(this, htmlElement); return htmlElement; } protected IHtmlFormElement GetAssignedForm() { INode node = base.Parent; while (!(node is IHtmlFormElement) && node != null) { node = node.ParentElement; } if (node == null && base.Owner == null) return null; if (node == null) { string attribute = GetAttribute(AttributeNames.Form); if (node != null || string.IsNullOrEmpty(attribute)) return null; node = base.Owner.GetElementById(attribute); } return node as IHtmlFormElement; } private CssStyleDeclaration CreateStyle() { if (base.Owner.Options.IsStyling) return new CssStyleDeclaration(GetAttribute(AttributeNames.Style)) { Changed = (EventHandler)delegate { UpdateAttribute(AttributeNames.Style, _style.CssText); } }; return null; } private void UpdateStyle(string value) { if (string.IsNullOrEmpty(value)) base.Attributes.Remove(base.Attributes.Get(AttributeNames.Style)); if (_style != null) _style.Update(value); } } }