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

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: removed enabling flag Created 5 years, 3 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 25 matching lines...) Expand all
36 } 36 }
37 NOTREACHED() << "Invalid selection bound type: " << type; 37 NOTREACHED() << "Invalid selection bound type: " << type;
38 return TouchHandleOrientation::UNDEFINED; 38 return TouchHandleOrientation::UNDEFINED;
39 } 39 }
40 40
41 } // namespace 41 } // namespace
42 42
43 TouchSelectionController::Config::Config() 43 TouchSelectionController::Config::Config()
44 : max_tap_duration(base::TimeDelta::FromMilliseconds(300)), 44 : max_tap_duration(base::TimeDelta::FromMilliseconds(300)),
45 tap_slop(8), 45 tap_slop(8),
46 enable_adaptive_handle_orientation(false),
46 enable_longpress_drag_selection(false), 47 enable_longpress_drag_selection(false),
47 show_on_tap_for_empty_editable(false) {} 48 show_on_tap_for_empty_editable(false) {}
48 49
49 TouchSelectionController::Config::~Config() { 50 TouchSelectionController::Config::~Config() {
50 } 51 }
51 52
52 TouchSelectionController::TouchSelectionController( 53 TouchSelectionController::TouchSelectionController(
53 TouchSelectionControllerClient* client, 54 TouchSelectionControllerClient* client,
54 const Config& config) 55 const Config& config)
55 : client_(client), 56 : client_(client),
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 137
137 if (start_orientation_ == TouchHandleOrientation::CENTER && 138 if (start_orientation_ == TouchHandleOrientation::CENTER &&
138 selection_editable_) { 139 selection_editable_) {
139 OnInsertionChanged(); 140 OnInsertionChanged();
140 return; 141 return;
141 } 142 }
142 143
143 HideAndDisallowShowingAutomatically(); 144 HideAndDisallowShowingAutomatically();
144 } 145 }
145 146
147 void TouchSelectionController::OnViewportChanged(
148 const gfx::RectF viewport_rect) {
149 // Trigger a force update if the viewport is changed, so that
150 // it triggers a call to change the mirror values if required.
151 if (viewport_rect_ == viewport_rect) {
152 return;
153 }
jdduke (slow) 2015/09/14 15:19:40 Nit: No need for braces on the return line.
AviD 2015/09/14 15:57:40 Done.
154
155 viewport_rect_ = viewport_rect;
156
157 if (active_status_ == INACTIVE)
158 return;
159
160 if (active_status_ == INSERTION_ACTIVE) {
161 DCHECK(insertion_handle_);
162 insertion_handle_->SetViewportRect(viewport_rect);
163 } else if (active_status_ == SELECTION_ACTIVE) {
164 DCHECK(start_selection_handle_);
165 DCHECK(end_selection_handle_);
166 start_selection_handle_->SetViewportRect(viewport_rect);
167 end_selection_handle_->SetViewportRect(viewport_rect);
168 }
169
170 // Update handle layout after setting the new Viewport size.
171 UpdateHandleLayoutIfNecessary();
172 }
173
146 bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) { 174 bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) {
147 if (config_.enable_longpress_drag_selection && 175 if (config_.enable_longpress_drag_selection &&
148 longpress_drag_selector_.WillHandleTouchEvent(event)) { 176 longpress_drag_selector_.WillHandleTouchEvent(event)) {
149 return true; 177 return true;
150 } 178 }
151 179
152 if (active_status_ == INSERTION_ACTIVE) { 180 if (active_status_ == INSERTION_ACTIVE) {
153 DCHECK(insertion_handle_); 181 DCHECK(insertion_handle_);
154 return insertion_handle_->WillHandleTouchEvent(event); 182 return insertion_handle_->WillHandleTouchEvent(event);
155 } 183 }
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 } 402 }
375 403
376 scoped_ptr<TouchHandleDrawable> TouchSelectionController::CreateDrawable() { 404 scoped_ptr<TouchHandleDrawable> TouchSelectionController::CreateDrawable() {
377 return client_->CreateDrawable(); 405 return client_->CreateDrawable();
378 } 406 }
379 407
380 base::TimeDelta TouchSelectionController::GetMaxTapDuration() const { 408 base::TimeDelta TouchSelectionController::GetMaxTapDuration() const {
381 return config_.max_tap_duration; 409 return config_.max_tap_duration;
382 } 410 }
383 411
412 bool TouchSelectionController::IsAdaptiveHandleOrientationEnabled() const {
413 return config_.enable_adaptive_handle_orientation;
414 }
415
384 void TouchSelectionController::OnLongPressDragActiveStateChanged() { 416 void TouchSelectionController::OnLongPressDragActiveStateChanged() {
385 // The handles should remain hidden for the duration of a longpress drag, 417 // The handles should remain hidden for the duration of a longpress drag,
386 // including the time between a longpress and the start of drag motion. 418 // including the time between a longpress and the start of drag motion.
387 RefreshHandleVisibility(); 419 RefreshHandleVisibility();
388 } 420 }
389 421
390 gfx::PointF TouchSelectionController::GetSelectionStart() const { 422 gfx::PointF TouchSelectionController::GetSelectionStart() const {
391 return GetStartPosition(); 423 return GetStartPosition();
392 } 424 }
393 425
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 HideAndDisallowShowingAutomatically(); 465 HideAndDisallowShowingAutomatically();
434 return; 466 return;
435 } 467 }
436 468
437 if (!activate_insertion_automatically_) 469 if (!activate_insertion_automatically_)
438 return; 470 return;
439 471
440 const bool activated = ActivateInsertionIfNecessary(); 472 const bool activated = ActivateInsertionIfNecessary();
441 473
442 const TouchHandle::AnimationStyle animation = GetAnimationStyle(!activated); 474 const TouchHandle::AnimationStyle animation = GetAnimationStyle(!activated);
475 insertion_handle_->SetFocus(start_.edge_top(), start_.edge_bottom());
443 insertion_handle_->SetVisible(GetStartVisible(), animation); 476 insertion_handle_->SetVisible(GetStartVisible(), animation);
444 insertion_handle_->SetPosition(GetStartPosition()); 477
478 UpdateHandleLayoutIfNecessary();
445 479
446 client_->OnSelectionEvent(activated ? INSERTION_HANDLE_SHOWN 480 client_->OnSelectionEvent(activated ? INSERTION_HANDLE_SHOWN
447 : INSERTION_HANDLE_MOVED); 481 : INSERTION_HANDLE_MOVED);
448 } 482 }
449 483
450 void TouchSelectionController::OnSelectionChanged() { 484 void TouchSelectionController::OnSelectionChanged() {
451 DeactivateInsertion(); 485 DeactivateInsertion();
452 486
453 if (!activate_selection_automatically_) 487 if (!activate_selection_automatically_)
454 return; 488 return;
455 489
456 const bool activated = ActivateSelectionIfNecessary(); 490 const bool activated = ActivateSelectionIfNecessary();
457 491
458 const TouchHandle::AnimationStyle animation = GetAnimationStyle(!activated); 492 const TouchHandle::AnimationStyle animation = GetAnimationStyle(!activated);
493
494 start_selection_handle_->SetFocus(start_.edge_top(), start_.edge_bottom());
495 end_selection_handle_->SetFocus(end_.edge_top(), end_.edge_bottom());
496
497 start_selection_handle_->SetOrientation(start_orientation_);
498 end_selection_handle_->SetOrientation(end_orientation_);
499
459 start_selection_handle_->SetVisible(GetStartVisible(), animation); 500 start_selection_handle_->SetVisible(GetStartVisible(), animation);
460 end_selection_handle_->SetVisible(GetEndVisible(), animation); 501 end_selection_handle_->SetVisible(GetEndVisible(), animation);
461 start_selection_handle_->SetPosition(GetStartPosition()); 502
462 end_selection_handle_->SetPosition(GetEndPosition()); 503 UpdateHandleLayoutIfNecessary();
463 504
464 client_->OnSelectionEvent(activated ? SELECTION_HANDLES_SHOWN 505 client_->OnSelectionEvent(activated ? SELECTION_HANDLES_SHOWN
465 : SELECTION_HANDLES_MOVED); 506 : SELECTION_HANDLES_MOVED);
466 } 507 }
467 508
468 bool TouchSelectionController::ActivateInsertionIfNecessary() { 509 bool TouchSelectionController::ActivateInsertionIfNecessary() {
469 DCHECK_NE(SELECTION_ACTIVE, active_status_); 510 DCHECK_NE(SELECTION_ACTIVE, active_status_);
470 511
471 if (!insertion_handle_) { 512 if (!insertion_handle_) {
472 insertion_handle_.reset( 513 insertion_handle_.reset(
473 new TouchHandle(this, TouchHandleOrientation::CENTER)); 514 new TouchHandle(this, TouchHandleOrientation::CENTER, viewport_rect_));
474 } 515 }
475 516
476 if (active_status_ == INACTIVE) { 517 if (active_status_ == INACTIVE) {
477 active_status_ = INSERTION_ACTIVE; 518 active_status_ = INSERTION_ACTIVE;
519 insertion_handle_->SetViewportRect(viewport_rect_);
478 insertion_handle_->SetEnabled(true); 520 insertion_handle_->SetEnabled(true);
479 return true; 521 return true;
480 } 522 }
481 return false; 523 return false;
482 } 524 }
483 525
484 void TouchSelectionController::DeactivateInsertion() { 526 void TouchSelectionController::DeactivateInsertion() {
485 if (active_status_ != INSERTION_ACTIVE) 527 if (active_status_ != INSERTION_ACTIVE)
486 return; 528 return;
487 DCHECK(insertion_handle_); 529 DCHECK(insertion_handle_);
488 active_status_ = INACTIVE; 530 active_status_ = INACTIVE;
489 insertion_handle_->SetEnabled(false); 531 insertion_handle_->SetEnabled(false);
490 client_->OnSelectionEvent(INSERTION_HANDLE_CLEARED); 532 client_->OnSelectionEvent(INSERTION_HANDLE_CLEARED);
491 } 533 }
492 534
493 bool TouchSelectionController::ActivateSelectionIfNecessary() { 535 bool TouchSelectionController::ActivateSelectionIfNecessary() {
494 DCHECK_NE(INSERTION_ACTIVE, active_status_); 536 DCHECK_NE(INSERTION_ACTIVE, active_status_);
495 537
496 if (!start_selection_handle_) { 538 if (!start_selection_handle_) {
497 start_selection_handle_.reset(new TouchHandle(this, start_orientation_)); 539 start_selection_handle_.reset(
540 new TouchHandle(this, start_orientation_, viewport_rect_));
498 } else { 541 } else {
542 start_selection_handle_->SetViewportRect(viewport_rect_);
499 start_selection_handle_->SetEnabled(true); 543 start_selection_handle_->SetEnabled(true);
500 start_selection_handle_->SetOrientation(start_orientation_);
501 } 544 }
502 545
503 if (!end_selection_handle_) { 546 if (!end_selection_handle_) {
504 end_selection_handle_.reset(new TouchHandle(this, end_orientation_)); 547 end_selection_handle_.reset(
548 new TouchHandle(this, end_orientation_, viewport_rect_));
505 } else { 549 } else {
550 end_selection_handle_->SetViewportRect(viewport_rect_);
jdduke (slow) 2015/09/14 15:19:40 Nit: Can we set the viewport after we set enabled
AviD 2015/09/14 15:57:40 Done.
506 end_selection_handle_->SetEnabled(true); 551 end_selection_handle_->SetEnabled(true);
507 end_selection_handle_->SetOrientation(end_orientation_);
508 } 552 }
509 553
510 // As a long press received while a selection is already active may trigger 554 // As a long press received while a selection is already active may trigger
511 // an entirely new selection, notify the client but avoid sending an 555 // an entirely new selection, notify the client but avoid sending an
512 // intervening SELECTION_HANDLES_CLEARED update to avoid unnecessary state 556 // intervening SELECTION_HANDLES_CLEARED update to avoid unnecessary state
513 // changes. 557 // changes.
514 if (active_status_ == INACTIVE || 558 if (active_status_ == INACTIVE ||
515 response_pending_input_event_ == LONG_PRESS) { 559 response_pending_input_event_ == LONG_PRESS) {
516 if (active_status_ == SELECTION_ACTIVE) { 560 if (active_status_ == SELECTION_ACTIVE) {
517 // The active selection session finishes with the start of the new one. 561 // The active selection session finishes with the start of the new one.
(...skipping 26 matching lines...) Expand all
544 // Only force the update if the reported selection is non-empty but still 588 // Only force the update if the reported selection is non-empty but still
545 // considered "inactive", i.e., it wasn't preceded by a user gesture or 589 // considered "inactive", i.e., it wasn't preceded by a user gesture or
546 // the handles have since been explicitly hidden. 590 // the handles have since been explicitly hidden.
547 if (active_status_ == INACTIVE && 591 if (active_status_ == INACTIVE &&
548 start_.type() != SelectionBound::EMPTY && 592 start_.type() != SelectionBound::EMPTY &&
549 end_.type() != SelectionBound::EMPTY) { 593 end_.type() != SelectionBound::EMPTY) {
550 force_next_update_ = true; 594 force_next_update_ = true;
551 } 595 }
552 } 596 }
553 597
598 void TouchSelectionController::UpdateHandleLayoutIfNecessary() {
599 if (active_status_ == INSERTION_ACTIVE) {
600 DCHECK(insertion_handle_);
601 insertion_handle_->UpdateHandleLayout();
602 } else if (active_status_ == SELECTION_ACTIVE) {
603 DCHECK(start_selection_handle_);
604 DCHECK(end_selection_handle_);
605 start_selection_handle_->UpdateHandleLayout();
606 end_selection_handle_->UpdateHandleLayout();
607 }
608 }
609
554 void TouchSelectionController::RefreshHandleVisibility() { 610 void TouchSelectionController::RefreshHandleVisibility() {
555 TouchHandle::AnimationStyle animation_style = GetAnimationStyle(true); 611 TouchHandle::AnimationStyle animation_style = GetAnimationStyle(true);
556 if (active_status_ == SELECTION_ACTIVE) { 612 if (active_status_ == SELECTION_ACTIVE) {
557 start_selection_handle_->SetVisible(GetStartVisible(), animation_style); 613 start_selection_handle_->SetVisible(GetStartVisible(), animation_style);
558 end_selection_handle_->SetVisible(GetEndVisible(), animation_style); 614 end_selection_handle_->SetVisible(GetEndVisible(), animation_style);
559 } 615 }
560 if (active_status_ == INSERTION_ACTIVE) 616 if (active_status_ == INSERTION_ACTIVE)
561 insertion_handle_->SetVisible(GetStartVisible(), animation_style); 617 insertion_handle_->SetVisible(GetStartVisible(), animation_style);
562 } 618 }
563 619
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
599 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_; 655 base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_;
600 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration", 656 UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration",
601 duration, 657 duration,
602 base::TimeDelta::FromMilliseconds(500), 658 base::TimeDelta::FromMilliseconds(500),
603 base::TimeDelta::FromSeconds(60), 659 base::TimeDelta::FromSeconds(60),
604 60); 660 60);
605 } 661 }
606 } 662 }
607 663
608 } // namespace ui 664 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698