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

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

Issue 481683003: Support for Adaptive Handle Orientation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: cleanup Created 5 years, 7 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 #include "base/metrics/histogram_macros.h" 9 #include "base/metrics/histogram_macros.h"
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 response_pending_input_event_(INPUT_EVENT_TYPE_NONE), 52 response_pending_input_event_(INPUT_EVENT_TYPE_NONE),
53 start_orientation_(TouchHandleOrientation::UNDEFINED), 53 start_orientation_(TouchHandleOrientation::UNDEFINED),
54 end_orientation_(TouchHandleOrientation::UNDEFINED), 54 end_orientation_(TouchHandleOrientation::UNDEFINED),
55 is_insertion_active_(false), 55 is_insertion_active_(false),
56 activate_insertion_automatically_(false), 56 activate_insertion_automatically_(false),
57 is_selection_active_(false), 57 is_selection_active_(false),
58 activate_selection_automatically_(false), 58 activate_selection_automatically_(false),
59 selection_empty_(false), 59 selection_empty_(false),
60 selection_editable_(false), 60 selection_editable_(false),
61 temporarily_hidden_(false), 61 temporarily_hidden_(false),
62 viewport_size_changed_(false),
62 selection_handle_dragged_(false) { 63 selection_handle_dragged_(false) {
63 DCHECK(client_); 64 DCHECK(client_);
64 } 65 }
65 66
66 TouchSelectionController::~TouchSelectionController() { 67 TouchSelectionController::~TouchSelectionController() {
67 } 68 }
68 69
70 void TouchSelectionController::OnViewportChanged(
71 const gfx::RectF viewport_rect) {
72 if (viewport_rect_ == viewport_rect)
73 return;
74 viewport_size_changed_ = true;
75 viewport_rect_ = viewport_rect;
76 }
77
69 void TouchSelectionController::OnSelectionBoundsChanged( 78 void TouchSelectionController::OnSelectionBoundsChanged(
70 const SelectionBound& start, 79 const SelectionBound& start,
71 const SelectionBound& end) { 80 const SelectionBound& end) {
72 if (start == start_ && end_ == end) 81 if (start == start_ && end_ == end && !viewport_size_changed_)
73 return; 82 return;
74 83
75 start_ = start; 84 start_ = start;
76 end_ = end; 85 end_ = end;
77 start_orientation_ = ToTouchHandleOrientation(start_.type()); 86 start_orientation_ = ToTouchHandleOrientation(start_.type());
78 end_orientation_ = ToTouchHandleOrientation(end_.type()); 87 end_orientation_ = ToTouchHandleOrientation(end_.type());
88 viewport_size_changed_ = false;
79 89
80 if (!activate_selection_automatically_ && 90 if (!activate_selection_automatically_ &&
81 !activate_insertion_automatically_) { 91 !activate_insertion_automatically_) {
82 DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_); 92 DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_);
83 return; 93 return;
84 } 94 }
85 95
86 // Ensure that |response_pending_input_event_| is cleared after the method 96 // Ensure that |response_pending_input_event_| is cleared after the method
87 // completes, while also making its current value available for the duration 97 // completes, while also making its current value available for the duration
88 // of the call. 98 // of the call.
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 if (!activate_insertion_automatically_) 332 if (!activate_insertion_automatically_)
323 return; 333 return;
324 334
325 const bool was_active = is_insertion_active_; 335 const bool was_active = is_insertion_active_;
326 const gfx::PointF position = GetStartPosition(); 336 const gfx::PointF position = GetStartPosition();
327 if (!is_insertion_active_) 337 if (!is_insertion_active_)
328 ActivateInsertion(); 338 ActivateInsertion();
329 else 339 else
330 client_->OnSelectionEvent(INSERTION_MOVED, position); 340 client_->OnSelectionEvent(INSERTION_MOVED, position);
331 341
342 insertion_handle_->SetViewportRect(viewport_rect_);
343 insertion_handle_->SetFocus(start_.edge_top(), start_.edge_bottom());
jdduke (slow) 2015/05/11 15:40:16 Hmm, shouldn't the visibility update come first?
AviD 2015/05/19 16:26:28 It wouldn't matter much here, as we call updateLay
332 insertion_handle_->SetVisible(GetStartVisible(), 344 insertion_handle_->SetVisible(GetStartVisible(),
333 GetAnimationStyle(was_active)); 345 GetAnimationStyle(was_active));
334 insertion_handle_->SetPosition(position);
335 } 346 }
336 347
337 void TouchSelectionController::OnSelectionChanged() { 348 void TouchSelectionController::OnSelectionChanged() {
338 DeactivateInsertion(); 349 DeactivateInsertion();
339 350
340 if (!activate_selection_automatically_) 351 if (!activate_selection_automatically_)
341 return; 352 return;
342 353
343 const bool was_active = is_selection_active_; 354 const bool was_active = is_selection_active_;
344 ActivateSelection(); 355 ActivateSelection();
345 356
346 const TouchHandle::AnimationStyle animation = GetAnimationStyle(was_active); 357 const TouchHandle::AnimationStyle animation = GetAnimationStyle(was_active);
347 start_selection_handle_->SetVisible(GetStartVisible(), animation); 358 start_selection_handle_->SetVisible(GetStartVisible(), animation);
348 end_selection_handle_->SetVisible(GetEndVisible(), animation); 359 end_selection_handle_->SetVisible(GetEndVisible(), animation);
349
350 start_selection_handle_->SetPosition(GetStartPosition());
jdduke (slow) 2015/05/11 15:40:16 Hmm, I think you need to rebase. We now only condi
AviD 2015/05/19 16:26:28 I will rebase in the next patch.
AviD 2015/05/21 09:23:15 Now that we have conditional calling of ActivateSe
351 end_selection_handle_->SetPosition(GetEndPosition());
352 } 360 }
353 361
354 void TouchSelectionController::ActivateInsertion() { 362 void TouchSelectionController::ActivateInsertion() {
355 DCHECK(!is_selection_active_); 363 DCHECK(!is_selection_active_);
356 364
357 if (!insertion_handle_) 365 if (!insertion_handle_)
358 insertion_handle_.reset( 366 insertion_handle_.reset(
359 new TouchHandle(this, TouchHandleOrientation::CENTER)); 367 new TouchHandle(this, TouchHandleOrientation::CENTER));
360 368
361 if (!is_insertion_active_) { 369 if (!is_insertion_active_) {
(...skipping 12 matching lines...) Expand all
374 client_->OnSelectionEvent(INSERTION_CLEARED, gfx::PointF()); 382 client_->OnSelectionEvent(INSERTION_CLEARED, gfx::PointF());
375 } 383 }
376 384
377 void TouchSelectionController::ActivateSelection() { 385 void TouchSelectionController::ActivateSelection() {
378 DCHECK(!is_insertion_active_); 386 DCHECK(!is_insertion_active_);
379 387
380 if (!start_selection_handle_) { 388 if (!start_selection_handle_) {
381 start_selection_handle_.reset(new TouchHandle(this, start_orientation_)); 389 start_selection_handle_.reset(new TouchHandle(this, start_orientation_));
382 } else { 390 } else {
383 start_selection_handle_->SetEnabled(true); 391 start_selection_handle_->SetEnabled(true);
392 start_selection_handle_->SetFocus(start_.edge_top(), start_.edge_bottom());
393 start_selection_handle_->SetViewportRect(viewport_rect_);
384 start_selection_handle_->SetOrientation(start_orientation_); 394 start_selection_handle_->SetOrientation(start_orientation_);
385 } 395 }
386 396
387 if (!end_selection_handle_) { 397 if (!end_selection_handle_) {
388 end_selection_handle_.reset(new TouchHandle(this, end_orientation_)); 398 end_selection_handle_.reset(new TouchHandle(this, end_orientation_));
389 } else { 399 } else {
390 end_selection_handle_->SetEnabled(true); 400 end_selection_handle_->SetEnabled(true);
401 end_selection_handle_->SetFocus(end_.edge_top(), end_.edge_bottom());
402 end_selection_handle_->SetViewportRect(viewport_rect_);
391 end_selection_handle_->SetOrientation(end_orientation_); 403 end_selection_handle_->SetOrientation(end_orientation_);
392 } 404 }
393 405
394 // As a long press received while a selection is already active may trigger 406 // As a long press received while a selection is already active may trigger
395 // an entirely new selection, notify the client but avoid sending an 407 // an entirely new selection, notify the client but avoid sending an
396 // intervening SELECTION_CLEARED update to avoid unnecessary state changes. 408 // intervening SELECTION_CLEARED update to avoid unnecessary state changes.
397 if (!is_selection_active_ || response_pending_input_event_ == LONG_PRESS) { 409 if (!is_selection_active_ || response_pending_input_event_ == LONG_PRESS) {
398 if (is_selection_active_) { 410 if (is_selection_active_) {
399 // The active selection session finishes with the start of the new one. 411 // The active selection session finishes with the start of the new one.
400 LogSelectionEnd(); 412 LogSelectionEnd();
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; 480 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_;
469 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", 481 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration",
470 duration, 482 duration,
471 base::TimeDelta::FromMilliseconds(500), 483 base::TimeDelta::FromMilliseconds(500),
472 base::TimeDelta::FromSeconds(60), 484 base::TimeDelta::FromSeconds(60),
473 60); 485 60);
474 } 486 }
475 } 487 }
476 488
477 } // namespace ui 489 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698