| 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 "ui/aura/mus/window_tree_client.h" | 5 #include "ui/aura/mus/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> |
| (...skipping 21 matching lines...) Expand all Loading... |
| 32 #include "ui/aura/mus/window_tree_client_delegate.h" | 32 #include "ui/aura/mus/window_tree_client_delegate.h" |
| 33 #include "ui/aura/mus/window_tree_client_observer.h" | 33 #include "ui/aura/mus/window_tree_client_observer.h" |
| 34 #include "ui/aura/mus/window_tree_host_mus.h" | 34 #include "ui/aura/mus/window_tree_host_mus.h" |
| 35 #include "ui/aura/window.h" | 35 #include "ui/aura/window.h" |
| 36 #include "ui/aura/window_delegate.h" | 36 #include "ui/aura/window_delegate.h" |
| 37 #include "ui/aura/window_tracker.h" | 37 #include "ui/aura/window_tracker.h" |
| 38 #include "ui/base/ui_base_types.h" | 38 #include "ui/base/ui_base_types.h" |
| 39 #include "ui/display/display.h" | 39 #include "ui/display/display.h" |
| 40 #include "ui/display/screen.h" | 40 #include "ui/display/screen.h" |
| 41 #include "ui/events/event.h" | 41 #include "ui/events/event.h" |
| 42 #include "ui/gfx/geometry/dip_util.h" |
| 42 #include "ui/gfx/geometry/insets.h" | 43 #include "ui/gfx/geometry/insets.h" |
| 43 #include "ui/gfx/geometry/size.h" | 44 #include "ui/gfx/geometry/size.h" |
| 44 | 45 |
| 45 #if defined(HiWord) | 46 #if defined(HiWord) |
| 46 #undef HiWord | 47 #undef HiWord |
| 47 #endif | 48 #endif |
| 48 #if defined(LoWord) | 49 #if defined(LoWord) |
| 49 #undef LoWord | 50 #undef LoWord |
| 50 #endif | 51 #endif |
| 51 | 52 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 } | 112 } |
| 112 | 113 |
| 113 WindowTreeHostMus* GetWindowTreeHostMus(WindowMus* window) { | 114 WindowTreeHostMus* GetWindowTreeHostMus(WindowMus* window) { |
| 114 return GetWindowTreeHostMus(window->GetWindow()); | 115 return GetWindowTreeHostMus(window->GetWindow()); |
| 115 } | 116 } |
| 116 | 117 |
| 117 bool IsInternalProperty(const void* key) { | 118 bool IsInternalProperty(const void* key) { |
| 118 return key == client::kModalKey; | 119 return key == client::kModalKey; |
| 119 } | 120 } |
| 120 | 121 |
| 122 // Helper function to get the device_scale_factor() of the display::Display |
| 123 // with |display_id|. |
| 124 float ScaleFactorForDisplay(Window* window) { |
| 125 // TODO(riajiang): Change to use display::GetDisplayWithDisplayId() after |
| 126 // https://codereview.chromium.org/2361283002/ is landed. |
| 127 return display::Screen::GetScreen() |
| 128 ->GetDisplayNearestWindow(window) |
| 129 .device_scale_factor(); |
| 130 } |
| 131 |
| 121 } // namespace | 132 } // namespace |
| 122 | 133 |
| 123 WindowTreeClient::WindowTreeClient( | 134 WindowTreeClient::WindowTreeClient( |
| 124 WindowTreeClientDelegate* delegate, | 135 WindowTreeClientDelegate* delegate, |
| 125 WindowManagerDelegate* window_manager_delegate, | 136 WindowManagerDelegate* window_manager_delegate, |
| 126 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request) | 137 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request) |
| 127 : client_id_(0), | 138 : client_id_(0), |
| 128 next_window_id_(1), | 139 next_window_id_(1), |
| 129 next_change_id_(1), | 140 next_change_id_(1), |
| 130 delegate_(delegate), | 141 delegate_(delegate), |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 factory->CreateWindowTree(GetProxy(&window_tree), | 209 factory->CreateWindowTree(GetProxy(&window_tree), |
| 199 binding_.CreateInterfacePtrAndBind()); | 210 binding_.CreateInterfacePtrAndBind()); |
| 200 SetWindowTree(std::move(window_tree)); | 211 SetWindowTree(std::move(window_tree)); |
| 201 } | 212 } |
| 202 | 213 |
| 203 void WindowTreeClient::SetClientArea( | 214 void WindowTreeClient::SetClientArea( |
| 204 Window* window, | 215 Window* window, |
| 205 const gfx::Insets& client_area, | 216 const gfx::Insets& client_area, |
| 206 const std::vector<gfx::Rect>& additional_client_areas) { | 217 const std::vector<gfx::Rect>& additional_client_areas) { |
| 207 DCHECK(tree_); | 218 DCHECK(tree_); |
| 208 tree_->SetClientArea(WindowMus::Get(window)->server_id(), client_area, | 219 float device_scale_factor = ScaleFactorForDisplay(window); |
| 209 additional_client_areas); | 220 std::vector<gfx::Rect> additional_client_areas_in_pixel; |
| 221 for (const gfx::Rect& area : additional_client_areas) { |
| 222 additional_client_areas_in_pixel.push_back( |
| 223 gfx::ConvertRectToPixel(device_scale_factor, area)); |
| 224 } |
| 225 tree_->SetClientArea( |
| 226 WindowMus::Get(window)->server_id(), |
| 227 gfx::ConvertInsetsToPixel(device_scale_factor, client_area), |
| 228 additional_client_areas_in_pixel); |
| 210 } | 229 } |
| 211 | 230 |
| 212 void WindowTreeClient::SetHitTestMask(Window* window, const gfx::Rect& mask) { | 231 void WindowTreeClient::SetHitTestMask(Window* window, const gfx::Rect& mask) { |
| 213 DCHECK(tree_); | 232 DCHECK(tree_); |
| 214 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), mask); | 233 tree_->SetHitTestMask( |
| 234 WindowMus::Get(window)->server_id(), |
| 235 gfx::ConvertRectToPixel(ScaleFactorForDisplay(window), mask)); |
| 215 } | 236 } |
| 216 | 237 |
| 217 void WindowTreeClient::ClearHitTestMask(Window* window) { | 238 void WindowTreeClient::ClearHitTestMask(Window* window) { |
| 218 DCHECK(tree_); | 239 DCHECK(tree_); |
| 219 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), base::nullopt); | 240 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), base::nullopt); |
| 220 } | 241 } |
| 221 | 242 |
| 222 void WindowTreeClient::SetCanFocus(Window* window, bool can_focus) { | 243 void WindowTreeClient::SetCanFocus(Window* window, bool can_focus) { |
| 223 DCHECK(tree_); | 244 DCHECK(tree_); |
| 224 DCHECK(window); | 245 DCHECK(window); |
| (...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 935 return; | 956 return; |
| 936 | 957 |
| 937 SetWindowBoundsFromServer(window, new_bounds); | 958 SetWindowBoundsFromServer(window, new_bounds); |
| 938 } | 959 } |
| 939 | 960 |
| 940 void WindowTreeClient::OnClientAreaChanged( | 961 void WindowTreeClient::OnClientAreaChanged( |
| 941 uint32_t window_id, | 962 uint32_t window_id, |
| 942 const gfx::Insets& new_client_area, | 963 const gfx::Insets& new_client_area, |
| 943 mojo::Array<gfx::Rect> new_additional_client_areas) { | 964 mojo::Array<gfx::Rect> new_additional_client_areas) { |
| 944 // TODO: client area. | 965 // TODO: client area. |
| 966 // TODO(riajiang): Convert from pixel to DIP. (http://crbug.com/600815) |
| 945 /* | 967 /* |
| 946 Window* window = GetWindowByServerId(window_id); | 968 Window* window = GetWindowByServerId(window_id); |
| 947 if (window) { | 969 if (window) { |
| 948 WindowPrivate(window).LocalSetClientArea( | 970 WindowPrivate(window).LocalSetClientArea( |
| 949 new_client_area, | 971 new_client_area, |
| 950 new_additional_client_areas.To<std::vector<gfx::Rect>>()); | 972 new_additional_client_areas.To<std::vector<gfx::Rect>>()); |
| 951 } | 973 } |
| 952 */ | 974 */ |
| 953 } | 975 } |
| 954 | 976 |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1291 } | 1313 } |
| 1292 */ | 1314 */ |
| 1293 } | 1315 } |
| 1294 | 1316 |
| 1295 void WindowTreeClient::WmDisplayModified(const display::Display& display) { | 1317 void WindowTreeClient::WmDisplayModified(const display::Display& display) { |
| 1296 DCHECK(window_manager_delegate_); | 1318 DCHECK(window_manager_delegate_); |
| 1297 // TODO(sky): this should likely route to WindowTreeHost. | 1319 // TODO(sky): this should likely route to WindowTreeHost. |
| 1298 window_manager_delegate_->OnWmDisplayModified(display); | 1320 window_manager_delegate_->OnWmDisplayModified(display); |
| 1299 } | 1321 } |
| 1300 | 1322 |
| 1323 // TODO(riajiang): Convert between pixel and DIP for window bounds properly. |
| 1324 // (http://crbug.com/646942) |
| 1301 void WindowTreeClient::WmSetBounds(uint32_t change_id, | 1325 void WindowTreeClient::WmSetBounds(uint32_t change_id, |
| 1302 Id window_id, | 1326 Id window_id, |
| 1303 const gfx::Rect& transit_bounds) { | 1327 const gfx::Rect& transit_bounds) { |
| 1304 WindowMus* window = GetWindowByServerId(window_id); | 1328 WindowMus* window = GetWindowByServerId(window_id); |
| 1305 bool result = false; | 1329 bool result = false; |
| 1306 if (window) { | 1330 if (window) { |
| 1307 DCHECK(window_manager_delegate_); | 1331 DCHECK(window_manager_delegate_); |
| 1308 gfx::Rect bounds = transit_bounds; | 1332 gfx::Rect bounds = transit_bounds; |
| 1309 // TODO: this needs to trigger scheduling a bounds change on |window|. | 1333 // TODO: this needs to trigger scheduling a bounds change on |window|. |
| 1310 result = | 1334 result = |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 void WindowTreeClient::ActivateNextWindow() { | 1481 void WindowTreeClient::ActivateNextWindow() { |
| 1458 if (window_manager_internal_client_) | 1482 if (window_manager_internal_client_) |
| 1459 window_manager_internal_client_->ActivateNextWindow(); | 1483 window_manager_internal_client_->ActivateNextWindow(); |
| 1460 } | 1484 } |
| 1461 | 1485 |
| 1462 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1486 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1463 Window* window, | 1487 Window* window, |
| 1464 const gfx::Vector2d& offset, | 1488 const gfx::Vector2d& offset, |
| 1465 const gfx::Insets& hit_area) { | 1489 const gfx::Insets& hit_area) { |
| 1466 if (window_manager_internal_client_) { | 1490 if (window_manager_internal_client_) { |
| 1491 // TODO(riajiang): Figure out if |offset| needs to be converted. |
| 1492 // (http://crbugs.com/646932) |
| 1467 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1493 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1468 WindowMus::Get(window)->server_id(), offset.x(), offset.y(), hit_area); | 1494 WindowMus::Get(window)->server_id(), offset.x(), offset.y(), |
| 1495 gfx::ConvertInsetsToDIP(ScaleFactorForDisplay(window), hit_area)); |
| 1469 } | 1496 } |
| 1470 } | 1497 } |
| 1471 | 1498 |
| 1472 void WindowTreeClient::OnWindowTreeHostBoundsWillChange( | 1499 void WindowTreeClient::OnWindowTreeHostBoundsWillChange( |
| 1473 WindowTreeHostMus* window_tree_host, | 1500 WindowTreeHostMus* window_tree_host, |
| 1474 const gfx::Rect& bounds) { | 1501 const gfx::Rect& bounds) { |
| 1475 ScheduleInFlightBoundsChange(WindowMus::Get(window_tree_host->window()), | 1502 ScheduleInFlightBoundsChange(WindowMus::Get(window_tree_host->window()), |
| 1476 window_tree_host->GetBounds(), bounds); | 1503 window_tree_host->GetBounds(), bounds); |
| 1477 } | 1504 } |
| 1478 | 1505 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1531 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( | 1558 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( |
| 1532 this, capture_synchronizer_.get(), window)); | 1559 this, capture_synchronizer_.get(), window)); |
| 1533 } | 1560 } |
| 1534 | 1561 |
| 1535 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { | 1562 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { |
| 1536 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( | 1563 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( |
| 1537 this, focus_synchronizer_.get(), window)); | 1564 this, focus_synchronizer_.get(), window)); |
| 1538 } | 1565 } |
| 1539 | 1566 |
| 1540 } // namespace aura | 1567 } // namespace aura |
| OLD | NEW |