diff options
| author | bsep <bsep@chromium.org> | 2016-03-18 11:42:18 -0700 |
|---|---|---|
| committer | Commit bot <commit-bot@chromium.org> | 2016-03-18 18:43:28 +0000 |
| commit | 840fc096207741050490badb7730f5a21b761fc4 (patch) | |
| tree | 066e2f6738025055151d855905d24ac6958035a0 | |
| parent | 2ffbd737186d21af4f6dd613b7241dae24c64f7d (diff) | |
| download | chromium_src-840fc096207741050490badb7730f5a21b761fc4.zip chromium_src-840fc096207741050490badb7730f5a21b761fc4.tar.gz chromium_src-840fc096207741050490badb7730f5a21b761fc4.tar.bz2 | |
Refactored hwnd_message_handler to be more readable. Changed the names of delegate booleans to make more sense. Removed version branches for unsupported versions of Windows.
For reference:
IsWidgetWindow -> HasNonClientView
IsUsingCustomFrame -> GetFrameMode == CustomDraw
!IsUsingCustomFrame -> GetFrameMode == SystemDraw
!remove_standard_frame_ -> HasFrame
!remove_standard_frame_ && !IsUsingCustomFrame -> HasSystemFrame
Review URL: https://codereview.chromium.org/1800293002
Cr-Commit-Position: refs/heads/master@{#382028}
7 files changed, 116 insertions, 114 deletions
diff --git a/chrome/browser/ui/views/frame/browser_desktop_window_tree_host_win.cc b/chrome/browser/ui/views/frame/browser_desktop_window_tree_host_win.cc index 035fcab..b91e5f1 100644 --- a/chrome/browser/ui/views/frame/browser_desktop_window_tree_host_win.cc +++ b/chrome/browser/ui/views/frame/browser_desktop_window_tree_host_win.cc @@ -204,19 +204,21 @@ void BrowserDesktopWindowTreeHostWin::PostHandleMSG(UINT message, } } - -bool BrowserDesktopWindowTreeHostWin::IsUsingCustomFrame() const { +views::FrameMode BrowserDesktopWindowTreeHostWin::GetFrameMode() const { // We don't theme popup or app windows, so regardless of whether or not a // theme is active for normal browser windows, we don't want to use the custom // frame for popups/apps. if (!browser_view_->IsBrowserTypeNormal() && - !DesktopWindowTreeHostWin::IsUsingCustomFrame()) { - return false; + DesktopWindowTreeHostWin::GetFrameMode() == + views::FrameMode::SYSTEM_DRAWN) { + return views::FrameMode::SYSTEM_DRAWN; } // Otherwise, we use the native frame when we're told we should by the theme // provider (e.g. no custom theme is active). - return !GetWidget()->GetThemeProvider()->ShouldUseNativeFrame(); + return GetWidget()->GetThemeProvider()->ShouldUseNativeFrame() + ? views::FrameMode::SYSTEM_DRAWN + : views::FrameMode::CUSTOM_DRAWN; } bool BrowserDesktopWindowTreeHostWin::ShouldUseNativeFrame() const { diff --git a/chrome/browser/ui/views/frame/browser_desktop_window_tree_host_win.h b/chrome/browser/ui/views/frame/browser_desktop_window_tree_host_win.h index 81314c5..91a7cd2 100644 --- a/chrome/browser/ui/views/frame/browser_desktop_window_tree_host_win.h +++ b/chrome/browser/ui/views/frame/browser_desktop_window_tree_host_win.h @@ -51,7 +51,7 @@ class BrowserDesktopWindowTreeHostWin : public BrowserDesktopWindowTreeHost, LPARAM l_param, LRESULT* result) override; void PostHandleMSG(UINT message, WPARAM w_param, LPARAM l_param) override; - bool IsUsingCustomFrame() const override; + views::FrameMode GetFrameMode() const override; bool ShouldUseNativeFrame() const override; void FrameTypeChanged() override; diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc index 92cc44e..9f58b13 100644 --- a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc +++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.cc @@ -137,8 +137,7 @@ void DesktopWindowTreeHostWin::Init(aura::Window* content_window, if (params.parent && params.parent->GetHost()) parent_hwnd = params.parent->GetHost()->GetAcceleratedWidget(); - message_handler_->set_remove_standard_frame(params.remove_standard_frame); - + remove_standard_frame_ = params.remove_standard_frame; has_non_client_view_ = Widget::RequiresNonClientView(params.type); gfx::Rect pixel_bounds = gfx::win::DIPToScreenRect(params.bounds); @@ -588,12 +587,17 @@ void DesktopWindowTreeHostWin::OnWindowHidingAnimationCompleted() { //////////////////////////////////////////////////////////////////////////////// // DesktopWindowTreeHostWin, HWNDMessageHandlerDelegate implementation: -bool DesktopWindowTreeHostWin::IsWidgetWindow() const { +bool DesktopWindowTreeHostWin::HasNonClientView() const { return has_non_client_view_; } -bool DesktopWindowTreeHostWin::IsUsingCustomFrame() const { - return !GetWidget()->ShouldUseNativeFrame(); +FrameMode DesktopWindowTreeHostWin::GetFrameMode() const { + return GetWidget()->ShouldUseNativeFrame() ? FrameMode::SYSTEM_DRAWN + : FrameMode::CUSTOM_DRAWN; +} + +bool DesktopWindowTreeHostWin::HasFrame() const { + return !remove_standard_frame_; } void DesktopWindowTreeHostWin::SchedulePaint() { diff --git a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.h b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.h index dee68df..3465112 100644 --- a/ui/views/widget/desktop_aura/desktop_window_tree_host_win.h +++ b/ui/views/widget/desktop_aura/desktop_window_tree_host_win.h @@ -126,8 +126,9 @@ class VIEWS_EXPORT DesktopWindowTreeHostWin void OnWindowHidingAnimationCompleted() override; // Overridden from HWNDMessageHandlerDelegate: - bool IsWidgetWindow() const override; - bool IsUsingCustomFrame() const override; + bool HasNonClientView() const override; + FrameMode GetFrameMode() const override; + bool HasFrame() const override; void SchedulePaint() override; void SetAlwaysRenderAsActive(bool always_render_as_active) override; bool IsAlwaysRenderAsActive() override; @@ -244,6 +245,9 @@ class VIEWS_EXPORT DesktopWindowTreeHostWin // Init time, before the Widget has created the NonClientView. bool has_non_client_view_; + // True if the window should have the frame removed. + bool remove_standard_frame_; + // Owned by TooltipController, but we need to forward events to it so we keep // a reference. corewm::TooltipWin* tooltip_; diff --git a/ui/views/win/hwnd_message_handler.cc b/ui/views/win/hwnd_message_handler.cc index 05ca954..7efa0a5 100644 --- a/ui/views/win/hwnd_message_handler.cc +++ b/ui/views/win/hwnd_message_handler.cc @@ -152,13 +152,10 @@ LRESULT CALLBACK MoveLoopMouseWatcher::KeyHook(int n_code, WPARAM w_param, LPARAM l_param) { if (n_code == HC_ACTION && w_param == VK_ESCAPE) { - if (base::win::GetVersion() >= base::win::VERSION_VISTA) { - int value = TRUE; - DwmSetWindowAttribute(instance_->host_->hwnd(), - DWMWA_TRANSITIONS_FORCEDISABLED, - &value, - sizeof(value)); - } + int value = TRUE; + DwmSetWindowAttribute(instance_->host_->hwnd(), + DWMWA_TRANSITIONS_FORCEDISABLED, &value, + sizeof(value)); if (instance_->hide_on_escape_) instance_->host_->Hide(); } @@ -316,7 +313,6 @@ HWNDMessageHandler::HWNDMessageHandler(HWNDMessageHandlerDelegate* delegate) delegate_(delegate), fullscreen_handler_(new FullscreenHandler), waiting_for_close_now_(false), - remove_standard_frame_(false), use_system_default_icon_(false), restored_enabled_(false), current_cursor_(NULL), @@ -389,11 +385,9 @@ void HWNDMessageHandler::Init(HWND parent, const gfx::Rect& bounds) { direct_manipulation_helper_->Initialize(hwnd()); // Disable pen flicks (http://crbug.com/506977) - if (base::win::GetVersion() >= base::win::VERSION_WIN7) { - ::SetProp(hwnd(), MICROSOFT_TABLETPENSERVICE_PROPERTY, - reinterpret_cast<HANDLE>(TABLET_DISABLE_FLICKS | - TABLET_DISABLE_FLICKFALLBACKKEYS)); - } + ::SetProp(hwnd(), MICROSOFT_TABLETPENSERVICE_PROPERTY, + reinterpret_cast<HANDLE>(TABLET_DISABLE_FLICKS | + TABLET_DISABLE_FLICKFALLBACKKEYS)); } void HWNDMessageHandler::InitModalType(ui::ModalType modal_type) { @@ -422,8 +416,7 @@ void HWNDMessageHandler::Close() { // Remove the property which disables pen flicks (http://crbug.com/506977) // for this window. - if (base::win::GetVersion() >= base::win::VERSION_WIN7) - ::RemoveProp(hwnd(), MICROSOFT_TABLETPENSERVICE_PROPERTY); + ::RemoveProp(hwnd(), MICROSOFT_TABLETPENSERVICE_PROPERTY); if (!waiting_for_close_now_) { // And we delay the close so that if we are called from an ATL callback, @@ -464,7 +457,7 @@ gfx::Rect HWNDMessageHandler::GetClientAreaBoundsInScreen() const { gfx::Rect HWNDMessageHandler::GetRestoredBounds() const { // If we're in fullscreen mode, we've changed the normal bounds to the monitor // rect, so return the saved bounds instead. - if (fullscreen_handler_->fullscreen()) + if (IsFullscreen()) return fullscreen_handler_->GetRestoreBounds(); gfx::Rect bounds; @@ -697,6 +690,10 @@ bool HWNDMessageHandler::IsMaximized() const { return !!::IsZoomed(hwnd()); } +bool HWNDMessageHandler::IsFullscreen() const { + return fullscreen_handler_->fullscreen(); +} + bool HWNDMessageHandler::IsAlwaysOnTop() const { return (GetWindowLong(hwnd(), GWL_EXSTYLE) & WS_EX_TOPMOST) != 0; } @@ -761,11 +758,9 @@ bool HWNDMessageHandler::HasCapture() const { } void HWNDMessageHandler::SetVisibilityChangedAnimationsEnabled(bool enabled) { - if (base::win::GetVersion() >= base::win::VERSION_VISTA) { - int dwm_value = enabled ? FALSE : TRUE; - DwmSetWindowAttribute( - hwnd(), DWMWA_TRANSITIONS_FORCEDISABLED, &dwm_value, sizeof(dwm_value)); - } + int dwm_value = enabled ? FALSE : TRUE; + DwmSetWindowAttribute(hwnd(), DWMWA_TRANSITIONS_FORCEDISABLED, &dwm_value, + sizeof(dwm_value)); } bool HWNDMessageHandler::SetTitle(const base::string16& title) { @@ -794,18 +789,11 @@ void HWNDMessageHandler::SetCursor(HCURSOR cursor) { } void HWNDMessageHandler::FrameTypeChanged() { - if (base::win::GetVersion() < base::win::VERSION_VISTA) { - // Don't redraw the window here, because we invalidate the window later. - ResetWindowRegion(true, false); - // The non-client view needs to update too. - delegate_->HandleFrameChanged(); - InvalidateRect(hwnd(), NULL, FALSE); - } else { - if (!custom_window_region_.is_valid() && !delegate_->IsUsingCustomFrame()) - dwm_transition_desired_ = true; - if (!dwm_transition_desired_ || !fullscreen_handler_->fullscreen()) - PerformDwmTransition(); - } + if (!custom_window_region_.is_valid() && + delegate_->GetFrameMode() == FrameMode::SYSTEM_DRAWN) + dwm_transition_desired_ = true; + if (!dwm_transition_desired_ || !IsFullscreen()) + PerformDwmTransition(); } void HWNDMessageHandler::SetWindowIcons(const gfx::ImageSkia& window_icon, @@ -1041,8 +1029,7 @@ void HWNDMessageHandler::PostProcessActivateMessage( // thread. This in turn ensures that maximized windows on the same thread /// don't obscure the taskbar, etc. if (!active) { - if (fullscreen_handler_->fullscreen() && - ::IsWindow(window_gaining_or_losing_activation)) { + if (IsFullscreen() && ::IsWindow(window_gaining_or_losing_activation)) { // Reduce the bounds of the window by 1px to ensure that Windows does // not treat this like a fullscreen window. MONITORINFO monitor_info = {sizeof(monitor_info)}; @@ -1055,7 +1042,7 @@ void HWNDMessageHandler::PostProcessActivateMessage( } } else if (background_fullscreen_hack_) { // Restore the bounds of the window to fullscreen. - DCHECK(fullscreen_handler_->fullscreen()); + DCHECK(IsFullscreen()); background_fullscreen_hack_ = false; MONITORINFO monitor_info = {sizeof(monitor_info)}; GetMonitorInfo(MonitorFromWindow(hwnd(), MONITOR_DEFAULTTOPRIMARY), @@ -1121,16 +1108,14 @@ bool HWNDMessageHandler::GetClientAreaInsets(gfx::Insets* insets) const { // Returning false causes the default handling in OnNCCalcSize() to // be invoked. - if (!delegate_->IsWidgetWindow() || - (!delegate_->IsUsingCustomFrame() && !remove_standard_frame_)) { + if (!delegate_->HasNonClientView() || HasSystemFrame()) return false; - } if (IsMaximized()) { // Windows automatically adds a standard width border to all sides when a // window is maximized. int border_thickness = GetSystemMetrics(SM_CXSIZEFRAME); - if (remove_standard_frame_) + if (!delegate_->HasFrame()) border_thickness -= 1; *insets = gfx::Insets( border_thickness, border_thickness, border_thickness, border_thickness); @@ -1150,7 +1135,8 @@ void HWNDMessageHandler::ResetWindowRegion(bool force, bool redraw) { // the delegate to allow for a custom hit mask. if ((window_ex_style() & WS_EX_COMPOSITED) == 0 && !custom_window_region_.is_valid() && - (!delegate_->IsUsingCustomFrame() || !delegate_->IsWidgetWindow())) { + (delegate_->GetFrameMode() == FrameMode::SYSTEM_DRAWN || + !delegate_->HasNonClientView())) { if (force) SetWindowRgn(hwnd(), NULL, redraw); return; @@ -1194,14 +1180,12 @@ void HWNDMessageHandler::ResetWindowRegion(bool force, bool redraw) { } void HWNDMessageHandler::UpdateDwmNcRenderingPolicy() { - if (base::win::GetVersion() < base::win::VERSION_VISTA) - return; - - if (fullscreen_handler_->fullscreen()) + if (IsFullscreen()) return; DWMNCRENDERINGPOLICY policy = - custom_window_region_.is_valid() || delegate_->IsUsingCustomFrame() + custom_window_region_.is_valid() || + delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN ? DWMNCRP_DISABLED : DWMNCRP_ENABLED; @@ -1260,14 +1244,19 @@ void HWNDMessageHandler::ForceRedrawWindow(int attempts) { InvalidateRect(hwnd(), NULL, FALSE); } +bool HWNDMessageHandler::HasSystemFrame() const { + return delegate_->HasFrame() && + delegate_->GetFrameMode() == FrameMode::SYSTEM_DRAWN; +} + // Message handlers ------------------------------------------------------------ void HWNDMessageHandler::OnActivateApp(BOOL active, DWORD thread_id) { - if (delegate_->IsWidgetWindow() && !active && + if (delegate_->HasNonClientView() && !active && thread_id != GetCurrentThreadId()) { delegate_->HandleAppDeactivated(); // Also update the native frame if it is rendering the non-client area. - if (!remove_standard_frame_ && !delegate_->IsUsingCustomFrame()) + if (HasSystemFrame()) DefWindowProcWithRedrawLock(WM_NCACTIVATE, FALSE, 0); } } @@ -1309,12 +1298,10 @@ void HWNDMessageHandler::OnCommand(UINT notification_code, LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) { if (window_ex_style() & WS_EX_COMPOSITED) { - if (base::win::GetVersion() >= base::win::VERSION_VISTA) { - // This is part of the magic to emulate layered windows with Aura - // see the explanation elsewere when we set WS_EX_COMPOSITED style. - MARGINS margins = {-1,-1,-1,-1}; - DwmExtendFrameIntoClientArea(hwnd(), &margins); - } + // This is part of the magic to emulate layered windows with Aura + // see the explanation elsewere when we set WS_EX_COMPOSITED style. + MARGINS margins = {-1, -1, -1, -1}; + DwmExtendFrameIntoClientArea(hwnd(), &margins); } fullscreen_handler_->set_hwnd(hwnd()); @@ -1326,7 +1313,7 @@ LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) { MAKELPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0); - if (remove_standard_frame_) { + if (!delegate_->HasFrame()) { SetWindowLong(hwnd(), GWL_STYLE, GetWindowLong(hwnd(), GWL_STYLE) & ~WS_CAPTION); SendFrameChanged(); @@ -1335,8 +1322,7 @@ LRESULT HWNDMessageHandler::OnCreate(CREATESTRUCT* create_struct) { // Get access to a modifiable copy of the system menu. GetSystemMenu(hwnd(), false); - if (base::win::GetVersion() >= base::win::VERSION_WIN7 && - ui::AreTouchEventsEnabled()) + if (ui::AreTouchEventsEnabled()) RegisterTouchWindow(hwnd(), TWF_WANTPALM); // We need to allow the delegate to size its contents since the window may not @@ -1370,7 +1356,7 @@ void HWNDMessageHandler::OnDisplayChange(UINT bits_per_pixel, LRESULT HWNDMessageHandler::OnDwmCompositionChanged(UINT msg, WPARAM w_param, LPARAM l_param) { - if (!delegate_->IsWidgetWindow()) { + if (!delegate_->HasNonClientView()) { SetMsgHandled(FALSE); return 0; } @@ -1491,7 +1477,7 @@ LRESULT HWNDMessageHandler::OnImeMessages(UINT message, } void HWNDMessageHandler::OnInitMenu(HMENU menu) { - bool is_fullscreen = fullscreen_handler_->fullscreen(); + bool is_fullscreen = IsFullscreen(); bool is_minimized = IsMinimized(); bool is_maximized = IsMaximized(); bool is_restored = !is_fullscreen && !is_minimized && !is_maximized; @@ -1559,7 +1545,7 @@ LRESULT HWNDMessageHandler::OnMouseActivate(UINT message, // TODO(beng): resolve this with the GetWindowLong() check on the subsequent // line. - if (delegate_->IsWidgetWindow()) { + if (delegate_->HasNonClientView()) { if (delegate_->CanActivate()) return MA_ACTIVATE; if (delegate_->WantsMouseEventsWhenInactive()) @@ -1600,7 +1586,7 @@ LRESULT HWNDMessageHandler::OnNCActivate(UINT message, bool render_as_active = delegate_->IsAlwaysRenderAsActive(); - if (!delegate_->IsWidgetWindow()) { + if (!delegate_->HasNonClientView()) { SetMsgHandled(FALSE); return 0; } @@ -1612,7 +1598,7 @@ LRESULT HWNDMessageHandler::OnNCActivate(UINT message, if (active && render_as_active) delegate_->SetAlwaysRenderAsActive(false); - if (delegate_->IsUsingCustomFrame()) { + if (delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN) { // TODO(beng, et al): Hack to redraw this window and child windows // synchronously upon activation. Not all child windows are redrawing // themselves leading to issues like http://crbug.com/74604 @@ -1629,10 +1615,7 @@ LRESULT HWNDMessageHandler::OnNCActivate(UINT message, if (IsVisible()) delegate_->SchedulePaint(); - // Avoid DefWindowProc non-client rendering over our custom frame on newer - // Windows versions only (breaks taskbar activation indication on XP/Vista). - if (delegate_->IsUsingCustomFrame() && - base::win::GetVersion() > base::win::VERSION_VISTA) { + if (delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN) { SetMsgHandled(TRUE); return TRUE; } @@ -1661,8 +1644,7 @@ LRESULT HWNDMessageHandler::OnNCCalcSize(BOOL mode, LPARAM l_param) { gfx::Insets insets; bool got_insets = GetClientAreaInsets(&insets); - if (!got_insets && !fullscreen_handler_->fullscreen() && - !(mode && remove_standard_frame_)) { + if (!got_insets && !IsFullscreen() && !(mode && !delegate_->HasFrame())) { SetMsgHandled(FALSE); return 0; } @@ -1701,7 +1683,7 @@ LRESULT HWNDMessageHandler::OnNCCalcSize(BOOL mode, LPARAM l_param) { if (autohide_edges & ViewsDelegate::EDGE_LEFT) client_rect->left += kAutoHideTaskbarThicknessPx; if (autohide_edges & ViewsDelegate::EDGE_TOP) { - if (!delegate_->IsUsingCustomFrame()) { + if (delegate_->GetFrameMode() == FrameMode::SYSTEM_DRAWN) { // Tricky bit. Due to a bug in DwmDefWindowProc()'s handling of // WM_NCHITTEST, having any nonclient area atop the window causes the // caption buttons to draw onscreen but not respond to mouse @@ -1740,14 +1722,14 @@ LRESULT HWNDMessageHandler::OnNCCalcSize(BOOL mode, LPARAM l_param) { } LRESULT HWNDMessageHandler::OnNCHitTest(const gfx::Point& point) { - if (!delegate_->IsWidgetWindow()) { + if (!delegate_->HasNonClientView()) { SetMsgHandled(FALSE); return 0; } // If the DWM is rendering the window controls, we need to give the DWM's // default window procedure first chance to handle hit testing. - if (!remove_standard_frame_ && !delegate_->IsUsingCustomFrame()) { + if (HasSystemFrame()) { LRESULT result; if (DwmDefWindowProc(hwnd(), WM_NCHITTEST, 0, MAKELPARAM(point.x(), point.y()), &result)) { @@ -1814,10 +1796,11 @@ LRESULT HWNDMessageHandler::OnNCHitTest(const gfx::Point& point) { } void HWNDMessageHandler::OnNCPaint(HRGN rgn) { - // We only do non-client painting if we're not using the native frame. + // We only do non-client painting if we're not using the system frame. // It's required to avoid some native painting artifacts from appearing when // the window is resized. - if (!delegate_->IsWidgetWindow() || !delegate_->IsUsingCustomFrame()) { + if (!delegate_->HasNonClientView() || + delegate_->GetFrameMode() == FrameMode::SYSTEM_DRAWN) { SetMsgHandled(FALSE); return; } @@ -1861,7 +1844,7 @@ void HWNDMessageHandler::OnNCPaint(HRGN rgn) { // When using a custom frame, we want to avoid calling DefWindowProc() since // that may render artifacts. - SetMsgHandled(delegate_->IsUsingCustomFrame()); + SetMsgHandled(delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN); } LRESULT HWNDMessageHandler::OnNCUAHDrawCaption(UINT message, @@ -1869,7 +1852,7 @@ LRESULT HWNDMessageHandler::OnNCUAHDrawCaption(UINT message, LPARAM l_param) { // See comment in widget_win.h at the definition of WM_NCUAHDRAWCAPTION for // an explanation about why we need to handle this message. - SetMsgHandled(delegate_->IsUsingCustomFrame()); + SetMsgHandled(delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN); return 0; } @@ -1878,7 +1861,7 @@ LRESULT HWNDMessageHandler::OnNCUAHDrawFrame(UINT message, LPARAM l_param) { // See comment in widget_win.h at the definition of WM_NCUAHDRAWCAPTION for // an explanation about why we need to handle this message. - SetMsgHandled(delegate_->IsUsingCustomFrame()); + SetMsgHandled(delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN); return 0; } @@ -2059,12 +2042,11 @@ void HWNDMessageHandler::OnSysCommand(UINT notification_code, // specific information so we must exclude this when comparing. static const int sc_mask = 0xFFF0; // Ignore size/move/maximize in fullscreen mode. - if (fullscreen_handler_->fullscreen() && - (((notification_code & sc_mask) == SC_SIZE) || - ((notification_code & sc_mask) == SC_MOVE) || - ((notification_code & sc_mask) == SC_MAXIMIZE))) + if (IsFullscreen() && (((notification_code & sc_mask) == SC_SIZE) || + ((notification_code & sc_mask) == SC_MOVE) || + ((notification_code & sc_mask) == SC_MAXIMIZE))) return; - if (delegate_->IsUsingCustomFrame()) { + if (delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN) { if ((notification_code & sc_mask) == SC_MINIMIZE || (notification_code & sc_mask) == SC_MAXIMIZE || (notification_code & sc_mask) == SC_RESTORE) { @@ -2218,9 +2200,8 @@ void HWNDMessageHandler::OnWindowPosChanging(WINDOWPOS* window_pos) { background_fullscreen_hack_ = false; } if (monitor && (monitor == last_monitor_) && - ((fullscreen_handler_->fullscreen() && - !background_fullscreen_hack_) || - work_area_changed)) { + ((IsFullscreen() && !background_fullscreen_hack_) || + work_area_changed)) { // A rect for the monitor we're on changed. Normally Windows notifies // us about this (and thus we're reaching here due to the SetWindowPos() // call in OnSettingChange() above), but with some software (e.g. @@ -2230,7 +2211,7 @@ void HWNDMessageHandler::OnWindowPosChanging(WINDOWPOS* window_pos) { // response is to throw away the existing position/size information in // |window_pos| and recalculate it based on the new work rect. gfx::Rect new_window_rect; - if (fullscreen_handler_->fullscreen()) { + if (IsFullscreen()) { new_window_rect = monitor_rect; } else if (IsMaximized()) { new_window_rect = work_area; @@ -2292,7 +2273,7 @@ void HWNDMessageHandler::OnWindowPosChanging(WINDOWPOS* window_pos) { void HWNDMessageHandler::OnWindowPosChanged(WINDOWPOS* window_pos) { if (DidClientAreaSizeChange(window_pos)) ClientAreaSizeChanged(); - if (remove_standard_frame_ && window_pos->flags & SWP_FRAMECHANGED && + if (!delegate_->HasFrame() && window_pos->flags & SWP_FRAMECHANGED && ui::win::IsAeroGlassEnabled() && (window_ex_style() & WS_EX_COMPOSITED) == 0) { MARGINS m = {10, 10, 10, 10}; @@ -2382,7 +2363,8 @@ LRESULT HWNDMessageHandler::HandleMouseEventInternal(UINT message, gfx::ShowSystemMenuAtPoint(hwnd(), gfx::Point(screen_point)); return 0; } - } else if (message == WM_NCLBUTTONDOWN && delegate_->IsUsingCustomFrame()) { + } else if (message == WM_NCLBUTTONDOWN && + delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN) { switch (w_param) { case HTCLOSE: case HTMINBUTTON: @@ -2453,7 +2435,8 @@ LRESULT HWNDMessageHandler::HandleMouseEventInternal(UINT message, } if (!handled && message == WM_NCLBUTTONDOWN && w_param != HTSYSMENU && - w_param != HTCAPTION && delegate_->IsUsingCustomFrame()) { + w_param != HTCAPTION && + delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN) { // TODO(msw): Eliminate undesired painting, or re-evaluate this workaround. // DefWindowProc for WM_NCLBUTTONDOWN does weird non-client painting, so we // need to call it inside a ScopedRedrawLock. This may cause other negative @@ -2505,7 +2488,7 @@ void HWNDMessageHandler::PerformDwmTransition() { // The non-client view needs to update too. delegate_->HandleFrameChanged(); - if (IsVisible() && !delegate_->IsUsingCustomFrame()) { + if (IsVisible() && delegate_->GetFrameMode() == FrameMode::SYSTEM_DRAWN) { // For some reason, we need to hide the window after we change from a custom // frame to a native frame. If we don't, the client area will be filled // with black. This seems to be related to an interaction between DWM and @@ -2608,7 +2591,7 @@ bool HWNDMessageHandler::HandleMouseInputForCaption(unsigned int message, // any member variables after the DefWindowProc call. left_button_down_on_caption_ = false; - if (delegate_->IsUsingCustomFrame()) { + if (delegate_->GetFrameMode() == FrameMode::CUSTOM_DRAWN) { DefWindowProcWithRedrawLock(WM_NCLBUTTONDOWN, HTCAPTION, l_param); } else { DefWindowProc(hwnd(), WM_NCLBUTTONDOWN, HTCAPTION, l_param); diff --git a/ui/views/win/hwnd_message_handler.h b/ui/views/win/hwnd_message_handler.h index 65578e8..143b1c6 100644 --- a/ui/views/win/hwnd_message_handler.h +++ b/ui/views/win/hwnd_message_handler.h @@ -163,6 +163,7 @@ class VIEWS_EXPORT HWNDMessageHandler : bool IsActive() const; bool IsMinimized() const; bool IsMaximized() const; + bool IsFullscreen() const; bool IsAlwaysOnTop() const; bool RunMoveLoop(const gfx::Vector2d& drag_offset, bool hide_on_escape); @@ -193,10 +194,6 @@ class VIEWS_EXPORT HWNDMessageHandler : void SetWindowIcons(const gfx::ImageSkia& window_icon, const gfx::ImageSkia& app_icon); - void set_remove_standard_frame(bool remove_standard_frame) { - remove_standard_frame_ = remove_standard_frame; - } - void set_use_system_default_icon(bool use_system_default_icon) { use_system_default_icon_ = use_system_default_icon; } @@ -313,6 +310,8 @@ class VIEWS_EXPORT HWNDMessageHandler : // onscreen. void ForceRedrawWindow(int attempts); + bool HasSystemFrame() const; + // Message Handlers ---------------------------------------------------------- BEGIN_SAFE_MSG_MAP_EX(weak_factory_) @@ -521,8 +520,6 @@ class VIEWS_EXPORT HWNDMessageHandler : // Set to true in Close() and false is CloseNow(). bool waiting_for_close_now_; - bool remove_standard_frame_; - bool use_system_default_icon_; // Whether all ancestors have been enabled. This is only used if is_modal_ is diff --git a/ui/views/win/hwnd_message_handler_delegate.h b/ui/views/win/hwnd_message_handler_delegate.h index 3e68197..007157a 100644 --- a/ui/views/win/hwnd_message_handler_delegate.h +++ b/ui/views/win/hwnd_message_handler_delegate.h @@ -24,17 +24,29 @@ class TouchEvent; namespace views { +enum class FrameMode { + SYSTEM_DRAWN, // "glass" frame + CUSTOM_DRAWN // "opaque" frame +}; + class InputMethod; // Implemented by the object that uses the HWNDMessageHandler to handle // notifications from the underlying HWND and service requests for data. class VIEWS_EXPORT HWNDMessageHandlerDelegate { public: - virtual bool IsWidgetWindow() const = 0; - - // TODO(beng): resolve this more satisfactorily vis-a-vis ShouldUseNativeFrame - // to avoid confusion. - virtual bool IsUsingCustomFrame() const = 0; + // True if the widget associated with this window has a non-client view. + virtual bool HasNonClientView() const = 0; + + // Returns who we want to be drawing the frame. Either the system (Windows) + // will handle it or Chrome will custom draw it. + virtual FrameMode GetFrameMode() const = 0; + + // True if a frame should be drawn. This will return true for some windows + // that don't have a visible frame. Those usually have the WS_POPUP style, for + // which Windows will remove the frame automatically if the frame mode is + // SYSTEM_DRAWN. + virtual bool HasFrame() const = 0; virtual void SchedulePaint() = 0; virtual void SetAlwaysRenderAsActive(bool always_render_as_active) = 0; |
