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

Unified Diff: chrome/browser/ui/views/frame/minimize_button_metrics_win.cc

Issue 2833363002: Add GetCaptionButtonHeightInDIPs() method (Closed)
Patch Set: Renamed variables and removed call to GetCaptionButtonHeightInDIPs, which depends on a CL still beiā€¦ Created 3 years, 7 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 | « chrome/browser/ui/views/frame/minimize_button_metrics_win.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..93080cd5c189c62b00c9e8fe87185b438f2cf545 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,29 @@ 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.
+ const int caption_height = GetSystemMetrics(SM_CYSIZE);
+ const int frame_thickness = GetSystemMetrics(SM_CYSIZEFRAME);
+
+ // 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 =
+ (caption_height + frame_thickness) / 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 +147,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
« no previous file with comments | « chrome/browser/ui/views/frame/minimize_button_metrics_win.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698