Commit 27077a29 authored by ben@chromium.org's avatar ben@chromium.org

Move more message handlers from NativeWidgetWin to HWNDMessageHandler.

Buildbots (not trybots) were giving grief on past iteration of this CL:
http://codereview.chromium.org/10832345/
... so I am splitting it into smaller pieces to help identify what piece was the cause.

http://crbug.com/142962
TBR=sky@chromium.org
Review URL: https://chromiumcodereview.appspot.com/10828395

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@152384 0039d316-1c4b-4281-b951-d872f2087c98
parent bd4bd0f2
......@@ -280,6 +280,13 @@ LRESULT HWNDMessageHandler::OnSetText(const wchar_t* text) {
reinterpret_cast<LPARAM>(text));
}
void HWNDMessageHandler::OnSize(UINT param, const CSize& size) {
RedrawWindow(hwnd(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN);
// ResetWindowRegion is going to trigger WM_NCPAINT. By doing it after we've
// invoked OnSize we ensure the RootView has been laid out.
ResetWindowRegion(false);
}
void HWNDMessageHandler::OnThemeChanged() {
ui::NativeThemeWin::instance()->CloseHandles();
}
......@@ -290,6 +297,48 @@ void HWNDMessageHandler::OnVScroll(int scroll_type,
SetMsgHandled(FALSE);
}
void HWNDMessageHandler::ResetWindowRegion(bool force) {
// A native frame uses the native window region, and we don't want to mess
// with it.
if (!delegate_->IsUsingCustomFrame() || !delegate_->IsWidgetWindow()) {
if (force)
SetWindowRgn(hwnd(), NULL, TRUE);
return;
}
// Changing the window region is going to force a paint. Only change the
// window region if the region really differs.
HRGN current_rgn = CreateRectRgn(0, 0, 0, 0);
int current_rgn_result = GetWindowRgn(hwnd(), current_rgn);
CRect window_rect;
GetWindowRect(hwnd(), &window_rect);
HRGN new_region;
if (delegate_->AsNativeWidgetWin()->IsMaximized()) {
HMONITOR monitor = MonitorFromWindow(hwnd(), MONITOR_DEFAULTTONEAREST);
MONITORINFO mi;
mi.cbSize = sizeof mi;
GetMonitorInfo(monitor, &mi);
CRect work_rect = mi.rcWork;
work_rect.OffsetRect(-window_rect.left, -window_rect.top);
new_region = CreateRectRgnIndirect(&work_rect);
} else {
gfx::Path window_mask;
delegate_->GetWindowMask(
gfx::Size(window_rect.Width(), window_rect.Height()), &window_mask);
new_region = window_mask.CreateNativeRegion();
}
if (current_rgn_result == ERROR || !EqualRgn(current_rgn, new_region)) {
// SetWindowRgn takes ownership of the HRGN created by CreateNativeRegion.
SetWindowRgn(hwnd(), new_region, TRUE);
} else {
DeleteObject(new_region);
}
DeleteObject(current_rgn);
}
////////////////////////////////////////////////////////////////////////////////
// HWNDMessageHandler, private:
......
......@@ -65,6 +65,7 @@ class VIEWS_EXPORT HWNDMessageHandler {
void OnSetFocus(HWND last_focused_window);
LRESULT OnSetIcon(UINT size_type, HICON new_icon);
LRESULT OnSetText(const wchar_t* text);
void OnSize(UINT param, const CSize& size);
void OnThemeChanged();
void OnVScroll(int scroll_type, short position, HWND scrollbar);
......@@ -74,6 +75,11 @@ class VIEWS_EXPORT HWNDMessageHandler {
remove_standard_frame_ = remove_standard_frame;
}
// Resets the window region for the current widget bounds if necessary.
// If |force| is true, the window region is reset to NULL even for native
// frame windows.
void ResetWindowRegion(bool force);
private:
// TODO(beng): This won't be a style violation once this object becomes the
// WindowImpl.
......
......@@ -544,7 +544,7 @@ NonClientFrameView* NativeWidgetWin::CreateNonClientFrameView() {
void NativeWidgetWin::UpdateFrameAfterFrameChange() {
// We've either gained or lost a custom window region, so reset it now.
ResetWindowRegion(true);
message_handler_->ResetWindowRegion(true);
}
bool NativeWidgetWin::ShouldUseNativeFrame() const {
......@@ -1906,10 +1906,7 @@ void NativeWidgetWin::OnSettingChange(UINT flags, const wchar_t* section) {
}
void NativeWidgetWin::OnSize(UINT param, const CSize& size) {
RedrawWindow(GetNativeView(), NULL, NULL, RDW_INVALIDATE | RDW_ALLCHILDREN);
// ResetWindowRegion is going to trigger WM_NCPAINT. By doing it after we've
// invoked OnSize we ensure the RootView has been laid out.
ResetWindowRegion(false);
message_handler_->OnSize(param, size);
}
void NativeWidgetWin::OnSysCommand(UINT notification_code, CPoint click) {
......@@ -2500,49 +2497,6 @@ void NativeWidgetWin::UpdateDWMFrame() {
DwmExtendFrameIntoClientArea(GetNativeView(), &m);
}
void NativeWidgetWin::ResetWindowRegion(bool force) {
// A native frame uses the native window region, and we don't want to mess
// with it.
if (GetWidget()->ShouldUseNativeFrame() || !GetWidget()->non_client_view()) {
if (force)
SetWindowRgn(NULL, TRUE);
return;
}
// Changing the window region is going to force a paint. Only change the
// window region if the region really differs.
HRGN current_rgn = CreateRectRgn(0, 0, 0, 0);
int current_rgn_result = GetWindowRgn(GetNativeView(), current_rgn);
CRect window_rect;
GetWindowRect(&window_rect);
HRGN new_region;
if (IsMaximized()) {
HMONITOR monitor =
MonitorFromWindow(GetNativeView(), MONITOR_DEFAULTTONEAREST);
MONITORINFO mi;
mi.cbSize = sizeof mi;
GetMonitorInfo(monitor, &mi);
CRect work_rect = mi.rcWork;
work_rect.OffsetRect(-window_rect.left, -window_rect.top);
new_region = CreateRectRgnIndirect(&work_rect);
} else {
gfx::Path window_mask;
GetWidget()->non_client_view()->GetWindowMask(
gfx::Size(window_rect.Width(), window_rect.Height()), &window_mask);
new_region = window_mask.CreateNativeRegion();
}
if (current_rgn_result == ERROR || !EqualRgn(current_rgn, new_region)) {
// SetWindowRgn takes ownership of the HRGN created by CreateNativeRegion.
SetWindowRgn(new_region, TRUE);
} else {
DeleteObject(new_region);
}
DeleteObject(current_rgn);
}
LRESULT NativeWidgetWin::DefWindowProcWithRedrawLock(UINT message,
WPARAM w_param,
LPARAM l_param) {
......
......@@ -542,11 +542,6 @@ class VIEWS_EXPORT NativeWidgetWin : public ui::WindowImpl,
// or subsequently.
void ClientAreaSizeChanged();
// Resets the window region for the current widget bounds if necessary.
// If |force| is true, the window region is reset to NULL even for native
// frame windows.
void ResetWindowRegion(bool force);
// When removing the standard frame, tells the DWM how much glass we want on
// the edges. Currently hardcoded to 10px on all sides.
void UpdateDWMFrame();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment