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/i18n/rtl.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/win/windows_version.h" | 9 #include "base/win/windows_version.h" |
10 #include "dwmapi.h" | 10 #include "dwmapi.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
47 MinimizeButtonMetrics::MinimizeButtonMetrics() | 47 MinimizeButtonMetrics::MinimizeButtonMetrics() |
48 : hwnd_(nullptr), | 48 : hwnd_(nullptr), |
49 cached_minimize_button_x_delta_(last_cached_minimize_button_x_delta_), | 49 cached_minimize_button_x_delta_(last_cached_minimize_button_x_delta_), |
50 was_activated_(false) { | 50 was_activated_(false) { |
51 } | 51 } |
52 | 52 |
53 MinimizeButtonMetrics::~MinimizeButtonMetrics() { | 53 MinimizeButtonMetrics::~MinimizeButtonMetrics() { |
54 } | 54 } |
55 | 55 |
56 // static | 56 // static |
57 int MinimizeButtonMetrics::GetCaptionButtonWidthInDIPs() { | |
58 return GetCaptionButtonDimensionInDIPs(SM_CXSIZE, SM_CXSIZEFRAME); | |
Peter Kasting
2017/05/11 01:03:43
It somewhat surprises me that the width would need
emx
2017/05/11 12:56:11
Me too! In fact, I've measured it carefully again
| |
59 } | |
60 | |
61 // static | |
57 int MinimizeButtonMetrics::GetCaptionButtonHeightInDIPs() { | 62 int MinimizeButtonMetrics::GetCaptionButtonHeightInDIPs() { |
63 return GetCaptionButtonDimensionInDIPs(SM_CYSIZE, SM_CYSIZEFRAME); | |
64 } | |
65 | |
66 // static | |
67 int MinimizeButtonMetrics::GetCaptionButtonDimensionInDIPs(int caption_metric, | |
68 int frame_metric) { | |
58 // At DPI scaling settings other than 100% the result won't be exactly right. | 69 // 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] | 70 // TODO: return a more accurate approximation [http://crbug.com/716365] |
60 | 71 |
61 // SM_CYSIZE returns the caption button height, but to get the full height | 72 // SM_CXSIZE/SM_CYSIZE return the caption button width/height, but to get the |
62 // from the top of the window we add SM_CYSIZEFRAME. | 73 // full width from the side/height from the top of the window we add |
63 const int caption_height = GetSystemMetrics(SM_CYSIZE); | 74 // SM_CXSIZEFRAME/SM_CYSIZEFRAME. |
64 const int frame_thickness = GetSystemMetrics(SM_CYSIZEFRAME); | 75 const int caption_dimension = GetSystemMetrics(caption_metric); |
76 const int frame_thickness = GetSystemMetrics(frame_metric); | |
65 | 77 |
66 // The result of GetSystemMetrics depends on the scale factor of the primary | 78 // 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 | 79 // display. Divide the sum by that to convert to DIPs. (Converting the two |
68 // and SM_CYSIZEFRAME to DIPs individually adds a bigger rounding error.) | 80 // metrics to DIPs individually adds a bigger rounding error.) |
69 float primary_device_scale_factor = | 81 float primary_device_scale_factor = |
70 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor(); | 82 display::Screen::GetScreen()->GetPrimaryDisplay().device_scale_factor(); |
71 float height_dips = | 83 float dimension_dips = |
72 (caption_height + frame_thickness) / primary_device_scale_factor; | 84 (caption_dimension + frame_thickness) / primary_device_scale_factor; |
73 | 85 |
74 // Testing shows that floor() gives a more accurate approximation than | 86 // Testing shows that floor() gives a more accurate approximation than |
75 // round() here. | 87 // round() here. |
76 return std::floor(height_dips); | 88 return std::floor(dimension_dips); |
77 } | 89 } |
78 | 90 |
79 void MinimizeButtonMetrics::Init(HWND hwnd) { | 91 void MinimizeButtonMetrics::Init(HWND hwnd) { |
80 DCHECK(!hwnd_); | 92 DCHECK(!hwnd_); |
81 hwnd_ = hwnd; | 93 hwnd_ = hwnd; |
82 } | 94 } |
83 | 95 |
84 void MinimizeButtonMetrics::OnHWNDActivated() { | 96 void MinimizeButtonMetrics::OnHWNDActivated() { |
85 was_activated_ = true; | 97 was_activated_ = true; |
86 // NOTE: we don't cache here as it seems only after the activate is the value | 98 // NOTE: we don't cache here as it seems only after the activate is the value |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
206 cached_minimize_button_x_delta_ = minimize_button_offset; | 218 cached_minimize_button_x_delta_ = minimize_button_offset; |
207 } else { | 219 } else { |
208 RECT client_rect = {0}; | 220 RECT client_rect = {0}; |
209 GetClientRect(hwnd_, &client_rect); | 221 GetClientRect(hwnd_, &client_rect); |
210 cached_minimize_button_x_delta_ = | 222 cached_minimize_button_x_delta_ = |
211 client_rect.right - minimize_button_offset; | 223 client_rect.right - minimize_button_offset; |
212 } | 224 } |
213 last_cached_minimize_button_x_delta_ = cached_minimize_button_x_delta_; | 225 last_cached_minimize_button_x_delta_ = cached_minimize_button_x_delta_; |
214 return minimize_button_offset; | 226 return minimize_button_offset; |
215 } | 227 } |
OLD | NEW |