Commit 1ee44ea9 authored by yosin's avatar yosin Committed by Commit bot

Move VisibleSelection::positionRespectingEditingBoundary() to EditingUtilities.cpp

This patch moves a member function |positionRespectingEditingBoundary()| in
|VisibleSelection| and gets rid of |visiblePositionRespectingEditingBoundary()|
to simplify |VisibleSelection| class for improving code health, since
these functions are used in one place.

BUG=n/a
TEST=n/a; no behavior changes

Review-Url: https://codereview.chromium.org/2022723002
Cr-Commit-Position: refs/heads/master@{#396779}
parent eb88a1e8
......@@ -1468,6 +1468,26 @@ unsigned numEnclosingMailBlockquotes(const Position& p)
return num;
}
PositionWithAffinity positionRespectingEditingBoundary(const Position& position, const LayoutPoint& localPoint, Node* targetNode)
{
if (!targetNode->layoutObject())
return PositionWithAffinity();
LayoutPoint selectionEndPoint = localPoint;
Element* editableElement = rootEditableElementOf(position);
if (editableElement && !editableElement->contains(targetNode)) {
if (!editableElement->layoutObject())
return PositionWithAffinity();
FloatPoint absolutePoint = targetNode->layoutObject()->localToAbsolute(FloatPoint(selectionEndPoint));
selectionEndPoint = roundedLayoutPoint(editableElement->layoutObject()->absoluteToLocal(absolutePoint));
targetNode = editableElement;
}
return targetNode->layoutObject()->positionForPoint(selectionEndPoint);
}
void updatePositionForNodeRemoval(Position& position, Node& node)
{
if (position.isNull())
......
......@@ -250,6 +250,7 @@ enum WhitespacePositionOption { NotConsiderNonCollapsibleWhitespace, ConsiderNon
Position leadingWhitespacePosition(const Position&, TextAffinity, WhitespacePositionOption = NotConsiderNonCollapsibleWhitespace);
Position trailingWhitespacePosition(const Position&, TextAffinity, WhitespacePositionOption = NotConsiderNonCollapsibleWhitespace);
unsigned numEnclosingMailBlockquotes(const Position&);
PositionWithAffinity positionRespectingEditingBoundary(const Position&, const LayoutPoint& localPoint, Node* targetNode);
void updatePositionForNodeRemoval(Position&, Node&);
// -------------------------------------------------------------------------
......
......@@ -197,7 +197,7 @@ void SelectionController::updateSelectionForMouseDrag(const HitTestResult& hitTe
if (!target)
return;
PositionWithAffinity rawTargetPosition = selection().selection().positionRespectingEditingBoundary(hitTestResult.localPoint(), target);
const PositionWithAffinity& rawTargetPosition = positionRespectingEditingBoundary(selection().selection().start(), hitTestResult.localPoint(), target);
VisiblePositionInFlatTree targetPosition = createVisiblePosition(fromPositionInDOMTree<EditingInFlatTreeStrategy>(rawTargetPosition));
// Don't modify the selection if we're not on a node.
if (targetPosition.isNull())
......
......@@ -733,33 +733,6 @@ void VisibleSelectionTemplate<Strategy>::adjustSelectionToAvoidCrossingEditingBo
m_extent = m_baseIsFirst ? m_end : m_start;
}
template <typename Strategy>
VisiblePositionTemplate<Strategy> VisibleSelectionTemplate<Strategy>::visiblePositionRespectingEditingBoundary(const LayoutPoint& localPoint, Node* targetNode) const
{
return createVisiblePosition(positionRespectingEditingBoundary(localPoint, targetNode));
}
template <typename Strategy>
PositionWithAffinityTemplate<Strategy> VisibleSelectionTemplate<Strategy>::positionRespectingEditingBoundary(const LayoutPoint& localPoint, Node* targetNode) const
{
if (!targetNode->layoutObject())
return PositionWithAffinityTemplate<Strategy>();
LayoutPoint selectionEndPoint = localPoint;
Element* editableElement = rootEditableElement();
if (editableElement && !editableElement->contains(targetNode)) {
if (!editableElement->layoutObject())
return PositionWithAffinityTemplate<Strategy>();
FloatPoint absolutePoint = targetNode->layoutObject()->localToAbsolute(FloatPoint(selectionEndPoint));
selectionEndPoint = roundedLayoutPoint(editableElement->layoutObject()->absoluteToLocal(absolutePoint));
targetNode = editableElement;
}
return fromPositionInDOMTree<Strategy>(targetNode->layoutObject()->positionForPoint(selectionEndPoint));
}
template <typename Strategy>
bool VisibleSelectionTemplate<Strategy>::isContentEditable() const
{
......
......@@ -129,9 +129,6 @@ public:
// ShadowRoot node for new shadow trees, or 0 for non-shadow trees.
Node* nonBoundaryShadowTreeRootNode() const;
VisiblePositionTemplate<Strategy> visiblePositionRespectingEditingBoundary(const LayoutPoint& localPoint, Node* targetNode) const;
PositionWithAffinityTemplate<Strategy> positionRespectingEditingBoundary(const LayoutPoint& localPoint, Node* targetNode) const;
bool isValidFor(const Document&) const;
void setWithoutValidation(const PositionTemplate<Strategy>&, const PositionTemplate<Strategy>&);
......
......@@ -2178,7 +2178,7 @@ VisiblePosition visiblePositionForContentsPoint(const IntPoint& contentsPoint, L
frame->document()->layoutViewItem().hitTest(result);
if (Node* node = result.innerNode())
return frame->selection().selection().visiblePositionRespectingEditingBoundary(result.localPoint(), node);
return createVisiblePosition(positionRespectingEditingBoundary(frame->selection().selection().start(), result.localPoint(), node));
return VisiblePosition();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment