| 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 UI_VIEWS_MUS_POINTER_WATCHER_EVENT_ROUTER2_H_ | 5 #ifndef UI_VIEWS_MUS_POINTER_WATCHER_EVENT_ROUTER_H_ |
| 6 #define UI_VIEWS_MUS_POINTER_WATCHER_EVENT_ROUTER2_H_ | 6 #define UI_VIEWS_MUS_POINTER_WATCHER_EVENT_ROUTER_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
| 11 #include "ui/aura/client/capture_client_observer.h" | 11 #include "ui/aura/client/capture_client_observer.h" |
| 12 #include "ui/aura/mus/window_tree_client_observer.h" | 12 #include "ui/aura/mus/window_tree_client_observer.h" |
| 13 #include "ui/views/mus/mus_export.h" | 13 #include "ui/views/mus/mus_export.h" |
| 14 | 14 |
| 15 namespace aura { | 15 namespace aura { |
| 16 class WindowTreeClient; | 16 class WindowTreeClient; |
| 17 } | 17 } |
| 18 | 18 |
| 19 namespace ui { | 19 namespace ui { |
| 20 class PointerEvent; | 20 class PointerEvent; |
| 21 } | 21 } |
| 22 | 22 |
| 23 namespace views { | 23 namespace views { |
| 24 | 24 |
| 25 class PointerWatcher; | 25 class PointerWatcher; |
| 26 class PointerWatcherEventRouter2Test; | 26 class PointerWatcherEventRouterTest; |
| 27 | 27 |
| 28 // PointerWatcherEventRouter2 is responsible for maintaining the list of | 28 // PointerWatcherEventRouter is responsible for maintaining the list of |
| 29 // PointerWatchers and notifying appropriately. It is expected the owner of | 29 // PointerWatchers and notifying appropriately. It is expected the owner of |
| 30 // PointerWatcherEventRouter2 is a WindowTreeClientDelegate and calls | 30 // PointerWatcherEventRouter is a WindowTreeClientDelegate and calls |
| 31 // OnPointerEventObserved(). | 31 // OnPointerEventObserved(). |
| 32 // TODO(sky): Nuke existing PointerWatcherEventRouter and rename this. | 32 class VIEWS_MUS_EXPORT PointerWatcherEventRouter |
| 33 class VIEWS_MUS_EXPORT PointerWatcherEventRouter2 | |
| 34 : public aura::WindowTreeClientObserver, | 33 : public aura::WindowTreeClientObserver, |
| 35 public aura::client::CaptureClientObserver { | 34 public aura::client::CaptureClientObserver { |
| 36 public: | 35 public: |
| 37 // Public solely for tests. | 36 // Public solely for tests. |
| 38 enum EventTypes { | 37 enum EventTypes { |
| 39 // No PointerWatchers have been added. | 38 // No PointerWatchers have been added. |
| 40 NONE, | 39 NONE, |
| 41 | 40 |
| 42 // Used when the only PointerWatchers added do not want moves. | 41 // Used when the only PointerWatchers added do not want moves. |
| 43 NON_MOVE_EVENTS, | 42 NON_MOVE_EVENTS, |
| 44 | 43 |
| 45 // Used when at least one PointerWatcher has been added that wants moves. | 44 // Used when at least one PointerWatcher has been added that wants moves. |
| 46 MOVE_EVENTS, | 45 MOVE_EVENTS, |
| 47 }; | 46 }; |
| 48 | 47 |
| 49 explicit PointerWatcherEventRouter2( | 48 explicit PointerWatcherEventRouter( |
| 50 aura::WindowTreeClient* window_tree_client); | 49 aura::WindowTreeClient* window_tree_client); |
| 51 ~PointerWatcherEventRouter2() override; | 50 ~PointerWatcherEventRouter() override; |
| 52 | 51 |
| 53 // Called by WindowTreeClientDelegate to notify PointerWatchers appropriately. | 52 // Called by WindowTreeClientDelegate to notify PointerWatchers appropriately. |
| 54 void OnPointerEventObserved(const ui::PointerEvent& event, | 53 void OnPointerEventObserved(const ui::PointerEvent& event, |
| 55 aura::Window* target); | 54 aura::Window* target); |
| 56 | 55 |
| 57 void AddPointerWatcher(PointerWatcher* watcher, bool wants_moves); | 56 void AddPointerWatcher(PointerWatcher* watcher, bool wants_moves); |
| 58 void RemovePointerWatcher(PointerWatcher* watcher); | 57 void RemovePointerWatcher(PointerWatcher* watcher); |
| 59 | 58 |
| 60 private: | 59 private: |
| 61 friend class PointerWatcherEventRouter2Test; | 60 friend class PointerWatcherEventRouterTest; |
| 62 | 61 |
| 63 // Determines EventTypes based on the number and type of PointerWatchers. | 62 // Determines EventTypes based on the number and type of PointerWatchers. |
| 64 EventTypes DetermineEventTypes(); | 63 EventTypes DetermineEventTypes(); |
| 65 | 64 |
| 66 // aura::WindowTreeClientObserver: | 65 // aura::WindowTreeClientObserver: |
| 67 void OnDidDestroyClient(aura::WindowTreeClient* client) override; | 66 void OnDidDestroyClient(aura::WindowTreeClient* client) override; |
| 68 | 67 |
| 69 // aura::client::CaptureClientObserver: | 68 // aura::client::CaptureClientObserver: |
| 70 void OnCaptureChanged(aura::Window* lost_capture, | 69 void OnCaptureChanged(aura::Window* lost_capture, |
| 71 aura::Window* gained_capture) override; | 70 aura::Window* gained_capture) override; |
| 72 | 71 |
| 73 aura::WindowTreeClient* window_tree_client_; | 72 aura::WindowTreeClient* window_tree_client_; |
| 74 // The true parameter to ObserverList indicates the list must be empty on | 73 // The true parameter to ObserverList indicates the list must be empty on |
| 75 // destruction. Two sets of observers are maintained, one for observers not | 74 // destruction. Two sets of observers are maintained, one for observers not |
| 76 // needing moves |non_move_watchers_| and |move_watchers_| for those | 75 // needing moves |non_move_watchers_| and |move_watchers_| for those |
| 77 // observers wanting moves too. | 76 // observers wanting moves too. |
| 78 base::ObserverList<views::PointerWatcher, true> non_move_watchers_; | 77 base::ObserverList<views::PointerWatcher, true> non_move_watchers_; |
| 79 base::ObserverList<views::PointerWatcher, true> move_watchers_; | 78 base::ObserverList<views::PointerWatcher, true> move_watchers_; |
| 80 | 79 |
| 81 EventTypes event_types_ = EventTypes::NONE; | 80 EventTypes event_types_ = EventTypes::NONE; |
| 82 | 81 |
| 83 DISALLOW_COPY_AND_ASSIGN(PointerWatcherEventRouter2); | 82 DISALLOW_COPY_AND_ASSIGN(PointerWatcherEventRouter); |
| 84 }; | 83 }; |
| 85 | 84 |
| 86 } // namespace views | 85 } // namespace views |
| 87 | 86 |
| 88 #endif // UI_VIEWS_MUS_POINTER_WATCHER_EVENT_ROUTER2_H_ | 87 #endif // UI_VIEWS_MUS_POINTER_WATCHER_EVENT_ROUTER_H_ |
| OLD | NEW |