/// <summary>
        /// Initializes a new instance of the <see cref="UvssSelectorPart"/> class.
        /// </summary>
        /// <param name="qualifier">The qualifier value for this selector part, if it has one.</param>
        /// <param name="element">The name of the element type that matches this selector part.</param>
        /// <param name="elementIsExact">A value indicating whether the element type that matches this 
        /// selector part must be an exact match.</param>
        /// <param name="id">The identifier of the element that matches this selector part.</param>
        /// <param name="pseudoClass">The selector part's pseudo-class, if any.</param>
        /// <param name="classes">The list of classes which match this selector part.</param>
        internal UvssSelectorPart(UvssSelectorPartQualifier qualifier, String element, Boolean elementIsExact,
            String id, String pseudoClass, IEnumerable<String> classes)
        {
            var rawID = (id != null && id.StartsWith("#")) ? id.Substring(1) : id;
            var rawPseudoClass = (pseudoClass != null && pseudoClass.StartsWith(":")) ? pseudoClass.Substring(1) : pseudoClass;
            var rawClassNames = from c in classes select c.StartsWith(".") ? c.Substring(1) : c;

            this.qualifier = qualifier;
            this.element = element;
            this.elementIsExact = elementIsExact;
            this.id = rawID;
            this.pseudoClass = rawPseudoClass;
            this.classes = new UvssClassCollection(rawClassNames);
            this.priority = CalculatePriority();
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UvssSelectorPart"/> class.
        /// </summary>
        /// <param name="qualifier">The qualifier value for this selector part, if it has one.</param>
        /// <param name="type">The name of the element type that matches this selector part.</param>
        /// <param name="typeIsExact">A value indicating whether the element type that matches this 
        /// selector part must be an exact match.</param>
        /// <param name="name">The name of the element that matches this selector part.</param>
        /// <param name="pseudoClass">The selector part's pseudo-class, if any.</param>
        /// <param name="classes">The list of classes which match this selector part.</param>
        internal UvssSelectorPart(UvssSelectorPartQualifier qualifier, String type, Boolean typeIsExact,
            String name, String pseudoClass, IEnumerable<String> classes)
        {
            var rawName = (name != null && name.StartsWith("#")) ? name.Substring(1) : name;
            var rawPseudoClass = (pseudoClass != null && pseudoClass.StartsWith(":")) ? pseudoClass.Substring(1) : pseudoClass;
            var rawClassNames = from c in classes select c.StartsWith(".") ? c.Substring(1) : c;

            this.qualifier = qualifier;
            this.type = type;
            this.typeIsExact = typeIsExact;
            this.name = rawName;
            this.pseudoClass = rawPseudoClass;
            this.classes = new UvssClassCollection(rawClassNames);
            this.priority = CalculatePriority();
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UvssSelectorPart"/> class.
        /// </summary>
        /// <param name="qualifier">The qualifier value for this selector part, if it has one.</param>
        /// <param name="type">The name of the element type that matches this selector part.</param>
        /// <param name="typeIsExact">A value indicating whether the element type that matches this
        /// selector part must be an exact match.</param>
        /// <param name="name">The name of the element that matches this selector part.</param>
        /// <param name="pseudoClass">The selector part's pseudo-class, if any.</param>
        /// <param name="classes">The list of classes which match this selector part.</param>
        internal UvssSelectorPart(UvssSelectorPartQualifier qualifier, String type, Boolean typeIsExact,
                                  String name, String pseudoClass, IEnumerable <String> classes)
        {
            var rawName        = (name != null && name.StartsWith("#")) ? name.Substring(1) : name;
            var rawPseudoClass = (pseudoClass != null && pseudoClass.StartsWith(":")) ? pseudoClass.Substring(1) : pseudoClass;
            var rawClassNames  = from c in classes select c.StartsWith(".") ? c.Substring(1) : c;

            this.qualifier   = qualifier;
            this.type        = type;
            this.typeIsExact = typeIsExact;
            this.name        = rawName;
            this.pseudoClass = rawPseudoClass;
            this.classes     = new UvssClassCollection(rawClassNames);
            this.priority    = CalculatePriority();
        }
        /// <summary>
        /// Compiles a <see cref="UvssSelectorPart"/> from the specified syntax node.
        /// </summary>
        private static UvssSelectorPart CompileSelectorPart(UvssSelectorPartSyntax node, UvssSelectorPartQualifier qualifier)
        {
            var element =
                node.SelectedType?.SelectedTypeIdentifier?.Text;

            if (element == "*")
            {
                element = null;
            }

            var elementIsExact =
                node.SelectedType?.ExclamationMarkToken != null;

            var id =
                node.SelectedName?.SelectedNameIdentifier?.Text;

            var pseudoClass =
                node.PseudoClass?.ClassNameIdentifier?.Text;

            var classes = new List <String>();

            for (int i = 0; i < node.SelectedClasses.Count; i++)
            {
                var selectedClass = node.SelectedClasses[i];
                classes.Add(selectedClass.SelectedClassIdentifier.Text);
            }

            return(new UvssSelectorPart(qualifier,
                                        element,
                                        elementIsExact,
                                        id,
                                        pseudoClass,
                                        classes));
        }
Esempio n. 5
0
        /// <summary>
        /// Gets a value indicating whether the specified UI element has an ancestor that matches the specified selector part.
        /// </summary>
        /// <param name="element">The UI element to evaluate. If a match is found, this variable will be updated to contain the matching element.</param>
        /// <param name="part">The selector part to evaluate.</param>
        /// <param name="root">The topmost root element to consider when tracing ancestors.</param>
        /// <param name="qualifier">A qualifier which specifies the relationship between the element and its ancestor.</param>
        /// <returns><see langword="true"/> if the element matches the selector part; otherwise, <see langword="false"/>.</returns>
        private static Boolean AncestorMatchesSelectorPart(ref UIElement element, UvssSelectorPart part, UIElement root, UvssSelectorPartQualifier qualifier)
        {
            if (qualifier == UvssSelectorPartQualifier.TemplatedChild)
            {
                var fe = element as FrameworkElement;
                if (fe != null && fe.TemplatedParent != null)
                {
                    var feTemplatedParent = (UIElement)fe.TemplatedParent;
                    if (ElementMatchesSelectorPart(feTemplatedParent, feTemplatedParent, part))
                    {
                        element = feTemplatedParent;
                        return(true);
                    }
                }
                return(false);
            }
            else
            {
                var current = element;
                while (true)
                {
                    if (current == root)
                    {
                        return(false);
                    }

                    current = ((qualifier == UvssSelectorPartQualifier.LogicalChild) ? LogicalTreeHelper.GetParent(current) : VisualTreeHelper.GetParent(current)) as UIElement;
                    if (current == null)
                    {
                        break;
                    }

                    if (ElementMatchesSelectorPart(root, current, part))
                    {
                        element = current;
                        return(true);
                    }

                    if (qualifier != UvssSelectorPartQualifier.None)
                    {
                        break;
                    }
                }
                return(false);
            }
        }