The CSSValue interface represents a simple or a complex value. A CSSValue object only occurs in a context of a CSS property
Inheritance: ICssValue
Exemplo n.º 1
0
 public CssAbsValue(CssValue cssValue, string propertyName, XmlElement element)
     : base()
 {
     _cssValue = cssValue;
     _propertyName = propertyName;
     _element = element;
 }
Exemplo n.º 2
0
 internal CssCollectedProperty(string name, int specificity, CssValue cssValue, CssStyleSheetType origin, string priority)
 {
     Name = name;
     Specificity = specificity;
     Origin = origin;
     CssValue = cssValue;
     Priority = priority;
 }
Exemplo n.º 3
0
 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);
        }
Exemplo n.º 5
0
 /// <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);
 }
Exemplo n.º 6
0
        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");
        }
Exemplo n.º 7
0
        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));
        }
Exemplo n.º 8
0
 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);
 }
Exemplo n.º 9
0
        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);
        }
Exemplo n.º 10
0
        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);
        }
Exemplo n.º 11
0
        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);
        }
Exemplo n.º 12
0
 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;
 }
Exemplo n.º 13
0
 /// <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);
     }
 }
Exemplo n.º 14
0
        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");
        }
Exemplo n.º 15
0
        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;
                }
            }
        }
Exemplo n.º 16
0
        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");
        }
Exemplo n.º 17
0
 /// <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);
 }
Exemplo n.º 18
0
        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));
                }
            }
        }
Exemplo n.º 19
0
 public void CssValueInheritTest()
 {
     CssValue cssValue = new CssValue(CssValueType.Inherit, "inherit", false);
             Assert.AreEqual("inherit", cssValue.CssText);
             Assert.AreEqual(CssValueType.Inherit, cssValue.CssValueType);
 }
Exemplo n.º 20
0
 internal CssProperty(bool isInherited, string initialValue)
 {
     this.IsInherited     = isInherited;
     this.InitialValue    = initialValue;
     this.InitialCssValue = null;
 }
Exemplo n.º 21
0
 internal CssProperty(bool isInherited, string initialValue)
 {
     this.IsInherited     = isInherited;
     this.InitialValue    = initialValue;
     this.InitialCssValue = null;
 }
Exemplo n.º 22
0
 public CssAbsValue(CssValue cssValue, string propertyName, XmlElement element) : base()
 {
     _cssValue     = cssValue;
     _propertyName = propertyName;
     _element      = element;
 }
        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;
                }
            }
        }
Exemplo n.º 24
0
 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);
 }