| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ui/touch_selection/touch_selection_controller_aura.h" |
| 6 |
| 7 #include "ui/aura/client/cursor_client.h" |
| 8 #include "ui/aura/client/screen_position_client.h" |
| 9 #include "ui/aura/env.h" |
| 10 #include "ui/aura/window.h" |
| 11 #include "ui/events/event.h" |
| 12 //#include "ui/events/gesture_detection/gesture_configuration.h" |
| 13 #include "ui/events/gestures/motion_event_aura.h" |
| 14 #include "ui/touch_selection/touch_handle_drawable_aura.h" |
| 15 #include "ui/touch_selection/touch_selection_controller_aura_test_api.h" |
| 16 |
| 17 namespace ui { |
| 18 |
| 19 class TouchSelectionControllerAura::EnvPreTargetHandler : public EventHandler { |
| 20 public: |
| 21 EnvPreTargetHandler(TouchSelectionControllerAura* selection_controller); |
| 22 ~EnvPreTargetHandler() override; |
| 23 |
| 24 private: |
| 25 // EventHandler: |
| 26 void OnKeyEvent(KeyEvent* event) override; |
| 27 void OnMouseEvent(MouseEvent* event) override; |
| 28 void OnScrollEvent(ScrollEvent* event) override; |
| 29 |
| 30 TouchSelectionControllerAura* selection_controller_; |
| 31 }; |
| 32 |
| 33 TouchSelectionControllerAura::EnvPreTargetHandler::EnvPreTargetHandler( |
| 34 TouchSelectionControllerAura* selection_controller) |
| 35 : selection_controller_(selection_controller) { |
| 36 aura::Env::GetInstance()->AddPreTargetHandler(this); |
| 37 } |
| 38 |
| 39 TouchSelectionControllerAura::EnvPreTargetHandler::~EnvPreTargetHandler() { |
| 40 aura::Env::GetInstance()->RemovePreTargetHandler(this); |
| 41 } |
| 42 |
| 43 void TouchSelectionControllerAura::EnvPreTargetHandler::OnKeyEvent( |
| 44 KeyEvent* event) { |
| 45 DCHECK(selection_controller_->is_insertion_active() || |
| 46 selection_controller_->is_selection_active()); |
| 47 |
| 48 selection_controller_->HideAndDisallowShowingAutomatically(); |
| 49 } |
| 50 |
| 51 void TouchSelectionControllerAura::EnvPreTargetHandler::OnMouseEvent( |
| 52 MouseEvent* event) { |
| 53 DCHECK(selection_controller_->is_insertion_active() || |
| 54 selection_controller_->is_selection_active()); |
| 55 aura::client::CursorClient* cursor_client = aura::client::GetCursorClient( |
| 56 selection_controller_->client()->GetNativeView()->GetRootWindow()); |
| 57 if (!cursor_client || cursor_client->IsMouseEventsEnabled()) |
| 58 selection_controller_->HideAndDisallowShowingAutomatically(); |
| 59 } |
| 60 |
| 61 void TouchSelectionControllerAura::EnvPreTargetHandler::OnScrollEvent( |
| 62 ScrollEvent* event) { |
| 63 DCHECK(selection_controller_->is_insertion_active() || |
| 64 selection_controller_->is_selection_active()); |
| 65 |
| 66 selection_controller_->HideAndDisallowShowingAutomatically(); |
| 67 } |
| 68 |
| 69 TouchSelectionControllerAura::TouchSelectionControllerAura( |
| 70 TouchSelectionControllerClient* client, |
| 71 base::TimeDelta tap_timeout, |
| 72 float tap_slop, |
| 73 bool show_on_tap_for_empty_editable) |
| 74 : TouchSelectionControllerImpl(client, |
| 75 tap_timeout, |
| 76 tap_slop, |
| 77 show_on_tap_for_empty_editable), |
| 78 motion_event_(new MotionEventAura), |
| 79 test_api_(nullptr) { |
| 80 DCHECK(client); |
| 81 client->GetNativeView()->AddPreTargetHandler(this); |
| 82 } |
| 83 |
| 84 TouchSelectionControllerAura::~TouchSelectionControllerAura() { |
| 85 client()->GetNativeView()->RemovePreTargetHandler(this); |
| 86 } |
| 87 |
| 88 void TouchSelectionControllerAura::ActivateInsertion() { |
| 89 if (!is_insertion_active()) |
| 90 env_pre_target_handler_.reset(new EnvPreTargetHandler(this)); |
| 91 TouchSelectionControllerImpl::ActivateInsertion(); |
| 92 } |
| 93 |
| 94 void TouchSelectionControllerAura::DeactivateInsertion() { |
| 95 env_pre_target_handler_.reset(); |
| 96 TouchSelectionControllerImpl::DeactivateInsertion(); |
| 97 } |
| 98 |
| 99 void TouchSelectionControllerAura::ActivateSelection() { |
| 100 if (!is_selection_active()) |
| 101 env_pre_target_handler_.reset(new EnvPreTargetHandler(this)); |
| 102 TouchSelectionControllerImpl::ActivateSelection(); |
| 103 } |
| 104 |
| 105 void TouchSelectionControllerAura::DeactivateSelection() { |
| 106 env_pre_target_handler_.reset(); |
| 107 TouchSelectionControllerImpl::DeactivateSelection(); |
| 108 } |
| 109 |
| 110 void TouchSelectionControllerAura::OnTouchEvent(TouchEvent* event) { |
| 111 const int index = motion_event_->FindPointerIndexOfId(event->touch_id()); |
| 112 const bool pointer_id_is_active = index != -1; |
| 113 |
| 114 if (event->type() != ET_TOUCH_PRESSED && !pointer_id_is_active) |
| 115 return; |
| 116 |
| 117 if (event->type() == ET_TOUCH_PRESSED && pointer_id_is_active) |
| 118 motion_event_.reset(new MotionEventAura); |
| 119 |
| 120 motion_event_->OnTouch(*event); |
| 121 if (WillHandleTouchEvent(*motion_event_)) |
| 122 event->SetHandled(); |
| 123 motion_event_->CleanupRemovedTouchPoints(*event); |
| 124 } |
| 125 |
| 126 void TouchSelectionControllerAura::OnGestureEvent(GestureEvent* event) { |
| 127 switch (event->type()) { |
| 128 case ET_GESTURE_LONG_PRESS: |
| 129 OnLongPressEvent(); |
| 130 break; |
| 131 case ET_GESTURE_TAP: |
| 132 if (RectBetweenSelectionBounds(start(), end()).Contains(event->x(), |
| 133 event->y())) { |
| 134 if (!is_insertion_active() && ! is_selection_active()) { |
| 135 AllowShowingFromCurrentSelection(); |
| 136 event->SetHandled(); |
| 137 } else if (!is_selection_editable()) { |
| 138 event->SetHandled(); |
| 139 } |
| 140 } |
| 141 if (!event->handled()) |
| 142 OnTapEvent(); |
| 143 break; |
| 144 default: |
| 145 break; |
| 146 } |
| 147 } |
| 148 |
| 149 } // namespace ui |
| OLD | NEW |