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