CssPageRule
Represents the @page rule.
using AngleSharp.Parser.Css;
namespace AngleSharp.Dom.Css
{
internal sealed class CssPageRule : CssRule, ICssPageRule, ICssRule, IStyleFormattable
{
private readonly CssStyleDeclaration _style;
private ISelector _selector;
public ISelector Selector {
get {
return _selector;
}
set {
if (value != null)
_selector = value;
}
}
public string SelectorText {
get {
return _selector.Text;
}
set {
ISelector selector = base.Parser.ParseSelector(value);
if (selector != null)
_selector = selector;
}
}
ICssStyleDeclaration ICssPageRule.Style {
get {
return _style;
}
}
public CssStyleDeclaration Style => _style;
internal CssPageRule(CssParser parser)
: base(CssRuleType.Page, parser)
{
_style = new CssStyleDeclaration(this);
_selector = SimpleSelector.All;
}
protected override void ReplaceWith(ICssRule rule)
{
CssPageRule cssPageRule = (CssPageRule)rule;
_selector = cssPageRule._selector;
_style.Clear();
_style.SetDeclarations(cssPageRule._style.Declarations);
}
public override string ToCss(IStyleFormatter formatter)
{
string rules = formatter.Block(_style);
return formatter.Rule("@page", _selector.Text, rules);
}
}
}