Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: ui/views/win/hwnd_message_handler.cc

Issue 12257016: (Not ready for review!) Toolbar and views high dpi support. Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Cleaned up more useless diffs. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/widget/aero_tooltip_manager.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/win/hwnd_message_handler.cc
diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc
index 6914dcd81fea44ba1a408fb1c012a9f1693a351d..c24479a601f7e6a40daf13b12485d5d80f3ac2fa 100644
--- a/ui/views/win/hwnd_message_handler.cc
+++ b/ui/views/win/hwnd_message_handler.cc
@@ -454,9 +454,28 @@ void HWNDMessageHandler::CloseNow() {
DestroyWindow(hwnd());
}
+void ConvertToScreen(RECT* rect) {
+#if defined(ENABLE_HIDPI)
+ static float os_scale = ui::GetDPIScale();
+ rect->left *= os_scale;
+ rect->right *= os_scale;
+ rect->top *= os_scale;
+ rect->bottom *= os_scale;
+#endif
+}
+
+void ConvertToScreen(POINT* point) {
+#if defined(ENABLE_HIDPI)
+ static float os_scale = ui::GetDPIScale();
+ point->x *= os_scale;
+ point->y *= os_scale;
+#endif
+}
+
gfx::Rect HWNDMessageHandler::GetWindowBoundsInScreen() const {
RECT r;
GetWindowRect(hwnd(), &r);
+ ConvertToScreen(&r);
return gfx::Rect(r);
}
@@ -465,6 +484,8 @@ gfx::Rect HWNDMessageHandler::GetClientAreaBoundsInScreen() const {
GetClientRect(hwnd(), &r);
POINT point = { r.left, r.top };
ClientToScreen(hwnd(), &point);
+ ConvertToScreen(&r); // Scales right/left
+ ConvertToScreen(&point); // Scale x/y
return gfx::Rect(point.x, point.y, r.right - r.left, r.bottom - r.top);
}
@@ -1041,6 +1062,17 @@ void HWNDMessageHandler::TrackMouseEvents(DWORD mouse_tracking_flags) {
}
}
+ui::ScaleFactor GetScaleFactor() {
+#if defined(ENABLE_HIDPI)
+ float scale = ui::GetDPIScale();
+ if (scale > 1.6)
+ return ui::SCALE_FACTOR_180P;
+ else if (scale > 1.2)
+ return ui::SCALE_FACTOR_140P;
+#endif
+ return ui::SCALE_FACTOR_100P;
+}
+
void HWNDMessageHandler::ClientAreaSizeChanged() {
RECT r = {0, 0, 0, 0};
if (delegate_->WidgetSizeIsClientSize()) {
@@ -1056,7 +1088,7 @@ void HWNDMessageHandler::ClientAreaSizeChanged() {
delegate_->HandleClientSizeChanged(s);
if (use_layered_buffer_) {
layered_window_contents_.reset(
- new gfx::Canvas(s, ui::SCALE_FACTOR_100P, false));
+ new gfx::Canvas(s, GetScaleFactor(), false));
}
}
@@ -1465,6 +1497,17 @@ LRESULT HWNDMessageHandler::OnMouseActivate(UINT message,
return MA_ACTIVATE;
}
+void ScaleScreenPoint(CPoint* point) {
+ static float dpi_scale = ui::GetDPIScale();
+ point->SetPoint( point->x * dpi_scale, point->y * dpi_scale);
+}
+
+void ScaleScreenPoint(POINT* point) {
+ static float dpi_scale = ui::GetDPIScale();
+ point->x *= dpi_scale;
+ point->y *= dpi_scale;
+}
+
LRESULT HWNDMessageHandler::OnMouseRange(UINT message,
WPARAM w_param,
LPARAM l_param) {
@@ -1480,6 +1523,7 @@ LRESULT HWNDMessageHandler::OnMouseRange(UINT message,
// |point| is in window coordinates, but WM_NCHITTEST and TrackPopupMenu()
// expect screen coordinates.
CPoint screen_point(l_param);
+ ScaleScreenPoint(&screen_point);
MapWindowPoints(hwnd(), HWND_DESKTOP, &screen_point, 1);
w_param = SendMessage(hwnd(), WM_NCHITTEST, 0,
MAKELPARAM(screen_point.x, screen_point.y));
@@ -1520,6 +1564,7 @@ LRESULT HWNDMessageHandler::OnMouseRange(UINT message,
MSG msg = { hwnd(), message, w_param, l_param, GetMessageTime(),
{ GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } };
+ //ScaleScreenPoint(&msg.pt);
ui::MouseEvent event(msg);
if (!touch_ids_.empty() || ui::IsMouseEventFromTouch(message))
event.set_flags(event.flags() | ui::EF_FROM_TOUCH);
« no previous file with comments | « ui/views/widget/aero_tooltip_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698