Chromium Code Reviews| Index: ui/views/mus/desktop_window_tree_host_mus.cc |
| diff --git a/ui/views/mus/desktop_window_tree_host_mus.cc b/ui/views/mus/desktop_window_tree_host_mus.cc |
| index 420841bc779c68fece4074e376a479be05299c5c..dd8625c51b80f924b29cf55600b90f81e611de6f 100644 |
| --- a/ui/views/mus/desktop_window_tree_host_mus.cc |
| +++ b/ui/views/mus/desktop_window_tree_host_mus.cc |
| @@ -12,6 +12,7 @@ |
| #include "ui/aura/mus/window_tree_host_mus.h" |
| #include "ui/aura/window.h" |
| #include "ui/display/screen.h" |
| +#include "ui/gfx/geometry/dip_util.h" |
| #include "ui/views/corewm/tooltip_aura.h" |
| #include "ui/views/mus/mus_client.h" |
| #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| @@ -49,9 +50,8 @@ bool DesktopWindowTreeHostMus::IsDocked() const { |
| void DesktopWindowTreeHostMus::Init(aura::Window* content_window, |
| const Widget::InitParams& params) { |
| - // TODO: handle device scale, http://crbug.com/663524. |
| if (!params.bounds.IsEmpty()) |
| - SetBounds(params.bounds); |
| + SetBounds(gfx::ConvertRectToPixel(GetScaleFactor(), params.bounds)); |
| } |
| void DesktopWindowTreeHostMus::OnNativeWidgetCreated( |
| @@ -152,11 +152,10 @@ bool DesktopWindowTreeHostMus::IsVisible() const { |
| void DesktopWindowTreeHostMus::SetSize(const gfx::Size& size) { |
| // Use GetBounds() as the origin of window() is always at 0, 0. |
| - gfx::Rect screen_bounds = GetBounds(); |
| - // TODO: handle device scale, http://crbug.com/663524. Also, |screen_bounds| |
| - // is in pixels and should be dip. |
| - screen_bounds.set_size(size); |
| - SetBounds(screen_bounds); |
| + gfx::Rect screen_bounds_in_pixels = GetBounds(); |
| + screen_bounds_in_pixels.set_size( |
| + gfx::ConvertSizeToPixel(GetScaleFactor(), size)); |
| + SetBounds(screen_bounds_in_pixels); |
|
sky
2016/11/21 22:27:25
This code is hard to read because it isn't clear w
|
| } |
| void DesktopWindowTreeHostMus::StackAbove(aura::Window* window) { |
| @@ -185,10 +184,7 @@ void DesktopWindowTreeHostMus::CenterWindow(const gfx::Size& size) { |
| gfx::Rect resulting_bounds(bounds_to_center_in); |
| resulting_bounds.ClampToCenteredSize(size); |
| - |
| - // TODO: handle device scale, http://crbug.com/663524. SetBounds() expects |
| - // pixels. |
| - SetBounds(resulting_bounds); |
| + SetBounds(gfx::ConvertRectToPixel(GetScaleFactor(), resulting_bounds)); |
| } |
| void DesktopWindowTreeHostMus::GetWindowPlacement( |
| @@ -200,8 +196,7 @@ void DesktopWindowTreeHostMus::GetWindowPlacement( |
| } |
| gfx::Rect DesktopWindowTreeHostMus::GetWindowBoundsInScreen() const { |
| - // TODO: convert to dips, http://crbug.com/663524. |
| - return GetBounds(); |
| + return gfx::ConvertRectToDIP(GetScaleFactor(), GetBounds()); |
| } |
| gfx::Rect DesktopWindowTreeHostMus::GetClientAreaBoundsInScreen() const { |
| @@ -431,14 +426,15 @@ void DesktopWindowTreeHostMus::HideImpl() { |
| } |
| void DesktopWindowTreeHostMus::SetBounds(const gfx::Rect& bounds_in_pixels) { |
| - // TODO: handle conversion to dips, http://crbug.com/663524. |
| gfx::Rect final_bounds_in_pixels = bounds_in_pixels; |
| if (GetBounds().size() != bounds_in_pixels.size()) { |
| gfx::Size size = bounds_in_pixels.size(); |
| - size.SetToMax(native_widget_delegate_->GetMinimumSize()); |
| - const gfx::Size max_size = native_widget_delegate_->GetMaximumSize(); |
| - if (!max_size.IsEmpty()) |
| - size.SetToMin(max_size); |
| + size.SetToMax(gfx::ConvertSizeToPixel( |
| + GetScaleFactor(), native_widget_delegate_->GetMinimumSize())); |
| + const gfx::Size max_size_in_pixels = gfx::ConvertSizeToPixel( |
| + GetScaleFactor(), native_widget_delegate_->GetMaximumSize()); |
| + if (!max_size_in_pixels.IsEmpty()) |
| + size.SetToMin(max_size_in_pixels); |
| final_bounds_in_pixels.set_size(size); |
| } |
| WindowTreeHostMus::SetBounds(final_bounds_in_pixels); |
| @@ -458,4 +454,11 @@ void DesktopWindowTreeHostMus::OnActiveFocusClientChanged( |
| } |
| } |
| +float DesktopWindowTreeHostMus::GetScaleFactor() const { |
| + // TODO(sky): GetDisplayNearestWindow() should take a const aura::Window*. |
| + return display::Screen::GetScreen() |
| + ->GetDisplayNearestWindow(const_cast<aura::Window*>(window())) |
| + .device_scale_factor(); |
| +} |
| + |
| } // namespace views |