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 "ash/shell.h" | |
8 #include "components/exo/surface.h" | 7 #include "components/exo/surface.h" |
9 #include "components/exo/touch_delegate.h" | 8 #include "components/exo/touch_delegate.h" |
| 9 #include "components/exo/wm_helper.h" |
10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
11 #include "ui/events/event.h" | 11 #include "ui/events/event.h" |
12 | 12 |
13 namespace exo { | 13 namespace exo { |
14 namespace { | 14 namespace { |
15 | 15 |
16 // Helper function that returns an iterator to the first item in |vector| | 16 // Helper function that returns an iterator to the first item in |vector| |
17 // with |value|. | 17 // with |value|. |
18 template <typename T, typename U> | 18 template <typename T, typename U> |
19 typename T::iterator FindVectorItem(T& vector, U value) { | 19 typename T::iterator FindVectorItem(T& vector, U value) { |
20 return std::find(vector.begin(), vector.end(), value); | 20 return std::find(vector.begin(), vector.end(), value); |
21 } | 21 } |
22 | 22 |
23 // Helper function that returns true if |vector| contains an item with |value|. | 23 // Helper function that returns true if |vector| contains an item with |value|. |
24 template <typename T, typename U> | 24 template <typename T, typename U> |
25 bool VectorContainsItem(T& vector, U value) { | 25 bool VectorContainsItem(T& vector, U value) { |
26 return FindVectorItem(vector, value) != vector.end(); | 26 return FindVectorItem(vector, value) != vector.end(); |
27 } | 27 } |
28 | 28 |
29 } // namespace | 29 } // namespace |
30 | 30 |
31 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
32 // Touch, public: | 32 // Touch, public: |
33 | 33 |
34 Touch::Touch(TouchDelegate* delegate) : delegate_(delegate) { | 34 Touch::Touch(TouchDelegate* delegate) : delegate_(delegate) { |
35 ash::Shell::GetInstance()->AddPreTargetHandler(this); | 35 WMHelper::GetInstance()->AddPreTargetHandler(this); |
36 } | 36 } |
37 | 37 |
38 Touch::~Touch() { | 38 Touch::~Touch() { |
39 delegate_->OnTouchDestroying(this); | 39 delegate_->OnTouchDestroying(this); |
40 if (focus_) | 40 if (focus_) |
41 focus_->RemoveSurfaceObserver(this); | 41 focus_->RemoveSurfaceObserver(this); |
42 ash::Shell::GetInstance()->RemovePreTargetHandler(this); | 42 WMHelper::GetInstance()->RemovePreTargetHandler(this); |
43 } | 43 } |
44 | 44 |
45 //////////////////////////////////////////////////////////////////////////////// | 45 //////////////////////////////////////////////////////////////////////////////// |
46 // ui::EventHandler overrides: | 46 // ui::EventHandler overrides: |
47 | 47 |
48 void Touch::OnTouchEvent(ui::TouchEvent* event) { | 48 void Touch::OnTouchEvent(ui::TouchEvent* event) { |
49 switch (event->type()) { | 49 switch (event->type()) { |
50 case ui::ET_TOUCH_PRESSED: { | 50 case ui::ET_TOUCH_PRESSED: { |
51 // Early out if event doesn't contain a valid target for touch device. | 51 // Early out if event doesn't contain a valid target for touch device. |
52 Surface* target = GetEffectiveTargetForEvent(event); | 52 Surface* target = GetEffectiveTargetForEvent(event); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 Surface* Touch::GetEffectiveTargetForEvent(ui::Event* event) const { | 142 Surface* Touch::GetEffectiveTargetForEvent(ui::Event* event) const { |
143 Surface* target = | 143 Surface* target = |
144 Surface::AsSurface(static_cast<aura::Window*>(event->target())); | 144 Surface::AsSurface(static_cast<aura::Window*>(event->target())); |
145 if (!target) | 145 if (!target) |
146 return nullptr; | 146 return nullptr; |
147 | 147 |
148 return delegate_->CanAcceptTouchEventsForSurface(target) ? target : nullptr; | 148 return delegate_->CanAcceptTouchEventsForSurface(target) ? target : nullptr; |
149 } | 149 } |
150 | 150 |
151 } // namespace exo | 151 } // namespace exo |
OLD | NEW |