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

Side by Side Diff: components/mus/public/cpp/lib/window_tree_client.cc

Issue 2018823002: Eliminate WindowTreeConnection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@connection
Patch Set: . Created 4 years, 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/mus/public/cpp/lib/window_tree_client_impl.h" 5 #include "components/mus/public/cpp/window_tree_client.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "components/mus/common/util.h" 15 #include "components/mus/common/util.h"
16 #include "components/mus/public/cpp/input_event_handler.h" 16 #include "components/mus/public/cpp/input_event_handler.h"
17 #include "components/mus/public/cpp/lib/in_flight_change.h" 17 #include "components/mus/public/cpp/lib/in_flight_change.h"
18 #include "components/mus/public/cpp/lib/window_private.h" 18 #include "components/mus/public/cpp/lib/window_private.h"
19 #include "components/mus/public/cpp/window_manager_delegate.h" 19 #include "components/mus/public/cpp/window_manager_delegate.h"
20 #include "components/mus/public/cpp/window_observer.h" 20 #include "components/mus/public/cpp/window_observer.h"
21 #include "components/mus/public/cpp/window_tracker.h" 21 #include "components/mus/public/cpp/window_tracker.h"
22 #include "components/mus/public/cpp/window_tree_connection.h" 22 #include "components/mus/public/cpp/window_tree_client_delegate.h"
23 #include "components/mus/public/cpp/window_tree_connection_observer.h" 23 #include "components/mus/public/cpp/window_tree_client_observer.h"
24 #include "components/mus/public/cpp/window_tree_delegate.h"
25 #include "services/shell/public/cpp/connector.h" 24 #include "services/shell/public/cpp/connector.h"
26 #include "ui/events/event.h" 25 #include "ui/events/event.h"
27 #include "ui/events/mojo/input_events_type_converters.h" 26 #include "ui/events/mojo/input_events_type_converters.h"
28 #include "ui/gfx/geometry/insets.h" 27 #include "ui/gfx/geometry/insets.h"
29 #include "ui/gfx/geometry/mojo/geometry_type_converters.h" 28 #include "ui/gfx/geometry/mojo/geometry_type_converters.h"
30 #include "ui/gfx/geometry/size.h" 29 #include "ui/gfx/geometry/size.h"
31 30
32 namespace mus { 31 namespace mus {
33 32
34 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) { 33 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) {
35 return (client_id << 16) | local_id; 34 return (client_id << 16) | local_id;
36 } 35 }
37 36
38 Id server_id(Window* window) { 37 Id server_id(Window* window) {
39 return WindowPrivate(window).server_id(); 38 return WindowPrivate(window).server_id();
40 } 39 }
41 40
42 // Helper called to construct a local window object from transport data. 41 // Helper called to construct a local window object from transport data.
43 Window* AddWindowToClient(WindowTreeClientImpl* client, 42 Window* AddWindowToClient(WindowTreeClient* client,
44 Window* parent, 43 Window* parent,
45 const mojom::WindowDataPtr& window_data) { 44 const mojom::WindowDataPtr& window_data) {
46 // We don't use the ctor that takes a WindowTreeConnection here, since it 45 // We don't use the ctor that takes a WindowTreeClient here, since it will
47 // will call back to the service and attempt to create a new window. 46 // call back to the service and attempt to create a new window.
48 Window* window = WindowPrivate::LocalCreate(); 47 Window* window = WindowPrivate::LocalCreate();
49 WindowPrivate private_window(window); 48 WindowPrivate private_window(window);
50 private_window.set_connection(client); 49 private_window.set_client(client);
51 private_window.set_server_id(window_data->window_id); 50 private_window.set_server_id(window_data->window_id);
52 private_window.set_visible(window_data->visible); 51 private_window.set_visible(window_data->visible);
53 private_window.LocalSetDisplay(window_data->display_id); 52 private_window.LocalSetDisplay(window_data->display_id);
54 private_window.set_properties( 53 private_window.set_properties(
55 window_data->properties 54 window_data->properties
56 .To<std::map<std::string, std::vector<uint8_t>>>()); 55 .To<std::map<std::string, std::vector<uint8_t>>>());
57 client->AddWindow(window); 56 client->AddWindow(window);
58 private_window.LocalSetBounds(gfx::Rect(), 57 private_window.LocalSetBounds(gfx::Rect(),
59 window_data->bounds.To<gfx::Rect>()); 58 window_data->bounds.To<gfx::Rect>());
60 if (parent) 59 if (parent)
61 WindowPrivate(parent).LocalAddChild(window); 60 WindowPrivate(parent).LocalAddChild(window);
62 return window; 61 return window;
63 } 62 }
64 63
65 Window* BuildWindowTree(WindowTreeClientImpl* client, 64 Window* BuildWindowTree(WindowTreeClient* client,
66 const mojo::Array<mojom::WindowDataPtr>& windows, 65 const mojo::Array<mojom::WindowDataPtr>& windows,
67 Window* initial_parent) { 66 Window* initial_parent) {
68 std::vector<Window*> parents; 67 std::vector<Window*> parents;
69 Window* root = NULL; 68 Window* root = NULL;
70 Window* last_window = NULL; 69 Window* last_window = NULL;
71 if (initial_parent) 70 if (initial_parent)
72 parents.push_back(initial_parent); 71 parents.push_back(initial_parent);
73 for (size_t i = 0; i < windows.size(); ++i) { 72 for (size_t i = 0; i < windows.size(); ++i) {
74 if (last_window && windows[i]->parent_id == server_id(last_window)) { 73 if (last_window && windows[i]->parent_id == server_id(last_window)) {
75 parents.push_back(last_window); 74 parents.push_back(last_window);
76 } else if (!parents.empty()) { 75 } else if (!parents.empty()) {
77 while (server_id(parents.back()) != windows[i]->parent_id) 76 while (server_id(parents.back()) != windows[i]->parent_id)
78 parents.pop_back(); 77 parents.pop_back();
79 } 78 }
80 Window* window = AddWindowToClient( 79 Window* window = AddWindowToClient(
81 client, !parents.empty() ? parents.back() : NULL, windows[i]); 80 client, !parents.empty() ? parents.back() : NULL, windows[i]);
82 if (!last_window) 81 if (!last_window)
83 root = window; 82 root = window;
84 last_window = window; 83 last_window = window;
85 } 84 }
86 return root; 85 return root;
87 } 86 }
88 87
89 WindowTreeConnection* WindowTreeConnection::Create( 88 WindowTreeClient::WindowTreeClient(
90 WindowTreeDelegate* delegate, 89 WindowTreeClientDelegate* delegate,
91 shell::Connector* connector) {
92 WindowTreeClientImpl* client =
93 new WindowTreeClientImpl(delegate, nullptr, nullptr);
94 client->ConnectViaWindowTreeFactory(connector);
95 return client;
96 }
97
98 WindowTreeConnection* WindowTreeConnection::Create(
99 WindowTreeDelegate* delegate,
100 mojo::InterfaceRequest<mojom::WindowTreeClient> request,
101 CreateType create_type) {
102 WindowTreeClientImpl* client =
103 new WindowTreeClientImpl(delegate, nullptr, std::move(request));
104 if (create_type == CreateType::WAIT_FOR_EMBED)
105 client->WaitForEmbed();
106 return client;
107 }
108
109 WindowTreeConnection* WindowTreeConnection::CreateForWindowManager(
110 WindowTreeDelegate* delegate,
111 mojo::InterfaceRequest<mojom::WindowTreeClient> request,
112 CreateType create_type,
113 WindowManagerDelegate* window_manager_delegate) {
114 WindowTreeClientImpl* client = new WindowTreeClientImpl(
115 delegate, window_manager_delegate, std::move(request));
116 if (create_type == CreateType::WAIT_FOR_EMBED)
117 client->WaitForEmbed();
118 return client;
119 }
120
121 WindowTreeClientImpl::WindowTreeClientImpl(
122 WindowTreeDelegate* delegate,
123 WindowManagerDelegate* window_manager_delegate, 90 WindowManagerDelegate* window_manager_delegate,
124 mojo::InterfaceRequest<mojom::WindowTreeClient> request) 91 mojo::InterfaceRequest<mojom::WindowTreeClient> request)
125 : client_id_(0), 92 : client_id_(0),
126 next_window_id_(1), 93 next_window_id_(1),
127 next_change_id_(1), 94 next_change_id_(1),
128 delegate_(delegate), 95 delegate_(delegate),
129 window_manager_delegate_(window_manager_delegate), 96 window_manager_delegate_(window_manager_delegate),
130 capture_window_(nullptr), 97 capture_window_(nullptr),
131 focused_window_(nullptr), 98 focused_window_(nullptr),
132 binding_(this), 99 binding_(this),
133 tree_(nullptr), 100 tree_(nullptr),
134 delete_on_no_roots_(true), 101 delete_on_no_roots_(true),
135 in_destructor_(false), 102 in_destructor_(false),
136 cursor_location_memory_(nullptr), 103 cursor_location_memory_(nullptr),
137 weak_factory_(this) { 104 weak_factory_(this) {
138 // Allow for a null request in tests. 105 // Allow for a null request in tests.
139 if (request.is_pending()) 106 if (request.is_pending())
140 binding_.Bind(std::move(request)); 107 binding_.Bind(std::move(request));
141 if (window_manager_delegate) 108 if (window_manager_delegate)
142 window_manager_delegate->SetWindowManagerClient(this); 109 window_manager_delegate->SetWindowManagerClient(this);
143 } 110 }
144 111
145 WindowTreeClientImpl::~WindowTreeClientImpl() { 112 WindowTreeClient::~WindowTreeClient() {
146 in_destructor_ = true; 113 in_destructor_ = true;
147 114
148 std::vector<Window*> non_owned; 115 std::vector<Window*> non_owned;
149 WindowTracker tracker; 116 WindowTracker tracker;
150 while (!windows_.empty()) { 117 while (!windows_.empty()) {
151 IdToWindowMap::iterator it = windows_.begin(); 118 IdToWindowMap::iterator it = windows_.begin();
152 if (OwnsWindow(it->second)) { 119 if (OwnsWindow(it->second)) {
153 it->second->Destroy(); 120 it->second->Destroy();
154 } else { 121 } else {
155 tracker.Add(it->second); 122 tracker.Add(it->second);
156 windows_.erase(it); 123 windows_.erase(it);
157 } 124 }
158 } 125 }
159 126
160 // Delete the non-owned windows last. In the typical case these are roots. The 127 // Delete the non-owned windows last. In the typical case these are roots. The
161 // exception is the window manager and embed roots, which may know about 128 // exception is the window manager and embed roots, which may know about
162 // other random windows that it doesn't own. 129 // other random windows that it doesn't own.
163 // NOTE: we manually delete as we're a friend. 130 // NOTE: we manually delete as we're a friend.
164 while (!tracker.windows().empty()) 131 while (!tracker.windows().empty())
165 delete tracker.windows().front(); 132 delete tracker.windows().front();
166 133
167 FOR_EACH_OBSERVER(WindowTreeConnectionObserver, observers_, 134 FOR_EACH_OBSERVER(WindowTreeClientObserver, observers_,
168 OnWillDestroyConnection(this)); 135 OnWillDestroyClient(this));
169 136
170 delegate_->OnConnectionLost(this); 137 delegate_->OnWindowTreeClientDestroyed(this);
171 } 138 }
172 139
173 void WindowTreeClientImpl::ConnectViaWindowTreeFactory( 140 void WindowTreeClient::ConnectViaWindowTreeFactory(
174 shell::Connector* connector) { 141 shell::Connector* connector) {
175 // Clients created with no root shouldn't delete automatically. 142 // Clients created with no root shouldn't delete automatically.
176 delete_on_no_roots_ = false; 143 delete_on_no_roots_ = false;
177 144
178 // The client id doesn't really matter, we use 101 purely for debugging. 145 // The client id doesn't really matter, we use 101 purely for debugging.
179 client_id_ = 101; 146 client_id_ = 101;
180 147
181 mojom::WindowTreeFactoryPtr factory; 148 mojom::WindowTreeFactoryPtr factory;
182 connector->ConnectToInterface("mojo:mus", &factory); 149 connector->ConnectToInterface("mojo:mus", &factory);
183 factory->CreateWindowTree(GetProxy(&tree_ptr_), 150 factory->CreateWindowTree(GetProxy(&tree_ptr_),
184 binding_.CreateInterfacePtrAndBind()); 151 binding_.CreateInterfacePtrAndBind());
185 tree_ = tree_ptr_.get(); 152 tree_ = tree_ptr_.get();
186 153
187 tree_ptr_->GetCursorLocationMemory( 154 tree_ptr_->GetCursorLocationMemory(
188 base::Bind(&WindowTreeClientImpl::OnReceivedCursorLocationMemory, 155 base::Bind(&WindowTreeClient::OnReceivedCursorLocationMemory,
189 weak_factory_.GetWeakPtr())); 156 weak_factory_.GetWeakPtr()));
190 } 157 }
191 158
192 void WindowTreeClientImpl::WaitForEmbed() { 159 void WindowTreeClient::WaitForEmbed() {
193 DCHECK(roots_.empty()); 160 DCHECK(roots_.empty());
194 // OnEmbed() is the first function called. 161 // OnEmbed() is the first function called.
195 binding_.WaitForIncomingMethodCall(); 162 binding_.WaitForIncomingMethodCall();
196 // TODO(sky): deal with pipe being closed before we get OnEmbed(). 163 // TODO(sky): deal with pipe being closed before we get OnEmbed().
197 } 164 }
198 165
199 void WindowTreeClientImpl::DestroyWindow(Window* window) { 166 void WindowTreeClient::DestroyWindow(Window* window) {
200 DCHECK(tree_); 167 DCHECK(tree_);
201 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( 168 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique(
202 new CrashInFlightChange(window, ChangeType::DELETE_WINDOW))); 169 new CrashInFlightChange(window, ChangeType::DELETE_WINDOW)));
203 tree_->DeleteWindow(change_id, server_id(window)); 170 tree_->DeleteWindow(change_id, server_id(window));
204 } 171 }
205 172
206 void WindowTreeClientImpl::AddChild(Window* parent, Id child_id) { 173 void WindowTreeClient::AddChild(Window* parent, Id child_id) {
207 DCHECK(tree_); 174 DCHECK(tree_);
208 const uint32_t change_id = ScheduleInFlightChange( 175 const uint32_t change_id = ScheduleInFlightChange(
209 base::WrapUnique(new CrashInFlightChange(parent, ChangeType::ADD_CHILD))); 176 base::WrapUnique(new CrashInFlightChange(parent, ChangeType::ADD_CHILD)));
210 tree_->AddWindow(change_id, parent->server_id(), child_id); 177 tree_->AddWindow(change_id, parent->server_id(), child_id);
211 } 178 }
212 179
213 void WindowTreeClientImpl::RemoveChild(Window* parent, Id child_id) { 180 void WindowTreeClient::RemoveChild(Window* parent, Id child_id) {
214 DCHECK(tree_); 181 DCHECK(tree_);
215 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( 182 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique(
216 new CrashInFlightChange(parent, ChangeType::REMOVE_CHILD))); 183 new CrashInFlightChange(parent, ChangeType::REMOVE_CHILD)));
217 tree_->RemoveWindowFromParent(change_id, child_id); 184 tree_->RemoveWindowFromParent(change_id, child_id);
218 } 185 }
219 186
220 void WindowTreeClientImpl::AddTransientWindow(Window* window, 187 void WindowTreeClient::AddTransientWindow(Window* window,
221 Id transient_window_id) { 188 Id transient_window_id) {
222 DCHECK(tree_); 189 DCHECK(tree_);
223 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( 190 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique(
224 new CrashInFlightChange(window, ChangeType::ADD_TRANSIENT_WINDOW))); 191 new CrashInFlightChange(window, ChangeType::ADD_TRANSIENT_WINDOW)));
225 tree_->AddTransientWindow(change_id, server_id(window), transient_window_id); 192 tree_->AddTransientWindow(change_id, server_id(window), transient_window_id);
226 } 193 }
227 194
228 void WindowTreeClientImpl::RemoveTransientWindowFromParent(Window* window) { 195 void WindowTreeClient::RemoveTransientWindowFromParent(Window* window) {
229 DCHECK(tree_); 196 DCHECK(tree_);
230 const uint32_t change_id = 197 const uint32_t change_id =
231 ScheduleInFlightChange(base::WrapUnique(new CrashInFlightChange( 198 ScheduleInFlightChange(base::WrapUnique(new CrashInFlightChange(
232 window, ChangeType::REMOVE_TRANSIENT_WINDOW_FROM_PARENT))); 199 window, ChangeType::REMOVE_TRANSIENT_WINDOW_FROM_PARENT)));
233 tree_->RemoveTransientWindowFromParent(change_id, server_id(window)); 200 tree_->RemoveTransientWindowFromParent(change_id, server_id(window));
234 } 201 }
235 202
236 void WindowTreeClientImpl::SetModal(Window* window) { 203 void WindowTreeClient::SetModal(Window* window) {
237 DCHECK(tree_); 204 DCHECK(tree_);
238 const uint32_t change_id = ScheduleInFlightChange( 205 const uint32_t change_id = ScheduleInFlightChange(
239 base::WrapUnique(new InFlightSetModalChange(window))); 206 base::WrapUnique(new InFlightSetModalChange(window)));
240 tree_->SetModal(change_id, server_id(window)); 207 tree_->SetModal(change_id, server_id(window));
241 } 208 }
242 209
243 void WindowTreeClientImpl::Reorder(Window* window, 210 void WindowTreeClient::Reorder(Window* window,
244 Id relative_window_id, 211 Id relative_window_id,
245 mojom::OrderDirection direction) { 212 mojom::OrderDirection direction) {
246 DCHECK(tree_); 213 DCHECK(tree_);
247 const uint32_t change_id = ScheduleInFlightChange( 214 const uint32_t change_id = ScheduleInFlightChange(
248 base::WrapUnique(new CrashInFlightChange(window, ChangeType::REORDER))); 215 base::WrapUnique(new CrashInFlightChange(window, ChangeType::REORDER)));
249 tree_->ReorderWindow(change_id, server_id(window), relative_window_id, 216 tree_->ReorderWindow(change_id, server_id(window), relative_window_id,
250 direction); 217 direction);
251 } 218 }
252 219
253 bool WindowTreeClientImpl::OwnsWindow(Window* window) const { 220 bool WindowTreeClient::OwnsWindow(Window* window) const {
254 // Windows created via CreateTopLevelWindow() are not owned by us, but have 221 // Windows created via CreateTopLevelWindow() are not owned by us, but have
255 // our client id. 222 // our client id.
256 return HiWord(server_id(window)) == client_id_ && 223 return HiWord(server_id(window)) == client_id_ &&
257 roots_.count(window) == 0; 224 roots_.count(window) == 0;
258 } 225 }
259 226
260 void WindowTreeClientImpl::SetBounds(Window* window, 227 void WindowTreeClient::SetBounds(Window* window,
261 const gfx::Rect& old_bounds, 228 const gfx::Rect& old_bounds,
262 const gfx::Rect& bounds) { 229 const gfx::Rect& bounds) {
263 DCHECK(tree_); 230 DCHECK(tree_);
264 const uint32_t change_id = ScheduleInFlightChange( 231 const uint32_t change_id = ScheduleInFlightChange(
265 base::WrapUnique(new InFlightBoundsChange(window, old_bounds))); 232 base::WrapUnique(new InFlightBoundsChange(window, old_bounds)));
266 tree_->SetWindowBounds(change_id, server_id(window), 233 tree_->SetWindowBounds(change_id, server_id(window),
267 mojo::Rect::From(bounds)); 234 mojo::Rect::From(bounds));
268 } 235 }
269 236
270 void WindowTreeClientImpl::SetCapture(Window* window) { 237 void WindowTreeClient::SetCapture(Window* window) {
271 // In order for us to get here we had to have exposed a window, which implies 238 // In order for us to get here we had to have exposed a window, which implies
272 // we got a client. 239 // we got a client.
273 DCHECK(tree_); 240 DCHECK(tree_);
274 if (capture_window_ == window) 241 if (capture_window_ == window)
275 return; 242 return;
276 const uint32_t change_id = ScheduleInFlightChange( 243 const uint32_t change_id = ScheduleInFlightChange(
277 base::WrapUnique(new InFlightCaptureChange(this, capture_window_))); 244 base::WrapUnique(new InFlightCaptureChange(this, capture_window_)));
278 tree_->SetCapture(change_id, server_id(window)); 245 tree_->SetCapture(change_id, server_id(window));
279 LocalSetCapture(window); 246 LocalSetCapture(window);
280 } 247 }
281 248
282 void WindowTreeClientImpl::ReleaseCapture(Window* window) { 249 void WindowTreeClient::ReleaseCapture(Window* window) {
283 // In order for us to get here we had to have exposed a window, which implies 250 // In order for us to get here we had to have exposed a window, which implies
284 // we got a client. 251 // we got a client.
285 DCHECK(tree_); 252 DCHECK(tree_);
286 if (capture_window_ != window) 253 if (capture_window_ != window)
287 return; 254 return;
288 const uint32_t change_id = ScheduleInFlightChange( 255 const uint32_t change_id = ScheduleInFlightChange(
289 base::WrapUnique(new InFlightCaptureChange(this, window))); 256 base::WrapUnique(new InFlightCaptureChange(this, window)));
290 tree_->ReleaseCapture(change_id, server_id(window)); 257 tree_->ReleaseCapture(change_id, server_id(window));
291 LocalSetCapture(nullptr); 258 LocalSetCapture(nullptr);
292 } 259 }
293 260
294 void WindowTreeClientImpl::SetClientArea( 261 void WindowTreeClient::SetClientArea(
295 Id window_id, 262 Id window_id,
296 const gfx::Insets& client_area, 263 const gfx::Insets& client_area,
297 const std::vector<gfx::Rect>& additional_client_areas) { 264 const std::vector<gfx::Rect>& additional_client_areas) {
298 DCHECK(tree_); 265 DCHECK(tree_);
299 tree_->SetClientArea( 266 tree_->SetClientArea(
300 window_id, mojo::Insets::From(client_area), 267 window_id, mojo::Insets::From(client_area),
301 mojo::Array<mojo::RectPtr>::From(additional_client_areas)); 268 mojo::Array<mojo::RectPtr>::From(additional_client_areas));
302 } 269 }
303 270
304 void WindowTreeClientImpl::SetHitTestMask(Id window_id, const gfx::Rect& mask) { 271 void WindowTreeClient::SetHitTestMask(Id window_id, const gfx::Rect& mask) {
305 DCHECK(tree_); 272 DCHECK(tree_);
306 tree_->SetHitTestMask(window_id, mojo::Rect::From(mask)); 273 tree_->SetHitTestMask(window_id, mojo::Rect::From(mask));
307 } 274 }
308 275
309 void WindowTreeClientImpl::ClearHitTestMask(Id window_id) { 276 void WindowTreeClient::ClearHitTestMask(Id window_id) {
310 DCHECK(tree_); 277 DCHECK(tree_);
311 tree_->SetHitTestMask(window_id, nullptr); 278 tree_->SetHitTestMask(window_id, nullptr);
312 } 279 }
313 280
314 void WindowTreeClientImpl::SetFocus(Window* window) { 281 void WindowTreeClient::SetFocus(Window* window) {
315 // In order for us to get here we had to have exposed a window, which implies 282 // In order for us to get here we had to have exposed a window, which implies
316 // we got a client. 283 // we got a client.
317 DCHECK(tree_); 284 DCHECK(tree_);
318 const uint32_t change_id = ScheduleInFlightChange( 285 const uint32_t change_id = ScheduleInFlightChange(
319 base::WrapUnique(new InFlightFocusChange(this, focused_window_))); 286 base::WrapUnique(new InFlightFocusChange(this, focused_window_)));
320 tree_->SetFocus(change_id, window ? server_id(window) : 0); 287 tree_->SetFocus(change_id, window ? server_id(window) : 0);
321 LocalSetFocus(window); 288 LocalSetFocus(window);
322 } 289 }
323 290
324 void WindowTreeClientImpl::SetCanFocus(Id window_id, bool can_focus) { 291 void WindowTreeClient::SetCanFocus(Id window_id, bool can_focus) {
325 DCHECK(tree_); 292 DCHECK(tree_);
326 tree_->SetCanFocus(window_id, can_focus); 293 tree_->SetCanFocus(window_id, can_focus);
327 } 294 }
328 295
329 void WindowTreeClientImpl::SetPredefinedCursor(Id window_id, 296 void WindowTreeClient::SetPredefinedCursor(Id window_id,
330 mus::mojom::Cursor cursor_id) { 297 mus::mojom::Cursor cursor_id) {
331 DCHECK(tree_); 298 DCHECK(tree_);
332 299
333 Window* window = GetWindowByServerId(window_id); 300 Window* window = GetWindowByServerId(window_id);
334 if (!window) 301 if (!window)
335 return; 302 return;
336 303
337 // We make an inflight change thing here. 304 // We make an inflight change thing here.
338 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( 305 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique(
339 new InFlightPredefinedCursorChange(window, window->predefined_cursor()))); 306 new InFlightPredefinedCursorChange(window, window->predefined_cursor())));
340 tree_->SetPredefinedCursor(change_id, window_id, cursor_id); 307 tree_->SetPredefinedCursor(change_id, window_id, cursor_id);
341 } 308 }
342 309
343 void WindowTreeClientImpl::SetVisible(Window* window, bool visible) { 310 void WindowTreeClient::SetVisible(Window* window, bool visible) {
344 DCHECK(tree_); 311 DCHECK(tree_);
345 const uint32_t change_id = ScheduleInFlightChange( 312 const uint32_t change_id = ScheduleInFlightChange(
346 base::WrapUnique(new InFlightVisibleChange(window, !visible))); 313 base::WrapUnique(new InFlightVisibleChange(window, !visible)));
347 tree_->SetWindowVisibility(change_id, server_id(window), visible); 314 tree_->SetWindowVisibility(change_id, server_id(window), visible);
348 } 315 }
349 316
350 void WindowTreeClientImpl::SetOpacity(Window* window, float opacity) { 317 void WindowTreeClient::SetOpacity(Window* window, float opacity) {
351 DCHECK(tree_); 318 DCHECK(tree_);
352 const uint32_t change_id = ScheduleInFlightChange( 319 const uint32_t change_id = ScheduleInFlightChange(
353 base::WrapUnique(new InFlightOpacityChange(window, window->opacity()))); 320 base::WrapUnique(new InFlightOpacityChange(window, window->opacity())));
354 tree_->SetWindowOpacity(change_id, server_id(window), opacity); 321 tree_->SetWindowOpacity(change_id, server_id(window), opacity);
355 } 322 }
356 323
357 void WindowTreeClientImpl::SetProperty(Window* window, 324 void WindowTreeClient::SetProperty(Window* window,
358 const std::string& name, 325 const std::string& name,
359 mojo::Array<uint8_t> data) { 326 mojo::Array<uint8_t> data) {
360 DCHECK(tree_); 327 DCHECK(tree_);
361 328
362 mojo::Array<uint8_t> old_value(nullptr); 329 mojo::Array<uint8_t> old_value(nullptr);
363 if (window->HasSharedProperty(name)) 330 if (window->HasSharedProperty(name))
364 old_value = mojo::Array<uint8_t>::From(window->properties_[name]); 331 old_value = mojo::Array<uint8_t>::From(window->properties_[name]);
365 332
366 const uint32_t change_id = ScheduleInFlightChange( 333 const uint32_t change_id = ScheduleInFlightChange(
367 base::WrapUnique(new InFlightPropertyChange(window, name, old_value))); 334 base::WrapUnique(new InFlightPropertyChange(window, name, old_value)));
368 tree_->SetWindowProperty(change_id, server_id(window), mojo::String(name), 335 tree_->SetWindowProperty(change_id, server_id(window), mojo::String(name),
369 std::move(data)); 336 std::move(data));
370 } 337 }
371 338
372 void WindowTreeClientImpl::SetWindowTextInputState( 339 void WindowTreeClient::SetWindowTextInputState(
373 Id window_id, 340 Id window_id,
374 mojo::TextInputStatePtr state) { 341 mojo::TextInputStatePtr state) {
375 DCHECK(tree_); 342 DCHECK(tree_);
376 tree_->SetWindowTextInputState(window_id, std::move(state)); 343 tree_->SetWindowTextInputState(window_id, std::move(state));
377 } 344 }
378 345
379 void WindowTreeClientImpl::SetImeVisibility(Id window_id, 346 void WindowTreeClient::SetImeVisibility(Id window_id,
380 bool visible, 347 bool visible,
381 mojo::TextInputStatePtr state) { 348 mojo::TextInputStatePtr state) {
382 DCHECK(tree_); 349 DCHECK(tree_);
383 tree_->SetImeVisibility(window_id, visible, std::move(state)); 350 tree_->SetImeVisibility(window_id, visible, std::move(state));
384 } 351 }
385 352
386 void WindowTreeClientImpl::Embed( 353 void WindowTreeClient::Embed(
387 Id window_id, 354 Id window_id,
388 mojom::WindowTreeClientPtr client, 355 mojom::WindowTreeClientPtr client,
389 const mojom::WindowTree::EmbedCallback& callback) { 356 const mojom::WindowTree::EmbedCallback& callback) {
390 DCHECK(tree_); 357 DCHECK(tree_);
391 tree_->Embed(window_id, std::move(client), callback); 358 tree_->Embed(window_id, std::move(client), callback);
392 } 359 }
393 360
394 void WindowTreeClientImpl::RequestClose(Window* window) { 361 void WindowTreeClient::RequestClose(Window* window) {
395 if (window_manager_internal_client_) 362 if (window_manager_internal_client_)
396 window_manager_internal_client_->WmRequestClose(server_id(window)); 363 window_manager_internal_client_->WmRequestClose(server_id(window));
397 } 364 }
398 365
399 void WindowTreeClientImpl::AttachSurface( 366 void WindowTreeClient::AttachSurface(
400 Id window_id, 367 Id window_id,
401 mojom::SurfaceType type, 368 mojom::SurfaceType type,
402 mojo::InterfaceRequest<mojom::Surface> surface, 369 mojo::InterfaceRequest<mojom::Surface> surface,
403 mojom::SurfaceClientPtr client) { 370 mojom::SurfaceClientPtr client) {
404 DCHECK(tree_); 371 DCHECK(tree_);
405 tree_->AttachSurface(window_id, type, std::move(surface), std::move(client)); 372 tree_->AttachSurface(window_id, type, std::move(surface), std::move(client));
406 } 373 }
407 374
408 void WindowTreeClientImpl::LocalSetCapture(Window* window) { 375 void WindowTreeClient::LocalSetCapture(Window* window) {
409 if (capture_window_ == window) 376 if (capture_window_ == window)
410 return; 377 return;
411 Window* lost_capture = capture_window_; 378 Window* lost_capture = capture_window_;
412 capture_window_ = window; 379 capture_window_ = window;
413 if (lost_capture) { 380 if (lost_capture) {
414 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(lost_capture).observers(), 381 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(lost_capture).observers(),
415 OnWindowLostCapture(lost_capture)); 382 OnWindowLostCapture(lost_capture));
416 } 383 }
417 } 384 }
418 385
419 void WindowTreeClientImpl::LocalSetFocus(Window* focused) { 386 void WindowTreeClient::LocalSetFocus(Window* focused) {
420 Window* blurred = focused_window_; 387 Window* blurred = focused_window_;
421 // Update |focused_window_| before calling any of the observers, so that the 388 // Update |focused_window_| before calling any of the observers, so that the
422 // observers get the correct result from calling |Window::HasFocus()|, 389 // observers get the correct result from calling |Window::HasFocus()|,
423 // |WindowTreeConnection::GetFocusedWindow()| etc. 390 // |WindowTreeClient::GetFocusedWindow()| etc.
424 focused_window_ = focused; 391 focused_window_ = focused;
425 if (blurred) { 392 if (blurred) {
426 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(blurred).observers(), 393 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(blurred).observers(),
427 OnWindowFocusChanged(focused, blurred)); 394 OnWindowFocusChanged(focused, blurred));
428 } 395 }
429 if (focused) { 396 if (focused) {
430 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(focused).observers(), 397 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(focused).observers(),
431 OnWindowFocusChanged(focused, blurred)); 398 OnWindowFocusChanged(focused, blurred));
432 } 399 }
433 FOR_EACH_OBSERVER(WindowTreeConnectionObserver, observers_, 400 FOR_EACH_OBSERVER(WindowTreeClientObserver, observers_,
434 OnWindowTreeFocusChanged(focused, blurred)); 401 OnWindowTreeFocusChanged(focused, blurred));
435 } 402 }
436 403
437 void WindowTreeClientImpl::AddWindow(Window* window) { 404 void WindowTreeClient::AddWindow(Window* window) {
438 DCHECK(windows_.find(server_id(window)) == windows_.end()); 405 DCHECK(windows_.find(server_id(window)) == windows_.end());
439 windows_[server_id(window)] = window; 406 windows_[server_id(window)] = window;
440 } 407 }
441 408
442 void WindowTreeClientImpl::OnWindowDestroying(Window* window) { 409 void WindowTreeClient::OnWindowDestroying(Window* window) {
443 // TODO(jonross): Also clear the focused window (crbug.com/611983) 410 // TODO(jonross): Also clear the focused window (crbug.com/611983)
444 if (window == capture_window_) { 411 if (window == capture_window_) {
445 InFlightCaptureChange reset_change(this, nullptr); 412 InFlightCaptureChange reset_change(this, nullptr);
446 ApplyServerChangeToExistingInFlightChange(reset_change); 413 ApplyServerChangeToExistingInFlightChange(reset_change);
447 // Normally just updating the queued changes is sufficient. However since 414 // Normally just updating the queued changes is sufficient. However since
448 // |window| is being destroyed, it will not be possible to notify its 415 // |window| is being destroyed, it will not be possible to notify its
449 // observers of the lost capture. Update local state now. 416 // observers of the lost capture. Update local state now.
450 LocalSetCapture(nullptr); 417 LocalSetCapture(nullptr);
451 } 418 }
452 } 419 }
453 420
454 void WindowTreeClientImpl::OnWindowDestroyed(Window* window) { 421 void WindowTreeClient::OnWindowDestroyed(Window* window) {
455 windows_.erase(server_id(window)); 422 windows_.erase(server_id(window));
456 423
457 for (auto& entry : embedded_windows_) { 424 for (auto& entry : embedded_windows_) {
458 auto it = entry.second.find(window); 425 auto it = entry.second.find(window);
459 if (it != entry.second.end()) { 426 if (it != entry.second.end()) {
460 entry.second.erase(it); 427 entry.second.erase(it);
461 break; 428 break;
462 } 429 }
463 } 430 }
464 431
465 // Remove any InFlightChanges associated with the window. 432 // Remove any InFlightChanges associated with the window.
466 std::set<uint32_t> in_flight_change_ids_to_remove; 433 std::set<uint32_t> in_flight_change_ids_to_remove;
467 for (const auto& pair : in_flight_map_) { 434 for (const auto& pair : in_flight_map_) {
468 if (pair.second->window() == window) 435 if (pair.second->window() == window)
469 in_flight_change_ids_to_remove.insert(pair.first); 436 in_flight_change_ids_to_remove.insert(pair.first);
470 } 437 }
471 for (auto change_id : in_flight_change_ids_to_remove) 438 for (auto change_id : in_flight_change_ids_to_remove)
472 in_flight_map_.erase(change_id); 439 in_flight_map_.erase(change_id);
473 440
474 if (roots_.erase(window) > 0 && roots_.empty() && delete_on_no_roots_ && 441 if (roots_.erase(window) > 0 && roots_.empty() && delete_on_no_roots_ &&
475 !in_destructor_) { 442 !in_destructor_) {
476 delete this; 443 delete this;
477 } 444 }
478 } 445 }
479 446
480 Window* WindowTreeClientImpl::GetWindowByServerId(Id id) { 447 Window* WindowTreeClient::GetWindowByServerId(Id id) {
481 IdToWindowMap::const_iterator it = windows_.find(id); 448 IdToWindowMap::const_iterator it = windows_.find(id);
482 return it != windows_.end() ? it->second : NULL; 449 return it != windows_.end() ? it->second : NULL;
483 } 450 }
484 451
485 InFlightChange* WindowTreeClientImpl::GetOldestInFlightChangeMatching( 452 InFlightChange* WindowTreeClient::GetOldestInFlightChangeMatching(
486 const InFlightChange& change) { 453 const InFlightChange& change) {
487 for (const auto& pair : in_flight_map_) { 454 for (const auto& pair : in_flight_map_) {
488 if (pair.second->window() == change.window() && 455 if (pair.second->window() == change.window() &&
489 pair.second->change_type() == change.change_type() && 456 pair.second->change_type() == change.change_type() &&
490 pair.second->Matches(change)) { 457 pair.second->Matches(change)) {
491 return pair.second.get(); 458 return pair.second.get();
492 } 459 }
493 } 460 }
494 return nullptr; 461 return nullptr;
495 } 462 }
496 463
497 uint32_t WindowTreeClientImpl::ScheduleInFlightChange( 464 uint32_t WindowTreeClient::ScheduleInFlightChange(
498 std::unique_ptr<InFlightChange> change) { 465 std::unique_ptr<InFlightChange> change) {
499 DCHECK(!change->window() || 466 DCHECK(!change->window() ||
500 windows_.count(change->window()->server_id()) > 0); 467 windows_.count(change->window()->server_id()) > 0);
501 const uint32_t change_id = next_change_id_++; 468 const uint32_t change_id = next_change_id_++;
502 in_flight_map_[change_id] = std::move(change); 469 in_flight_map_[change_id] = std::move(change);
503 return change_id; 470 return change_id;
504 } 471 }
505 472
506 bool WindowTreeClientImpl::ApplyServerChangeToExistingInFlightChange( 473 bool WindowTreeClient::ApplyServerChangeToExistingInFlightChange(
507 const InFlightChange& change) { 474 const InFlightChange& change) {
508 InFlightChange* existing_change = GetOldestInFlightChangeMatching(change); 475 InFlightChange* existing_change = GetOldestInFlightChangeMatching(change);
509 if (!existing_change) 476 if (!existing_change)
510 return false; 477 return false;
511 478
512 existing_change->SetRevertValueFrom(change); 479 existing_change->SetRevertValueFrom(change);
513 return true; 480 return true;
514 } 481 }
515 482
516 Window* WindowTreeClientImpl::NewWindowImpl( 483 Window* WindowTreeClient::NewWindowImpl(
517 NewWindowType type, 484 NewWindowType type,
518 const Window::SharedProperties* properties) { 485 const Window::SharedProperties* properties) {
519 DCHECK(tree_); 486 DCHECK(tree_);
520 Window* window = 487 Window* window =
521 new Window(this, MakeTransportId(client_id_, next_window_id_++)); 488 new Window(this, MakeTransportId(client_id_, next_window_id_++));
522 if (properties) 489 if (properties)
523 window->properties_ = *properties; 490 window->properties_ = *properties;
524 AddWindow(window); 491 AddWindow(window);
525 492
526 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique( 493 const uint32_t change_id = ScheduleInFlightChange(base::WrapUnique(
527 new CrashInFlightChange(window, type == NewWindowType::CHILD 494 new CrashInFlightChange(window, type == NewWindowType::CHILD
528 ? ChangeType::NEW_WINDOW 495 ? ChangeType::NEW_WINDOW
529 : ChangeType::NEW_TOP_LEVEL_WINDOW))); 496 : ChangeType::NEW_TOP_LEVEL_WINDOW)));
530 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties; 497 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties;
531 if (properties) { 498 if (properties) {
532 transport_properties = 499 transport_properties =
533 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(*properties); 500 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(*properties);
534 } 501 }
535 if (type == NewWindowType::CHILD) { 502 if (type == NewWindowType::CHILD) {
536 tree_->NewWindow(change_id, server_id(window), 503 tree_->NewWindow(change_id, server_id(window),
537 std::move(transport_properties)); 504 std::move(transport_properties));
538 } else { 505 } else {
539 roots_.insert(window); 506 roots_.insert(window);
540 tree_->NewTopLevelWindow(change_id, server_id(window), 507 tree_->NewTopLevelWindow(change_id, server_id(window),
541 std::move(transport_properties)); 508 std::move(transport_properties));
542 } 509 }
543 return window; 510 return window;
544 } 511 }
545 512
546 void WindowTreeClientImpl::OnEmbedImpl(mojom::WindowTree* window_tree, 513 void WindowTreeClient::OnEmbedImpl(mojom::WindowTree* window_tree,
547 ClientSpecificId client_id, 514 ClientSpecificId client_id,
548 mojom::WindowDataPtr root_data, 515 mojom::WindowDataPtr root_data,
549 Id focused_window_id, 516 Id focused_window_id,
550 bool drawn) { 517 bool drawn) {
551 // WARNING: this is only called if WindowTreeClientImpl was created as the 518 // WARNING: this is only called if WindowTreeClient was created as the
552 // result of an embedding. 519 // result of an embedding.
553 tree_ = window_tree; 520 tree_ = window_tree;
554 client_id_ = client_id; 521 client_id_ = client_id;
555 522
556 DCHECK(roots_.empty()); 523 DCHECK(roots_.empty());
557 Window* root = AddWindowToClient(this, nullptr, root_data); 524 Window* root = AddWindowToClient(this, nullptr, root_data);
558 roots_.insert(root); 525 roots_.insert(root);
559 526
560 focused_window_ = GetWindowByServerId(focused_window_id); 527 focused_window_ = GetWindowByServerId(focused_window_id);
561 528
562 WindowPrivate(root).LocalSetParentDrawn(drawn); 529 WindowPrivate(root).LocalSetParentDrawn(drawn);
563 530
564 delegate_->OnEmbed(root); 531 delegate_->OnEmbed(root);
565 532
566 if (focused_window_) { 533 if (focused_window_) {
567 FOR_EACH_OBSERVER(WindowTreeConnectionObserver, observers_, 534 FOR_EACH_OBSERVER(WindowTreeClientObserver, observers_,
568 OnWindowTreeFocusChanged(focused_window_, nullptr)); 535 OnWindowTreeFocusChanged(focused_window_, nullptr));
569 } 536 }
570 } 537 }
571 538
572 void WindowTreeClientImpl::OnReceivedCursorLocationMemory( 539 void WindowTreeClient::OnReceivedCursorLocationMemory(
573 mojo::ScopedSharedBufferHandle handle) { 540 mojo::ScopedSharedBufferHandle handle) {
574 cursor_location_handle_ = std::move(handle); 541 cursor_location_handle_ = std::move(handle);
575 MojoResult result = mojo::MapBuffer( 542 MojoResult result = mojo::MapBuffer(
576 cursor_location_handle_.get(), 0, 543 cursor_location_handle_.get(), 0,
577 sizeof(base::subtle::Atomic32), 544 sizeof(base::subtle::Atomic32),
578 reinterpret_cast<void**>(&cursor_location_memory_), 545 reinterpret_cast<void**>(&cursor_location_memory_),
579 MOJO_MAP_BUFFER_FLAG_NONE); 546 MOJO_MAP_BUFFER_FLAG_NONE);
580 if (result != MOJO_RESULT_OK) { 547 if (result != MOJO_RESULT_OK) {
581 NOTREACHED(); 548 NOTREACHED();
582 return; 549 return;
583 } 550 }
584 DCHECK(cursor_location_memory_); 551 DCHECK(cursor_location_memory_);
585 } 552 }
586 553
587 //////////////////////////////////////////////////////////////////////////////// 554 ////////////////////////////////////////////////////////////////////////////////
588 // WindowTreeClientImpl, WindowTreeConnection implementation: 555 // WindowTreeClient, WindowTreeClient implementation:
589 556
590 void WindowTreeClientImpl::SetDeleteOnNoRoots(bool value) { 557 void WindowTreeClient::SetDeleteOnNoRoots(bool value) {
591 delete_on_no_roots_ = value; 558 delete_on_no_roots_ = value;
592 } 559 }
593 560
594 const std::set<Window*>& WindowTreeClientImpl::GetRoots() { 561 const std::set<Window*>& WindowTreeClient::GetRoots() {
595 return roots_; 562 return roots_;
596 } 563 }
597 564
598 Window* WindowTreeClientImpl::GetFocusedWindow() { 565 Window* WindowTreeClient::GetFocusedWindow() {
599 return focused_window_; 566 return focused_window_;
600 } 567 }
601 568
602 void WindowTreeClientImpl::ClearFocus() { 569 void WindowTreeClient::ClearFocus() {
603 if (!focused_window_) 570 if (!focused_window_)
604 return; 571 return;
605 572
606 SetFocus(nullptr); 573 SetFocus(nullptr);
607 } 574 }
608 575
609 gfx::Point WindowTreeClientImpl::GetCursorScreenPoint() { 576 gfx::Point WindowTreeClient::GetCursorScreenPoint() {
610 // We raced initialization. Return (0, 0). 577 // We raced initialization. Return (0, 0).
611 if (!cursor_location_memory_) 578 if (!cursor_location_memory_)
612 return gfx::Point(); 579 return gfx::Point();
613 580
614 base::subtle::Atomic32 location = 581 base::subtle::Atomic32 location =
615 base::subtle::NoBarrier_Load(cursor_location_memory_); 582 base::subtle::NoBarrier_Load(cursor_location_memory_);
616 return gfx::Point(static_cast<int16_t>(location >> 16), 583 return gfx::Point(static_cast<int16_t>(location >> 16),
617 static_cast<int16_t>(location & 0xFFFF)); 584 static_cast<int16_t>(location & 0xFFFF));
618 } 585 }
619 586
620 void WindowTreeClientImpl::SetEventObserver(mojom::EventMatcherPtr matcher) { 587 void WindowTreeClient::SetEventObserver(mojom::EventMatcherPtr matcher) {
621 if (matcher.is_null()) { 588 if (matcher.is_null()) {
622 has_event_observer_ = false; 589 has_event_observer_ = false;
623 tree_->SetEventObserver(nullptr, 0u); 590 tree_->SetEventObserver(nullptr, 0u);
624 } else { 591 } else {
625 has_event_observer_ = true; 592 has_event_observer_ = true;
626 event_observer_id_++; 593 event_observer_id_++;
627 tree_->SetEventObserver(std::move(matcher), event_observer_id_); 594 tree_->SetEventObserver(std::move(matcher), event_observer_id_);
628 } 595 }
629 } 596 }
630 597
631 Window* WindowTreeClientImpl::NewWindow( 598 Window* WindowTreeClient::NewWindow(
632 const Window::SharedProperties* properties) { 599 const Window::SharedProperties* properties) {
633 return NewWindowImpl(NewWindowType::CHILD, properties); 600 return NewWindowImpl(NewWindowType::CHILD, properties);
634 } 601 }
635 602
636 Window* WindowTreeClientImpl::NewTopLevelWindow( 603 Window* WindowTreeClient::NewTopLevelWindow(
637 const Window::SharedProperties* properties) { 604 const Window::SharedProperties* properties) {
638 Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties); 605 Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties);
639 // Assume newly created top level windows are drawn by default, otherwise 606 // Assume newly created top level windows are drawn by default, otherwise
640 // requests to focus will fail. We will get the real value in 607 // requests to focus will fail. We will get the real value in
641 // OnTopLevelCreated(). 608 // OnTopLevelCreated().
642 window->LocalSetParentDrawn(true); 609 window->LocalSetParentDrawn(true);
643 return window; 610 return window;
644 } 611 }
645 612
646 //////////////////////////////////////////////////////////////////////////////// 613 ////////////////////////////////////////////////////////////////////////////////
647 // WindowTreeClientImpl, WindowTreeClient implementation: 614 // WindowTreeClient, WindowTreeClient implementation:
648 615
649 void WindowTreeClientImpl::AddObserver(WindowTreeConnectionObserver* observer) { 616 void WindowTreeClient::AddObserver(WindowTreeClientObserver* observer) {
650 observers_.AddObserver(observer); 617 observers_.AddObserver(observer);
651 } 618 }
652 619
653 void WindowTreeClientImpl::RemoveObserver( 620 void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) {
654 WindowTreeConnectionObserver* observer) {
655 observers_.RemoveObserver(observer); 621 observers_.RemoveObserver(observer);
656 } 622 }
657 623
658 void WindowTreeClientImpl::OnEmbed(ClientSpecificId client_id, 624 void WindowTreeClient::OnEmbed(ClientSpecificId client_id,
659 mojom::WindowDataPtr root_data, 625 mojom::WindowDataPtr root_data,
660 mojom::WindowTreePtr tree, 626 mojom::WindowTreePtr tree,
661 Id focused_window_id, 627 Id focused_window_id,
662 bool drawn) { 628 bool drawn) {
663 DCHECK(!tree_ptr_); 629 DCHECK(!tree_ptr_);
664 tree_ptr_ = std::move(tree); 630 tree_ptr_ = std::move(tree);
665 tree_ptr_.set_connection_error_handler([this]() { delete this; }); 631 tree_ptr_.set_connection_error_handler([this]() { delete this; });
666 632
667 if (window_manager_delegate_) { 633 if (window_manager_delegate_) {
668 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_, 634 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_,
669 tree_ptr_.associated_group())); 635 tree_ptr_.associated_group()));
670 } 636 }
671 637
672 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data), 638 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data),
673 focused_window_id, drawn); 639 focused_window_id, drawn);
674 } 640 }
675 641
676 void WindowTreeClientImpl::OnEmbeddedAppDisconnected(Id window_id) { 642 void WindowTreeClient::OnEmbeddedAppDisconnected(Id window_id) {
677 Window* window = GetWindowByServerId(window_id); 643 Window* window = GetWindowByServerId(window_id);
678 if (window) { 644 if (window) {
679 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(), 645 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(),
680 OnWindowEmbeddedAppDisconnected(window)); 646 OnWindowEmbeddedAppDisconnected(window));
681 } 647 }
682 } 648 }
683 649
684 void WindowTreeClientImpl::OnUnembed(Id window_id) { 650 void WindowTreeClient::OnUnembed(Id window_id) {
685 Window* window = GetWindowByServerId(window_id); 651 Window* window = GetWindowByServerId(window_id);
686 if (!window) 652 if (!window)
687 return; 653 return;
688 654
689 delegate_->OnUnembed(window); 655 delegate_->OnUnembed(window);
690 WindowPrivate(window).LocalDestroy(); 656 WindowPrivate(window).LocalDestroy();
691 } 657 }
692 658
693 void WindowTreeClientImpl::OnLostCapture(Id window_id) { 659 void WindowTreeClient::OnLostCapture(Id window_id) {
694 Window* window = GetWindowByServerId(window_id); 660 Window* window = GetWindowByServerId(window_id);
695 if (!window) 661 if (!window)
696 return; 662 return;
697 663
698 InFlightCaptureChange reset_change(this, nullptr); 664 InFlightCaptureChange reset_change(this, nullptr);
699 if (ApplyServerChangeToExistingInFlightChange(reset_change)) 665 if (ApplyServerChangeToExistingInFlightChange(reset_change))
700 return; 666 return;
701 667
702 LocalSetCapture(nullptr); 668 LocalSetCapture(nullptr);
703 } 669 }
704 670
705 void WindowTreeClientImpl::OnTopLevelCreated(uint32_t change_id, 671 void WindowTreeClient::OnTopLevelCreated(uint32_t change_id,
706 mojom::WindowDataPtr data, 672 mojom::WindowDataPtr data,
707 bool drawn) { 673 bool drawn) {
708 // The server ack'd the top level window we created and supplied the state 674 // The server ack'd the top level window we created and supplied the state
709 // of the window at the time the server created it. For properties we do not 675 // of the window at the time the server created it. For properties we do not
710 // have changes in flight for we can update them immediately. For properties 676 // have changes in flight for we can update them immediately. For properties
711 // with changes in flight we set the revert value from the server. 677 // with changes in flight we set the revert value from the server.
712 678
713 if (!in_flight_map_.count(change_id)) { 679 if (!in_flight_map_.count(change_id)) {
714 // The window may have been destroyed locally before the server could finish 680 // The window may have been destroyed locally before the server could finish
715 // creating the window, and before the server received the notification that 681 // creating the window, and before the server received the notification that
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 if (current_change) 728 if (current_change)
763 current_change->SetRevertValueFrom(property_change); 729 current_change->SetRevertValueFrom(property_change);
764 else 730 else
765 window_private.LocalSetSharedProperty(pair.first, &(pair.second)); 731 window_private.LocalSetSharedProperty(pair.first, &(pair.second));
766 } 732 }
767 733
768 // Top level windows should not have a parent. 734 // Top level windows should not have a parent.
769 DCHECK_EQ(0u, data->parent_id); 735 DCHECK_EQ(0u, data->parent_id);
770 } 736 }
771 737
772 void WindowTreeClientImpl::OnWindowBoundsChanged(Id window_id, 738 void WindowTreeClient::OnWindowBoundsChanged(Id window_id,
773 mojo::RectPtr old_bounds, 739 mojo::RectPtr old_bounds,
774 mojo::RectPtr new_bounds) { 740 mojo::RectPtr new_bounds) {
775 Window* window = GetWindowByServerId(window_id); 741 Window* window = GetWindowByServerId(window_id);
776 if (!window) 742 if (!window)
777 return; 743 return;
778 744
779 InFlightBoundsChange new_change(window, new_bounds.To<gfx::Rect>()); 745 InFlightBoundsChange new_change(window, new_bounds.To<gfx::Rect>());
780 if (ApplyServerChangeToExistingInFlightChange(new_change)) 746 if (ApplyServerChangeToExistingInFlightChange(new_change))
781 return; 747 return;
782 748
783 WindowPrivate(window) 749 WindowPrivate(window)
784 .LocalSetBounds(old_bounds.To<gfx::Rect>(), new_bounds.To<gfx::Rect>()); 750 .LocalSetBounds(old_bounds.To<gfx::Rect>(), new_bounds.To<gfx::Rect>());
785 } 751 }
786 752
787 void WindowTreeClientImpl::OnClientAreaChanged( 753 void WindowTreeClient::OnClientAreaChanged(
788 uint32_t window_id, 754 uint32_t window_id,
789 mojo::InsetsPtr new_client_area, 755 mojo::InsetsPtr new_client_area,
790 mojo::Array<mojo::RectPtr> new_additional_client_areas) { 756 mojo::Array<mojo::RectPtr> new_additional_client_areas) {
791 Window* window = GetWindowByServerId(window_id); 757 Window* window = GetWindowByServerId(window_id);
792 if (window) { 758 if (window) {
793 WindowPrivate(window).LocalSetClientArea( 759 WindowPrivate(window).LocalSetClientArea(
794 new_client_area.To<gfx::Insets>(), 760 new_client_area.To<gfx::Insets>(),
795 new_additional_client_areas.To<std::vector<gfx::Rect>>()); 761 new_additional_client_areas.To<std::vector<gfx::Rect>>());
796 } 762 }
797 } 763 }
798 764
799 void WindowTreeClientImpl::OnTransientWindowAdded( 765 void WindowTreeClient::OnTransientWindowAdded(
800 uint32_t window_id, 766 uint32_t window_id,
801 uint32_t transient_window_id) { 767 uint32_t transient_window_id) {
802 Window* window = GetWindowByServerId(window_id); 768 Window* window = GetWindowByServerId(window_id);
803 Window* transient_window = GetWindowByServerId(transient_window_id); 769 Window* transient_window = GetWindowByServerId(transient_window_id);
804 // window or transient_window or both may be null if a local delete occurs 770 // window or transient_window or both may be null if a local delete occurs
805 // with an in flight add from the server. 771 // with an in flight add from the server.
806 if (window && transient_window) 772 if (window && transient_window)
807 WindowPrivate(window).LocalAddTransientWindow(transient_window); 773 WindowPrivate(window).LocalAddTransientWindow(transient_window);
808 } 774 }
809 775
810 void WindowTreeClientImpl::OnTransientWindowRemoved( 776 void WindowTreeClient::OnTransientWindowRemoved(
811 uint32_t window_id, 777 uint32_t window_id,
812 uint32_t transient_window_id) { 778 uint32_t transient_window_id) {
813 Window* window = GetWindowByServerId(window_id); 779 Window* window = GetWindowByServerId(window_id);
814 Window* transient_window = GetWindowByServerId(transient_window_id); 780 Window* transient_window = GetWindowByServerId(transient_window_id);
815 // window or transient_window or both may be null if a local delete occurs 781 // window or transient_window or both may be null if a local delete occurs
816 // with an in flight delete from the server. 782 // with an in flight delete from the server.
817 if (window && transient_window) 783 if (window && transient_window)
818 WindowPrivate(window).LocalRemoveTransientWindow(transient_window); 784 WindowPrivate(window).LocalRemoveTransientWindow(transient_window);
819 } 785 }
820 786
821 void WindowTreeClientImpl::OnWindowHierarchyChanged( 787 void WindowTreeClient::OnWindowHierarchyChanged(
822 Id window_id, 788 Id window_id,
823 Id old_parent_id, 789 Id old_parent_id,
824 Id new_parent_id, 790 Id new_parent_id,
825 mojo::Array<mojom::WindowDataPtr> windows) { 791 mojo::Array<mojom::WindowDataPtr> windows) {
826 Window* initial_parent = 792 Window* initial_parent =
827 windows.size() ? GetWindowByServerId(windows[0]->parent_id) : NULL; 793 windows.size() ? GetWindowByServerId(windows[0]->parent_id) : NULL;
828 794
829 const bool was_window_known = GetWindowByServerId(window_id) != nullptr; 795 const bool was_window_known = GetWindowByServerId(window_id) != nullptr;
830 796
831 BuildWindowTree(this, windows, initial_parent); 797 BuildWindowTree(this, windows, initial_parent);
832 798
833 // If the window was not known, then BuildWindowTree() will have created it 799 // If the window was not known, then BuildWindowTree() will have created it
834 // and parented the window. 800 // and parented the window.
835 if (!was_window_known) 801 if (!was_window_known)
836 return; 802 return;
837 803
838 Window* new_parent = GetWindowByServerId(new_parent_id); 804 Window* new_parent = GetWindowByServerId(new_parent_id);
839 Window* old_parent = GetWindowByServerId(old_parent_id); 805 Window* old_parent = GetWindowByServerId(old_parent_id);
840 Window* window = GetWindowByServerId(window_id); 806 Window* window = GetWindowByServerId(window_id);
841 if (new_parent) 807 if (new_parent)
842 WindowPrivate(new_parent).LocalAddChild(window); 808 WindowPrivate(new_parent).LocalAddChild(window);
843 else 809 else
844 WindowPrivate(old_parent).LocalRemoveChild(window); 810 WindowPrivate(old_parent).LocalRemoveChild(window);
845 } 811 }
846 812
847 void WindowTreeClientImpl::OnWindowReordered(Id window_id, 813 void WindowTreeClient::OnWindowReordered(Id window_id,
848 Id relative_window_id, 814 Id relative_window_id,
849 mojom::OrderDirection direction) { 815 mojom::OrderDirection direction) {
850 Window* window = GetWindowByServerId(window_id); 816 Window* window = GetWindowByServerId(window_id);
851 Window* relative_window = GetWindowByServerId(relative_window_id); 817 Window* relative_window = GetWindowByServerId(relative_window_id);
852 if (window && relative_window) 818 if (window && relative_window)
853 WindowPrivate(window).LocalReorder(relative_window, direction); 819 WindowPrivate(window).LocalReorder(relative_window, direction);
854 } 820 }
855 821
856 void WindowTreeClientImpl::OnWindowDeleted(Id window_id) { 822 void WindowTreeClient::OnWindowDeleted(Id window_id) {
857 Window* window = GetWindowByServerId(window_id); 823 Window* window = GetWindowByServerId(window_id);
858 if (window) 824 if (window)
859 WindowPrivate(window).LocalDestroy(); 825 WindowPrivate(window).LocalDestroy();
860 } 826 }
861 827
862 Window* WindowTreeClientImpl::GetCaptureWindow() { 828 Window* WindowTreeClient::GetCaptureWindow() {
863 return capture_window_; 829 return capture_window_;
864 } 830 }
865 831
866 void WindowTreeClientImpl::OnWindowVisibilityChanged(Id window_id, 832 void WindowTreeClient::OnWindowVisibilityChanged(Id window_id,
867 bool visible) { 833 bool visible) {
868 Window* window = GetWindowByServerId(window_id); 834 Window* window = GetWindowByServerId(window_id);
869 if (!window) 835 if (!window)
870 return; 836 return;
871 837
872 InFlightVisibleChange new_change(window, visible); 838 InFlightVisibleChange new_change(window, visible);
873 if (ApplyServerChangeToExistingInFlightChange(new_change)) 839 if (ApplyServerChangeToExistingInFlightChange(new_change))
874 return; 840 return;
875 841
876 WindowPrivate(window).LocalSetVisible(visible); 842 WindowPrivate(window).LocalSetVisible(visible);
877 } 843 }
878 844
879 void WindowTreeClientImpl::OnWindowOpacityChanged(Id window_id, 845 void WindowTreeClient::OnWindowOpacityChanged(Id window_id,
880 float old_opacity, 846 float old_opacity,
881 float new_opacity) { 847 float new_opacity) {
882 Window* window = GetWindowByServerId(window_id); 848 Window* window = GetWindowByServerId(window_id);
883 if (!window) 849 if (!window)
884 return; 850 return;
885 851
886 InFlightOpacityChange new_change(window, new_opacity); 852 InFlightOpacityChange new_change(window, new_opacity);
887 if (ApplyServerChangeToExistingInFlightChange(new_change)) 853 if (ApplyServerChangeToExistingInFlightChange(new_change))
888 return; 854 return;
889 855
890 WindowPrivate(window).LocalSetOpacity(new_opacity); 856 WindowPrivate(window).LocalSetOpacity(new_opacity);
891 } 857 }
892 858
893 void WindowTreeClientImpl::OnWindowParentDrawnStateChanged(Id window_id, 859 void WindowTreeClient::OnWindowParentDrawnStateChanged(Id window_id,
894 bool drawn) { 860 bool drawn) {
895 Window* window = GetWindowByServerId(window_id); 861 Window* window = GetWindowByServerId(window_id);
896 if (window) 862 if (window)
897 WindowPrivate(window).LocalSetParentDrawn(drawn); 863 WindowPrivate(window).LocalSetParentDrawn(drawn);
898 } 864 }
899 865
900 void WindowTreeClientImpl::OnWindowSharedPropertyChanged( 866 void WindowTreeClient::OnWindowSharedPropertyChanged(
901 Id window_id, 867 Id window_id,
902 const mojo::String& name, 868 const mojo::String& name,
903 mojo::Array<uint8_t> new_data) { 869 mojo::Array<uint8_t> new_data) {
904 Window* window = GetWindowByServerId(window_id); 870 Window* window = GetWindowByServerId(window_id);
905 if (!window) 871 if (!window)
906 return; 872 return;
907 873
908 InFlightPropertyChange new_change(window, name, new_data); 874 InFlightPropertyChange new_change(window, name, new_data);
909 if (ApplyServerChangeToExistingInFlightChange(new_change)) 875 if (ApplyServerChangeToExistingInFlightChange(new_change))
910 return; 876 return;
911 877
912 WindowPrivate(window).LocalSetSharedProperty(name, std::move(new_data)); 878 WindowPrivate(window).LocalSetSharedProperty(name, std::move(new_data));
913 } 879 }
914 880
915 void WindowTreeClientImpl::OnWindowInputEvent(uint32_t event_id, 881 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id,
916 Id window_id, 882 Id window_id,
917 mojom::EventPtr event, 883 mojom::EventPtr event,
918 uint32_t event_observer_id) { 884 uint32_t event_observer_id) {
919 std::unique_ptr<ui::Event> ui_event = event.To<std::unique_ptr<ui::Event>>(); 885 std::unique_ptr<ui::Event> ui_event = event.To<std::unique_ptr<ui::Event>>();
920 Window* window = GetWindowByServerId(window_id); // May be null. 886 Window* window = GetWindowByServerId(window_id); // May be null.
921 887
922 // Non-zero event_observer_id means it matched an event observer on the 888 // Non-zero event_observer_id means it matched an event observer on the
923 // server. 889 // server.
924 if (event_observer_id != 0 && has_event_observer_ && 890 if (event_observer_id != 0 && has_event_observer_ &&
925 event_observer_id == event_observer_id_) 891 event_observer_id == event_observer_id_)
(...skipping 10 matching lines...) Expand all
936 base::Unretained(tree_), event_id))); 902 base::Unretained(tree_), event_id)));
937 window->input_event_handler_->OnWindowInputEvent( 903 window->input_event_handler_->OnWindowInputEvent(
938 window, *event.To<std::unique_ptr<ui::Event>>().get(), &ack_callback); 904 window, *event.To<std::unique_ptr<ui::Event>>().get(), &ack_callback);
939 905
940 // The handler did not take ownership of the callback, so we send the ack, 906 // The handler did not take ownership of the callback, so we send the ack,
941 // marking the event as not consumed. 907 // marking the event as not consumed.
942 if (ack_callback) 908 if (ack_callback)
943 ack_callback->Run(mojom::EventResult::UNHANDLED); 909 ack_callback->Run(mojom::EventResult::UNHANDLED);
944 } 910 }
945 911
946 void WindowTreeClientImpl::OnEventObserved(mojom::EventPtr event, 912 void WindowTreeClient::OnEventObserved(mojom::EventPtr event,
947 uint32_t event_observer_id) { 913 uint32_t event_observer_id) {
948 if (has_event_observer_ && event_observer_id == event_observer_id_) { 914 if (has_event_observer_ && event_observer_id == event_observer_id_) {
949 std::unique_ptr<ui::Event> ui_event = 915 std::unique_ptr<ui::Event> ui_event =
950 event.To<std::unique_ptr<ui::Event>>(); 916 event.To<std::unique_ptr<ui::Event>>();
951 delegate_->OnEventObserved(*ui_event, nullptr /* target */); 917 delegate_->OnEventObserved(*ui_event, nullptr /* target */);
952 } 918 }
953 } 919 }
954 920
955 void WindowTreeClientImpl::OnWindowFocused(Id focused_window_id) { 921 void WindowTreeClient::OnWindowFocused(Id focused_window_id) {
956 Window* focused_window = GetWindowByServerId(focused_window_id); 922 Window* focused_window = GetWindowByServerId(focused_window_id);
957 InFlightFocusChange new_change(this, focused_window); 923 InFlightFocusChange new_change(this, focused_window);
958 if (ApplyServerChangeToExistingInFlightChange(new_change)) 924 if (ApplyServerChangeToExistingInFlightChange(new_change))
959 return; 925 return;
960 926
961 LocalSetFocus(focused_window); 927 LocalSetFocus(focused_window);
962 } 928 }
963 929
964 void WindowTreeClientImpl::OnWindowPredefinedCursorChanged( 930 void WindowTreeClient::OnWindowPredefinedCursorChanged(
965 Id window_id, 931 Id window_id,
966 mojom::Cursor cursor) { 932 mojom::Cursor cursor) {
967 Window* window = GetWindowByServerId(window_id); 933 Window* window = GetWindowByServerId(window_id);
968 if (!window) 934 if (!window)
969 return; 935 return;
970 936
971 InFlightPredefinedCursorChange new_change(window, cursor); 937 InFlightPredefinedCursorChange new_change(window, cursor);
972 if (ApplyServerChangeToExistingInFlightChange(new_change)) 938 if (ApplyServerChangeToExistingInFlightChange(new_change))
973 return; 939 return;
974 940
975 WindowPrivate(window).LocalSetPredefinedCursor(cursor); 941 WindowPrivate(window).LocalSetPredefinedCursor(cursor);
976 } 942 }
977 943
978 void WindowTreeClientImpl::OnChangeCompleted(uint32_t change_id, bool success) { 944 void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) {
979 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); 945 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id]));
980 in_flight_map_.erase(change_id); 946 in_flight_map_.erase(change_id);
981 if (!change) 947 if (!change)
982 return; 948 return;
983 949
984 if (!success) 950 if (!success)
985 change->ChangeFailed(); 951 change->ChangeFailed();
986 952
987 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change); 953 InFlightChange* next_change = GetOldestInFlightChangeMatching(*change);
988 if (next_change) { 954 if (next_change) {
989 if (!success) 955 if (!success)
990 next_change->SetRevertValueFrom(*change); 956 next_change->SetRevertValueFrom(*change);
991 } else if (!success) { 957 } else if (!success) {
992 change->Revert(); 958 change->Revert();
993 } 959 }
994 } 960 }
995 961
996 void WindowTreeClientImpl::GetWindowManager( 962 void WindowTreeClient::GetWindowManager(
997 mojo::AssociatedInterfaceRequest<WindowManager> internal) { 963 mojo::AssociatedInterfaceRequest<WindowManager> internal) {
998 window_manager_internal_.reset( 964 window_manager_internal_.reset(
999 new mojo::AssociatedBinding<mojom::WindowManager>(this, 965 new mojo::AssociatedBinding<mojom::WindowManager>(this,
1000 std::move(internal))); 966 std::move(internal)));
1001 } 967 }
1002 968
1003 void WindowTreeClientImpl::RequestClose(uint32_t window_id) { 969 void WindowTreeClient::RequestClose(uint32_t window_id) {
1004 Window* window = GetWindowByServerId(window_id); 970 Window* window = GetWindowByServerId(window_id);
1005 if (!window || !IsRoot(window)) 971 if (!window || !IsRoot(window))
1006 return; 972 return;
1007 973
1008 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(), 974 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(),
1009 OnRequestClose(window)); 975 OnRequestClose(window));
1010 } 976 }
1011 977
1012 void WindowTreeClientImpl::WmSetBounds(uint32_t change_id, 978 void WindowTreeClient::WmSetBounds(uint32_t change_id,
1013 Id window_id, 979 Id window_id,
1014 mojo::RectPtr transit_bounds) { 980 mojo::RectPtr transit_bounds) {
1015 Window* window = GetWindowByServerId(window_id); 981 Window* window = GetWindowByServerId(window_id);
1016 bool result = false; 982 bool result = false;
1017 if (window) { 983 if (window) {
1018 DCHECK(window_manager_delegate_); 984 DCHECK(window_manager_delegate_);
1019 gfx::Rect bounds = transit_bounds.To<gfx::Rect>(); 985 gfx::Rect bounds = transit_bounds.To<gfx::Rect>();
1020 result = window_manager_delegate_->OnWmSetBounds(window, &bounds); 986 result = window_manager_delegate_->OnWmSetBounds(window, &bounds);
1021 if (result) { 987 if (result) {
1022 // If the resulting bounds differ return false. Returning false ensures 988 // If the resulting bounds differ return false. Returning false ensures
1023 // the client applies the bounds we set below. 989 // the client applies the bounds we set below.
1024 result = bounds == transit_bounds.To<gfx::Rect>(); 990 result = bounds == transit_bounds.To<gfx::Rect>();
1025 window->SetBounds(bounds); 991 window->SetBounds(bounds);
1026 } 992 }
1027 } 993 }
1028 if (window_manager_internal_client_) 994 if (window_manager_internal_client_)
1029 window_manager_internal_client_->WmResponse(change_id, result); 995 window_manager_internal_client_->WmResponse(change_id, result);
1030 } 996 }
1031 997
1032 void WindowTreeClientImpl::WmSetProperty(uint32_t change_id, 998 void WindowTreeClient::WmSetProperty(uint32_t change_id,
1033 Id window_id, 999 Id window_id,
1034 const mojo::String& name, 1000 const mojo::String& name,
1035 mojo::Array<uint8_t> transit_data) { 1001 mojo::Array<uint8_t> transit_data) {
1036 Window* window = GetWindowByServerId(window_id); 1002 Window* window = GetWindowByServerId(window_id);
1037 bool result = false; 1003 bool result = false;
1038 if (window) { 1004 if (window) {
1039 DCHECK(window_manager_delegate_); 1005 DCHECK(window_manager_delegate_);
1040 std::unique_ptr<std::vector<uint8_t>> data; 1006 std::unique_ptr<std::vector<uint8_t>> data;
1041 if (!transit_data.is_null()) { 1007 if (!transit_data.is_null()) {
1042 data.reset( 1008 data.reset(
1043 new std::vector<uint8_t>(transit_data.To<std::vector<uint8_t>>())); 1009 new std::vector<uint8_t>(transit_data.To<std::vector<uint8_t>>()));
1044 } 1010 }
1045 result = window_manager_delegate_->OnWmSetProperty(window, name, &data); 1011 result = window_manager_delegate_->OnWmSetProperty(window, name, &data);
1046 if (result) { 1012 if (result) {
1047 // If the resulting bounds differ return false. Returning false ensures 1013 // If the resulting bounds differ return false. Returning false ensures
1048 // the client applies the bounds we set below. 1014 // the client applies the bounds we set below.
1049 window->SetSharedPropertyInternal(name, data.get()); 1015 window->SetSharedPropertyInternal(name, data.get());
1050 } 1016 }
1051 } 1017 }
1052 if (window_manager_internal_client_) 1018 if (window_manager_internal_client_)
1053 window_manager_internal_client_->WmResponse(change_id, result); 1019 window_manager_internal_client_->WmResponse(change_id, result);
1054 } 1020 }
1055 1021
1056 void WindowTreeClientImpl::WmCreateTopLevelWindow( 1022 void WindowTreeClient::WmCreateTopLevelWindow(
1057 uint32_t change_id, 1023 uint32_t change_id,
1058 ClientSpecificId requesting_client_id, 1024 ClientSpecificId requesting_client_id,
1059 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { 1025 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) {
1060 std::map<std::string, std::vector<uint8_t>> properties = 1026 std::map<std::string, std::vector<uint8_t>> properties =
1061 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); 1027 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>();
1062 Window* window = 1028 Window* window =
1063 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties); 1029 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties);
1064 embedded_windows_[requesting_client_id].insert(window); 1030 embedded_windows_[requesting_client_id].insert(window);
1065 if (window_manager_internal_client_) { 1031 if (window_manager_internal_client_) {
1066 window_manager_internal_client_->OnWmCreatedTopLevelWindow( 1032 window_manager_internal_client_->OnWmCreatedTopLevelWindow(
1067 change_id, server_id(window)); 1033 change_id, server_id(window));
1068 } 1034 }
1069 } 1035 }
1070 1036
1071 void WindowTreeClientImpl::WmClientJankinessChanged(ClientSpecificId client_id, 1037 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id,
1072 bool janky) { 1038 bool janky) {
1073 if (window_manager_delegate_) { 1039 if (window_manager_delegate_) {
1074 auto it = embedded_windows_.find(client_id); 1040 auto it = embedded_windows_.find(client_id);
1075 CHECK(it != embedded_windows_.end()); 1041 CHECK(it != embedded_windows_.end());
1076 window_manager_delegate_->OnWmClientJankinessChanged( 1042 window_manager_delegate_->OnWmClientJankinessChanged(
1077 embedded_windows_[client_id], janky); 1043 embedded_windows_[client_id], janky);
1078 } 1044 }
1079 } 1045 }
1080 1046
1081 void WindowTreeClientImpl::OnAccelerator(uint32_t id, mojom::EventPtr event) { 1047 void WindowTreeClient::OnAccelerator(uint32_t id, mojom::EventPtr event) {
1082 window_manager_delegate_->OnAccelerator( 1048 window_manager_delegate_->OnAccelerator(
1083 id, *event.To<std::unique_ptr<ui::Event>>().get()); 1049 id, *event.To<std::unique_ptr<ui::Event>>().get());
1084 } 1050 }
1085 1051
1086 void WindowTreeClientImpl::SetFrameDecorationValues( 1052 void WindowTreeClient::SetFrameDecorationValues(
1087 mojom::FrameDecorationValuesPtr values) { 1053 mojom::FrameDecorationValuesPtr values) {
1088 if (window_manager_internal_client_) { 1054 if (window_manager_internal_client_) {
1089 window_manager_internal_client_->WmSetFrameDecorationValues( 1055 window_manager_internal_client_->WmSetFrameDecorationValues(
1090 std::move(values)); 1056 std::move(values));
1091 } 1057 }
1092 } 1058 }
1093 1059
1094 void WindowTreeClientImpl::SetNonClientCursor(Window* window, 1060 void WindowTreeClient::SetNonClientCursor(Window* window,
1095 mus::mojom::Cursor cursor_id) { 1061 mus::mojom::Cursor cursor_id) {
1096 window_manager_internal_client_->WmSetNonClientCursor(server_id(window), 1062 window_manager_internal_client_->WmSetNonClientCursor(server_id(window),
1097 cursor_id); 1063 cursor_id);
1098 } 1064 }
1099 1065
1100 void WindowTreeClientImpl::AddAccelerator( 1066 void WindowTreeClient::AddAccelerator(
1101 uint32_t id, 1067 uint32_t id,
1102 mojom::EventMatcherPtr event_matcher, 1068 mojom::EventMatcherPtr event_matcher,
1103 const base::Callback<void(bool)>& callback) { 1069 const base::Callback<void(bool)>& callback) {
1104 if (window_manager_internal_client_) { 1070 if (window_manager_internal_client_) {
1105 window_manager_internal_client_->AddAccelerator( 1071 window_manager_internal_client_->AddAccelerator(
1106 id, std::move(event_matcher), callback); 1072 id, std::move(event_matcher), callback);
1107 } 1073 }
1108 } 1074 }
1109 1075
1110 void WindowTreeClientImpl::RemoveAccelerator(uint32_t id) { 1076 void WindowTreeClient::RemoveAccelerator(uint32_t id) {
1111 if (window_manager_internal_client_) { 1077 if (window_manager_internal_client_) {
1112 window_manager_internal_client_->RemoveAccelerator(id); 1078 window_manager_internal_client_->RemoveAccelerator(id);
1113 } 1079 }
1114 } 1080 }
1115 1081
1116 void WindowTreeClientImpl::AddActivationParent(Window* window) { 1082 void WindowTreeClient::AddActivationParent(Window* window) {
1117 if (window_manager_internal_client_) 1083 if (window_manager_internal_client_)
1118 window_manager_internal_client_->AddActivationParent(server_id(window)); 1084 window_manager_internal_client_->AddActivationParent(server_id(window));
1119 } 1085 }
1120 1086
1121 void WindowTreeClientImpl::RemoveActivationParent(Window* window) { 1087 void WindowTreeClient::RemoveActivationParent(Window* window) {
1122 if (window_manager_internal_client_) 1088 if (window_manager_internal_client_)
1123 window_manager_internal_client_->RemoveActivationParent(server_id(window)); 1089 window_manager_internal_client_->RemoveActivationParent(server_id(window));
1124 } 1090 }
1125 1091
1126 void WindowTreeClientImpl::ActivateNextWindow() { 1092 void WindowTreeClient::ActivateNextWindow() {
1127 if (window_manager_internal_client_) 1093 if (window_manager_internal_client_)
1128 window_manager_internal_client_->ActivateNextWindow(); 1094 window_manager_internal_client_->ActivateNextWindow();
1129 } 1095 }
1130 1096
1131 void WindowTreeClientImpl::SetUnderlaySurfaceOffsetAndExtendedHitArea( 1097 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea(
1132 Window* window, 1098 Window* window,
1133 const gfx::Vector2d& offset, 1099 const gfx::Vector2d& offset,
1134 const gfx::Insets& hit_area) { 1100 const gfx::Insets& hit_area) {
1135 if (window_manager_internal_client_) { 1101 if (window_manager_internal_client_) {
1136 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1102 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1137 server_id(window), offset.x(), offset.y(), 1103 server_id(window), offset.x(), offset.y(),
1138 mojo::Insets::From(hit_area)); 1104 mojo::Insets::From(hit_area));
1139 } 1105 }
1140 } 1106 }
1141 1107
1142 } // namespace mus 1108 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698