Index: ui/views/widget/native_widget_win.cc |
diff --git a/ui/views/widget/native_widget_win.cc b/ui/views/widget/native_widget_win.cc |
index 8abb6aeab43fe31224f5728722397181d6f62d3c..cdcb1817c93cb4d4e83f1376c3402cd8fa26d2c2 100644 |
--- a/ui/views/widget/native_widget_win.cc |
+++ b/ui/views/widget/native_widget_win.cc |
@@ -23,6 +23,7 @@ |
#include "ui/base/l10n/l10n_util_win.h" |
#include "ui/base/theme_provider.h" |
#include "ui/base/view_prop.h" |
+#include "ui/base/win/dpi.h" |
#include "ui/base/win/hwnd_util.h" |
#include "ui/base/win/mouse_wheel_util.h" |
#include "ui/base/win/shell.h" |
@@ -30,7 +31,9 @@ |
#include "ui/gfx/canvas_paint.h" |
#include "ui/gfx/canvas_skia_paint.h" |
#include "ui/gfx/path.h" |
+#include "ui/gfx/point_conversions.h" |
#include "ui/gfx/screen.h" |
+#include "ui/gfx/size_conversions.h" |
#include "ui/native_theme/native_theme.h" |
#include "ui/views/controls/native_control_win.h" |
#include "ui/views/controls/textfield/textfield.h" |
@@ -97,6 +100,7 @@ NativeWidgetWin::~NativeWidgetWin() { |
// static |
gfx::Font NativeWidgetWin::GetWindowTitleFont() { |
+ // TODO: Consider scaling to screen dpi. |
kevers
2013/04/19 20:31:42
AdjustUIFont should already be adjusting the size
|
NONCLIENTMETRICS ncm; |
base::win::GetNonClientMetrics(&ncm); |
l10n_util::AdjustUIFont(&(ncm.lfCaptionFont)); |
@@ -112,8 +116,11 @@ void NativeWidgetWin::Show(int show_state) { |
// NativeWidgetWin, NativeWidget implementation: |
void NativeWidgetWin::InitNativeWidget(const Widget::InitParams& params) { |
- SetInitParams(params); |
- message_handler_->Init(params.parent, params.bounds); |
+ gfx::Rect pixel_bounds = ui::win::DIPToScreenRect(params.bounds); |
+ Widget::InitParams params_in_pixel(params); |
+ params_in_pixel.bounds = pixel_bounds; |
+ SetInitParams(params_in_pixel); |
+ message_handler_->Init(params.parent, pixel_bounds); |
} |
NonClientFrameView* NativeWidgetWin::CreateNonClientFrameView() { |
@@ -210,7 +217,8 @@ internal::InputMethodDelegate* NativeWidgetWin::GetInputMethodDelegate() { |
} |
void NativeWidgetWin::CenterWindow(const gfx::Size& size) { |
- message_handler_->CenterWindow(size); |
+ gfx::Size size_in_pixels = ui::win::DIPToScreenSize(size); |
+ message_handler_->CenterWindow(size_in_pixels); |
} |
void NativeWidgetWin::GetWindowPlacement( |
@@ -245,7 +253,11 @@ gfx::Rect NativeWidgetWin::GetRestoredBounds() const { |
} |
void NativeWidgetWin::SetBounds(const gfx::Rect& bounds) { |
- message_handler_->SetBounds(bounds); |
+ float scale = ui::win::GetDeviceScaleFactor(); |
+ gfx::Rect bounds_in_pixels( |
+ gfx::ToCeiledPoint(gfx::ScalePoint(bounds.origin(), scale)), |
+ gfx::ToFlooredSize(gfx::ScaleSize(bounds.size(), scale))); |
+ message_handler_->SetBounds(bounds_in_pixels); |
} |
void NativeWidgetWin::SetSize(const gfx::Size& size) { |
@@ -286,7 +298,8 @@ void NativeWidgetWin::Hide() { |
void NativeWidgetWin::ShowMaximizedWithBounds( |
const gfx::Rect& restored_bounds) { |
- message_handler_->ShowMaximizedWithBounds(restored_bounds); |
+ gfx::Rect pixel_bounds = ui::win::DIPToScreenRect(restored_bounds); |
+ message_handler_->ShowMaximizedWithBounds(pixel_bounds); |
} |
void NativeWidgetWin::ShowWithWindowState(ui::WindowShowState show_state) { |
@@ -392,7 +405,8 @@ void NativeWidgetWin::RunShellDrag(View* view, |
} |
void NativeWidgetWin::SchedulePaintInRect(const gfx::Rect& rect) { |
- message_handler_->SchedulePaintInRect(rect); |
+ gfx::Rect pixel_rect = ui::win::DIPToScreenRect(rect); |
+ message_handler_->SchedulePaintInRect(pixel_rect); |
} |
void NativeWidgetWin::SetCursor(gfx::NativeCursor cursor) { |
@@ -404,8 +418,9 @@ void NativeWidgetWin::ClearNativeFocus() { |
} |
gfx::Rect NativeWidgetWin::GetWorkAreaBoundsInScreen() const { |
- return gfx::Screen::GetNativeScreen()->GetDisplayNearestWindow( |
- GetNativeView()).work_area(); |
+ return ui::win::ScreenToDIPRect( |
+ gfx::Screen::GetNativeScreen()->GetDisplayNearestWindow( |
+ GetNativeView()).work_area()); |
} |
void NativeWidgetWin::SetInactiveRenderingDisabled(bool value) { |
@@ -535,12 +550,13 @@ bool NativeWidgetWin::GetClientAreaInsets(gfx::Insets* insets) const { |
void NativeWidgetWin::GetMinMaxSize(gfx::Size* min_size, |
gfx::Size* max_size) const { |
- *min_size = delegate_->GetMinimumSize(); |
- *max_size = delegate_->GetMaximumSize(); |
+ *min_size = ui::win::ScreenToDIPSize(delegate_->GetMinimumSize()); |
+ *max_size = ui::win::ScreenToDIPSize(delegate_->GetMaximumSize()); |
} |
gfx::Size NativeWidgetWin::GetRootViewSize() const { |
- return GetWidget()->GetRootView()->size(); |
+ gfx::Size pixel_size = GetWidget()->GetRootView()->size(); |
+ return ui::win::ScreenToDIPSize(pixel_size); |
} |
void NativeWidgetWin::ResetWindowControls() { |
@@ -675,7 +691,8 @@ void NativeWidgetWin::HandleVisibilityChanged(bool visible) { |
} |
void NativeWidgetWin::HandleClientSizeChanged(const gfx::Size& new_size) { |
- delegate_->OnNativeWidgetSizeChanged(new_size); |
+ gfx::Size size_in_dip = ui::win::ScreenToDIPSize(new_size); |
+ delegate_->OnNativeWidgetSizeChanged(size_in_dip); |
} |
void NativeWidgetWin::HandleFrameChanged() { |
@@ -698,8 +715,10 @@ void NativeWidgetWin::HandleNativeBlur(HWND focused_window) { |
} |
bool NativeWidgetWin::HandleMouseEvent(const ui::MouseEvent& event) { |
- delegate_->OnMouseEvent(const_cast<ui::MouseEvent*>(&event)); |
- return event.handled(); |
+ ui::MouseEvent dpi_event(event); |
+ dpi_event.set_location(ui::win::ScreenToDIPPoint(event.location())); |
+ delegate_->OnMouseEvent(&dpi_event); |
+ return dpi_event.handled(); |
} |
bool NativeWidgetWin::HandleKeyEvent(const ui::KeyEvent& event) { |
@@ -745,7 +764,8 @@ void NativeWidgetWin::HandleInputLanguageChange(DWORD character_set, |
} |
bool NativeWidgetWin::HandlePaintAccelerated(const gfx::Rect& invalid_rect) { |
- return delegate_->OnNativeWidgetPaintAccelerated(gfx::Rect(invalid_rect)); |
+ gfx::Rect dpi_rect = ui::win::ScreenToDIPRect(invalid_rect); |
+ return delegate_->OnNativeWidgetPaintAccelerated(dpi_rect); |
} |
void NativeWidgetWin::HandlePaint(gfx::Canvas* canvas) { |
@@ -834,11 +854,11 @@ bool Widget::ConvertRect(const Widget* source, |
if (source_hwnd == target_hwnd) |
return true; |
- RECT win_rect = rect->ToRECT(); |
+ RECT win_rect = ui::win::DIPToScreenRect(*rect).ToRECT(); |
if (::MapWindowPoints(source_hwnd, target_hwnd, |
reinterpret_cast<LPPOINT>(&win_rect), |
sizeof(RECT)/sizeof(POINT))) { |
- *rect = gfx::Rect(win_rect); |
+ *rect = ui::win::ScreenToDIPRect(gfx::Rect(win_rect)); |
return true; |
} |
return false; |