Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 "services/ui/public/cpp/window_tree_client.h" | 5 #include "services/ui/public/cpp/window_tree_client.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 "services/service_manager/public/cpp/connector.h" | 15 #include "services/service_manager/public/cpp/connector.h" |
| 16 #include "services/ui/common/util.h" | 16 #include "services/ui/common/util.h" |
| 17 #include "services/ui/public/cpp/in_flight_change.h" | 17 #include "services/ui/public/cpp/in_flight_change.h" |
| 18 #include "services/ui/public/cpp/input_event_handler.h" | 18 #include "services/ui/public/cpp/input_event_handler.h" |
| 19 #include "services/ui/public/cpp/surface_id_handler.h" | 19 #include "services/ui/public/cpp/surface_id_handler.h" |
| 20 #include "services/ui/public/cpp/window_drop_target.h" | 20 #include "services/ui/public/cpp/window_drop_target.h" |
| 21 #include "services/ui/public/cpp/window_manager_delegate.h" | 21 #include "services/ui/public/cpp/window_manager_delegate.h" |
| 22 #include "services/ui/public/cpp/window_observer.h" | 22 #include "services/ui/public/cpp/window_observer.h" |
| 23 #include "services/ui/public/cpp/window_private.h" | 23 #include "services/ui/public/cpp/window_private.h" |
| 24 #include "services/ui/public/cpp/window_tracker.h" | 24 #include "services/ui/public/cpp/window_tracker.h" |
| 25 #include "services/ui/public/cpp/window_tree_client_delegate.h" | 25 #include "services/ui/public/cpp/window_tree_client_delegate.h" |
| 26 #include "services/ui/public/cpp/window_tree_client_observer.h" | 26 #include "services/ui/public/cpp/window_tree_client_observer.h" |
| 27 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom .h" | 27 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom .h" |
| 28 #include "ui/display/screen.h" | |
| 28 #include "ui/events/event.h" | 29 #include "ui/events/event.h" |
| 30 #include "ui/gfx/geometry/dip_util.h" | |
| 29 #include "ui/gfx/geometry/insets.h" | 31 #include "ui/gfx/geometry/insets.h" |
| 30 #include "ui/gfx/geometry/size.h" | 32 #include "ui/gfx/geometry/size.h" |
| 31 | 33 |
| 32 namespace ui { | 34 namespace ui { |
| 33 | 35 |
| 34 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) { | 36 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) { |
| 35 return (client_id << 16) | local_id; | 37 return (client_id << 16) | local_id; |
| 36 } | 38 } |
| 37 | 39 |
| 40 // Helper function to get the device_scale_factor() of the display::Display | |
| 41 // with |display_id|. | |
| 42 float ScaleFactorForDisplay(int64_t display_id) { | |
| 43 // TODO(riajiang): Change to use display::GetDisplayWithDisplayId() after | |
| 44 // https://codereview.chromium.org/2361283002/ is landed. | |
| 45 std::vector<display::Display> displays = | |
| 46 display::Screen::GetScreen()->GetAllDisplays(); | |
| 47 auto iter = std::find_if(displays.begin(), displays.end(), | |
| 48 [display_id](const display::Display& display) { | |
| 49 return display.id() == display_id; | |
| 50 }); | |
| 51 if (iter != displays.end()) | |
| 52 return iter->device_scale_factor(); | |
| 53 return 1.f; | |
| 54 } | |
| 55 | |
| 38 // Helper called to construct a local window object from transport data. | 56 // Helper called to construct a local window object from transport data. |
| 39 Window* AddWindowToClient(WindowTreeClient* client, | 57 Window* AddWindowToClient(WindowTreeClient* client, |
| 40 Window* parent, | 58 Window* parent, |
| 41 const mojom::WindowDataPtr& window_data) { | 59 const mojom::WindowDataPtr& window_data) { |
| 42 // We don't use the ctor that takes a WindowTreeClient here, since it will | 60 // We don't use the ctor that takes a WindowTreeClient here, since it will |
| 43 // call back to the service and attempt to create a new window. | 61 // call back to the service and attempt to create a new window. |
| 44 Window* window = WindowPrivate::LocalCreate(); | 62 Window* window = WindowPrivate::LocalCreate(); |
| 45 WindowPrivate private_window(window); | 63 WindowPrivate private_window(window); |
| 46 private_window.set_client(client); | 64 private_window.set_client(client); |
| 47 private_window.set_server_id(window_data->window_id); | 65 private_window.set_server_id(window_data->window_id); |
| 48 private_window.set_visible(window_data->visible); | 66 private_window.set_visible(window_data->visible); |
| 49 private_window.set_properties( | 67 private_window.set_properties( |
| 50 window_data->properties | 68 window_data->properties |
| 51 .To<std::map<std::string, std::vector<uint8_t>>>()); | 69 .To<std::map<std::string, std::vector<uint8_t>>>()); |
| 52 client->AddWindow(window); | 70 client->AddWindow(window); |
| 53 private_window.LocalSetBounds(gfx::Rect(), window_data->bounds); | 71 private_window.LocalSetBounds( |
| 72 gfx::Rect(), | |
| 73 gfx::ConvertRectToDIP(ScaleFactorForDisplay(window->display_id()), | |
| 74 window_data->bounds)); | |
| 54 if (parent) | 75 if (parent) |
| 55 WindowPrivate(parent).LocalAddChild(window); | 76 WindowPrivate(parent).LocalAddChild(window); |
| 56 return window; | 77 return window; |
| 57 } | 78 } |
| 58 | 79 |
| 59 struct WindowTreeClient::CurrentDragState { | 80 struct WindowTreeClient::CurrentDragState { |
| 60 // The current change id of the current drag an drop ipc. | 81 // The current change id of the current drag an drop ipc. |
| 61 uint32_t change_id; | 82 uint32_t change_id; |
| 62 | 83 |
| 63 // The effect to return when we send our finish signal. | 84 // The effect to return when we send our finish signal. |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 211 return HiWord(server_id(window)) == client_id_ && | 232 return HiWord(server_id(window)) == client_id_ && |
| 212 roots_.count(const_cast<Window*>(window)) == 0; | 233 roots_.count(const_cast<Window*>(window)) == 0; |
| 213 } | 234 } |
| 214 | 235 |
| 215 void WindowTreeClient::SetBounds(Window* window, | 236 void WindowTreeClient::SetBounds(Window* window, |
| 216 const gfx::Rect& old_bounds, | 237 const gfx::Rect& old_bounds, |
| 217 const gfx::Rect& bounds) { | 238 const gfx::Rect& bounds) { |
| 218 DCHECK(tree_); | 239 DCHECK(tree_); |
| 219 const uint32_t change_id = ScheduleInFlightChange( | 240 const uint32_t change_id = ScheduleInFlightChange( |
| 220 base::MakeUnique<InFlightBoundsChange>(window, old_bounds)); | 241 base::MakeUnique<InFlightBoundsChange>(window, old_bounds)); |
| 221 tree_->SetWindowBounds(change_id, server_id(window), bounds); | 242 tree_->SetWindowBounds( |
| 243 change_id, server_id(window), | |
| 244 gfx::ConvertRectToPixel(ScaleFactorForDisplay(window->display_id()), | |
| 245 bounds)); | |
| 222 } | 246 } |
| 223 | 247 |
| 224 void WindowTreeClient::SetCapture(Window* window) { | 248 void WindowTreeClient::SetCapture(Window* window) { |
| 225 // In order for us to get here we had to have exposed a window, which implies | 249 // In order for us to get here we had to have exposed a window, which implies |
| 226 // we got a client. | 250 // we got a client. |
| 227 DCHECK(tree_); | 251 DCHECK(tree_); |
| 228 if (capture_window_ == window) | 252 if (capture_window_ == window) |
| 229 return; | 253 return; |
| 230 const uint32_t change_id = ScheduleInFlightChange( | 254 const uint32_t change_id = ScheduleInFlightChange( |
| 231 base::MakeUnique<InFlightCaptureChange>(this, capture_window_)); | 255 base::MakeUnique<InFlightCaptureChange>(this, capture_window_)); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 243 base::MakeUnique<InFlightCaptureChange>(this, window)); | 267 base::MakeUnique<InFlightCaptureChange>(this, window)); |
| 244 tree_->ReleaseCapture(change_id, server_id(window)); | 268 tree_->ReleaseCapture(change_id, server_id(window)); |
| 245 LocalSetCapture(nullptr); | 269 LocalSetCapture(nullptr); |
| 246 } | 270 } |
| 247 | 271 |
| 248 void WindowTreeClient::SetClientArea( | 272 void WindowTreeClient::SetClientArea( |
| 249 Id window_id, | 273 Id window_id, |
| 250 const gfx::Insets& client_area, | 274 const gfx::Insets& client_area, |
| 251 const std::vector<gfx::Rect>& additional_client_areas) { | 275 const std::vector<gfx::Rect>& additional_client_areas) { |
| 252 DCHECK(tree_); | 276 DCHECK(tree_); |
| 253 tree_->SetClientArea(window_id, client_area, additional_client_areas); | 277 float device_scale_factor = |
| 278 ScaleFactorForDisplay(GetWindowByServerId(window_id)->display_id()); | |
| 279 if (device_scale_factor == 1.f) { | |
| 280 tree_->SetClientArea(window_id, client_area, additional_client_areas); | |
| 281 } else { | |
| 282 std::vector<gfx::Rect> additional_client_areas_in_pixel; | |
| 283 for (const gfx::Rect& area : additional_client_areas) { | |
| 284 additional_client_areas_in_pixel.push_back( | |
| 285 gfx::ConvertRectToPixel(device_scale_factor, area)); | |
| 286 } | |
| 287 tree_->SetClientArea( | |
| 288 window_id, gfx::ConvertInsetsToPixel(device_scale_factor, client_area), | |
| 289 additional_client_areas_in_pixel); | |
| 290 } | |
| 254 } | 291 } |
| 255 | 292 |
| 256 void WindowTreeClient::SetHitTestMask(Id window_id, const gfx::Rect& mask) { | 293 void WindowTreeClient::SetHitTestMask(Id window_id, const gfx::Rect& mask) { |
| 257 DCHECK(tree_); | 294 DCHECK(tree_); |
| 258 tree_->SetHitTestMask(window_id, mask); | 295 tree_->SetHitTestMask( |
| 296 window_id, | |
| 297 gfx::ConvertRectToPixel( | |
| 298 ScaleFactorForDisplay(GetWindowByServerId(window_id)->display_id()), | |
| 299 mask)); | |
| 259 } | 300 } |
| 260 | 301 |
| 261 void WindowTreeClient::ClearHitTestMask(Id window_id) { | 302 void WindowTreeClient::ClearHitTestMask(Id window_id) { |
| 262 DCHECK(tree_); | 303 DCHECK(tree_); |
| 263 tree_->SetHitTestMask(window_id, base::nullopt); | 304 tree_->SetHitTestMask(window_id, base::nullopt); |
| 264 } | 305 } |
| 265 | 306 |
| 266 void WindowTreeClient::SetFocus(Window* window) { | 307 void WindowTreeClient::SetFocus(Window* window) { |
| 267 // In order for us to get here we had to have exposed a window, which implies | 308 // In order for us to get here we had to have exposed a window, which implies |
| 268 // we got a client. | 309 // we got a client. |
| (...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 865 DCHECK_EQ(0u, data->parent_id); | 906 DCHECK_EQ(0u, data->parent_id); |
| 866 } | 907 } |
| 867 | 908 |
| 868 void WindowTreeClient::OnWindowBoundsChanged(Id window_id, | 909 void WindowTreeClient::OnWindowBoundsChanged(Id window_id, |
| 869 const gfx::Rect& old_bounds, | 910 const gfx::Rect& old_bounds, |
| 870 const gfx::Rect& new_bounds) { | 911 const gfx::Rect& new_bounds) { |
| 871 Window* window = GetWindowByServerId(window_id); | 912 Window* window = GetWindowByServerId(window_id); |
| 872 if (!window) | 913 if (!window) |
| 873 return; | 914 return; |
| 874 | 915 |
| 875 InFlightBoundsChange new_change(window, new_bounds); | 916 float device_scale_factor = ScaleFactorForDisplay(window->display_id()); |
| 917 gfx::Rect old_bounds_in_dip = | |
| 918 gfx::ConvertRectToDIP(device_scale_factor, old_bounds); | |
| 919 gfx::Rect new_bounds_in_dip = | |
| 920 gfx::ConvertRectToDIP(device_scale_factor, new_bounds); | |
| 921 | |
| 922 InFlightBoundsChange new_change(window, new_bounds_in_dip); | |
| 876 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 923 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 877 return; | 924 return; |
| 878 | 925 WindowPrivate(window).LocalSetBounds(old_bounds_in_dip, new_bounds_in_dip); |
| 879 WindowPrivate(window).LocalSetBounds(old_bounds, new_bounds); | |
| 880 } | 926 } |
| 881 | 927 |
| 882 void WindowTreeClient::OnClientAreaChanged( | 928 void WindowTreeClient::OnClientAreaChanged( |
| 883 uint32_t window_id, | 929 uint32_t window_id, |
| 884 const gfx::Insets& new_client_area, | 930 const gfx::Insets& new_client_area, |
| 885 mojo::Array<gfx::Rect> new_additional_client_areas) { | 931 mojo::Array<gfx::Rect> new_additional_client_areas) { |
| 886 Window* window = GetWindowByServerId(window_id); | 932 Window* window = GetWindowByServerId(window_id); |
| 887 if (window) { | 933 if (window) { |
| 888 WindowPrivate(window).LocalSetClientArea( | 934 float device_scale_factor = ScaleFactorForDisplay(window->display_id()); |
| 889 new_client_area, | 935 if (device_scale_factor == 1.f) { |
| 890 new_additional_client_areas.To<std::vector<gfx::Rect>>()); | 936 WindowPrivate(window).LocalSetClientArea( |
| 937 new_client_area, | |
| 938 new_additional_client_areas.To<std::vector<gfx::Rect>>()); | |
| 939 } else { | |
| 940 std::vector<gfx::Rect> new_additional_client_areas_in_dip; | |
| 941 for (const gfx::Rect& area : new_additional_client_areas) { | |
| 942 new_additional_client_areas_in_dip.push_back( | |
| 943 gfx::ConvertRectToDIP(device_scale_factor, area)); | |
| 944 } | |
| 945 WindowPrivate(window).LocalSetClientArea( | |
| 946 gfx::ConvertInsetsToDIP(device_scale_factor, new_client_area), | |
| 947 new_additional_client_areas_in_dip); | |
| 948 } | |
| 891 } | 949 } |
| 892 } | 950 } |
| 893 | 951 |
| 894 void WindowTreeClient::OnTransientWindowAdded( | 952 void WindowTreeClient::OnTransientWindowAdded( |
| 895 uint32_t window_id, | 953 uint32_t window_id, |
| 896 uint32_t transient_window_id) { | 954 uint32_t transient_window_id) { |
| 897 Window* window = GetWindowByServerId(window_id); | 955 Window* window = GetWindowByServerId(window_id); |
| 898 Window* transient_window = GetWindowByServerId(transient_window_id); | 956 Window* transient_window = GetWindowByServerId(transient_window_id); |
| 899 // window or transient_window or both may be null if a local delete occurs | 957 // window or transient_window or both may be null if a local delete occurs |
| 900 // with an in flight add from the server. | 958 // with an in flight add from the server. |
| (...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1261 window_manager_delegate_->OnWmDisplayModified(display); | 1319 window_manager_delegate_->OnWmDisplayModified(display); |
| 1262 } | 1320 } |
| 1263 | 1321 |
| 1264 void WindowTreeClient::WmSetBounds(uint32_t change_id, | 1322 void WindowTreeClient::WmSetBounds(uint32_t change_id, |
| 1265 Id window_id, | 1323 Id window_id, |
| 1266 const gfx::Rect& transit_bounds) { | 1324 const gfx::Rect& transit_bounds) { |
| 1267 Window* window = GetWindowByServerId(window_id); | 1325 Window* window = GetWindowByServerId(window_id); |
| 1268 bool result = false; | 1326 bool result = false; |
| 1269 if (window) { | 1327 if (window) { |
| 1270 DCHECK(window_manager_delegate_); | 1328 DCHECK(window_manager_delegate_); |
| 1271 gfx::Rect bounds = transit_bounds; | 1329 gfx::Rect transit_bounds_in_dip = gfx::ConvertRectToDIP( |
| 1330 ScaleFactorForDisplay(window->display_id()), transit_bounds); | |
| 1331 gfx::Rect bounds = transit_bounds_in_dip; | |
| 1272 result = window_manager_delegate_->OnWmSetBounds(window, &bounds); | 1332 result = window_manager_delegate_->OnWmSetBounds(window, &bounds); |
| 1273 if (result) { | 1333 if (result) { |
| 1274 // If the resulting bounds differ return false. Returning false ensures | 1334 // If the resulting bounds differ return false. Returning false ensures |
| 1275 // the client applies the bounds we set below. | 1335 // the client applies the bounds we set below. |
| 1276 result = bounds == transit_bounds; | 1336 result = bounds == transit_bounds_in_dip; |
| 1277 window->SetBounds(bounds); | 1337 window->SetBounds(bounds); |
| 1278 } | 1338 } |
| 1279 } | 1339 } |
| 1280 if (window_manager_internal_client_) | 1340 if (window_manager_internal_client_) |
| 1281 window_manager_internal_client_->WmResponse(change_id, result); | 1341 window_manager_internal_client_->WmResponse(change_id, result); |
| 1282 } | 1342 } |
| 1283 | 1343 |
| 1284 void WindowTreeClient::WmSetProperty(uint32_t change_id, | 1344 void WindowTreeClient::WmSetProperty(uint32_t change_id, |
| 1285 Id window_id, | 1345 Id window_id, |
| 1286 const mojo::String& name, | 1346 const mojo::String& name, |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1415 if (window_manager_internal_client_) | 1475 if (window_manager_internal_client_) |
| 1416 window_manager_internal_client_->ActivateNextWindow(); | 1476 window_manager_internal_client_->ActivateNextWindow(); |
| 1417 } | 1477 } |
| 1418 | 1478 |
| 1419 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1479 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1420 Window* window, | 1480 Window* window, |
| 1421 const gfx::Vector2d& offset, | 1481 const gfx::Vector2d& offset, |
| 1422 const gfx::Insets& hit_area) { | 1482 const gfx::Insets& hit_area) { |
| 1423 if (window_manager_internal_client_) { | 1483 if (window_manager_internal_client_) { |
| 1424 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1484 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1425 server_id(window), offset.x(), offset.y(), hit_area); | 1485 server_id(window), offset.x(), offset.y(), |
|
sky
2016/11/10 23:55:15
Similar comment about converting offset.x/y.
| |
| 1486 gfx::ConvertInsetsToDIP(ScaleFactorForDisplay(window->display_id()), | |
| 1487 hit_area)); | |
| 1426 } | 1488 } |
| 1427 } | 1489 } |
| 1428 | 1490 |
| 1429 } // namespace ui | 1491 } // namespace ui |
| OLD | NEW |