Chromium Code Reviews| Index: chrome/browser/ui/views/frame/minimize_button_metrics_win.cc |
| diff --git a/chrome/browser/ui/views/frame/minimize_button_metrics_win.cc b/chrome/browser/ui/views/frame/minimize_button_metrics_win.cc |
| index 095f2574c83c9ed91b29b7ec8972c8022cbe5d8d..8084a4c4ebf69774f201710fdc2ec512eacfeff6 100644 |
| --- a/chrome/browser/ui/views/frame/minimize_button_metrics_win.cc |
| +++ b/chrome/browser/ui/views/frame/minimize_button_metrics_win.cc |
| @@ -4,11 +4,12 @@ |
| #include "chrome/browser/ui/views/frame/minimize_button_metrics_win.h" |
| -#include "base/logging.h" |
| #include "base/i18n/rtl.h" |
| +#include "base/logging.h" |
| #include "base/win/windows_version.h" |
| #include "dwmapi.h" |
| #include "ui/base/win/shell.h" |
| +#include "ui/display/display.h" |
| #include "ui/display/win/dpi.h" |
| #include "ui/display/win/screen_win.h" |
| #include "ui/gfx/geometry/point.h" |
| @@ -52,6 +53,28 @@ MinimizeButtonMetrics::MinimizeButtonMetrics() |
| MinimizeButtonMetrics::~MinimizeButtonMetrics() { |
| } |
| +// static |
| +int MinimizeButtonMetrics::GetCaptionButtonHeightInDIPs() { |
| + // At DPI scaling settings other than 100% the result won't be exactly right. |
| + // TODO: return a more accurate approximation [http://crbug.com/716365] |
| + |
| + // SM_CYSIZE returns the caption button height, but to get the full height |
| + // from the top of the window we add SM_CYSIZEFRAME. |
| + int cysize = GetSystemMetrics(SM_CYSIZE); |
| + int cysizeframe = GetSystemMetrics(SM_CYSIZEFRAME); |
|
Peter Kasting
2017/05/05 22:41:01
Nit: Dunno if this would be clearer if these were
emx
2017/05/09 09:37:58
Done.
|
| + |
| + // The result of GetSystemMetrics depends on the scale factor of the primary |
| + // display. Divide the sum by that to convert to DIPs. (Converting SM_CYSIZE |
| + // and SM_CYSIZEFRAME to DIPs individually adds a bigger rounding error.) |
| + float primary_device_scale_factor = |
| + display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor(); |
| + float height_dips = (cysize + cysizeframe) / primary_device_scale_factor; |
| + |
| + // Testing shows that floor() gives a more accurate approximation than |
| + // round() here. |
| + return std::floor(height_dips); |
| +} |
| + |
| void MinimizeButtonMetrics::Init(HWND hwnd) { |
| DCHECK(!hwnd_); |
| hwnd_ = hwnd; |
| @@ -123,7 +146,7 @@ int MinimizeButtonMetrics::GetMinimizeButtonOffsetForWindow() const { |
| TITLEBARINFOEX titlebar_info = {0}; |
| titlebar_info.cbSize = sizeof(TITLEBARINFOEX); |
| SendMessage(hwnd_, WM_GETTITLEBARINFOEX, 0, |
| - reinterpret_cast<WPARAM>(&titlebar_info)); |
| + reinterpret_cast<LPARAM>(&titlebar_info)); |
| // Under DWM WM_GETTITLEBARINFOEX won't return the right thing until after |
| // WM_NCACTIVATE (maybe it returns classic values?). In an attempt to |