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

Side by Side Diff: components/mus/public/cpp/lib/window.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/window.h" 5 #include "components/mus/public/cpp/window.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 12
13 #include "base/bind.h" 13 #include "base/bind.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "components/mus/common/transient_window_utils.h" 15 #include "components/mus/common/transient_window_utils.h"
16 #include "components/mus/public/cpp/lib/window_private.h" 16 #include "components/mus/public/cpp/lib/window_private.h"
17 #include "components/mus/public/cpp/lib/window_tree_client_impl.h"
18 #include "components/mus/public/cpp/property_type_converters.h" 17 #include "components/mus/public/cpp/property_type_converters.h"
19 #include "components/mus/public/cpp/window_observer.h" 18 #include "components/mus/public/cpp/window_observer.h"
20 #include "components/mus/public/cpp/window_property.h" 19 #include "components/mus/public/cpp/window_property.h"
21 #include "components/mus/public/cpp/window_surface.h" 20 #include "components/mus/public/cpp/window_surface.h"
22 #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_client.h"
23 #include "components/mus/public/interfaces/window_manager.mojom.h" 23 #include "components/mus/public/interfaces/window_manager.mojom.h"
24 #include "ui/display/display.h" 24 #include "ui/display/display.h"
25 #include "ui/gfx/geometry/rect.h" 25 #include "ui/gfx/geometry/rect.h"
26 #include "ui/gfx/geometry/size.h" 26 #include "ui/gfx/geometry/size.h"
27 27
28 namespace mus { 28 namespace mus {
29 29
30 namespace { 30 namespace {
31 31
32 void NotifyWindowTreeChangeAtReceiver( 32 void NotifyWindowTreeChangeAtReceiver(
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 } 140 }
141 141
142 private: 142 private:
143 Window* window_; 143 Window* window_;
144 const gfx::Rect old_bounds_; 144 const gfx::Rect old_bounds_;
145 const gfx::Rect new_bounds_; 145 const gfx::Rect new_bounds_;
146 146
147 DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier); 147 DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier);
148 }; 148 };
149 149
150 // Some operations are only permitted in the connection that created the window. 150 // Some operations are only permitted in the client that created the window.
151 bool OwnsWindow(WindowTreeConnection* connection, Window* window) { 151 bool OwnsWindow(WindowTreeClient* client, Window* window) {
152 return !connection || 152 return !client || client->OwnsWindow(window);
153 static_cast<WindowTreeClientImpl*>(connection)->OwnsWindow(window);
154 } 153 }
155 154
156 bool IsConnectionRoot(Window* window) { 155 bool IsClientRoot(Window* window) {
157 return window->connection() && 156 return window->window_tree() &&
158 window->connection()->GetRoots().count(window) > 0; 157 window->window_tree()->GetRoots().count(window) > 0;
159 } 158 }
160 159
161 bool OwnsWindowOrIsRoot(Window* window) { 160 bool OwnsWindowOrIsRoot(Window* window) {
162 return OwnsWindow(window->connection(), window) || IsConnectionRoot(window); 161 return OwnsWindow(window->window_tree(), window) || IsClientRoot(window);
163 } 162 }
164 163
165 void EmptyEmbedCallback(bool result) {} 164 void EmptyEmbedCallback(bool result) {}
166 165
167 } // namespace 166 } // namespace
168 167
169 //////////////////////////////////////////////////////////////////////////////// 168 ////////////////////////////////////////////////////////////////////////////////
170 // Window, public: 169 // Window, public:
171 170
172 void Window::Destroy() { 171 void Window::Destroy() {
173 if (!OwnsWindowOrIsRoot(this)) 172 if (!OwnsWindowOrIsRoot(this))
174 return; 173 return;
175 174
176 if (connection_) 175 if (client_)
177 tree_client()->DestroyWindow(this); 176 window_tree()->DestroyWindow(this);
sky 2016/05/27 20:45:55 window_tree() -> client_
178 while (!children_.empty()) { 177 while (!children_.empty()) {
179 Window* child = children_.front(); 178 Window* child = children_.front();
180 if (!OwnsWindow(connection_, child)) { 179 if (!OwnsWindow(client_, child)) {
181 WindowPrivate(child).ClearParent(); 180 WindowPrivate(child).ClearParent();
182 children_.erase(children_.begin()); 181 children_.erase(children_.begin());
183 } else { 182 } else {
184 child->Destroy(); 183 child->Destroy();
185 DCHECK(std::find(children_.begin(), children_.end(), child) == 184 DCHECK(std::find(children_.begin(), children_.end(), child) ==
186 children_.end()); 185 children_.end());
187 } 186 }
188 } 187 }
189 LocalDestroy(); 188 LocalDestroy();
190 } 189 }
191 190
192 void Window::SetBounds(const gfx::Rect& bounds) { 191 void Window::SetBounds(const gfx::Rect& bounds) {
193 if (!OwnsWindowOrIsRoot(this)) 192 if (!OwnsWindowOrIsRoot(this))
194 return; 193 return;
195 if (bounds_ == bounds) 194 if (bounds_ == bounds)
196 return; 195 return;
197 if (connection_) 196 if (client_)
198 tree_client()->SetBounds(this, bounds_, bounds); 197 window_tree()->SetBounds(this, bounds_, bounds);
199 LocalSetBounds(bounds_, bounds); 198 LocalSetBounds(bounds_, bounds);
200 } 199 }
201 200
202 gfx::Rect Window::GetBoundsInRoot() const { 201 gfx::Rect Window::GetBoundsInRoot() const {
203 gfx::Vector2d offset; 202 gfx::Vector2d offset;
204 for (const Window* w = parent(); w != nullptr; w = w->parent()) 203 for (const Window* w = parent(); w != nullptr; w = w->parent())
205 offset += w->bounds().OffsetFromOrigin(); 204 offset += w->bounds().OffsetFromOrigin();
206 return bounds() + offset; 205 return bounds() + offset;
207 } 206 }
208 207
209 void Window::SetClientArea( 208 void Window::SetClientArea(
210 const gfx::Insets& client_area, 209 const gfx::Insets& client_area,
211 const std::vector<gfx::Rect>& additional_client_areas) { 210 const std::vector<gfx::Rect>& additional_client_areas) {
212 if (!OwnsWindowOrIsRoot(this)) 211 if (!OwnsWindowOrIsRoot(this))
213 return; 212 return;
214 213
215 if (connection_) 214 if (client_)
216 tree_client()->SetClientArea(server_id_, client_area, 215 window_tree()->SetClientArea(server_id_, client_area,
217 additional_client_areas); 216 additional_client_areas);
218 LocalSetClientArea(client_area, additional_client_areas); 217 LocalSetClientArea(client_area, additional_client_areas);
219 } 218 }
220 219
221 void Window::SetHitTestMask(const gfx::Rect& mask) { 220 void Window::SetHitTestMask(const gfx::Rect& mask) {
222 if (!OwnsWindowOrIsRoot(this)) 221 if (!OwnsWindowOrIsRoot(this))
223 return; 222 return;
224 223
225 if (hit_test_mask_ && *hit_test_mask_ == mask) 224 if (hit_test_mask_ && *hit_test_mask_ == mask)
226 return; 225 return;
227 226
228 if (connection_) 227 if (client_)
229 tree_client()->SetHitTestMask(server_id_, mask); 228 window_tree()->SetHitTestMask(server_id_, mask);
230 hit_test_mask_.reset(new gfx::Rect(mask)); 229 hit_test_mask_.reset(new gfx::Rect(mask));
231 } 230 }
232 231
233 void Window::ClearHitTestMask() { 232 void Window::ClearHitTestMask() {
234 if (!OwnsWindowOrIsRoot(this)) 233 if (!OwnsWindowOrIsRoot(this))
235 return; 234 return;
236 235
237 if (!hit_test_mask_) 236 if (!hit_test_mask_)
238 return; 237 return;
239 238
240 if (connection_) 239 if (client_)
241 tree_client()->ClearHitTestMask(server_id_); 240 window_tree()->ClearHitTestMask(server_id_);
242 hit_test_mask_.reset(); 241 hit_test_mask_.reset();
243 } 242 }
244 243
245 void Window::SetVisible(bool value) { 244 void Window::SetVisible(bool value) {
246 if (visible_ == value) 245 if (visible_ == value)
247 return; 246 return;
248 247
249 if (connection_) 248 if (client_)
250 tree_client()->SetVisible(this, value); 249 window_tree()->SetVisible(this, value);
251 LocalSetVisible(value); 250 LocalSetVisible(value);
252 } 251 }
253 252
254 void Window::SetOpacity(float opacity) { 253 void Window::SetOpacity(float opacity) {
255 if (connection_) 254 if (client_)
256 tree_client()->SetOpacity(this, opacity); 255 window_tree()->SetOpacity(this, opacity);
257 LocalSetOpacity(opacity); 256 LocalSetOpacity(opacity);
258 } 257 }
259 258
260 void Window::SetPredefinedCursor(mus::mojom::Cursor cursor_id) { 259 void Window::SetPredefinedCursor(mus::mojom::Cursor cursor_id) {
261 if (cursor_id_ == cursor_id) 260 if (cursor_id_ == cursor_id)
262 return; 261 return;
263 262
264 if (connection_) 263 if (client_)
265 tree_client()->SetPredefinedCursor(server_id_, cursor_id); 264 window_tree()->SetPredefinedCursor(server_id_, cursor_id);
266 LocalSetPredefinedCursor(cursor_id); 265 LocalSetPredefinedCursor(cursor_id);
267 } 266 }
268 267
269 bool Window::IsDrawn() const { 268 bool Window::IsDrawn() const {
270 if (!visible_) 269 if (!visible_)
271 return false; 270 return false;
272 return parent_ ? parent_->IsDrawn() : parent_drawn_; 271 return parent_ ? parent_->IsDrawn() : parent_drawn_;
273 } 272 }
274 273
275 std::unique_ptr<WindowSurface> Window::RequestSurface(mojom::SurfaceType type) { 274 std::unique_ptr<WindowSurface> Window::RequestSurface(mojom::SurfaceType type) {
276 std::unique_ptr<WindowSurfaceBinding> surface_binding; 275 std::unique_ptr<WindowSurfaceBinding> surface_binding;
277 std::unique_ptr<WindowSurface> surface = 276 std::unique_ptr<WindowSurface> surface =
278 WindowSurface::Create(&surface_binding); 277 WindowSurface::Create(&surface_binding);
279 AttachSurface(type, std::move(surface_binding)); 278 AttachSurface(type, std::move(surface_binding));
280 return surface; 279 return surface;
281 } 280 }
282 281
283 void Window::AttachSurface( 282 void Window::AttachSurface(
284 mojom::SurfaceType type, 283 mojom::SurfaceType type,
285 std::unique_ptr<WindowSurfaceBinding> surface_binding) { 284 std::unique_ptr<WindowSurfaceBinding> surface_binding) {
286 tree_client()->AttachSurface( 285 window_tree()->AttachSurface(
287 server_id_, type, std::move(surface_binding->surface_request_), 286 server_id_, type, std::move(surface_binding->surface_request_),
288 mojo::MakeProxy(std::move(surface_binding->surface_client_))); 287 mojo::MakeProxy(std::move(surface_binding->surface_client_)));
289 } 288 }
290 289
291 void Window::ClearSharedProperty(const std::string& name) { 290 void Window::ClearSharedProperty(const std::string& name) {
292 SetSharedPropertyInternal(name, nullptr); 291 SetSharedPropertyInternal(name, nullptr);
293 } 292 }
294 293
295 bool Window::HasSharedProperty(const std::string& name) const { 294 bool Window::HasSharedProperty(const std::string& name) const {
296 return properties_.count(name) > 0; 295 return properties_.count(name) > 0;
297 } 296 }
298 297
299 void Window::AddObserver(WindowObserver* observer) { 298 void Window::AddObserver(WindowObserver* observer) {
300 observers_.AddObserver(observer); 299 observers_.AddObserver(observer);
301 } 300 }
302 301
303 void Window::RemoveObserver(WindowObserver* observer) { 302 void Window::RemoveObserver(WindowObserver* observer) {
304 observers_.RemoveObserver(observer); 303 observers_.RemoveObserver(observer);
305 } 304 }
306 305
307 const Window* Window::GetRoot() const { 306 const Window* Window::GetRoot() const {
308 const Window* root = this; 307 const Window* root = this;
309 for (const Window* parent = this; parent; parent = parent->parent()) 308 for (const Window* parent = this; parent; parent = parent->parent())
310 root = parent; 309 root = parent;
311 return root; 310 return root;
312 } 311 }
313 312
314 void Window::AddChild(Window* child) { 313 void Window::AddChild(Window* child) {
315 // TODO(beng): not necessarily valid to all connections, but possibly to the 314 // TODO(beng): not necessarily valid to all clients, but possibly to the
316 // embeddee in an embedder-embeddee relationship. 315 // embeddee in an embedder-embeddee relationship.
317 if (connection_) 316 if (client_)
318 CHECK_EQ(child->connection(), connection_); 317 CHECK_EQ(child->window_tree(), client_);
319 // Roots can not be added as children of other windows. 318 // Roots can not be added as children of other windows.
320 if (tree_client() && tree_client()->IsRoot(child)) 319 if (window_tree() && window_tree()->IsRoot(child))
321 return; 320 return;
322 LocalAddChild(child); 321 LocalAddChild(child);
323 if (connection_) 322 if (client_)
324 tree_client()->AddChild(this, child->server_id()); 323 window_tree()->AddChild(this, child->server_id());
325 } 324 }
326 325
327 void Window::RemoveChild(Window* child) { 326 void Window::RemoveChild(Window* child) {
328 // TODO(beng): not necessarily valid to all connections, but possibly to the 327 // TODO(beng): not necessarily valid to all clients, but possibly to the
329 // embeddee in an embedder-embeddee relationship. 328 // embeddee in an embedder-embeddee relationship.
330 if (connection_) 329 if (client_)
331 CHECK_EQ(child->connection(), connection_); 330 CHECK_EQ(child->window_tree(), client_);
332 LocalRemoveChild(child); 331 LocalRemoveChild(child);
333 if (connection_) 332 if (client_)
334 tree_client()->RemoveChild(this, child->server_id()); 333 window_tree()->RemoveChild(this, child->server_id());
335 } 334 }
336 335
337 void Window::Reorder(Window* relative, mojom::OrderDirection direction) { 336 void Window::Reorder(Window* relative, mojom::OrderDirection direction) {
338 if (!LocalReorder(relative, direction)) 337 if (!LocalReorder(relative, direction))
339 return; 338 return;
340 if (connection_) 339 if (client_)
341 tree_client()->Reorder(this, relative->server_id(), direction); 340 window_tree()->Reorder(this, relative->server_id(), direction);
342 } 341 }
343 342
344 void Window::MoveToFront() { 343 void Window::MoveToFront() {
345 if (!parent_ || parent_->children_.back() == this) 344 if (!parent_ || parent_->children_.back() == this)
346 return; 345 return;
347 Reorder(parent_->children_.back(), mojom::OrderDirection::ABOVE); 346 Reorder(parent_->children_.back(), mojom::OrderDirection::ABOVE);
348 } 347 }
349 348
350 void Window::MoveToBack() { 349 void Window::MoveToBack() {
351 if (!parent_ || parent_->children_.front() == this) 350 if (!parent_ || parent_->children_.front() == this)
352 return; 351 return;
353 Reorder(parent_->children_.front(), mojom::OrderDirection::BELOW); 352 Reorder(parent_->children_.front(), mojom::OrderDirection::BELOW);
354 } 353 }
355 354
356 bool Window::Contains(const Window* child) const { 355 bool Window::Contains(const Window* child) const {
357 if (!child) 356 if (!child)
358 return false; 357 return false;
359 if (child == this) 358 if (child == this)
360 return true; 359 return true;
361 if (connection_) 360 if (client_)
362 CHECK_EQ(child->connection_, connection_); 361 CHECK_EQ(child->client_, client_);
363 for (const Window* p = child->parent(); p; p = p->parent()) { 362 for (const Window* p = child->parent(); p; p = p->parent()) {
364 if (p == this) 363 if (p == this)
365 return true; 364 return true;
366 } 365 }
367 return false; 366 return false;
368 } 367 }
369 368
370 void Window::AddTransientWindow(Window* transient_window) { 369 void Window::AddTransientWindow(Window* transient_window) {
371 // A system modal window cannot become a transient child. 370 // A system modal window cannot become a transient child.
372 DCHECK(!transient_window->is_modal() || transient_window->transient_parent()); 371 DCHECK(!transient_window->is_modal() || transient_window->transient_parent());
373 372
374 if (connection_) 373 if (client_)
375 CHECK_EQ(transient_window->connection(), connection_); 374 CHECK_EQ(transient_window->window_tree(), client_);
376 LocalAddTransientWindow(transient_window); 375 LocalAddTransientWindow(transient_window);
377 if (connection_) 376 if (client_)
378 tree_client()->AddTransientWindow(this, transient_window->server_id()); 377 window_tree()->AddTransientWindow(this, transient_window->server_id());
379 } 378 }
380 379
381 void Window::RemoveTransientWindow(Window* transient_window) { 380 void Window::RemoveTransientWindow(Window* transient_window) {
382 if (connection_) 381 if (client_)
383 CHECK_EQ(transient_window->connection(), connection_); 382 CHECK_EQ(transient_window->window_tree(), client_);
384 LocalRemoveTransientWindow(transient_window); 383 LocalRemoveTransientWindow(transient_window);
385 if (connection_) 384 if (client_)
386 tree_client()->RemoveTransientWindowFromParent(transient_window); 385 window_tree()->RemoveTransientWindowFromParent(transient_window);
387 } 386 }
388 387
389 void Window::SetModal() { 388 void Window::SetModal() {
390 if (is_modal_) 389 if (is_modal_)
391 return; 390 return;
392 391
393 LocalSetModal(); 392 LocalSetModal();
394 if (connection_) 393 if (client_)
395 tree_client()->SetModal(this); 394 window_tree()->SetModal(this);
396 } 395 }
397 396
398 Window* Window::GetChildByLocalId(int id) { 397 Window* Window::GetChildByLocalId(int id) {
399 if (id == local_id_) 398 if (id == local_id_)
400 return this; 399 return this;
401 // TODO(beng): this could be improved depending on how we decide to own 400 // TODO(beng): this could be improved depending on how we decide to own
402 // windows. 401 // windows.
403 for (Window* child : children_) { 402 for (Window* child : children_) {
404 Window* matching_child = child->GetChildByLocalId(id); 403 Window* matching_child = child->GetChildByLocalId(id);
405 if (matching_child) 404 if (matching_child)
406 return matching_child; 405 return matching_child;
407 } 406 }
408 return nullptr; 407 return nullptr;
409 } 408 }
410 409
411 void Window::SetTextInputState(mojo::TextInputStatePtr state) { 410 void Window::SetTextInputState(mojo::TextInputStatePtr state) {
412 if (connection_) 411 if (client_)
413 tree_client()->SetWindowTextInputState(server_id_, std::move(state)); 412 window_tree()->SetWindowTextInputState(server_id_, std::move(state));
414 } 413 }
415 414
416 void Window::SetImeVisibility(bool visible, mojo::TextInputStatePtr state) { 415 void Window::SetImeVisibility(bool visible, mojo::TextInputStatePtr state) {
417 // SetImeVisibility() shouldn't be used if the window is not editable. 416 // SetImeVisibility() shouldn't be used if the window is not editable.
418 DCHECK(state.is_null() || state->type != mojo::TextInputType::NONE); 417 DCHECK(state.is_null() || state->type != mojo::TextInputType::NONE);
419 if (connection_) 418 if (client_)
420 tree_client()->SetImeVisibility(server_id_, visible, std::move(state)); 419 window_tree()->SetImeVisibility(server_id_, visible, std::move(state));
421 } 420 }
422 421
423 bool Window::HasCapture() const { 422 bool Window::HasCapture() const {
424 return connection_ && connection_->GetCaptureWindow() == this; 423 return client_ && client_->GetCaptureWindow() == this;
425 } 424 }
426 425
427 void Window::SetCapture() { 426 void Window::SetCapture() {
428 if (connection_) 427 if (client_)
429 tree_client()->SetCapture(this); 428 window_tree()->SetCapture(this);
430 } 429 }
431 430
432 void Window::ReleaseCapture() { 431 void Window::ReleaseCapture() {
433 if (connection_) 432 if (client_)
434 tree_client()->ReleaseCapture(this); 433 window_tree()->ReleaseCapture(this);
435 } 434 }
436 435
437 void Window::SetFocus() { 436 void Window::SetFocus() {
438 if (connection_ && IsDrawn()) 437 if (client_ && IsDrawn())
439 tree_client()->SetFocus(this); 438 window_tree()->SetFocus(this);
440 } 439 }
441 440
442 bool Window::HasFocus() const { 441 bool Window::HasFocus() const {
443 return connection_ && connection_->GetFocusedWindow() == this; 442 return client_ && client_->GetFocusedWindow() == this;
444 } 443 }
445 444
446 void Window::SetCanFocus(bool can_focus) { 445 void Window::SetCanFocus(bool can_focus) {
447 if (connection_) 446 if (client_)
448 tree_client()->SetCanFocus(server_id_, can_focus); 447 window_tree()->SetCanFocus(server_id_, can_focus);
449 } 448 }
450 449
451 void Window::Embed(mus::mojom::WindowTreeClientPtr client) { 450 void Window::Embed(mus::mojom::WindowTreeClientPtr client) {
452 Embed(std::move(client), base::Bind(&EmptyEmbedCallback)); 451 Embed(std::move(client), base::Bind(&EmptyEmbedCallback));
453 } 452 }
454 453
455 void Window::Embed(mus::mojom::WindowTreeClientPtr client, 454 void Window::Embed(mus::mojom::WindowTreeClientPtr client,
456 const EmbedCallback& callback) { 455 const EmbedCallback& callback) {
457 if (PrepareForEmbed()) 456 if (PrepareForEmbed())
458 tree_client()->Embed(server_id_, std::move(client), callback); 457 window_tree()->Embed(server_id_, std::move(client), callback);
459 else 458 else
460 callback.Run(false); 459 callback.Run(false);
461 } 460 }
462 461
463 void Window::RequestClose() { 462 void Window::RequestClose() {
464 if (tree_client()) 463 if (window_tree())
465 tree_client()->RequestClose(this); 464 window_tree()->RequestClose(this);
466 } 465 }
467 466
468 std::string Window::GetName() const { 467 std::string Window::GetName() const {
469 if (HasSharedProperty(mojom::WindowManager::kName_Property)) 468 if (HasSharedProperty(mojom::WindowManager::kName_Property))
470 return GetSharedProperty<std::string>(mojom::WindowManager::kName_Property); 469 return GetSharedProperty<std::string>(mojom::WindowManager::kName_Property);
471 470
472 return std::string(); 471 return std::string();
473 } 472 }
474 473
475 //////////////////////////////////////////////////////////////////////////////// 474 ////////////////////////////////////////////////////////////////////////////////
476 // Window, protected: 475 // Window, protected:
477 476
478 Window::Window() : Window(nullptr, static_cast<Id>(-1)) {} 477 Window::Window() : Window(nullptr, static_cast<Id>(-1)) {}
479 478
480 Window::~Window() { 479 Window::~Window() {
481 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroying(this)); 480 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroying(this));
482 if (tree_client()) 481 if (window_tree())
483 tree_client()->OnWindowDestroying(this); 482 window_tree()->OnWindowDestroying(this);
484 483
485 if (HasFocus()) { 484 if (HasFocus()) {
486 // The focused window is being removed. When this happens the server 485 // The focused window is being removed. When this happens the server
487 // advances focus. We don't want to randomly pick a Window to get focus, so 486 // advances focus. We don't want to randomly pick a Window to get focus, so
488 // we update local state only, and wait for the next focus change from the 487 // we update local state only, and wait for the next focus change from the
489 // server. 488 // server.
490 tree_client()->LocalSetFocus(nullptr); 489 window_tree()->LocalSetFocus(nullptr);
491 } 490 }
492 491
493 // Remove from transient parent. 492 // Remove from transient parent.
494 if (transient_parent_) 493 if (transient_parent_)
495 transient_parent_->LocalRemoveTransientWindow(this); 494 transient_parent_->LocalRemoveTransientWindow(this);
496 495
497 // Remove transient children. 496 // Remove transient children.
498 while (!transient_children_.empty()) { 497 while (!transient_children_.empty()) {
499 Window* transient_child = transient_children_.front(); 498 Window* transient_child = transient_children_.front();
500 LocalRemoveTransientWindow(transient_child); 499 LocalRemoveTransientWindow(transient_child);
(...skipping 17 matching lines...) Expand all
518 for (auto& pair : prop_map_) { 517 for (auto& pair : prop_map_) {
519 if (pair.second.deallocator) 518 if (pair.second.deallocator)
520 (*pair.second.deallocator)(pair.second.value); 519 (*pair.second.deallocator)(pair.second.value);
521 } 520 }
522 prop_map_.clear(); 521 prop_map_.clear();
523 522
524 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroyed(this)); 523 FOR_EACH_OBSERVER(WindowObserver, observers_, OnWindowDestroyed(this));
525 524
526 // Invoke after observers so that can clean up any internal state observers 525 // Invoke after observers so that can clean up any internal state observers
527 // may have changed. 526 // may have changed.
528 if (tree_client()) 527 if (window_tree())
529 tree_client()->OnWindowDestroyed(this); 528 window_tree()->OnWindowDestroyed(this);
530 } 529 }
531 530
532 //////////////////////////////////////////////////////////////////////////////// 531 ////////////////////////////////////////////////////////////////////////////////
533 // Window, private: 532 // Window, private:
534 533
535 Window::Window(WindowTreeConnection* connection, Id id) 534 Window::Window(WindowTreeClient* client, Id id)
536 : connection_(connection), 535 : client_(client),
537 server_id_(id), 536 server_id_(id),
538 parent_(nullptr), 537 parent_(nullptr),
539 stacking_target_(nullptr), 538 stacking_target_(nullptr),
540 transient_parent_(nullptr), 539 transient_parent_(nullptr),
541 is_modal_(false), 540 is_modal_(false),
542 // Matches aura, see aura::Window for details. 541 // Matches aura, see aura::Window for details.
543 observers_(base::ObserverList<WindowObserver>::NOTIFY_EXISTING_ONLY), 542 observers_(base::ObserverList<WindowObserver>::NOTIFY_EXISTING_ONLY),
544 input_event_handler_(nullptr), 543 input_event_handler_(nullptr),
545 visible_(false), 544 visible_(false),
546 opacity_(1.0f), 545 opacity_(1.0f),
547 display_id_(display::Display::kInvalidDisplayID), 546 display_id_(display::Display::kInvalidDisplayID),
548 cursor_id_(mojom::Cursor::CURSOR_NULL), 547 cursor_id_(mojom::Cursor::CURSOR_NULL),
549 parent_drawn_(false) {} 548 parent_drawn_(false) {}
550 549
551 WindowTreeClientImpl* Window::tree_client() {
552 return static_cast<WindowTreeClientImpl*>(connection_);
553 }
554
555 void Window::SetSharedPropertyInternal(const std::string& name, 550 void Window::SetSharedPropertyInternal(const std::string& name,
556 const std::vector<uint8_t>* value) { 551 const std::vector<uint8_t>* value) {
557 if (!OwnsWindowOrIsRoot(this)) 552 if (!OwnsWindowOrIsRoot(this))
558 return; 553 return;
559 554
560 if (connection_) { 555 if (client_) {
561 mojo::Array<uint8_t> transport_value(nullptr); 556 mojo::Array<uint8_t> transport_value(nullptr);
562 if (value) { 557 if (value) {
563 transport_value.resize(value->size()); 558 transport_value.resize(value->size());
564 if (value->size()) 559 if (value->size())
565 memcpy(&transport_value.front(), &(value->front()), value->size()); 560 memcpy(&transport_value.front(), &(value->front()), value->size());
566 } 561 }
567 // TODO: add test coverage of this (450303). 562 // TODO: add test coverage of this (450303).
568 tree_client()->SetProperty(this, name, std::move(transport_value)); 563 window_tree()->SetProperty(this, name, std::move(transport_value));
569 } 564 }
570 LocalSetSharedProperty(name, value); 565 LocalSetSharedProperty(name, value);
571 } 566 }
572 567
573 int64_t Window::SetLocalPropertyInternal(const void* key, 568 int64_t Window::SetLocalPropertyInternal(const void* key,
574 const char* name, 569 const char* name,
575 PropertyDeallocator deallocator, 570 PropertyDeallocator deallocator,
576 int64_t value, 571 int64_t value,
577 int64_t default_value) { 572 int64_t default_value) {
578 int64_t old = GetLocalPropertyInternal(key, default_value); 573 int64_t old = GetLocalPropertyInternal(key, default_value);
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
643 638
644 bool Window::LocalReorder(Window* relative, mojom::OrderDirection direction) { 639 bool Window::LocalReorder(Window* relative, mojom::OrderDirection direction) {
645 OrderChangedNotifier notifier(this, relative, direction); 640 OrderChangedNotifier notifier(this, relative, direction);
646 return ReorderImpl(this, relative, direction, &notifier); 641 return ReorderImpl(this, relative, direction, &notifier);
647 } 642 }
648 643
649 void Window::LocalSetBounds(const gfx::Rect& old_bounds, 644 void Window::LocalSetBounds(const gfx::Rect& old_bounds,
650 const gfx::Rect& new_bounds) { 645 const gfx::Rect& new_bounds) {
651 // If this client owns the window, then it should be the only one to change 646 // If this client owns the window, then it should be the only one to change
652 // the bounds. 647 // the bounds.
653 DCHECK(!OwnsWindow(connection_, this) || old_bounds == bounds_); 648 DCHECK(!OwnsWindow(client_, this) || old_bounds == bounds_);
654 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds); 649 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds);
655 bounds_ = new_bounds; 650 bounds_ = new_bounds;
656 } 651 }
657 652
658 void Window::LocalSetClientArea( 653 void Window::LocalSetClientArea(
659 const gfx::Insets& new_client_area, 654 const gfx::Insets& new_client_area,
660 const std::vector<gfx::Rect>& additional_client_areas) { 655 const std::vector<gfx::Rect>& additional_client_areas) {
661 const std::vector<gfx::Rect> old_additional_client_areas = 656 const std::vector<gfx::Rect> old_additional_client_areas =
662 additional_client_areas_; 657 additional_client_areas_;
663 const gfx::Insets old_client_area = client_area_; 658 const gfx::Insets old_client_area = client_area_;
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 void Window::NotifyWindowVisibilityChangedUp(Window* target) { 797 void Window::NotifyWindowVisibilityChangedUp(Window* target) {
803 // Start with the parent as we already notified |this| 798 // Start with the parent as we already notified |this|
804 // in NotifyWindowVisibilityChangedDown. 799 // in NotifyWindowVisibilityChangedDown.
805 for (Window* window = parent(); window; window = window->parent()) { 800 for (Window* window = parent(); window; window = window->parent()) {
806 bool ret = window->NotifyWindowVisibilityChangedAtReceiver(target); 801 bool ret = window->NotifyWindowVisibilityChangedAtReceiver(target);
807 DCHECK(ret); 802 DCHECK(ret);
808 } 803 }
809 } 804 }
810 805
811 bool Window::PrepareForEmbed() { 806 bool Window::PrepareForEmbed() {
812 if (!OwnsWindow(connection_, this)) 807 if (!OwnsWindow(client_, this))
813 return false; 808 return false;
814 809
815 while (!children_.empty()) 810 while (!children_.empty())
816 RemoveChild(children_[0]); 811 RemoveChild(children_[0]);
817 return true; 812 return true;
818 } 813 }
819 814
820 void Window::RemoveTransientWindowImpl(Window* transient_window) { 815 void Window::RemoveTransientWindowImpl(Window* transient_window) {
821 Window::Children::iterator it = std::find( 816 Window::Children::iterator it = std::find(
822 transient_children_.begin(), transient_children_.end(), transient_window); 817 transient_children_.begin(), transient_children_.end(), transient_window);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 notifier->NotifyWindowReordered(); 880 notifier->NotifyWindowReordered();
886 881
887 return true; 882 return true;
888 } 883 }
889 884
890 // static 885 // static
891 Window** Window::GetStackingTarget(Window* window) { 886 Window** Window::GetStackingTarget(Window* window) {
892 return &window->stacking_target_; 887 return &window->stacking_target_;
893 } 888 }
894 } // namespace mus 889 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/public/cpp/lib/scoped_window_ptr.cc ('k') | components/mus/public/cpp/lib/window_private.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698