AngleSharp by Florian Rappl

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

.NET API 1,208,832 bytes

 HtmlElement

Represents a standard HTML element in the node tree.
using AngleSharp.Dom.Collections; using AngleSharp.Dom.Css; using AngleSharp.Dom.Events; using AngleSharp.Extensions; using AngleSharp.Html; using AngleSharp.Services; using System; namespace AngleSharp.Dom.Html { internal class HtmlElement : Element, IHtmlElement, IElement, INode, IEventTarget, IMarkupFormattable, IParentNode, IChildNode, INonDocumentTypeChildNode, IElementCssInlineStyle { private ICssStyleDeclaration _style; private StringMap _dataset; private IHtmlMenuElement _menu; private SettableTokenList _dropZone; public bool IsHidden { get { return HasOwnAttribute(AttributeNames.Hidden); } set { SetOwnAttribute(AttributeNames.Hidden, value ? string.Empty : null); } } public IHtmlMenuElement ContextMenu { get { if (_menu == null) { string ownAttribute = GetOwnAttribute(AttributeNames.ContextMenu); if (!string.IsNullOrEmpty(ownAttribute)) return base.Owner.GetElementById(ownAttribute) as IHtmlMenuElement; } return _menu; } set { _menu = value; } } public ISettableTokenList DropZone { get { if (_dropZone == null) { _dropZone = new SettableTokenList(GetOwnAttribute(AttributeNames.DropZone)); CreateBindings(_dropZone, AttributeNames.DropZone); } return _dropZone; } } public bool IsDraggable { get { return GetOwnAttribute(AttributeNames.Draggable).ToBoolean(false); } set { SetOwnAttribute(AttributeNames.Draggable, value.ToString()); } } public string AccessKey { get { return GetOwnAttribute(AttributeNames.AccessKey) ?? string.Empty; } set { SetOwnAttribute(AttributeNames.AccessKey, value); } } public string AccessKeyLabel => AccessKey; public string Language { get { return GetOwnAttribute(AttributeNames.Lang) ?? GetDefaultLanguage(); } set { SetOwnAttribute(AttributeNames.Lang, value); } } public string Title { get { return GetOwnAttribute(AttributeNames.Title); } set { SetOwnAttribute(AttributeNames.Title, value); } } public string Direction { get { return GetOwnAttribute(AttributeNames.Dir); } set { SetOwnAttribute(AttributeNames.Dir, value); } } public bool IsSpellChecked { get { return GetOwnAttribute(AttributeNames.Spellcheck).ToBoolean(false); } set { SetOwnAttribute(AttributeNames.Spellcheck, value.ToString()); } } public int TabIndex { get { return GetOwnAttribute(AttributeNames.TabIndex).ToInteger(0); } set { SetOwnAttribute(AttributeNames.TabIndex, value.ToString()); } } public IStringMap Dataset => _dataset ?? (_dataset = new StringMap("data-", this)); public ICssStyleDeclaration Style => _style ?? (_style = CreateStyle()); public string ContentEditable { get { return GetOwnAttribute(AttributeNames.ContentEditable); } set { SetOwnAttribute(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 GetOwnAttribute(AttributeNames.Translate).ToEnum(SimpleChoice.Yes) == SimpleChoice.Yes; } set { SetOwnAttribute(AttributeNames.Translate, value ? Keywords.Yes : Keywords.No); } } public HtmlElement(Document owner, string localName, string prefix = null, NodeFlags flags = NodeFlags.None) : base(owner, Combine(prefix, localName), localName, prefix, Namespaces.HtmlUri, flags | NodeFlags.HtmlMember) { string style = AttributeNames.Style; Action<string> callback = delegate(string value) { IBindable bindable = _style as IBindable; if (string.IsNullOrEmpty(value)) RemoveAttribute(AttributeNames.Style); bindable?.Update(value); }; RegisterAttributeObserver(style, callback); } public void DoSpellCheck() { ISpellCheckService spellCheck = base.Owner.Options.GetSpellCheck(Language); } public virtual void DoClick() { IsClickedCancelled(); } public virtual void DoFocus() { } public virtual void DoBlur() { } public override INode Clone(bool deep = true) { HtmlElement htmlElement = Factory.HtmlElements.Create(base.Owner, base.LocalName, base.Prefix); 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) { string ownAttribute = GetOwnAttribute(AttributeNames.Form); Document owner = base.Owner; if (owner == null || node != null || string.IsNullOrEmpty(ownAttribute)) return null; node = owner.GetElementById(ownAttribute); } return node as IHtmlFormElement; } private string GetDefaultLanguage() { IHtmlElement htmlElement = base.ParentElement as IHtmlElement; if (htmlElement == null) return base.Owner.Options.GetLanguage(); return htmlElement.Language; } protected bool IsClickedCancelled() { return this.Fire(delegate(MouseEvent m) { m.Init(EventNames.Click, true, true, base.Owner.DefaultView, 0, 0, 0, 0, 0, false, false, false, false, MouseButton.Primary, this); }, null); } private static string Combine(string prefix, string localName) { return ((prefix != null) ? (prefix + ":" + localName) : localName).ToUpperInvariant(); } } }