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 DeviceScaleFactorForDisplay(int64_t display_id) { | |
|
kylechar
2016/11/10 14:30:52
Name this something like ScaleFactorForDisplay()?
riajiang
2016/11/10 19:16:08
I see, done.
| |
| 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 float device_scale_factor = DeviceScaleFactorForDisplay(window->display_id()); |
| 72 if (device_scale_factor == 1.f) { | |
| 73 private_window.LocalSetBounds(gfx::Rect(), window_data->bounds); | |
| 74 } else { | |
| 75 private_window.LocalSetBounds( | |
| 76 gfx::Rect(), | |
| 77 gfx::ConvertRectToDIP(device_scale_factor, window_data->bounds)); | |
| 78 } | |
| 54 if (parent) | 79 if (parent) |
| 55 WindowPrivate(parent).LocalAddChild(window); | 80 WindowPrivate(parent).LocalAddChild(window); |
| 56 return window; | 81 return window; |
| 57 } | 82 } |
| 58 | 83 |
| 59 struct WindowTreeClient::CurrentDragState { | 84 struct WindowTreeClient::CurrentDragState { |
| 60 // The current change id of the current drag an drop ipc. | 85 // The current change id of the current drag an drop ipc. |
| 61 uint32_t change_id; | 86 uint32_t change_id; |
| 62 | 87 |
| 63 // The effect to return when we send our finish signal. | 88 // 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_ && | 236 return HiWord(server_id(window)) == client_id_ && |
| 212 roots_.count(const_cast<Window*>(window)) == 0; | 237 roots_.count(const_cast<Window*>(window)) == 0; |
| 213 } | 238 } |
| 214 | 239 |
| 215 void WindowTreeClient::SetBounds(Window* window, | 240 void WindowTreeClient::SetBounds(Window* window, |
| 216 const gfx::Rect& old_bounds, | 241 const gfx::Rect& old_bounds, |
| 217 const gfx::Rect& bounds) { | 242 const gfx::Rect& bounds) { |
| 218 DCHECK(tree_); | 243 DCHECK(tree_); |
| 219 const uint32_t change_id = ScheduleInFlightChange( | 244 const uint32_t change_id = ScheduleInFlightChange( |
| 220 base::MakeUnique<InFlightBoundsChange>(window, old_bounds)); | 245 base::MakeUnique<InFlightBoundsChange>(window, old_bounds)); |
| 221 tree_->SetWindowBounds(change_id, server_id(window), bounds); | 246 float device_scale_factor = DeviceScaleFactorForDisplay(window->display_id()); |
| 247 if (device_scale_factor == 1.f) { | |
|
sky
2016/11/09 23:22:57
I think the code you have would be simpler if you
riajiang
2016/11/10 19:16:08
I did conditionals to avoid extra work if DSF is 1
sky
2016/11/10 23:55:14
This isn't a performance sensitive area, so going
| |
| 248 tree_->SetWindowBounds(change_id, server_id(window), bounds); | |
| 249 } else { | |
| 250 tree_->SetWindowBounds( | |
| 251 change_id, server_id(window), | |
| 252 gfx::ConvertRectToPixel(device_scale_factor, bounds)); | |
| 253 } | |
| 222 } | 254 } |
| 223 | 255 |
| 224 void WindowTreeClient::SetCapture(Window* window) { | 256 void WindowTreeClient::SetCapture(Window* window) { |
| 225 // In order for us to get here we had to have exposed a window, which implies | 257 // In order for us to get here we had to have exposed a window, which implies |
| 226 // we got a client. | 258 // we got a client. |
| 227 DCHECK(tree_); | 259 DCHECK(tree_); |
| 228 if (capture_window_ == window) | 260 if (capture_window_ == window) |
| 229 return; | 261 return; |
| 230 const uint32_t change_id = ScheduleInFlightChange( | 262 const uint32_t change_id = ScheduleInFlightChange( |
| 231 base::MakeUnique<InFlightCaptureChange>(this, capture_window_)); | 263 base::MakeUnique<InFlightCaptureChange>(this, capture_window_)); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 243 base::MakeUnique<InFlightCaptureChange>(this, window)); | 275 base::MakeUnique<InFlightCaptureChange>(this, window)); |
| 244 tree_->ReleaseCapture(change_id, server_id(window)); | 276 tree_->ReleaseCapture(change_id, server_id(window)); |
| 245 LocalSetCapture(nullptr); | 277 LocalSetCapture(nullptr); |
| 246 } | 278 } |
| 247 | 279 |
| 248 void WindowTreeClient::SetClientArea( | 280 void WindowTreeClient::SetClientArea( |
| 249 Id window_id, | 281 Id window_id, |
| 250 const gfx::Insets& client_area, | 282 const gfx::Insets& client_area, |
| 251 const std::vector<gfx::Rect>& additional_client_areas) { | 283 const std::vector<gfx::Rect>& additional_client_areas) { |
| 252 DCHECK(tree_); | 284 DCHECK(tree_); |
| 253 tree_->SetClientArea(window_id, client_area, additional_client_areas); | 285 float device_scale_factor = |
| 286 DeviceScaleFactorForDisplay(GetWindowByServerId(window_id)->display_id()); | |
| 287 if (device_scale_factor == 1.f) { | |
| 288 tree_->SetClientArea(window_id, client_area, additional_client_areas); | |
| 289 } else { | |
| 290 std::vector<gfx::Rect> additional_client_areas_in_pixel; | |
| 291 for (const gfx::Rect& area : additional_client_areas) { | |
| 292 additional_client_areas_in_pixel.push_back( | |
| 293 gfx::ConvertRectToPixel(device_scale_factor, area)); | |
| 294 } | |
| 295 tree_->SetClientArea( | |
| 296 window_id, gfx::ConvertInsetsToPixel(device_scale_factor, client_area), | |
| 297 additional_client_areas_in_pixel); | |
| 298 } | |
| 254 } | 299 } |
| 255 | 300 |
| 256 void WindowTreeClient::SetHitTestMask(Id window_id, const gfx::Rect& mask) { | 301 void WindowTreeClient::SetHitTestMask(Id window_id, const gfx::Rect& mask) { |
| 257 DCHECK(tree_); | 302 DCHECK(tree_); |
| 258 tree_->SetHitTestMask(window_id, mask); | 303 float device_scale_factor = |
| 304 DeviceScaleFactorForDisplay(GetWindowByServerId(window_id)->display_id()); | |
| 305 if (device_scale_factor == 1.f) { | |
| 306 tree_->SetHitTestMask(window_id, mask); | |
| 307 } else { | |
| 308 tree_->SetHitTestMask(window_id, | |
| 309 gfx::ConvertRectToPixel(device_scale_factor, mask)); | |
| 310 } | |
| 259 } | 311 } |
| 260 | 312 |
| 261 void WindowTreeClient::ClearHitTestMask(Id window_id) { | 313 void WindowTreeClient::ClearHitTestMask(Id window_id) { |
| 262 DCHECK(tree_); | 314 DCHECK(tree_); |
| 263 tree_->SetHitTestMask(window_id, base::nullopt); | 315 tree_->SetHitTestMask(window_id, base::nullopt); |
| 264 } | 316 } |
| 265 | 317 |
| 266 void WindowTreeClient::SetFocus(Window* window) { | 318 void WindowTreeClient::SetFocus(Window* window) { |
| 267 // In order for us to get here we had to have exposed a window, which implies | 319 // In order for us to get here we had to have exposed a window, which implies |
| 268 // we got a client. | 320 // we got a client. |
| (...skipping 603 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 872 DCHECK_EQ(0u, data->parent_id); | 924 DCHECK_EQ(0u, data->parent_id); |
| 873 } | 925 } |
| 874 | 926 |
| 875 void WindowTreeClient::OnWindowBoundsChanged(Id window_id, | 927 void WindowTreeClient::OnWindowBoundsChanged(Id window_id, |
| 876 const gfx::Rect& old_bounds, | 928 const gfx::Rect& old_bounds, |
| 877 const gfx::Rect& new_bounds) { | 929 const gfx::Rect& new_bounds) { |
| 878 Window* window = GetWindowByServerId(window_id); | 930 Window* window = GetWindowByServerId(window_id); |
| 879 if (!window) | 931 if (!window) |
| 880 return; | 932 return; |
| 881 | 933 |
| 882 InFlightBoundsChange new_change(window, new_bounds); | 934 float device_scale_factor = DeviceScaleFactorForDisplay(window->display_id()); |
| 883 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 935 if (device_scale_factor == 1.f) { |
| 884 return; | 936 InFlightBoundsChange new_change(window, new_bounds); |
|
sky
2016/11/09 23:22:57
Isn't new_bounds in pixels? On 245 I believe the n
riajiang
2016/11/10 19:16:08
new_bounds is in pixels, but since DSF is 1 here,
| |
| 885 | 937 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 886 WindowPrivate(window).LocalSetBounds(old_bounds, new_bounds); | 938 return; |
| 939 WindowPrivate(window).LocalSetBounds(old_bounds, new_bounds); | |
| 940 } else { | |
| 941 gfx::Rect old_bounds_in_dip = | |
| 942 gfx::ConvertRectToDIP(device_scale_factor, old_bounds); | |
| 943 gfx::Rect new_bounds_in_dip = | |
| 944 gfx::ConvertRectToDIP(device_scale_factor, new_bounds); | |
| 945 InFlightBoundsChange new_change(window, new_bounds_in_dip); | |
| 946 if (ApplyServerChangeToExistingInFlightChange(new_change)) | |
| 947 return; | |
| 948 WindowPrivate(window).LocalSetBounds(old_bounds_in_dip, new_bounds_in_dip); | |
| 949 } | |
| 887 } | 950 } |
| 888 | 951 |
| 889 void WindowTreeClient::OnClientAreaChanged( | 952 void WindowTreeClient::OnClientAreaChanged( |
| 890 uint32_t window_id, | 953 uint32_t window_id, |
| 891 const gfx::Insets& new_client_area, | 954 const gfx::Insets& new_client_area, |
| 892 mojo::Array<gfx::Rect> new_additional_client_areas) { | 955 mojo::Array<gfx::Rect> new_additional_client_areas) { |
| 893 Window* window = GetWindowByServerId(window_id); | 956 Window* window = GetWindowByServerId(window_id); |
| 894 if (window) { | 957 if (window) { |
| 895 WindowPrivate(window).LocalSetClientArea( | 958 float device_scale_factor = |
| 896 new_client_area, | 959 DeviceScaleFactorForDisplay(window->display_id()); |
| 897 new_additional_client_areas.To<std::vector<gfx::Rect>>()); | 960 if (device_scale_factor == 1.f) { |
| 961 WindowPrivate(window).LocalSetClientArea( | |
| 962 new_client_area, | |
| 963 new_additional_client_areas.To<std::vector<gfx::Rect>>()); | |
| 964 } else { | |
| 965 std::vector<gfx::Rect> new_additional_client_areas_in_dip; | |
| 966 for (const gfx::Rect& area : new_additional_client_areas) { | |
| 967 new_additional_client_areas_in_dip.push_back( | |
| 968 gfx::ConvertRectToDIP(device_scale_factor, area)); | |
| 969 } | |
| 970 WindowPrivate(window).LocalSetClientArea( | |
| 971 gfx::ConvertInsetsToDIP(device_scale_factor, new_client_area), | |
| 972 new_additional_client_areas_in_dip); | |
| 973 } | |
| 898 } | 974 } |
| 899 } | 975 } |
| 900 | 976 |
| 901 void WindowTreeClient::OnTransientWindowAdded( | 977 void WindowTreeClient::OnTransientWindowAdded( |
| 902 uint32_t window_id, | 978 uint32_t window_id, |
| 903 uint32_t transient_window_id) { | 979 uint32_t transient_window_id) { |
| 904 Window* window = GetWindowByServerId(window_id); | 980 Window* window = GetWindowByServerId(window_id); |
| 905 Window* transient_window = GetWindowByServerId(transient_window_id); | 981 Window* transient_window = GetWindowByServerId(transient_window_id); |
| 906 // window or transient_window or both may be null if a local delete occurs | 982 // window or transient_window or both may be null if a local delete occurs |
| 907 // with an in flight add from the server. | 983 // with an in flight add from the server. |
| (...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1270 window_manager_delegate_->OnWmDisplayModified(display); | 1346 window_manager_delegate_->OnWmDisplayModified(display); |
| 1271 } | 1347 } |
| 1272 | 1348 |
| 1273 void WindowTreeClient::WmSetBounds(uint32_t change_id, | 1349 void WindowTreeClient::WmSetBounds(uint32_t change_id, |
| 1274 Id window_id, | 1350 Id window_id, |
| 1275 const gfx::Rect& transit_bounds) { | 1351 const gfx::Rect& transit_bounds) { |
| 1276 Window* window = GetWindowByServerId(window_id); | 1352 Window* window = GetWindowByServerId(window_id); |
| 1277 bool result = false; | 1353 bool result = false; |
| 1278 if (window) { | 1354 if (window) { |
| 1279 DCHECK(window_manager_delegate_); | 1355 DCHECK(window_manager_delegate_); |
| 1280 gfx::Rect bounds = transit_bounds; | 1356 float device_scale_factor = |
| 1357 DeviceScaleFactorForDisplay(window->display_id()); | |
| 1358 gfx::Rect transit_bounds_in_dip; | |
| 1359 if (device_scale_factor == 1.f) { | |
| 1360 transit_bounds_in_dip = transit_bounds; | |
| 1361 } else { | |
| 1362 transit_bounds_in_dip = | |
| 1363 gfx::ConvertRectToDIP(device_scale_factor, transit_bounds); | |
| 1364 } | |
| 1365 gfx::Rect bounds = transit_bounds_in_dip; | |
| 1281 result = window_manager_delegate_->OnWmSetBounds(window, &bounds); | 1366 result = window_manager_delegate_->OnWmSetBounds(window, &bounds); |
| 1282 if (result) { | 1367 if (result) { |
| 1283 // If the resulting bounds differ return false. Returning false ensures | 1368 // If the resulting bounds differ return false. Returning false ensures |
| 1284 // the client applies the bounds we set below. | 1369 // the client applies the bounds we set below. |
| 1285 result = bounds == transit_bounds; | 1370 result = bounds == transit_bounds_in_dip; |
| 1286 window->SetBounds(bounds); | 1371 window->SetBounds(bounds); |
| 1287 } | 1372 } |
| 1288 } | 1373 } |
| 1289 if (window_manager_internal_client_) | 1374 if (window_manager_internal_client_) |
| 1290 window_manager_internal_client_->WmResponse(change_id, result); | 1375 window_manager_internal_client_->WmResponse(change_id, result); |
| 1291 } | 1376 } |
| 1292 | 1377 |
| 1293 void WindowTreeClient::WmSetProperty(uint32_t change_id, | 1378 void WindowTreeClient::WmSetProperty(uint32_t change_id, |
| 1294 Id window_id, | 1379 Id window_id, |
| 1295 const mojo::String& name, | 1380 const mojo::String& name, |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1423 void WindowTreeClient::ActivateNextWindow() { | 1508 void WindowTreeClient::ActivateNextWindow() { |
| 1424 if (window_manager_internal_client_) | 1509 if (window_manager_internal_client_) |
| 1425 window_manager_internal_client_->ActivateNextWindow(); | 1510 window_manager_internal_client_->ActivateNextWindow(); |
| 1426 } | 1511 } |
| 1427 | 1512 |
| 1428 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1513 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1429 Window* window, | 1514 Window* window, |
| 1430 const gfx::Vector2d& offset, | 1515 const gfx::Vector2d& offset, |
| 1431 const gfx::Insets& hit_area) { | 1516 const gfx::Insets& hit_area) { |
| 1432 if (window_manager_internal_client_) { | 1517 if (window_manager_internal_client_) { |
| 1433 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1518 float device_scale_factor = |
| 1434 server_id(window), offset.x(), offset.y(), hit_area); | 1519 DeviceScaleFactorForDisplay(window->display_id()); |
| 1520 if (device_scale_factor == 1.f) { | |
| 1521 window_manager_internal_client_ | |
| 1522 ->SetUnderlaySurfaceOffsetAndExtendedHitArea( | |
| 1523 server_id(window), offset.x(), offset.y(), hit_area); | |
| 1524 } else { | |
| 1525 window_manager_internal_client_ | |
| 1526 ->SetUnderlaySurfaceOffsetAndExtendedHitArea( | |
| 1527 server_id(window), offset.x(), offset.y(), | |
| 1528 gfx::ConvertInsetsToDIP(device_scale_factor, hit_area)); | |
| 1529 } | |
| 1435 } | 1530 } |
| 1436 } | 1531 } |
| 1437 | 1532 |
| 1438 } // namespace ui | 1533 } // namespace ui |
| OLD | NEW |