Example #1
0
        ///// <summary>
        ///// Gets the elements in the range that match the filter.
        ///// </summary>
        ///// <param name="filter">the delegate testing each element to determine if it should be added to the list of elements to return</param>
        ///// <param name="inScopeElementsOnly">if true, the only</param>
        ///// <returns></returns>
        //public IHTMLElement[] GetElements(IHTMLElementFilter filter, bool inScopeElementsOnly)
        //{
        //    ArrayList list = new ArrayList();
        //    if (!IsEmpty())
        //    {
        //        Hashtable usedElements = new Hashtable();
        //        MarkupPointer p = MarkupServices.CreateMarkupPointer(Start);
        //        MarkupPointer end = MarkupServices.CreateMarkupPointer(End);
        //        MarkupContext context = p.Right(false);

        //        //move p through the range to locate each the elements adding elements that pass the filter
        //        while (p.IsLeftOfOrEqualTo(end))
        //        {
        //            if (context.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_EnterScope
        //                || context.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_ExitScope
        //                || context.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_NoScope)
        //            {
        //                if (usedElements[context.Element] == null)
        //                {
        //                    if ((inScopeElementsOnly && isInScope(context.Element)) || !inScopeElementsOnly)
        //                        if (filter(context.Element))
        //                        {
        //                            list.Add(context.Element);
        //                        }

        //                    //cache the fact that we've already tested this element.
        //                    usedElements[context.Element] = context.Element;
        //                }
        //            }
        //            p.Right(true, context);
        //        }
        //    }
        //    return HTMLElementHelper.ToElementArray(list);
        //}

        /// <summary>
        /// Gets the first element in the range that match the filter.
        /// </summary>
        /// <param name="filter">the delegate testing each element to determine if it should be added to the list of elements to return</param>
        /// <param name="inScopeElementsOnly">if true, the only</param>
        /// <returns></returns>
        public IHTMLElement GetFirstElement(IHTMLElementFilter filter, bool inScopeElementsOnly)
        {
            ArrayList list = new ArrayList();

            if (!IsEmpty())
            {
                Hashtable     usedElements = new Hashtable();
                MarkupPointer p            = MarkupServices.CreateMarkupPointer(Start);
                MarkupPointer end          = MarkupServices.CreateMarkupPointer(End);
                MarkupContext context      = p.Right(false);

                //move p through the range to locate each the elements adding elements that pass the filter
                while (p.IsLeftOfOrEqualTo(end))
                {
                    if (context.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_EnterScope ||
                        context.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_ExitScope ||
                        context.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_NoScope)
                    {
                        if (usedElements[context.Element] == null)
                        {
                            if ((inScopeElementsOnly && isInScope(context.Element)) || !inScopeElementsOnly)
                            {
                                if (filter(context.Element))
                                {
                                    return(context.Element);
                                }
                            }

                            //cache the fact that we've already tested this element.
                            usedElements[context.Element] = context.Element;
                        }
                    }
                    p.Right(true, context);
                }
            }
            return(null);
        }