Commit be46a162 authored by yosin@chromium.org's avatar yosin@chromium.org

Move rootUserSelectAllForNode() to EditingStrategy template class from...

Move rootUserSelectAllForNode() to EditingStrategy template class from PositionAlgorithm template class

This patch moves |rootUserSelectAllForNode()| to |EditingStrategy| template
class from |PositionAlgorithm| template class to simplify |PositionAlgorithm|
class for improving code health, since an implementation of
|rootUserSelectAllForNode()| is independent from |PositionAlgorithm|.

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

Review URL: https://codereview.chromium.org/1287053007

git-svn-id: svn://svn.chromium.org/blink/trunk@200899 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 3be2fd75
......@@ -67,6 +67,29 @@ int EditingAlgorithm<Traversal>::lastOffsetForEditing(const Node* node)
return 1;
}
template <typename Strategy>
Node* EditingAlgorithm<Strategy>::rootUserSelectAllForNode(Node* node)
{
if (!node || !nodeIsUserSelectAll(node))
return nullptr;
Node* parent = Strategy::parent(*node);
if (!parent)
return node;
Node* candidateRoot = node;
while (parent) {
if (!parent->layoutObject()) {
parent = Strategy::parent(*parent);
continue;
}
if (!nodeIsUserSelectAll(parent))
break;
candidateRoot = parent;
parent = Strategy::parent(*candidateRoot);
}
return candidateRoot;
}
template class CORE_TEMPLATE_EXPORT EditingAlgorithm<NodeTraversal>;
template class CORE_TEMPLATE_EXPORT EditingAlgorithm<ComposedTreeTraversal>;
......
......@@ -33,6 +33,7 @@ public:
// Positions. Be sure to call |parentAnchoredEquivalent()| on a Position
// before using it to create a DOM Range, or an exception will be thrown.
static int lastOffsetForEditing(const Node*);
static Node* rootUserSelectAllForNode(Node*);
};
extern template class CORE_EXTERN_TEMPLATE_EXPORT EditingAlgorithm<NodeTraversal>;
......
......@@ -639,7 +639,7 @@ VisiblePosition FrameSelection::nextWordPositionForPlatform(const VisiblePositio
static void adjustPositionForUserSelectAll(VisiblePosition& pos, bool isForward)
{
if (Node* rootUserSelectAll = Position::rootUserSelectAllForNode(pos.deepEquivalent().anchorNode()))
if (Node* rootUserSelectAll = EditingStrategy::rootUserSelectAllForNode(pos.deepEquivalent().anchorNode()))
pos = VisiblePosition(isForward ? positionAfterNode(rootUserSelectAll).downstream(CanCrossEditingBoundary) : positionBeforeNode(rootUserSelectAll).upstream(CanCrossEditingBoundary));
}
......
......@@ -527,29 +527,6 @@ PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::downstream(EditingBound
return mostBackwardCaretPosition(*this, rule);
}
template <typename Strategy>
Node* PositionAlgorithm<Strategy>::rootUserSelectAllForNode(Node* node)
{
if (!node || !nodeIsUserSelectAll(node))
return 0;
Node* parent = Strategy::parent(*node);
if (!parent)
return node;
Node* candidateRoot = node;
while (parent) {
if (!parent->layoutObject()) {
parent = Strategy::parent(*parent);
continue;
}
if (!nodeIsUserSelectAll(parent))
break;
candidateRoot = parent;
parent = Strategy::parent(*candidateRoot);
}
return candidateRoot;
}
template <typename Strategy>
bool PositionAlgorithm<Strategy>::isCandidate() const
{
......
......@@ -192,7 +192,6 @@ public:
InlineBoxPosition computeInlineBoxPosition(TextAffinity) const;
InlineBoxPosition computeInlineBoxPosition(TextAffinity, TextDirection primaryDirection) const;
static Node* rootUserSelectAllForNode(Node*);
static PositionAlgorithm<Strategy> beforeNode(Node* anchorNode);
static PositionAlgorithm<Strategy> afterNode(Node* anchorNode);
static PositionAlgorithm<Strategy> inParentBeforeNode(const Node& anchorNode);
......
......@@ -81,12 +81,12 @@ bool dispatchSelectStart(Node* node)
return node->dispatchEvent(Event::createCancelableBubble(EventTypeNames::selectstart));
}
template <typename Strategy>
template <typename SelectionType>
VisibleSelection expandSelectionToRespectUserSelectAllAlgorithm(Node* targetNode, const VisibleSelection& selection)
{
using PositionType = typename Strategy::PositionType;
using PositionType = typename SelectionType::PositionType;
Node* rootUserSelectAll = PositionType::rootUserSelectAllForNode(targetNode);
Node* rootUserSelectAll = SelectionType::Strategy::rootUserSelectAllForNode(targetNode);
if (!rootUserSelectAll)
return selection;
......@@ -249,8 +249,9 @@ void SelectionController::updateSelectionForMouseDragAlgorithm(const HitTestResu
}
if (RuntimeEnabledFeatures::userSelectAllEnabled()) {
Node* rootUserSelectAllForMousePressNode = Position::rootUserSelectAllForNode(mousePressNode);
if (rootUserSelectAllForMousePressNode && rootUserSelectAllForMousePressNode == Position::rootUserSelectAllForNode(target)) {
// TODO(yosin) Should we use |Strategy::rootUserSelectAllForNode()|?
Node* rootUserSelectAllForMousePressNode = EditingStrategy::rootUserSelectAllForNode(mousePressNode);
if (rootUserSelectAllForMousePressNode && rootUserSelectAllForMousePressNode == EditingStrategy::rootUserSelectAllForNode(target)) {
newSelection.setBase(PositionType::beforeNode(rootUserSelectAllForMousePressNode).upstream(CanCrossEditingBoundary));
newSelection.setExtent(PositionType::afterNode(rootUserSelectAllForMousePressNode).downstream(CanCrossEditingBoundary));
} else {
......@@ -262,7 +263,7 @@ void SelectionController::updateSelectionForMouseDragAlgorithm(const HitTestResu
newSelection.setBase(PositionType::afterNode(rootUserSelectAllForMousePressNode).downstream(CanCrossEditingBoundary));
}
Node* rootUserSelectAllForTarget = Position::rootUserSelectAllForNode(target);
Node* rootUserSelectAllForTarget = EditingStrategy::rootUserSelectAllForNode(target);
if (rootUserSelectAllForTarget && mousePressNode->layoutObject() && Strategy::toPositionType(target->layoutObject()->positionForPoint(hitTestResult.localPoint()).position()).compareTo(Strategy::toPositionType(mousePressNode->layoutObject()->positionForPoint(dragStartPos).position())) < 0)
newSelection.setExtent(PositionType::beforeNode(rootUserSelectAllForTarget).upstream(CanCrossEditingBoundary));
else if (rootUserSelectAllForTarget && mousePressNode->layoutObject())
......
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