AngleSharp by Florian Rappl

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

.NET API 1,189,376 bytes

 HtmlObjectElement

Represents the HTML object element.
using AngleSharp.Dom.Css; using AngleSharp.Extensions; using AngleSharp.Html; using AngleSharp.Network; using AngleSharp.Services.Media; using System; using System.Threading; using System.Threading.Tasks; namespace AngleSharp.Dom.Html { internal sealed class HtmlObjectElement : HtmlFormControlElement, IHtmlObjectElement, IHtmlElement, IElement, INode, IEventTarget, IMarkupFormattable, IParentNode, IChildNode, INonDocumentTypeChildNode, IElementCssInlineStyle, IValidation, IDisposable { private readonly BoundLocation _data; private Task<IObjectInfo> _resourceTask; private CancellationTokenSource _cts; public string Source { get { return _data.Href; } set { _data.Href = value; } } public string Type { get { return GetOwnAttribute(AttributeNames.Type); } set { SetOwnAttribute(AttributeNames.Type, value); } } public bool TypeMustMatch { get { return GetOwnAttribute(AttributeNames.TypeMustMatch) != null; } set { SetOwnAttribute(AttributeNames.TypeMustMatch, value ? string.Empty : null); } } 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 { get { if (_resourceTask == null) return 0; if (!_resourceTask.IsCompleted || _resourceTask.Result == null) return 0; return _resourceTask.Result.Width; } } public int OriginalHeight { get { if (_resourceTask == null) return 0; if (!_resourceTask.IsCompleted || _resourceTask.Result == null) return 0; return _resourceTask.Result.Height; } } public IDocument ContentDocument => null; public IWindow ContentWindow => null; public HtmlObjectElement(Document owner, string prefix = null) : base(owner, Tags.Object, prefix, NodeFlags.Scoped) { _data = new BoundLocation(this, AttributeNames.Data); RegisterAttributeObserver(AttributeNames.Data, UpdateSource); } public void Dispose() { if (_cts != null) _cts.Cancel(); _cts = null; _resourceTask = null; } protected override bool CanBeValidated() { return false; } private void UpdateSource(string value) { if (_cts != null) _cts.Cancel(); if (!string.IsNullOrEmpty(value)) { Url url = new Url(Source); _cts = new CancellationTokenSource(); _resourceTask = LoadAsync(url, _cts.Token); } } private async Task<IObjectInfo> LoadAsync(Url url, CancellationToken cancel) { ResourceRequest request = this.CreateRequestFor(url); ConfiguredTaskAwaiter val = AwaitExtensions.ConfigureAwait<IObjectInfo>(Owner.LoadResource<IObjectInfo>(request, cancel), false).GetAwaiter(); if (!val.get_IsCompleted()) { await val; ConfiguredTaskAwaiter val2 = default(ConfiguredTaskAwaiter); val = val2; } !0 result = val.GetResult(); val = default(ConfiguredTaskAwaiter); this.FireSimpleEvent(EventNames.Load, false, false); return (IObjectInfo)result; } } }