Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(675)

Unified Diff: Source/core/editing/Position.cpp

Issue 1301643003: Move a member function inRenderedText() out from PositionAlgorithm template class (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-20T14:30:47 Rebase Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/core/editing/Position.h ('k') | Source/core/editing/VisibleUnits.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/editing/Position.cpp
diff --git a/Source/core/editing/Position.cpp b/Source/core/editing/Position.cpp
index 6716f960a70ab8033c29ccc9d94401ea67a8e9c0..7cfed11938bece4112691b9e8151d991f2740c5f 100644
--- a/Source/core/editing/Position.cpp
+++ b/Source/core/editing/Position.cpp
@@ -883,7 +883,7 @@ bool PositionAlgorithm<Strategy>::isCandidate() const
}
if (layoutObject->isText())
- return !nodeIsUserSelectNone(anchorNode()) && inRenderedText();
+ return !nodeIsUserSelectNone(anchorNode()) && inRenderedText(*this);
if (layoutObject->isSVG()) {
// We don't consider SVG elements are contenteditable except for
@@ -912,33 +912,47 @@ bool PositionAlgorithm<Strategy>::isCandidate() const
return false;
}
+// TODO(yosin) We should move |inRenderedText()| to "VisibleUnits.h" for
+// reduce dependency of |LayoutObject| in |Position| class.
template <typename Strategy>
-bool PositionAlgorithm<Strategy>::inRenderedText() const
+static bool inRenderedTextAlgorithm(const PositionAlgorithm<Strategy>& position)
{
- if (isNull() || !anchorNode()->isTextNode())
+ Node* const anchorNode = position.anchorNode();
+ if (!anchorNode || !anchorNode->isTextNode())
return false;
- LayoutObject* layoutObject = anchorNode()->layoutObject();
+ LayoutObject* layoutObject = anchorNode->layoutObject();
if (!layoutObject)
return false;
+ const int offsetInNode = position.computeEditingOffset();
LayoutText* textLayoutObject = toLayoutText(layoutObject);
for (InlineTextBox *box = textLayoutObject->firstTextBox(); box; box = box->nextTextBox()) {
- if (m_offset < static_cast<int>(box->start()) && !textLayoutObject->containsReversedText()) {
+ if (offsetInNode < static_cast<int>(box->start()) && !textLayoutObject->containsReversedText()) {
// The offset we're looking for is before this node
// this means the offset must be in content that is
// not laid out. Return false.
return false;
}
- if (box->containsCaretOffset(m_offset)) {
+ if (box->containsCaretOffset(offsetInNode)) {
// Return false for offsets inside composed characters.
- return m_offset == 0 || m_offset == textLayoutObject->nextOffset(textLayoutObject->previousOffset(m_offset));
+ return offsetInNode == 0 || offsetInNode == textLayoutObject->nextOffset(textLayoutObject->previousOffset(offsetInNode));
}
}
return false;
}
+bool inRenderedText(const Position& position)
+{
+ return inRenderedTextAlgorithm<EditingStrategy>(position);
+}
+
+bool inRenderedText(const PositionInComposedTree& position)
+{
+ return inRenderedTextAlgorithm<EditingInComposedTreeStrategy>(position);
+}
+
bool isRenderedCharacter(const Position& position)
{
if (position.isNull())
« no previous file with comments | « Source/core/editing/Position.h ('k') | Source/core/editing/VisibleUnits.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698