Chromium Code Reviews| 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 int cysize = GetSystemMetrics(SM_CYSIZE); | |
| 64 int cysizeframe = GetSystemMetrics(SM_CYSIZEFRAME); | |
|
Peter Kasting
2017/05/05 22:41:01
Nit: Dunno if this would be clearer if these were
emx
2017/05/09 09:37:58
Done.
| |
| 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 = (cysize + cysizeframe) / primary_device_scale_factor; | |
| 72 | |
| 73 // Testing shows that floor() gives a more accurate approximation than | |
| 74 // round() here. | |
| 75 return std::floor(height_dips); | |
| 76 } | |
| 77 | |
| 55 void MinimizeButtonMetrics::Init(HWND hwnd) { | 78 void MinimizeButtonMetrics::Init(HWND hwnd) { |
| 56 DCHECK(!hwnd_); | 79 DCHECK(!hwnd_); |
| 57 hwnd_ = hwnd; | 80 hwnd_ = hwnd; |
| 58 } | 81 } |
| 59 | 82 |
| 60 void MinimizeButtonMetrics::OnHWNDActivated() { | 83 void MinimizeButtonMetrics::OnHWNDActivated() { |
| 61 was_activated_ = true; | 84 was_activated_ = true; |
| 62 // NOTE: we don't cache here as it seems only after the activate is the value | 85 // NOTE: we don't cache here as it seems only after the activate is the value |
| 63 // correct. | 86 // correct. |
| 64 } | 87 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 if (!dwm_button_pos) { | 139 if (!dwm_button_pos) { |
| 117 // Fallback to using the message for the titlebar info only if the above | 140 // 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 | 141 // 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 | 142 // 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 | 143 // 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 | 144 // code is always the same and similarly the state never seems to change |
| 122 // (titlebar_info.rgstate). | 145 // (titlebar_info.rgstate). |
| 123 TITLEBARINFOEX titlebar_info = {0}; | 146 TITLEBARINFOEX titlebar_info = {0}; |
| 124 titlebar_info.cbSize = sizeof(TITLEBARINFOEX); | 147 titlebar_info.cbSize = sizeof(TITLEBARINFOEX); |
| 125 SendMessage(hwnd_, WM_GETTITLEBARINFOEX, 0, | 148 SendMessage(hwnd_, WM_GETTITLEBARINFOEX, 0, |
| 126 reinterpret_cast<WPARAM>(&titlebar_info)); | 149 reinterpret_cast<LPARAM>(&titlebar_info)); |
| 127 | 150 |
| 128 // Under DWM WM_GETTITLEBARINFOEX won't return the right thing until after | 151 // Under DWM WM_GETTITLEBARINFOEX won't return the right thing until after |
| 129 // WM_NCACTIVATE (maybe it returns classic values?). In an attempt to | 152 // WM_NCACTIVATE (maybe it returns classic values?). In an attempt to |
| 130 // return a consistant value we cache the last value across instances and | 153 // return a consistant value we cache the last value across instances and |
| 131 // use it until we get the activate. | 154 // use it until we get the activate. |
| 132 if (titlebar_info.rgrect[2].left == titlebar_info.rgrect[2].right || | 155 if (titlebar_info.rgrect[2].left == titlebar_info.rgrect[2].right || |
| 133 (titlebar_info.rgstate[2] & | 156 (titlebar_info.rgstate[2] & |
| 134 (STATE_SYSTEM_INVISIBLE | STATE_SYSTEM_OFFSCREEN | | 157 (STATE_SYSTEM_INVISIBLE | STATE_SYSTEM_OFFSCREEN | |
| 135 STATE_SYSTEM_UNAVAILABLE))) | 158 STATE_SYSTEM_UNAVAILABLE))) |
| 136 return 0; | 159 return 0; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 182 cached_minimize_button_x_delta_ = minimize_button_offset; | 205 cached_minimize_button_x_delta_ = minimize_button_offset; |
| 183 } else { | 206 } else { |
| 184 RECT client_rect = {0}; | 207 RECT client_rect = {0}; |
| 185 GetClientRect(hwnd_, &client_rect); | 208 GetClientRect(hwnd_, &client_rect); |
| 186 cached_minimize_button_x_delta_ = | 209 cached_minimize_button_x_delta_ = |
| 187 client_rect.right - minimize_button_offset; | 210 client_rect.right - minimize_button_offset; |
| 188 } | 211 } |
| 189 last_cached_minimize_button_x_delta_ = cached_minimize_button_x_delta_; | 212 last_cached_minimize_button_x_delta_ = cached_minimize_button_x_delta_; |
| 190 return minimize_button_offset; | 213 return minimize_button_offset; |
| 191 } | 214 } |
| OLD | NEW |