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 "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 DeviceScaleFactorForDisplay(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 = DeviceScaleFactorForDisplay(window); |
| 208 additional_client_areas); | 219 if (device_scale_factor == 1.f) { |
| 220 tree_->SetClientArea(WindowMus::Get(window)->server_id(), client_area, | |
| 221 additional_client_areas); | |
| 222 } else { | |
| 223 std::vector<gfx::Rect> additional_client_areas_in_pixel; | |
| 224 for (const gfx::Rect& area : additional_client_areas) { | |
| 225 additional_client_areas_in_pixel.push_back( | |
| 226 gfx::ConvertRectToPixel(device_scale_factor, area)); | |
| 227 } | |
| 228 tree_->SetClientArea( | |
| 229 WindowMus::Get(window)->server_id(), | |
| 230 gfx::ConvertInsetsToPixel(device_scale_factor, client_area), | |
| 231 additional_client_areas_in_pixel); | |
| 232 } | |
| 209 } | 233 } |
| 210 | 234 |
| 211 void WindowTreeClient::SetHitTestMask(Window* window, const gfx::Rect& mask) { | 235 void WindowTreeClient::SetHitTestMask(Window* window, const gfx::Rect& mask) { |
| 212 DCHECK(tree_); | 236 DCHECK(tree_); |
| 213 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), mask); | 237 float device_scale_factor = DeviceScaleFactorForDisplay(window); |
| 238 if (device_scale_factor == 1.f) { | |
| 239 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), mask); | |
| 240 } else { | |
| 241 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), | |
| 242 gfx::ConvertRectToPixel(device_scale_factor, mask)); | |
| 243 } | |
| 214 } | 244 } |
| 215 | 245 |
| 216 void WindowTreeClient::ClearHitTestMask(Window* window) { | 246 void WindowTreeClient::ClearHitTestMask(Window* window) { |
| 217 DCHECK(tree_); | 247 DCHECK(tree_); |
| 218 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), base::nullopt); | 248 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), base::nullopt); |
| 219 } | 249 } |
| 220 | 250 |
| 221 void WindowTreeClient::SetCanFocus(Window* window, bool can_focus) { | 251 void WindowTreeClient::SetCanFocus(Window* window, bool can_focus) { |
| 222 DCHECK(tree_); | 252 DCHECK(tree_); |
| 223 DCHECK(window); | 253 DCHECK(window); |
| (...skipping 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 940 return; | 970 return; |
| 941 | 971 |
| 942 SetWindowBoundsFromServer(window, new_bounds); | 972 SetWindowBoundsFromServer(window, new_bounds); |
| 943 } | 973 } |
| 944 | 974 |
| 945 void WindowTreeClient::OnClientAreaChanged( | 975 void WindowTreeClient::OnClientAreaChanged( |
| 946 uint32_t window_id, | 976 uint32_t window_id, |
| 947 const gfx::Insets& new_client_area, | 977 const gfx::Insets& new_client_area, |
| 948 mojo::Array<gfx::Rect> new_additional_client_areas) { | 978 mojo::Array<gfx::Rect> new_additional_client_areas) { |
| 949 // TODO: client area. | 979 // TODO: client area. |
| 980 // TODO(riajiang): Convert from pixel to DIP. | |
|
sky
2016/11/09 23:22:57
Reference bugs.
riajiang
2016/11/10 19:16:08
Done.
| |
| 950 /* | 981 /* |
| 951 Window* window = GetWindowByServerId(window_id); | 982 Window* window = GetWindowByServerId(window_id); |
| 952 if (window) { | 983 if (window) { |
| 953 WindowPrivate(window).LocalSetClientArea( | 984 WindowPrivate(window).LocalSetClientArea( |
| 954 new_client_area, | 985 new_client_area, |
| 955 new_additional_client_areas.To<std::vector<gfx::Rect>>()); | 986 new_additional_client_areas.To<std::vector<gfx::Rect>>()); |
| 956 } | 987 } |
| 957 */ | 988 */ |
| 958 } | 989 } |
| 959 | 990 |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1298 } | 1329 } |
| 1299 */ | 1330 */ |
| 1300 } | 1331 } |
| 1301 | 1332 |
| 1302 void WindowTreeClient::WmDisplayModified(const display::Display& display) { | 1333 void WindowTreeClient::WmDisplayModified(const display::Display& display) { |
| 1303 DCHECK(window_manager_delegate_); | 1334 DCHECK(window_manager_delegate_); |
| 1304 // TODO(sky): this should likely route to WindowTreeHost. | 1335 // TODO(sky): this should likely route to WindowTreeHost. |
| 1305 window_manager_delegate_->OnWmDisplayModified(display); | 1336 window_manager_delegate_->OnWmDisplayModified(display); |
| 1306 } | 1337 } |
| 1307 | 1338 |
| 1339 // TODO(riajiang): Convert between pixel and DIP for window bounds properly. | |
| 1308 void WindowTreeClient::WmSetBounds(uint32_t change_id, | 1340 void WindowTreeClient::WmSetBounds(uint32_t change_id, |
| 1309 Id window_id, | 1341 Id window_id, |
| 1310 const gfx::Rect& transit_bounds) { | 1342 const gfx::Rect& transit_bounds) { |
| 1311 WindowMus* window = GetWindowByServerId(window_id); | 1343 WindowMus* window = GetWindowByServerId(window_id); |
| 1312 bool result = false; | 1344 bool result = false; |
| 1313 if (window) { | 1345 if (window) { |
| 1314 DCHECK(window_manager_delegate_); | 1346 DCHECK(window_manager_delegate_); |
| 1315 gfx::Rect bounds = transit_bounds; | 1347 gfx::Rect bounds = transit_bounds; |
| 1316 // TODO: this needs to trigger scheduling a bounds change on |window|. | 1348 // TODO: this needs to trigger scheduling a bounds change on |window|. |
| 1317 result = | 1349 result = |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1464 void WindowTreeClient::ActivateNextWindow() { | 1496 void WindowTreeClient::ActivateNextWindow() { |
| 1465 if (window_manager_internal_client_) | 1497 if (window_manager_internal_client_) |
| 1466 window_manager_internal_client_->ActivateNextWindow(); | 1498 window_manager_internal_client_->ActivateNextWindow(); |
| 1467 } | 1499 } |
| 1468 | 1500 |
| 1469 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1501 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1470 Window* window, | 1502 Window* window, |
| 1471 const gfx::Vector2d& offset, | 1503 const gfx::Vector2d& offset, |
| 1472 const gfx::Insets& hit_area) { | 1504 const gfx::Insets& hit_area) { |
| 1473 if (window_manager_internal_client_) { | 1505 if (window_manager_internal_client_) { |
| 1474 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1506 float device_scale_factor = DeviceScaleFactorForDisplay(window); |
| 1475 WindowMus::Get(window)->server_id(), offset.x(), offset.y(), hit_area); | 1507 if (device_scale_factor == 1.f) { |
| 1508 window_manager_internal_client_ | |
| 1509 ->SetUnderlaySurfaceOffsetAndExtendedHitArea( | |
| 1510 WindowMus::Get(window)->server_id(), offset.x(), offset.y(), | |
| 1511 hit_area); | |
| 1512 } else { | |
| 1513 window_manager_internal_client_ | |
| 1514 ->SetUnderlaySurfaceOffsetAndExtendedHitArea( | |
| 1515 WindowMus::Get(window)->server_id(), offset.x(), offset.y(), | |
| 1516 gfx::ConvertInsetsToDIP(device_scale_factor, hit_area)); | |
| 1517 } | |
| 1476 } | 1518 } |
| 1477 } | 1519 } |
| 1478 | 1520 |
| 1479 void WindowTreeClient::OnWindowTreeHostBoundsWillChange( | 1521 void WindowTreeClient::OnWindowTreeHostBoundsWillChange( |
| 1480 WindowTreeHostMus* window_tree_host, | 1522 WindowTreeHostMus* window_tree_host, |
| 1481 const gfx::Rect& bounds) { | 1523 const gfx::Rect& bounds) { |
| 1482 ScheduleInFlightBoundsChange(WindowMus::Get(window_tree_host->window()), | 1524 ScheduleInFlightBoundsChange(WindowMus::Get(window_tree_host->window()), |
| 1483 window_tree_host->GetBounds(), bounds); | 1525 window_tree_host->GetBounds(), bounds); |
| 1484 } | 1526 } |
| 1485 | 1527 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1538 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( | 1580 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( |
| 1539 this, capture_synchronizer_.get(), window)); | 1581 this, capture_synchronizer_.get(), window)); |
| 1540 } | 1582 } |
| 1541 | 1583 |
| 1542 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { | 1584 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { |
| 1543 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( | 1585 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( |
| 1544 this, focus_synchronizer_.get(), window)); | 1586 this, focus_synchronizer_.get(), window)); |
| 1545 } | 1587 } |
| 1546 | 1588 |
| 1547 } // namespace aura | 1589 } // namespace aura |
| OLD | NEW |