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

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

Issue 2932283002: Introduce IsCaretAtEdgeOfInlineTextBox() to simplify ComputeInlineBoxPosition() (Closed)
Patch Set: 2017-06-13T16:36:07 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 10d7bb2428cb8dcae515df30e6b47cfe308179ee..92e04449d57e489d619a4ce336aaaa50f7b81030 100644
--- a/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
+++ b/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
@@ -755,6 +755,20 @@ static InlineBoxPosition AdjustInlineBoxPositionForTextDirection(InlineBox*,
UnicodeBidi,
TextDirection);
+// Returns true if |caret_offset| is at edge of |box| based on |affinity|.
+// |caret_offset| must be either |box.CaretMinOffset()| or
+// |box.CaretMaxOffset()|.
+static bool IsCaretAtEdgeOfInlineTextBox(int caret_offset,
+ const InlineTextBox& box,
+ TextAffinity affinity) {
+ if (caret_offset == box.CaretMinOffset())
+ return affinity == TextAffinity::kDownstream;
+ DCHECK_EQ(caret_offset, box.CaretMaxOffset());
+ if (affinity == TextAffinity::kUpstream)
+ return true;
+ return box.NextLeafChild() && box.NextLeafChild()->IsLineBreak();
+}
+
template <typename Strategy>
static InlineBoxPosition ComputeInlineBoxPositionTemplate(
const PositionTemplate<Strategy>& position,
@@ -817,12 +831,7 @@ static InlineBoxPosition ComputeInlineBoxPositionTemplate(
if (caret_offset > caret_min_offset && caret_offset < caret_max_offset)
return InlineBoxPosition(box, caret_offset);
- if (((caret_offset == caret_max_offset) ^
- (affinity == TextAffinity::kDownstream)) ||
- ((caret_offset == caret_min_offset) ^
- (affinity == TextAffinity::kUpstream)) ||
- (caret_offset == caret_max_offset && box->NextLeafChild() &&
- box->NextLeafChild()->IsLineBreak())) {
+ if (IsCaretAtEdgeOfInlineTextBox(caret_offset, *box, affinity)) {
inline_box = box;
break;
}
« 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