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

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

Issue 2833363002: Add GetCaptionButtonHeightInDIPs() method (Closed)
Patch Set: 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..80fd29d775a6971d3b9f933fe6d51fdafafb2dbd 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);
Peter Kasting 2017/04/24 23:00:17 Nit: This is a bizarre choice. Why not just -1?
emx 2017/04/25 11:57:40 I agree that it's a bizarre choice, but I wanted t
Peter Kasting 2017/04/26 01:04:23 It's theoretically valid, but the only real constr
+
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::button_bounds_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,28 @@ int MinimizeButtonMetrics::GetAndCacheMinimizeButtonOffsetX() const {
last_cached_minimize_button_x_delta_ = cached_minimize_button_x_delta_;
return minimize_button_offset;
}
+
+int MinimizeButtonMetrics::GetMinimizeButtonHeight() const {
+ // It's hard to get the height of the caption buttons exactly right for all
+ // resolutions/DPI settings. GetSystemMetricsForDpi is probaly the real
+ // solution [http://crbug.com/668278], but GetSystemMetrics provides a good
Peter Kasting 2017/04/24 23:00:17 Bug 668278 is a tracking bug, it's not about addin
emx 2017/04/25 11:57:40 robliao@ and bsep@ told me that GetSystemMetricsFo
+ // approximation for now.
+
+ // Note that the following methods do not return the correct result with DPI
+ // scaling settings other than 100%:
Peter Kasting 2017/04/24 23:00:17 In what way are they incorrect?
emx 2017/04/25 11:57:40 More accurately, they're not what the caller expec
+ // DwmGetWindowAttribute(hwnd_, DWMWA_CAPTION_BUTTON_BOUNDS, ...)
+ // SendMessage(hwnd_, WM_GETTITLEBARINFOEX, ...)
+ // display::win::ScreenWin::GetSystemMetricsInDIP(SM_CYSIZE)
+ // display::win::ScreenWin::GetSystemMetricsForHwnd(hwnd_, SM_CYSIZE)
+
+ if (button_bounds_height_ == kInvalidHeight) {
+ int button_height_from_sysmetrics = GetSystemMetrics(SM_CYSIZE);
+ if (button_height_from_sysmetrics == 0) {
Peter Kasting 2017/04/24 23:00:17 When can this happen? This needs to be explained.
emx 2017/04/25 11:57:40 I don't know when it can happen. MSDN does not exp
Peter Kasting 2017/04/26 01:04:23 Most other places in code that we call GetSystemMe
+ DLOG(ERROR) << "GetSystemMetrics(SM_CYSIZE) error " << ::GetLastError();
Peter Kasting 2017/04/24 23:00:17 Avoid logging.
emx 2017/04/25 11:57:40 Logging removed.
+ return GetDefaultButtonHeight();
+ }
+ button_bounds_height_ = button_height_from_sysmetrics;
+ }
+
+ return button_bounds_height_;
+}

Powered by Google App Engine
This is Rietveld 408576698