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

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

Issue 2918783002: Extract InlineBox handling from MostForwardCaretPosition() (Closed)
Patch Set: 2017-06-05T18:17:50 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 3e2484f8e54e686ead2e863588adec4cfa121e51..51f879e050b88c0bc3d281dd12ae2a746788a42e 100644
--- a/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
+++ b/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
@@ -2822,59 +2822,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 (CanForwardCaretPosition(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 CanForwardCaretPosition(const LayoutText* text_layout_object,
Xiaocheng 2017/06/05 19:35:53 nit: |CanBeForwardCaretPosition| seems a better na
yosin_UTC9 2017/06/06 04:21:14 Done. Thanks for providing good name.
+ 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: |MostForwardCaretPosition()| has
Xiaocheng 2017/06/05 19:35:53 nit: s/Forward/Backward/
yosin_UTC9 2017/06/06 04:21:14 Done. Thanks for catching this.
+ // 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