コード例 #1
0
        /// <summary>
        /// Adds a styling rule to the prioritizer.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="selector">The selector which caused this style to be considered.</param>
        /// <param name="navigationExpression">The navigation expression associated with the style.</param>
        /// <param name="rule">The styling rule to add to the prioritizer.</param>
        /// <param name="index">The index of the rule's rule set within the style sheet.</param>
        public void Add(UltravioletContext uv, UvssSelector selector, NavigationExpression?navigationExpression, UvssRule rule, Int32 index)
        {
            Contract.Require(uv, nameof(uv));

            var key      = new StyleKey(rule.CanonicalName, navigationExpression);
            var priority = CalculatePriorityFromSelector(selector, rule.IsImportant);

            PrioritizedStyle existing;

            if (!rules.TryGetValue(key, out existing))
            {
                rules[key] = new PrioritizedStyle(rule, selector, priority, index);
            }
            else
            {
                var comparison = selector.ComparePriority(existing.Selector);
                if (comparison == 0 && index > existing.Index)
                {
                    comparison = 1;
                }

                if (comparison > 0 && (rule.IsImportant || !existing.Style.IsImportant))
                {
                    rules[key] = new PrioritizedStyle(rule, selector, priority, index);
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Adds a style to the prioritizer.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="selector">The selector which caused this style to be considered.</param>
        /// <param name="navigationExpression">The navigation expression associated with the style.</param>
        /// <param name="style">The style to add to the prioritizer.</param>
        public void Add(UltravioletContext uv, UvssSelector selector, NavigationExpression? navigationExpression, UvssStyle style)
        {
            Contract.Require(uv, "uv");

            var key = new StyleKey(style.CanonicalName, navigationExpression);
            var priority = CalculatePriorityFromSelector(selector, style.IsImportant);

            PrioritizedStyle existing;
            if (!styles.TryGetValue(key, out existing))
            {
                styles[key] = new PrioritizedStyle(style, selector, priority);
            }
            else
            {
                if (selector.IsHigherPriorityThan(existing.Selector) && (style.IsImportant || !existing.Style.IsImportant))
                {
                    styles[key] = new PrioritizedStyle(style, selector, priority);
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Adds a styling rule to the prioritizer.
        /// </summary>
        /// <param name="uv">The Ultraviolet context.</param>
        /// <param name="selector">The selector which caused this style to be considered.</param>
        /// <param name="navigationExpression">The navigation expression associated with the style.</param>
        /// <param name="rule">The styling rule to add to the prioritizer.</param>
        /// <param name="index">The index of the rule's rule set within the style sheet.</param>
        public void Add(UltravioletContext uv, UvssSelector selector, NavigationExpression? navigationExpression, UvssRule rule, Int32 index)
        {
            Contract.Require(uv, nameof(uv));

            var key = new StyleKey(rule.CanonicalName, navigationExpression);
            var priority = CalculatePriorityFromSelector(selector, rule.IsImportant);

            PrioritizedStyle existing;
            if (!rules.TryGetValue(key, out existing))
            {
                rules[key] = new PrioritizedStyle(rule, selector, priority, index);
            }
            else
            {
                var comparison = selector.ComparePriority(existing.Selector);
                if (comparison == 0 && index > existing.Index)
                    comparison = 1;

                if (comparison > 0 && (rule.IsImportant || !existing.Style.IsImportant))
                {
                    rules[key] = new PrioritizedStyle(rule, selector, priority, index);
                }
            }
        }