diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-20 20:42:03 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-08-20 20:42:03 +0000 |
commit | 27077a2972931a32a10abf2bfd0acbbe75eccaa2 (patch) | |
tree | 70b4884177b5dacba85530466130a8a743f6e964 /ui | |
parent | bd4bd0f2dce566d057f2c660006727a2b3e6205a (diff) | |
download | chromium_src-27077a2972931a32a10abf2bfd0acbbe75eccaa2.zip chromium_src-27077a2972931a32a10abf2bfd0acbbe75eccaa2.tar.gz chromium_src-27077a2972931a32a10abf2bfd0acbbe75eccaa2.tar.bz2 |
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
Diffstat (limited to 'ui')
-rw-r--r-- | ui/views/widget/hwnd_message_handler.cc | 49 | ||||
-rw-r--r-- | ui/views/widget/hwnd_message_handler.h | 6 | ||||
-rw-r--r-- | ui/views/widget/native_widget_win.cc | 50 | ||||
-rw-r--r-- | ui/views/widget/native_widget_win.h | 5 |
4 files changed, 57 insertions, 53 deletions
diff --git a/ui/views/widget/hwnd_message_handler.cc b/ui/views/widget/hwnd_message_handler.cc index 42f46b4..34e4aa5 100644 --- a/ui/views/widget/hwnd_message_handler.cc +++ b/ui/views/widget/hwnd_message_handler.cc @@ -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: diff --git a/ui/views/widget/hwnd_message_handler.h b/ui/views/widget/hwnd_message_handler.h index 61ee4c4..5df42b2 100644 --- a/ui/views/widget/hwnd_message_handler.h +++ b/ui/views/widget/hwnd_message_handler.h @@ -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. diff --git a/ui/views/widget/native_widget_win.cc b/ui/views/widget/native_widget_win.cc index 66da7fe..957b35e 100644 --- a/ui/views/widget/native_widget_win.cc +++ b/ui/views/widget/native_widget_win.cc @@ -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) { diff --git a/ui/views/widget/native_widget_win.h b/ui/views/widget/native_widget_win.h index 23ba9d4..0132859 100644 --- a/ui/views/widget/native_widget_win.h +++ b/ui/views/widget/native_widget_win.h @@ -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(); |