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

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

Issue 2919503003: Extract InlineBox handling from MostBackwardCaretPosition() (Closed)
Patch Set: 2017-06-06T13:42:15 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..6fb14614dc67bdfe99034630212853e34b5605fa 100644
--- a/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
+++ b/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
@@ -2027,77 +2027,91 @@ static PositionTemplate<Strategy> MostBackwardCaretPosition(
current_node, layout_object->CaretMaxOffset() + 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->Start()) {
- if (text_layout_object->IsTextFragment() &&
- ToLayoutTextFragment(layout_object)
- ->IsRemainingTextLayoutObject()) {
- // |currentPos| is at start of remaining text of
- // |Text| node with :first-letter.
- DCHECK_GE(current_pos.OffsetInLeafNode(), 1);
- LayoutObject* first_letter_layout_object =
- ToLayoutTextFragment(layout_object)
- ->GetFirstLetterPseudoElement()
- ->GetLayoutObject();
- if (first_letter_layout_object &&
- first_letter_layout_object->Style()->Visibility() ==
- EVisibility::kVisible)
- return current_pos.ComputePosition();
- }
- continue;
- }
- if (text_offset <= box->Start() + box->Len()) {
- if (text_offset > box->Start())
- return current_pos.ComputePosition();
- continue;
- }
-
- if (box == last_text_box ||
- text_offset != box->Start() + box->Len() + 1)
- continue;
+ if (CanBeBackwardCaretPosition(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
+// |MostBackwardCaretPosition()|. We should study this function more and
+// name it appropriately. See https://trac.webkit.org/changeset/32438/
+// which introduce this.
+static bool CanBeBackwardCaretPosition(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->Start()) {
+ if (text_layout_object->IsTextFragment() &&
+ ToLayoutTextFragment(text_layout_object)
+ ->IsRemainingTextLayoutObject()) {
+ // |offset_in_node| is at start of remaining text of
+ // |Text| node with :first-letter.
+ DCHECK_GE(offset_in_node, 1);
+ LayoutObject* first_letter_layout_object =
+ ToLayoutTextFragment(text_layout_object)
+ ->GetFirstLetterPseudoElement()
+ ->GetLayoutObject();
+ if (first_letter_layout_object &&
+ first_letter_layout_object->Style()->Visibility() ==
+ EVisibility::kVisible)
+ return true;
+ }
+ continue;
+ }
+ if (text_offset <= box->Start() + box->Len()) {
+ 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() + 1)
+ 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
+ // 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;
}
+
+ if (continues_on_next_line)
+ return true;
}
- return last_visible.DeprecatedComputePosition();
+ return false;
}
Position MostBackwardCaretPosition(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