| 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..e2b91a44936b9959cf7ce7cf8d2d873abbe093e1 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,10 @@ const int kWin8ButtonBoundsPositionOffset = 10;
|
| const int kWin10ButtonBoundsPositionOffset = 6;
|
| const int kInvalidOffset = static_cast<int>(0x80000000);
|
|
|
| +// This constant was determined manually by testing on windows 10.
|
| +const int kWin10ButtonHeight = 30;
|
| +const int kInvalidHeight = static_cast<int>(0x80000000);
|
| +
|
| using base::win::GetVersion;
|
| using display::win::ScreenWin;
|
|
|
| @@ -35,6 +39,10 @@ int GetDefaultButtonBoundsOffset() {
|
| return kWin7ButtonBoundsPositionOffset;
|
| }
|
|
|
| +int GetDefaultButtonHeight() {
|
| + return kWin10ButtonHeight;
|
| +}
|
| +
|
| } // namespace
|
|
|
| // static
|
| @@ -43,6 +51,9 @@ int MinimizeButtonMetrics::last_cached_minimize_button_x_delta_ = 0;
|
| // static
|
| int MinimizeButtonMetrics::button_bounds_position_offset_ = kInvalidOffset;
|
|
|
| +// statis
|
| +int MinimizeButtonMetrics::button_bounds_height_ = kInvalidHeight;
|
| +
|
| MinimizeButtonMetrics::MinimizeButtonMetrics()
|
| : hwnd_(nullptr),
|
| cached_minimize_button_x_delta_(last_cached_minimize_button_x_delta_),
|
| @@ -63,6 +74,36 @@ void MinimizeButtonMetrics::OnHWNDActivated() {
|
| // correct.
|
| }
|
|
|
| +void MinimizeButtonMetrics::UpdateButtonBoundsSizes(const RECT& button_bounds,
|
| + const RECT& window_bounds) const {
|
| +// LOG(ERROR) << "X BUTTON BOUNDS " << button_bounds.left << ", " << button_bounds.top << " - " << button_bounds.right - button_bounds.left << " x " << button_bounds.top - button_bounds.bottom;
|
| +
|
| + if (button_bounds_position_offset_ != kInvalidOffset) {
|
| + return;
|
| + }
|
| + DCHECK_EQ(kInvalidHeight, button_bounds_height_);
|
| +
|
| + if (button_bounds.left == button_bounds.right || button_bounds.top == button_bounds.left) {
|
| + return;
|
| + }
|
| + if (!was_activated_ || !IsWindowVisible(hwnd_)) {
|
| + return;
|
| + }
|
| +
|
| + TITLEBARINFOEX info = { 0 };
|
| + info.cbSize = sizeof(info);
|
| + SendMessage(hwnd_, WM_GETTITLEBARINFOEX, 0,
|
| + reinterpret_cast<LPARAM>(&info));
|
| + if (info.rgrect[2].right == info.rgrect[2].left ||
|
| + (info.rgstate[2] & (STATE_SYSTEM_INVISIBLE | STATE_SYSTEM_OFFSCREEN |
|
| + STATE_SYSTEM_UNAVAILABLE))) {
|
| + return;
|
| + }
|
| + button_bounds_position_offset_ =
|
| + info.rgrect[2].left - (button_bounds.left + window_bounds.left);
|
| + button_bounds_height_ = button_bounds.bottom - button_bounds.top;
|
| +}
|
| +
|
| // This function attempts to calculate the odd and varying difference
|
| // between the results of DwmGetWindowAttribute with the
|
| // DWMWA_CAPTION_BUTTON_BOUNDS flag and the information from the
|
| @@ -72,20 +113,9 @@ void MinimizeButtonMetrics::OnHWNDActivated() {
|
| int MinimizeButtonMetrics::GetButtonBoundsPositionOffset(
|
| const RECT& button_bounds,
|
| const RECT& window_bounds) const {
|
| - if (button_bounds_position_offset_ == kInvalidOffset) {
|
| - if (!was_activated_ || !IsWindowVisible(hwnd_))
|
| - return GetDefaultButtonBoundsOffset();
|
| - TITLEBARINFOEX info = {0};
|
| - info.cbSize = sizeof(info);
|
| - SendMessage(hwnd_, WM_GETTITLEBARINFOEX, 0,
|
| - reinterpret_cast<LPARAM>(&info));
|
| - if (info.rgrect[2].right == info.rgrect[2].left ||
|
| - (info.rgstate[2] & (STATE_SYSTEM_INVISIBLE | STATE_SYSTEM_OFFSCREEN |
|
| - STATE_SYSTEM_UNAVAILABLE)))
|
| - return GetDefaultButtonBoundsOffset();
|
| - button_bounds_position_offset_ =
|
| - info.rgrect[2].left - (button_bounds.left + window_bounds.left);
|
| - }
|
| + UpdateButtonBoundsSizes(button_bounds, window_bounds);
|
| + if (button_bounds_position_offset_ == kInvalidOffset)
|
| + return GetDefaultButtonBoundsOffset();
|
| return button_bounds_position_offset_;
|
| }
|
|
|
| @@ -189,3 +219,27 @@ int MinimizeButtonMetrics::GetAndCacheMinimizeButtonOffsetX() const {
|
| last_cached_minimize_button_x_delta_ = cached_minimize_button_x_delta_;
|
| return minimize_button_offset;
|
| }
|
| +
|
| +int MinimizeButtonMetrics::GetMinimizeButtonHeight() const {
|
| + if (button_bounds_height_ == kInvalidHeight) {
|
| + RECT button_bounds = { 0 };
|
| + if (SUCCEEDED(DwmGetWindowAttribute(hwnd_, DWMWA_CAPTION_BUTTON_BOUNDS,
|
| + &button_bounds, sizeof(button_bounds)))) {
|
| + // This converts the button coordinate into screen coordinates
|
| + // thus, ensuring that the identity switcher is placed in the
|
| + // same location as before. An additional constant is added because
|
| + // there is a difference between the caption button bounds and
|
| + // the values obtained through WM_GETTITLEBARINFOEX. This difference
|
| + // varies between OS versions, and no metric describing this difference
|
| + // has been located.
|
| + RECT window_bounds = { 0 };
|
| + if (GetWindowRect(hwnd_, &window_bounds)) {
|
| + UpdateButtonBoundsSizes(button_bounds, window_bounds);
|
| + }
|
| + }
|
| + }
|
| +
|
| + if (button_bounds_height_ == kInvalidHeight)
|
| + return GetDefaultButtonHeight();
|
| + return button_bounds_height_;
|
| +}
|
|
|