protected bool IsCaretWithin(Rectangle clientRect) { IHTMLCaretRaw caret = GetCaret(); POINT p; caret.GetLocation(out p, true); Point pt = new Point(p.x, p.y); return(pt.X >= clientRect.X && pt.X <= clientRect.Right && pt.Y >= clientRect.Y && pt.Y <= clientRect.Bottom); }
/// <summary> /// Navigates the editor's caret to the next editable region. /// </summary> /// <param name="direction"></param> private bool MoveCaretToNextRegion(MOVE_DIRECTION direction) { IHTMLElement nextRegion; _ELEMENT_ADJACENCY nextRegionAdjacency; bool preserveXLocation; if (direction == MOVE_DIRECTION.UP || direction == MOVE_DIRECTION.LEFT) { nextRegion = PreviousEditableRegion; nextRegionAdjacency = _ELEMENT_ADJACENCY.ELEM_ADJ_BeforeEnd; preserveXLocation = direction == MOVE_DIRECTION.UP; } else if (direction == MOVE_DIRECTION.DOWN || direction == MOVE_DIRECTION.RIGHT) { nextRegion = NextEditableRegion; nextRegionAdjacency = _ELEMENT_ADJACENCY.ELEM_ADJ_AfterBegin; preserveXLocation = direction == MOVE_DIRECTION.DOWN; if (nextRegion == null) { return(false); } MarkupPointer selectRegion = EditorContext.MarkupServices.CreateMarkupPointer(nextRegion, nextRegionAdjacency); MarkupContext mc = selectRegion.Right(false); if (mc.Context == _MARKUP_CONTEXT_TYPE.CONTEXT_TYPE_EnterScope && mc.Element is IHTMLElement3 && SmartContentSelection.SelectIfSmartContentElement(EditorContext, mc.Element) != null) { return(true); } } else { throw new ArgumentException("Unsupported move direction detected: " + direction); } IDisplayServicesRaw displayServices = (IDisplayServicesRaw)HTMLElement.document; IDisplayPointerRaw displayPointer; displayServices.CreateDisplayPointer(out displayPointer); IHTMLCaretRaw caret = GetCaret(); caret.MoveDisplayPointerToCaret(displayPointer); ILineInfo lineInfo; displayPointer.GetLineInfo(out lineInfo); if (nextRegion != null) { MarkupPointer mp = EditorContext.MarkupServices.CreateMarkupPointer(nextRegion, nextRegionAdjacency); DisplayServices.TraceMoveToMarkupPointer(displayPointer, mp); try { caret.MoveCaretToPointer(displayPointer, true, _CARET_DIRECTION.CARET_DIRECTION_SAME); if (preserveXLocation) { POINT caretLocation; caret.GetLocation(out caretLocation, true); caretLocation.x = lineInfo.x; uint hitTestResults; displayPointer.MoveToPoint(caretLocation, _COORD_SYSTEM.COORD_SYSTEM_GLOBAL, nextRegion, 0, out hitTestResults); caret.MoveCaretToPointer(displayPointer, true, _CARET_DIRECTION.CARET_DIRECTION_SAME); } //BEP: using this line causes scrolling (nextRegion as IHTMLElement2).focus(); (nextRegion as IHTMLElement3).setActive(); return(true); } catch (Exception e) { Debug.Fail("Unexpected exception in MoveCaretToNextRegion: " + e.ToString()); } caret.MoveCaretToPointer(displayPointer, true, _CARET_DIRECTION.CARET_DIRECTION_SAME); } return(false); }