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

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

Issue 2072343002: Changes how window manager obtains WindowTree from mus (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: include 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_tree_client.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_client_delegate.h" 22 #include "components/mus/public/cpp/window_tree_client_delegate.h"
23 #include "components/mus/public/cpp/window_tree_client_observer.h" 23 #include "components/mus/public/cpp/window_tree_client_observer.h"
24 #include "components/mus/public/interfaces/window_manager_window_tree_factory.mo jom.h"
24 #include "services/shell/public/cpp/connector.h" 25 #include "services/shell/public/cpp/connector.h"
26 #include "ui/display/mojo/display_type_converters.h"
25 #include "ui/events/event.h" 27 #include "ui/events/event.h"
26 #include "ui/gfx/geometry/insets.h" 28 #include "ui/gfx/geometry/insets.h"
27 #include "ui/gfx/geometry/size.h" 29 #include "ui/gfx/geometry/size.h"
28 30
29 namespace mus { 31 namespace mus {
30 32
31 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) { 33 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) {
32 return (client_id << 16) | local_id; 34 return (client_id << 16) | local_id;
33 } 35 }
34 36
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 mojo::InterfaceRequest<mojom::WindowTreeClient> request) 89 mojo::InterfaceRequest<mojom::WindowTreeClient> request)
88 : client_id_(0), 90 : client_id_(0),
89 next_window_id_(1), 91 next_window_id_(1),
90 next_change_id_(1), 92 next_change_id_(1),
91 delegate_(delegate), 93 delegate_(delegate),
92 window_manager_delegate_(window_manager_delegate), 94 window_manager_delegate_(window_manager_delegate),
93 capture_window_(nullptr), 95 capture_window_(nullptr),
94 focused_window_(nullptr), 96 focused_window_(nullptr),
95 binding_(this), 97 binding_(this),
96 tree_(nullptr), 98 tree_(nullptr),
97 delete_on_no_roots_(true), 99 delete_on_no_roots_(!window_manager_delegate),
98 in_destructor_(false), 100 in_destructor_(false),
99 cursor_location_memory_(nullptr), 101 cursor_location_memory_(nullptr),
100 weak_factory_(this) { 102 weak_factory_(this) {
101 // Allow for a null request in tests. 103 // Allow for a null request in tests.
102 if (request.is_pending()) 104 if (request.is_pending())
103 binding_.Bind(std::move(request)); 105 binding_.Bind(std::move(request));
104 if (window_manager_delegate) 106 if (window_manager_delegate)
105 window_manager_delegate->SetWindowManagerClient(this); 107 window_manager_delegate->SetWindowManagerClient(this);
106 } 108 }
107 109
(...skipping 28 matching lines...) Expand all
136 void WindowTreeClient::ConnectViaWindowTreeFactory( 138 void WindowTreeClient::ConnectViaWindowTreeFactory(
137 shell::Connector* connector) { 139 shell::Connector* connector) {
138 // Clients created with no root shouldn't delete automatically. 140 // Clients created with no root shouldn't delete automatically.
139 delete_on_no_roots_ = false; 141 delete_on_no_roots_ = false;
140 142
141 // The client id doesn't really matter, we use 101 purely for debugging. 143 // The client id doesn't really matter, we use 101 purely for debugging.
142 client_id_ = 101; 144 client_id_ = 101;
143 145
144 mojom::WindowTreeFactoryPtr factory; 146 mojom::WindowTreeFactoryPtr factory;
145 connector->ConnectToInterface("mojo:mus", &factory); 147 connector->ConnectToInterface("mojo:mus", &factory);
146 factory->CreateWindowTree(GetProxy(&tree_ptr_), 148 mojom::WindowTreePtr window_tree;
149 factory->CreateWindowTree(GetProxy(&window_tree),
147 binding_.CreateInterfacePtrAndBind()); 150 binding_.CreateInterfacePtrAndBind());
148 tree_ = tree_ptr_.get(); 151 SetWindowTree(std::move(window_tree));
152 }
149 153
150 tree_ptr_->GetCursorLocationMemory( 154 void WindowTreeClient::ConnectAsWindowManager(shell::Connector* connector) {
151 base::Bind(&WindowTreeClient::OnReceivedCursorLocationMemory, 155 DCHECK(window_manager_delegate_);
152 weak_factory_.GetWeakPtr())); 156
157 mojom::WindowManagerWindowTreeFactoryPtr factory;
158 connector->ConnectToInterface("mojo:mus", &factory);
159 mojom::WindowTreePtr window_tree;
160 factory->CreateWindowTree(GetProxy(&window_tree),
161 binding_.CreateInterfacePtrAndBind());
162 SetWindowTree(std::move(window_tree));
153 } 163 }
154 164
155 void WindowTreeClient::WaitForEmbed() { 165 void WindowTreeClient::WaitForEmbed() {
156 DCHECK(roots_.empty()); 166 DCHECK(roots_.empty());
157 // OnEmbed() is the first function called. 167 // OnEmbed() is the first function called.
158 binding_.WaitForIncomingMethodCall(); 168 binding_.WaitForIncomingMethodCall();
159 // TODO(sky): deal with pipe being closed before we get OnEmbed(). 169 // TODO(sky): deal with pipe being closed before we get OnEmbed().
160 } 170 }
161 171
162 void WindowTreeClient::DestroyWindow(Window* window) { 172 void WindowTreeClient::DestroyWindow(Window* window) {
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 tree_->NewWindow(change_id, server_id(window), 504 tree_->NewWindow(change_id, server_id(window),
495 std::move(transport_properties)); 505 std::move(transport_properties));
496 } else { 506 } else {
497 roots_.insert(window); 507 roots_.insert(window);
498 tree_->NewTopLevelWindow(change_id, server_id(window), 508 tree_->NewTopLevelWindow(change_id, server_id(window),
499 std::move(transport_properties)); 509 std::move(transport_properties));
500 } 510 }
501 return window; 511 return window;
502 } 512 }
503 513
514 void WindowTreeClient::SetWindowTree(mojom::WindowTreePtr window_tree_ptr) {
515 tree_ptr_ = std::move(window_tree_ptr);
516 tree_ = tree_ptr_.get();
517
518 tree_ptr_->GetCursorLocationMemory(
519 base::Bind(&WindowTreeClient::OnReceivedCursorLocationMemory,
520 weak_factory_.GetWeakPtr()));
521
522 tree_ptr_.set_connection_error_handler(base::Bind(
523 &WindowTreeClient::OnConnectionLost, weak_factory_.GetWeakPtr()));
524
525 if (window_manager_delegate_) {
526 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_,
527 tree_ptr_.associated_group()));
528 }
529 }
530
531 void WindowTreeClient::OnConnectionLost() {
532 delete this;
533 }
534
504 void WindowTreeClient::OnEmbedImpl(mojom::WindowTree* window_tree, 535 void WindowTreeClient::OnEmbedImpl(mojom::WindowTree* window_tree,
505 ClientSpecificId client_id, 536 ClientSpecificId client_id,
506 mojom::WindowDataPtr root_data, 537 mojom::WindowDataPtr root_data,
507 int64_t display_id, 538 int64_t display_id,
508 Id focused_window_id, 539 Id focused_window_id,
509 bool drawn) { 540 bool drawn) {
510 // WARNING: this is only called if WindowTreeClient was created as the 541 // WARNING: this is only called if WindowTreeClient was created as the
511 // result of an embedding. 542 // result of an embedding.
512 tree_ = window_tree; 543 tree_ = window_tree;
513 client_id_ = client_id; 544 client_id_ = client_id;
514 545
515 DCHECK(roots_.empty()); 546 DCHECK(roots_.empty());
516 Window* root = AddWindowToClient(this, nullptr, root_data); 547 Window* root = AddWindowToClient(this, nullptr, root_data);
517 WindowPrivate(root).LocalSetDisplay(display_id); 548 WindowPrivate(root).LocalSetDisplay(display_id);
518 roots_.insert(root); 549 roots_.insert(root);
519 550
520 focused_window_ = GetWindowByServerId(focused_window_id); 551 focused_window_ = GetWindowByServerId(focused_window_id);
521 552
522 WindowPrivate(root).LocalSetParentDrawn(drawn); 553 WindowPrivate(root).LocalSetParentDrawn(drawn);
523 554
524 delegate_->OnEmbed(root); 555 delegate_->OnEmbed(root);
525 556
526 if (focused_window_) { 557 if (focused_window_) {
527 FOR_EACH_OBSERVER(WindowTreeClientObserver, observers_, 558 FOR_EACH_OBSERVER(WindowTreeClientObserver, observers_,
528 OnWindowTreeFocusChanged(focused_window_, nullptr)); 559 OnWindowTreeFocusChanged(focused_window_, nullptr));
529 } 560 }
530 } 561 }
531 562
563 void WindowTreeClient::WmNewDisplayAddedImpl(const display::Display& display,
564 mojom::WindowDataPtr root_data,
565 bool parent_drawn) {
566 DCHECK(window_manager_delegate_);
567
568 Window* root = AddWindowToClient(this, nullptr, root_data);
569 WindowPrivate(root).LocalSetDisplay(display.id());
570 WindowPrivate(root).LocalSetParentDrawn(parent_drawn);
571 roots_.insert(root);
572
573 window_manager_delegate_->OnWmNewDisplay(root, display);
574 }
575
532 void WindowTreeClient::OnReceivedCursorLocationMemory( 576 void WindowTreeClient::OnReceivedCursorLocationMemory(
533 mojo::ScopedSharedBufferHandle handle) { 577 mojo::ScopedSharedBufferHandle handle) {
534 cursor_location_handle_ = std::move(handle); 578 cursor_location_handle_ = std::move(handle);
535 MojoResult result = mojo::MapBuffer( 579 MojoResult result = mojo::MapBuffer(
536 cursor_location_handle_.get(), 0, 580 cursor_location_handle_.get(), 0,
537 sizeof(base::subtle::Atomic32), 581 sizeof(base::subtle::Atomic32),
538 reinterpret_cast<void**>(&cursor_location_memory_), 582 reinterpret_cast<void**>(&cursor_location_memory_),
539 MOJO_MAP_BUFFER_FLAG_NONE); 583 MOJO_MAP_BUFFER_FLAG_NONE);
540 if (result != MOJO_RESULT_OK) { 584 if (result != MOJO_RESULT_OK) {
541 NOTREACHED(); 585 NOTREACHED();
(...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after
993 1037
994 void WindowTreeClient::RequestClose(uint32_t window_id) { 1038 void WindowTreeClient::RequestClose(uint32_t window_id) {
995 Window* window = GetWindowByServerId(window_id); 1039 Window* window = GetWindowByServerId(window_id);
996 if (!window || !IsRoot(window)) 1040 if (!window || !IsRoot(window))
997 return; 1041 return;
998 1042
999 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(), 1043 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(),
1000 OnRequestClose(window)); 1044 OnRequestClose(window));
1001 } 1045 }
1002 1046
1047 void WindowTreeClient::OnConnect(ClientSpecificId client_id) {
1048 client_id_ = client_id;
1049 }
1050
1051 void WindowTreeClient::WmNewDisplayAdded(mojom::DisplayPtr display,
1052 mojom::WindowDataPtr root_data,
1053 bool parent_drawn) {
1054 WmNewDisplayAddedImpl(display.To<display::Display>(), std::move(root_data),
1055 parent_drawn);
1056 }
1057
1003 void WindowTreeClient::WmSetBounds(uint32_t change_id, 1058 void WindowTreeClient::WmSetBounds(uint32_t change_id,
1004 Id window_id, 1059 Id window_id,
1005 const gfx::Rect& transit_bounds) { 1060 const gfx::Rect& transit_bounds) {
1006 Window* window = GetWindowByServerId(window_id); 1061 Window* window = GetWindowByServerId(window_id);
1007 bool result = false; 1062 bool result = false;
1008 if (window) { 1063 if (window) {
1009 DCHECK(window_manager_delegate_); 1064 DCHECK(window_manager_delegate_);
1010 gfx::Rect bounds = transit_bounds; 1065 gfx::Rect bounds = transit_bounds;
1011 result = window_manager_delegate_->OnWmSetBounds(window, &bounds); 1066 result = window_manager_delegate_->OnWmSetBounds(window, &bounds);
1012 if (result) { 1067 if (result) {
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 Window* window, 1179 Window* window,
1125 const gfx::Vector2d& offset, 1180 const gfx::Vector2d& offset,
1126 const gfx::Insets& hit_area) { 1181 const gfx::Insets& hit_area) {
1127 if (window_manager_internal_client_) { 1182 if (window_manager_internal_client_) {
1128 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1183 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1129 server_id(window), offset.x(), offset.y(), hit_area); 1184 server_id(window), offset.x(), offset.y(), hit_area);
1130 } 1185 }
1131 } 1186 }
1132 1187
1133 } // namespace mus 1188 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/public/cpp/lib/in_flight_change.cc ('k') | components/mus/public/cpp/tests/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698