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

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

Issue 2972773002: Introduce ComputeSelectionMode in LayoutSelection (Closed)
Patch Set: Created 3 years, 5 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/LayoutSelection.cpp
diff --git a/third_party/WebKit/Source/core/editing/LayoutSelection.cpp b/third_party/WebKit/Source/core/editing/LayoutSelection.cpp
index 633bfb729e545e86325248c9d3d1a440f351ec2e..bde8150398df160f23b3ab508de9e8e66f74e268 100644
--- a/third_party/WebKit/Source/core/editing/LayoutSelection.cpp
+++ b/third_party/WebKit/Source/core/editing/LayoutSelection.cpp
@@ -109,32 +109,44 @@ LayoutSelection::LayoutSelection(FrameSelection& frame_selection)
has_pending_selection_(false),
paint_range_(SelectionPaintRange()) {}
-static bool ShouldShowBlockCursor(const FrameSelection& frame_selection,
- const VisibleSelectionInFlatTree& selection) {
+enum class SelectionMode {
+ kNone,
+ kRange,
+ kBlockCursor,
+};
+static SelectionMode ComputeSelectionMode(
yosin_UTC9 2017/07/05 09:32:16 nit: Could you add a blank line to separate |enum|
+ const FrameSelection& frame_selection,
+ const VisibleSelectionInFlatTree& selection) {
+ if (selection.IsRange())
+ return SelectionMode::kRange;
if (!frame_selection.ShouldShowBlockCursor())
- return false;
- if (selection.GetSelectionType() != SelectionType::kCaretSelection)
- return false;
- if (IsLogicalEndOfLine(selection.VisibleEnd()))
- return false;
- return true;
+ return SelectionMode::kNone;
+ if (IsLogicalEndOfLine(selection.VisibleStart()))
+ return SelectionMode::kNone;
+ return SelectionMode::kBlockCursor;
}
static EphemeralRangeInFlatTree CalcSelection(
const FrameSelection& frame_selection) {
const VisibleSelectionInFlatTree& original_selection =
frame_selection.ComputeVisibleSelectionInFlatTree();
-
- if (!ShouldShowBlockCursor(frame_selection, original_selection))
- return {original_selection.Start(), original_selection.End()};
-
- const PositionInFlatTree end_position = NextPositionOf(
- original_selection.Start(), PositionMoveType::kGraphemeCluster);
- const VisibleSelectionInFlatTree& block_cursor = CreateVisibleSelection(
- SelectionInFlatTree::Builder()
- .SetBaseAndExtent(original_selection.Start(), end_position)
- .Build());
- return {block_cursor.Start(), block_cursor.End()};
+ switch (ComputeSelectionMode(frame_selection, original_selection)) {
+ case SelectionMode::kNone:
+ return {};
+ case SelectionMode::kRange:
+ return {original_selection.Start(), original_selection.End()};
+ case SelectionMode::kBlockCursor: {
+ const PositionInFlatTree end_position = NextPositionOf(
+ original_selection.Start(), PositionMoveType::kGraphemeCluster);
+ const VisibleSelectionInFlatTree& block_cursor = CreateVisibleSelection(
+ SelectionInFlatTree::Builder()
+ .SetBaseAndExtent(original_selection.Start(), end_position)
+ .Build());
+ return {block_cursor.Start(), block_cursor.End()};
+ }
+ }
+ NOTREACHED();
+ return {};
}
// Objects each have a single selection rect to examine.
« 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