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

Unified Diff: third_party/WebKit/Source/core/editing/VisibleUnits.cpp

Issue 2924793002: Refactor CanBe{Back,For}wardCaretPosition() (Closed)
Patch Set: 2017-06-06T17:25:09 Created 3 years, 6 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 | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/core/editing/VisibleUnits.cpp
diff --git a/third_party/WebKit/Source/core/editing/VisibleUnits.cpp b/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
index d4e28c9a326586dbed9f7932c065844061f95356..cc8315794d10cab1d3117ec11aa3ac2dfd509213 100644
--- a/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
+++ b/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
@@ -2036,6 +2036,36 @@ static PositionTemplate<Strategy> MostBackwardCaretPosition(
return last_visible.DeprecatedComputePosition();
}
+// The text continues on the next line only if the last text box is not on this
+// line and none of the boxes on this line have a larger start offset.
+static bool DoesContinueOnNextLine(const LayoutText& text_layout_object,
+ InlineBox* box,
+ unsigned text_offset) {
+ InlineTextBox* const last_text_box = text_layout_object.LastTextBox();
+ DCHECK_NE(box, last_text_box);
+ for (InlineBox* runner = box->NextLeafChild(); runner;
+ runner = runner->NextLeafChild()) {
+ if (runner == last_text_box)
+ return false;
+ if (LineLayoutAPIShim::LayoutObjectFrom(runner->GetLineLayoutItem()) ==
+ text_layout_object &&
+ ToInlineTextBox(runner)->Start() >= text_offset)
+ return false;
+ }
+
+ for (InlineBox* runner = box->PrevLeafChild(); runner;
+ runner = runner->PrevLeafChild()) {
+ if (runner == last_text_box)
+ return false;
+ if (LineLayoutAPIShim::LayoutObjectFrom(runner->GetLineLayoutItem()) ==
+ text_layout_object &&
+ ToInlineTextBox(runner)->Start() >= text_offset)
+ return false;
+ }
+
+ return true;
+}
+
// TODO(editing-dev): This function is just moved out from
// |MostBackwardCaretPosition()|. We should study this function more and
// name it appropriately. See https://trac.webkit.org/changeset/32438/
@@ -2075,40 +2105,7 @@ static bool CanBeBackwardCaretPosition(const LayoutText* text_layout_object,
if (box == last_text_box || text_offset != box->Start() + box->Len() + 1)
continue;
- // TODO(yosin): We should move below code fragment into
- // |DoesContinueOnNextLine()|. Note: |MostForwardCaretPosition()| has
- // same code fragment except for comparison on |text_offset|.
- // Backward: other_box->Start() > text_offset
- // Forward: other_box->Start() >= text_offset
- // The text continues on the next line only if the last text box is not
- // on this line and none of the boxes on this line have a larger start
- // offset.
- bool continues_on_next_line = true;
- InlineBox* other_box = box;
- while (continues_on_next_line) {
- other_box = other_box->NextLeafChild();
- if (!other_box)
- break;
- if (other_box == last_text_box ||
- (LineLayoutAPIShim::LayoutObjectFrom(
- other_box->GetLineLayoutItem()) == text_layout_object &&
- ToInlineTextBox(other_box)->Start() > text_offset))
- continues_on_next_line = false;
- }
-
- other_box = box;
- while (continues_on_next_line) {
- other_box = other_box->PrevLeafChild();
- if (!other_box)
- break;
- if (other_box == last_text_box ||
- (LineLayoutAPIShim::LayoutObjectFrom(
- other_box->GetLineLayoutItem()) == text_layout_object &&
- ToInlineTextBox(other_box)->Start() > text_offset))
- continues_on_next_line = false;
- }
-
- if (continues_on_next_line)
+ if (DoesContinueOnNextLine(*text_layout_object, box, text_offset + 1))
return true;
}
return false;
@@ -2247,40 +2244,7 @@ static bool CanBeForwardCaretPosition(const LayoutText* text_layout_object,
if (box == last_text_box || text_offset != box->Start() + box->Len())
continue;
- // TODO(yosin): We should move below code fragment into
- // |DoesContinueOnNextLine()|. Note: |MostBackwardCaretPosition()| has
- // same code fragment except for comparison on |text_offset|.
- // Backward: other_box->Start() > text_offset
- // Forward: other_box->Start() >= text_offset
- // The text continues on the next line only if the last text box is not
- // on this line and none of the boxes on this line have a larger start
- // offset.
- bool continues_on_next_line = true;
- InlineBox* other_box = box;
- while (continues_on_next_line) {
- other_box = other_box->NextLeafChild();
- if (!other_box)
- break;
- if (other_box == last_text_box ||
- (LineLayoutAPIShim::LayoutObjectFrom(
- other_box->GetLineLayoutItem()) == text_layout_object &&
- ToInlineTextBox(other_box)->Start() >= text_offset))
- continues_on_next_line = false;
- }
-
- other_box = box;
- while (continues_on_next_line) {
- other_box = other_box->PrevLeafChild();
- if (!other_box)
- break;
- if (other_box == last_text_box ||
- (LineLayoutAPIShim::LayoutObjectFrom(
- other_box->GetLineLayoutItem()) == text_layout_object &&
- ToInlineTextBox(other_box)->Start() >= text_offset))
- continues_on_next_line = false;
- }
-
- if (continues_on_next_line)
+ if (DoesContinueOnNextLine(*text_layout_object, box, text_offset))
return true;
}
return false;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698