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

Side by Side Diff: components/mus/public/cpp/lib/window_tree_client_impl.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: rebase 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/lib/window_tree_client_impl.h" 5 #include "components/mus/public/cpp/lib/window_tree_client_impl.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_connection.h" 22 #include "components/mus/public/cpp/window_tree_connection.h"
23 #include "components/mus/public/cpp/window_tree_connection_observer.h" 23 #include "components/mus/public/cpp/window_tree_connection_observer.h"
24 #include "components/mus/public/cpp/window_tree_delegate.h" 24 #include "components/mus/public/cpp/window_tree_delegate.h"
25 #include "services/shell/public/cpp/connector.h" 25 #include "services/shell/public/cpp/connector.h"
26 #include "ui/events/event.h" 26 #include "ui/events/event.h"
27 #include "ui/events/mojo/input_events_type_converters.h" 27 #include "ui/events/mojo/input_events_type_converters.h"
28 #include "ui/gfx/geometry/insets.h" 28 #include "ui/gfx/geometry/insets.h"
29 #include "ui/gfx/geometry/mojo/geometry_type_converters.h"
30 #include "ui/gfx/geometry/size.h" 29 #include "ui/gfx/geometry/size.h"
31 30
32 namespace mus { 31 namespace mus {
33 32
34 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) { 33 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) {
35 return (client_id << 16) | local_id; 34 return (client_id << 16) | local_id;
36 } 35 }
37 36
38 Id server_id(Window* window) { 37 Id server_id(Window* window) {
39 return WindowPrivate(window).server_id(); 38 return WindowPrivate(window).server_id();
40 } 39 }
41 40
42 // Helper called to construct a local window object from transport data. 41 // Helper called to construct a local window object from transport data.
43 Window* AddWindowToClient(WindowTreeClientImpl* client, 42 Window* AddWindowToClient(WindowTreeClientImpl* client,
44 Window* parent, 43 Window* parent,
45 const mojom::WindowDataPtr& window_data) { 44 const mojom::WindowDataPtr& window_data) {
46 // We don't use the ctor that takes a WindowTreeConnection here, since it 45 // We don't use the ctor that takes a WindowTreeConnection here, since it
47 // will call back to the service and attempt to create a new window. 46 // will call back to the service and attempt to create a new window.
48 Window* window = WindowPrivate::LocalCreate(); 47 Window* window = WindowPrivate::LocalCreate();
49 WindowPrivate private_window(window); 48 WindowPrivate private_window(window);
50 private_window.set_connection(client); 49 private_window.set_connection(client);
51 private_window.set_server_id(window_data->window_id); 50 private_window.set_server_id(window_data->window_id);
52 private_window.set_visible(window_data->visible); 51 private_window.set_visible(window_data->visible);
53 private_window.set_properties( 52 private_window.set_properties(
54 window_data->properties 53 window_data->properties
55 .To<std::map<std::string, std::vector<uint8_t>>>()); 54 .To<std::map<std::string, std::vector<uint8_t>>>());
56 client->AddWindow(window); 55 client->AddWindow(window);
57 private_window.LocalSetBounds(gfx::Rect(), 56 private_window.LocalSetBounds(gfx::Rect(), window_data->bounds);
58 window_data->bounds.To<gfx::Rect>());
59 if (parent) 57 if (parent)
60 WindowPrivate(parent).LocalAddChild(window); 58 WindowPrivate(parent).LocalAddChild(window);
61 return window; 59 return window;
62 } 60 }
63 61
64 Window* BuildWindowTree(WindowTreeClientImpl* client, 62 Window* BuildWindowTree(WindowTreeClientImpl* client,
65 const mojo::Array<mojom::WindowDataPtr>& windows, 63 const mojo::Array<mojom::WindowDataPtr>& windows,
66 Window* initial_parent) { 64 Window* initial_parent) {
67 std::vector<Window*> parents; 65 std::vector<Window*> parents;
68 Window* root = NULL; 66 Window* root = NULL;
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 return HiWord(server_id(window)) == client_id_ && 253 return HiWord(server_id(window)) == client_id_ &&
256 roots_.count(window) == 0; 254 roots_.count(window) == 0;
257 } 255 }
258 256
259 void WindowTreeClientImpl::SetBounds(Window* window, 257 void WindowTreeClientImpl::SetBounds(Window* window,
260 const gfx::Rect& old_bounds, 258 const gfx::Rect& old_bounds,
261 const gfx::Rect& bounds) { 259 const gfx::Rect& bounds) {
262 DCHECK(tree_); 260 DCHECK(tree_);
263 const uint32_t change_id = ScheduleInFlightChange( 261 const uint32_t change_id = ScheduleInFlightChange(
264 base::WrapUnique(new InFlightBoundsChange(window, old_bounds))); 262 base::WrapUnique(new InFlightBoundsChange(window, old_bounds)));
265 tree_->SetWindowBounds(change_id, server_id(window), 263 tree_->SetWindowBounds(change_id, server_id(window), bounds);
266 mojo::Rect::From(bounds));
267 } 264 }
268 265
269 void WindowTreeClientImpl::SetCapture(Window* window) { 266 void WindowTreeClientImpl::SetCapture(Window* window) {
270 // In order for us to get here we had to have exposed a window, which implies 267 // In order for us to get here we had to have exposed a window, which implies
271 // we got a client. 268 // we got a client.
272 DCHECK(tree_); 269 DCHECK(tree_);
273 if (capture_window_ == window) 270 if (capture_window_ == window)
274 return; 271 return;
275 const uint32_t change_id = ScheduleInFlightChange( 272 const uint32_t change_id = ScheduleInFlightChange(
276 base::WrapUnique(new InFlightCaptureChange(this, capture_window_))); 273 base::WrapUnique(new InFlightCaptureChange(this, capture_window_)));
(...skipping 11 matching lines...) Expand all
288 base::WrapUnique(new InFlightCaptureChange(this, window))); 285 base::WrapUnique(new InFlightCaptureChange(this, window)));
289 tree_->ReleaseCapture(change_id, server_id(window)); 286 tree_->ReleaseCapture(change_id, server_id(window));
290 LocalSetCapture(nullptr); 287 LocalSetCapture(nullptr);
291 } 288 }
292 289
293 void WindowTreeClientImpl::SetClientArea( 290 void WindowTreeClientImpl::SetClientArea(
294 Id window_id, 291 Id window_id,
295 const gfx::Insets& client_area, 292 const gfx::Insets& client_area,
296 const std::vector<gfx::Rect>& additional_client_areas) { 293 const std::vector<gfx::Rect>& additional_client_areas) {
297 DCHECK(tree_); 294 DCHECK(tree_);
298 tree_->SetClientArea( 295 tree_->SetClientArea(window_id, client_area, additional_client_areas);
299 window_id, mojo::Insets::From(client_area),
300 mojo::Array<mojo::RectPtr>::From(additional_client_areas));
301 } 296 }
302 297
303 void WindowTreeClientImpl::SetHitTestMask(Id window_id, const gfx::Rect& mask) { 298 void WindowTreeClientImpl::SetHitTestMask(Id window_id, const gfx::Rect& mask) {
304 DCHECK(tree_); 299 DCHECK(tree_);
305 tree_->SetHitTestMask(window_id, mojo::Rect::From(mask)); 300 tree_->SetHitTestMask(window_id, mask);
306 } 301 }
307 302
308 void WindowTreeClientImpl::ClearHitTestMask(Id window_id) { 303 void WindowTreeClientImpl::ClearHitTestMask(Id window_id) {
309 DCHECK(tree_); 304 DCHECK(tree_);
310 tree_->SetHitTestMask(window_id, nullptr); 305 tree_->SetHitTestMask(window_id, {});
311 } 306 }
312 307
313 void WindowTreeClientImpl::SetFocus(Window* window) { 308 void WindowTreeClientImpl::SetFocus(Window* window) {
314 // In order for us to get here we had to have exposed a window, which implies 309 // In order for us to get here we had to have exposed a window, which implies
315 // we got a client. 310 // we got a client.
316 DCHECK(tree_); 311 DCHECK(tree_);
317 const uint32_t change_id = ScheduleInFlightChange( 312 const uint32_t change_id = ScheduleInFlightChange(
318 base::WrapUnique(new InFlightFocusChange(this, focused_window_))); 313 base::WrapUnique(new InFlightFocusChange(this, focused_window_)));
319 tree_->SetFocus(change_id, window ? server_id(window) : 0); 314 tree_->SetFocus(change_id, window ? server_id(window) : 0);
320 LocalSetFocus(window); 315 LocalSetFocus(window);
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 if (data->visible) { 730 if (data->visible) {
736 InFlightVisibleChange visible_change(window, data->visible); 731 InFlightVisibleChange visible_change(window, data->visible);
737 InFlightChange* current_change = 732 InFlightChange* current_change =
738 GetOldestInFlightChangeMatching(visible_change); 733 GetOldestInFlightChangeMatching(visible_change);
739 if (current_change) 734 if (current_change)
740 current_change->SetRevertValueFrom(visible_change); 735 current_change->SetRevertValueFrom(visible_change);
741 else 736 else
742 window_private.LocalSetVisible(true); 737 window_private.LocalSetVisible(true);
743 } 738 }
744 739
745 const gfx::Rect bounds(data->bounds.To<gfx::Rect>()); 740 const gfx::Rect bounds(data->bounds);
746 { 741 {
747 InFlightBoundsChange bounds_change(window, bounds); 742 InFlightBoundsChange bounds_change(window, bounds);
748 InFlightChange* current_change = 743 InFlightChange* current_change =
749 GetOldestInFlightChangeMatching(bounds_change); 744 GetOldestInFlightChangeMatching(bounds_change);
750 if (current_change) 745 if (current_change)
751 current_change->SetRevertValueFrom(bounds_change); 746 current_change->SetRevertValueFrom(bounds_change);
752 else if (window->bounds() != bounds) 747 else if (window->bounds() != bounds)
753 window_private.LocalSetBounds(window->bounds(), bounds); 748 window_private.LocalSetBounds(window->bounds(), bounds);
754 } 749 }
755 750
(...skipping 10 matching lines...) Expand all
766 current_change->SetRevertValueFrom(property_change); 761 current_change->SetRevertValueFrom(property_change);
767 else 762 else
768 window_private.LocalSetSharedProperty(pair.first, &(pair.second)); 763 window_private.LocalSetSharedProperty(pair.first, &(pair.second));
769 } 764 }
770 765
771 // Top level windows should not have a parent. 766 // Top level windows should not have a parent.
772 DCHECK_EQ(0u, data->parent_id); 767 DCHECK_EQ(0u, data->parent_id);
773 } 768 }
774 769
775 void WindowTreeClientImpl::OnWindowBoundsChanged(Id window_id, 770 void WindowTreeClientImpl::OnWindowBoundsChanged(Id window_id,
776 mojo::RectPtr old_bounds, 771 const gfx::Rect& old_bounds,
777 mojo::RectPtr new_bounds) { 772 const gfx::Rect& new_bounds) {
778 Window* window = GetWindowByServerId(window_id); 773 Window* window = GetWindowByServerId(window_id);
779 if (!window) 774 if (!window)
780 return; 775 return;
781 776
782 InFlightBoundsChange new_change(window, new_bounds.To<gfx::Rect>()); 777 InFlightBoundsChange new_change(window, new_bounds);
783 if (ApplyServerChangeToExistingInFlightChange(new_change)) 778 if (ApplyServerChangeToExistingInFlightChange(new_change))
784 return; 779 return;
785 780
786 WindowPrivate(window) 781 WindowPrivate(window).LocalSetBounds(old_bounds, new_bounds);
787 .LocalSetBounds(old_bounds.To<gfx::Rect>(), new_bounds.To<gfx::Rect>());
788 } 782 }
789 783
790 void WindowTreeClientImpl::OnClientAreaChanged( 784 void WindowTreeClientImpl::OnClientAreaChanged(
791 uint32_t window_id, 785 uint32_t window_id,
792 mojo::InsetsPtr new_client_area, 786 const gfx::Insets& new_client_area,
793 mojo::Array<mojo::RectPtr> new_additional_client_areas) { 787 mojo::Array<gfx::Rect> new_additional_client_areas) {
794 Window* window = GetWindowByServerId(window_id); 788 Window* window = GetWindowByServerId(window_id);
795 if (window) { 789 if (window) {
796 WindowPrivate(window).LocalSetClientArea( 790 WindowPrivate(window).LocalSetClientArea(
797 new_client_area.To<gfx::Insets>(), 791 new_client_area,
798 new_additional_client_areas.To<std::vector<gfx::Rect>>()); 792 new_additional_client_areas.To<std::vector<gfx::Rect>>());
799 } 793 }
800 } 794 }
801 795
802 void WindowTreeClientImpl::OnTransientWindowAdded( 796 void WindowTreeClientImpl::OnTransientWindowAdded(
803 uint32_t window_id, 797 uint32_t window_id,
804 uint32_t transient_window_id) { 798 uint32_t transient_window_id) {
805 Window* window = GetWindowByServerId(window_id); 799 Window* window = GetWindowByServerId(window_id);
806 Window* transient_window = GetWindowByServerId(transient_window_id); 800 Window* transient_window = GetWindowByServerId(transient_window_id);
807 // window or transient_window or both may be null if a local delete occurs 801 // window or transient_window or both may be null if a local delete occurs
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1007 Window* window = GetWindowByServerId(window_id); 1001 Window* window = GetWindowByServerId(window_id);
1008 if (!window || !IsRoot(window)) 1002 if (!window || !IsRoot(window))
1009 return; 1003 return;
1010 1004
1011 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(), 1005 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(),
1012 OnRequestClose(window)); 1006 OnRequestClose(window));
1013 } 1007 }
1014 1008
1015 void WindowTreeClientImpl::WmSetBounds(uint32_t change_id, 1009 void WindowTreeClientImpl::WmSetBounds(uint32_t change_id,
1016 Id window_id, 1010 Id window_id,
1017 mojo::RectPtr transit_bounds) { 1011 const gfx::Rect& transit_bounds) {
1018 Window* window = GetWindowByServerId(window_id); 1012 Window* window = GetWindowByServerId(window_id);
1019 bool result = false; 1013 bool result = false;
1020 if (window) { 1014 if (window) {
1021 DCHECK(window_manager_delegate_); 1015 DCHECK(window_manager_delegate_);
1022 gfx::Rect bounds = transit_bounds.To<gfx::Rect>(); 1016 gfx::Rect bounds = transit_bounds;
1023 result = window_manager_delegate_->OnWmSetBounds(window, &bounds); 1017 result = window_manager_delegate_->OnWmSetBounds(window, &bounds);
1024 if (result) { 1018 if (result) {
1025 // If the resulting bounds differ return false. Returning false ensures 1019 // If the resulting bounds differ return false. Returning false ensures
1026 // the client applies the bounds we set below. 1020 // the client applies the bounds we set below.
1027 result = bounds == transit_bounds.To<gfx::Rect>(); 1021 result = bounds == transit_bounds;
1028 window->SetBounds(bounds); 1022 window->SetBounds(bounds);
1029 } 1023 }
1030 } 1024 }
1031 if (window_manager_internal_client_) 1025 if (window_manager_internal_client_)
1032 window_manager_internal_client_->WmResponse(change_id, result); 1026 window_manager_internal_client_->WmResponse(change_id, result);
1033 } 1027 }
1034 1028
1035 void WindowTreeClientImpl::WmSetProperty(uint32_t change_id, 1029 void WindowTreeClientImpl::WmSetProperty(uint32_t change_id,
1036 Id window_id, 1030 Id window_id,
1037 const mojo::String& name, 1031 const mojo::String& name,
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 if (window_manager_internal_client_) 1124 if (window_manager_internal_client_)
1131 window_manager_internal_client_->ActivateNextWindow(); 1125 window_manager_internal_client_->ActivateNextWindow();
1132 } 1126 }
1133 1127
1134 void WindowTreeClientImpl::SetUnderlaySurfaceOffsetAndExtendedHitArea( 1128 void WindowTreeClientImpl::SetUnderlaySurfaceOffsetAndExtendedHitArea(
1135 Window* window, 1129 Window* window,
1136 const gfx::Vector2d& offset, 1130 const gfx::Vector2d& offset,
1137 const gfx::Insets& hit_area) { 1131 const gfx::Insets& hit_area) {
1138 if (window_manager_internal_client_) { 1132 if (window_manager_internal_client_) {
1139 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1133 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1140 server_id(window), offset.x(), offset.y(), 1134 server_id(window), offset.x(), offset.y(), hit_area);
1141 mojo::Insets::From(hit_area));
1142 } 1135 }
1143 } 1136 }
1144 1137
1145 } // namespace mus 1138 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698