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

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

Issue 2008193002: Change mojo geometry structs from using type converters to StructTraits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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/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/ws/default_access_policy.h" 15 #include "components/mus/ws/default_access_policy.h"
16 #include "components/mus/ws/display.h" 16 #include "components/mus/ws/display.h"
17 #include "components/mus/ws/display_manager.h" 17 #include "components/mus/ws/display_manager.h"
18 #include "components/mus/ws/event_matcher.h" 18 #include "components/mus/ws/event_matcher.h"
19 #include "components/mus/ws/focus_controller.h" 19 #include "components/mus/ws/focus_controller.h"
20 #include "components/mus/ws/operation.h" 20 #include "components/mus/ws/operation.h"
21 #include "components/mus/ws/platform_display.h" 21 #include "components/mus/ws/platform_display.h"
22 #include "components/mus/ws/server_window.h" 22 #include "components/mus/ws/server_window.h"
23 #include "components/mus/ws/server_window_observer.h" 23 #include "components/mus/ws/server_window_observer.h"
24 #include "components/mus/ws/user_display_manager.h" 24 #include "components/mus/ws/user_display_manager.h"
25 #include "components/mus/ws/window_manager_state.h" 25 #include "components/mus/ws/window_manager_state.h"
26 #include "components/mus/ws/window_server.h" 26 #include "components/mus/ws/window_server.h"
27 #include "components/mus/ws/window_tree_binding.h" 27 #include "components/mus/ws/window_tree_binding.h"
28 #include "mojo/converters/geometry/geometry_type_converters.h"
29 #include "mojo/converters/ime/ime_type_converters.h" 28 #include "mojo/converters/ime/ime_type_converters.h"
30 #include "mojo/converters/input_events/input_events_type_converters.h" 29 #include "mojo/converters/input_events/input_events_type_converters.h"
31 #include "mojo/converters/surfaces/surfaces_type_converters.h" 30 #include "mojo/converters/surfaces/surfaces_type_converters.h"
32 #include "ui/platform_window/text_input_state.h" 31 #include "ui/platform_window/text_input_state.h"
33 32
34 using mojo::Array; 33 using mojo::Array;
35 using mojo::Callback; 34 using mojo::Callback;
36 using mojo::InterfaceRequest; 35 using mojo::InterfaceRequest;
37 using mojo::Rect;
38 using mojo::String; 36 using mojo::String;
39 37
40 namespace mus { 38 namespace mus {
41 namespace ws { 39 namespace ws {
42 40
43 class TargetedEvent : public ServerWindowObserver { 41 class TargetedEvent : public ServerWindowObserver {
44 public: 42 public:
45 TargetedEvent(ServerWindow* target, const ui::Event& event) 43 TargetedEvent(ServerWindow* target, const ui::Event& event)
46 : target_(target), event_(ui::Event::Clone(event)) { 44 : target_(target), event_(ui::Event::Clone(event)) {
47 target_->AddObserver(this); 45 target_->AddObserver(this);
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 } 405 }
408 } 406 }
409 407
410 void WindowTree::ProcessWindowBoundsChanged(const ServerWindow* window, 408 void WindowTree::ProcessWindowBoundsChanged(const ServerWindow* window,
411 const gfx::Rect& old_bounds, 409 const gfx::Rect& old_bounds,
412 const gfx::Rect& new_bounds, 410 const gfx::Rect& new_bounds,
413 bool originated_change) { 411 bool originated_change) {
414 ClientWindowId client_window_id; 412 ClientWindowId client_window_id;
415 if (originated_change || !IsWindowKnown(window, &client_window_id)) 413 if (originated_change || !IsWindowKnown(window, &client_window_id))
416 return; 414 return;
417 client()->OnWindowBoundsChanged(client_window_id.id, Rect::From(old_bounds), 415 client()->OnWindowBoundsChanged(client_window_id.id, old_bounds, new_bounds);
418 Rect::From(new_bounds));
419 } 416 }
420 417
421 void WindowTree::ProcessClientAreaChanged( 418 void WindowTree::ProcessClientAreaChanged(
422 const ServerWindow* window, 419 const ServerWindow* window,
423 const gfx::Insets& new_client_area, 420 const gfx::Insets& new_client_area,
424 const std::vector<gfx::Rect>& new_additional_client_areas, 421 const std::vector<gfx::Rect>& new_additional_client_areas,
425 bool originated_change) { 422 bool originated_change) {
426 ClientWindowId client_window_id; 423 ClientWindowId client_window_id;
427 if (originated_change || !IsWindowKnown(window, &client_window_id)) 424 if (originated_change || !IsWindowKnown(window, &client_window_id))
428 return; 425 return;
429 client()->OnClientAreaChanged( 426 client()->OnClientAreaChanged(
430 client_window_id.id, mojo::Insets::From(new_client_area), 427 client_window_id.id, new_client_area,
431 mojo::Array<mojo::RectPtr>::From(new_additional_client_areas)); 428 std::vector<gfx::Rect>(new_additional_client_areas));
432 } 429 }
433 430
434 void WindowTree::ProcessViewportMetricsChanged( 431 void WindowTree::ProcessViewportMetricsChanged(
435 Display* display, 432 Display* display,
436 const mojom::ViewportMetrics& old_metrics, 433 const mojom::ViewportMetrics& old_metrics,
437 const mojom::ViewportMetrics& new_metrics, 434 const mojom::ViewportMetrics& new_metrics,
438 bool originated_change) { 435 bool originated_change) {
439 mojo::Array<Id> window_ids; 436 mojo::Array<Id> window_ids;
440 for (const ServerWindow* root : roots_) { 437 for (const ServerWindow* root : roots_) {
441 if (GetDisplay(root) == display) { 438 if (GetDisplay(root) == display) {
(...skipping 431 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 const ServerWindow* parent = window->parent(); 870 const ServerWindow* parent = window->parent();
874 // If the parent isn't known, it means the parent is not visible to us (not 871 // If the parent isn't known, it means the parent is not visible to us (not
875 // in roots), and should not be sent over. 872 // in roots), and should not be sent over.
876 if (parent && !IsWindowKnown(parent)) 873 if (parent && !IsWindowKnown(parent))
877 parent = nullptr; 874 parent = nullptr;
878 mojom::WindowDataPtr window_data(mojom::WindowData::New()); 875 mojom::WindowDataPtr window_data(mojom::WindowData::New());
879 window_data->parent_id = 876 window_data->parent_id =
880 parent ? ClientWindowIdForWindow(parent).id : ClientWindowId().id; 877 parent ? ClientWindowIdForWindow(parent).id : ClientWindowId().id;
881 window_data->window_id = 878 window_data->window_id =
882 window ? ClientWindowIdForWindow(window).id : ClientWindowId().id; 879 window ? ClientWindowIdForWindow(window).id : ClientWindowId().id;
883 window_data->bounds = Rect::From(window->bounds()); 880 window_data->bounds = window->bounds();
884 window_data->properties = 881 window_data->properties =
885 mojo::Map<String, Array<uint8_t>>::From(window->properties()); 882 mojo::Map<String, Array<uint8_t>>::From(window->properties());
886 window_data->visible = window->visible(); 883 window_data->visible = window->visible();
887 window_data->viewport_metrics = 884 window_data->viewport_metrics =
888 window_server_->GetViewportMetricsForWindow(window); 885 window_server_->GetViewportMetricsForWindow(window);
889 return window_data; 886 return window_data;
890 } 887 }
891 888
892 void WindowTree::GetWindowTreeImpl( 889 void WindowTree::GetWindowTreeImpl(
893 const ServerWindow* window, 890 const ServerWindow* window,
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 DVLOG(1) << "SetEventObserver event type not allowed"; 1176 DVLOG(1) << "SetEventObserver event type not allowed";
1180 return; 1177 return;
1181 } 1178 }
1182 1179
1183 event_observer_matcher_.reset(new EventMatcher(*matcher)); 1180 event_observer_matcher_.reset(new EventMatcher(*matcher));
1184 event_observer_id_ = observer_id; 1181 event_observer_id_ = observer_id;
1185 } 1182 }
1186 1183
1187 void WindowTree::SetWindowBounds(uint32_t change_id, 1184 void WindowTree::SetWindowBounds(uint32_t change_id,
1188 Id window_id, 1185 Id window_id,
1189 mojo::RectPtr bounds) { 1186 const gfx::Rect& bounds) {
1190 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); 1187 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
1191 if (window && ShouldRouteToWindowManager(window)) { 1188 if (window && ShouldRouteToWindowManager(window)) {
1192 const uint32_t wm_change_id = 1189 const uint32_t wm_change_id =
1193 window_server_->GenerateWindowManagerChangeId(this, change_id); 1190 window_server_->GenerateWindowManagerChangeId(this, change_id);
1194 // |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
1195 // 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.
1196 WindowManagerState* wms = display_manager() 1193 WindowManagerState* wms = display_manager()
1197 ->GetWindowManagerAndDisplay(window) 1194 ->GetWindowManagerAndDisplay(window)
1198 .window_manager_state; 1195 .window_manager_state;
1199 wms->tree()->window_manager_internal_->WmSetBounds( 1196 wms->tree()->window_manager_internal_->WmSetBounds(
1200 wm_change_id, wms->tree()->ClientWindowIdForWindow(window).id, 1197 wm_change_id, wms->tree()->ClientWindowIdForWindow(window).id,
1201 std::move(bounds)); 1198 std::move(bounds));
1202 return; 1199 return;
1203 } 1200 }
1204 1201
1205 // Only the owner of the window can change the bounds. 1202 // Only the owner of the window can change the bounds.
1206 bool success = window && access_policy_->CanSetWindowBounds(window); 1203 bool success = window && access_policy_->CanSetWindowBounds(window);
1207 if (success) { 1204 if (success) {
1208 Operation op(this, window_server_, OperationType::SET_WINDOW_BOUNDS); 1205 Operation op(this, window_server_, OperationType::SET_WINDOW_BOUNDS);
1209 window->SetBounds(bounds.To<gfx::Rect>()); 1206 window->SetBounds(bounds);
1210 } 1207 }
1211 client()->OnChangeCompleted(change_id, success); 1208 client()->OnChangeCompleted(change_id, success);
1212 } 1209 }
1213 1210
1214 void WindowTree::SetWindowVisibility(uint32_t change_id, 1211 void WindowTree::SetWindowVisibility(uint32_t change_id,
1215 Id transport_window_id, 1212 Id transport_window_id,
1216 bool visible) { 1213 bool visible) {
1217 client()->OnChangeCompleted( 1214 client()->OnChangeCompleted(
1218 change_id, 1215 change_id,
1219 SetWindowVisibility(ClientWindowId(transport_window_id), visible)); 1216 SetWindowVisibility(ClientWindowId(transport_window_id), visible));
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
1321 target = targeted_event->target(); 1318 target = targeted_event->target();
1322 event = targeted_event->TakeEvent(); 1319 event = targeted_event->TakeEvent();
1323 } while (!event_queue_.empty() && !GetDisplay(target)); 1320 } while (!event_queue_.empty() && !GetDisplay(target));
1324 if (target) 1321 if (target)
1325 DispatchInputEventImpl(target, *event); 1322 DispatchInputEventImpl(target, *event);
1326 } 1323 }
1327 } 1324 }
1328 1325
1329 void WindowTree::SetClientArea( 1326 void WindowTree::SetClientArea(
1330 Id transport_window_id, 1327 Id transport_window_id,
1331 mojo::InsetsPtr insets, 1328 const gfx::Insets& insets,
1332 mojo::Array<mojo::RectPtr> transport_additional_client_areas) { 1329 mojo::Array<gfx::Rect> transport_additional_client_areas) {
1333 ServerWindow* window = 1330 ServerWindow* window =
1334 GetWindowByClientId(ClientWindowId(transport_window_id)); 1331 GetWindowByClientId(ClientWindowId(transport_window_id));
1335 if (!window || !access_policy_->CanSetClientArea(window)) 1332 if (!window || !access_policy_->CanSetClientArea(window))
1336 return; 1333 return;
1337 1334
1338 std::vector<gfx::Rect> additional_client_areas = 1335 std::vector<gfx::Rect> additional_client_areas =
1339 transport_additional_client_areas.To<std::vector<gfx::Rect>>(); 1336 transport_additional_client_areas.To<std::vector<gfx::Rect>>();
1340 window->SetClientArea(insets.To<gfx::Insets>(), additional_client_areas); 1337 window->SetClientArea(insets, additional_client_areas);
1341 } 1338 }
1342 1339
1343 void WindowTree::SetHitTestMask(Id transport_window_id, mojo::RectPtr mask) { 1340 void WindowTree::SetHitTestMask(Id transport_window_id, const gfx::Rect& mask) {
1344 ServerWindow* window = 1341 ServerWindow* window =
1345 GetWindowByClientId(ClientWindowId(transport_window_id)); 1342 GetWindowByClientId(ClientWindowId(transport_window_id));
1346 if (!window || !access_policy_->CanSetHitTestMask(window)) { 1343 if (!window || !access_policy_->CanSetHitTestMask(window)) {
1347 DVLOG(1) << "SetHitTestMask failed"; 1344 DVLOG(1) << "SetHitTestMask failed";
1348 return; 1345 return;
1349 } 1346 }
1350 1347
1351 if (mask) 1348 if (!mask.IsEmpty())
1352 window->SetHitTestMask(mask.To<gfx::Rect>()); 1349 window->SetHitTestMask(mask);
1353 else 1350 else
1354 window->ClearHitTestMask(); 1351 window->ClearHitTestMask();
1355 } 1352 }
1356 1353
1357 void WindowTree::Embed(Id transport_window_id, 1354 void WindowTree::Embed(Id transport_window_id,
1358 mojom::WindowTreeClientPtr client, 1355 mojom::WindowTreeClientPtr client,
1359 const EmbedCallback& callback) { 1356 const EmbedCallback& callback) {
1360 callback.Run(Embed(ClientWindowId(transport_window_id), std::move(client))); 1357 callback.Run(Embed(ClientWindowId(transport_window_id), std::move(client)));
1361 } 1358 }
1362 1359
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
1440 Display* display = GetDisplayForWindowManager(); 1437 Display* display = GetDisplayForWindowManager();
1441 if (!display) 1438 if (!display)
1442 return; 1439 return;
1443 display->ActivateNextWindow(); 1440 display->ActivateNextWindow();
1444 } 1441 }
1445 1442
1446 void WindowTree::SetUnderlaySurfaceOffsetAndExtendedHitArea( 1443 void WindowTree::SetUnderlaySurfaceOffsetAndExtendedHitArea(
1447 Id window_id, 1444 Id window_id,
1448 int32_t x_offset, 1445 int32_t x_offset,
1449 int32_t y_offset, 1446 int32_t y_offset,
1450 mojo::InsetsPtr hit_area) { 1447 const gfx::Insets& hit_area) {
1451 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id)); 1448 ServerWindow* window = GetWindowByClientId(ClientWindowId(window_id));
1452 if (!window) 1449 if (!window)
1453 return; 1450 return;
1454 1451
1455 window->SetUnderlayOffset(gfx::Vector2d(x_offset, y_offset)); 1452 window->SetUnderlayOffset(gfx::Vector2d(x_offset, y_offset));
1456 window->set_extended_hit_test_region(hit_area.To<gfx::Insets>()); 1453 window->set_extended_hit_test_region(hit_area);
1457 } 1454 }
1458 1455
1459 void WindowTree::WmResponse(uint32_t change_id, bool response) { 1456 void WindowTree::WmResponse(uint32_t change_id, bool response) {
1460 // TODO(sky): think about what else case means. 1457 // TODO(sky): think about what else case means.
1461 if (GetDisplayForWindowManager()) 1458 if (GetDisplayForWindowManager())
1462 window_server_->WindowManagerChangeCompleted(change_id, response); 1459 window_server_->WindowManagerChangeCompleted(change_id, response);
1463 } 1460 }
1464 1461
1465 void WindowTree::WmRequestClose(Id transport_window_id) { 1462 void WindowTree::WmRequestClose(Id transport_window_id) {
1466 // Only the WindowManager should be using this. 1463 // Only the WindowManager should be using this.
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1518 } 1515 }
1519 1516
1520 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy( 1517 bool WindowTree::IsWindowRootOfAnotherTreeForAccessPolicy(
1521 const ServerWindow* window) const { 1518 const ServerWindow* window) const {
1522 WindowTree* tree = window_server_->GetTreeWithRoot(window); 1519 WindowTree* tree = window_server_->GetTreeWithRoot(window);
1523 return tree && tree != this; 1520 return tree && tree != this;
1524 } 1521 }
1525 1522
1526 } // namespace ws 1523 } // namespace ws
1527 } // namespace mus 1524 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698