| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef ASH_AURA_POINTER_WATCHER_ADAPTER_H_ |
| 6 #define ASH_AURA_POINTER_WATCHER_ADAPTER_H_ |
| 7 |
| 5 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 6 #include "ash/common/pointer_watcher_delegate.h" | |
| 7 #include "base/macros.h" | 9 #include "base/macros.h" |
| 8 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| 9 #include "ui/events/event_handler.h" | 11 #include "ui/events/event_handler.h" |
| 10 | 12 |
| 11 namespace gfx { | 13 namespace gfx { |
| 12 class Point; | 14 class Point; |
| 13 } | 15 } |
| 14 | 16 |
| 15 namespace ui { | 17 namespace ui { |
| 16 class LocatedEvent; | 18 class LocatedEvent; |
| 17 class PointerEvent; | 19 class PointerEvent; |
| 18 } | 20 } |
| 19 | 21 |
| 20 namespace views { | 22 namespace views { |
| 23 class PointerWatcher; |
| 21 class Widget; | 24 class Widget; |
| 22 } | 25 } |
| 23 | 26 |
| 24 namespace ash { | 27 namespace ash { |
| 25 | 28 |
| 26 // Support for PointerWatchers in non-mus ash, implemented with a pre-target | 29 // Support for PointerWatchers in non-mus ash, implemented with a pre-target |
| 27 // EventHandler on the Shell. | 30 // EventHandler on the Shell. |
| 28 class ASH_EXPORT PointerWatcherDelegateAura : public PointerWatcherDelegate, | 31 class ASH_EXPORT PointerWatcherAdapter : public ui::EventHandler { |
| 29 public ui::EventHandler { | |
| 30 public: | 32 public: |
| 31 PointerWatcherDelegateAura(); | 33 PointerWatcherAdapter(); |
| 32 ~PointerWatcherDelegateAura() override; | 34 ~PointerWatcherAdapter() override; |
| 33 | 35 |
| 34 // PointerWatcherDelegate: | 36 // See WmShell::AddPointerWatcher() for details. |
| 35 void AddPointerWatcher(views::PointerWatcher* watcher, | 37 void AddPointerWatcher(views::PointerWatcher* watcher, bool wants_moves); |
| 36 bool wants_moves) override; | 38 void RemovePointerWatcher(views::PointerWatcher* watcher); |
| 37 void RemovePointerWatcher(views::PointerWatcher* watcher) override; | |
| 38 | 39 |
| 39 // ui::EventHandler: | 40 // ui::EventHandler: |
| 40 void OnMouseEvent(ui::MouseEvent* event) override; | 41 void OnMouseEvent(ui::MouseEvent* event) override; |
| 41 void OnTouchEvent(ui::TouchEvent* event) override; | 42 void OnTouchEvent(ui::TouchEvent* event) override; |
| 42 | 43 |
| 43 private: | 44 private: |
| 44 gfx::Point GetLocationInScreen(const ui::LocatedEvent& event) const; | 45 gfx::Point GetLocationInScreen(const ui::LocatedEvent& event) const; |
| 45 views::Widget* GetTargetWidget(const ui::LocatedEvent& event) const; | 46 views::Widget* GetTargetWidget(const ui::LocatedEvent& event) const; |
| 46 | 47 |
| 47 // Calls OnPointerEventObserved() on the appropriate set of watchers as | 48 // Calls OnPointerEventObserved() on the appropriate set of watchers as |
| 48 // determined by the type of event. |original_event| is the original | 49 // determined by the type of event. |original_event| is the original |
| 49 // event supplied to OnMouseEvent()/OnTouchEvent(), |pointer_event| is | 50 // event supplied to OnMouseEvent()/OnTouchEvent(), |pointer_event| is |
| 50 // |original_event| converted to a PointerEvent. | 51 // |original_event| converted to a PointerEvent. |
| 51 void NotifyWatchers(const ui::PointerEvent& pointer_event, | 52 void NotifyWatchers(const ui::PointerEvent& pointer_event, |
| 52 const ui::LocatedEvent& original_event); | 53 const ui::LocatedEvent& original_event); |
| 53 | 54 |
| 54 // The true parameter to ObserverList indicates the list must be empty on | 55 // The true parameter to ObserverList indicates the list must be empty on |
| 55 // destruction. Two sets of observers are maintained, one for observers not | 56 // destruction. Two sets of observers are maintained, one for observers not |
| 56 // needing moves |non_move_watchers_| and |move_watchers_| for those | 57 // needing moves |non_move_watchers_| and |move_watchers_| for those |
| 57 // observers wanting moves too. | 58 // observers wanting moves too. |
| 58 base::ObserverList<views::PointerWatcher, true> non_move_watchers_; | 59 base::ObserverList<views::PointerWatcher, true> non_move_watchers_; |
| 59 base::ObserverList<views::PointerWatcher, true> move_watchers_; | 60 base::ObserverList<views::PointerWatcher, true> move_watchers_; |
| 60 | 61 |
| 61 DISALLOW_COPY_AND_ASSIGN(PointerWatcherDelegateAura); | 62 DISALLOW_COPY_AND_ASSIGN(PointerWatcherAdapter); |
| 62 }; | 63 }; |
| 63 | 64 |
| 64 } // namespace ash | 65 } // namespace ash |
| 66 |
| 67 #endif // ASH_AURA_POINTER_WATCHER_ADAPTER_H_ |
| OLD | NEW |