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

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

Issue 2918783002: Extract InlineBox handling from MostForwardCaretPosition() (Closed)
Patch Set: 2017-06-06T13:19:51 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 674ec43e7e6de1391063bda523020869fc8d9982..df4e00f484b46903e78c470d6b545652393d4290 100644
--- a/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
+++ b/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
@@ -2203,59 +2203,73 @@ PositionTemplate<Strategy> MostForwardCaretPosition(
current_node, layout_object->CaretMinOffset() + text_start_offset);
}
- // Map offset in DOM node to offset in InlineBox.
- DCHECK_GE(current_pos.OffsetInLeafNode(),
- static_cast<int>(text_start_offset));
- const unsigned text_offset =
- current_pos.OffsetInLeafNode() - text_start_offset;
- InlineTextBox* last_text_box = text_layout_object->LastTextBox();
- for (InlineTextBox* box = text_layout_object->FirstTextBox(); box;
- box = box->NextTextBox()) {
- if (text_offset <= box->end()) {
- if (text_offset >= box->Start())
- return current_pos.ComputePosition();
- continue;
- }
-
- if (box == last_text_box || text_offset != box->Start() + box->Len())
- continue;
+ if (CanBeForwardCaretPosition(text_layout_object,
+ current_pos.OffsetInLeafNode())) {
+ return current_pos.ComputePosition();
+ }
+ }
+ }
+ 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.
+// TODO(editing-dev): This function is just moved out from
+// |MostForwardCaretPosition()|. We should study this function more and
+// name it appropriately. See https://trac.webkit.org/changeset/32438/
+// which introduce this.
+static bool CanBeForwardCaretPosition(const LayoutText* text_layout_object,
+ int offset_in_node) {
+ const unsigned text_start_offset = text_layout_object->TextStartOffset();
+ DCHECK_GE(offset_in_node, static_cast<int>(text_start_offset));
+ const unsigned text_offset = offset_in_node - text_start_offset;
+ InlineTextBox* const last_text_box = text_layout_object->LastTextBox();
+ for (InlineTextBox* box = text_layout_object->FirstTextBox(); box;
+ box = box->NextTextBox()) {
+ if (text_offset <= box->end()) {
+ if (text_offset >= box->Start())
+ return true;
+ continue;
+ }
- 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;
- }
+ if (box == last_text_box || text_offset != box->Start() + box->Len())
+ continue;
- 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;
- }
+ // 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;
+ }
- if (continues_on_next_line)
- return current_pos.ComputePosition();
- }
+ 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;
}
- }
- return last_visible.DeprecatedComputePosition();
+ if (continues_on_next_line)
+ return true;
+ }
+ return false;
}
Position MostForwardCaretPosition(const Position& position,
« 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