| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 "components/exo/touch.h" | 5 #include "components/exo/touch.h" |
| 6 | 6 |
| 7 #include "components/exo/surface.h" | 7 #include "components/exo/surface.h" |
| 8 #include "components/exo/touch_delegate.h" | 8 #include "components/exo/touch_delegate.h" |
| 9 #include "components/exo/touch_stylus_delegate.h" | 9 #include "components/exo/touch_stylus_delegate.h" |
| 10 #include "components/exo/wm_helper.h" | 10 #include "components/exo/wm_helper.h" |
| 11 #include "ui/aura/window.h" | 11 #include "ui/aura/window.h" |
| 12 #include "ui/events/event.h" | 12 #include "ui/events/event.h" |
| 13 | 13 |
| 14 namespace exo { | 14 namespace exo { |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 // Helper function that returns an iterator to the first item in |vector| | 17 // Helper function that returns an iterator to the first item in |vector| |
| 18 // with |value|. | 18 // with |value|. |
| 19 template <typename T, typename U> | 19 template <typename T, typename U> |
| 20 typename T::iterator FindVectorItem(T& vector, U value) { | 20 typename T::iterator FindVectorItem(T& vector, U value) { |
| 21 return std::find(vector.begin(), vector.end(), value); | 21 return std::find(vector.begin(), vector.end(), value); |
| 22 } | 22 } |
| 23 | 23 |
| 24 // Helper function that returns true if |vector| contains an item with |value|. | 24 // Helper function that returns true if |vector| contains an item with |value|. |
| 25 template <typename T, typename U> | 25 template <typename T, typename U> |
| 26 bool VectorContainsItem(T& vector, U value) { | 26 bool VectorContainsItem(T& vector, U value) { |
| 27 return FindVectorItem(vector, value) != vector.end(); | 27 return FindVectorItem(vector, value) != vector.end(); |
| 28 } | 28 } |
| 29 | 29 |
| 30 gfx::PointF EventLocationInWindow(ui::TouchEvent* event, aura::Window* window) { |
| 31 ui::Layer* root = window->GetRootWindow()->layer(); |
| 32 ui::Layer* target = window->layer(); |
| 33 |
| 34 gfx::Transform transform; |
| 35 target->GetTargetTransformRelativeTo(root, &transform); |
| 36 auto point = gfx::Point3F(event->root_location_f()); |
| 37 transform.TransformPointReverse(&point); |
| 38 return point.AsPointF(); |
| 39 } |
| 40 |
| 30 } // namespace | 41 } // namespace |
| 31 | 42 |
| 32 //////////////////////////////////////////////////////////////////////////////// | 43 //////////////////////////////////////////////////////////////////////////////// |
| 33 // Touch, public: | 44 // Touch, public: |
| 34 | 45 |
| 35 Touch::Touch(TouchDelegate* delegate) : delegate_(delegate) { | 46 Touch::Touch(TouchDelegate* delegate) : delegate_(delegate) { |
| 36 WMHelper::GetInstance()->AddPreTargetHandler(this); | 47 WMHelper::GetInstance()->AddPreTargetHandler(this); |
| 37 } | 48 } |
| 38 | 49 |
| 39 Touch::~Touch() { | 50 Touch::~Touch() { |
| (...skipping 30 matching lines...) Expand all Loading... |
| 70 DCHECK(!focus_); | 81 DCHECK(!focus_); |
| 71 focus_ = target; | 82 focus_ = target; |
| 72 focus_->AddSurfaceObserver(this); | 83 focus_->AddSurfaceObserver(this); |
| 73 } | 84 } |
| 74 | 85 |
| 75 DCHECK(!VectorContainsItem(touch_points_, event->touch_id())); | 86 DCHECK(!VectorContainsItem(touch_points_, event->touch_id())); |
| 76 touch_points_.push_back(event->touch_id()); | 87 touch_points_.push_back(event->touch_id()); |
| 77 | 88 |
| 78 // Convert location to focus surface coordinate space. | 89 // Convert location to focus surface coordinate space. |
| 79 DCHECK(focus_); | 90 DCHECK(focus_); |
| 80 gfx::Point location = event->location(); | 91 gfx::PointF location = EventLocationInWindow(event, focus_->window()); |
| 81 aura::Window::ConvertPointToTarget(target->window(), focus_->window(), | |
| 82 &location); | |
| 83 | 92 |
| 84 // Generate a touch down event for the focus surface. Note that this can | 93 // Generate a touch down event for the focus surface. Note that this can |
| 85 // be different from the target surface. | 94 // be different from the target surface. |
| 86 delegate_->OnTouchDown(focus_, event->time_stamp(), event->touch_id(), | 95 delegate_->OnTouchDown(focus_, event->time_stamp(), event->touch_id(), |
| 87 location); | 96 location); |
| 88 if (stylus_delegate_ && | 97 if (stylus_delegate_ && |
| 89 event->pointer_details().pointer_type != | 98 event->pointer_details().pointer_type != |
| 90 ui::EventPointerType::POINTER_TYPE_TOUCH) { | 99 ui::EventPointerType::POINTER_TYPE_TOUCH) { |
| 91 stylus_delegate_->OnTouchTool(event->touch_id(), | 100 stylus_delegate_->OnTouchTool(event->touch_id(), |
| 92 event->pointer_details().pointer_type); | 101 event->pointer_details().pointer_type); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 108 | 117 |
| 109 delegate_->OnTouchUp(event->time_stamp(), event->touch_id()); | 118 delegate_->OnTouchUp(event->time_stamp(), event->touch_id()); |
| 110 } break; | 119 } break; |
| 111 case ui::ET_TOUCH_MOVED: { | 120 case ui::ET_TOUCH_MOVED: { |
| 112 auto it = FindVectorItem(touch_points_, event->touch_id()); | 121 auto it = FindVectorItem(touch_points_, event->touch_id()); |
| 113 if (it == touch_points_.end()) | 122 if (it == touch_points_.end()) |
| 114 return; | 123 return; |
| 115 | 124 |
| 116 DCHECK(focus_); | 125 DCHECK(focus_); |
| 117 // Convert location to focus surface coordinate space. | 126 // Convert location to focus surface coordinate space. |
| 118 gfx::Point location = event->location(); | 127 gfx::PointF location = EventLocationInWindow(event, focus_->window()); |
| 119 aura::Window::ConvertPointToTarget( | |
| 120 static_cast<aura::Window*>(event->target()), focus_->window(), | |
| 121 &location); | |
| 122 | |
| 123 delegate_->OnTouchMotion(event->time_stamp(), event->touch_id(), | 128 delegate_->OnTouchMotion(event->time_stamp(), event->touch_id(), |
| 124 location); | 129 location); |
| 125 send_details = true; | 130 send_details = true; |
| 126 } break; | 131 } break; |
| 127 case ui::ET_TOUCH_CANCELLED: { | 132 case ui::ET_TOUCH_CANCELLED: { |
| 128 auto it = FindVectorItem(touch_points_, event->touch_id()); | 133 auto it = FindVectorItem(touch_points_, event->touch_id()); |
| 129 if (it == touch_points_.end()) | 134 if (it == touch_points_.end()) |
| 130 return; | 135 return; |
| 131 | 136 |
| 132 DCHECK(focus_); | 137 DCHECK(focus_); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 Surface* Touch::GetEffectiveTargetForEvent(ui::Event* event) const { | 189 Surface* Touch::GetEffectiveTargetForEvent(ui::Event* event) const { |
| 185 Surface* target = | 190 Surface* target = |
| 186 Surface::AsSurface(static_cast<aura::Window*>(event->target())); | 191 Surface::AsSurface(static_cast<aura::Window*>(event->target())); |
| 187 if (!target) | 192 if (!target) |
| 188 return nullptr; | 193 return nullptr; |
| 189 | 194 |
| 190 return delegate_->CanAcceptTouchEventsForSurface(target) ? target : nullptr; | 195 return delegate_->CanAcceptTouchEventsForSurface(target) ? target : nullptr; |
| 191 } | 196 } |
| 192 | 197 |
| 193 } // namespace exo | 198 } // namespace exo |
| OLD | NEW |