Пример #1
0
        private int CountVisibleElements(IHTMLElement node)
        {
            if (node == null)
            {
                return(0);
            }

            int count = 0;
            IHTMLElementCollection all = (IHTMLElementCollection)node.all;

            foreach (IHTMLElement child in all)
            {
                if (ElementFilters.IsVisibleEmptyElement(child))
                {
                    count++;
                }
            }
            return(count);
        }
        /// <summary>
        /// Returns true if shift+tab focused region changing is supported for the current edit location
        /// </summary>
        /// <returns></returns>
        private bool ShiftTabFocusChangeSupported()
        {
            //Shift-tab is only supported if the caret is positioned at the beginning of the post
            //If the selection is currently inside a non-blockquote block element with no visible content
            //to the left of it, then focus change is supported.

            if (!EditorContext.Selection.SelectedMarkupRange.IsEmpty())
            {
                return(false);
            }

            MarkupRange range = ElementRange.Clone();

            range.Start.MoveAdjacentToElement(HTMLElement, _ELEMENT_ADJACENCY.ELEM_ADJ_AfterBegin);
            range.End = EditorContext.Selection.SelectedMarkupRange.Start;

            //if there is any text between the caret and the beginning of the post,
            //then ShiftTab focus changing is not allowed.
            string text = range.Text;

            if (text != null && range.Text.Trim() != String.Empty)
            {
                return(false);
            }

            MarkupContext context = new MarkupContext();

            range.Start.Right(true, context);
            int blockElementDepth = 0;

            while (range.Start.IsLeftOfOrEqualTo(range.End))
            {
                if (context.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_EnterScope || context.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_NoScope)
                {
                    string tagName = context.Element.tagName;
                    if (tagName.Equals("BLOCKQUOTE") || ElementFilters.IsListElement(context.Element) || ElementFilters.IsListItemElement(context.Element))
                    {
                        return(false); //ShiftTab in a blockquote or list implies "un-blockquote" or "un-list"
                    }
                    else if (ElementFilters.IsBlockElement(context.Element))
                    {
                        blockElementDepth++;
                        if (blockElementDepth > 1)
                        {
                            return(false); //there are multiple block elements, so this is not the beginning
                        }
                    }
                    else if (ElementFilters.IsVisibleEmptyElement(context.Element))
                    {
                        return(false); //there is a visible empty element (like an image), so this is not the beginning
                    }
                }
                else if (context.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_ExitScope)
                {
                    if (ElementFilters.IsVisibleEmptyElement(context.Element))
                    {
                        return(false); //there is a visible empty element (like an image), so this is not the beginning
                    }
                }
                range.Start.Right(true, context);
            }

            return(true);
        }