OLD | NEW |
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 Loading... |
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_watcher = HasPointerWatcher(); |
| 82 pointer_watchers_.AddObserver(watcher); |
| 83 if (!had_watcher) { |
| 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 (!HasPointerWatcher()) { |
| 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)); |
(...skipping 11 matching lines...) Expand all Loading... |
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), |
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 |
| 132 bool WindowManagerConnection::HasPointerWatcher() { |
| 133 // Check to see if we really have any observers left. This doesn't use |
| 134 // base::ObserverList<>::might_have_observers() because that returns true |
| 135 // during iteration over the list even when the last observer is removed. |
| 136 base::ObserverList<PointerWatcher>::Iterator iterator(&pointer_watchers_); |
| 137 return !!iterator.GetNext(); |
| 138 } |
| 139 |
109 void WindowManagerConnection::OnEmbed(mus::Window* root) {} | 140 void WindowManagerConnection::OnEmbed(mus::Window* root) {} |
110 | 141 |
111 void WindowManagerConnection::OnConnectionLost( | 142 void WindowManagerConnection::OnConnectionLost( |
112 mus::WindowTreeConnection* connection) {} | 143 mus::WindowTreeConnection* connection) {} |
113 | 144 |
| 145 void WindowManagerConnection::OnEventObserved(const ui::Event& event) { |
| 146 if (event.type() == ui::ET_MOUSE_PRESSED) { |
| 147 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, |
| 148 OnMousePressed(*event.AsMouseEvent())); |
| 149 } else if (event.type() == ui::ET_TOUCH_PRESSED) { |
| 150 FOR_EACH_OBSERVER(PointerWatcher, pointer_watchers_, |
| 151 OnTouchPressed(*event.AsTouchEvent())); |
| 152 } |
| 153 } |
| 154 |
114 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { | 155 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { |
115 if (window_tree_connection_) | 156 if (window_tree_connection_) |
116 NativeWidgetMus::NotifyFrameChanged(window_tree_connection_.get()); | 157 NativeWidgetMus::NotifyFrameChanged(window_tree_connection_.get()); |
117 } | 158 } |
118 | 159 |
119 } // namespace views | 160 } // namespace views |
OLD | NEW |