EphemeralRange LocalFrame::rangeForPoint(const IntPoint& framePoint) { const PositionWithAffinity positionWithAffinity = positionForPoint(framePoint); if (positionWithAffinity.isNull()) return EphemeralRange(); VisiblePosition position = createVisiblePosition(positionWithAffinity); VisiblePosition previous = previousPositionOf(position); if (previous.isNotNull()) { const EphemeralRange previousCharacterRange = makeRange(previous, position); IntRect rect = editor().firstRectForRange(previousCharacterRange); if (rect.contains(framePoint)) return EphemeralRange(previousCharacterRange); } VisiblePosition next = nextPositionOf(position); const EphemeralRange nextCharacterRange = makeRange(position, next); if (nextCharacterRange.isNotNull()) { IntRect rect = editor().firstRectForRange(nextCharacterRange); if (rect.contains(framePoint)) return EphemeralRange(nextCharacterRange); } return EphemeralRange(); }
PositionWithAffinity LocalFrame::positionForPoint(const IntPoint& framePoint) { HitTestResult result = eventHandler().hitTestResultAtPoint(framePoint); Node* node = result.innerNodeOrImageMapImage(); if (!node) return PositionWithAffinity(); LayoutObject* layoutObject = node->layoutObject(); if (!layoutObject) return PositionWithAffinity(); const PositionWithAffinity position = layoutObject->positionForPoint(result.localPoint()); if (position.isNull()) return PositionWithAffinity(firstPositionInOrBeforeNode(node)); return position; }
void CaretBase::updateCaretRect(const PositionWithAffinity& caretPosition) { m_caretLocalRect = LayoutRect(); if (caretPosition.isNull()) return; DCHECK(caretPosition.anchorNode()->layoutObject()); // First compute a rect local to the layoutObject at the selection start. LayoutObject* layoutObject; m_caretLocalRect = localCaretRectOfPosition(caretPosition, layoutObject); // Get the layoutObject that will be responsible for painting the caret // (which is either the layoutObject we just found, or one of its containers). LayoutBlockItem caretPainterItem = LayoutBlockItem(caretLayoutObject(caretPosition.anchorNode())); mapCaretRectToCaretPainter(LayoutItem(layoutObject), caretPainterItem, m_caretLocalRect); }