OLD | NEW |
---|---|
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" |
11 #include "ui/base/win/shell.h" | 11 #include "ui/base/win/shell.h" |
12 #include "ui/display/win/dpi.h" | 12 #include "ui/display/win/dpi.h" |
13 #include "ui/display/win/screen_win.h" | 13 #include "ui/display/win/screen_win.h" |
14 #include "ui/gfx/geometry/point.h" | 14 #include "ui/gfx/geometry/point.h" |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 // These constants were determined by manually adding various offsets | 18 // These constants were determined by manually adding various offsets |
19 // until the identity switcher was placed at the same location as before. | 19 // until the identity switcher was placed at the same location as before. |
20 // When a new or updated OS version is released, a new constant may need | 20 // When a new or updated OS version is released, a new constant may need |
21 // to be added to this list and GetDefaultButtonBoundsOffset() is updated. | 21 // to be added to this list and GetDefaultButtonBoundsOffset() is updated. |
22 const int kWin7ButtonBoundsPositionOffset = 1; | 22 const int kWin7ButtonBoundsPositionOffset = 1; |
23 const int kWin8ButtonBoundsPositionOffset = 10; | 23 const int kWin8ButtonBoundsPositionOffset = 10; |
24 const int kWin10ButtonBoundsPositionOffset = 6; | 24 const int kWin10ButtonBoundsPositionOffset = 6; |
25 const int kInvalidOffset = static_cast<int>(0x80000000); | 25 const int kInvalidOffset = static_cast<int>(0x80000000); |
26 | 26 |
27 // This constant was determined manually by testing on windows 10. | |
28 const int kWin10ButtonHeight = 30; | |
29 const int kInvalidHeight = static_cast<int>(0x80000000); | |
30 | |
27 using base::win::GetVersion; | 31 using base::win::GetVersion; |
28 using display::win::ScreenWin; | 32 using display::win::ScreenWin; |
29 | 33 |
30 int GetDefaultButtonBoundsOffset() { | 34 int GetDefaultButtonBoundsOffset() { |
31 if (GetVersion() >= base::win::VERSION_WIN10) | 35 if (GetVersion() >= base::win::VERSION_WIN10) |
32 return kWin10ButtonBoundsPositionOffset; | 36 return kWin10ButtonBoundsPositionOffset; |
33 if (GetVersion() >= base::win::VERSION_WIN8) | 37 if (GetVersion() >= base::win::VERSION_WIN8) |
34 return kWin8ButtonBoundsPositionOffset; | 38 return kWin8ButtonBoundsPositionOffset; |
35 return kWin7ButtonBoundsPositionOffset; | 39 return kWin7ButtonBoundsPositionOffset; |
36 } | 40 } |
37 | 41 |
42 int GetDefaultButtonHeight() { | |
43 return kWin10ButtonHeight; | |
44 } | |
45 | |
38 } // namespace | 46 } // namespace |
39 | 47 |
40 // static | 48 // static |
41 int MinimizeButtonMetrics::last_cached_minimize_button_x_delta_ = 0; | 49 int MinimizeButtonMetrics::last_cached_minimize_button_x_delta_ = 0; |
42 | 50 |
43 // static | 51 // static |
44 int MinimizeButtonMetrics::button_bounds_position_offset_ = kInvalidOffset; | 52 int MinimizeButtonMetrics::button_bounds_position_offset_ = kInvalidOffset; |
45 | 53 |
54 // static | |
55 int MinimizeButtonMetrics::button_bounds_height_ = kInvalidHeight; | |
56 | |
46 MinimizeButtonMetrics::MinimizeButtonMetrics() | 57 MinimizeButtonMetrics::MinimizeButtonMetrics() |
47 : hwnd_(nullptr), | 58 : hwnd_(nullptr), |
48 cached_minimize_button_x_delta_(last_cached_minimize_button_x_delta_), | 59 cached_minimize_button_x_delta_(last_cached_minimize_button_x_delta_), |
49 was_activated_(false) { | 60 was_activated_(false) { |
50 } | 61 } |
51 | 62 |
52 MinimizeButtonMetrics::~MinimizeButtonMetrics() { | 63 MinimizeButtonMetrics::~MinimizeButtonMetrics() { |
53 } | 64 } |
54 | 65 |
55 void MinimizeButtonMetrics::Init(HWND hwnd) { | 66 void MinimizeButtonMetrics::Init(HWND hwnd) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
116 if (!dwm_button_pos) { | 127 if (!dwm_button_pos) { |
117 // Fallback to using the message for the titlebar info only if the above | 128 // 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 | 129 // 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 | 130 // 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 | 131 // 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 | 132 // code is always the same and similarly the state never seems to change |
122 // (titlebar_info.rgstate). | 133 // (titlebar_info.rgstate). |
123 TITLEBARINFOEX titlebar_info = {0}; | 134 TITLEBARINFOEX titlebar_info = {0}; |
124 titlebar_info.cbSize = sizeof(TITLEBARINFOEX); | 135 titlebar_info.cbSize = sizeof(TITLEBARINFOEX); |
125 SendMessage(hwnd_, WM_GETTITLEBARINFOEX, 0, | 136 SendMessage(hwnd_, WM_GETTITLEBARINFOEX, 0, |
126 reinterpret_cast<WPARAM>(&titlebar_info)); | 137 reinterpret_cast<LPARAM>(&titlebar_info)); |
127 | 138 |
128 // Under DWM WM_GETTITLEBARINFOEX won't return the right thing until after | 139 // Under DWM WM_GETTITLEBARINFOEX won't return the right thing until after |
129 // WM_NCACTIVATE (maybe it returns classic values?). In an attempt to | 140 // WM_NCACTIVATE (maybe it returns classic values?). In an attempt to |
130 // return a consistant value we cache the last value across instances and | 141 // return a consistant value we cache the last value across instances and |
131 // use it until we get the activate. | 142 // use it until we get the activate. |
132 if (titlebar_info.rgrect[2].left == titlebar_info.rgrect[2].right || | 143 if (titlebar_info.rgrect[2].left == titlebar_info.rgrect[2].right || |
133 (titlebar_info.rgstate[2] & | 144 (titlebar_info.rgstate[2] & |
134 (STATE_SYSTEM_INVISIBLE | STATE_SYSTEM_OFFSCREEN | | 145 (STATE_SYSTEM_INVISIBLE | STATE_SYSTEM_OFFSCREEN | |
135 STATE_SYSTEM_UNAVAILABLE))) | 146 STATE_SYSTEM_UNAVAILABLE))) |
136 return 0; | 147 return 0; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 cached_minimize_button_x_delta_ = minimize_button_offset; | 193 cached_minimize_button_x_delta_ = minimize_button_offset; |
183 } else { | 194 } else { |
184 RECT client_rect = {0}; | 195 RECT client_rect = {0}; |
185 GetClientRect(hwnd_, &client_rect); | 196 GetClientRect(hwnd_, &client_rect); |
186 cached_minimize_button_x_delta_ = | 197 cached_minimize_button_x_delta_ = |
187 client_rect.right - minimize_button_offset; | 198 client_rect.right - minimize_button_offset; |
188 } | 199 } |
189 last_cached_minimize_button_x_delta_ = cached_minimize_button_x_delta_; | 200 last_cached_minimize_button_x_delta_ = cached_minimize_button_x_delta_; |
190 return minimize_button_offset; | 201 return minimize_button_offset; |
191 } | 202 } |
203 | |
204 int MinimizeButtonMetrics::GetMinimizeButtonHeight() const { | |
205 // We want the "tall" avatar button to be the same height as the caption | |
msarda
2017/04/21 09:43:28
Who is "we"?
Also, it is not clear why the commen
emx
2017/04/24 16:23:10
Done.
| |
206 // buttons [http://crbug.com/635699] but it's very hard to get this right for | |
207 // all resolutions/DPI settings. GetSystemMetricsForDpi is probaly the real | |
208 // solution [http://crbug.com/668278]. GetSystemMetrics provides a good | |
209 // approximation for now. | |
210 | |
211 // Note that the following methods do not return the correct result with DPI | |
212 // scaling settings other than 100%: | |
213 // DwmGetWindowAttribute(hwnd_, DWMWA_CAPTION_BUTTON_BOUNDS, ...) | |
214 // SendMessage(hwnd_, WM_GETTITLEBARINFOEX, ...) | |
215 // display::win::ScreenWin::GetSystemMetricsInDIP(SM_CYSIZE) | |
216 // display::win::ScreenWin::GetSystemMetricsForHwnd(hwnd_, SM_CYSIZE) | |
217 | |
218 if (button_bounds_height_ == kInvalidHeight) { | |
219 int button_height_from_sysmetrics = GetSystemMetrics(SM_CYSIZE); | |
220 if (button_height_from_sysmetrics == 0) { | |
221 LOG(ERROR) << "GetSystemMetrics(SM_CYSIZE) error " << ::GetLastError(); | |
msarda
2017/04/21 09:43:28
If the user is in this case, then I think this lin
emx
2017/04/24 16:23:10
Done.
| |
222 return GetDefaultButtonHeight(); | |
msarda
2017/04/21 09:43:28
From the name of the method, it looks like this fu
emx
2017/04/24 16:23:10
Done.
| |
223 } | |
224 button_bounds_height_ = button_height_from_sysmetrics; | |
225 } | |
226 | |
227 return button_bounds_height_; | |
228 } | |
OLD | NEW |