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

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: 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/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 "mojo/converters/geometry/geometry_type_converters.h"
26 #include "mojo/converters/input_events/input_events_type_converters.h" 25 #include "mojo/converters/input_events/input_events_type_converters.h"
27 #include "services/shell/public/cpp/connector.h" 26 #include "services/shell/public/cpp/connector.h"
28 #include "ui/events/event.h" 27 #include "ui/events/event.h"
29 #include "ui/gfx/geometry/insets.h" 28 #include "ui/gfx/geometry/insets.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(ConnectionSpecificId connection_id, 33 Id MakeTransportId(ConnectionSpecificId connection_id,
35 ConnectionSpecificId local_id) { 34 ConnectionSpecificId local_id) {
(...skipping 14 matching lines...) Expand all
50 WindowPrivate private_window(window); 49 WindowPrivate private_window(window);
51 private_window.set_connection(client); 50 private_window.set_connection(client);
52 private_window.set_server_id(window_data->window_id); 51 private_window.set_server_id(window_data->window_id);
53 private_window.set_visible(window_data->visible); 52 private_window.set_visible(window_data->visible);
54 private_window.LocalSetViewportMetrics(mojom::ViewportMetrics(), 53 private_window.LocalSetViewportMetrics(mojom::ViewportMetrics(),
55 *window_data->viewport_metrics); 54 *window_data->viewport_metrics);
56 private_window.set_properties( 55 private_window.set_properties(
57 window_data->properties 56 window_data->properties
58 .To<std::map<std::string, std::vector<uint8_t>>>()); 57 .To<std::map<std::string, std::vector<uint8_t>>>());
59 client->AddWindow(window); 58 client->AddWindow(window);
60 private_window.LocalSetBounds(gfx::Rect(), 59 private_window.LocalSetBounds(gfx::Rect(), window_data->bounds);
61 window_data->bounds.To<gfx::Rect>());
62 if (parent) 60 if (parent)
63 WindowPrivate(parent).LocalAddChild(window); 61 WindowPrivate(parent).LocalAddChild(window);
64 return window; 62 return window;
65 } 63 }
66 64
67 Window* BuildWindowTree(WindowTreeClientImpl* client, 65 Window* BuildWindowTree(WindowTreeClientImpl* client,
68 const mojo::Array<mojom::WindowDataPtr>& windows, 66 const mojo::Array<mojom::WindowDataPtr>& windows,
69 Window* initial_parent) { 67 Window* initial_parent) {
70 std::vector<Window*> parents; 68 std::vector<Window*> parents;
71 Window* root = NULL; 69 Window* root = NULL;
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 return HiWord(server_id(window)) == connection_id_ && 266 return HiWord(server_id(window)) == connection_id_ &&
269 roots_.count(window) == 0; 267 roots_.count(window) == 0;
270 } 268 }
271 269
272 void WindowTreeClientImpl::SetBounds(Window* window, 270 void WindowTreeClientImpl::SetBounds(Window* window,
273 const gfx::Rect& old_bounds, 271 const gfx::Rect& old_bounds,
274 const gfx::Rect& bounds) { 272 const gfx::Rect& bounds) {
275 DCHECK(tree_); 273 DCHECK(tree_);
276 const uint32_t change_id = ScheduleInFlightChange( 274 const uint32_t change_id = ScheduleInFlightChange(
277 base::WrapUnique(new InFlightBoundsChange(window, old_bounds))); 275 base::WrapUnique(new InFlightBoundsChange(window, old_bounds)));
278 tree_->SetWindowBounds(change_id, server_id(window), 276 tree_->SetWindowBounds(change_id, server_id(window), bounds);
279 mojo::Rect::From(bounds));
280 } 277 }
281 278
282 void WindowTreeClientImpl::SetCapture(Window* window) { 279 void WindowTreeClientImpl::SetCapture(Window* window) {
283 // In order for us to get here we had to have exposed a window, which implies 280 // In order for us to get here we had to have exposed a window, which implies
284 // we got a connection. 281 // we got a connection.
285 DCHECK(tree_); 282 DCHECK(tree_);
286 if (capture_window_ == window) 283 if (capture_window_ == window)
287 return; 284 return;
288 const uint32_t change_id = ScheduleInFlightChange( 285 const uint32_t change_id = ScheduleInFlightChange(
289 base::WrapUnique(new InFlightCaptureChange(this, capture_window_))); 286 base::WrapUnique(new InFlightCaptureChange(this, capture_window_)));
(...skipping 11 matching lines...) Expand all
301 base::WrapUnique(new InFlightCaptureChange(this, window))); 298 base::WrapUnique(new InFlightCaptureChange(this, window)));
302 tree_->ReleaseCapture(change_id, server_id(window)); 299 tree_->ReleaseCapture(change_id, server_id(window));
303 LocalSetCapture(nullptr); 300 LocalSetCapture(nullptr);
304 } 301 }
305 302
306 void WindowTreeClientImpl::SetClientArea( 303 void WindowTreeClientImpl::SetClientArea(
307 Id window_id, 304 Id window_id,
308 const gfx::Insets& client_area, 305 const gfx::Insets& client_area,
309 const std::vector<gfx::Rect>& additional_client_areas) { 306 const std::vector<gfx::Rect>& additional_client_areas) {
310 DCHECK(tree_); 307 DCHECK(tree_);
311 tree_->SetClientArea( 308 tree_->SetClientArea(window_id, client_area,
312 window_id, mojo::Insets::From(client_area), 309 std::vector<gfx::Rect>(additional_client_areas));
dcheng 2016/05/26 22:20:40 Why is there an explicit copy here?
Sam McNally 2016/05/27 03:44:47 mojo::Array has a std::vector constructor, but it
dcheng 2016/05/27 03:47:54 Why can't it have a const std::vector<>& version t
Sam McNally 2016/05/27 06:34:05 Done. mojo::Array is getting quite strange now: mo
313 mojo::Array<mojo::RectPtr>::From(additional_client_areas));
314 } 310 }
315 311
316 void WindowTreeClientImpl::SetHitTestMask(Id window_id, const gfx::Rect& mask) { 312 void WindowTreeClientImpl::SetHitTestMask(Id window_id, const gfx::Rect& mask) {
317 DCHECK(tree_); 313 DCHECK(tree_);
318 tree_->SetHitTestMask(window_id, mojo::Rect::From(mask)); 314 tree_->SetHitTestMask(window_id, mask);
319 } 315 }
320 316
321 void WindowTreeClientImpl::ClearHitTestMask(Id window_id) { 317 void WindowTreeClientImpl::ClearHitTestMask(Id window_id) {
322 DCHECK(tree_); 318 DCHECK(tree_);
323 tree_->SetHitTestMask(window_id, nullptr); 319 tree_->SetHitTestMask(window_id, {});
324 } 320 }
325 321
326 void WindowTreeClientImpl::SetFocus(Window* window) { 322 void WindowTreeClientImpl::SetFocus(Window* window) {
327 // In order for us to get here we had to have exposed a window, which implies 323 // In order for us to get here we had to have exposed a window, which implies
328 // we got a connection. 324 // we got a connection.
329 DCHECK(tree_); 325 DCHECK(tree_);
330 const uint32_t change_id = ScheduleInFlightChange( 326 const uint32_t change_id = ScheduleInFlightChange(
331 base::WrapUnique(new InFlightFocusChange(this, focused_window_))); 327 base::WrapUnique(new InFlightFocusChange(this, focused_window_)));
332 tree_->SetFocus(change_id, window ? server_id(window) : 0); 328 tree_->SetFocus(change_id, window ? server_id(window) : 0);
333 LocalSetFocus(window); 329 LocalSetFocus(window);
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 if (data->visible) { 729 if (data->visible) {
734 InFlightVisibleChange visible_change(window, data->visible); 730 InFlightVisibleChange visible_change(window, data->visible);
735 InFlightChange* current_change = 731 InFlightChange* current_change =
736 GetOldestInFlightChangeMatching(visible_change); 732 GetOldestInFlightChangeMatching(visible_change);
737 if (current_change) 733 if (current_change)
738 current_change->SetRevertValueFrom(visible_change); 734 current_change->SetRevertValueFrom(visible_change);
739 else 735 else
740 window_private.LocalSetVisible(true); 736 window_private.LocalSetVisible(true);
741 } 737 }
742 738
743 const gfx::Rect bounds(data->bounds.To<gfx::Rect>()); 739 const gfx::Rect bounds(data->bounds);
744 { 740 {
745 InFlightBoundsChange bounds_change(window, bounds); 741 InFlightBoundsChange bounds_change(window, bounds);
746 InFlightChange* current_change = 742 InFlightChange* current_change =
747 GetOldestInFlightChangeMatching(bounds_change); 743 GetOldestInFlightChangeMatching(bounds_change);
748 if (current_change) 744 if (current_change)
749 current_change->SetRevertValueFrom(bounds_change); 745 current_change->SetRevertValueFrom(bounds_change);
750 else if (window->bounds() != bounds) 746 else if (window->bounds() != bounds)
751 window_private.LocalSetBounds(window->bounds(), bounds); 747 window_private.LocalSetBounds(window->bounds(), bounds);
752 } 748 }
753 749
(...skipping 10 matching lines...) Expand all
764 current_change->SetRevertValueFrom(property_change); 760 current_change->SetRevertValueFrom(property_change);
765 else 761 else
766 window_private.LocalSetSharedProperty(pair.first, &(pair.second)); 762 window_private.LocalSetSharedProperty(pair.first, &(pair.second));
767 } 763 }
768 764
769 // Top level windows should not have a parent. 765 // Top level windows should not have a parent.
770 DCHECK_EQ(0u, data->parent_id); 766 DCHECK_EQ(0u, data->parent_id);
771 } 767 }
772 768
773 void WindowTreeClientImpl::OnWindowBoundsChanged(Id window_id, 769 void WindowTreeClientImpl::OnWindowBoundsChanged(Id window_id,
774 mojo::RectPtr old_bounds, 770 const gfx::Rect& old_bounds,
775 mojo::RectPtr new_bounds) { 771 const gfx::Rect& new_bounds) {
776 Window* window = GetWindowByServerId(window_id); 772 Window* window = GetWindowByServerId(window_id);
777 if (!window) 773 if (!window)
778 return; 774 return;
779 775
780 InFlightBoundsChange new_change(window, new_bounds.To<gfx::Rect>()); 776 InFlightBoundsChange new_change(window, new_bounds);
781 if (ApplyServerChangeToExistingInFlightChange(new_change)) 777 if (ApplyServerChangeToExistingInFlightChange(new_change))
782 return; 778 return;
783 779
784 WindowPrivate(window) 780 WindowPrivate(window).LocalSetBounds(old_bounds, new_bounds);
785 .LocalSetBounds(old_bounds.To<gfx::Rect>(), new_bounds.To<gfx::Rect>());
786 } 781 }
787 782
788 void WindowTreeClientImpl::OnClientAreaChanged( 783 void WindowTreeClientImpl::OnClientAreaChanged(
789 uint32_t window_id, 784 uint32_t window_id,
790 mojo::InsetsPtr new_client_area, 785 const gfx::Insets& new_client_area,
791 mojo::Array<mojo::RectPtr> new_additional_client_areas) { 786 mojo::Array<gfx::Rect> new_additional_client_areas) {
792 Window* window = GetWindowByServerId(window_id); 787 Window* window = GetWindowByServerId(window_id);
793 if (window) { 788 if (window) {
794 WindowPrivate(window).LocalSetClientArea( 789 WindowPrivate(window).LocalSetClientArea(
795 new_client_area.To<gfx::Insets>(), 790 new_client_area,
796 new_additional_client_areas.To<std::vector<gfx::Rect>>()); 791 new_additional_client_areas.To<std::vector<gfx::Rect>>());
797 } 792 }
798 } 793 }
799 794
800 void WindowTreeClientImpl::OnTransientWindowAdded( 795 void WindowTreeClientImpl::OnTransientWindowAdded(
801 uint32_t window_id, 796 uint32_t window_id,
802 uint32_t transient_window_id) { 797 uint32_t transient_window_id) {
803 Window* window = GetWindowByServerId(window_id); 798 Window* window = GetWindowByServerId(window_id);
804 Window* transient_window = GetWindowByServerId(transient_window_id); 799 Window* transient_window = GetWindowByServerId(transient_window_id);
805 // window or transient_window or both may be null if a local delete occurs 800 // window or transient_window or both may be null if a local delete occurs
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 Window* window = GetWindowByServerId(window_id); 1024 Window* window = GetWindowByServerId(window_id);
1030 if (!window || !IsRoot(window)) 1025 if (!window || !IsRoot(window))
1031 return; 1026 return;
1032 1027
1033 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(), 1028 FOR_EACH_OBSERVER(WindowObserver, *WindowPrivate(window).observers(),
1034 OnRequestClose(window)); 1029 OnRequestClose(window));
1035 } 1030 }
1036 1031
1037 void WindowTreeClientImpl::WmSetBounds(uint32_t change_id, 1032 void WindowTreeClientImpl::WmSetBounds(uint32_t change_id,
1038 Id window_id, 1033 Id window_id,
1039 mojo::RectPtr transit_bounds) { 1034 const gfx::Rect& transit_bounds) {
1040 Window* window = GetWindowByServerId(window_id); 1035 Window* window = GetWindowByServerId(window_id);
1041 bool result = false; 1036 bool result = false;
1042 if (window) { 1037 if (window) {
1043 DCHECK(window_manager_delegate_); 1038 DCHECK(window_manager_delegate_);
1044 gfx::Rect bounds = transit_bounds.To<gfx::Rect>(); 1039 gfx::Rect bounds = transit_bounds;
1045 result = window_manager_delegate_->OnWmSetBounds(window, &bounds); 1040 result = window_manager_delegate_->OnWmSetBounds(window, &bounds);
1046 if (result) { 1041 if (result) {
1047 // If the resulting bounds differ return false. Returning false ensures 1042 // If the resulting bounds differ return false. Returning false ensures
1048 // the client applies the bounds we set below. 1043 // the client applies the bounds we set below.
1049 result = bounds == transit_bounds.To<gfx::Rect>(); 1044 result = bounds == transit_bounds;
1050 window->SetBounds(bounds); 1045 window->SetBounds(bounds);
1051 } 1046 }
1052 } 1047 }
1053 if (window_manager_internal_client_) 1048 if (window_manager_internal_client_)
1054 window_manager_internal_client_->WmResponse(change_id, result); 1049 window_manager_internal_client_->WmResponse(change_id, result);
1055 } 1050 }
1056 1051
1057 void WindowTreeClientImpl::WmSetProperty(uint32_t change_id, 1052 void WindowTreeClientImpl::WmSetProperty(uint32_t change_id,
1058 Id window_id, 1053 Id window_id,
1059 const mojo::String& name, 1054 const mojo::String& name,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 if (window_manager_internal_client_) 1148 if (window_manager_internal_client_)
1154 window_manager_internal_client_->ActivateNextWindow(); 1149 window_manager_internal_client_->ActivateNextWindow();
1155 } 1150 }
1156 1151
1157 void WindowTreeClientImpl::SetUnderlaySurfaceOffsetAndExtendedHitArea( 1152 void WindowTreeClientImpl::SetUnderlaySurfaceOffsetAndExtendedHitArea(
1158 Window* window, 1153 Window* window,
1159 const gfx::Vector2d& offset, 1154 const gfx::Vector2d& offset,
1160 const gfx::Insets& hit_area) { 1155 const gfx::Insets& hit_area) {
1161 if (window_manager_internal_client_) { 1156 if (window_manager_internal_client_) {
1162 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( 1157 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea(
1163 server_id(window), offset.x(), offset.y(), 1158 server_id(window), offset.x(), offset.y(), hit_area);
1164 mojo::Insets::From(hit_area));
1165 } 1159 }
1166 } 1160 }
1167 1161
1168 } // namespace mus 1162 } // namespace mus
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698