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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
4 * reserved. 4 * reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 102
103 current_ = nullptr; 103 current_ = nullptr;
104 return *this; 104 return *this;
105 } 105 }
106 106
107 LayoutSelection::LayoutSelection(FrameSelection& frame_selection) 107 LayoutSelection::LayoutSelection(FrameSelection& frame_selection)
108 : frame_selection_(&frame_selection), 108 : frame_selection_(&frame_selection),
109 has_pending_selection_(false), 109 has_pending_selection_(false),
110 paint_range_(SelectionPaintRange()) {} 110 paint_range_(SelectionPaintRange()) {}
111 111
112 static bool ShouldShowBlockCursor(const FrameSelection& frame_selection, 112 enum class SelectionMode {
113 const VisibleSelectionInFlatTree& selection) { 113 kNone,
114 kRange,
115 kBlockCursor,
116 };
117 static SelectionMode ComputeSelectionMode(
yosin_UTC9 2017/07/05 09:32:16 nit: Could you add a blank line to separate |enum|
118 const FrameSelection& frame_selection,
119 const VisibleSelectionInFlatTree& selection) {
120 if (selection.IsRange())
121 return SelectionMode::kRange;
114 if (!frame_selection.ShouldShowBlockCursor()) 122 if (!frame_selection.ShouldShowBlockCursor())
115 return false; 123 return SelectionMode::kNone;
116 if (selection.GetSelectionType() != SelectionType::kCaretSelection) 124 if (IsLogicalEndOfLine(selection.VisibleStart()))
117 return false; 125 return SelectionMode::kNone;
118 if (IsLogicalEndOfLine(selection.VisibleEnd())) 126 return SelectionMode::kBlockCursor;
119 return false;
120 return true;
121 } 127 }
122 128
123 static EphemeralRangeInFlatTree CalcSelection( 129 static EphemeralRangeInFlatTree CalcSelection(
124 const FrameSelection& frame_selection) { 130 const FrameSelection& frame_selection) {
125 const VisibleSelectionInFlatTree& original_selection = 131 const VisibleSelectionInFlatTree& original_selection =
126 frame_selection.ComputeVisibleSelectionInFlatTree(); 132 frame_selection.ComputeVisibleSelectionInFlatTree();
127 133 switch (ComputeSelectionMode(frame_selection, original_selection)) {
128 if (!ShouldShowBlockCursor(frame_selection, original_selection)) 134 case SelectionMode::kNone:
129 return {original_selection.Start(), original_selection.End()}; 135 return {};
130 136 case SelectionMode::kRange:
131 const PositionInFlatTree end_position = NextPositionOf( 137 return {original_selection.Start(), original_selection.End()};
132 original_selection.Start(), PositionMoveType::kGraphemeCluster); 138 case SelectionMode::kBlockCursor: {
133 const VisibleSelectionInFlatTree& block_cursor = CreateVisibleSelection( 139 const PositionInFlatTree end_position = NextPositionOf(
134 SelectionInFlatTree::Builder() 140 original_selection.Start(), PositionMoveType::kGraphemeCluster);
135 .SetBaseAndExtent(original_selection.Start(), end_position) 141 const VisibleSelectionInFlatTree& block_cursor = CreateVisibleSelection(
136 .Build()); 142 SelectionInFlatTree::Builder()
137 return {block_cursor.Start(), block_cursor.End()}; 143 .SetBaseAndExtent(original_selection.Start(), end_position)
144 .Build());
145 return {block_cursor.Start(), block_cursor.End()};
146 }
147 }
148 NOTREACHED();
149 return {};
138 } 150 }
139 151
140 // Objects each have a single selection rect to examine. 152 // Objects each have a single selection rect to examine.
141 using SelectedObjectMap = HashMap<LayoutObject*, SelectionState>; 153 using SelectedObjectMap = HashMap<LayoutObject*, SelectionState>;
142 // Blocks contain selected objects and fill gaps between them, either on the 154 // Blocks contain selected objects and fill gaps between them, either on the
143 // left, right, or in between lines and blocks. 155 // left, right, or in between lines and blocks.
144 // In order to get the visual rect right, we have to examine left, middle, and 156 // In order to get the visual rect right, we have to examine left, middle, and
145 // right rects individually, since otherwise the union of those rects might 157 // right rects individually, since otherwise the union of those rects might
146 // remain the same even when changes have occurred. 158 // remain the same even when changes have occurred.
147 using SelectedBlockMap = HashMap<LayoutBlock*, SelectionState>; 159 using SelectedBlockMap = HashMap<LayoutBlock*, SelectionState>;
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 390
379 runner->SetShouldInvalidateSelection(); 391 runner->SetShouldInvalidateSelection();
380 } 392 }
381 } 393 }
382 394
383 DEFINE_TRACE(LayoutSelection) { 395 DEFINE_TRACE(LayoutSelection) {
384 visitor->Trace(frame_selection_); 396 visitor->Trace(frame_selection_);
385 } 397 }
386 398
387 } // namespace blink 399 } // namespace blink
OLDNEW
« 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