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