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/i18n/rtl.h" |
7 #include "base/logging.h" | 8 #include "base/logging.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/display.h" |
12 #include "ui/display/win/dpi.h" | 13 #include "ui/display/win/dpi.h" |
13 #include "ui/display/win/screen_win.h" | 14 #include "ui/display/win/screen_win.h" |
14 #include "ui/gfx/geometry/point.h" | 15 #include "ui/gfx/geometry/point.h" |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // These constants were determined by manually adding various offsets | 19 // These constants were determined by manually adding various offsets |
19 // until the identity switcher was placed at the same location as before. | 20 // 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 | 21 // 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. | 22 // to be added to this list and GetDefaultButtonBoundsOffset() is updated. |
(...skipping 23 matching lines...) Expand all Loading... |
45 | 46 |
46 MinimizeButtonMetrics::MinimizeButtonMetrics() | 47 MinimizeButtonMetrics::MinimizeButtonMetrics() |
47 : hwnd_(nullptr), | 48 : hwnd_(nullptr), |
48 cached_minimize_button_x_delta_(last_cached_minimize_button_x_delta_), | 49 cached_minimize_button_x_delta_(last_cached_minimize_button_x_delta_), |
49 was_activated_(false) { | 50 was_activated_(false) { |
50 } | 51 } |
51 | 52 |
52 MinimizeButtonMetrics::~MinimizeButtonMetrics() { | 53 MinimizeButtonMetrics::~MinimizeButtonMetrics() { |
53 } | 54 } |
54 | 55 |
| 56 // static |
| 57 int MinimizeButtonMetrics::GetCaptionButtonHeightInDIPs() { |
| 58 // At DPI scaling settings other than 100% the result won't be exactly right. |
| 59 // TODO: return a more accurate approximation [http://crbug.com/716365] |
| 60 |
| 61 // SM_CYSIZE returns the caption button height, but to get the full height |
| 62 // from the top of the window we add SM_CYSIZEFRAME. |
| 63 const int caption_height = GetSystemMetrics(SM_CYSIZE); |
| 64 const int frame_thickness = GetSystemMetrics(SM_CYSIZEFRAME); |
| 65 |
| 66 // The result of GetSystemMetrics depends on the scale factor of the primary |
| 67 // display. Divide the sum by that to convert to DIPs. (Converting SM_CYSIZE |
| 68 // and SM_CYSIZEFRAME to DIPs individually adds a bigger rounding error.) |
| 69 float primary_device_scale_factor = |
| 70 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor(); |
| 71 float height_dips = |
| 72 (caption_height + frame_thickness) / primary_device_scale_factor; |
| 73 |
| 74 // Testing shows that floor() gives a more accurate approximation than |
| 75 // round() here. |
| 76 return std::floor(height_dips); |
| 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 Loading... |
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 Loading... |
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 } |
OLD | NEW |