public CssAbsValue(CssValue cssValue, string propertyName, XmlElement element) : base() { _cssValue = cssValue; _propertyName = propertyName; _element = element; }
internal CssCollectedProperty(string name, int specificity, CssValue cssValue, CssStyleSheetType origin, string priority) { Name = name; Specificity = specificity; Origin = origin; CssValue = cssValue; Priority = priority; }
public CssCollectedProperty(string name, int specificity, CssValue cssValue, CssStyleSheetType origin, string priority) { _name = name; _specificity = specificity; _origin = origin; _cssValue = cssValue; _priority = priority; }
/// <summary> /// Used to retrieve the value of a CSS property if it has been explicitly set within this declaration block. /// </summary> /// <param name="propertyName">The name of the CSS property. See the CSS property index.</param> /// <returns>Returns the value of the property if it has been explicitly set for this declaration block. Returns the empty string if the property has not been set.</returns> public override string GetPropertyValue(string propertyName) { CssValue value = (CssValue)GetPropertyCssValue(propertyName); if (value != null) { return(value.CssText); } return(string.Empty); }
/// <summary> /// Used to retrieve the object representation of the value of a CSS property if it has been explicitly set /// within this declaration block. This method returns null if the property is a shorthand property. /// Shorthand property values can only be accessed and modified as strings, using the getPropertyValue and /// setProperty methods. /// </summary> /// <param name="propertyName">The name of the CSS property. See the CSS property index.</param> /// <returns>Returns the value of the property if it has been explicitly set for this declaration block. /// Returns null if the property has not been set.</returns> public virtual ICssValue GetPropertyCssValue(string propertyName) { if (_styles.ContainsKey(propertyName)) { CssStyleBlock scs = _styles[propertyName]; if (scs.CssValue == null) { scs.CssValue = CssValue.GetCssValue(scs.Value, ReadOnly); } return(scs.CssValue); } return(null); }
public void TestFloatPcValue() { CssStyleDeclaration csd = (CssStyleDeclaration)((CssStyleRule)cssStyleSheet.CssRules[5]).Style; CssValue val = (CssValue)csd.GetPropertyCssValue("float-pc"); Assert.IsTrue(val is CssPrimitiveValue); CssPrimitiveValue primValue = (CssPrimitiveValue)csd.GetPropertyCssValue("float-pc"); Assert.AreEqual("10pc", primValue.CssText, "CssText"); Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType, "CssValueType"); Assert.AreEqual(CssPrimitiveType.Pc, primValue.PrimitiveType, "PrimitiveType"); Assert.AreEqual(10, primValue.GetFloatValue(CssPrimitiveType.Pc), "To PC"); }
public void TestFloatInValue() { CssStyleDeclaration csd = (CssStyleDeclaration)((CssStyleRule)cssStyleSheet.CssRules[5]).Style; CssValue val = (CssValue)csd.GetPropertyCssValue("float-in"); Assert.IsTrue(val is CssPrimitiveValue); CssPrimitiveValue primValue = (CssPrimitiveValue)csd.GetPropertyCssValue("float-in"); Assert.AreEqual("10in", primValue.CssText); Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType); Assert.AreEqual(CssPrimitiveType.In, primValue.PrimitiveType); Assert.AreEqual(10, primValue.GetFloatValue(CssPrimitiveType.In)); }
public CssValue GetInitialCssValue(string propertyName) { if (_properties.ContainsKey(propertyName)) { CssProperty cssProp = _properties[propertyName]; if (cssProp.InitialCssValue == null) { cssProp.InitialCssValue = CssValue.GetCssValue(cssProp.InitialValue, false); } return(cssProp.InitialCssValue); } return(null); }
public void TestFloatUnitlessValue() { CssStyleDeclaration csd = (CssStyleDeclaration)((CssStyleRule)cssStyleSheet.CssRules[5]).Style; CssValue val = (CssValue)csd.GetPropertyCssValue("float-unitless"); Assert.IsTrue(val is CssPrimitiveValue); CssPrimitiveValue primValue = (CssPrimitiveValue)csd.GetPropertyCssValue("float-unitless"); Assert.AreEqual("67", primValue.CssText); Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType); Assert.AreEqual(CssPrimitiveType.Number, primValue.PrimitiveType); double res = primValue.GetFloatValue(CssPrimitiveType.Number); Assert.AreEqual(67, res); }
public void TestFloatPxValue() { CssStyleDeclaration csd = (CssStyleDeclaration)((CssStyleRule)cssStyleSheet.CssRules[5]).Style; CssValue val = (CssValue)csd.GetPropertyCssValue("float-px"); Assert.IsTrue(val is CssPrimitiveValue); CssPrimitiveValue primValue = (CssPrimitiveValue)csd.GetPropertyCssValue("float-px"); Assert.AreEqual("12px", primValue.CssText); Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType); Assert.AreEqual(CssPrimitiveType.Px, primValue.PrimitiveType); double res = primValue.GetFloatValue(CssPrimitiveType.Px); Assert.AreEqual(12, res); }
public void TestStringValue() { CssStyleDeclaration csd = (CssStyleDeclaration)((CssStyleRule)cssStyleSheet.CssRules[1]).Style; CssValue val = (CssValue)csd.GetPropertyCssValue("string"); Assert.IsTrue(val is CssPrimitiveValue); CssPrimitiveValue primValue = (CssPrimitiveValue)csd.GetPropertyCssValue("string"); Assert.AreEqual("\"a string\"", primValue.CssText); Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType); Assert.AreEqual(CssPrimitiveType.String, primValue.PrimitiveType); string str = primValue.GetStringValue(); Assert.AreEqual("a string", str); }
public CssAbsValue(CssValue cssValue, string propertyName, XmlElement element) : base() { if (cssValue == null) { throw new ArgumentNullException(nameof(cssValue)); } if (element == null) { throw new ArgumentNullException(nameof(element)); } _cssValue = cssValue; _propertyName = propertyName; _element = element; }
/// <summary> /// Used to retrieve the object representation of the value of a CSS property if it has been explicitly set within this declaration block. This method returns null if the property is a shorthand property. Shorthand property values can only be accessed and modified as strings, using the getPropertyValue and setProperty methods. /// </summary> /// <param name="propertyName">The name of the CSS property. See the CSS property index.</param> /// <returns>Returns the value of the property if it has been explicitly set for this declaration block. Returns null if the property has not been set.</returns> public virtual ICssValue GetPropertyCssValue(string propertyName) { if (styles.ContainsKey(propertyName)) { SharpCssStyle scs = (SharpCssStyle)styles[propertyName]; if (scs.CssValue == null) { scs.CssValue = CssValue.GetCssValue(scs.Value, ReadOnly); } return(scs.CssValue); } else { return(null); } }
public void TestColorLongHexValue() { CssValue val = (CssValue)colorRules.GetPropertyCssValue("longhex"); Assert.IsTrue(val is CssPrimitiveValue, "1"); CssPrimitiveValue primValue = (CssPrimitiveValue)colorRules.GetPropertyCssValue("longhex"); Assert.AreEqual("rgb(101,67,33)", primValue.CssText, "2"); Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType, "3"); Assert.AreEqual(CssPrimitiveType.RgbColor, primValue.PrimitiveType, "4"); RgbColor color = (RgbColor)primValue.GetRgbColorValue(); Assert.AreEqual(101, color.Red.GetFloatValue(CssPrimitiveType.Number), "5"); Assert.AreEqual(67, color.Green.GetFloatValue(CssPrimitiveType.Number), "6"); Assert.AreEqual(33, color.Blue.GetFloatValue(CssPrimitiveType.Number), "7"); Assert.AreEqual(ColorTranslator.FromHtml("#654321"), color.GdiColor, "8"); }
public void CollectProperty(string name, int specificity, CssValue cssValue, CssStyleSheetType origin, string priority) { CssCollectedProperty newProp = new CssCollectedProperty(name, specificity, cssValue, origin, priority); if (!collectedStyles.ContainsKey(name)) { collectedStyles[name] = newProp; } else { CssCollectedProperty existingProp = collectedStyles[name]; if (newProp.IsBetterThen(existingProp)) { collectedStyles[name] = newProp; } } }
public void TestFloatPtValue() { CssStyleDeclaration csd = (CssStyleDeclaration)((CssStyleRule)cssStyleSheet.CssRules[5]).Style; CssValue val = (CssValue)csd.GetPropertyCssValue("float-pt"); Assert.IsTrue(val is CssPrimitiveValue); CssPrimitiveValue primValue = (CssPrimitiveValue)csd.GetPropertyCssValue("float-pt"); Assert.AreEqual("10pt", primValue.CssText, "CssText"); Assert.AreEqual(CssValueType.PrimitiveValue, primValue.CssValueType, "CssValueType"); Assert.AreEqual(CssPrimitiveType.Pt, primValue.PrimitiveType, "PrimitiveType"); Assert.AreEqual(10, primValue.GetFloatValue(CssPrimitiveType.Pt), "To PC"); Assert.AreEqual(10 / 72D * 2.54D, primValue.GetFloatValue(CssPrimitiveType.Cm), "To CM"); Assert.AreEqual(100 / 72D * 2.54D, primValue.GetFloatValue(CssPrimitiveType.Mm), "To MM"); Assert.AreEqual(10 / 72D, primValue.GetFloatValue(CssPrimitiveType.In), "To IN"); Assert.AreEqual(10 / 12D, primValue.GetFloatValue(CssPrimitiveType.Pc), "To PT"); }
/// <summary> /// Used to retrieve the object representation of the value of a CSS property if it has been explicitly set /// within this declaration block. This method returns null if the property is a shorthand property. /// Shorthand property values can only be accessed and modified as strings, using the getPropertyValue and /// setProperty methods. /// </summary> /// <param name="propertyName">The name of the CSS property. See the CSS property index.</param> /// <returns>Returns the value of the property if it has been explicitly set for this declaration block. /// Returns null if the property has not been set.</returns> public virtual ICssValue GetPropertyCssValue(string propertyName) { if (string.IsNullOrWhiteSpace(propertyName)) { return(null); } if (_styles.ContainsKey(propertyName)) { CssStyleBlock scs = _styles[propertyName]; if (propertyName.Equals(SvgConstants.AttrFontFamily, StringComparison.OrdinalIgnoreCase)) { scs.CssValue = new CssValue(CssValueType.PrimitiveValue, scs.Value, ReadOnly); } else if (scs.CssValue == null) { scs.CssValue = CssValue.GetCssValue(scs.Value, ReadOnly); } return(scs.CssValue); } return(null); }
public override ICssValue GetPropertyCssValue(string propertyName) { if (collectedStyles.ContainsKey(propertyName)) { CssCollectedProperty scp = collectedStyles[propertyName]; if (scp.CssValue.CssValueType == CssValueType.Inherit) { // get style from parent chain return(getParentStyle(propertyName)); } else { return(scp.CssValue.GetAbsoluteValue(propertyName, _element)); } } else { // should this property inherit? CssXmlDocument doc = (CssXmlDocument)_element.OwnerDocument; if (doc.CssPropertyProfile.IsInheritable(propertyName)) { ICssValue parValue = getParentStyle(propertyName); if (parValue != null) { return(parValue); } } string initValue = doc.CssPropertyProfile.GetInitialValue(propertyName); if (initValue == null) { return(null); } else { return(CssValue.GetCssValue(initValue, false).GetAbsoluteValue(propertyName, _element)); } } }
public void CssValueInheritTest() { CssValue cssValue = new CssValue(CssValueType.Inherit, "inherit", false); Assert.AreEqual("inherit", cssValue.CssText); Assert.AreEqual(CssValueType.Inherit, cssValue.CssValueType); }
internal CssProperty(bool isInherited, string initialValue) { this.IsInherited = isInherited; this.InitialValue = initialValue; this.InitialCssValue = null; }
public void CssValueCustomTest() { CssValue cssValue = new CssValue(CssValueType.Custom, "some custom value ", false); Assert.AreEqual("some custom value", cssValue.CssText); Assert.AreEqual(CssValueType.Custom, cssValue.CssValueType); }