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

Move honorEditingBoundaryAtOr{Before,After}() for VisiblePosition to VisibleUnits.cpp

This patch moves |honorEditingBoundaryAtOr{Before,After}()| for
|VisiblePosition| to "VisibleUnits.cpp" form "VisiblePosition.cpp" to make
"VisiblePosition.cpp" to simpler for improving code health and ease of
templatizing |VisiblePosition| class to introduce composed tree version.

This patch is a preparation of making selection to handle granularity for web
component, http://crrev.com/1277863002

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

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

git-svn-id: svn://svn.chromium.org/blink/trunk@201622 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 4ecc7300
...@@ -63,74 +63,6 @@ VisiblePosition VisiblePosition::createWithoutCanonicalization(const PositionWit ...@@ -63,74 +63,6 @@ VisiblePosition VisiblePosition::createWithoutCanonicalization(const PositionWit
return VisiblePosition(canonicalized); return VisiblePosition(canonicalized);
} }
template <typename Strategy>
PositionWithAffinityTemplate<Strategy> honorEditingBoundaryAtOrBeforeAlgorithm(const PositionWithAffinityTemplate<Strategy>& pos, const PositionAlgorithm<Strategy>& anchor)
{
if (pos.isNull())
return pos;
ContainerNode* highestRoot = highestEditableRoot(anchor);
// Return empty position if pos is not somewhere inside the editable region containing this position
if (highestRoot && !pos.position().anchorNode()->isDescendantOf(highestRoot))
return PositionWithAffinityTemplate<Strategy>();
// Return pos itself if the two are from the very same editable region, or both are non-editable
// FIXME: In the non-editable case, just because the new position is non-editable doesn't mean movement
// to it is allowed. VisibleSelection::adjustForEditableContent has this problem too.
if (highestEditableRoot(pos.position()) == highestRoot)
return pos;
// Return empty position if this position is non-editable, but pos is editable
// FIXME: Move to the previous non-editable region.
if (!highestRoot)
return PositionWithAffinityTemplate<Strategy>();
// Return the last position before pos that is in the same editable region as this position
return lastEditablePositionBeforePositionInRoot(pos.position(), highestRoot);
}
PositionWithAffinity honorEditingBoundaryAtOrBeforeOf(const PositionWithAffinity& pos, const Position& anchor)
{
return honorEditingBoundaryAtOrBeforeAlgorithm(pos, anchor);
}
PositionInComposedTreeWithAffinity honorEditingBoundaryAtOrBeforeOf(const PositionInComposedTreeWithAffinity& pos, const PositionInComposedTree& anchor)
{
return honorEditingBoundaryAtOrBeforeAlgorithm(pos, anchor);
}
VisiblePosition honorEditingBoundaryAtOrBefore(const VisiblePosition& pos, const Position& anchor)
{
return createVisiblePosition(honorEditingBoundaryAtOrBeforeOf(pos.toPositionWithAffinity(), anchor));
}
VisiblePosition honorEditingBoundaryAtOrAfter(const VisiblePosition& pos, const Position& anchor)
{
if (pos.isNull())
return pos;
ContainerNode* highestRoot = highestEditableRoot(anchor);
// Return empty position if pos is not somewhere inside the editable region containing this position
if (highestRoot && !pos.deepEquivalent().anchorNode()->isDescendantOf(highestRoot))
return VisiblePosition();
// Return pos itself if the two are from the very same editable region, or both are non-editable
// FIXME: In the non-editable case, just because the new position is non-editable doesn't mean movement
// to it is allowed. VisibleSelection::adjustForEditableContent has this problem too.
if (highestEditableRoot(pos.deepEquivalent()) == highestRoot)
return pos;
// Return empty position if this position is non-editable, but pos is editable
// FIXME: Move to the next non-editable region.
if (!highestRoot)
return VisiblePosition();
// Return the next position after pos that is in the same editable region as this position
return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(), highestRoot);
}
template<typename Strategy> template<typename Strategy>
static PositionWithAffinityTemplate<Strategy> createVisiblePositionAlgorithm(const PositionAlgorithm<Strategy>& position, TextAffinity affinity) static PositionWithAffinityTemplate<Strategy> createVisiblePositionAlgorithm(const PositionAlgorithm<Strategy>& position, TextAffinity affinity)
{ {
......
...@@ -106,14 +106,6 @@ private: ...@@ -106,14 +106,6 @@ private:
PositionWithAffinity m_positionWithAffinity; PositionWithAffinity m_positionWithAffinity;
}; };
// TODO(yosin) We should move |honorEditingBoundaryAtOr{Before,After} to
// "VisibleUnits.cpp" as static function.
// next() and previous() will increment/decrement by a character cluster.
VisiblePosition honorEditingBoundaryAtOrBefore(const VisiblePosition&, const Position& anchor);
PositionWithAffinity honorEditingBoundaryAtOrBeforeOf(const PositionWithAffinity&, const Position& anchor);
PositionInComposedTreeWithAffinity honorEditingBoundaryAtOrBeforeOf(const PositionInComposedTreeWithAffinity&, const PositionInComposedTree& anchor);
VisiblePosition honorEditingBoundaryAtOrAfter(const VisiblePosition&, const Position& anchor);
CORE_EXPORT VisiblePosition createVisiblePosition(const Position&, TextAffinity = VP_DEFAULT_AFFINITY); CORE_EXPORT VisiblePosition createVisiblePosition(const Position&, TextAffinity = VP_DEFAULT_AFFINITY);
CORE_EXPORT VisiblePosition createVisiblePosition(const PositionWithAffinity&); CORE_EXPORT VisiblePosition createVisiblePosition(const PositionWithAffinity&);
CORE_EXPORT VisiblePosition createVisiblePosition(const PositionInComposedTree&, TextAffinity = VP_DEFAULT_AFFINITY); CORE_EXPORT VisiblePosition createVisiblePosition(const PositionInComposedTree&, TextAffinity = VP_DEFAULT_AFFINITY);
......
...@@ -166,6 +166,84 @@ PositionInComposedTree canonicalPositionOf(const PositionInComposedTree& positio ...@@ -166,6 +166,84 @@ PositionInComposedTree canonicalPositionOf(const PositionInComposedTree& positio
return canonicalPosition(position); return canonicalPosition(position);
} }
template <typename Strategy>
static PositionWithAffinityTemplate<Strategy> honorEditingBoundaryAtOrBeforeAlgorithm(const PositionWithAffinityTemplate<Strategy>& pos, const PositionAlgorithm<Strategy>& anchor)
{
if (pos.isNull())
return pos;
ContainerNode* highestRoot = highestEditableRoot(anchor);
// Return empty position if |pos| is not somewhere inside the editable
// region containing this position
if (highestRoot && !pos.position().anchorNode()->isDescendantOf(highestRoot))
return PositionWithAffinityTemplate<Strategy>();
// Return |pos| itself if the two are from the very same editable region, or
// both are non-editable
// TODO(yosin) In the non-editable case, just because the new position is
// non-editable doesn't mean movement to it is allowed.
// |VisibleSelection::adjustForEditableContent()| has this problem too.
if (highestEditableRoot(pos.position()) == highestRoot)
return pos;
// Return empty position if this position is non-editable, but |pos| is
// editable.
// TODO(yosin) Move to the previous non-editable region.
if (!highestRoot)
return PositionWithAffinityTemplate<Strategy>();
// Return the last position before |pos| that is in the same editable region
// as this position
return lastEditablePositionBeforePositionInRoot(pos.position(), highestRoot);
}
static PositionWithAffinity honorEditingBoundaryAtOrBeforeOf(const PositionWithAffinity& pos, const Position& anchor)
{
return honorEditingBoundaryAtOrBeforeAlgorithm(pos, anchor);
}
static PositionInComposedTreeWithAffinity honorEditingBoundaryAtOrBeforeOf(const PositionInComposedTreeWithAffinity& pos, const PositionInComposedTree& anchor)
{
return honorEditingBoundaryAtOrBeforeAlgorithm(pos, anchor);
}
static VisiblePosition honorEditingBoundaryAtOrBefore(const VisiblePosition& pos, const Position& anchor)
{
return createVisiblePosition(honorEditingBoundaryAtOrBeforeOf(pos.toPositionWithAffinity(), anchor));
}
static VisiblePosition honorEditingBoundaryAtOrAfter(const VisiblePosition& pos, const Position& anchor)
{
if (pos.isNull())
return pos;
ContainerNode* highestRoot = highestEditableRoot(anchor);
// Return empty position if |pos| is not somewhere inside the editable
// region // containing this position
if (highestRoot && !pos.deepEquivalent().anchorNode()->isDescendantOf(highestRoot))
return VisiblePosition();
// Return |pos| itself if the two are from the very same editable region, or
// both are non-editable
// TODO(yosin) In the non-editable case, just because the new position is
// non-editable doesn't mean movement to it is allowed.
// |VisibleSelection::adjustForEditableContent()| has this problem too.
if (highestEditableRoot(pos.deepEquivalent()) == highestRoot)
return pos;
// Return empty position if this position is non-editable, but |pos| is
// editable
// TODO(yosin) Move to the next non-editable region.
if (!highestRoot)
return VisiblePosition();
// Return the next position after |pos| that is in the same editable region
// as this position
return firstEditableVisiblePositionAfterPositionInRoot(pos.deepEquivalent(), highestRoot);
}
static Node* previousLeafWithSameEditability(Node* node, EditableType editableType) static Node* previousLeafWithSameEditability(Node* node, EditableType editableType)
{ {
bool editable = node->hasEditableStyle(editableType); bool editable = node->hasEditableStyle(editableType);
......
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