PseudoElement
abstract class PseudoElement : IElement, INode, IEventTarget, IMarkupFormattable, IParentNode, IChildNode, INonDocumentTypeChildNode, IPseudoElement, IStyleUtilities
A wrapper around an element to extend the DOM.
using AngleSharp.Css;
using AngleSharp.Dom.Css;
using AngleSharp.Dom.Events;
using AngleSharp.Extensions;
using System;
using System.Collections.Generic;
namespace AngleSharp.Dom
{
internal abstract class PseudoElement : IElement, INode, IEventTarget, IMarkupFormattable, IParentNode, IChildNode, INonDocumentTypeChildNode, IPseudoElement, IStyleUtilities
{
private sealed class BeforePseudoElement : PseudoElement
{
public override string PseudoName => "::" + PseudoElementNames.Before;
public BeforePseudoElement(IElement host)
: base(host)
{
}
}
private sealed class AfterPseudoElement : PseudoElement
{
public override string PseudoName => "::" + PseudoElementNames.After;
public AfterPseudoElement(IElement host)
: base(host)
{
}
}
private static readonly Dictionary<string, Func<IElement, PseudoElement>> creators = new Dictionary<string, Func<IElement, PseudoElement>>(StringComparer.OrdinalIgnoreCase) {
{
":" + PseudoElementNames.Before,
(IElement element) => new BeforePseudoElement(element)
},
{
"::" + PseudoElementNames.Before,
(IElement element) => new BeforePseudoElement(element)
},
{
":" + PseudoElementNames.After,
(IElement element) => new AfterPseudoElement(element)
},
{
"::" + PseudoElementNames.After,
(IElement element) => new AfterPseudoElement(element)
}
};
private readonly IElement _host;
public ICssStyleDeclaration CascadedStyle => Owner.DefaultView.GetStyleCollection().ComputeCascadedStyle(this);
public ICssStyleDeclaration DefaultStyle => Owner.DefaultView.ComputeDefaultStyle(this);
public ICssStyleDeclaration RawComputedStyle => Owner.DefaultView.ComputeRawStyle(this);
public ICssStyleDeclaration UsedStyle => Owner.DefaultView.ComputeUsedStyle(this);
public string Prefix => _host.Prefix;
public abstract string PseudoName { get; }
public string LocalName => _host.LocalName;
public string NamespaceUri => _host.NamespaceUri;
public IEnumerable<IAttr> Attributes => _host.Attributes;
public ITokenList ClassList => _host.ClassList;
public string ClassName {
get {
return _host.ClassName;
}
set {
}
}
public string Id {
get {
return _host.Id;
}
set {
}
}
public string InnerHtml {
get {
return string.Empty;
}
set {
}
}
public string OuterHtml {
get {
return string.Empty;
}
set {
}
}
public string TagName => _host.TagName;
public bool IsFocused => _host.IsFocused;
public string BaseUri => _host.BaseUri;
public Url BaseUrl => _host.BaseUrl;
public string NodeName => _host.NodeName;
public INodeList ChildNodes => _host.ChildNodes;
public IDocument Owner => _host.Owner;
public IElement ParentElement => _host.ParentElement;
public INode Parent => _host.Parent;
public INode FirstChild => _host.FirstChild;
public INode LastChild => _host.LastChild;
public INode NextSibling => _host.NextSibling;
public INode PreviousSibling => _host.PreviousSibling;
public NodeType NodeType => NodeType.Element;
public string NodeValue {
get {
return _host.NodeValue;
}
set {
}
}
public string TextContent {
get {
return string.Empty;
}
set {
}
}
public bool HasChildNodes => _host.HasChildNodes;
public IHtmlCollection<IElement> Children => _host.Children;
public IElement FirstElementChild => _host.FirstElementChild;
public IElement LastElementChild => _host.LastElementChild;
public int ChildElementCount => _host.ChildElementCount;
public IElement NextElementSibling => _host.NextElementSibling;
public IElement PreviousElementSibling => _host.PreviousElementSibling;
public static PseudoElement Create(IElement host, string pseudoSelector)
{
if (!string.IsNullOrEmpty(pseudoSelector) && creators.TryGetValue(pseudoSelector, out Func<IElement, PseudoElement> value))
return value(host);
return null;
}
public PseudoElement(IElement host)
{
_host = host;
}
public void Insert(AdjacentPosition position, string html)
{
}
public bool HasAttribute(string name)
{
return _host.HasAttribute(name);
}
public bool HasAttribute(string namespaceUri, string localName)
{
return _host.HasAttribute(namespaceUri, localName);
}
public string GetAttribute(string name)
{
return _host.GetAttribute(name);
}
public string GetAttribute(string namespaceUri, string localName)
{
return _host.GetAttribute(namespaceUri, localName);
}
public void SetAttribute(string name, string value)
{
}
public void SetAttribute(string namespaceUri, string name, string value)
{
}
public void RemoveAttribute(string name)
{
}
public void RemoveAttribute(string namespaceUri, string localName)
{
}
public IHtmlCollection<IElement> GetElementsByClassName(string classNames)
{
return _host.GetElementsByClassName(classNames);
}
public IHtmlCollection<IElement> GetElementsByTagName(string tagName)
{
return _host.GetElementsByTagName(tagName);
}
public IHtmlCollection<IElement> GetElementsByTagNameNS(string namespaceUri, string tagName)
{
return _host.GetElementsByTagNameNS(namespaceUri, tagName);
}
public bool Matches(string selectors)
{
return _host.Matches(selectors);
}
public INode Clone(bool deep = true)
{
return _host.Clone(deep);
}
public IPseudoElement Pseudo(string pseudoElement)
{
return null;
}
public bool Equals(INode otherNode)
{
return _host.Equals(otherNode);
}
public DocumentPositions CompareDocumentPosition(INode otherNode)
{
return _host.CompareDocumentPosition(otherNode);
}
public void Normalize()
{
_host.Normalize();
}
public bool Contains(INode otherNode)
{
return _host.Contains(otherNode);
}
public bool IsDefaultNamespace(string namespaceUri)
{
return _host.IsDefaultNamespace(namespaceUri);
}
public string LookupNamespaceUri(string prefix)
{
return _host.LookupNamespaceUri(prefix);
}
public string LookupPrefix(string namespaceUri)
{
return _host.LookupPrefix(namespaceUri);
}
public INode AppendChild(INode child)
{
return _host.AppendChild(child);
}
public INode InsertBefore(INode newElement, INode referenceElement)
{
return _host.InsertBefore(newElement, referenceElement);
}
public INode RemoveChild(INode child)
{
return _host.RemoveChild(child);
}
public INode ReplaceChild(INode newChild, INode oldChild)
{
return _host.ReplaceChild(newChild, oldChild);
}
public string ToHtml()
{
return _host.ToHtml();
}
public void AddEventListener(string type, DomEventHandler callback = null, bool capture = false)
{
_host.AddEventListener(type, callback, capture);
}
public void RemoveEventListener(string type, DomEventHandler callback = null, bool capture = false)
{
_host.RemoveEventListener(type, callback, capture);
}
public bool Dispatch(Event ev)
{
return _host.Dispatch(ev);
}
public void Append(params INode[] nodes)
{
_host.Append(nodes);
}
public void Prepend(params INode[] nodes)
{
_host.Prepend(nodes);
}
public IElement QuerySelector(string selectors)
{
return _host.QuerySelector(selectors);
}
public IHtmlCollection<IElement> QuerySelectorAll(string selectors)
{
return _host.QuerySelectorAll(selectors);
}
public void Before(params INode[] nodes)
{
_host.Before(nodes);
}
public void After(params INode[] nodes)
{
_host.After(nodes);
}
public void Replace(params INode[] nodes)
{
_host.Replace(nodes);
}
public void Remove()
{
_host.Remove();
}
public string ToHtml(IMarkupFormatter formatter)
{
return _host.ToHtml(formatter);
}
}
}