Used internally to store collected properties.
コード例 #1
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));
                }
                return(scp.CssValue.GetAbsoluteValue(propertyName, _element));
            }

            // 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);
            }
            return(CssValue.GetCssValue(initValue, false).GetAbsoluteValue(propertyName, _element));
        }
コード例 #2
0
 /// <summary>
 /// Returns the origin type of the collected property
 /// </summary>
 /// <param name="propertyName">The name of the property</param>
 /// <returns>The origin type</returns>
 public CssStyleSheetType GetPropertyOrigin(string propertyName)
 {
     if (_collectedStyles.ContainsKey(propertyName))
     {
         CssCollectedProperty scp = _collectedStyles[propertyName];
         return(scp.Origin);
     }
     return(CssStyleSheetType.Unknown);
 }
コード例 #3
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;
                }
            }
        }
コード例 #4
0
        internal bool IsBetterThen(CssCollectedProperty existing)
        {
            bool yes = false;

            #region sorting according to the rules at http:            //www.w3.org/TR/CSS21/cascade.html#cascading-order
            bool gotHigherSpecificity = (Specificity >= existing.Specificity);

            switch (existing.Origin)
            {
            case CssStyleSheetType.UserAgent:
                yes = (Origin == CssStyleSheetType.UserAgent) ? gotHigherSpecificity : true;
                break;

            case CssStyleSheetType.NonCssPresentationalHints:
                yes = (Origin != CssStyleSheetType.UserAgent);
                break;

            case CssStyleSheetType.Inline:
                yes = (Origin != CssStyleSheetType.UserAgent &&
                       Origin != CssStyleSheetType.NonCssPresentationalHints);
                break;

            case CssStyleSheetType.Author:
                if (Origin == CssStyleSheetType.Author &&
                    Priority == existing.Priority &&
                    gotHigherSpecificity)
                {
                    // author rules of the same priority
                    yes = true;
                }
                else if (Origin == CssStyleSheetType.Inline)
                {
                    // inline rules override author rules
                    yes = true;
                }
                else if (Origin == CssStyleSheetType.User && Priority == "important")
                {
                    // !important user rules overrides author rules
                    yes = true;
                }
                else if (Origin == CssStyleSheetType.Author &&
                         existing.Priority != "important" &&
                         Priority == "important"
                         )
                {
                    // !important author rules override non-!important author rules
                    yes = true;
                }
                break;

            case CssStyleSheetType.User:
                if (Origin == CssStyleSheetType.User &&
                    existing.Priority == Priority &&
                    gotHigherSpecificity)
                {
                    yes = true;
                }
                else if ((Origin == CssStyleSheetType.Author || Origin == CssStyleSheetType.Inline) &&
                         existing.Priority != "important")
                {
                    // author rules overrides not !important user rules
                    yes = true;
                }
                else if (Origin == CssStyleSheetType.User &&
                         Priority == "important")
                {
                    // !important user rules override non-!important user rules
                    yes = true;
                }
                break;
            }
            #endregion

            return(yes);
        }
コード例 #5
0
        internal bool IsBetterThen(CssCollectedProperty existing)
        {
            bool yes = false;
            #region sorting according to the rules at http://www.w3.org/TR/CSS21/cascade.html#cascading-order
            bool gotHigherSpecificity = (Specificity>=existing.Specificity);

            switch(existing.Origin)
            {
                case CssStyleSheetType.UserAgent:
                    yes = (Origin == CssStyleSheetType.UserAgent) ? gotHigherSpecificity : true;
                    break;
                case CssStyleSheetType.NonCssPresentationalHints:
                    yes = (Origin != CssStyleSheetType.UserAgent);
                    break;
                case CssStyleSheetType.Inline:
                    yes = (Origin != CssStyleSheetType.UserAgent &&
                        Origin != CssStyleSheetType.NonCssPresentationalHints);
                    break;
                case CssStyleSheetType.Author:
                    if(Origin == CssStyleSheetType.Author &&
                        Priority == existing.Priority &&
                        gotHigherSpecificity)
                    {
                        // author rules of the same priority
                        yes = true;
                    }
                    else if(Origin == CssStyleSheetType.Inline)
                    {
                        // inline rules override author rules
                        yes = true;
                    }
                    else if(Origin == CssStyleSheetType.User && Priority == "important")
                    {
                        // !important user rules overrides author rules
                        yes = true;
                    }
                    else if(Origin == CssStyleSheetType.Author &&
                        existing.Priority != "important" &&
                        Priority == "important"
                        )
                    {
                        // !important author rules override non-!important author rules
                        yes = true;
                    }
                    break;
                case CssStyleSheetType.User:
                    if(Origin == CssStyleSheetType.User &&
                        existing.Priority == Priority &&
                        gotHigherSpecificity)
                    {
                        yes = true;
                    }
                    else if((Origin == CssStyleSheetType.Author || Origin == CssStyleSheetType.Inline) &&
                        existing.Priority != "important")
                    {
                        // author rules overrides not !important user rules
                        yes = true;
                    }
                    else if(Origin == CssStyleSheetType.User &&
                        Priority == "important")
                    {
                        // !important user rules override non-!important user rules
                        yes = true;
                    }
                    break;
            }
            #endregion

            return yes;
        }
コード例 #6
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;
                }
            }
        }