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

Side by Side Diff: ui/views/selection_controller.cc

Issue 2379993005: Label selection experiment (Closed)
Patch Set: -- Created 4 years, 2 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 | « ui/views/selection_controller.h ('k') | ui/views/style/platform_style.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/selection_controller.h" 5 #include "ui/views/selection_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ui/events/event.h" 9 #include "ui/events/event.h"
10 #include "ui/gfx/render_text.h" 10 #include "ui/gfx/render_text.h"
(...skipping 16 matching lines...) Expand all
27 return handled; 27 return handled;
28 28
29 if (event.IsOnlyLeftMouseButton()) { 29 if (event.IsOnlyLeftMouseButton()) {
30 delegate_->OnBeforeMouseAction(); 30 delegate_->OnBeforeMouseAction();
31 bool selection_changed = false; 31 bool selection_changed = false;
32 delegate_->SetTextBeingDragged(false); 32 delegate_->SetTextBeingDragged(false);
33 switch (aggregated_clicks_) { 33 switch (aggregated_clicks_) {
34 case 0: 34 case 0:
35 // If the click location is within existing selection, it may be a 35 // If the click location is within existing selection, it may be a
36 // potential drag and drop. 36 // potential drag and drop.
37 if (GetRenderText()->IsPointInSelection(event.location())) { 37 if (delegate_->SupportsDrag() &&
38 GetRenderText()->IsPointInSelection(event.location())) {
38 delegate_->SetTextBeingDragged(true); 39 delegate_->SetTextBeingDragged(true);
39 } else { 40 } else {
40 MoveCursorTo(event.location(), event.IsShiftDown()); 41 MoveCursorTo(event.location(), event.IsShiftDown());
41 selection_changed = true; 42 selection_changed = true;
42 } 43 }
43 break; 44 break;
44 case 1: 45 case 1:
45 // Select the word at the click location on a double click. 46 // Select the word at the click location on a double click.
46 SelectWordAt(event.location()); 47 SelectWordAt(event.location());
47 selection_changed = true; 48 selection_changed = true;
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 198 }
198 199
199 gfx::RenderText* SelectionController::GetRenderText() { 200 gfx::RenderText* SelectionController::GetRenderText() {
200 return delegate_->GetRenderTextForSelection(); 201 return delegate_->GetRenderTextForSelection();
201 } 202 }
202 203
203 void SelectionController::SelectThroughLastDragLocation() { 204 void SelectionController::SelectThroughLastDragLocation() {
204 delegate_->OnBeforeMouseAction(); 205 delegate_->OnBeforeMouseAction();
205 206
206 // Todo(karandeepb): See if this can be handled at the RenderText level. 207 // Todo(karandeepb): See if this can be handled at the RenderText level.
207 const bool drags_to_end = PlatformStyle::kTextfieldDragVerticallyDragsToEnd; 208 const bool drags_to_end = PlatformStyle::kTextDragVerticallyDragsToEnd;
208 if (drags_to_end && last_drag_location_.y() < 0) 209 if (drags_to_end && last_drag_location_.y() < 0)
209 SelectTillEdge(gfx::CURSOR_LEFT); 210 SelectTillEdge(gfx::CURSOR_LEFT);
210 else if (drags_to_end && last_drag_location_.y() > delegate_->GetViewHeight()) 211 else if (drags_to_end && last_drag_location_.y() > delegate_->GetViewHeight())
211 SelectTillEdge(gfx::CURSOR_RIGHT); 212 SelectTillEdge(gfx::CURSOR_RIGHT);
212 else 213 else
213 MoveCursorTo(last_drag_location_, true); 214 MoveCursorTo(last_drag_location_, true);
214 215
215 if (aggregated_clicks_ == 1) { 216 if (aggregated_clicks_ == 1) {
216 SelectWord(); 217 SelectWord();
217 // Expand the selection so the initially selected word remains selected. 218 // Expand the selection so the initially selected word remains selected.
218 gfx::Range selection = GetRenderText()->selection(); 219 gfx::Range selection = GetRenderText()->selection();
219 const size_t min = 220 const size_t min =
220 std::min(selection.GetMin(), double_click_word_.GetMin()); 221 std::min(selection.GetMin(), double_click_word_.GetMin());
221 const size_t max = 222 const size_t max =
222 std::max(selection.GetMax(), double_click_word_.GetMax()); 223 std::max(selection.GetMax(), double_click_word_.GetMax());
223 const bool reversed = selection.is_reversed(); 224 const bool reversed = selection.is_reversed();
224 selection.set_start(reversed ? max : min); 225 selection.set_start(reversed ? max : min);
225 selection.set_end(reversed ? min : max); 226 selection.set_end(reversed ? min : max);
226 SelectRange(selection); 227 SelectRange(selection);
227 } 228 }
228 delegate_->OnAfterMouseAction(false, true); 229 delegate_->OnAfterMouseAction(false, true);
229 } 230 }
230 231
231 } // namespace views 232 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/selection_controller.h ('k') | ui/views/style/platform_style.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698