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/shell/public/cpp/connector.h" | 15 #include "services/shell/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/window_drop_target.h" | 19 #include "services/ui/public/cpp/window_drop_target.h" |
| 20 #include "services/ui/public/cpp/window_manager_delegate.h" | 20 #include "services/ui/public/cpp/window_manager_delegate.h" |
| 21 #include "services/ui/public/cpp/window_observer.h" | 21 #include "services/ui/public/cpp/window_observer.h" |
| 22 #include "services/ui/public/cpp/window_private.h" | 22 #include "services/ui/public/cpp/window_private.h" |
| 23 #include "services/ui/public/cpp/window_tracker.h" | 23 #include "services/ui/public/cpp/window_tracker.h" |
| 24 #include "services/ui/public/cpp/window_tree_client_delegate.h" | 24 #include "services/ui/public/cpp/window_tree_client_delegate.h" |
| 25 #include "services/ui/public/cpp/window_tree_client_observer.h" | 25 #include "services/ui/public/cpp/window_tree_client_observer.h" |
| 26 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom .h" | 26 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom .h" |
| 27 #include "ui/display/screen.h" | |
| 27 #include "ui/events/event.h" | 28 #include "ui/events/event.h" |
| 28 #include "ui/gfx/geometry/insets.h" | 29 #include "ui/gfx/geometry/insets.h" |
| 29 #include "ui/gfx/geometry/size.h" | 30 #include "ui/gfx/geometry/size.h" |
| 31 #include "ui/gfx/geometry/vector2d_conversions.h" | |
| 30 | 32 |
| 31 namespace ui { | 33 namespace ui { |
| 32 | 34 |
| 33 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) { | 35 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) { |
| 34 return (client_id << 16) | local_id; | 36 return (client_id << 16) | local_id; |
| 35 } | 37 } |
| 36 | 38 |
| 37 // Helper called to construct a local window object from transport data. | 39 // Helper called to construct a local window object from transport data. |
| 38 Window* AddWindowToClient(WindowTreeClient* client, | 40 Window* AddWindowToClient(WindowTreeClient* client, |
| 39 Window* parent, | 41 Window* parent, |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 241 base::MakeUnique<InFlightCaptureChange>(this, window)); | 243 base::MakeUnique<InFlightCaptureChange>(this, window)); |
| 242 tree_->ReleaseCapture(change_id, server_id(window)); | 244 tree_->ReleaseCapture(change_id, server_id(window)); |
| 243 LocalSetCapture(nullptr); | 245 LocalSetCapture(nullptr); |
| 244 } | 246 } |
| 245 | 247 |
| 246 void WindowTreeClient::SetClientArea( | 248 void WindowTreeClient::SetClientArea( |
| 247 Id window_id, | 249 Id window_id, |
| 248 const gfx::Insets& client_area, | 250 const gfx::Insets& client_area, |
| 249 const std::vector<gfx::Rect>& additional_client_areas) { | 251 const std::vector<gfx::Rect>& additional_client_areas) { |
| 250 DCHECK(tree_); | 252 DCHECK(tree_); |
| 251 tree_->SetClientArea(window_id, client_area, additional_client_areas); | 253 Window* window = GetWindowByServerId(window_id); |
| 254 // TODO(riajiang): Change to use display::GetDisplayWithDisplayId() after | |
| 255 // https://codereview.chromium.org/2361283002/ is landed. | |
| 256 int64_t display_id = window->display_id(); | |
| 257 std::vector<display::Display> displays = | |
| 258 display::Screen::GetScreen()->GetAllDisplays(); | |
| 259 auto iter = std::find_if(displays.begin(), displays.end(), | |
| 260 [display_id](const display::Display& display) { | |
| 261 return display.id() == display_id; | |
| 262 }); | |
| 263 if (iter != displays.end()) { | |
| 264 if (iter->device_scale_factor() == 1.f) { | |
| 265 tree_->SetClientArea(window_id, client_area, additional_client_areas); | |
| 266 } else { | |
| 267 std::vector<gfx::Rect> scaled_additional_client_areas; | |
| 268 for (const gfx::Rect& area : additional_client_areas) { | |
| 269 scaled_additional_client_areas.push_back( | |
| 270 gfx::ScaleToEnclosingRect(area, iter->device_scale_factor())); | |
| 271 } | |
| 272 tree_->SetClientArea(window_id, | |
| 273 client_area.Scale(iter->device_scale_factor()), | |
| 274 scaled_additional_client_areas); | |
| 275 } | |
| 276 } | |
| 252 } | 277 } |
| 253 | 278 |
| 254 void WindowTreeClient::SetHitTestMask(Id window_id, const gfx::Rect& mask) { | 279 void WindowTreeClient::SetHitTestMask(Id window_id, const gfx::Rect& mask) { |
| 255 DCHECK(tree_); | 280 DCHECK(tree_); |
| 256 tree_->SetHitTestMask(window_id, mask); | 281 tree_->SetHitTestMask(window_id, mask); |
| 257 } | 282 } |
| 258 | 283 |
| 259 void WindowTreeClient::ClearHitTestMask(Id window_id) { | 284 void WindowTreeClient::ClearHitTestMask(Id window_id) { |
| 260 DCHECK(tree_); | 285 DCHECK(tree_); |
| 261 tree_->SetHitTestMask(window_id, base::nullopt); | 286 tree_->SetHitTestMask(window_id, base::nullopt); |
| (...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 884 | 909 |
| 885 WindowPrivate(window).LocalSetBounds(old_bounds, new_bounds); | 910 WindowPrivate(window).LocalSetBounds(old_bounds, new_bounds); |
| 886 } | 911 } |
| 887 | 912 |
| 888 void WindowTreeClient::OnClientAreaChanged( | 913 void WindowTreeClient::OnClientAreaChanged( |
| 889 uint32_t window_id, | 914 uint32_t window_id, |
| 890 const gfx::Insets& new_client_area, | 915 const gfx::Insets& new_client_area, |
| 891 mojo::Array<gfx::Rect> new_additional_client_areas) { | 916 mojo::Array<gfx::Rect> new_additional_client_areas) { |
| 892 Window* window = GetWindowByServerId(window_id); | 917 Window* window = GetWindowByServerId(window_id); |
| 893 if (window) { | 918 if (window) { |
| 894 WindowPrivate(window).LocalSetClientArea( | 919 // TODO(riajiang): Change to use display::GetDisplayWithDisplayId() after |
|
sky
2016/10/06 16:38:13
You could at least make this code use a common fun
riajiang
2016/10/06 19:33:03
Yes! Done.
| |
| 895 new_client_area, | 920 // https://codereview.chromium.org/2361283002/ is landed. |
| 896 new_additional_client_areas.To<std::vector<gfx::Rect>>()); | 921 int64_t display_id = window->display_id(); |
| 922 std::vector<display::Display> displays = | |
| 923 display::Screen::GetScreen()->GetAllDisplays(); | |
| 924 auto iter = std::find_if(displays.begin(), displays.end(), | |
| 925 [display_id](const display::Display& display) { | |
| 926 return display.id() == display_id; | |
| 927 }); | |
| 928 if (iter != displays.end()) { | |
| 929 if (iter->device_scale_factor() == 1.f) { | |
| 930 WindowPrivate(window).LocalSetClientArea( | |
| 931 new_client_area, | |
| 932 new_additional_client_areas.To<std::vector<gfx::Rect>>()); | |
| 933 } else { | |
| 934 std::vector<gfx::Rect> scaled_new_additional_client_areas; | |
| 935 for (const gfx::Rect& area : new_additional_client_areas) { | |
| 936 scaled_new_additional_client_areas.push_back( | |
| 937 gfx::ScaleToEnclosingRect(area, | |
| 938 1.f / iter->device_scale_factor())); | |
| 939 } | |
| 940 WindowPrivate(window).LocalSetClientArea( | |
| 941 new_client_area.Scale(1.f / iter->device_scale_factor()), | |
| 942 scaled_new_additional_client_areas); | |
| 943 } | |
| 944 } | |
| 897 } | 945 } |
| 898 } | 946 } |
| 899 | 947 |
| 900 void WindowTreeClient::OnTransientWindowAdded( | 948 void WindowTreeClient::OnTransientWindowAdded( |
| 901 uint32_t window_id, | 949 uint32_t window_id, |
| 902 uint32_t transient_window_id) { | 950 uint32_t transient_window_id) { |
| 903 Window* window = GetWindowByServerId(window_id); | 951 Window* window = GetWindowByServerId(window_id); |
| 904 Window* transient_window = GetWindowByServerId(transient_window_id); | 952 Window* transient_window = GetWindowByServerId(transient_window_id); |
| 905 // window or transient_window or both may be null if a local delete occurs | 953 // window or transient_window or both may be null if a local delete occurs |
| 906 // with an in flight add from the server. | 954 // with an in flight add from the server. |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1400 void WindowTreeClient::ActivateNextWindow() { | 1448 void WindowTreeClient::ActivateNextWindow() { |
| 1401 if (window_manager_internal_client_) | 1449 if (window_manager_internal_client_) |
| 1402 window_manager_internal_client_->ActivateNextWindow(); | 1450 window_manager_internal_client_->ActivateNextWindow(); |
| 1403 } | 1451 } |
| 1404 | 1452 |
| 1405 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1453 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1406 Window* window, | 1454 Window* window, |
| 1407 const gfx::Vector2d& offset, | 1455 const gfx::Vector2d& offset, |
| 1408 const gfx::Insets& hit_area) { | 1456 const gfx::Insets& hit_area) { |
| 1409 if (window_manager_internal_client_) { | 1457 if (window_manager_internal_client_) { |
| 1410 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1458 // TODO(riajiang): Change to use display::GetDisplayWithDisplayId() after |
| 1411 server_id(window), offset.x(), offset.y(), hit_area); | 1459 // https://codereview.chromium.org/2361283002/ is landed. |
| 1460 int64_t display_id = window->display_id(); | |
| 1461 std::vector<display::Display> displays = | |
| 1462 display::Screen::GetScreen()->GetAllDisplays(); | |
| 1463 auto iter = std::find_if(displays.begin(), displays.end(), | |
| 1464 [display_id](const display::Display& display) { | |
| 1465 return display.id() == display_id; | |
| 1466 }); | |
| 1467 if (iter != displays.end()) { | |
| 1468 if (iter->device_scale_factor() == 1.f) { | |
| 1469 window_manager_internal_client_ | |
| 1470 ->SetUnderlaySurfaceOffsetAndExtendedHitArea( | |
| 1471 server_id(window), offset.x(), offset.y(), hit_area); | |
| 1472 } else { | |
| 1473 window_manager_internal_client_ | |
| 1474 ->SetUnderlaySurfaceOffsetAndExtendedHitArea( | |
| 1475 server_id(window), offset.x(), offset.y(), | |
| 1476 hit_area.Scale(1.f / iter->device_scale_factor())); | |
| 1477 } | |
| 1478 } | |
| 1412 } | 1479 } |
| 1413 } | 1480 } |
| 1414 | 1481 |
| 1415 } // namespace ui | 1482 } // namespace ui |
| OLD | NEW |