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 2869213002: Move ExpandToParagraphBoundary to VisibleUnits (Closed)
Patch Set: 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
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 a234656ab5f420fdfc89510245cc750322b15ce5..01bbc7bce3b203a20be0edbfc68ef703c755ce39 100644
--- a/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
+++ b/third_party/WebKit/Source/core/editing/VisibleUnits.cpp
@@ -2143,6 +2143,33 @@ VisiblePosition NextParagraphPosition(const VisiblePosition& p, LayoutUnit x) {
return pos;
}
+EphemeralRange ExpandToParagraphBoundary(const EphemeralRange& range) {
+ const VisiblePosition& start = CreateVisiblePosition(range.StartPosition());
+ DCHECK(start.IsNotNull()) << range.StartPosition();
+ const Position& paragraph_start = StartOfParagraph(start).DeepEquivalent();
+ DCHECK(paragraph_start.IsNotNull()) << range.StartPosition();
+
+ const VisiblePosition& end = CreateVisiblePosition(range.EndPosition());
+ DCHECK(end.IsNotNull()) << range.EndPosition();
+ const Position& paragraph_end = EndOfParagraph(end).DeepEquivalent();
+ DCHECK(paragraph_end.IsNotNull()) << range.EndPosition();
+
+ // TODO(xiaochengh): There are some cases (crbug.com/640112) where we get
+ // |paragraphStart > paragraphEnd|, which is the reason we cannot directly
+ // return |EphemeralRange(paragraphStart, paragraphEnd)|. This is not
+ // desired, though. We should do more investigation to ensure that why
+ // |paragraphStart <= paragraphEnd| is violated.
+ const Position& result_start =
+ paragraph_start.IsNotNull() && paragraph_start <= range.StartPosition()
+ ? paragraph_start
+ : range.StartPosition();
+ const Position& result_end =
+ paragraph_end.IsNotNull() && paragraph_end >= range.EndPosition()
+ ? paragraph_end
+ : range.EndPosition();
+ return EphemeralRange(result_start, result_end);
+}
+
// ---------
VisiblePosition StartOfBlock(const VisiblePosition& visible_position,

Powered by Google App Engine
This is Rietveld 408576698