diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-18 15:15:59 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-18 15:15:59 +0000 |
commit | cdc05ec939773ef32e249d43b6f7393ee985d1fe (patch) | |
tree | f8229612e46e8e0e8518122aa84f0725fd521ff2 /views/window | |
parent | d5d1ad4336d7d8ada639f868088d6dca70674def (diff) | |
download | chromium_src-cdc05ec939773ef32e249d43b6f7393ee985d1fe.zip chromium_src-cdc05ec939773ef32e249d43b6f7393ee985d1fe.tar.gz chromium_src-cdc05ec939773ef32e249d43b6f7393ee985d1fe.tar.bz2 |
Re-land:
Consolidate ShouldUseNativeFrame/AlwaysUseNativeFrame/UseNativeFrame spaghetti. See earlier commit in log for full description.
THIS WILL BREAK chrome_frame_tests!
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/7036011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85765 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/window')
-rw-r--r-- | views/window/native_window_delegate.h | 4 | ||||
-rw-r--r-- | views/window/non_client_view.cc | 23 | ||||
-rw-r--r-- | views/window/non_client_view.h | 14 | ||||
-rw-r--r-- | views/window/window.cc | 20 | ||||
-rw-r--r-- | views/window/window.h | 18 | ||||
-rw-r--r-- | views/window/window_win.cc | 31 |
6 files changed, 48 insertions, 62 deletions
diff --git a/views/window/native_window_delegate.h b/views/window/native_window_delegate.h index c88924b..12cf3cf 100644 --- a/views/window/native_window_delegate.h +++ b/views/window/native_window_delegate.h @@ -35,10 +35,6 @@ class NativeWindowDelegate { // Returns true if the window is a dialog box. virtual bool IsDialogBox() const = 0; - // Returns true if the window is using a system native frame. Returns false if - // it is rendering its own title bar, borders and controls. - virtual bool IsUsingNativeFrame() const = 0; - // Returns the smallest size the window can be resized to by the user. virtual gfx::Size GetMinimumSize() const = 0; diff --git a/views/window/non_client_view.cc b/views/window/non_client_view.cc index 5830d73..a930a19 100644 --- a/views/window/non_client_view.cc +++ b/views/window/non_client_view.cc @@ -66,21 +66,6 @@ void NonClientView::UpdateFrame() { frame_->UpdateFrameAfterFrameChange(); } -bool NonClientView::UseNativeFrame() const { - if (frame_view_.get()) { - // The frame view may always require a native frame, e.g. popups on Vista+ - // when themes are active. - if (frame_view_->AlwaysUseNativeFrame()) - return true; - - // The frame view may always require a custom frame, e.g. Constrained - // Windows. - if (frame_view_->AlwaysUseCustomFrame()) - return false; - } - return frame_->ShouldUseNativeFrame(); -} - void NonClientView::DisableInactiveRendering(bool disable) { frame_view_->DisableInactiveRendering(disable); } @@ -192,14 +177,6 @@ views::View* NonClientView::GetEventHandlerForPoint(const gfx::Point& point) { //////////////////////////////////////////////////////////////////////////////// // NonClientFrameView, View overrides: -bool NonClientFrameView::AlwaysUseCustomFrame() const { - return false; -} - -bool NonClientFrameView::AlwaysUseNativeFrame() const { - return false; -} - bool NonClientFrameView::HitTest(const gfx::Point& l) const { // For the default case, we assume the non-client frame view never overlaps // the client view. diff --git a/views/window/non_client_view.h b/views/window/non_client_view.h index d678571..0127d8b 100644 --- a/views/window/non_client_view.h +++ b/views/window/non_client_view.h @@ -45,16 +45,6 @@ class NonClientFrameView : public View { // view should be laid out within. virtual gfx::Rect GetBoundsForClientView() const = 0; - // Returns true if this FrameView should always use the custom frame, - // regardless of the system settings. An example is the Constrained Window, - // which is a child window and must always provide its own frame. - virtual bool AlwaysUseCustomFrame() const; - - // Like AlwaysUseCustomFrame, returns true if this FrameView should always use - // the native frame, regardless of theme settings. An example is popup/app - // windows, which we do not ever want to show themed. - virtual bool AlwaysUseNativeFrame() const; - virtual gfx::Rect GetWindowBoundsForClientBounds( const gfx::Rect& client_bounds) const = 0; @@ -161,10 +151,6 @@ class NonClientView : public View { // |use_native_frame|. void UpdateFrame(); - // Returns true if the native window frame should be used, false if the - // NonClientView provides its own frame implementation. - bool UseNativeFrame() const; - // Prevents the window from being rendered as deactivated when |disable| is // true, until called with |disable| false. Used when a sub-window is to be // shown that shouldn't visually de-activate the window. diff --git a/views/window/window.cc b/views/window/window.cc index efc9f15..8ebc366 100644 --- a/views/window/window.cc +++ b/views/window/window.cc @@ -37,7 +37,8 @@ Window::Window() saved_maximized_state_(false), minimum_size_(100, 100), disable_inactive_rendering_(false), - window_closed_(false) { + window_closed_(false), + frame_type_(FRAME_TYPE_DEFAULT) { } Window::~Window() { @@ -238,9 +239,22 @@ gfx::NativeWindow Window::GetNativeWindow() const { } bool Window::ShouldUseNativeFrame() const { + if (frame_type_ != FRAME_TYPE_DEFAULT) + return frame_type_ == FRAME_TYPE_FORCE_NATIVE; return native_window_->ShouldUseNativeFrame(); } +void Window::DebugToggleFrameType() { + if (frame_type_ == FRAME_TYPE_DEFAULT) { + frame_type_ = ShouldUseNativeFrame() ? FRAME_TYPE_FORCE_CUSTOM : + FRAME_TYPE_FORCE_NATIVE; + } else { + frame_type_ = frame_type_ == FRAME_TYPE_FORCE_CUSTOM ? + FRAME_TYPE_FORCE_NATIVE : FRAME_TYPE_FORCE_CUSTOM; + } + FrameTypeChanged(); +} + void Window::FrameTypeChanged() { native_window_->FrameTypeChanged(); } @@ -269,10 +283,6 @@ bool Window::IsDialogBox() const { return !!window_delegate_->AsDialogDelegate(); } -bool Window::IsUsingNativeFrame() const { - return non_client_view_->UseNativeFrame(); -} - gfx::Size Window::GetMinimumSize() const { return non_client_view_->GetMinimumSize(); } diff --git a/views/window/window.h b/views/window/window.h index 191aba4..eb8490a 100644 --- a/views/window/window.h +++ b/views/window/window.h @@ -52,6 +52,12 @@ class Window : public Widget, Widget::InitParams widget_init_params; }; + enum FrameType { + FRAME_TYPE_DEFAULT, // Use whatever the default would be. + FRAME_TYPE_FORCE_CUSTOM, // Force the custom frame. + FRAME_TYPE_FORCE_NATIVE // Force the native frame. + }; + Window(); virtual ~Window(); @@ -162,9 +168,16 @@ class Window : public Widget, // Retrieves the Window's native window handle. gfx::NativeWindow GetNativeWindow() const; + void set_frame_type(FrameType frame_type) { frame_type_ = frame_type; } + FrameType frame_type() const { return frame_type_; } + // Whether we should be using a native frame. bool ShouldUseNativeFrame() const; + // Forces the frame into the alternate frame type (custom or native) depending + // on its current state. + void DebugToggleFrameType(); + // Tell the window that something caused the frame type to change. void FrameTypeChanged(); @@ -201,7 +214,6 @@ class Window : public Widget, virtual void EnableInactiveRendering() OVERRIDE; virtual bool IsModal() const OVERRIDE; virtual bool IsDialogBox() const OVERRIDE; - virtual bool IsUsingNativeFrame() const OVERRIDE; virtual gfx::Size GetMinimumSize() const OVERRIDE; virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE; virtual bool ExecuteCommand(int command_id) OVERRIDE; @@ -248,6 +260,10 @@ class Window : public Widget, // Set to true if the window is in the process of closing . bool window_closed_; + // The current frame type in use by this window. Defaults to + // FRAME_TYPE_DEFAULT. + FrameType frame_type_; + DISALLOW_COPY_AND_ASSIGN(Window); }; diff --git a/views/window/window_win.cc b/views/window/window_win.cc index e73c144..2845379 100644 --- a/views/window/window_win.cc +++ b/views/window/window_win.cc @@ -310,7 +310,7 @@ gfx::Font WindowWin::GetWindowTitleFont() { gfx::Insets WindowWin::GetClientAreaInsets() const { // Returning an empty Insets object causes the default handling in // WidgetWin::OnNCCalcSize() to be invoked. - if (delegate_->IsUsingNativeFrame()) + if (GetWindow()->ShouldUseNativeFrame()) return gfx::Insets(); if (IsMaximized()) { @@ -414,7 +414,7 @@ void WindowWin::OnExitSizeMove() { WidgetWin::OnExitSizeMove(); delegate_->OnNativeWindowEndUserBoundsChange(); - if (!ShouldUseNativeFrame()) { + if (!GetWindow()->ShouldUseNativeFrame()) { // Sending SWP_FRAMECHANGED forces a non-client repaint, which fixes the // glitch in rendering the bottom pixel of the window caused by us // offsetting the client rect there (See comment in GetClientAreaInsets()). @@ -438,7 +438,7 @@ void WindowWin::OnGetMinMaxInfo(MINMAXINFO* minmax_info) { void WindowWin::OnInitMenu(HMENU menu) { // We only need to manually enable the system menu if we're not using a native // frame. - if (delegate_->IsUsingNativeFrame()) + if (GetWindow()->ShouldUseNativeFrame()) WidgetWin::OnInitMenu(menu); bool is_fullscreen = IsFullscreen(); @@ -484,7 +484,8 @@ LRESULT WindowWin::OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param) { ExecuteSystemMenuCommand(id); return 0; } - } else if (message == WM_NCLBUTTONDOWN && !delegate_->IsUsingNativeFrame()) { + } else if (message == WM_NCLBUTTONDOWN && + !GetWindow()->ShouldUseNativeFrame()) { switch (w_param) { case HTCLOSE: case HTMINBUTTON: @@ -562,7 +563,7 @@ LRESULT WindowWin::OnNCActivate(BOOL active) { if (IsVisible()) GetWindow()->non_client_view()->SchedulePaint(); - if (!ShouldUseNativeFrame()) { + if (!GetWindow()->ShouldUseNativeFrame()) { // 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 @@ -624,7 +625,7 @@ LRESULT WindowWin::OnNCCalcSize(BOOL mode, LPARAM l_param) { if (EdgeHasTopmostAutoHideTaskbar(ABE_LEFT, monitor)) client_rect->left += kAutoHideTaskbarThicknessPx; if (EdgeHasTopmostAutoHideTaskbar(ABE_TOP, monitor)) { - if (delegate_->IsUsingNativeFrame()) { + if (GetWindow()->ShouldUseNativeFrame()) { // 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 @@ -665,7 +666,7 @@ LRESULT WindowWin::OnNCCalcSize(BOOL mode, LPARAM l_param) { LRESULT WindowWin::OnNCHitTest(const CPoint& point) { // 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 (ShouldUseNativeFrame()) { + if (GetWindow()->ShouldUseNativeFrame()) { LRESULT result; if (DwmDefWindowProc(GetNativeView(), WM_NCHITTEST, 0, MAKELPARAM(point.x, point.y), &result)) { @@ -690,14 +691,14 @@ void WindowWin::OnNCPaint(HRGN rgn) { // When using a custom frame, we want to avoid calling DefWindowProc() since // that may render artifacts. SetMsgHandled((!IsActive() || is_in_size_move_) && - !delegate_->IsUsingNativeFrame()); + !GetWindow()->ShouldUseNativeFrame()); } LRESULT WindowWin::OnNCUAHDrawCaption(UINT msg, WPARAM w_param, 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_->IsUsingNativeFrame()); + SetMsgHandled(!GetWindow()->ShouldUseNativeFrame()); return 0; } @@ -705,7 +706,7 @@ LRESULT WindowWin::OnNCUAHDrawFrame(UINT msg, WPARAM w_param, 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_->IsUsingNativeFrame()); + SetMsgHandled(!GetWindow()->ShouldUseNativeFrame()); return 0; } @@ -762,7 +763,7 @@ void WindowWin::OnSysCommand(UINT notification_code, CPoint click) { ((notification_code & sc_mask) == SC_MOVE) || ((notification_code & sc_mask) == SC_MAXIMIZE))) return; - if (!delegate_->IsUsingNativeFrame()) { + if (!GetWindow()->ShouldUseNativeFrame()) { if ((notification_code & sc_mask) == SC_MINIMIZE || (notification_code & sc_mask) == SC_MAXIMIZE || (notification_code & sc_mask) == SC_RESTORE) { @@ -1205,7 +1206,7 @@ void WindowWin::SetUseDragFrame(bool use_drag_frame) { } NonClientFrameView* WindowWin::CreateFrameViewForWindow() { - if (ShouldUseNativeFrame()) + if (GetWindow()->ShouldUseNativeFrame()) return new NativeFrameView(GetWindow()); return new CustomFrameView(GetWindow()); } @@ -1232,8 +1233,8 @@ void WindowWin::FrameTypeChanged() { // the DWM's glass non-client rendering is enabled, which is why // DWMNCRP_ENABLED is used for the native frame case. _DISABLED means the // DWM doesn't render glass, and so is used in the custom frame case. - DWMNCRENDERINGPOLICY policy = - delegate_->IsUsingNativeFrame() ? DWMNCRP_ENABLED : DWMNCRP_DISABLED; + DWMNCRENDERINGPOLICY policy = GetWindow()->ShouldUseNativeFrame() ? + DWMNCRP_ENABLED : DWMNCRP_DISABLED; DwmSetWindowAttribute(GetNativeView(), DWMWA_NCRENDERING_POLICY, &policy, sizeof(DWMNCRENDERINGPOLICY)); } @@ -1307,7 +1308,7 @@ void WindowWin::UnlockUpdates() { void WindowWin::ResetWindowRegion(bool force) { // A native frame uses the native window region, and we don't want to mess // with it. - if (delegate_->IsUsingNativeFrame()) { + if (GetWindow()->ShouldUseNativeFrame()) { if (force) SetWindowRgn(NULL, TRUE); return; |