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

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

Issue 1766943002: Refators display related functionality into own class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 4 years, 9 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') | no next file » | 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 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/stl_util.h" 12 #include "base/stl_util.h"
13 #include "components/mus/ws/connection_manager.h" 13 #include "components/mus/ws/connection_manager.h"
14 #include "components/mus/ws/default_access_policy.h" 14 #include "components/mus/ws/default_access_policy.h"
15 #include "components/mus/ws/display.h" 15 #include "components/mus/ws/display.h"
16 #include "components/mus/ws/display_manager.h"
16 #include "components/mus/ws/focus_controller.h" 17 #include "components/mus/ws/focus_controller.h"
17 #include "components/mus/ws/operation.h" 18 #include "components/mus/ws/operation.h"
18 #include "components/mus/ws/platform_display.h" 19 #include "components/mus/ws/platform_display.h"
19 #include "components/mus/ws/server_window.h" 20 #include "components/mus/ws/server_window.h"
20 #include "components/mus/ws/server_window_observer.h" 21 #include "components/mus/ws/server_window_observer.h"
21 #include "components/mus/ws/window_manager_access_policy.h" 22 #include "components/mus/ws/window_manager_access_policy.h"
22 #include "components/mus/ws/window_manager_state.h" 23 #include "components/mus/ws/window_manager_state.h"
23 #include "components/mus/ws/window_tree_binding.h" 24 #include "components/mus/ws/window_tree_binding.h"
24 #include "mojo/converters/geometry/geometry_type_converters.h" 25 #include "mojo/converters/geometry/geometry_type_converters.h"
25 #include "mojo/converters/ime/ime_type_converters.h" 26 #include "mojo/converters/ime/ime_type_converters.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 } 148 }
148 149
149 const ServerWindow* WindowTree::GetWindowByClientId( 150 const ServerWindow* WindowTree::GetWindowByClientId(
150 const ClientWindowId& id) const { 151 const ClientWindowId& id) const {
151 auto iter = client_id_to_window_id_map_.find(id); 152 auto iter = client_id_to_window_id_map_.find(id);
152 return iter == client_id_to_window_id_map_.end() ? nullptr 153 return iter == client_id_to_window_id_map_.end() ? nullptr
153 : GetWindow(iter->second); 154 : GetWindow(iter->second);
154 } 155 }
155 156
156 const Display* WindowTree::GetDisplay(const ServerWindow* window) const { 157 const Display* WindowTree::GetDisplay(const ServerWindow* window) const {
157 return window ? connection_manager_->GetDisplayContaining(window) : nullptr; 158 return window ? display_manager()->GetDisplayContaining(window) : nullptr;
158 } 159 }
159 160
160 void WindowTree::OnWindowDestroyingTreeImpl(WindowTree* tree) { 161 void WindowTree::OnWindowDestroyingTreeImpl(WindowTree* tree) {
161 // Notify our client if |tree| was embedded in any of our views. 162 // Notify our client if |tree| was embedded in any of our views.
162 for (const auto* tree_root : tree->roots_) { 163 for (const auto* tree_root : tree->roots_) {
163 const bool owns_tree_root = tree_root->id().connection_id == id_; 164 const bool owns_tree_root = tree_root->id().connection_id == id_;
164 if (owns_tree_root || (is_embed_root_ && IsWindowKnown(tree_root))) { 165 if (owns_tree_root || (is_embed_root_ && IsWindowKnown(tree_root))) {
165 client()->OnEmbeddedAppDisconnected( 166 client()->OnEmbeddedAppDisconnected(
166 ClientWindowIdForWindow(tree_root).id); 167 ClientWindowIdForWindow(tree_root).id);
167 } 168 }
(...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after
556 return; 557 return;
557 ClientWindowId client_window_id, transient_client_window_id; 558 ClientWindowId client_window_id, transient_client_window_id;
558 if (!IsWindowKnown(window, &client_window_id) || 559 if (!IsWindowKnown(window, &client_window_id) ||
559 !IsWindowKnown(transient_window, &transient_client_window_id)) { 560 !IsWindowKnown(transient_window, &transient_client_window_id)) {
560 return; 561 return;
561 } 562 }
562 client()->OnTransientWindowRemoved(client_window_id.id, 563 client()->OnTransientWindowRemoved(client_window_id.id,
563 transient_client_window_id.id); 564 transient_client_window_id.id);
564 } 565 }
565 566
567 DisplayManager* WindowTree::display_manager() {
568 return connection_manager_->display_manager();
569 }
570
571 const DisplayManager* WindowTree::display_manager() const {
572 return connection_manager_->display_manager();
573 }
574
566 Display* WindowTree::GetDisplayForWindowManager() { 575 Display* WindowTree::GetDisplayForWindowManager() {
567 // The WindowTree for the wm has one and only one root. 576 // The WindowTree for the wm has one and only one root.
568 CHECK_EQ(1u, roots_.size()); 577 CHECK_EQ(1u, roots_.size());
569 578
570 // Indicates this connection is for the wm. 579 // Indicates this connection is for the wm.
571 DCHECK(window_manager_internal_); 580 DCHECK(window_manager_internal_);
572 581
573 Display* display = GetDisplay(*roots_.begin()); 582 Display* display = GetDisplay(*roots_.begin());
574 WindowManagerAndDisplay wm_and_display = 583 WindowManagerAndDisplay wm_and_display =
575 connection_manager_->GetWindowManagerAndDisplay(*roots_.begin()); 584 display_manager()->GetWindowManagerAndDisplay(*roots_.begin());
576 CHECK(wm_and_display.display); 585 CHECK(wm_and_display.display);
577 CHECK(wm_and_display.window_manager_state); 586 CHECK(wm_and_display.window_manager_state);
578 DCHECK_EQ(this, wm_and_display.window_manager_state->tree()); 587 DCHECK_EQ(this, wm_and_display.window_manager_state->tree());
579 return display; 588 return display;
580 } 589 }
581 590
582 bool WindowTree::ShouldRouteToWindowManager(const ServerWindow* window) const { 591 bool WindowTree::ShouldRouteToWindowManager(const ServerWindow* window) const {
583 // If the client created this window, then do not route it through the WM. 592 // If the client created this window, then do not route it through the WM.
584 if (window->id().connection_id == id_) 593 if (window->id().connection_id == id_)
585 return false; 594 return false;
586 595
587 // If the client did not create the window, then it must be the root of the 596 // If the client did not create the window, then it must be the root of the
588 // client. If not, that means the client should not know about this window, 597 // client. If not, that means the client should not know about this window,
589 // and so do not route the request to the WM. 598 // and so do not route the request to the WM.
590 if (roots_.count(window) == 0) 599 if (roots_.count(window) == 0)
591 return false; 600 return false;
592 601
593 // The WindowManager is attached to the root of the Display, if there isn't a 602 // The WindowManager is attached to the root of the Display, if there isn't a
594 // WindowManager attached no need to route to it. 603 // WindowManager attached no need to route to it.
595 const WindowManagerState* wms = 604 const WindowManagerState* wms = display_manager()
596 connection_manager_->GetWindowManagerAndDisplay(window) 605 ->GetWindowManagerAndDisplay(window)
597 .window_manager_state; 606 .window_manager_state;
598 if (!wms || !wms->tree()->window_manager_internal_) 607 if (!wms || !wms->tree()->window_manager_internal_)
599 return false; 608 return false;
600 609
601 // Requests coming from the WM should not be routed through the WM again. 610 // Requests coming from the WM should not be routed through the WM again.
602 const bool is_wm = wms->tree() == this; 611 const bool is_wm = wms->tree() == this;
603 return is_wm ? false : true; 612 return is_wm ? false : true;
604 } 613 }
605 614
606 void WindowTree::ProcessLostCapture(const ServerWindow* old_capture_window, 615 void WindowTree::ProcessLostCapture(const ServerWindow* old_capture_window,
607 bool originated_change) { 616 bool originated_change) {
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
884 client()->OnChangeCompleted( 893 client()->OnChangeCompleted(
885 change_id, NewWindow(ClientWindowId(transport_window_id), properties)); 894 change_id, NewWindow(ClientWindowId(transport_window_id), properties));
886 } 895 }
887 896
888 void WindowTree::NewTopLevelWindow( 897 void WindowTree::NewTopLevelWindow(
889 uint32_t change_id, 898 uint32_t change_id,
890 Id transport_window_id, 899 Id transport_window_id,
891 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { 900 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) {
892 DCHECK(!waiting_for_top_level_window_info_); 901 DCHECK(!waiting_for_top_level_window_info_);
893 const ClientWindowId client_window_id(transport_window_id); 902 const ClientWindowId client_window_id(transport_window_id);
894 Display* display = connection_manager_->GetActiveDisplay(); 903 Display* display = display_manager()->GetActiveDisplay();
895 // TODO(sky): need a way for client to provide context. 904 // TODO(sky): need a way for client to provide context.
896 WindowManagerState* wms = 905 WindowManagerState* wms =
897 display ? display->GetFirstWindowManagerState() : nullptr; 906 display ? display->GetFirstWindowManagerState() : nullptr;
898 if (!wms || wms->tree() == this || !IsValidIdForNewWindow(client_window_id)) { 907 if (!wms || wms->tree() == this || !IsValidIdForNewWindow(client_window_id)) {
899 client()->OnChangeCompleted(change_id, false); 908 client()->OnChangeCompleted(change_id, false);
900 return; 909 return;
901 } 910 }
902 911
903 // The server creates the real window. Any further messages from the client 912 // The server creates the real window. Any further messages from the client
904 // may try to alter the window. Pause incoming messages so that we know we 913 // may try to alter the window. Pause incoming messages so that we know we
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 1041
1033 void WindowTree::SetWindowBounds(uint32_t change_id, 1042 void WindowTree::SetWindowBounds(uint32_t change_id,
1034 Id window_id, 1043 Id window_id,
1035 mojo::RectPtr bounds) { 1044 mojo::RectPtr bounds) {
1036 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); 1045 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
1037 if (window && ShouldRouteToWindowManager(window)) { 1046 if (window && ShouldRouteToWindowManager(window)) {
1038 const uint32_t wm_change_id = 1047 const uint32_t wm_change_id =
1039 connection_manager_->GenerateWindowManagerChangeId(this, change_id); 1048 connection_manager_->GenerateWindowManagerChangeId(this, change_id);
1040 // |window_id| may be a client id, use the id from the window to ensure 1049 // |window_id| may be a client id, use the id from the window to ensure
1041 // the windowmanager doesn't get an id it doesn't know about. 1050 // the windowmanager doesn't get an id it doesn't know about.
1042 WindowManagerState* wms = 1051 WindowManagerState* wms = display_manager()
1043 connection_manager_->GetWindowManagerAndDisplay(window) 1052 ->GetWindowManagerAndDisplay(window)
1044 .window_manager_state; 1053 .window_manager_state;
1045 wms->tree()->window_manager_internal_->WmSetBounds( 1054 wms->tree()->window_manager_internal_->WmSetBounds(
1046 wm_change_id, wms->tree()->ClientWindowIdForWindow(window).id, 1055 wm_change_id, wms->tree()->ClientWindowIdForWindow(window).id,
1047 std::move(bounds)); 1056 std::move(bounds));
1048 return; 1057 return;
1049 } 1058 }
1050 1059
1051 // Only the owner of the window can change the bounds. 1060 // Only the owner of the window can change the bounds.
1052 bool success = window && access_policy_->CanSetWindowBounds(window); 1061 bool success = window && access_policy_->CanSetWindowBounds(window);
1053 if (success) { 1062 if (success) {
1054 Operation op(this, connection_manager_, OperationType::SET_WINDOW_BOUNDS); 1063 Operation op(this, connection_manager_, OperationType::SET_WINDOW_BOUNDS);
(...skipping 12 matching lines...) Expand all
1067 1076
1068 void WindowTree::SetWindowProperty(uint32_t change_id, 1077 void WindowTree::SetWindowProperty(uint32_t change_id,
1069 Id transport_window_id, 1078 Id transport_window_id,
1070 const mojo::String& name, 1079 const mojo::String& name,
1071 mojo::Array<uint8_t> value) { 1080 mojo::Array<uint8_t> value) {
1072 ServerWindow* window = 1081 ServerWindow* window =
1073 GetWindowByClientId(ClientWindowId(transport_window_id)); 1082 GetWindowByClientId(ClientWindowId(transport_window_id));
1074 if (window && ShouldRouteToWindowManager(window)) { 1083 if (window && ShouldRouteToWindowManager(window)) {
1075 const uint32_t wm_change_id = 1084 const uint32_t wm_change_id =
1076 connection_manager_->GenerateWindowManagerChangeId(this, change_id); 1085 connection_manager_->GenerateWindowManagerChangeId(this, change_id);
1077 WindowManagerState* wms = 1086 WindowManagerState* wms = display_manager()
1078 connection_manager_->GetWindowManagerAndDisplay(window) 1087 ->GetWindowManagerAndDisplay(window)
1079 .window_manager_state; 1088 .window_manager_state;
1080 wms->tree()->window_manager_internal_->WmSetProperty( 1089 wms->tree()->window_manager_internal_->WmSetProperty(
1081 wm_change_id, wms->tree()->ClientWindowIdForWindow(window).id, name, 1090 wm_change_id, wms->tree()->ClientWindowIdForWindow(window).id, name,
1082 std::move(value)); 1091 std::move(value));
1083 return; 1092 return;
1084 } 1093 }
1085 const bool success = window && access_policy_->CanSetWindowProperties(window); 1094 const bool success = window && access_policy_->CanSetWindowProperties(window);
1086 if (success) { 1095 if (success) {
1087 Operation op(this, connection_manager_, OperationType::SET_WINDOW_PROPERTY); 1096 Operation op(this, connection_manager_, OperationType::SET_WINDOW_PROPERTY);
1088 if (value.is_null()) { 1097 if (value.is_null()) {
1089 window->SetProperty(name, nullptr); 1098 window->SetProperty(name, nullptr);
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 1367
1359 for (const auto* root : roots_) { 1368 for (const auto* root : roots_) {
1360 if (root->Contains(window)) 1369 if (root->Contains(window))
1361 return true; 1370 return true;
1362 } 1371 }
1363 return false; 1372 return false;
1364 } 1373 }
1365 1374
1366 } // namespace ws 1375 } // namespace ws
1367 } // namespace mus 1376 } // namespace mus
OLDNEW
« no previous file with comments | « components/mus/ws/window_tree.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698