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

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

Issue 2833363002: Add GetCaptionButtonHeightInDIPs() method (Closed)
Patch Set: Addressed review comments Created 3 years, 8 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
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..1124386f9b2115a33f4235267c4b0fc7fd05bc78 100644
--- a/chrome/browser/ui/views/frame/minimize_button_metrics_win.cc
+++ b/chrome/browser/ui/views/frame/minimize_button_metrics_win.cc
@@ -24,6 +24,12 @@ const int kWin8ButtonBoundsPositionOffset = 10;
const int kWin10ButtonBoundsPositionOffset = 6;
const int kInvalidOffset = static_cast<int>(0x80000000);
+// These constant were determined manually by testing on Windows 7, 8 and 10.
+const int kWin7ButtonHeight = 20;
+const int kWin8ButtonHeight = 20;
+const int kWin10ButtonHeight = 28;
+const int kInvalidHeight = static_cast<int>(0x80000000);
+
using base::win::GetVersion;
using display::win::ScreenWin;
@@ -35,6 +41,14 @@ int GetDefaultButtonBoundsOffset() {
return kWin7ButtonBoundsPositionOffset;
}
+int GetDefaultButtonHeight() {
+ if (GetVersion() >= base::win::VERSION_WIN10)
+ return kWin10ButtonHeight;
+ if (GetVersion() >= base::win::VERSION_WIN8)
+ return kWin8ButtonHeight;
+ return kWin7ButtonHeight;
+}
+
} // namespace
// static
@@ -43,6 +57,9 @@ int MinimizeButtonMetrics::last_cached_minimize_button_x_delta_ = 0;
// static
int MinimizeButtonMetrics::button_bounds_position_offset_ = kInvalidOffset;
+// static
+int MinimizeButtonMetrics::caption_button_height_ = kInvalidHeight;
+
MinimizeButtonMetrics::MinimizeButtonMetrics()
: hwnd_(nullptr),
cached_minimize_button_x_delta_(last_cached_minimize_button_x_delta_),
@@ -123,7 +140,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
@@ -189,3 +206,29 @@ int MinimizeButtonMetrics::GetAndCacheMinimizeButtonOffsetX() const {
last_cached_minimize_button_x_delta_ = cached_minimize_button_x_delta_;
return minimize_button_offset;
}
+
+int MinimizeButtonMetrics::GetCaptionButtonHeight() const {
+ // It's hard to get the height of the caption buttons exactly right for all
+ // resolutions/DPI settings. http://crbug.com/668278 tracks pixel-precise
+ // positioning for this. (According to robliao@ and bsep@ the solution is
+ // probably GetSystemMetricsForDpi.) GetSystemMetrics provides a good
+ // approximation - it seems to be no more than 1px off in practice.
Peter Kasting 2017/04/26 01:04:23 This comment confuses me a bit because it's not cl
emx 2017/04/26 14:19:26 OK, Mihai and I looked into this together and I've
+
+ // Note that the following methods do not return the results the caller
+ // expects with DPI scaling settings other than 100%:
+ // DwmGetWindowAttribute(hwnd_, DWMWA_CAPTION_BUTTON_BOUNDS, ...)
+ // SendMessage(hwnd_, WM_GETTITLEBARINFOEX, ...)
+ // display::win::ScreenWin::GetSystemMetricsInDIP(SM_CYSIZE)
+ // these all return (height * scale factor) e.g. 56 at 200%
Peter Kasting 2017/04/26 01:04:23 This doesn't seem right, reading the code. GetSys
emx 2017/04/26 14:19:26 Yes, you're right, I got GetSystemMetricsForHwnd a
+ // display::win::ScreenWin::GetSystemMetricsForHwnd(hwnd_, SM_CYSIZE)
+ // returns (height / by primary monitor scale factor) e.g. 22 for 125%
+
+ if (caption_button_height_ == kInvalidHeight) {
+ int button_height_from_sysmetrics = GetSystemMetrics(SM_CYSIZE);
+ if (button_height_from_sysmetrics == 0)
+ return GetDefaultButtonHeight();
+ caption_button_height_ = button_height_from_sysmetrics;
+ }
+
+ return caption_button_height_;
+}
« no previous file with comments | « chrome/browser/ui/views/frame/minimize_button_metrics_win.h ('k') | chrome/browser/ui/views/frame/native_browser_frame.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698