HtmlObjectElement
sealed class HtmlObjectElement : HtmlFormControlElement, IHtmlObjectElement, IHtmlElement, IElement, INode, IEventTarget, IMarkupFormattable, IParentNode, IChildNode, INonDocumentTypeChildNode, IElementCssInlineStyle, IValidation
Represents the HTML object element.
using AngleSharp.Dom.Css;
using AngleSharp.Extensions;
using AngleSharp.Html;
using AngleSharp.Network;
using AngleSharp.Services.Media;
using System.Threading.Tasks;
namespace AngleSharp.Dom.Html
{
internal sealed class HtmlObjectElement : HtmlFormControlElement, IHtmlObjectElement, IHtmlElement, IElement, INode, IEventTarget, IMarkupFormattable, IParentNode, IChildNode, INonDocumentTypeChildNode, IElementCssInlineStyle, IValidation
{
private IObjectInfo _obj;
private IDownload _download;
public string Source {
get {
return this.GetUrlAttribute(AttributeNames.Data);
}
set {
this.SetOwnAttribute(AttributeNames.Data, value);
}
}
public string Type {
get {
return this.GetOwnAttribute(AttributeNames.Type);
}
set {
this.SetOwnAttribute(AttributeNames.Type, value);
}
}
public bool TypeMustMatch {
get {
return this.HasOwnAttribute(AttributeNames.TypeMustMatch);
}
set {
this.SetOwnAttribute(AttributeNames.TypeMustMatch, value ? string.Empty : null);
}
}
public string UseMap {
get {
return this.GetOwnAttribute(AttributeNames.UseMap);
}
set {
this.SetOwnAttribute(AttributeNames.UseMap, value);
}
}
public int DisplayWidth {
get {
return this.GetOwnAttribute(AttributeNames.Width).ToInteger(OriginalWidth);
}
set {
this.SetOwnAttribute(AttributeNames.Width, value.ToString());
}
}
public int DisplayHeight {
get {
return this.GetOwnAttribute(AttributeNames.Height).ToInteger(OriginalHeight);
}
set {
this.SetOwnAttribute(AttributeNames.Height, value.ToString());
}
}
public int OriginalWidth {
get {
if (_obj == null)
return 0;
return _obj.Width;
}
}
public int OriginalHeight {
get {
if (_obj == null)
return 0;
return _obj.Height;
}
}
public IDocument ContentDocument => null;
public IWindow ContentWindow => null;
public HtmlObjectElement(Document owner, string prefix = null)
: base(owner, TagNames.Object, prefix, NodeFlags.Scoped)
{
}
protected override bool CanBeValidated()
{
return false;
}
internal override void SetupElement()
{
base.SetupElement();
string ownAttribute = this.GetOwnAttribute(AttributeNames.Data);
RegisterAttributeObserver(AttributeNames.Data, UpdateSource);
if (ownAttribute != null)
UpdateSource(ownAttribute);
}
private void UpdateSource(string value)
{
if (_download != null && !_download.IsCompleted)
_download.Cancel();
Document owner = base.Owner;
if (!string.IsNullOrEmpty(value) && owner != null) {
IResourceLoader loader = owner.Loader;
if (loader != null) {
Url url = new Url(Source);
ResourceRequest request = this.CreateRequestFor(url);
IDownload download = loader.DownloadAsync(request);
Task<bool> task = this.ProcessResource(download, delegate(IObjectInfo result) {
_obj = result;
});
owner.DelayLoad(task);
_download = download;
}
}
}
}
}