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