コード例 #1
0
        /// <summary>
        /// Find the most logic direction to move the cursor so that it matches the where has clicked
        /// </summary>
        /// <param name="Selection"></param>
        /// <returns></returns>
        public static Direction FindSelectionToLogicalPosition(MarkupRange Selection, IHTMLElement body, bool?forward)
        {
            // There is a selection, not just a click
            if (!Selection.Start.IsEqualTo(Selection.End))
            {
                return(Direction.None);
            }

            Direction dir = ImageBreakout(Selection.Start);

            if (dir != Direction.None)
            {
                return(dir);
            }

            MarkupContext contextRight = Selection.Start.Right(false);
            MarkupContext contextLeft  = Selection.Start.Left(false);

            // there is text or some other type of content around the click
            if (!((contextLeft.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_EnterScope || contextLeft.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_ExitScope) &&
                  (contextRight.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_EnterScope || contextRight.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_ExitScope)))
            {
                return(Direction.None);
            }

            // The click is not between two block elements, so it should be fine where it is
            if (!ElementFilters.IsBlockElement(contextLeft.Element) || !ElementFilters.IsBlockElement(contextRight.Element))
            {
                return(Direction.None);
            }

            // </blockElement>|</postBody>
            if (contextLeft.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_EnterScope &&
                !IsSmartContent(contextLeft) &&
                contextRight.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_ExitScope &&
                contextRight.Element.id == body.id)
            {
                return(Direction.Left);
            }

            // <postBody>|<blockElement>
            if (contextRight.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_EnterScope &&
                !IsSmartContent(contextRight) &&
                contextLeft.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_ExitScope &&
                contextLeft.Element.id == body.id)
            {
                return(Direction.Right);
            }

            // </blockElement>|<blockElement>
            if (contextLeft.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_EnterScope &&
                !IsSmartContent(contextLeft) &&
                contextRight.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_EnterScope &&
                !IsSmartContent(contextRight))
            {
                return(forward == null || forward == true ? Direction.Right : Direction.Left);
            }

            return(Direction.None);
        }
コード例 #2
0
        public static MarkupRange GetEditableRange(IHTMLElement e, MshtmlMarkupServices markupServices)
        {
            IHTMLElement3 editableElement = null;

            while (e != null)
            {
                if (((IHTMLElement3)e).isContentEditable)
                {
                    editableElement = (IHTMLElement3)e;
                    if (ElementFilters.IsBlockElement(e))
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
                e = e.parentElement;
            }

            if (editableElement != null)
            {
                return(markupServices.CreateMarkupRange((IHTMLElement)editableElement, false));
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
 private static MoveFilterResult StopBeforeExitBlock(MarkupContext mc)
 {
     if (mc.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_ExitScope && ElementFilters.IsBlockElement(mc.Element))
     {
         return(MoveFilterResult.STOP_BACK);
     }
     return(MoveFilterResult.CONTINUE);
 }
コード例 #4
0
 private static MoveFilterResult StopAfterEnterBlock(MarkupContext mc)
 {
     if (mc.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_EnterScope && ElementFilters.IsBlockElement(mc.Element))
     {
         return(MoveFilterResult.STOP);
     }
     return(MoveFilterResult.CONTINUE);
 }
コード例 #5
0
        /// <summary>
        /// Retrieves the block element that this pointer is positioned within.
        /// </summary>
        public IHTMLElement CurrentBlockScope()
        {
            IHTMLElement parent = CurrentScope;

            while (parent != null && !ElementFilters.IsBlockElement(parent))
            {
                parent = parent.parentElement;
            }
            return(parent);
        }