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

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

Issue 2918783002: Extract InlineBox handling from MostForwardCaretPosition() (Closed)
Patch Set: 2017-06-01T18:38:06 Created 3 years, 7 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..afaa409fb90c9a30c6745085cb58e7d4e174ed3f 100644
--- a/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
+++ b/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
@@ -2822,59 +2822,66 @@ 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 (IsOffsetRenderedForForward(text_layout_object,
+ current_pos.OffsetInLeafNode())) {
+ return current_pos.ComputePosition();
+ }
+ }
+ }
+ return last_visible.DeprecatedComputePosition();
+}
- if (box == last_text_box || text_offset != box->Start() + box->Len())
- continue;
+// Returns true if |offset| is rendered text of |layout_text_object|
Xiaocheng 2017/06/01 22:19:47 The purpose of the function isn't clear. An offse
yosin_UTC9 2017/06/05 09:12:15 Oops, sorry for confusion. |offset| should be |off
+static bool IsOffsetRenderedForForward(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;
Xiaocheng 2017/06/01 22:19:48 It returns true here if an adjacent character at e
yosin_UTC9 2017/06/05 09:12:15 My interpretation is that if |text_offset| is in |
+ continue;
+ }
- // 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.
+ if (box == last_text_box || text_offset != box->Start() + box->Len())
+ 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;
- }
+ // The text continues on the next line only if the last text box is not
Xiaocheng 2017/06/01 22:19:48 nit: We can save one line here.
yosin_UTC9 2017/06/05 09:12:15 Done.
+ // on this line and none of the boxes on this line have a larger start
+ // offset.
- 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;
- }
+ 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;
Xiaocheng 2017/06/01 22:19:47 I haven't understood in what situation |continues_
yosin_UTC9 2017/06/05 09:12:15 It seems most of case, |continues_on_next_line| re
+ }
+ 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