diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-02 22:07:05 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-02 22:07:05 +0000 |
commit | 14bcec307d7ec6b13e90fe5e5ac8ca5aaa397b4b (patch) | |
tree | 7c88cf92588f0d99a38757f52cc92b47f7e053ef /views/window | |
parent | 6b8b0f08cfebb37c13f6c835c37d9ed9e982fc37 (diff) | |
download | chromium_src-14bcec307d7ec6b13e90fe5e5ac8ca5aaa397b4b.zip chromium_src-14bcec307d7ec6b13e90fe5e5ac8ca5aaa397b4b.tar.gz chromium_src-14bcec307d7ec6b13e90fe5e5ac8ca5aaa397b4b.tar.bz2 |
Move NonClientView and FrameType logic from Window to Widget.
Also fixes leak of default WidgetDelegate by replacing it with a DefaultWidgetDelegate subclass that overrides DeleteDelegate and deletes itself. This required moving the destruction logic from Window down onto Widget.
BUG=72040
TEST=none
Review URL: http://codereview.chromium.org/7033049
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@87702 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/window')
-rw-r--r-- | views/window/custom_frame_view.cc | 16 | ||||
-rw-r--r-- | views/window/custom_frame_view.h | 6 | ||||
-rw-r--r-- | views/window/native_frame_view.cc | 8 | ||||
-rw-r--r-- | views/window/native_frame_view.h | 6 | ||||
-rw-r--r-- | views/window/native_window.h | 8 | ||||
-rw-r--r-- | views/window/native_window_delegate.h | 7 | ||||
-rw-r--r-- | views/window/native_window_gtk.cc | 26 | ||||
-rw-r--r-- | views/window/native_window_gtk.h | 5 | ||||
-rw-r--r-- | views/window/native_window_views.cc | 15 | ||||
-rw-r--r-- | views/window/native_window_views.h | 4 | ||||
-rw-r--r-- | views/window/native_window_win.cc | 104 | ||||
-rw-r--r-- | views/window/native_window_win.h | 10 | ||||
-rw-r--r-- | views/window/non_client_view.cc | 12 | ||||
-rw-r--r-- | views/window/non_client_view.h | 5 | ||||
-rw-r--r-- | views/window/window.cc | 128 | ||||
-rw-r--r-- | views/window/window.h | 64 |
16 files changed, 74 insertions, 350 deletions
diff --git a/views/window/custom_frame_view.cc b/views/window/custom_frame_view.cc index 85d6ac9..6f9bb8f 100644 --- a/views/window/custom_frame_view.cc +++ b/views/window/custom_frame_view.cc @@ -63,7 +63,7 @@ const int kTitleCaptionSpacing = 5; /////////////////////////////////////////////////////////////////////////////// // CustomFrameView, public: -CustomFrameView::CustomFrameView(Window* frame) +CustomFrameView::CustomFrameView(Widget* frame) : ALLOW_THIS_IN_INITIALIZER_LIST(close_button_(new ImageButton(this))), ALLOW_THIS_IN_INITIALIZER_LIST(restore_button_(new ImageButton(this))), ALLOW_THIS_IN_INITIALIZER_LIST(maximize_button_(new ImageButton(this))), @@ -112,10 +112,10 @@ CustomFrameView::CustomFrameView(Window* frame) rb.GetBitmapNamed(IDR_MINIMIZE_P)); AddChildView(minimize_button_); - should_show_minmax_buttons_ = frame_->window_delegate()->CanMaximize(); - should_show_client_edge_ = frame_->window_delegate()->ShouldShowClientEdge(); + should_show_minmax_buttons_ = frame_->widget_delegate()->CanMaximize(); + should_show_client_edge_ = frame_->widget_delegate()->ShouldShowClientEdge(); - if (frame_->window_delegate()->ShouldShowWindowIcon()) { + if (frame_->widget_delegate()->ShouldShowWindowIcon()) { window_icon_ = new ImageButton(this); AddChildView(window_icon_); } @@ -176,7 +176,7 @@ int CustomFrameView::NonClientHitTest(const gfx::Point& point) { int window_component = GetHTComponentForFrame(point, FrameBorderThickness(), NonClientBorderThickness(), kResizeAreaCornerSize, kResizeAreaCornerSize, - frame_->window_delegate()->CanResize()); + frame_->widget_delegate()->CanResize()); // Fall back to the caption if no other component matches. return (window_component == HTNOWHERE) ? HTCAPTION : window_component; } @@ -403,7 +403,7 @@ void CustomFrameView::PaintMaximizedFrameBorder(gfx::Canvas* canvas) { } void CustomFrameView::PaintTitleBar(gfx::Canvas* canvas) { - WindowDelegate* d = frame_->window_delegate(); + WidgetDelegate* d = frame_->widget_delegate(); // It seems like in some conditions we can be asked to paint after the window // that contains us is WM_DESTROYed. At this point, our delegate is NULL. The @@ -536,11 +536,11 @@ void CustomFrameView::LayoutTitleBar() { // The window title is based on the calculated icon position, even when there // is no icon. gfx::Rect icon_bounds(IconBounds()); - if (frame_->window_delegate()->ShouldShowWindowIcon()) + if (frame_->widget_delegate()->ShouldShowWindowIcon()) window_icon_->SetBoundsRect(icon_bounds); // Size the title. - int title_x = frame_->window_delegate()->ShouldShowWindowIcon() ? + int title_x = frame_->widget_delegate()->ShouldShowWindowIcon() ? icon_bounds.right() + kIconTitleSpacing : icon_bounds.x(); int title_height = title_font_->GetHeight(); // We bias the title position so that when the difference between the icon and diff --git a/views/window/custom_frame_view.h b/views/window/custom_frame_view.h index 16f8ace..aa3367d 100644 --- a/views/window/custom_frame_view.h +++ b/views/window/custom_frame_view.h @@ -7,8 +7,8 @@ #pragma once #include "views/controls/button/image_button.h" +#include "views/widget/widget.h" #include "views/window/non_client_view.h" -#include "views/window/window.h" #include "views/window/window_resources.h" namespace gfx { @@ -32,7 +32,7 @@ namespace views { class CustomFrameView : public NonClientFrameView, public ButtonListener { public: - explicit CustomFrameView(Window* frame); + explicit CustomFrameView(Widget* frame); virtual ~CustomFrameView(); // Overridden from NonClientFrameView: @@ -114,7 +114,7 @@ class CustomFrameView : public NonClientFrameView, bool should_show_client_edge_; // The window that owns this view. - Window* frame_; + Widget* frame_; // Initialize various static resources. static void InitClass(); diff --git a/views/window/native_frame_view.cc b/views/window/native_frame_view.cc index 55906ba..752bdec1f 100644 --- a/views/window/native_frame_view.cc +++ b/views/window/native_frame_view.cc @@ -4,16 +4,16 @@ #include "views/window/native_frame_view.h" +#include "views/widget/native_widget.h" #include "views/widget/native_widget_win.h" -#include "views/window/native_window.h" -#include "views/window/window.h" +#include "views/widget/widget.h" namespace views { //////////////////////////////////////////////////////////////////////////////// // NativeFrameView, public: -NativeFrameView::NativeFrameView(Window* frame) +NativeFrameView::NativeFrameView(Widget* frame) : NonClientFrameView(), frame_(frame) { } @@ -32,7 +32,7 @@ gfx::Rect NativeFrameView::GetWindowBoundsForClientBounds( const gfx::Rect& client_bounds) const { RECT rect = client_bounds.ToRECT(); NativeWidgetWin* widget_win = - static_cast<NativeWidgetWin*>(frame_->native_window()->AsNativeWidget()); + static_cast<NativeWidgetWin*>(frame_->native_widget()); AdjustWindowRectEx(&rect, widget_win->window_style(), FALSE, widget_win->window_ex_style()); return gfx::Rect(rect); diff --git a/views/window/native_frame_view.h b/views/window/native_frame_view.h index 9bc943f..6c50648 100644 --- a/views/window/native_frame_view.h +++ b/views/window/native_frame_view.h @@ -10,11 +10,11 @@ namespace views { -class Window; +class Widget; class NativeFrameView : public NonClientFrameView { public: - explicit NativeFrameView(Window* frame); + explicit NativeFrameView(Widget* frame); virtual ~NativeFrameView(); // NonClientFrameView overrides: @@ -33,7 +33,7 @@ class NativeFrameView : public NonClientFrameView { private: // Our containing frame. - Window* frame_; + Widget* frame_; DISALLOW_COPY_AND_ASSIGN(NativeFrameView); }; diff --git a/views/window/native_window.h b/views/window/native_window.h index dc3a579..ca5c6fc 100644 --- a/views/window/native_window.h +++ b/views/window/native_window.h @@ -63,14 +63,6 @@ class NativeWindow { // Enables or disables the close button for the window. virtual void EnableClose(bool enable) = 0; - - // Window pass-thrus --------------------------------------------------------- - // See documentation in window.h - - virtual NonClientFrameView* CreateFrameViewForWindow() = 0; - virtual void UpdateFrameAfterFrameChange() = 0; - virtual bool ShouldUseNativeFrame() const = 0; - virtual void FrameTypeChanged() = 0; }; } // namespace views diff --git a/views/window/native_window_delegate.h b/views/window/native_window_delegate.h index 12cf3cf..e596120 100644 --- a/views/window/native_window_delegate.h +++ b/views/window/native_window_delegate.h @@ -36,11 +36,11 @@ class NativeWindowDelegate { virtual bool IsDialogBox() const = 0; // Returns the smallest size the window can be resized to by the user. - virtual gfx::Size GetMinimumSize() const = 0; + virtual gfx::Size GetMinimumSize() = 0; // Returns the non-client component (see views/window/hit_test.h) containing // |point|, in client coordinates. - virtual int GetNonClientComponent(const gfx::Point& point) const = 0; + virtual int GetNonClientComponent(const gfx::Point& point) = 0; // Runs the specified native command. Returns true if the command is handled. virtual bool ExecuteCommand(int command_id) = 0; @@ -59,9 +59,6 @@ class NativeWindowDelegate { // last chance to do anything with the native window handle. virtual void OnNativeWindowDestroying() = 0; - // Called just after the native window is destroyed. - virtual void OnNativeWindowDestroyed() = 0; - // Called when the native window's position or size has changed. virtual void OnNativeWindowBoundsChanged() = 0; diff --git a/views/window/native_window_gtk.cc b/views/window/native_window_gtk.cc index 7d238d4..dd944ad 100644 --- a/views/window/native_window_gtk.cc +++ b/views/window/native_window_gtk.cc @@ -238,27 +238,6 @@ const Window* NativeWindowGtk::GetWindow() const { return delegate_->AsWindow(); } -NonClientFrameView* NativeWindowGtk::CreateFrameViewForWindow() { - return NULL; -} - -void NativeWindowGtk::UpdateFrameAfterFrameChange() { - // We currently don't support different frame types on Gtk, so we don't - // need to implement this. - NOTIMPLEMENTED(); -} - -bool NativeWindowGtk::ShouldUseNativeFrame() const { - return false; -} - -void NativeWindowGtk::FrameTypeChanged() { - // This is called when the Theme has changed, so forward the event to the root - // widget. - GetWidget()->ThemeChanged(); - GetWidget()->GetRootView()->SchedulePaint(); -} - //////////////////////////////////////////////////////////////////////////////// // NativeWindowGtk, NativeWidgetGtk overrides: @@ -302,11 +281,6 @@ void NativeWindowGtk::OnDestroy(GtkWidget* widget) { NativeWidgetGtk::OnDestroy(widget); } -void NativeWindowGtk::OnDestroyed(GObject *where_the_object_was) { - delegate_->OnNativeWindowDestroyed(); - NativeWidgetGtk::OnDestroyed(where_the_object_was); -} - //////////////////////////////////////////////////////////////////////////////// // NativeWindow, public: diff --git a/views/window/native_window_gtk.h b/views/window/native_window_gtk.h index f939f97..3ea4c25 100644 --- a/views/window/native_window_gtk.h +++ b/views/window/native_window_gtk.h @@ -52,10 +52,6 @@ class NativeWindowGtk : public NativeWidgetGtk, public NativeWindow { virtual void ShowNativeWindow(ShowState state) OVERRIDE; virtual void BecomeModal() OVERRIDE; virtual void EnableClose(bool enable) OVERRIDE; - virtual NonClientFrameView* CreateFrameViewForWindow() OVERRIDE; - virtual void UpdateFrameAfterFrameChange() OVERRIDE; - virtual bool ShouldUseNativeFrame() const OVERRIDE; - virtual void FrameTypeChanged() OVERRIDE; // Overridden from NativeWidgetGtk: virtual void Restore() OVERRIDE; @@ -66,7 +62,6 @@ class NativeWindowGtk : public NativeWidgetGtk, public NativeWindow { friend class Window; virtual void OnDestroy(GtkWidget* widget); - virtual void OnDestroyed(GObject *where_the_object_was); private: static gboolean CallConfigureEvent(GtkWidget* widget, diff --git a/views/window/native_window_views.cc b/views/window/native_window_views.cc index c9f2a84..26bc697 100644 --- a/views/window/native_window_views.cc +++ b/views/window/native_window_views.cc @@ -57,19 +57,4 @@ void NativeWindowViews::BecomeModal() { void NativeWindowViews::EnableClose(bool enable) { } -NonClientFrameView* NativeWindowViews::CreateFrameViewForWindow() { - return NULL; -} - -void NativeWindowViews::UpdateFrameAfterFrameChange() { -} - -bool NativeWindowViews::ShouldUseNativeFrame() const { - NOTIMPLEMENTED(); - return false; -} - -void NativeWindowViews::FrameTypeChanged() { -} - } // namespace views diff --git a/views/window/native_window_views.h b/views/window/native_window_views.h index 20eb3d0..1489d08 100644 --- a/views/window/native_window_views.h +++ b/views/window/native_window_views.h @@ -33,10 +33,6 @@ class NativeWindowViews : public NativeWidgetViews, virtual void ShowNativeWindow(ShowState state) OVERRIDE; virtual void BecomeModal() OVERRIDE; virtual void EnableClose(bool enable) OVERRIDE; - virtual NonClientFrameView* CreateFrameViewForWindow() OVERRIDE; - virtual void UpdateFrameAfterFrameChange() OVERRIDE; - virtual bool ShouldUseNativeFrame() const OVERRIDE; - virtual void FrameTypeChanged() OVERRIDE; internal::NativeWindowDelegate* delegate_; diff --git a/views/window/native_window_win.cc b/views/window/native_window_win.cc index db688df..df35437 100644 --- a/views/window/native_window_win.cc +++ b/views/window/native_window_win.cc @@ -22,7 +22,6 @@ #include "views/accessibility/native_view_accessibility_win.h" #include "views/window/client_view.h" #include "views/window/native_window_delegate.h" -#include "views/window/native_frame_view.h" #include "views/window/non_client_view.h" #include "views/window/window_delegate.h" @@ -75,13 +74,6 @@ void SendFrameChanged(HWND window) { SWP_NOSENDCHANGING | SWP_NOSIZE | SWP_NOZORDER); } -// Callback used to notify child windows that the top level window received a -// DWMCompositionChanged message. -BOOL CALLBACK SendDwmCompositionChanged(HWND window, LPARAM param) { - SendMessage(window, WM_DWMCOMPOSITIONCHANGED, 0, 0); - return TRUE; -} - // Enables or disables the menu item for the specified command and menu. void EnableMenuItem(HMENU menu, UINT command, bool enabled) { UINT flags = MF_BYCOMMAND | (enabled ? MF_ENABLED : MF_DISABLED | MF_GRAYED); @@ -316,11 +308,6 @@ void NativeWindowWin::OnExitSizeMove() { delegate_->OnNativeWindowEndUserBoundsChange(); } -void NativeWindowWin::OnFinalMessage(HWND window) { - delegate_->OnNativeWindowDestroyed(); - NativeWidgetWin::OnFinalMessage(window); -} - void NativeWindowWin::OnGetMinMaxInfo(MINMAXINFO* minmax_info) { gfx::Size min_window_size(delegate_->GetMinimumSize()); minmax_info->ptMinTrackSize.x = min_window_size.width(); @@ -737,10 +724,7 @@ LRESULT NativeWindowWin::OnSetText(const wchar_t* text) { void NativeWindowWin::OnSize(UINT size_param, const CSize& new_size) { delegate_->OnNativeWindowBoundsChanged(); 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); + NativeWidgetWin::OnSize(size_param, new_size); } void NativeWindowWin::OnSysCommand(UINT notification_code, CPoint click) { @@ -919,49 +903,6 @@ void NativeWindowWin::EnableClose(bool enable) { SendFrameChanged(GetNativeView()); } -NonClientFrameView* NativeWindowWin::CreateFrameViewForWindow() { - return GetWindow()->ShouldUseNativeFrame() ? - new NativeFrameView(GetWindow()) : NULL; -} - -void NativeWindowWin::UpdateFrameAfterFrameChange() { - // We've either gained or lost a custom window region, so reset it now. - ResetWindowRegion(true); -} - -bool NativeWindowWin::ShouldUseNativeFrame() const { - return NativeWidgetWin::IsAeroGlassEnabled(); -} - -void NativeWindowWin::FrameTypeChanged() { - // Called when the frame type could possibly be changing (theme change or - // DWM composition change). - if (base::win::GetVersion() >= base::win::VERSION_VISTA) { - // We need to toggle the rendering policy of the DWM/glass frame as we - // change from opaque to glass. "Non client rendering enabled" means that - // 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 = GetWindow()->ShouldUseNativeFrame() ? - DWMNCRP_ENABLED : DWMNCRP_DISABLED; - DwmSetWindowAttribute(GetNativeView(), DWMWA_NCRENDERING_POLICY, - &policy, sizeof(DWMNCRENDERINGPOLICY)); - } - - // Send a frame change notification, since the non-client metrics have - // changed. - SendFrameChanged(GetNativeView()); - - // Update the non-client view with the correct frame view for the active frame - // type. - GetWindow()->non_client_view()->UpdateFrame(); - - // WM_DWMCOMPOSITIONCHANGED is only sent to top level windows, however we want - // to notify our children too, since we can have MDI child windows who need to - // update their appearance. - EnumChildWindows(GetNativeView(), &SendDwmCompositionChanged, NULL); -} - //////////////////////////////////////////////////////////////////////////////// // NativeWindowWin, NativeWidgetWin overrides: @@ -1023,49 +964,6 @@ void NativeWindowWin::UnlockUpdates() { lock_updates_ = false; } -void NativeWindowWin::ResetWindowRegion(bool force) { - // A native frame uses the native window region, and we don't want to mess - // with it. - if (GetWindow()->ShouldUseNativeFrame()) { - 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; - GetWindow()->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 NativeWindowWin::CallDefaultNCActivateHandler(BOOL active) { // The DefWindowProc handling for WM_NCACTIVATE renders the classic-look // window title bar directly, so we need to use a redraw lock here to prevent diff --git a/views/window/native_window_win.h b/views/window/native_window_win.h index d251579..8652c42 100644 --- a/views/window/native_window_win.h +++ b/views/window/native_window_win.h @@ -81,7 +81,6 @@ class NativeWindowWin : public NativeWidgetWin, LPARAM l_param) OVERRIDE; virtual void OnEnterSizeMove() OVERRIDE; virtual void OnExitSizeMove() OVERRIDE; - virtual void OnFinalMessage(HWND window) OVERRIDE; virtual void OnGetMinMaxInfo(MINMAXINFO* minmax_info) OVERRIDE; virtual void OnInitMenu(HMENU menu) OVERRIDE; virtual LRESULT OnMouseActivate(UINT message, WPARAM w_param, LPARAM l_param) @@ -115,10 +114,6 @@ class NativeWindowWin : public NativeWidgetWin, virtual void ShowNativeWindow(ShowState state) OVERRIDE; virtual void BecomeModal() OVERRIDE; virtual void EnableClose(bool enable) OVERRIDE; - virtual NonClientFrameView* CreateFrameViewForWindow() OVERRIDE; - virtual void UpdateFrameAfterFrameChange() OVERRIDE; - virtual bool ShouldUseNativeFrame() const OVERRIDE; - virtual void FrameTypeChanged() OVERRIDE; // Overridden from NativeWidgetWin: virtual bool IsActive() const OVERRIDE; @@ -140,11 +135,6 @@ class NativeWindowWin : public NativeWidgetWin, // Stops ignoring SetWindowPos() requests (see below). void StopIgnoringPosChanges() { ignore_window_pos_changes_ = false; } - // Resets the window region for the current window bounds if necessary. - // If |force| is true, the window region is reset to NULL even for native - // frame windows. - void ResetWindowRegion(bool force); - // Update accessibility information via our WindowDelegate. void UpdateAccessibleName(std::wstring& accessible_name); void UpdateAccessibleRole(); diff --git a/views/window/non_client_view.cc b/views/window/non_client_view.cc index a930a19..febf26c 100644 --- a/views/window/non_client_view.cc +++ b/views/window/non_client_view.cc @@ -29,9 +29,8 @@ static const int kClientViewIndex = 1; //////////////////////////////////////////////////////////////////////////////// // NonClientView, public: -NonClientView::NonClientView(Window* frame) - : frame_(frame), - client_view_(NULL) { +NonClientView::NonClientView() + : client_view_(NULL) { } NonClientView::~NonClientView() { @@ -59,11 +58,12 @@ void NonClientView::WindowClosing() { } void NonClientView::UpdateFrame() { - SetFrameView(frame_->CreateFrameViewForWindow()); - GetWidget()->ThemeChanged(); + Widget* widget = GetWidget(); + SetFrameView(widget->CreateNonClientFrameView()); + widget->ThemeChanged(); Layout(); SchedulePaint(); - frame_->UpdateFrameAfterFrameChange(); + widget->UpdateFrameAfterFrameChange(); } void NonClientView::DisableInactiveRendering(bool disable) { diff --git a/views/window/non_client_view.h b/views/window/non_client_view.h index 0127d8b..395ec18 100644 --- a/views/window/non_client_view.h +++ b/views/window/non_client_view.h @@ -130,7 +130,7 @@ class NonClientFrameView : public View { // class NonClientView : public View { public: - explicit NonClientView(Window* frame); + NonClientView(); virtual ~NonClientView(); // Returns the current NonClientFrameView instance, or NULL if @@ -213,9 +213,6 @@ class NonClientView : public View { OVERRIDE; private: - // The frame that hosts this NonClientView. - Window* frame_; - // A ClientView object or subclass, responsible for sizing the contents view // of the window, hit testing and perhaps other tasks depending on the // implementation. diff --git a/views/window/window.cc b/views/window/window.cc index bae284e..4dc8fd8 100644 --- a/views/window/window.cc +++ b/views/window/window.cc @@ -14,7 +14,6 @@ #include "ui/gfx/size.h" #include "views/widget/widget.h" #include "views/widget/native_widget.h" -#include "views/window/custom_frame_view.h" #include "views/window/native_window.h" #include "views/window/window_delegate.h" @@ -32,14 +31,10 @@ Window::InitParams::InitParams(WindowDelegate* window_delegate) Window::Window() : native_window_(NULL), - window_delegate_(NULL), - ALLOW_THIS_IN_INITIALIZER_LIST( - non_client_view_(new NonClientView(this))), saved_maximized_state_(false), minimum_size_(100, 100), disable_inactive_rendering_(false), - window_closed_(false), - frame_type_(FRAME_TYPE_DEFAULT) { + window_closed_(false) { } Window::~Window() { @@ -80,18 +75,13 @@ gfx::Size Window::GetLocalizedContentsSize(int col_resource_id, } void Window::InitWindow(const InitParams& params) { - window_delegate_ = params.window_delegate; - DCHECK(window_delegate_); - DCHECK(!window_delegate_->window_); - window_delegate_->window_ = this; native_window_ = params.native_window ? params.native_window : NativeWindow::CreateNativeWindow(this); - // If frame_view was set already, don't replace it with default one. - if (!non_client_view()->frame_view()) - non_client_view()->SetFrameView(CreateFrameViewForWindow()); InitParams modified_params = params; modified_params.widget_init_params.delegate = params.window_delegate; + DCHECK(!modified_params.widget_init_params.delegate->window_); + modified_params.widget_init_params.delegate->window_ = this; modified_params.widget_init_params.native_widget = native_window_->AsNativeWidget(); Init(modified_params.widget_init_params); @@ -112,65 +102,36 @@ void Window::ShowInactive() { void Window::DisableInactiveRendering() { disable_inactive_rendering_ = true; - non_client_view_->DisableInactiveRendering(disable_inactive_rendering_); + non_client_view()->DisableInactiveRendering(disable_inactive_rendering_); } void Window::EnableClose(bool enable) { - non_client_view_->EnableClose(enable); + non_client_view()->EnableClose(enable); native_window_->EnableClose(enable); } void Window::UpdateWindowTitle() { // If the non-client view is rendering its own title, it'll need to relayout // now. - non_client_view_->Layout(); + non_client_view()->Layout(); // Update the native frame's text. We do this regardless of whether or not // the native frame is being used, since this also updates the taskbar, etc. string16 window_title; - if (native_window_->AsNativeWidget()->IsScreenReaderActive()) - window_title = WideToUTF16(window_delegate_->GetAccessibleWindowTitle()); - else - window_title = WideToUTF16(window_delegate_->GetWindowTitle()); + if (native_window_->AsNativeWidget()->IsScreenReaderActive()) { + window_title = WideToUTF16(widget_delegate()->GetAccessibleWindowTitle()); + } else { + window_title = WideToUTF16(widget_delegate()->GetWindowTitle()); + } base::i18n::AdjustStringForLocaleDirection(&window_title); native_window_->AsNativeWidget()->SetWindowTitle(UTF16ToWide(window_title)); } void Window::UpdateWindowIcon() { - non_client_view_->UpdateWindowIcon(); + non_client_view()->UpdateWindowIcon(); native_window_->AsNativeWidget()->SetWindowIcons( - window_delegate_->GetWindowIcon(), - window_delegate_->GetWindowAppIcon()); -} - -NonClientFrameView* Window::CreateFrameViewForWindow() { - NonClientFrameView* frame_view = native_window_->CreateFrameViewForWindow(); - return frame_view ? frame_view : new CustomFrameView(this); -} - -void Window::UpdateFrameAfterFrameChange() { - native_window_->UpdateFrameAfterFrameChange(); -} - -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(); + widget_delegate()->GetWindowIcon(), + widget_delegate()->GetWindowAppIcon()); } //////////////////////////////////////////////////////////////////////////////// @@ -194,7 +155,7 @@ void Window::Close() { return; } - if (non_client_view_->CanClose()) { + if (non_client_view()->CanClose()) { SaveWindowPosition(); Widget::Close(); window_closed_ = true; @@ -205,7 +166,7 @@ void Window::Close() { // Window, internal::NativeWindowDelegate implementation: bool Window::CanActivate() const { - return window_delegate_->CanActivate(); + return widget_delegate()->CanActivate(); } bool Window::IsInactiveRenderingDisabled() const { @@ -214,43 +175,44 @@ bool Window::IsInactiveRenderingDisabled() const { void Window::EnableInactiveRendering() { disable_inactive_rendering_ = false; - non_client_view_->DisableInactiveRendering(false); + non_client_view()->DisableInactiveRendering(false); } bool Window::IsModal() const { - return window_delegate_->IsModal(); + return widget_delegate()->IsModal(); } bool Window::IsDialogBox() const { - return !!window_delegate_->AsDialogDelegate(); + return !!widget_delegate()->AsDialogDelegate(); } -gfx::Size Window::GetMinimumSize() const { - return non_client_view_->GetMinimumSize(); +gfx::Size Window::GetMinimumSize() { + return non_client_view()->GetMinimumSize(); } -int Window::GetNonClientComponent(const gfx::Point& point) const { - return non_client_view_->NonClientHitTest(point); +int Window::GetNonClientComponent(const gfx::Point& point) { + return non_client_view()->NonClientHitTest(point); } bool Window::ExecuteCommand(int command_id) { - return window_delegate_->ExecuteWindowsCommand(command_id); + return widget_delegate()->ExecuteWindowsCommand(command_id); } void Window::OnNativeWindowCreated(const gfx::Rect& bounds) { - if (window_delegate_->IsModal()) + if (widget_delegate()->IsModal()) native_window_->BecomeModal(); // Create the ClientView, add it to the NonClientView and add the // NonClientView to the RootView. This will cause everything to be parented. - non_client_view_->set_client_view(window_delegate_->CreateClientView(this)); - SetContentsView(non_client_view_); + non_client_view()->set_client_view( + widget_delegate()->CreateClientView(this)); + SetContentsView(non_client_view()); UpdateWindowTitle(); native_window_->AsNativeWidget()->SetAccessibleRole( - window_delegate_->GetAccessibleWindowRole()); + widget_delegate()->GetAccessibleWindowRole()); native_window_->AsNativeWidget()->SetAccessibleState( - window_delegate_->GetAccessibleWindowState()); + widget_delegate()->GetAccessibleWindowState()); SetInitialBounds(bounds); } @@ -258,25 +220,20 @@ void Window::OnNativeWindowCreated(const gfx::Rect& bounds) { void Window::OnNativeWindowActivationChanged(bool active) { if (!active) SaveWindowPosition(); - window_delegate_->OnWindowActivationChanged(active); + widget_delegate()->OnWindowActivationChanged(active); } void Window::OnNativeWindowBeginUserBoundsChange() { - window_delegate_->OnWindowBeginUserBoundsChange(); + widget_delegate()->OnWindowBeginUserBoundsChange(); } void Window::OnNativeWindowEndUserBoundsChange() { - window_delegate_->OnWindowEndUserBoundsChange(); + widget_delegate()->OnWindowEndUserBoundsChange(); } void Window::OnNativeWindowDestroying() { - non_client_view_->WindowClosing(); - window_delegate_->WindowClosing(); -} - -void Window::OnNativeWindowDestroyed() { - window_delegate_->DeleteDelegate(); - window_delegate_ = NULL; + non_client_view()->WindowClosing(); + widget_delegate()->WindowClosing(); } void Window::OnNativeWindowBoundsChanged() { @@ -301,13 +258,14 @@ void Window::SetInitialBounds(const gfx::Rect& bounds) { // state will have been lost. Sadly there's no way to tell on Windows when // a window is restored from maximized state, so we can't more accurately // track maximized state independently of sizing information. - window_delegate_->GetSavedMaximizedState(&saved_maximized_state_); + widget_delegate()->GetSavedMaximizedState( + &saved_maximized_state_); // Restore the window's placement from the controller. gfx::Rect saved_bounds = bounds; - if (window_delegate_->GetSavedWindowBounds(&saved_bounds)) { - if (!window_delegate_->ShouldRestoreWindowSize()) { - saved_bounds.set_size(non_client_view_->GetPreferredSize()); + if (widget_delegate()->GetSavedWindowBounds(&saved_bounds)) { + if (!widget_delegate()->ShouldRestoreWindowSize()) { + saved_bounds.set_size(non_client_view()->GetPreferredSize()); } else { // Make sure the bounds are at least the minimum size. if (saved_bounds.width() < minimum_size_.width()) { @@ -333,7 +291,7 @@ void Window::SetInitialBounds(const gfx::Rect& bounds) { // No initial bounds supplied, so size the window to its content and // center over its parent. native_window_->AsNativeWidget()->CenterWindow( - non_client_view_->GetPreferredSize()); + non_client_view()->GetPreferredSize()); } else { // Use the supplied initial bounds. SetBoundsConstrained(bounds, NULL); @@ -346,7 +304,7 @@ void Window::SaveWindowPosition() { // by go/crash) that in some circumstances we can end up here after // WM_DESTROY, at which point the window delegate is likely gone. So just // bail. - if (!window_delegate_) + if (!widget_delegate()) return; bool maximized; @@ -354,7 +312,7 @@ void Window::SaveWindowPosition() { native_window_->AsNativeWidget()->GetWindowBoundsAndMaximizedState( &bounds, &maximized); - window_delegate_->SaveWindowPlacement(bounds, maximized); + widget_delegate()->SaveWindowPlacement(bounds, maximized); } } // namespace views diff --git a/views/window/window.h b/views/window/window.h index 98fc322..d659686 100644 --- a/views/window/window.h +++ b/views/window/window.h @@ -8,9 +8,7 @@ #include "ui/gfx/native_widget_types.h" #include "views/widget/widget.h" -#include "views/window/client_view.h" #include "views/window/native_window_delegate.h" -#include "views/window/non_client_view.h" namespace gfx { class Font; @@ -21,7 +19,6 @@ class Size; namespace views { class NativeWindow; -class NonClientFrameView; class Widget; class WindowDelegate; @@ -43,12 +40,6 @@ 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(); @@ -98,25 +89,6 @@ class Window : public Widget, // Tell the window to update its icon from the delegate. void UpdateWindowIcon(); - // Creates an appropriate NonClientFrameView for this window. - virtual NonClientFrameView* CreateFrameViewForWindow(); - - // Updates the frame after an event caused it to be changed. - virtual void UpdateFrameAfterFrameChange(); - - 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(); - // Overridden from Widget: virtual void Show() OVERRIDE; virtual void Close() OVERRIDE; @@ -126,23 +98,7 @@ class Window : public Widget, const_cast<const Window*>(this)->window_delegate()); } const WindowDelegate* window_delegate() const { - return window_delegate_; - } - - NonClientView* non_client_view() { - return const_cast<NonClientView*>( - const_cast<const Window*>(this)->non_client_view()); - } - const NonClientView* non_client_view() const { - return non_client_view_; - } - - ClientView* client_view() { - return const_cast<ClientView*>( - const_cast<const Window*>(this)->client_view()); - } - const ClientView* client_view() const { - return non_client_view()->client_view(); + return reinterpret_cast<WindowDelegate*>(widget_delegate()); } NativeWindow* native_window() { return native_window_; } @@ -154,15 +110,14 @@ class Window : public Widget, virtual void EnableInactiveRendering() OVERRIDE; virtual bool IsModal() const OVERRIDE; virtual bool IsDialogBox() const OVERRIDE; - virtual gfx::Size GetMinimumSize() const OVERRIDE; - virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE; + virtual gfx::Size GetMinimumSize() OVERRIDE; + virtual int GetNonClientComponent(const gfx::Point& point) OVERRIDE; virtual bool ExecuteCommand(int command_id) OVERRIDE; virtual void OnNativeWindowCreated(const gfx::Rect& bounds) OVERRIDE; virtual void OnNativeWindowActivationChanged(bool active) OVERRIDE; virtual void OnNativeWindowBeginUserBoundsChange() OVERRIDE; virtual void OnNativeWindowEndUserBoundsChange() OVERRIDE; virtual void OnNativeWindowDestroying() OVERRIDE; - virtual void OnNativeWindowDestroyed() OVERRIDE; virtual void OnNativeWindowBoundsChanged() OVERRIDE; virtual Window* AsWindow() OVERRIDE; virtual internal::NativeWidgetDelegate* AsNativeWidgetDelegate() OVERRIDE; @@ -177,15 +132,6 @@ class Window : public Widget, NativeWindow* native_window_; - // Our window delegate (see InitWindow() method for documentation). - WindowDelegate* window_delegate_; - - // The View that provides the non-client area of the window (title bar, - // window controls, sizing borders etc). To use an implementation other than - // the default, this class must be sub-classed and this value set to the - // desired implementation before calling |InitWindow()|. - NonClientView* non_client_view_; - // The saved maximized state for this window. See note in SetInitialBounds // that explains why we save this. bool saved_maximized_state_; @@ -200,10 +146,6 @@ 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); }; |