// niklas@protocol7.com
// 80
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
namespace SharpVectors.Dom.Css
{
///
/// The CSSPageRule interface represents a @page rule within a CSS style sheet. The @page rule is used to specify the dimensions, orientation, margins, etc. of a page box for paged media.
///
public sealed class CssPageRule : CssRule, ICssPageRule
{
#region Static members
private static Regex regex = new Regex(@"^@font-face");
internal static CssRule Parse(ref string css, object parent, bool readOnly,
IList replacedStrings, CssStyleSheetType origin)
{
Match match = regex.Match(css);
if(match.Success)
{
CssPageRule rule = new CssPageRule(match, parent, readOnly, replacedStrings, origin);
css = css.Substring(match.Length);
rule.style = new CssStyleDeclaration(ref css, rule, true, origin);
return rule;
}
else
{
// didn't match => do nothing
return null;
}
}
#endregion
#region Constructors
///
/// The constructor for CssPageRule
///
/// The Regex match that found the charset rule
/// The parent rule or parent stylesheet
/// True if this instance is readonly
/// An array of strings that have been replaced in the string used for matching. These needs to be put back use the DereplaceStrings method
/// The type of CssStyleSheet
internal CssPageRule(Match match, object parent, bool readOnly,
IList replacedStrings, CssStyleSheetType origin)
: base(parent, readOnly, replacedStrings, origin)
{
// TODO: selectorText = DeReplaceStrings(match.Groups["pageselector"].Value.Trim());
}
#endregion
#region Implementation of ICssPageRule
private string selectorText;
///
/// The parsable textual representation of the page selector for the rule.
///
/// SYNTAX_ERR: Raised if the specified CSS string value has a syntax error and is unparsable.
/// NO_MODIFICATION_ALLOWED_ERR: Raised if this rule is readonly.
public string SelectorText
{
get
{
return selectorText;
}
set
{
/* SYNTAX_ERR: Raised if the specified CSS string value has a syntax error and is unparsable.*/
if (readOnly)
throw new DomException(DomExceptionType.NoModificationAllowedErr);
selectorText = value;
}
}
private CssStyleDeclaration style;
///
/// The declaration-block of this rule.
///
public ICssStyleDeclaration Style
{
get
{
return style;
}
}
#endregion
#region Implementation of ICssRule
///
/// The type of the rule. The expectation is that binding-specific casting methods can be used to cast down from an instance of the CSSRule interface to the specific derived interface implied by the type.
///
public override CssRuleType Type
{
get
{
return CssRuleType.PageRule;
}
}
#endregion
}
}