This source file includes following definitions.
- GetMinimizeButtonOffsetForWindow
- was_activated_
- Init
- OnHWNDActivated
- GetMinimizeButtonOffsetX
- GetAndCacheMinimizeButtonOffsetX
#include "chrome/browser/ui/views/frame/minimize_button_metrics_win.h"
#include "base/logging.h"
#include "base/i18n/rtl.h"
#include "ui/base/win/shell.h"
#include "ui/gfx/win/dpi.h"
namespace {
int GetMinimizeButtonOffsetForWindow(HWND hwnd) {
TITLEBARINFOEX titlebar_info = {0};
titlebar_info.cbSize = sizeof(TITLEBARINFOEX);
SendMessage(hwnd, WM_GETTITLEBARINFOEX, 0,
reinterpret_cast<WPARAM>(&titlebar_info));
if (titlebar_info.rgrect[2].left == titlebar_info.rgrect[2].right ||
(titlebar_info.rgstate[2] & (STATE_SYSTEM_INVISIBLE ||
STATE_SYSTEM_OFFSCREEN ||
STATE_SYSTEM_UNAVAILABLE))) {
return 0;
}
RECT window_rect = {0};
GetWindowRect(hwnd, &window_rect);
POINT minimize_button_corner = { titlebar_info.rgrect[2].left, 0 };
if (minimize_button_corner.x > window_rect.right) {
minimize_button_corner.x =
static_cast<int>(minimize_button_corner.x /
gfx::win::GetUndocumentedDPIScale());
}
MapWindowPoints(HWND_DESKTOP, hwnd, &minimize_button_corner, 1);
return minimize_button_corner.x / gfx::win::GetDeviceScaleFactor();
}
}
int MinimizeButtonMetrics::last_cached_minimize_button_x_delta_ = 0;
MinimizeButtonMetrics::MinimizeButtonMetrics()
: hwnd_(NULL),
cached_minimize_button_x_delta_(last_cached_minimize_button_x_delta_),
was_activated_(false) {
}
MinimizeButtonMetrics::~MinimizeButtonMetrics() {
}
void MinimizeButtonMetrics::Init(HWND hwnd) {
DCHECK(!hwnd_);
hwnd_ = hwnd;
}
void MinimizeButtonMetrics::OnHWNDActivated() {
was_activated_ = true;
}
int MinimizeButtonMetrics::GetMinimizeButtonOffsetX() const {
if (was_activated_ || !ui::win::IsAeroGlassEnabled() ||
cached_minimize_button_x_delta_ == 0) {
const int minimize_button_offset = GetAndCacheMinimizeButtonOffsetX();
if (minimize_button_offset > 0)
return minimize_button_offset;
}
DCHECK(cached_minimize_button_x_delta_);
if (base::i18n::IsRTL())
return cached_minimize_button_x_delta_;
RECT client_rect = {0};
GetClientRect(hwnd_, &client_rect);
return client_rect.right - cached_minimize_button_x_delta_;
}
int MinimizeButtonMetrics::GetAndCacheMinimizeButtonOffsetX() const {
const int minimize_button_offset = GetMinimizeButtonOffsetForWindow(hwnd_);
if (minimize_button_offset <= 0)
return 0;
if (base::i18n::IsRTL()) {
cached_minimize_button_x_delta_ = minimize_button_offset;
} else {
RECT client_rect = {0};
GetClientRect(hwnd_, &client_rect);
cached_minimize_button_x_delta_ =
client_rect.right - minimize_button_offset;
}
last_cached_minimize_button_x_delta_ = cached_minimize_button_x_delta_;
return minimize_button_offset;
}