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

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

Issue 2413223003: Views:: Make Labels support text selection. (Closed)
Patch Set: -- Created 4 years, 1 month 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
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 14 matching lines...) Expand all
25 bool SelectionController::OnMousePressed(const ui::MouseEvent& event, 25 bool SelectionController::OnMousePressed(const ui::MouseEvent& event,
26 bool handled) { 26 bool handled) {
27 gfx::RenderText* render_text = GetRenderText(); 27 gfx::RenderText* render_text = GetRenderText();
28 DCHECK(render_text); 28 DCHECK(render_text);
29 29
30 TrackMouseClicks(event); 30 TrackMouseClicks(event);
31 if (handled) 31 if (handled)
32 return true; 32 return true;
33 33
34 if (event.IsOnlyLeftMouseButton()) { 34 if (event.IsOnlyLeftMouseButton()) {
35 delegate_->SetTextBeingDragged(false); 35 if (delegate_->SupportsDrag())
msw 2016/10/28 06:30:26 Is this just disabling something that otherwise wo
karandeepb 2016/11/01 11:06:25 To support dragging selected text, Labels would ne
36 delegate_->SetTextBeingDragged(false);
37
36 switch (aggregated_clicks_) { 38 switch (aggregated_clicks_) {
37 case 0: 39 case 0:
38 // If the click location is within an existing selection, it may be a 40 // If the click location is within an existing selection, it may be a
39 // potential drag and drop. 41 // potential drag and drop.
40 if (render_text->IsPointInSelection(event.location())) { 42 if (delegate_->SupportsDrag() &&
43 render_text->IsPointInSelection(event.location())) {
41 delegate_->SetTextBeingDragged(true); 44 delegate_->SetTextBeingDragged(true);
42 } else { 45 } else {
43 delegate_->OnBeforePointerAction(); 46 delegate_->OnBeforePointerAction();
44 const bool selection_changed = 47 const bool selection_changed =
45 render_text->MoveCursorTo(event.location(), event.IsShiftDown()); 48 render_text->MoveCursorTo(event.location(), event.IsShiftDown());
46 delegate_->OnAfterPointerAction(false, selection_changed); 49 delegate_->OnAfterPointerAction(false, selection_changed);
47 } 50 }
48 break; 51 break;
49 case 1: 52 case 1:
50 // Select the word at the click location on a double click. 53 // Select the word at the click location on a double click.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 123
121 drag_selection_timer_.Stop(); 124 drag_selection_timer_.Stop();
122 125
123 // Cancel suspected drag initiations, the user was clicking in the selection. 126 // Cancel suspected drag initiations, the user was clicking in the selection.
124 if (delegate_->HasTextBeingDragged()) { 127 if (delegate_->HasTextBeingDragged()) {
125 delegate_->OnBeforePointerAction(); 128 delegate_->OnBeforePointerAction();
126 const bool selection_changed = 129 const bool selection_changed =
127 render_text->MoveCursorTo(event.location(), false); 130 render_text->MoveCursorTo(event.location(), false);
128 delegate_->OnAfterPointerAction(false, selection_changed); 131 delegate_->OnAfterPointerAction(false, selection_changed);
129 } 132 }
130 delegate_->SetTextBeingDragged(false); 133
134 if (delegate_->SupportsDrag())
135 delegate_->SetTextBeingDragged(false);
131 136
132 if (handles_selection_clipboard_ && !render_text->selection().is_empty()) 137 if (handles_selection_clipboard_ && !render_text->selection().is_empty())
133 delegate_->UpdateSelectionClipboard(); 138 delegate_->UpdateSelectionClipboard();
134 } 139 }
135 140
136 void SelectionController::OnMouseCaptureLost() { 141 void SelectionController::OnMouseCaptureLost() {
137 gfx::RenderText* render_text = GetRenderText(); 142 gfx::RenderText* render_text = GetRenderText();
138 DCHECK(render_text); 143 DCHECK(render_text);
139 144
140 drag_selection_timer_.Stop(); 145 drag_selection_timer_.Stop();
(...skipping 24 matching lines...) Expand all
165 return delegate_->GetRenderTextForSelectionController(); 170 return delegate_->GetRenderTextForSelectionController();
166 } 171 }
167 172
168 void SelectionController::SelectThroughLastDragLocation() { 173 void SelectionController::SelectThroughLastDragLocation() {
169 gfx::RenderText* render_text = GetRenderText(); 174 gfx::RenderText* render_text = GetRenderText();
170 DCHECK(render_text); 175 DCHECK(render_text);
171 176
172 delegate_->OnBeforePointerAction(); 177 delegate_->OnBeforePointerAction();
173 178
174 // TODO(karandeepb): See if this can be handled at the RenderText level. 179 // TODO(karandeepb): See if this can be handled at the RenderText level.
175 const bool drags_to_end = PlatformStyle::kTextfieldDragVerticallyDragsToEnd; 180 const bool drags_to_end = PlatformStyle::kTextDragVerticallyDragsToEnd;
176 if (drags_to_end && last_drag_location_.y() < 0) { 181 if (drags_to_end && last_drag_location_.y() < 0) {
177 render_text->MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT, 182 render_text->MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_LEFT,
178 gfx::SELECTION_RETAIN); 183 gfx::SELECTION_RETAIN);
179 } else if (drags_to_end && 184 } else if (drags_to_end &&
180 last_drag_location_.y() > delegate_->GetViewHeight()) { 185 last_drag_location_.y() > delegate_->GetViewHeight()) {
181 render_text->MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT, 186 render_text->MoveCursor(gfx::LINE_BREAK, gfx::CURSOR_RIGHT,
182 gfx::SELECTION_RETAIN); 187 gfx::SELECTION_RETAIN);
183 } else { 188 } else {
184 render_text->MoveCursorTo(last_drag_location_, true); 189 render_text->MoveCursorTo(last_drag_location_, true);
185 } 190 }
186 191
187 if (aggregated_clicks_ == 1) { 192 if (aggregated_clicks_ == 1) {
188 render_text->SelectWord(); 193 render_text->SelectWord();
189 // Expand the selection so the initially selected word remains selected. 194 // Expand the selection so the initially selected word remains selected.
190 gfx::Range selection = render_text->selection(); 195 gfx::Range selection = render_text->selection();
191 const size_t min = 196 const size_t min =
192 std::min(selection.GetMin(), double_click_word_.GetMin()); 197 std::min(selection.GetMin(), double_click_word_.GetMin());
193 const size_t max = 198 const size_t max =
194 std::max(selection.GetMax(), double_click_word_.GetMax()); 199 std::max(selection.GetMax(), double_click_word_.GetMax());
195 const bool reversed = selection.is_reversed(); 200 const bool reversed = selection.is_reversed();
196 selection.set_start(reversed ? max : min); 201 selection.set_start(reversed ? max : min);
197 selection.set_end(reversed ? min : max); 202 selection.set_end(reversed ? min : max);
198 render_text->SelectRange(selection); 203 render_text->SelectRange(selection);
199 } 204 }
200 delegate_->OnAfterPointerAction(false, true); 205 delegate_->OnAfterPointerAction(false, true);
201 } 206 }
202 207
203 } // namespace views 208 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698