Chromium Code Reviews| Index: ui/aura/mus/window_tree_client.cc |
| diff --git a/ui/aura/mus/window_tree_client.cc b/ui/aura/mus/window_tree_client.cc |
| index 5e8b37d2d29ec593d7aa67ab8d9cea795e9fb481..c2e94634f31f8b9a08eb15d7a83d8913c9688c38 100644 |
| --- a/ui/aura/mus/window_tree_client.cc |
| +++ b/ui/aura/mus/window_tree_client.cc |
| @@ -38,6 +38,7 @@ |
| #include "ui/display/display.h" |
| #include "ui/display/screen.h" |
| #include "ui/events/event.h" |
| +#include "ui/gfx/geometry/dip_util.h" |
| #include "ui/gfx/geometry/insets.h" |
| #include "ui/gfx/geometry/size.h" |
| @@ -117,6 +118,22 @@ bool IsInternalProperty(const void* key) { |
| return key == client::kModalKey; |
| } |
| +// Helper function to get the device_scale_factor() of the display::Display |
| +// with |display_id|. |
| +float DeviceScaleFactorForDisplay(int64_t display_id) { |
| + // TODO(riajiang): Change to use display::GetDisplayWithDisplayId() after |
| + // https://codereview.chromium.org/2361283002/ is landed. |
| + std::vector<display::Display> displays = |
| + display::Screen::GetScreen()->GetAllDisplays(); |
| + auto iter = std::find_if(displays.begin(), displays.end(), |
|
sky
2016/11/09 00:21:13
When this function is used you always have a windo
riajiang
2016/11/09 21:07:08
Changed to use GetDisplayNearestWindow. Kept the T
|
| + [display_id](const display::Display& display) { |
| + return display.id() == display_id; |
| + }); |
| + if (iter != displays.end()) |
| + return iter->device_scale_factor(); |
| + return 1.f; |
| +} |
| + |
| } // namespace |
| WindowTreeClient::WindowTreeClient( |
| @@ -204,13 +221,34 @@ void WindowTreeClient::SetClientArea( |
| const gfx::Insets& client_area, |
| const std::vector<gfx::Rect>& additional_client_areas) { |
| DCHECK(tree_); |
| - tree_->SetClientArea(WindowMus::Get(window)->server_id(), client_area, |
| - additional_client_areas); |
| + float device_scale_factor = |
| + DeviceScaleFactorForDisplay(GetWindowTreeHostMus(window)->display_id()); |
|
sky
2016/11/09 00:21:13
GetWindowTreeHostMus might return null.
riajiang
2016/11/09 21:07:08
Not using GetWindowTreeHostMus anymore since chang
|
| + if (device_scale_factor == 1.f) { |
| + tree_->SetClientArea(WindowMus::Get(window)->server_id(), client_area, |
| + additional_client_areas); |
| + } else { |
| + std::vector<gfx::Rect> additional_client_areas_in_pixel; |
| + for (const gfx::Rect& area : additional_client_areas) { |
| + additional_client_areas_in_pixel.push_back( |
| + gfx::ConvertRectToPixel(device_scale_factor, area)); |
| + } |
| + tree_->SetClientArea( |
| + WindowMus::Get(window)->server_id(), |
| + gfx::ConvertInsetsToPixel(device_scale_factor, client_area), |
| + additional_client_areas_in_pixel); |
| + } |
| } |
| void WindowTreeClient::SetHitTestMask(Window* window, const gfx::Rect& mask) { |
| DCHECK(tree_); |
| - tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), mask); |
| + float device_scale_factor = |
| + DeviceScaleFactorForDisplay(GetWindowTreeHostMus(window)->display_id()); |
| + if (device_scale_factor == 1.f) { |
| + tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), mask); |
| + } else { |
| + tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), |
| + gfx::ConvertRectToPixel(device_scale_factor, mask)); |
| + } |
| } |
| void WindowTreeClient::ClearHitTestMask(Window* window) { |
| @@ -947,6 +985,7 @@ void WindowTreeClient::OnClientAreaChanged( |
| const gfx::Insets& new_client_area, |
| mojo::Array<gfx::Rect> new_additional_client_areas) { |
| // TODO: client area. |
| + // TODO(riajiang): Convert from pixel to DIP. |
| /* |
| Window* window = GetWindowByServerId(window_id); |
| if (window) { |
| @@ -1305,6 +1344,7 @@ void WindowTreeClient::WmDisplayModified(const display::Display& display) { |
| window_manager_delegate_->OnWmDisplayModified(display); |
| } |
| +// TODO(riajiang): Convert between pixel and DIP for window bounds properly. |
| void WindowTreeClient::WmSetBounds(uint32_t change_id, |
| Id window_id, |
| const gfx::Rect& transit_bounds) { |
| @@ -1471,8 +1511,19 @@ void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| const gfx::Vector2d& offset, |
| const gfx::Insets& hit_area) { |
| if (window_manager_internal_client_) { |
| - window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| - WindowMus::Get(window)->server_id(), offset.x(), offset.y(), hit_area); |
| + float device_scale_factor = |
| + DeviceScaleFactorForDisplay(GetWindowTreeHostMus(window)->display_id()); |
| + if (device_scale_factor == 1.f) { |
| + window_manager_internal_client_ |
| + ->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| + WindowMus::Get(window)->server_id(), offset.x(), offset.y(), |
| + hit_area); |
| + } else { |
| + window_manager_internal_client_ |
| + ->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| + WindowMus::Get(window)->server_id(), offset.x(), offset.y(), |
| + gfx::ConvertInsetsToDIP(device_scale_factor, hit_area)); |
| + } |
| } |
| } |