Index: ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc |
diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc |
index a6f120943f57de515556c227b84f04f8f253b208..c73c51b30927f05f33fef84c7ccc51b40b2cdf86 100644 |
--- a/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc |
+++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_x11.cc |
@@ -31,12 +31,15 @@ |
#include "ui/events/x/device_list_cache_x.h" |
#include "ui/events/x/touch_factory_x11.h" |
#include "ui/gfx/display.h" |
+#include "ui/gfx/geometry/size_conversions.h" |
#include "ui/gfx/image/image_skia.h" |
#include "ui/gfx/image/image_skia_rep.h" |
#include "ui/gfx/insets.h" |
#include "ui/gfx/path.h" |
#include "ui/gfx/path_x11.h" |
+#include "ui/gfx/point.h" |
#include "ui/gfx/screen.h" |
+#include "ui/gfx/size.h" |
#include "ui/native_theme/native_theme.h" |
#include "ui/views/corewm/tooltip_aura.h" |
#include "ui/views/ime/input_method.h" |
@@ -123,6 +126,46 @@ const char* kAtomsToCache[] = { |
} // namespace |
+float GetDeviceScaleFactor() { |
+ gfx::Display display = gfx::Screen::GetNativeScreen()->GetPrimaryDisplay(); |
+ return display.device_scale_factor(); |
+} |
+ |
+gfx::Point ScreenToDIPPoint(const gfx::Point& pixel_point) { |
+ return ToFlooredPoint(ScalePoint(pixel_point, 1.0f / GetDeviceScaleFactor())); |
+} |
+ |
+gfx::Point DIPToScreenPoint(const gfx::Point& dip_point) { |
+ return ToFlooredPoint(gfx::ScalePoint(dip_point, GetDeviceScaleFactor())); |
+} |
+ |
+gfx::Size ScreenToDIPSize(const gfx::Size& size_in_pixels) { |
+ // Always ceil sizes. Otherwise we may be leaving off part of the bounds. |
+ return gfx::ToCeiledSize( |
+ gfx::ScaleSize(size_in_pixels, 1.0f / GetDeviceScaleFactor())); |
+} |
+ |
+gfx::Size DIPToScreenSize(const gfx::Size& dip_size) { |
+ // Always ceil sizes. Otherwise we may be leaving off part of the bounds. |
+ return gfx::ToCeiledSize(gfx::ScaleSize(dip_size, GetDeviceScaleFactor())); |
+} |
+ |
+gfx::Rect DIPToScreenRect(const gfx::Rect& dip_bounds) { |
+ // See comment in ScreenToDIPRect for why we calculate size like this. |
+ return gfx::Rect(DIPToScreenPoint(dip_bounds.origin()), |
+ DIPToScreenSize(dip_bounds.size())); |
+} |
+ |
+gfx::Rect ScreenToDIPRect(const gfx::Rect& pixel_bounds) { |
+ // It's important we scale the origin and size separately. If we instead |
+ // calculated the size from the floored origin and ceiled right the size could |
+ // vary depending upon where the two points land. That would cause problems |
+ // for the places this code is used (in particular mapping from native window |
+ // bounds to DIPs). |
+ return gfx::Rect(ScreenToDIPPoint(pixel_bounds.origin()), |
+ ScreenToDIPSize(pixel_bounds.size())); |
+} |
+ |
//////////////////////////////////////////////////////////////////////////////// |
// DesktopWindowTreeHostX11, public: |
@@ -385,7 +428,7 @@ bool DesktopWindowTreeHostX11::IsVisible() const { |
} |
void DesktopWindowTreeHostX11::SetSize(const gfx::Size& requested_size) { |
- gfx::Size size = AdjustSize(requested_size); |
+ gfx::Size size = AdjustSize(DIPToScreenSize(requested_size)); |
bool size_changed = bounds_.size() != size; |
XResizeWindow(xdisplay_, xwindow_, size.width(), size.height()); |
bounds_.set_size(size); |
@@ -399,9 +442,11 @@ void DesktopWindowTreeHostX11::StackAtTop() { |
XRaiseWindow(xdisplay_, xwindow_); |
} |
-void DesktopWindowTreeHostX11::CenterWindow(const gfx::Size& size) { |
+void DesktopWindowTreeHostX11::CenterWindow(const gfx::Size& size_dip) { |
gfx::Rect parent_bounds = GetWorkAreaBoundsInScreen(); |
+ gfx::Size size = DIPToScreenSize(size_dip); |
+ |
// If |window_|'s transient parent bounds are big enough to contain |size|, |
// use them instead. |
if (wm::GetTransientParent(content_window_)) { |
@@ -444,7 +489,7 @@ void DesktopWindowTreeHostX11::GetWindowPlacement( |
} |
gfx::Rect DesktopWindowTreeHostX11::GetWindowBoundsInScreen() const { |
- return bounds_; |
+ return ScreenToDIPRect(bounds_); |
} |
gfx::Rect DesktopWindowTreeHostX11::GetClientAreaBoundsInScreen() const { |
@@ -456,7 +501,7 @@ gfx::Rect DesktopWindowTreeHostX11::GetClientAreaBoundsInScreen() const { |
// Attempts to calculate the rect by asking the NonClientFrameView what it |
// thought its GetBoundsForClientView() were broke combobox drop down |
// placement. |
- return bounds_; |
+ return ScreenToDIPRect(bounds_); |
} |
gfx::Rect DesktopWindowTreeHostX11::GetRestoredBounds() const { |
@@ -465,7 +510,7 @@ gfx::Rect DesktopWindowTreeHostX11::GetRestoredBounds() const { |
// or restoring bounds, we can record the current bounds before we request |
// maximization, and clear it when we detect a state change. |
if (!restored_bounds_.IsEmpty()) |
- return restored_bounds_; |
+ return ScreenToDIPRect(restored_bounds_); |
return GetWindowBoundsInScreen(); |
} |
@@ -474,7 +519,7 @@ gfx::Rect DesktopWindowTreeHostX11::GetWorkAreaBoundsInScreen() const { |
std::vector<int> value; |
if (ui::GetIntArrayProperty(x_root_window_, "_NET_WORKAREA", &value) && |
value.size() >= 4) { |
- return gfx::Rect(value[0], value[1], value[2], value[3]); |
+ return ScreenToDIPRect(gfx::Rect(value[0], value[1], value[2], value[3])); |
} |
// Fetch the geometry of the root window. |
@@ -488,7 +533,7 @@ gfx::Rect DesktopWindowTreeHostX11::GetWorkAreaBoundsInScreen() const { |
return gfx::Rect(0, 0, 10, 10); |
} |
- return gfx::Rect(x, y, width, height); |
+ return ScreenToDIPRect(gfx::Rect(x, y, width, height)); |
Elliot Glaysher
2014/10/16 00:27:40
So bounds in screen are also dips?
scottmg
2014/10/17 00:09:11
Yeah, that's confusing, but that one's Screen/Clie
|
} |
void DesktopWindowTreeHostX11::SetShape(gfx::NativeRegion native_region) { |
@@ -1086,12 +1131,14 @@ void DesktopWindowTreeHostX11::InitX11Window( |
} |
} |
- bounds_ = gfx::Rect(params.bounds.origin(), |
- AdjustSize(params.bounds.size())); |
+ gfx::Point origin_screen = DIPToScreenPoint(params.bounds.origin()); |
+ gfx::Size size_screen = DIPToScreenSize(params.bounds.size()); |
+ bounds_ = gfx::Rect(origin_screen, |
+ AdjustSize(size_screen)); |
xwindow_ = XCreateWindow( |
xdisplay_, x_root_window_, |
- bounds_.x(), bounds_.y(), |
- bounds_.width(), bounds_.height(), |
+ origin_screen.x(), origin_screen.y(), |
+ size_screen.width(), size_screen.height(), |
0, // border width |
depth, |
InputOutput, |