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

Side by Side Diff: ui/touch_selection/touch_selection_controller.cc

Issue 698253004: Reland: Implement Aura side of unified touch text selection for contents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed overrides in TouchHandleDrawableAura Created 5 years, 11 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/touch_selection/touch_selection_controller.h" 5 #include "ui/touch_selection/touch_selection_controller.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 9
10 namespace ui { 10 namespace ui {
(...skipping 12 matching lines...) Expand all
23 } 23 }
24 NOTREACHED() << "Invalid selection bound type: " << type; 24 NOTREACHED() << "Invalid selection bound type: " << type;
25 return TOUCH_HANDLE_ORIENTATION_UNDEFINED; 25 return TOUCH_HANDLE_ORIENTATION_UNDEFINED;
26 } 26 }
27 27
28 } // namespace 28 } // namespace
29 29
30 TouchSelectionController::TouchSelectionController( 30 TouchSelectionController::TouchSelectionController(
31 TouchSelectionControllerClient* client, 31 TouchSelectionControllerClient* client,
32 base::TimeDelta tap_timeout, 32 base::TimeDelta tap_timeout,
33 float tap_slop) 33 float tap_slop,
34 bool show_on_tap_for_empty_editable)
34 : client_(client), 35 : client_(client),
35 tap_timeout_(tap_timeout), 36 tap_timeout_(tap_timeout),
36 tap_slop_(tap_slop), 37 tap_slop_(tap_slop),
38 show_on_tap_for_empty_editable_(show_on_tap_for_empty_editable),
37 response_pending_input_event_(INPUT_EVENT_TYPE_NONE), 39 response_pending_input_event_(INPUT_EVENT_TYPE_NONE),
38 start_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), 40 start_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED),
39 end_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), 41 end_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED),
40 is_insertion_active_(false), 42 is_insertion_active_(false),
41 activate_insertion_automatically_(false), 43 activate_insertion_automatically_(false),
42 is_selection_active_(false), 44 is_selection_active_(false),
43 activate_selection_automatically_(false), 45 activate_selection_automatically_(false),
44 selection_empty_(false), 46 selection_empty_(false),
45 selection_editable_(false), 47 selection_editable_(false),
46 temporarily_hidden_(false) { 48 temporarily_hidden_(false) {
47 DCHECK(client_); 49 DCHECK(client_);
48 HideAndDisallowShowingAutomatically();
49 } 50 }
50 51
51 TouchSelectionController::~TouchSelectionController() { 52 TouchSelectionController::~TouchSelectionController() {
52 } 53 }
53 54
54 void TouchSelectionController::OnSelectionBoundsChanged( 55 void TouchSelectionController::OnSelectionBoundsUpdated(
55 const SelectionBound& start, 56 const SelectionBound& start,
56 const SelectionBound& end) { 57 const SelectionBound& end) {
57 if (start == start_ && end_ == end) 58 if (start == start_ && end_ == end)
58 return; 59 return;
59 60
60 start_ = start; 61 start_ = start;
61 end_ = end; 62 end_ = end;
62 start_orientation_ = ToTouchHandleOrientation(start_.type()); 63 start_orientation_ = ToTouchHandleOrientation(start_.type());
63 end_orientation_ = ToTouchHandleOrientation(end_.type()); 64 end_orientation_ = ToTouchHandleOrientation(end_.type());
64 65
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 207
207 if (is_selection_active_) { 208 if (is_selection_active_) {
208 bool needs_animate = start_selection_handle_->Animate(frame_time); 209 bool needs_animate = start_selection_handle_->Animate(frame_time);
209 needs_animate |= end_selection_handle_->Animate(frame_time); 210 needs_animate |= end_selection_handle_->Animate(frame_time);
210 return needs_animate; 211 return needs_animate;
211 } 212 }
212 213
213 return false; 214 return false;
214 } 215 }
215 216
217 void TouchSelectionController::TryActivateSelection() {
jdduke (slow) 2015/01/28 16:35:32 How exactly does this differ from |AllowShowingFro
mohsen 2015/02/22 23:23:09 Oh, I missed |AllowShowingFromCurrentSelection()|
218 if (GetStartPosition() != GetEndPosition()) {
219 SelectionBound start = start_;
220 SelectionBound end = end_;
221 ShowSelectionHandlesAutomatically();
222 OnSelectionBoundsUpdated(start, end);
223 }
224 }
225
216 void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) { 226 void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) {
217 if (&handle == insertion_handle_.get()) { 227 if (&handle == insertion_handle_.get()) {
218 client_->OnSelectionEvent(INSERTION_DRAG_STARTED, handle.position()); 228 client_->OnSelectionEvent(INSERTION_DRAG_STARTED, handle.position());
219 return; 229 return;
220 } 230 }
221 231
222 gfx::PointF base, extent; 232 gfx::PointF base, extent;
223 if (&handle == start_selection_handle_.get()) { 233 if (&handle == start_selection_handle_.get()) {
224 base = end_selection_handle_->position() + GetEndLineOffset(); 234 base = end_selection_handle_->position() + GetEndLineOffset();
225 extent = start_selection_handle_->position() + GetStartLineOffset(); 235 extent = start_selection_handle_->position() + GetStartLineOffset();
(...skipping 18 matching lines...) Expand all
244 : GetEndLineOffset(); 254 : GetEndLineOffset();
245 gfx::PointF line_position = position + line_offset; 255 gfx::PointF line_position = position + line_offset;
246 if (&handle == insertion_handle_.get()) { 256 if (&handle == insertion_handle_.get()) {
247 client_->MoveCaret(line_position); 257 client_->MoveCaret(line_position);
248 } else { 258 } else {
249 client_->MoveRangeSelectionExtent(line_position); 259 client_->MoveRangeSelectionExtent(line_position);
250 } 260 }
251 } 261 }
252 262
253 void TouchSelectionController::OnHandleDragEnd(const TouchHandle& handle) { 263 void TouchSelectionController::OnHandleDragEnd(const TouchHandle& handle) {
254 if (&handle != insertion_handle_.get()) 264 if (&handle == insertion_handle_.get())
265 client_->OnSelectionEvent(INSERTION_DRAG_STOPPED, handle.position());
266 else
255 client_->OnSelectionEvent(SELECTION_DRAG_STOPPED, handle.position()); 267 client_->OnSelectionEvent(SELECTION_DRAG_STOPPED, handle.position());
256 } 268 }
257 269
258 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) { 270 void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) {
259 if (insertion_handle_ && &handle == insertion_handle_.get()) 271 if (insertion_handle_ && &handle == insertion_handle_.get())
260 client_->OnSelectionEvent(INSERTION_TAPPED, handle.position()); 272 client_->OnSelectionEvent(INSERTION_TAPPED, handle.position());
261 } 273 }
262 274
263 void TouchSelectionController::SetNeedsAnimate() { 275 void TouchSelectionController::SetNeedsAnimate() {
264 client_->SetNeedsAnimate(); 276 client_->SetNeedsAnimate();
(...skipping 21 matching lines...) Expand all
286 void TouchSelectionController::ShowSelectionHandlesAutomatically() { 298 void TouchSelectionController::ShowSelectionHandlesAutomatically() {
287 if (activate_selection_automatically_) 299 if (activate_selection_automatically_)
288 return; 300 return;
289 activate_selection_automatically_ = true; 301 activate_selection_automatically_ = true;
290 ResetCachedValuesIfInactive(); 302 ResetCachedValuesIfInactive();
291 } 303 }
292 304
293 void TouchSelectionController::OnInsertionChanged() { 305 void TouchSelectionController::OnInsertionChanged() {
294 DeactivateSelection(); 306 DeactivateSelection();
295 307
296 if (response_pending_input_event_ == TAP && selection_empty_) { 308 if (response_pending_input_event_ == TAP && selection_empty_ &&
309 !show_on_tap_for_empty_editable_) {
297 HideAndDisallowShowingAutomatically(); 310 HideAndDisallowShowingAutomatically();
298 return; 311 return;
299 } 312 }
300 313
301 if (!activate_insertion_automatically_) 314 if (!activate_insertion_automatically_)
302 return; 315 return;
303 316
304 const bool was_active = is_insertion_active_; 317 const bool was_active = is_insertion_active_;
305 const gfx::PointF position = GetStartPosition(); 318 const gfx::PointF position = GetStartPosition();
306 if (!is_insertion_active_) 319 if (!is_insertion_active_)
307 ActivateInsertion(); 320 ActivateInsertion();
308 else 321 else
309 client_->OnSelectionEvent(INSERTION_MOVED, position); 322 client_->OnSelectionEvent(INSERTION_MOVED, position);
310 323
311 insertion_handle_->SetVisible(GetStartVisible(), 324 insertion_handle_->SetVisible(GetStartVisible(),
312 GetAnimationStyle(was_active)); 325 GetAnimationStyle(was_active));
313 insertion_handle_->SetPosition(position); 326 insertion_handle_->SetPosition(position);
314 } 327 }
315 328
316 void TouchSelectionController::OnSelectionChanged() { 329 void TouchSelectionController::OnSelectionChanged() {
317 DeactivateInsertion(); 330 DeactivateInsertion();
318 331
319 if (!activate_selection_automatically_) 332 if (!activate_selection_automatically_) // XXX: needed?
320 return; 333 return;
321 334
322 const bool was_active = is_selection_active_; 335 const bool was_active = is_selection_active_;
323 ActivateSelection(); 336 ActivateSelection();
324 337
325 const TouchHandle::AnimationStyle animation = GetAnimationStyle(was_active); 338 const TouchHandle::AnimationStyle animation = GetAnimationStyle(was_active);
326 start_selection_handle_->SetVisible(GetStartVisible(), animation); 339 start_selection_handle_->SetVisible(GetStartVisible(), animation);
327 end_selection_handle_->SetVisible(GetEndVisible(), animation); 340 end_selection_handle_->SetVisible(GetEndVisible(), animation);
328 341
329 start_selection_handle_->SetPosition(GetStartPosition()); 342 start_selection_handle_->SetPosition(GetStartPosition());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 437 }
425 438
426 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle( 439 TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle(
427 bool was_active) const { 440 bool was_active) const {
428 return was_active && client_->SupportsAnimation() 441 return was_active && client_->SupportsAnimation()
429 ? TouchHandle::ANIMATION_SMOOTH 442 ? TouchHandle::ANIMATION_SMOOTH
430 : TouchHandle::ANIMATION_NONE; 443 : TouchHandle::ANIMATION_NONE;
431 } 444 }
432 445
433 } // namespace ui 446 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698