Exemple #1
0
 internal override void ComputeStyle(CssPropertyBag style, IWindow window, IElement element)
 {
     if (_selector.Match(element))
     {
         style.ExtendWith(_style, _selector.Specifity);
     }
 }
        /// <summary>
        /// Returns the first element within the document (using depth-first pre-order traversal
        /// of the document's nodes) that matches the specified group of selectors.
        /// </summary>
        /// <param name="elements">The elements to take as source.</param>
        /// <param name="selector">A selector object.</param>
        /// <returns>An element object.</returns>
        public static IElement?QuerySelector(this INodeList elements, ISelector selector)
        {
            for (var i = 0; i < elements.Length; i++)
            {
                if (elements[i] is IElement element)
                {
                    if (selector.Match(element))
                    {
                        return(element);
                    }

                    if (element.HasChildNodes)
                    {
                        element = QuerySelector(element.ChildNodes, selector) !;

                        if (element != null)
                        {
                            return(element);
                        }
                    }
                }
            }

            return(null);
        }
Exemple #3
0
        /// <summary>
        /// Returns the first element within the document (using depth-first pre-order traversal
        /// of the document's nodes) that matches the specified group of selectors.
        /// </summary>
        /// <param name="elements">The elements to take as source.</param>
        /// <param name="selector">A selector object.</param>
        /// <returns>An element object.</returns>
        public static IElement QuerySelector(this INodeList elements, ISelector selector)
        {
            for (int i = 0; i < elements.Length; i++)
            {
                var element = elements[i] as IElement;

                if (element != null)
                {
                    if (selector.Match(element))
                    {
                        return(element);
                    }

                    if (!element.HasChildNodes)
                    {
                        continue;
                    }

                    element = QuerySelector(element.ChildNodes, selector);

                    if (element != null)
                    {
                        return(element);
                    }
                }
            }

            return(null);
        }
 static IEnumerable <IElement> Filter(this IEnumerable <IElement> elements, ISelector selector, Boolean result)
 {
     foreach (var element in elements)
     {
         if (selector.Match(element) == result)
         {
             yield return(element);
         }
     }
 }
Exemple #5
0
 private static void MatchAll(this ISelector selector, IEnumerable <IElement> elements, IElement scope, List <IElement> result)
 {
     foreach (var element in elements)
     {
         foreach (var descendentAndSelf in element.DescendentsAndSelf <IElement>())
         {
             if (selector.Match(descendentAndSelf, scope))
             {
                 result.Add(descendentAndSelf);
             }
         }
     }
 }
Exemple #6
0
        /// <summary>
        /// Returns the first element within the given elements (using depth-first
        /// pre-order traversal) that match the selectors with the given scope.
        /// </summary>
        /// <param name="selector">A selector object.</param>
        /// <param name="elements">The elements to take as source.</param>
        /// <param name="scope">The element to take as scope.</param>
        /// <returns>The resulting element or null.</returns>
        public static IElement?MatchAny(this ISelector selector, IEnumerable <IElement> elements, IElement?scope)
        {
            foreach (var element in elements)
            {
                foreach (var descendentAndSelf in element.DescendentsAndSelf <IElement>())
                {
                    if (selector.Match(descendentAndSelf, scope))
                    {
                        return(descendentAndSelf);
                    }
                }
            }

            return(null);
        }
        static IEnumerable <IElement> GetMany(this IEnumerable <IElement> elements, Func <IElement, IEnumerable <IElement> > getter, ISelector selector)
        {
            foreach (var element in elements)
            {
                var children = getter(element);

                foreach (var child in children)
                {
                    if (selector.Match(child))
                    {
                        yield return(child);
                    }
                }
            }
        }
Exemple #8
0
        private static IEnumerable <T> Filter <T>(this IEnumerable <T> elements, ISelector selector, Boolean result)
            where T : IElement
        {
            if (selector == null)
            {
                selector = SimpleSelector.All;
            }

            foreach (var element in elements)
            {
                if (selector.Match(element) == result)
                {
                    yield return(element);
                }
            }
        }
 /// <summary>
 /// Returns a list of the elements within the document (using depth-first pre-order traversal
 /// of the document's nodes) that match the specified group of selectors.
 /// </summary>
 /// <param name="elements">The elements to take as source.</param>
 /// <param name="selector">A selector object.</param>
 /// <param name="result">A reference to the list where to store the results.</param>
 public static void QuerySelectorAll(this INodeList elements, ISelector selector, List <IElement> result)
 {
     for (var i = 0; i < elements.Length; i++)
     {
         if (elements[i] is IElement element)
         {
             foreach (var descendentAndSelf in element.DescendentsAndSelf <IElement>())
             {
                 if (selector.Match(descendentAndSelf))
                 {
                     result.Add(descendentAndSelf);
                 }
             }
         }
     }
 }
Exemple #10
0
        private int GetEndGroupIndex(StyleSheet styleSheet, ISelector selector, SelectorType type)
        {
            if (selector.GroupCount == 1)
            {
                return(0);
            }

            var testStartGroupIndex = selector.GroupCount - 2;
            var testEndGroupIndex   = 0;

            var match = selector.Match(styleSheet, this, testStartGroupIndex, testEndGroupIndex);

            if (match.IsSuccess)
            {
                testEndGroupIndex = selector.GroupCount - 1;
            }

            return(testEndGroupIndex);
        }
Exemple #11
0
        public static void QuerySelectorAll(this INodeList elements, ISelector selector, List <IElement> result)
        {
            for (int i = 0; i < elements.Length; i++)
            {
                var element = elements[i] as IElement;
                if (element != null)
                {
                    if (selector.Match(element))
                    {
                        result.Add(element);
                    }

                    if (element.HasChildNodes)
                    {
                        element.ChildNodes.QuerySelectorAll(selector, result);
                    }
                }
            }
        }
Exemple #12
0
        public static void QuerySelectorAll <TDependencyObject>(this IList <IDomElement <TDependencyObject> > elements, StyleSheet styleSheet, ISelector selector, IList <IDomElement <TDependencyObject> > result)
            where TDependencyObject : class
        {
            "QuerySelectorAll".Measure(() =>
            {
                var length        = elements.Count;
                var skipThisLevel = false;

                for (int i = 0; i < length; i++)
                {
                    var element = elements[i];
                    if (!skipThisLevel)
                    {
                        if (element.StyleInfo?.CurrentStyleSheet != styleSheet ||
                            element.StyleInfo.DoMatchCheck == SelectorType.None)
                        {
                            continue;
                        }

                        var match = selector.Match(styleSheet, element);

                        if (match.IsSuccess)
                        {
                            result.Add(element);
                        }
                        else if (match.HasGeneralParentFailed)
                        {
                            //return;
                            skipThisLevel = true;
                        }
                        else if (match.HasDirectParentFailed)
                        {
                            skipThisLevel = true;
                        }
                    }

                    if (element.ChildNodes.Count != 0)
                    {
                        element.ChildNodes.QuerySelectorAll(styleSheet, selector, result);
                    }
                }
            });
        }
        static IEnumerable <IElement> Get(this IEnumerable <IElement> elements, Func <IElement, IElement> getter, ISelector selector)
        {
            foreach (var element in elements)
            {
                var child = getter(element);

                while (child != null)
                {
                    if (selector.Match(child))
                    {
                        yield return(child);

                        break;
                    }

                    child = getter(child);
                }
            }
        }
Exemple #14
0
        public static IDomElement <TDependencyObject> QuerySelector <TDependencyObject>(this IList <IDomElement <TDependencyObject> > elements, StyleSheet styleSheet, ISelector selector)
            where TDependencyObject : class
        {
            var length        = elements.Count;
            var skipThisLevel = false;

            for (int i = 0; i < length; i++)
            {
                var element = elements[i];
                if (!skipThisLevel)
                {
                    var match = selector.Match(styleSheet, element);
                    if (match.IsSuccess)
                    {
                        return(element);
                    }
                    else if (match.HasGeneralParentFailed)
                    {
                        //return null;
                        skipThisLevel = true;
                    }
                    else if (match.HasDirectParentFailed)
                    {
                        skipThisLevel = true;
                    }
                }

                if (element.ChildNodes.Count != 0)
                {
                    element = element.ChildNodes.QuerySelector(styleSheet, selector);

                    if (element != null)
                    {
                        return(element);
                    }
                }
            }

            return(null);
        }
Exemple #15
0
        public ICollection <T> GetMatches(ISelector <T> selector)
        {
            if (selector == null)
            {
                return(new List <T>(_local));
            }
            else
            {
                List <T>        col  = new List <T>();
                IEnumerator <T> iter = _local.GetEnumerator();

                while (iter.MoveNext())
                {
                    T obj = iter.Current;
                    if (selector.Match(obj))
                    {
                        col.Add(obj);
                    }
                }

                return(col);
            }
        }
Exemple #16
0
        //public string LookupNamespaceUri(string prefix)
        //{
        //    return namespaceProvider.LookupNamespaceUri(this, prefix);
        //}

        //public string LookupPrefix(string namespaceUri)
        //{
        //    return namespaceProvider.LookupPrefix(this, namespaceUri);
        //}

        public MatchResult Matches(StyleSheet styleSheet, ISelector selector)
        {
            return(selector.Match(styleSheet, this));
        }
Exemple #17
0
        public static void QuerySelectorAll <TDependencyObject, TDependencyProperty>(this IList <IDomElement <TDependencyObject, TDependencyProperty> > elements, StyleSheet styleSheet, ISelector selector, IList <IDomElement <TDependencyObject, TDependencyProperty> > result, SelectorType type)
            where TDependencyObject : class
        {
            var length        = elements.Count;
            var skipThisLevel = false;

            for (int i = 0; i < length; i++)
            {
                var element = elements[i];
                var inTree  = true;

                if (type == SelectorType.LogicalTree &&
                    !element.IsInLogicalTree)
                {
                    inTree = false;
                }
                else if (type == SelectorType.VisualTree &&
                         !element.IsInVisualTree)
                {
                    inTree = false;
                }
                else if (!element.IsReady)
                {
                    inTree = false;
                }


                if (!skipThisLevel &&
                    inTree)
                {
                    var shouldNotProcess =
                        !object.ReferenceEquals(element.StyleInfo != null ? element.StyleInfo.CurrentStyleSheet : null, styleSheet) ||
                        (element.StyleInfo.DoMatchCheck & type) != type;

                    if (shouldNotProcess)
                    {
                        continue;
                    }

                    var match = selector.Match(styleSheet, element);

                    if (match.IsSuccess)
                    {
                        result.Add(element);
                    }
                    else if (match.HasGeneralParentFailed)
                    {
                        skipThisLevel = true;
                    }
                    else if (match.HasDirectParentFailed)
                    {
                        skipThisLevel = true;
                    }
                }

                if (inTree)
                {
                    var children = type == SelectorType.LogicalTree ? element.LogicalChildNodes : element.ChildNodes;
                    if (children.Count != 0)
                    {
                        children.QuerySelectorAll(styleSheet, selector, result, type);
                    }
                }
            }
        }
        static IEnumerable<IElement> GetMany(this IEnumerable<IElement> elements, Func<IElement, IEnumerable<IElement>> getter, ISelector selector)
        {
            foreach (var element in elements)
            {
                var children = getter(element);

                foreach (var child in children)
                {
                    if (selector.Match(child))
                        yield return child;
                }
            }
        }
Exemple #19
0
 /// <summary>
 /// Provides an alternate to <see cref="ISelector.Match(IElement, IElement)" /> that sets the
 /// scope to the owning document element (if there is one).
 /// </summary>
 /// <param name="selector">The selector.</param>
 /// <param name="element">The element to match against.</param>
 /// <returns>The result of the match.</returns>
 public static Boolean Match(this ISelector selector, IElement element)
 {
     return(selector.Match(element, element?.Owner.DocumentElement));
 }
        static IEnumerable<IElement> Get(this IEnumerable<IElement> elements, Func<IElement, IElement> getter, ISelector selector)
        {
            foreach (var element in elements)
            {
                var child = getter(element);

                while (child != null)
                {
                    if (selector.Match(child))
                    {
                        yield return child;
                        break;
                    }

                    child = getter(child);
                }
            }
        }
 static IEnumerable<IElement> Filter(this IEnumerable<IElement> elements, ISelector selector, Boolean result)
 {
     foreach (var element in elements)
     {
         if (selector.Match(element) == result)
             yield return element;
     }
 }
Exemple #22
0
 /// <summary>
 /// Provides an alternate to <see cref="ISelector.Match(IElement, IElement)" /> that sets the
 /// scope to the owning document element (if there is one).
 /// </summary>
 /// <param name="selector">The selector.</param>
 /// <param name="element">The element to match against.</param>
 /// <returns>The result of the match.</returns>
 public static Boolean Match(this ISelector selector, IElement element) => selector.Match(element, element?.Owner !.DocumentElement);