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

Side by Side Diff: ui/views/mus/window_manager_connection.cc

Issue 1921673005: mus: Add PointerWatcher for passively observing mouse and touch events (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months 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 unified diff | Download patch
OLDNEW
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 "ui/views/mus/window_manager_connection.h" 5 #include "ui/views/mus/window_manager_connection.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/lazy_instance.h" 9 #include "base/lazy_instance.h"
10 #include "base/threading/thread_local.h" 10 #include "base/threading/thread_local.h"
11 #include "components/mus/public/cpp/property_type_converters.h" 11 #include "components/mus/public/cpp/property_type_converters.h"
12 #include "components/mus/public/cpp/window.h" 12 #include "components/mus/public/cpp/window.h"
13 #include "components/mus/public/cpp/window_property.h" 13 #include "components/mus/public/cpp/window_property.h"
14 #include "components/mus/public/cpp/window_tree_connection.h" 14 #include "components/mus/public/cpp/window_tree_connection.h"
15 #include "components/mus/public/interfaces/input_event_matcher.mojom.h"
15 #include "components/mus/public/interfaces/window_tree.mojom.h" 16 #include "components/mus/public/interfaces/window_tree.mojom.h"
16 #include "mojo/converters/geometry/geometry_type_converters.h" 17 #include "mojo/converters/geometry/geometry_type_converters.h"
17 #include "services/shell/public/cpp/connection.h" 18 #include "services/shell/public/cpp/connection.h"
18 #include "services/shell/public/cpp/connector.h" 19 #include "services/shell/public/cpp/connector.h"
19 #include "ui/events/devices/device_data_manager.h" 20 #include "ui/events/devices/device_data_manager.h"
20 #include "ui/views/mus/native_widget_mus.h" 21 #include "ui/views/mus/native_widget_mus.h"
21 #include "ui/views/mus/screen_mus.h" 22 #include "ui/views/mus/screen_mus.h"
23 #include "ui/views/pointer_watcher.h"
22 #include "ui/views/views_delegate.h" 24 #include "ui/views/views_delegate.h"
23 25
24 namespace views { 26 namespace views {
25 namespace { 27 namespace {
26 28
27 using WindowManagerConnectionPtr = 29 using WindowManagerConnectionPtr =
28 base::ThreadLocalPointer<views::WindowManagerConnection>; 30 base::ThreadLocalPointer<views::WindowManagerConnection>;
29 31
30 // Env is thread local so that aura may be used on multiple threads. 32 // Env is thread local so that aura may be used on multiple threads.
31 base::LazyInstance<WindowManagerConnectionPtr>::Leaky lazy_tls_ptr = 33 base::LazyInstance<WindowManagerConnectionPtr>::Leaky lazy_tls_ptr =
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 const Widget::InitParams& init_params, 70 const Widget::InitParams& init_params,
69 internal::NativeWidgetDelegate* delegate) { 71 internal::NativeWidgetDelegate* delegate) {
70 std::map<std::string, std::vector<uint8_t>> properties = props; 72 std::map<std::string, std::vector<uint8_t>> properties = props;
71 NativeWidgetMus::ConfigurePropertiesForNewWindow(init_params, &properties); 73 NativeWidgetMus::ConfigurePropertiesForNewWindow(init_params, &properties);
72 properties[mus::mojom::WindowManager::kAppID_Property] = 74 properties[mus::mojom::WindowManager::kAppID_Property] =
73 mojo::ConvertTo<std::vector<uint8_t>>(identity_.name()); 75 mojo::ConvertTo<std::vector<uint8_t>>(identity_.name());
74 return new NativeWidgetMus(delegate, connector_, NewWindow(properties), 76 return new NativeWidgetMus(delegate, connector_, NewWindow(properties),
75 mus::mojom::SurfaceType::DEFAULT); 77 mus::mojom::SurfaceType::DEFAULT);
76 } 78 }
77 79
80 void WindowManagerConnection::AddPointerWatcher(PointerWatcher* watcher) {
81 bool had_observers = pointer_watchers_.might_have_observers();
82 pointer_watchers_.AddObserver(watcher);
83 if (!had_observers) {
84 // Start a watcher for pointer down.
85 // TODO(jamescook): Extend event observers to handle multiple event types.
86 mus::mojom::EventMatcherPtr matcher = mus::mojom::EventMatcher::New();
87 matcher->type_matcher = mus::mojom::EventTypeMatcher::New();
88 matcher->type_matcher->type = mus::mojom::EventType::POINTER_DOWN;
89 window_tree_connection_->SetEventObserver(std::move(matcher));
90 }
91 }
92
93 void WindowManagerConnection::RemovePointerWatcher(PointerWatcher* watcher) {
94 pointer_watchers_.RemoveObserver(watcher);
95 if (!pointer_watchers_.might_have_observers()) {
96 // Last PointerWatcher removed, stop the event observer.
97 window_tree_connection_->SetEventObserver(nullptr);
98 }
99 }
100
78 WindowManagerConnection::WindowManagerConnection( 101 WindowManagerConnection::WindowManagerConnection(
79 shell::Connector* connector, 102 shell::Connector* connector,
80 const shell::Identity& identity) 103 const shell::Identity& identity)
81 : connector_(connector), 104 : connector_(connector),
82 identity_(identity), 105 identity_(identity),
83 window_tree_connection_(nullptr) { 106 window_tree_connection_(nullptr) {
84 window_tree_connection_.reset( 107 window_tree_connection_.reset(
85 mus::WindowTreeConnection::Create(this, connector_)); 108 mus::WindowTreeConnection::Create(this, connector_));
86 109
87 screen_.reset(new ScreenMus(this)); 110 screen_.reset(new ScreenMus(this));
88 screen_->Init(connector); 111 screen_->Init(connector);
89 112
90 // TODO(sad): We should have a DeviceDataManager implementation that talks to 113 // TODO(sad): We should have a DeviceDataManager implementation that talks to
91 // a mojo service to learn about the input-devices on the system. 114 // a mojo service to learn about the input-devices on the system.
92 // http://crbug.com/601981 115 // http://crbug.com/601981
93 ui::DeviceDataManager::CreateInstance(); 116 ui::DeviceDataManager::CreateInstance();
94 117
95 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind( 118 ViewsDelegate::GetInstance()->set_native_widget_factory(base::Bind(
96 &WindowManagerConnection::CreateNativeWidgetMus, 119 &WindowManagerConnection::CreateNativeWidgetMus,
97 base::Unretained(this), 120 base::Unretained(this),
98 std::map<std::string, std::vector<uint8_t>>())); 121 std::map<std::string, std::vector<uint8_t>>()));
99 } 122 }
100 123
101 WindowManagerConnection::~WindowManagerConnection() { 124 WindowManagerConnection::~WindowManagerConnection() {
102 // ~WindowTreeConnection calls back to us (we're the WindowTreeDelegate), 125 // ~WindowTreeConnection calls back to us (we're the WindowTreeDelegate),
sky 2016/04/26 16:55:48 Deal with pointer_watchers_ having observers? Or D
James Cook 2016/04/26 17:42:45 Add ObserverList check_empty flag.
103 // destroy it while we are still valid. 126 // destroy it while we are still valid.
104 window_tree_connection_.reset(); 127 window_tree_connection_.reset();
105 128
106 ui::DeviceDataManager::DeleteInstance(); 129 ui::DeviceDataManager::DeleteInstance();
107 } 130 }
108 131
109 void WindowManagerConnection::OnEmbed(mus::Window* root) {} 132 void WindowManagerConnection::OnEmbed(mus::Window* root) {}
110 133
111 void WindowManagerConnection::OnConnectionLost( 134 void WindowManagerConnection::OnConnectionLost(
112 mus::WindowTreeConnection* connection) {} 135 mus::WindowTreeConnection* connection) {}
113 136
137 void WindowManagerConnection::OnEventObserved(const ui::Event& event) {
138 if (event.type() == ui::ET_MOUSE_PRESSED) {
139 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_,
140 OnMousePressed(*event.AsMouseEvent()));
141 } else if (event.type() == ui::ET_TOUCH_PRESSED) {
142 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_,
143 OnTouchPressed(*event.AsTouchEvent()));
144 }
145 }
146
114 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { 147 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() {
115 if (window_tree_connection_) 148 if (window_tree_connection_)
116 NativeWidgetMus::NotifyFrameChanged(window_tree_connection_.get()); 149 NativeWidgetMus::NotifyFrameChanged(window_tree_connection_.get());
117 } 150 }
118 151
119 } // namespace views 152 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698