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

Side by Side Diff: components/mus/ws/window_tree.cc

Issue 2089023002: Promotes remaining global window manager state into WindowManagerState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: override 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
« no previous file with comments | « components/mus/ws/window_tree.h ('k') | components/mus/ws/window_tree_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/ws/window_tree.h" 5 #include "components/mus/ws/window_tree.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "base/stl_util.h" 14 #include "base/stl_util.h"
15 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h" 15 #include "components/mus/public/cpp/surfaces/surfaces_type_converters.h"
16 #include "components/mus/ws/default_access_policy.h" 16 #include "components/mus/ws/default_access_policy.h"
17 #include "components/mus/ws/display.h" 17 #include "components/mus/ws/display.h"
18 #include "components/mus/ws/display_manager.h" 18 #include "components/mus/ws/display_manager.h"
19 #include "components/mus/ws/event_matcher.h" 19 #include "components/mus/ws/event_matcher.h"
20 #include "components/mus/ws/focus_controller.h" 20 #include "components/mus/ws/focus_controller.h"
21 #include "components/mus/ws/global_window_manager_state.h"
22 #include "components/mus/ws/operation.h" 21 #include "components/mus/ws/operation.h"
23 #include "components/mus/ws/platform_display.h" 22 #include "components/mus/ws/platform_display.h"
24 #include "components/mus/ws/server_window.h" 23 #include "components/mus/ws/server_window.h"
25 #include "components/mus/ws/server_window_observer.h" 24 #include "components/mus/ws/server_window_observer.h"
26 #include "components/mus/ws/user_display_manager.h" 25 #include "components/mus/ws/user_display_manager.h"
26 #include "components/mus/ws/window_manager_display_root.h"
27 #include "components/mus/ws/window_manager_state.h" 27 #include "components/mus/ws/window_manager_state.h"
28 #include "components/mus/ws/window_server.h" 28 #include "components/mus/ws/window_server.h"
29 #include "components/mus/ws/window_tree_binding.h" 29 #include "components/mus/ws/window_tree_binding.h"
30 #include "ui/display/display.h" 30 #include "ui/display/display.h"
31 #include "ui/platform_window/mojo/ime_type_converters.h" 31 #include "ui/platform_window/mojo/ime_type_converters.h"
32 #include "ui/platform_window/text_input_state.h" 32 #include "ui/platform_window/text_input_state.h"
33 33
34 using mojo::Array; 34 using mojo::Array;
35 using mojo::InterfaceRequest; 35 using mojo::InterfaceRequest;
36 using mojo::String; 36 using mojo::String;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 const bool drawn = root->parent() && root->parent()->IsDrawn(); 113 const bool drawn = root->parent() && root->parent()->IsDrawn();
114 client()->OnEmbed(id_, WindowToWindowData(to_send.front()), std::move(tree), 114 client()->OnEmbed(id_, WindowToWindowData(to_send.front()), std::move(tree),
115 display_id, focused_window_id.id, drawn); 115 display_id, focused_window_id.id, drawn);
116 } 116 }
117 117
118 void WindowTree::ConfigureWindowManager() { 118 void WindowTree::ConfigureWindowManager() {
119 DCHECK(!window_manager_internal_); 119 DCHECK(!window_manager_internal_);
120 window_manager_internal_ = binding_->GetWindowManager(); 120 window_manager_internal_ = binding_->GetWindowManager();
121 window_manager_internal_->OnConnect(id_); 121 window_manager_internal_->OnConnect(id_);
122 global_window_manager_state_.reset(new GlobalWindowManagerState(this)); 122 window_manager_state_.reset(new WindowManagerState(this));
123 } 123 }
124 124
125 const ServerWindow* WindowTree::GetWindow(const WindowId& id) const { 125 const ServerWindow* WindowTree::GetWindow(const WindowId& id) const {
126 if (id_ == id.client_id) { 126 if (id_ == id.client_id) {
127 auto iter = created_window_map_.find(id); 127 auto iter = created_window_map_.find(id);
128 return iter == created_window_map_.end() ? nullptr : iter->second; 128 return iter == created_window_map_.end() ? nullptr : iter->second;
129 } 129 }
130 return window_server_->GetWindow(id); 130 return window_server_->GetWindow(id);
131 } 131 }
132 132
(...skipping 17 matching lines...) Expand all
150 const ClientWindowId& id) const { 150 const ClientWindowId& id) const {
151 auto iter = client_id_to_window_id_map_.find(id); 151 auto iter = client_id_to_window_id_map_.find(id);
152 return iter == client_id_to_window_id_map_.end() ? nullptr 152 return iter == client_id_to_window_id_map_.end() ? nullptr
153 : GetWindow(iter->second); 153 : GetWindow(iter->second);
154 } 154 }
155 155
156 const Display* WindowTree::GetDisplay(const ServerWindow* window) const { 156 const Display* WindowTree::GetDisplay(const ServerWindow* window) const {
157 return window ? display_manager()->GetDisplayContaining(window) : nullptr; 157 return window ? display_manager()->GetDisplayContaining(window) : nullptr;
158 } 158 }
159 159
160 const WindowManagerState* WindowTree::GetWindowManagerState( 160 const WindowManagerDisplayRoot* WindowTree::GetWindowManagerDisplayRoot(
161 const ServerWindow* window) const { 161 const ServerWindow* window) const {
162 return window 162 return window ? display_manager()->GetWindowManagerDisplayRoot(window)
163 ? display_manager() 163 : nullptr;
164 ->GetWindowManagerAndDisplay(window)
165 .window_manager_state
166 : nullptr;
167 } 164 }
168 165
169 DisplayManager* WindowTree::display_manager() { 166 DisplayManager* WindowTree::display_manager() {
170 return window_server_->display_manager(); 167 return window_server_->display_manager();
171 } 168 }
172 169
173 const DisplayManager* WindowTree::display_manager() const { 170 const DisplayManager* WindowTree::display_manager() const {
174 return window_server_->display_manager(); 171 return window_server_->display_manager();
175 } 172 }
176 173
177 void WindowTree::AddRootForWindowManager(const ServerWindow* root) { 174 void WindowTree::AddRootForWindowManager(const ServerWindow* root) {
178 DCHECK(window_manager_internal_); 175 DCHECK(window_manager_internal_);
179 const ClientWindowId client_window_id(WindowIdToTransportId(root->id())); 176 const ClientWindowId client_window_id(WindowIdToTransportId(root->id()));
180 DCHECK_EQ(0u, client_id_to_window_id_map_.count(client_window_id)); 177 DCHECK_EQ(0u, client_id_to_window_id_map_.count(client_window_id));
181 client_id_to_window_id_map_[client_window_id] = root->id(); 178 client_id_to_window_id_map_[client_window_id] = root->id();
182 window_id_to_client_id_map_[root->id()] = client_window_id; 179 window_id_to_client_id_map_[root->id()] = client_window_id;
183 roots_.insert(root); 180 roots_.insert(root);
184 181
185 Display* display = GetDisplay(root); 182 Display* display = GetDisplay(root);
186 DCHECK(display); 183 DCHECK(display);
187 184
188 window_manager_internal_->WmNewDisplayAdded(display->ToMojomDisplay(), 185 window_manager_internal_->WmNewDisplayAdded(display->ToMojomDisplay(),
189 WindowToWindowData(root), 186 WindowToWindowData(root),
190 root->parent()->IsDrawn()); 187 root->parent()->IsDrawn());
191 } 188 }
192 189
193 void WindowTree::OnWindowDestroyingTreeImpl(WindowTree* tree) { 190 void WindowTree::OnWindowDestroyingTreeImpl(WindowTree* tree) {
194 if (event_source_wms_ && event_source_wms_->tree() == tree) 191 if (window_manager_state_)
192 window_manager_state_->OnWillDestroyTree(tree);
193
194 if (event_source_wms_ && event_source_wms_->window_tree() == tree)
195 event_source_wms_ = nullptr; 195 event_source_wms_ = nullptr;
196 196
197 // Notify our client if |tree| was embedded in any of our views. 197 // Notify our client if |tree| was embedded in any of our views.
198 for (const auto* tree_root : tree->roots_) { 198 for (const auto* tree_root : tree->roots_) {
199 const bool owns_tree_root = tree_root->id().client_id == id_; 199 const bool owns_tree_root = tree_root->id().client_id == id_;
200 if (owns_tree_root) { 200 if (owns_tree_root) {
201 client()->OnEmbeddedAppDisconnected( 201 client()->OnEmbeddedAppDisconnected(
202 ClientWindowIdForWindow(tree_root).id); 202 ClientWindowIdForWindow(tree_root).id);
203 } 203 }
204 } 204 }
205 } 205 }
206 206
207 void WindowTree::NotifyChangeCompleted( 207 void WindowTree::NotifyChangeCompleted(
208 uint32_t change_id, 208 uint32_t change_id,
209 mojom::WindowManagerErrorCode error_code) { 209 mojom::WindowManagerErrorCode error_code) {
210 client()->OnChangeCompleted( 210 client()->OnChangeCompleted(
211 change_id, error_code == mojom::WindowManagerErrorCode::SUCCESS); 211 change_id, error_code == mojom::WindowManagerErrorCode::SUCCESS);
212 } 212 }
213 213
214 bool WindowTree::SetCapture(const ClientWindowId& client_window_id) { 214 bool WindowTree::SetCapture(const ClientWindowId& client_window_id) {
215 ServerWindow* window = GetWindowByClientId(client_window_id); 215 ServerWindow* window = GetWindowByClientId(client_window_id);
216 WindowManagerState* wms = GetWindowManagerState(window); 216 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window);
217 ServerWindow* current_capture_window = wms ? wms->capture_window() : nullptr; 217 ServerWindow* current_capture_window =
218 if (window && window->IsDrawn() && wms && wms->IsActive() && 218 display_root ? display_root->window_manager_state()->capture_window()
219 : nullptr;
220 if (window && window->IsDrawn() && display_root &&
221 display_root->window_manager_state()->IsActive() &&
219 access_policy_->CanSetCapture(window) && 222 access_policy_->CanSetCapture(window) &&
220 (!current_capture_window || 223 (!current_capture_window ||
221 access_policy_->CanSetCapture(current_capture_window))) { 224 access_policy_->CanSetCapture(current_capture_window))) {
222 return wms->SetCapture(window, id_); 225 return display_root->window_manager_state()->SetCapture(window, id_);
223 } 226 }
224 return false; 227 return false;
225 } 228 }
226 229
227 bool WindowTree::NewWindow( 230 bool WindowTree::NewWindow(
228 const ClientWindowId& client_window_id, 231 const ClientWindowId& client_window_id,
229 const std::map<std::string, std::vector<uint8_t>>& properties) { 232 const std::map<std::string, std::vector<uint8_t>>& properties) {
230 if (!IsValidIdForNewWindow(client_window_id)) 233 if (!IsValidIdForNewWindow(client_window_id))
231 return false; 234 return false;
232 const WindowId window_id = GenerateNewWindowId(); 235 const WindowId window_id = GenerateNewWindowId();
(...skipping 27 matching lines...) Expand all
260 access_policy_->CanAddTransientWindow(window, transient_window)) { 263 access_policy_->CanAddTransientWindow(window, transient_window)) {
261 Operation op(this, window_server_, OperationType::ADD_TRANSIENT_WINDOW); 264 Operation op(this, window_server_, OperationType::ADD_TRANSIENT_WINDOW);
262 return window->AddTransientWindow(transient_window); 265 return window->AddTransientWindow(transient_window);
263 } 266 }
264 return false; 267 return false;
265 } 268 }
266 269
267 bool WindowTree::SetModal(const ClientWindowId& window_id) { 270 bool WindowTree::SetModal(const ClientWindowId& window_id) {
268 ServerWindow* window = GetWindowByClientId(window_id); 271 ServerWindow* window = GetWindowByClientId(window_id);
269 if (window && access_policy_->CanSetModal(window)) { 272 if (window && access_policy_->CanSetModal(window)) {
270 WindowManagerState* wms = GetWindowManagerState(window); 273 WindowManagerDisplayRoot* display_root =
274 GetWindowManagerDisplayRoot(window);
271 if (window->transient_parent()) { 275 if (window->transient_parent()) {
272 window->SetModal(); 276 window->SetModal();
273 } else if (user_id_ != InvalidUserId()) { 277 } else if (user_id_ != InvalidUserId()) {
274 if (wms) 278 if (display_root)
275 wms->AddSystemModalWindow(window); 279 display_root->window_manager_state()->AddSystemModalWindow(window);
276 } else { 280 } else {
277 return false; 281 return false;
278 } 282 }
279 if (wms) 283 if (display_root)
280 wms->ReleaseCaptureBlockedByModalWindow(window); 284 display_root->window_manager_state()->ReleaseCaptureBlockedByModalWindow(
285 window);
281 return true; 286 return true;
282 } 287 }
283 return false; 288 return false;
284 } 289 }
285 290
286 std::vector<const ServerWindow*> WindowTree::GetWindowTree( 291 std::vector<const ServerWindow*> WindowTree::GetWindowTree(
287 const ClientWindowId& window_id) const { 292 const ClientWindowId& window_id) const {
288 const ServerWindow* window = GetWindowByClientId(window_id); 293 const ServerWindow* window = GetWindowByClientId(window_id);
289 std::vector<const ServerWindow*> windows; 294 std::vector<const ServerWindow*> windows;
290 if (window) 295 if (window)
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
676 return; 681 return;
677 ClientWindowId client_window_id, transient_client_window_id; 682 ClientWindowId client_window_id, transient_client_window_id;
678 if (!IsWindowKnown(window, &client_window_id) || 683 if (!IsWindowKnown(window, &client_window_id) ||
679 !IsWindowKnown(transient_window, &transient_client_window_id)) { 684 !IsWindowKnown(transient_window, &transient_client_window_id)) {
680 return; 685 return;
681 } 686 }
682 client()->OnTransientWindowRemoved(client_window_id.id, 687 client()->OnTransientWindowRemoved(client_window_id.id,
683 transient_client_window_id.id); 688 transient_client_window_id.id);
684 } 689 }
685 690
686 WindowManagerState* WindowTree::GetWindowManagerStateForWindowManager() { 691 bool WindowTree::ShouldRouteToWindowManager(const ServerWindow* window) const {
687 // Indicates the client is the wm. 692 if (window_manager_state_)
688 DCHECK(window_manager_internal_); 693 return false; // We are the window manager, don't route to ourself.
689 694
690 if (roots_.size() > 1) {
691 // TODO(sky): fix the > 1 case, http://crbug.com/611563.
692 NOTIMPLEMENTED();
693 }
694
695 WindowManagerState* wms = display_manager()
696 ->GetWindowManagerAndDisplay(*roots_.begin())
697 .window_manager_state;
698 CHECK(wms);
699 DCHECK_EQ(this, wms->tree());
700 return wms;
701 }
702
703 bool WindowTree::ShouldRouteToWindowManager(const ServerWindow* window) const {
704 // If the client created this window, then do not route it through the WM. 695 // If the client created this window, then do not route it through the WM.
705 if (window->id().client_id == id_) 696 if (window->id().client_id == id_)
706 return false; 697 return false;
707 698
708 // If the client did not create the window, then it must be the root of the 699 // If the client did not create the window, then it must be the root of the
709 // client. If not, that means the client should not know about this window, 700 // client. If not, that means the client should not know about this window,
710 // and so do not route the request to the WM. 701 // and so do not route the request to the WM.
711 if (roots_.count(window) == 0) 702 if (roots_.count(window) == 0)
712 return false; 703 return false;
713 704
714 // The WindowManager is attached to the root of the Display, if there isn't a 705 // The WindowManager is attached to the root of the Display, if there isn't a
715 // WindowManager attached no need to route to it. 706 // WindowManager attached no need to route to it.
716 const WindowManagerState* wms = display_manager() 707 const WindowManagerDisplayRoot* display_root =
717 ->GetWindowManagerAndDisplay(window) 708 GetWindowManagerDisplayRoot(window);
718 .window_manager_state; 709 if (!display_root)
719 if (!wms || !wms->tree()->window_manager_internal_)
720 return false; 710 return false;
721 711
722 // Requests coming from the WM should not be routed through the WM again. 712 // Route to the windowmanager if the windowmanager created the window.
723 const bool is_wm = wms->tree() == this; 713 return display_root->window_manager_state()->window_tree()->id() ==
724 return is_wm ? false : true; 714 window->id().client_id;
725 } 715 }
726 716
727 void WindowTree::ProcessLostCapture(const ServerWindow* old_capture_window, 717 void WindowTree::ProcessLostCapture(const ServerWindow* old_capture_window,
728 bool originated_change) { 718 bool originated_change) {
729 if ((originated_change && 719 if ((originated_change &&
730 window_server_->current_operation_type() == 720 window_server_->current_operation_type() ==
731 OperationType::RELEASE_CAPTURE) || 721 OperationType::RELEASE_CAPTURE) ||
732 !IsWindowKnown(old_capture_window)) { 722 !IsWindowKnown(old_capture_window)) {
733 return; 723 return;
734 } 724 }
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 } 960 }
971 961
972 void WindowTree::DispatchInputEventImpl(ServerWindow* target, 962 void WindowTree::DispatchInputEventImpl(ServerWindow* target,
973 const ui::Event& event) { 963 const ui::Event& event) {
974 DCHECK(!event_ack_id_); 964 DCHECK(!event_ack_id_);
975 // We do not want to create a sequential id for each event, because that can 965 // We do not want to create a sequential id for each event, because that can
976 // leak some information to the client. So instead, manufacture the id 966 // leak some information to the client. So instead, manufacture the id
977 // randomly. 967 // randomly.
978 // TODO(moshayedi): Find a faster way to generate ids. 968 // TODO(moshayedi): Find a faster way to generate ids.
979 event_ack_id_ = 0x1000000 | (rand() & 0xffffff); 969 event_ack_id_ = 0x1000000 | (rand() & 0xffffff);
980 event_source_wms_ = GetWindowManagerState(target); 970 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(target);
971 DCHECK(display_root);
972 event_source_wms_ = display_root->window_manager_state();
981 // Should only get events from windows attached to a host. 973 // Should only get events from windows attached to a host.
982 DCHECK(event_source_wms_); 974 DCHECK(event_source_wms_);
983 bool matched_observer = 975 bool matched_observer =
984 event_observer_matcher_ && event_observer_matcher_->MatchesEvent(event); 976 event_observer_matcher_ && event_observer_matcher_->MatchesEvent(event);
985 client()->OnWindowInputEvent( 977 client()->OnWindowInputEvent(
986 event_ack_id_, ClientWindowIdForWindow(target).id, 978 event_ack_id_, ClientWindowIdForWindow(target).id,
987 ui::Event::Clone(event), matched_observer ? event_observer_id_ : 0); 979 ui::Event::Clone(event), matched_observer ? event_observer_id_ : 0);
988 } 980 }
989 981
990 void WindowTree::SendToEventObserver(const ui::Event& event) { 982 void WindowTree::SendToEventObserver(const ui::Event& event) {
(...skipping 18 matching lines...) Expand all
1009 uint32_t change_id, 1001 uint32_t change_id,
1010 Id transport_window_id, 1002 Id transport_window_id,
1011 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { 1003 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) {
1012 DCHECK(!waiting_for_top_level_window_info_); 1004 DCHECK(!waiting_for_top_level_window_info_);
1013 const ClientWindowId client_window_id(transport_window_id); 1005 const ClientWindowId client_window_id(transport_window_id);
1014 // TODO(sky): need a way for client to provide context to figure out display. 1006 // TODO(sky): need a way for client to provide context to figure out display.
1015 Display* display = display_manager()->displays().empty() 1007 Display* display = display_manager()->displays().empty()
1016 ? nullptr 1008 ? nullptr
1017 : *(display_manager()->displays().begin()); 1009 : *(display_manager()->displays().begin());
1018 // TODO(sky): move checks to accesspolicy. 1010 // TODO(sky): move checks to accesspolicy.
1019 WindowManagerState* wms = 1011 WindowManagerDisplayRoot* display_root =
1020 display && user_id_ != InvalidUserId() 1012 display && user_id_ != InvalidUserId()
1021 ? display->GetWindowManagerStateForUser(user_id_) 1013 ? display->GetWindowManagerDisplayRootForUser(user_id_)
1022 : nullptr; 1014 : nullptr;
1023 if (!wms || wms->tree() == this || !IsValidIdForNewWindow(client_window_id)) { 1015 if (!display_root ||
1016 display_root->window_manager_state()->window_tree() == this ||
1017 !IsValidIdForNewWindow(client_window_id)) {
1024 client()->OnChangeCompleted(change_id, false); 1018 client()->OnChangeCompleted(change_id, false);
1025 return; 1019 return;
1026 } 1020 }
1027 1021
1028 // The server creates the real window. Any further messages from the client 1022 // The server creates the real window. Any further messages from the client
1029 // may try to alter the window. Pause incoming messages so that we know we 1023 // may try to alter the window. Pause incoming messages so that we know we
1030 // can't get a message for a window before the window is created. Once the 1024 // can't get a message for a window before the window is created. Once the
1031 // window is created we'll resume processing. 1025 // window is created we'll resume processing.
1032 binding_->SetIncomingMethodCallProcessingPaused(true); 1026 binding_->SetIncomingMethodCallProcessingPaused(true);
1033 1027
1034 const uint32_t wm_change_id = 1028 const uint32_t wm_change_id =
1035 window_server_->GenerateWindowManagerChangeId(this, change_id); 1029 window_server_->GenerateWindowManagerChangeId(this, change_id);
1036 1030
1037 waiting_for_top_level_window_info_.reset( 1031 waiting_for_top_level_window_info_.reset(
1038 new WaitingForTopLevelWindowInfo(client_window_id, wm_change_id)); 1032 new WaitingForTopLevelWindowInfo(client_window_id, wm_change_id));
1039 1033
1040 wms->tree()->window_manager_internal_->WmCreateTopLevelWindow( 1034 display_root->window_manager_state()
1041 wm_change_id, id_, std::move(transport_properties)); 1035 ->window_tree()
1036 ->window_manager_internal_->WmCreateTopLevelWindow(
1037 wm_change_id, id_, std::move(transport_properties));
1042 } 1038 }
1043 1039
1044 void WindowTree::DeleteWindow(uint32_t change_id, Id transport_window_id) { 1040 void WindowTree::DeleteWindow(uint32_t change_id, Id transport_window_id) {
1045 ServerWindow* window = 1041 ServerWindow* window =
1046 GetWindowByClientId(ClientWindowId(transport_window_id)); 1042 GetWindowByClientId(ClientWindowId(transport_window_id));
1047 bool success = false; 1043 bool success = false;
1048 bool should_close = window && (access_policy_->CanDeleteWindow(window) || 1044 bool should_close = window && (access_policy_->CanDeleteWindow(window) ||
1049 ShouldRouteToWindowManager(window)); 1045 ShouldRouteToWindowManager(window));
1050 if (should_close) { 1046 if (should_close) {
1051 WindowTree* tree = 1047 WindowTree* tree =
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 GetWindowTree(ClientWindowId(window_id))); 1121 GetWindowTree(ClientWindowId(window_id)));
1126 callback.Run(WindowsToWindowDatas(windows)); 1122 callback.Run(WindowsToWindowDatas(windows));
1127 } 1123 }
1128 1124
1129 void WindowTree::SetCapture(uint32_t change_id, Id window_id) { 1125 void WindowTree::SetCapture(uint32_t change_id, Id window_id) {
1130 client()->OnChangeCompleted(change_id, SetCapture(ClientWindowId(window_id))); 1126 client()->OnChangeCompleted(change_id, SetCapture(ClientWindowId(window_id)));
1131 } 1127 }
1132 1128
1133 void WindowTree::ReleaseCapture(uint32_t change_id, Id window_id) { 1129 void WindowTree::ReleaseCapture(uint32_t change_id, Id window_id) {
1134 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); 1130 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
1135 WindowManagerState* wms = GetWindowManagerState(window); 1131 WindowManagerDisplayRoot* display_root = GetWindowManagerDisplayRoot(window);
1136 ServerWindow* current_capture_window = wms ? wms->capture_window() : nullptr; 1132 ServerWindow* current_capture_window =
1137 bool success = window && wms && wms->IsActive() && 1133 display_root ? display_root->window_manager_state()->capture_window()
1134 : nullptr;
1135 bool success = window && display_root &&
1136 display_root->window_manager_state()->IsActive() &&
1138 (!current_capture_window || 1137 (!current_capture_window ||
1139 access_policy_->CanSetCapture(current_capture_window)) && 1138 access_policy_->CanSetCapture(current_capture_window)) &&
1140 window == current_capture_window; 1139 window == current_capture_window;
1141 if (success) { 1140 if (success) {
1142 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE); 1141 Operation op(this, window_server_, OperationType::RELEASE_CAPTURE);
1143 success = wms->SetCapture(nullptr, kInvalidClientId); 1142 success = display_root->window_manager_state()->SetCapture(
1143 nullptr, kInvalidClientId);
1144 } 1144 }
1145 client()->OnChangeCompleted(change_id, success); 1145 client()->OnChangeCompleted(change_id, success);
1146 } 1146 }
1147 1147
1148 void WindowTree::SetEventObserver(mojom::EventMatcherPtr matcher, 1148 void WindowTree::SetEventObserver(mojom::EventMatcherPtr matcher,
1149 uint32_t observer_id) { 1149 uint32_t observer_id) {
1150 if (matcher.is_null() || observer_id == 0) { 1150 if (matcher.is_null() || observer_id == 0) {
1151 // Clear any existing event observer. 1151 // Clear any existing event observer.
1152 event_observer_matcher_.reset(); 1152 event_observer_matcher_.reset();
1153 event_observer_id_ = 0; 1153 event_observer_id_ = 0;
(...skipping 29 matching lines...) Expand all
1183 1183
1184 void WindowTree::SetWindowBounds(uint32_t change_id, 1184 void WindowTree::SetWindowBounds(uint32_t change_id,
1185 Id window_id, 1185 Id window_id,
1186 const gfx::Rect& bounds) { 1186 const gfx::Rect& bounds) {
1187 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); 1187 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
1188 if (window && ShouldRouteToWindowManager(window)) { 1188 if (window && ShouldRouteToWindowManager(window)) {
1189 const uint32_t wm_change_id = 1189 const uint32_t wm_change_id =
1190 window_server_->GenerateWindowManagerChangeId(this, change_id); 1190 window_server_->GenerateWindowManagerChangeId(this, change_id);
1191 // |window_id| may be a client id, use the id from the window to ensure 1191 // |window_id| may be a client id, use the id from the window to ensure
1192 // the windowmanager doesn't get an id it doesn't know about. 1192 // the windowmanager doesn't get an id it doesn't know about.
1193 WindowManagerState* wms = display_manager() 1193 WindowManagerDisplayRoot* display_root =
1194 ->GetWindowManagerAndDisplay(window) 1194 GetWindowManagerDisplayRoot(window);
1195 .window_manager_state; 1195 WindowTree* wm_tree = display_root->window_manager_state()->window_tree();
1196 wms->tree()->window_manager_internal_->WmSetBounds( 1196 wm_tree->window_manager_internal_->WmSetBounds(
1197 wm_change_id, wms->tree()->ClientWindowIdForWindow(window).id, 1197 wm_change_id, wm_tree->ClientWindowIdForWindow(window).id,
1198 std::move(bounds)); 1198 std::move(bounds));
1199 return; 1199 return;
1200 } 1200 }
1201 1201
1202 // Only the owner of the window can change the bounds. 1202 // Only the owner of the window can change the bounds.
1203 bool success = window && access_policy_->CanSetWindowBounds(window); 1203 bool success = window && access_policy_->CanSetWindowBounds(window);
1204 if (success) { 1204 if (success) {
1205 Operation op(this, window_server_, OperationType::SET_WINDOW_BOUNDS); 1205 Operation op(this, window_server_, OperationType::SET_WINDOW_BOUNDS);
1206 window->SetBounds(bounds); 1206 window->SetBounds(bounds);
1207 } 1207 }
(...skipping 10 matching lines...) Expand all
1218 1218
1219 void WindowTree::SetWindowProperty(uint32_t change_id, 1219 void WindowTree::SetWindowProperty(uint32_t change_id,
1220 Id transport_window_id, 1220 Id transport_window_id,
1221 const mojo::String& name, 1221 const mojo::String& name,
1222 mojo::Array<uint8_t> value) { 1222 mojo::Array<uint8_t> value) {
1223 ServerWindow* window = 1223 ServerWindow* window =
1224 GetWindowByClientId(ClientWindowId(transport_window_id)); 1224 GetWindowByClientId(ClientWindowId(transport_window_id));
1225 if (window && ShouldRouteToWindowManager(window)) { 1225 if (window && ShouldRouteToWindowManager(window)) {
1226 const uint32_t wm_change_id = 1226 const uint32_t wm_change_id =
1227 window_server_->GenerateWindowManagerChangeId(this, change_id); 1227 window_server_->GenerateWindowManagerChangeId(this, change_id);
1228 WindowManagerState* wms = display_manager() 1228 WindowManagerDisplayRoot* display_root =
1229 ->GetWindowManagerAndDisplay(window) 1229 GetWindowManagerDisplayRoot(window);
1230 .window_manager_state; 1230 WindowTree* wm_tree = display_root->window_manager_state()->window_tree();
1231 wms->tree()->window_manager_internal_->WmSetProperty( 1231 wm_tree->window_manager_internal_->WmSetProperty(
1232 wm_change_id, wms->tree()->ClientWindowIdForWindow(window).id, name, 1232 wm_change_id, wm_tree->ClientWindowIdForWindow(window).id, name,
1233 std::move(value)); 1233 std::move(value));
1234 return; 1234 return;
1235 } 1235 }
1236 const bool success = window && access_policy_->CanSetWindowProperties(window); 1236 const bool success = window && access_policy_->CanSetWindowProperties(window);
1237 if (success) { 1237 if (success) {
1238 Operation op(this, window_server_, OperationType::SET_WINDOW_PROPERTY); 1238 Operation op(this, window_server_, OperationType::SET_WINDOW_PROPERTY);
1239 if (value.is_null()) { 1239 if (value.is_null()) {
1240 window->SetProperty(name, nullptr); 1240 window->SetProperty(name, nullptr);
1241 } else { 1241 } else {
1242 std::vector<uint8_t> data = value.To<std::vector<uint8_t>>(); 1242 std::vector<uint8_t> data = value.To<std::vector<uint8_t>>();
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 1293
1294 void WindowTree::OnWindowInputEventAck(uint32_t event_id, 1294 void WindowTree::OnWindowInputEventAck(uint32_t event_id,
1295 mojom::EventResult result) { 1295 mojom::EventResult result) {
1296 if (event_ack_id_ == 0 || event_id != event_ack_id_) { 1296 if (event_ack_id_ == 0 || event_id != event_ack_id_) {
1297 // TODO(sad): Something bad happened. Kill the client? 1297 // TODO(sad): Something bad happened. Kill the client?
1298 NOTIMPLEMENTED() << "Wrong event acked."; 1298 NOTIMPLEMENTED() << "Wrong event acked.";
1299 } 1299 }
1300 event_ack_id_ = 0; 1300 event_ack_id_ = 0;
1301 1301
1302 if (janky_) 1302 if (janky_)
1303 event_source_wms_->tree()->ClientJankinessChanged(this); 1303 event_source_wms_->window_tree()->ClientJankinessChanged(this);
1304 1304
1305 WindowManagerState* event_source_wms = event_source_wms_; 1305 WindowManagerState* event_source_wms = event_source_wms_;
1306 event_source_wms_ = nullptr; 1306 event_source_wms_ = nullptr;
1307 if (event_source_wms) 1307 if (event_source_wms)
1308 event_source_wms->OnEventAck(this, result); 1308 event_source_wms->OnEventAck(this, result);
1309 1309
1310 if (!event_queue_.empty()) { 1310 if (!event_queue_.empty()) {
1311 DCHECK(!event_ack_id_); 1311 DCHECK(!event_ack_id_);
1312 ServerWindow* target = nullptr; 1312 ServerWindow* target = nullptr;
1313 std::unique_ptr<ui::Event> event; 1313 std::unique_ptr<ui::Event> event;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1401 void WindowTree::GetCursorLocationMemory( 1401 void WindowTree::GetCursorLocationMemory(
1402 const GetCursorLocationMemoryCallback& callback) { 1402 const GetCursorLocationMemoryCallback& callback) {
1403 callback.Run( 1403 callback.Run(
1404 window_server_->display_manager()->GetUserDisplayManager(user_id_)-> 1404 window_server_->display_manager()->GetUserDisplayManager(user_id_)->
1405 GetCursorLocationMemory()); 1405 GetCursorLocationMemory());
1406 } 1406 }
1407 1407
1408 void WindowTree::AddAccelerator(uint32_t id, 1408 void WindowTree::AddAccelerator(uint32_t id,
1409 mojom::EventMatcherPtr event_matcher, 1409 mojom::EventMatcherPtr event_matcher,
1410 const AddAcceleratorCallback& callback) { 1410 const AddAcceleratorCallback& callback) {
1411 WindowManagerState* wms = GetWindowManagerStateForWindowManager(); 1411 DCHECK(window_manager_state_);
1412 const bool success = 1412 const bool success =
1413 wms->event_dispatcher()->AddAccelerator(id, std::move(event_matcher)); 1413 window_manager_state_->event_dispatcher()->AddAccelerator(
1414 id, std::move(event_matcher));
1414 callback.Run(success); 1415 callback.Run(success);
1415 } 1416 }
1416 1417
1417 void WindowTree::RemoveAccelerator(uint32_t id) { 1418 void WindowTree::RemoveAccelerator(uint32_t id) {
1418 WindowManagerState* wms = GetWindowManagerStateForWindowManager(); 1419 window_manager_state_->event_dispatcher()->RemoveAccelerator(id);
1419 wms->event_dispatcher()->RemoveAccelerator(id);
1420 } 1420 }
1421 1421
1422 void WindowTree::AddActivationParent(Id transport_window_id) { 1422 void WindowTree::AddActivationParent(Id transport_window_id) {
1423 AddActivationParent(ClientWindowId(transport_window_id)); 1423 AddActivationParent(ClientWindowId(transport_window_id));
1424 } 1424 }
1425 1425
1426 void WindowTree::RemoveActivationParent(Id transport_window_id) { 1426 void WindowTree::RemoveActivationParent(Id transport_window_id) {
1427 ServerWindow* window = 1427 ServerWindow* window =
1428 GetWindowByClientId(ClientWindowId(transport_window_id)); 1428 GetWindowByClientId(ClientWindowId(transport_window_id));
1429 if (window) { 1429 if (window) {
1430 Display* display = GetDisplay(window); 1430 Display* display = GetDisplay(window);
1431 if (display) 1431 if (display)
1432 display->RemoveActivationParent(window); 1432 display->RemoveActivationParent(window);
1433 else 1433 else
1434 DVLOG(1) << "RemoveActivationParent window not associated with display"; 1434 DVLOG(1) << "RemoveActivationParent window not associated with display";
1435 } else { 1435 } else {
1436 DVLOG(1) << "RemoveActivationParent supplied invalid window id"; 1436 DVLOG(1) << "RemoveActivationParent supplied invalid window id";
1437 } 1437 }
1438 } 1438 }
1439 1439
1440 void WindowTree::ActivateNextWindow() { 1440 void WindowTree::ActivateNextWindow() {
1441 // TODO(sky): this needs to track active window. http://crbug.com/611563. 1441 DCHECK(window_manager_state_);
1442 GetWindowManagerStateForWindowManager()->display()->ActivateNextWindow(); 1442 if (window_server_->user_id_tracker()->active_id() != user_id_)
1443 return;
1444
1445 ServerWindow* focused_window = window_server_->GetFocusedWindow();
1446 if (focused_window) {
1447 WindowManagerDisplayRoot* display_root =
1448 GetWindowManagerDisplayRoot(focused_window);
1449 if (display_root->window_manager_state() != window_manager_state_.get()) {
1450 // We aren't active.
1451 return;
1452 }
1453 display_root->display()->ActivateNextWindow();
1454 return;
1455 }
1456 // Use the first display.
1457 std::set<Display*> displays = window_server_->display_manager()->displays();
1458 if (displays.empty())
1459 return;
1460
1461 (*displays.begin())->ActivateNextWindow();
1443 } 1462 }
1444 1463
1445 void WindowTree::SetUnderlaySurfaceOffsetAndExtendedHitArea( 1464 void WindowTree::SetUnderlaySurfaceOffsetAndExtendedHitArea(
1446 Id window_id, 1465 Id window_id,
1447 int32_t x_offset, 1466 int32_t x_offset,
1448 int32_t y_offset, 1467 int32_t y_offset,
1449 const gfx::Insets& hit_area) { 1468 const gfx::Insets& hit_area) {
1450 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); 1469 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
1451 if (!window) 1470 if (!window)
1452 return; 1471 return;
(...skipping 11 matching lines...) Expand all
1464 GetWindowByClientId(ClientWindowId(transport_window_id)); 1483 GetWindowByClientId(ClientWindowId(transport_window_id));
1465 WindowTree* tree = window_server_->GetTreeWithRoot(window); 1484 WindowTree* tree = window_server_->GetTreeWithRoot(window);
1466 if (tree && tree != this) { 1485 if (tree && tree != this) {
1467 tree->client()->RequestClose(tree->ClientWindowIdForWindow(window).id); 1486 tree->client()->RequestClose(tree->ClientWindowIdForWindow(window).id);
1468 } 1487 }
1469 // TODO(sky): think about what else case means. 1488 // TODO(sky): think about what else case means.
1470 } 1489 }
1471 1490
1472 void WindowTree::WmSetFrameDecorationValues( 1491 void WindowTree::WmSetFrameDecorationValues(
1473 mojom::FrameDecorationValuesPtr values) { 1492 mojom::FrameDecorationValuesPtr values) {
1474 DCHECK(global_window_manager_state_); 1493 DCHECK(window_manager_state_);
1475 global_window_manager_state_->SetFrameDecorationValues(std::move(values)); 1494 window_manager_state_->SetFrameDecorationValues(std::move(values));
1476 } 1495 }
1477 1496
1478 void WindowTree::WmSetNonClientCursor(uint32_t window_id, 1497 void WindowTree::WmSetNonClientCursor(uint32_t window_id,
1479 mojom::Cursor cursor_id) { 1498 mojom::Cursor cursor_id) {
1480 WindowManagerState* wm_state = GetWindowManagerStateForWindowManager(); 1499 DCHECK(window_manager_state_);
1481 if (wm_state) { 1500 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
1482 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); 1501 if (window) {
1483 if (window) 1502 window->SetNonClientCursor(cursor_id);
1484 window->SetNonClientCursor(cursor_id); 1503 } else {
1504 DVLOG(1) << "trying to update non-client cursor of invalid window";
1485 } 1505 }
1486 } 1506 }
1487 1507
1488 void WindowTree::OnWmCreatedTopLevelWindow(uint32_t change_id, 1508 void WindowTree::OnWmCreatedTopLevelWindow(uint32_t change_id,
1489 Id transport_window_id) { 1509 Id transport_window_id) {
1490 ServerWindow* window = 1510 ServerWindow* window =
1491 GetWindowByClientId(ClientWindowId(transport_window_id)); 1511 GetWindowByClientId(ClientWindowId(transport_window_id));
1492 if (window && window->id().client_id != id_) { 1512 if (window && window->id().client_id != id_) {
1493 DVLOG(1) << "OnWmCreatedTopLevelWindow supplied invalid window id"; 1513 DVLOG(1) << "OnWmCreatedTopLevelWindow supplied invalid window id";
1494 window_server_->WindowManagerSentBogusMessage(); 1514 window_server_->WindowManagerSentBogusMessage();
(...skipping 12 matching lines...) Expand all
1507 } 1527 }
1508 1528
1509 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( 1529 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy(
1510 const ServerWindow* window) const { 1530 const ServerWindow* window) const {
1511 WindowTree* tree = window_server_->GetTreeWithRoot(window); 1531 WindowTree* tree = window_server_->GetTreeWithRoot(window);
1512 return tree && tree != this; 1532 return tree && tree != this;
1513 } 1533 }
1514 1534
1515 } // namespace ws 1535 } // namespace ws
1516 } // namespace mus 1536 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/window_tree.h ('k') | components/mus/ws/window_tree_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698