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

Side by Side Diff: chrome/browser/ui/views/frame/minimize_button_metrics_win.cc

Issue 2833363002: Add GetCaptionButtonHeightInDIPs() method (Closed)
Patch Set: Made MinimizeButtonMetrics::GetCaptionButtonHeight() static and reverted the rest of the changes 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/frame/minimize_button_metrics_win.h" 5 #include "chrome/browser/ui/views/frame/minimize_button_metrics_win.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/win/windows_version.h" 9 #include "base/win/windows_version.h"
10 #include "dwmapi.h" 10 #include "dwmapi.h"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 45
46 MinimizeButtonMetrics::MinimizeButtonMetrics() 46 MinimizeButtonMetrics::MinimizeButtonMetrics()
47 : hwnd_(nullptr), 47 : hwnd_(nullptr),
48 cached_minimize_button_x_delta_(last_cached_minimize_button_x_delta_), 48 cached_minimize_button_x_delta_(last_cached_minimize_button_x_delta_),
49 was_activated_(false) { 49 was_activated_(false) {
50 } 50 }
51 51
52 MinimizeButtonMetrics::~MinimizeButtonMetrics() { 52 MinimizeButtonMetrics::~MinimizeButtonMetrics() {
53 } 53 }
54 54
55 // static
56 int MinimizeButtonMetrics::GetCaptionButtonHeight() {
57 // Caption button height is not affected by DPI settings.
Peter Kasting 2017/04/26 17:19:52 robliao says that in his testing, this isn't corre
58 // GetSystemMetrics(SM_CYSIZE) returns the same value regardless of the DPI
59 // settings of any monitor (28 on Windows 10). This is what needs to be
Peter Kasting 2017/04/26 17:19:52 Rob also notes he gets 22 here, not 28. I would j
60 // passed to a View, which then takes care of the scaling.
Peter Kasting 2017/04/26 17:19:52 Nit: No need for the last sentence here
61
62 // A View drawn to this height may look ~1px off at some DPI settings.
Peter Kasting 2017/04/26 17:19:52 I think "~1" is inaccurate here. Assuming the con
63 // http://crbug.com/668278 tracks pixel-precise positioning for this.
64 // (According to robliao@ and bsep@ the solution is probably
65 // GetSystemMetricsForDpi.)
66
67 // Note that the following methods all return scaled values, which is not
68 // what the caller expects:
69 // DwmGetWindowAttribute(hwnd_, DWMWA_CAPTION_BUTTON_BOUNDS, ...)
70 // SendMessage(hwnd_, WM_GETTITLEBARINFOEX, ...)
71 // display::win::ScreenWin::GetSystemMetricsForHwnd(hwnd_, SM_CYSIZE)
72 // these all return (height * scale factor) e.g. 56 at 200%
73 // display::win::ScreenWin::GetSystemMetricsInDIP(SM_CYSIZE)
74 // returns (height / by primary monitor scale factor) e.g. 22 for 125%
Peter Kasting 2017/04/26 17:19:52 I would omit this comment entirely, as your first
75
76 return GetSystemMetrics(SM_CYSIZE);
77 }
78
55 void MinimizeButtonMetrics::Init(HWND hwnd) { 79 void MinimizeButtonMetrics::Init(HWND hwnd) {
56 DCHECK(!hwnd_); 80 DCHECK(!hwnd_);
57 hwnd_ = hwnd; 81 hwnd_ = hwnd;
58 } 82 }
59 83
60 void MinimizeButtonMetrics::OnHWNDActivated() { 84 void MinimizeButtonMetrics::OnHWNDActivated() {
61 was_activated_ = true; 85 was_activated_ = true;
62 // NOTE: we don't cache here as it seems only after the activate is the value 86 // NOTE: we don't cache here as it seems only after the activate is the value
63 // correct. 87 // correct.
64 } 88 }
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 if (!dwm_button_pos) { 140 if (!dwm_button_pos) {
117 // Fallback to using the message for the titlebar info only if the above 141 // Fallback to using the message for the titlebar info only if the above
118 // code fails. It can fail if DWM is disabled globally or only for the 142 // code fails. It can fail if DWM is disabled globally or only for the
119 // given HWND. The WM_GETTITLEBARINFOEX message can fail if we are not 143 // given HWND. The WM_GETTITLEBARINFOEX message can fail if we are not
120 // active/visible. By fail we get a location of 0; the return status 144 // active/visible. By fail we get a location of 0; the return status
121 // code is always the same and similarly the state never seems to change 145 // code is always the same and similarly the state never seems to change
122 // (titlebar_info.rgstate). 146 // (titlebar_info.rgstate).
123 TITLEBARINFOEX titlebar_info = {0}; 147 TITLEBARINFOEX titlebar_info = {0};
124 titlebar_info.cbSize = sizeof(TITLEBARINFOEX); 148 titlebar_info.cbSize = sizeof(TITLEBARINFOEX);
125 SendMessage(hwnd_, WM_GETTITLEBARINFOEX, 0, 149 SendMessage(hwnd_, WM_GETTITLEBARINFOEX, 0,
126 reinterpret_cast<WPARAM>(&titlebar_info)); 150 reinterpret_cast<LPARAM>(&titlebar_info));
127 151
128 // Under DWM WM_GETTITLEBARINFOEX won't return the right thing until after 152 // Under DWM WM_GETTITLEBARINFOEX won't return the right thing until after
129 // WM_NCACTIVATE (maybe it returns classic values?). In an attempt to 153 // WM_NCACTIVATE (maybe it returns classic values?). In an attempt to
130 // return a consistant value we cache the last value across instances and 154 // return a consistant value we cache the last value across instances and
131 // use it until we get the activate. 155 // use it until we get the activate.
132 if (titlebar_info.rgrect[2].left == titlebar_info.rgrect[2].right || 156 if (titlebar_info.rgrect[2].left == titlebar_info.rgrect[2].right ||
133 (titlebar_info.rgstate[2] & 157 (titlebar_info.rgstate[2] &
134 (STATE_SYSTEM_INVISIBLE | STATE_SYSTEM_OFFSCREEN | 158 (STATE_SYSTEM_INVISIBLE | STATE_SYSTEM_OFFSCREEN |
135 STATE_SYSTEM_UNAVAILABLE))) 159 STATE_SYSTEM_UNAVAILABLE)))
136 return 0; 160 return 0;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 cached_minimize_button_x_delta_ = minimize_button_offset; 206 cached_minimize_button_x_delta_ = minimize_button_offset;
183 } else { 207 } else {
184 RECT client_rect = {0}; 208 RECT client_rect = {0};
185 GetClientRect(hwnd_, &client_rect); 209 GetClientRect(hwnd_, &client_rect);
186 cached_minimize_button_x_delta_ = 210 cached_minimize_button_x_delta_ =
187 client_rect.right - minimize_button_offset; 211 client_rect.right - minimize_button_offset;
188 } 212 }
189 last_cached_minimize_button_x_delta_ = cached_minimize_button_x_delta_; 213 last_cached_minimize_button_x_delta_ = cached_minimize_button_x_delta_;
190 return minimize_button_offset; 214 return minimize_button_offset;
191 } 215 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698