Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(443)

Unified Diff: ui/views/mus/pointer_watcher_event_router2.h

Issue 2521823002: Wires up PointerWatcherEventRouter for views aura-mus (Closed)
Patch Set: cleanup Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ui/views/mus/pointer_watcher_event_router2.h
diff --git a/ui/views/mus/pointer_watcher_event_router2.h b/ui/views/mus/pointer_watcher_event_router2.h
new file mode 100644
index 0000000000000000000000000000000000000000..b7577a30f9d5817d73612a394df357126c51cb2b
--- /dev/null
+++ b/ui/views/mus/pointer_watcher_event_router2.h
@@ -0,0 +1,91 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef UI_VIEWS_MUS_POINTER_WATCHER_EVENT_ROUTER2_H_
+#define UI_VIEWS_MUS_POINTER_WATCHER_EVENT_ROUTER2_H_
+
+#include "base/compiler_specific.h"
+#include "base/macros.h"
+#include "base/observer_list.h"
+#include "ui/aura/client/capture_client_observer.h"
+#include "ui/aura/mus/window_tree_client_observer.h"
+#include "ui/views/mus/mus_export.h"
+
+namespace aura {
+class WindowTreeClient;
+namespace client {
+class CaptureClient;
+}
+}
+
+namespace ui {
+class PointerEvent;
+}
+
+namespace views {
+
+class PointerWatcher;
+class PointerWatcherEventRouter2Test;
+
+// PointerWatcherEventRouter2 is responsible for maintaining the list of
+// PointerWatchers and notifying appropriately. It is expected the owner of
+// PointerWatcherEventRouter2 is a WindowTreeClientDelegate and calls
+// OnPointerEventObserved().
+// TODO(sky): Nuke existing PointerWatcherEventRouter and rename this.
+class VIEWS_MUS_EXPORT PointerWatcherEventRouter2
+ : public aura::WindowTreeClientObserver,
+ public aura::client::CaptureClientObserver {
+ public:
+ // Public solely for tests.
+ enum EventTypes {
+ // No PointerWatchers have been added.
+ NONE,
+
+ // Used when the only PointerWatchers added do not want moves.
+ NON_MOVE_EVENTS,
+
+ // Used when at least one PointerWatcher has been added that wants moves.
+ MOVE_EVENTS,
+ };
+
+ explicit PointerWatcherEventRouter2(
+ aura::WindowTreeClient* window_tree_client);
+ ~PointerWatcherEventRouter2() override;
+
+ // Called by WindowTreeClientDelegate to notify PointerWatchers appropriately.
+ void OnPointerEventObserved(const ui::PointerEvent& event,
+ aura::Window* target);
+
+ void AddPointerWatcher(PointerWatcher* watcher, bool wants_moves);
+ void RemovePointerWatcher(PointerWatcher* watcher);
+
+ private:
+ friend class PointerWatcherEventRouter2Test;
+
+ // Determines EventTypes based on the number and type of PointerWatchers.
+ EventTypes DetermineEventTypes();
+
+ // aura::WindowTreeClientObserver:
+ void OnDidDestroyClient(aura::WindowTreeClient* client) override;
+
+ // aura::client::CaptureClientObserver:
+ void OnCaptureChanged(aura::Window* lost_capture,
+ aura::Window* gained_capture) override;
+
+ aura::WindowTreeClient* window_tree_client_;
+ // The true parameter to ObserverList indicates the list must be empty on
+ // destruction. Two sets of observers are maintained, one for observers not
+ // needing moves |non_move_watchers_| and |move_watchers_| for those
+ // observers wanting moves too.
+ base::ObserverList<views::PointerWatcher, true> non_move_watchers_;
+ base::ObserverList<views::PointerWatcher, true> move_watchers_;
+
+ EventTypes event_types_ = EventTypes::NONE;
+
+ DISALLOW_COPY_AND_ASSIGN(PointerWatcherEventRouter2);
+};
+
+} // namespace views
+
+#endif // UI_VIEWS_MUS_POINTER_WATCHER_EVENT_ROUTER2_H_

Powered by Google App Engine
This is Rietveld 408576698