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 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 127 if (type_iter == properties.end()) | 127 if (type_iter == properties.end()) |
| 128 return; | 128 return; |
| 129 | 129 |
| 130 // TODO: need to validate type! http://crbug.com/654924. | 130 // TODO: need to validate type! http://crbug.com/654924. |
| 131 ui::mojom::WindowType window_type = static_cast<ui::mojom::WindowType>( | 131 ui::mojom::WindowType window_type = static_cast<ui::mojom::WindowType>( |
| 132 mojo::ConvertTo<int32_t>(type_iter->second)); | 132 mojo::ConvertTo<int32_t>(type_iter->second)); |
| 133 SetWindowType(window, window_type); | 133 SetWindowType(window, window_type); |
| 134 } | 134 } |
| 135 | 135 |
| 136 // Helper function to get the device_scale_factor() of the display::Display | 136 // Helper function to get the device_scale_factor() of the display::Display |
| 137 // with |display_id|. | 137 // nearest to |window|. |
| 138 float ScaleFactorForDisplay(Window* window) { | 138 float ScaleFactorForDisplay(Window* window) { |
| 139 // TODO(riajiang): Change to use display::GetDisplayWithDisplayId() after | |
| 140 // https://codereview.chromium.org/2361283002/ is landed. | |
| 141 return display::Screen::GetScreen() | 139 return display::Screen::GetScreen() |
| 142 ->GetDisplayNearestWindow(window) | 140 ->GetDisplayNearestWindow(window) |
| 143 .device_scale_factor(); | 141 .device_scale_factor(); |
| 144 } | 142 } |
| 145 | 143 |
| 146 } // namespace | 144 } // namespace |
| 147 | 145 |
| 148 WindowTreeClient::WindowTreeClient( | 146 WindowTreeClient::WindowTreeClient( |
| 149 service_manager::Connector* connector, | 147 service_manager::Connector* connector, |
| 150 WindowTreeClientDelegate* delegate, | 148 WindowTreeClientDelegate* delegate, |
| (...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 638 | 636 |
| 639 void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window, | 637 void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window, |
| 640 const gfx::Rect& old_bounds, | 638 const gfx::Rect& old_bounds, |
| 641 const gfx::Rect& new_bounds) { | 639 const gfx::Rect& new_bounds) { |
| 642 // Changes to bounds of root windows are routed through | 640 // Changes to bounds of root windows are routed through |
| 643 // OnWindowTreeHostBoundsWillChange(). Any bounds that happen here are a side | 641 // OnWindowTreeHostBoundsWillChange(). Any bounds that happen here are a side |
| 644 // effect of those and can be ignored. | 642 // effect of those and can be ignored. |
| 645 if (IsRoot(window)) | 643 if (IsRoot(window)) |
| 646 return; | 644 return; |
| 647 | 645 |
| 648 ScheduleInFlightBoundsChange(window, old_bounds, new_bounds); | 646 ScheduleInFlightBoundsChange( |
| 647 window, gfx::ConvertRectToPixel( | |
| 648 ScaleFactorForDisplay(window->GetWindow()), old_bounds), | |
| 649 gfx::ConvertRectToPixel(ScaleFactorForDisplay(window->GetWindow()), | |
| 650 new_bounds)); | |
| 649 } | 651 } |
| 650 | 652 |
| 651 void WindowTreeClient::OnWindowMusAddChild(WindowMus* parent, | 653 void WindowTreeClient::OnWindowMusAddChild(WindowMus* parent, |
| 652 WindowMus* child) { | 654 WindowMus* child) { |
| 653 // TODO: add checks to ensure this can work. | 655 // TODO: add checks to ensure this can work. |
| 654 const uint32_t change_id = ScheduleInFlightChange( | 656 const uint32_t change_id = ScheduleInFlightChange( |
| 655 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::ADD_CHILD)); | 657 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::ADD_CHILD)); |
| 656 tree_->AddWindow(change_id, parent->server_id(), child->server_id()); | 658 tree_->AddWindow(change_id, parent->server_id(), child->server_id()); |
| 657 } | 659 } |
| 658 | 660 |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 915 SetWindowVisibleFromServer(window, true); | 917 SetWindowVisibleFromServer(window, true); |
| 916 } | 918 } |
| 917 | 919 |
| 918 const gfx::Rect bounds(data->bounds); | 920 const gfx::Rect bounds(data->bounds); |
| 919 { | 921 { |
| 920 InFlightBoundsChange bounds_change(this, window, bounds); | 922 InFlightBoundsChange bounds_change(this, window, bounds); |
| 921 InFlightChange* current_change = | 923 InFlightChange* current_change = |
| 922 GetOldestInFlightChangeMatching(bounds_change); | 924 GetOldestInFlightChangeMatching(bounds_change); |
| 923 if (current_change) | 925 if (current_change) |
| 924 current_change->SetRevertValueFrom(bounds_change); | 926 current_change->SetRevertValueFrom(bounds_change); |
| 925 else if (window->GetWindow()->bounds() != bounds) | 927 else if (gfx::ConvertRectToPixel(ScaleFactorForDisplay(window->GetWindow()), |
| 928 window->GetWindow()->bounds()) != bounds) | |
|
sadrul
2016/12/16 18:14:08
Some conversions are happening in WindowPortMus, a
riajiang
2016/12/19 23:51:55
Moved all conversions in WTC. ServerChangeData now
| |
| 926 SetWindowBoundsFromServer(window, bounds); | 929 SetWindowBoundsFromServer(window, bounds); |
| 927 } | 930 } |
| 928 | 931 |
| 929 // There is currently no API to bulk set properties, so we iterate over each | 932 // There is currently no API to bulk set properties, so we iterate over each |
| 930 // property individually. | 933 // property individually. |
| 931 for (const auto& pair : data->properties) { | 934 for (const auto& pair : data->properties) { |
| 932 std::unique_ptr<std::vector<uint8_t>> revert_value( | 935 std::unique_ptr<std::vector<uint8_t>> revert_value( |
| 933 base::MakeUnique<std::vector<uint8_t>>(pair.second)); | 936 base::MakeUnique<std::vector<uint8_t>>(pair.second)); |
| 934 InFlightPropertyChange property_change(window, pair.first, | 937 InFlightPropertyChange property_change(window, pair.first, |
| 935 std::move(revert_value)); | 938 std::move(revert_value)); |
| (...skipping 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1337 } | 1340 } |
| 1338 } | 1341 } |
| 1339 } | 1342 } |
| 1340 | 1343 |
| 1341 void WindowTreeClient::WmDisplayModified(const display::Display& display) { | 1344 void WindowTreeClient::WmDisplayModified(const display::Display& display) { |
| 1342 DCHECK(window_manager_delegate_); | 1345 DCHECK(window_manager_delegate_); |
| 1343 // TODO(sky): this should likely route to WindowTreeHost. | 1346 // TODO(sky): this should likely route to WindowTreeHost. |
| 1344 window_manager_delegate_->OnWmDisplayModified(display); | 1347 window_manager_delegate_->OnWmDisplayModified(display); |
| 1345 } | 1348 } |
| 1346 | 1349 |
| 1347 // TODO(riajiang): Convert between pixel and DIP for window bounds properly. | |
| 1348 // (http://crbug.com/646942) | |
| 1349 void WindowTreeClient::WmSetBounds(uint32_t change_id, | 1350 void WindowTreeClient::WmSetBounds(uint32_t change_id, |
| 1350 Id window_id, | 1351 Id window_id, |
| 1351 const gfx::Rect& transit_bounds) { | 1352 const gfx::Rect& transit_bounds) { |
|
sky
2016/12/15 22:07:32
Rename to transit_bounds_in_pixels.
riajiang
2016/12/19 23:51:55
Done.
| |
| 1352 WindowMus* window = GetWindowByServerId(window_id); | 1353 WindowMus* window = GetWindowByServerId(window_id); |
| 1353 bool result = false; | 1354 bool result = false; |
| 1354 if (window) { | 1355 if (window) { |
| 1356 float device_scale_factor = ScaleFactorForDisplay(window->GetWindow()); | |
| 1355 DCHECK(window_manager_delegate_); | 1357 DCHECK(window_manager_delegate_); |
| 1356 gfx::Rect bounds = transit_bounds; | 1358 gfx::Rect transit_bounds_in_dip = |
| 1359 gfx::ConvertRectToDIP(device_scale_factor, transit_bounds); | |
| 1360 gfx::Rect bounds_in_dip = transit_bounds_in_dip; | |
| 1357 // TODO: this needs to trigger scheduling a bounds change on |window|. | 1361 // TODO: this needs to trigger scheduling a bounds change on |window|. |
| 1358 result = | 1362 result = window_manager_delegate_->OnWmSetBounds(window->GetWindow(), |
| 1359 window_manager_delegate_->OnWmSetBounds(window->GetWindow(), &bounds); | 1363 &bounds_in_dip); |
| 1360 if (result) { | 1364 if (result) { |
| 1361 // If the resulting bounds differ return false. Returning false ensures | 1365 // If the resulting bounds differ return false. Returning false ensures |
| 1362 // the client applies the bounds we set below. | 1366 // the client applies the bounds we set below. |
| 1363 result = bounds == transit_bounds; | 1367 result = bounds_in_dip == transit_bounds_in_dip; |
| 1364 window->SetBoundsFromServer(bounds); | 1368 window->SetBoundsFromServer( |
| 1369 gfx::ConvertRectToPixel(device_scale_factor, bounds_in_dip)); | |
|
sky
2016/12/15 22:07:32
I think you should fix 672151 before this, otherwi
riajiang
2016/12/19 23:51:55
As discussed, ignoring this comment.
| |
| 1365 } | 1370 } |
| 1366 } | 1371 } |
| 1367 if (window_manager_internal_client_) | 1372 if (window_manager_internal_client_) |
| 1368 window_manager_internal_client_->WmResponse(change_id, result); | 1373 window_manager_internal_client_->WmResponse(change_id, result); |
| 1369 } | 1374 } |
| 1370 | 1375 |
| 1371 void WindowTreeClient::WmSetProperty( | 1376 void WindowTreeClient::WmSetProperty( |
| 1372 uint32_t change_id, | 1377 uint32_t change_id, |
| 1373 Id window_id, | 1378 Id window_id, |
| 1374 const std::string& name, | 1379 const std::string& name, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1518 void WindowTreeClient::ActivateNextWindow() { | 1523 void WindowTreeClient::ActivateNextWindow() { |
| 1519 if (window_manager_internal_client_) | 1524 if (window_manager_internal_client_) |
| 1520 window_manager_internal_client_->ActivateNextWindow(); | 1525 window_manager_internal_client_->ActivateNextWindow(); |
| 1521 } | 1526 } |
| 1522 | 1527 |
| 1523 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1528 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1524 Window* window, | 1529 Window* window, |
| 1525 const gfx::Vector2d& offset, | 1530 const gfx::Vector2d& offset, |
| 1526 const gfx::Insets& hit_area) { | 1531 const gfx::Insets& hit_area) { |
| 1527 if (window_manager_internal_client_) { | 1532 if (window_manager_internal_client_) { |
| 1528 // TODO(riajiang): Figure out if |offset| needs to be converted. | 1533 float device_scale_factor = ScaleFactorForDisplay(window); |
| 1529 // (http://crbugs.com/646932) | |
| 1530 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1534 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1531 WindowMus::Get(window)->server_id(), offset.x(), offset.y(), | 1535 WindowMus::Get(window)->server_id(), offset.x() * device_scale_factor, |
| 1532 gfx::ConvertInsetsToDIP(ScaleFactorForDisplay(window), hit_area)); | 1536 offset.y() * device_scale_factor, |
| 1537 gfx::ConvertInsetsToPixel(device_scale_factor, hit_area)); | |
| 1533 } | 1538 } |
| 1534 } | 1539 } |
| 1535 | 1540 |
| 1536 void WindowTreeClient::RequestClose(Window* window) { | 1541 void WindowTreeClient::RequestClose(Window* window) { |
| 1537 DCHECK(window); | 1542 DCHECK(window); |
| 1538 if (window_manager_internal_client_) | 1543 if (window_manager_internal_client_) |
| 1539 window_manager_internal_client_->WmRequestClose( | 1544 window_manager_internal_client_->WmRequestClose( |
| 1540 WindowMus::Get(window)->server_id()); | 1545 WindowMus::Get(window)->server_id()); |
| 1541 } | 1546 } |
| 1542 | 1547 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1687 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( | 1692 return ScheduleInFlightChange(base::MakeUnique<InFlightCaptureChange>( |
| 1688 this, capture_synchronizer_.get(), window)); | 1693 this, capture_synchronizer_.get(), window)); |
| 1689 } | 1694 } |
| 1690 | 1695 |
| 1691 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { | 1696 uint32_t WindowTreeClient::CreateChangeIdForFocus(WindowMus* window) { |
| 1692 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( | 1697 return ScheduleInFlightChange(base::MakeUnique<InFlightFocusChange>( |
| 1693 this, focus_synchronizer_.get(), window)); | 1698 this, focus_synchronizer_.get(), window)); |
| 1694 } | 1699 } |
| 1695 | 1700 |
| 1696 } // namespace aura | 1701 } // namespace aura |
| OLD | NEW |