summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-02 22:07:05 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-02 22:07:05 +0000
commit14bcec307d7ec6b13e90fe5e5ac8ca5aaa397b4b (patch)
tree7c88cf92588f0d99a38757f52cc92b47f7e053ef /views
parent6b8b0f08cfebb37c13f6c835c37d9ed9e982fc37 (diff)
downloadchromium_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')
-rw-r--r--views/widget/native_widget.h8
-rw-r--r--views/widget/native_widget_delegate.h3
-rw-r--r--views/widget/native_widget_gtk.cc22
-rw-r--r--views/widget/native_widget_gtk.h4
-rw-r--r--views/widget/native_widget_views.cc15
-rw-r--r--views/widget/native_widget_views.h4
-rw-r--r--views/widget/native_widget_win.cc107
-rw-r--r--views/widget/native_widget_win.h9
-rw-r--r--views/widget/widget.cc67
-rw-r--r--views/widget/widget.h60
-rw-r--r--views/widget/widget_delegate.cc4
-rw-r--r--views/widget/widget_delegate.h5
-rw-r--r--views/window/custom_frame_view.cc16
-rw-r--r--views/window/custom_frame_view.h6
-rw-r--r--views/window/native_frame_view.cc8
-rw-r--r--views/window/native_frame_view.h6
-rw-r--r--views/window/native_window.h8
-rw-r--r--views/window/native_window_delegate.h7
-rw-r--r--views/window/native_window_gtk.cc26
-rw-r--r--views/window/native_window_gtk.h5
-rw-r--r--views/window/native_window_views.cc15
-rw-r--r--views/window/native_window_views.h4
-rw-r--r--views/window/native_window_win.cc104
-rw-r--r--views/window/native_window_win.h10
-rw-r--r--views/window/non_client_view.cc12
-rw-r--r--views/window/non_client_view.h5
-rw-r--r--views/window/window.cc128
-rw-r--r--views/window/window.h64
28 files changed, 379 insertions, 353 deletions
diff --git a/views/widget/native_widget.h b/views/widget/native_widget.h
index f3faba0..6cb4147 100644
--- a/views/widget/native_widget.h
+++ b/views/widget/native_widget.h
@@ -66,6 +66,14 @@ class NativeWidget {
// Initializes the NativeWidget.
virtual void InitNativeWidget(const Widget::InitParams& params) = 0;
+ // Returns a NonClientFrameView for the widget's NonClientView, or NULL if
+ // the NativeWidget wants no special NonClientFrameView.
+ virtual NonClientFrameView* CreateNonClientFrameView() = 0;
+
+ virtual void UpdateFrameAfterFrameChange() = 0;
+ virtual bool ShouldUseNativeFrame() const = 0;
+ virtual void FrameTypeChanged() = 0;
+
// Returns the Widget associated with this NativeWidget. This function is
// guaranteed to return non-NULL for the lifetime of the NativeWidget.
virtual Widget* GetWidget() = 0;
diff --git a/views/widget/native_widget_delegate.h b/views/widget/native_widget_delegate.h
index 05af457..d39bd58 100644
--- a/views/widget/native_widget_delegate.h
+++ b/views/widget/native_widget_delegate.h
@@ -31,6 +31,9 @@ class NativeWidgetDelegate {
// Called when the native widget is created.
virtual void OnNativeWidgetCreated() = 0;
+ // Called just after the native widget is destroyed.
+ virtual void OnNativeWidgetDestroyed() = 0;
+
// Called when the NativeWidget changed size to |new_size|.
virtual void OnSizeChanged(const gfx::Size& new_size) = 0;
diff --git a/views/widget/native_widget_gtk.cc b/views/widget/native_widget_gtk.cc
index c5f926c..392abe8 100644
--- a/views/widget/native_widget_gtk.cc
+++ b/views/widget/native_widget_gtk.cc
@@ -736,6 +736,27 @@ void NativeWidgetGtk::InitNativeWidget(const Widget::InitParams& params) {
}
}
+NonClientFrameView* NativeWidgetGtk::CreateNonClientFrameView() {
+ return NULL;
+}
+
+void NativeWidgetGtk::UpdateFrameAfterFrameChange() {
+ // We currently don't support different frame types on Gtk, so we don't
+ // need to implement this.
+ NOTIMPLEMENTED();
+}
+
+bool NativeWidgetGtk::ShouldUseNativeFrame() const {
+ return false;
+}
+
+void NativeWidgetGtk::FrameTypeChanged() {
+ // This is called when the Theme has changed, so forward the event to the root
+ // widget.
+ GetWidget()->ThemeChanged();
+ GetWidget()->GetRootView()->SchedulePaint();
+}
+
Widget* NativeWidgetGtk::GetWidget() {
return delegate_->AsWidget();
}
@@ -1435,6 +1456,7 @@ void NativeWidgetGtk::OnDestroy(GtkWidget* object) {
}
void NativeWidgetGtk::OnDestroyed(GObject *where_the_object_was) {
+ delegate_->OnNativeWidgetDestroyed();
if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
delete this;
}
diff --git a/views/widget/native_widget_gtk.h b/views/widget/native_widget_gtk.h
index e6a9951..2603298 100644
--- a/views/widget/native_widget_gtk.h
+++ b/views/widget/native_widget_gtk.h
@@ -148,6 +148,10 @@ class NativeWidgetGtk : public NativeWidget,
// Overridden from NativeWidget:
virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
+ virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
+ virtual void UpdateFrameAfterFrameChange() OVERRIDE;
+ virtual bool ShouldUseNativeFrame() const OVERRIDE;
+ virtual void FrameTypeChanged() OVERRIDE;
virtual Widget* GetWidget() OVERRIDE;
virtual const Widget* GetWidget() const OVERRIDE;
virtual gfx::NativeView GetNativeView() const OVERRIDE;
diff --git a/views/widget/native_widget_views.cc b/views/widget/native_widget_views.cc
index 9f26791..d0eebe4 100644
--- a/views/widget/native_widget_views.cc
+++ b/views/widget/native_widget_views.cc
@@ -48,6 +48,21 @@ void NativeWidgetViews::InitNativeWidget(const Widget::InitParams& params) {
// TODO(beng): SetInitParams().
}
+NonClientFrameView* NativeWidgetViews::CreateNonClientFrameView() {
+ return NULL;
+}
+
+void NativeWidgetViews::UpdateFrameAfterFrameChange() {
+}
+
+bool NativeWidgetViews::ShouldUseNativeFrame() const {
+ NOTIMPLEMENTED();
+ return false;
+}
+
+void NativeWidgetViews::FrameTypeChanged() {
+}
+
Widget* NativeWidgetViews::GetWidget() {
return delegate_->AsWidget();
}
diff --git a/views/widget/native_widget_views.h b/views/widget/native_widget_views.h
index 96bdc9a..f6d445d 100644
--- a/views/widget/native_widget_views.h
+++ b/views/widget/native_widget_views.h
@@ -35,6 +35,10 @@ class NativeWidgetViews : public NativeWidget {
protected:
// Overridden from NativeWidget:
virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
+ virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
+ virtual void UpdateFrameAfterFrameChange() OVERRIDE;
+ virtual bool ShouldUseNativeFrame() const OVERRIDE;
+ virtual void FrameTypeChanged() OVERRIDE;
virtual Widget* GetWidget() OVERRIDE;
virtual const Widget* GetWidget() const OVERRIDE;
virtual gfx::NativeView GetNativeView() const OVERRIDE;
diff --git a/views/widget/native_widget_win.cc b/views/widget/native_widget_win.cc
index 1afb3e5..db9f73a 100644
--- a/views/widget/native_widget_win.cc
+++ b/views/widget/native_widget_win.cc
@@ -37,6 +37,7 @@
#include "views/widget/native_widget_delegate.h"
#include "views/widget/root_view.h"
#include "views/widget/widget_delegate.h"
+#include "views/window/native_frame_view.h"
#include "views/window/native_window_win.h"
#pragma comment(lib, "dwmapi.lib")
@@ -167,6 +168,21 @@ void SetChildBounds(HWND child_window,
actual_bounds.height(), flags);
}
+// 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;
+}
+
+// Tells the window its frame (non-client area) has changed.
+void SendFrameChanged(HWND window) {
+ SetWindowPos(window, NULL, 0, 0, 0, 0,
+ SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOCOPYBITS |
+ SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOREPOSITION |
+ SWP_NOSENDCHANGING | SWP_NOSIZE | SWP_NOZORDER);
+}
+
// Links the HWND to its NativeWidget.
const char* const kNativeWidgetKey = "__VIEWS_NATIVE_WIDGET__";
@@ -275,6 +291,49 @@ void NativeWidgetWin::InitNativeWidget(const Widget::InitParams& params) {
WindowImpl::Init(parent, params.bounds);
}
+NonClientFrameView* NativeWidgetWin::CreateNonClientFrameView() {
+ return GetWidget()->ShouldUseNativeFrame() ?
+ new NativeFrameView(GetWidget()) : NULL;
+}
+
+void NativeWidgetWin::UpdateFrameAfterFrameChange() {
+ // We've either gained or lost a custom window region, so reset it now.
+ ResetWindowRegion(true);
+}
+
+bool NativeWidgetWin::ShouldUseNativeFrame() const {
+ return IsAeroGlassEnabled();
+}
+
+void NativeWidgetWin::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 = GetWidget()->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.
+ GetWidget()->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);
+}
+
Widget* NativeWidgetWin::GetWidget() {
return delegate_->AsWidget();
}
@@ -1241,7 +1300,9 @@ void NativeWidgetWin::OnSettingChange(UINT flags, const wchar_t* section) {
}
void NativeWidgetWin::OnSize(UINT param, const CSize& size) {
- SetMsgHandled(FALSE);
+ // 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 NativeWidgetWin::OnSysCommand(UINT notification_code, CPoint click) {
@@ -1275,6 +1336,7 @@ void NativeWidgetWin::OnWindowPosChanged(WINDOWPOS* window_pos) {
}
void NativeWidgetWin::OnFinalMessage(HWND window) {
+ delegate_->OnNativeWidgetDestroyed();
if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
delete this;
}
@@ -1478,6 +1540,49 @@ void NativeWidgetWin::ClientAreaSizeChanged() {
}
}
+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()) {
+ 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);
+}
+
gfx::AcceleratedWidget NativeWidgetWin::GetAcceleratedWidget() {
#if defined(VIEWS_COMPOSITOR)
return hwnd();
diff --git a/views/widget/native_widget_win.h b/views/widget/native_widget_win.h
index 40f4c84..7dd4995 100644
--- a/views/widget/native_widget_win.h
+++ b/views/widget/native_widget_win.h
@@ -176,6 +176,10 @@ class NativeWidgetWin : public ui::WindowImpl,
// Overridden from NativeWidget:
virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
+ virtual NonClientFrameView* CreateNonClientFrameView() OVERRIDE;
+ virtual void UpdateFrameAfterFrameChange() OVERRIDE;
+ virtual bool ShouldUseNativeFrame() const OVERRIDE;
+ virtual void FrameTypeChanged() OVERRIDE;
virtual Widget* GetWidget() OVERRIDE;
virtual const Widget* GetWidget() const OVERRIDE;
virtual gfx::NativeView GetNativeView() const OVERRIDE;
@@ -475,6 +479,11 @@ class 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);
+
// Overridden from NativeWidget.
virtual gfx::AcceleratedWidget GetAcceleratedWidget() OVERRIDE;
diff --git a/views/widget/widget.cc b/views/widget/widget.cc
index bc84fb0..e2b2202 100644
--- a/views/widget/widget.cc
+++ b/views/widget/widget.cc
@@ -14,6 +14,7 @@
#include "views/widget/root_view.h"
#include "views/widget/native_widget.h"
#include "views/widget/widget_delegate.h"
+#include "views/window/custom_frame_view.h"
namespace views {
@@ -22,6 +23,22 @@ namespace {
bool use_pure_views = false;
}
+// A default implementation of WidgetDelegate, used by Widget when no
+// WidgetDelegate is supplied.
+class DefaultWidgetDelegate : public WidgetDelegate {
+ public:
+ DefaultWidgetDelegate() {}
+ virtual ~DefaultWidgetDelegate() {}
+
+ // Overridden from WidgetDelegate:
+ virtual void DeleteDelegate() OVERRIDE {
+ delete this;
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(DefaultWidgetDelegate);
+};
+
////////////////////////////////////////////////////////////////////////////////
// Widget, InitParams:
@@ -73,10 +90,13 @@ Widget::Widget()
: is_mouse_button_pressed_(false),
last_mouse_event_was_move_(false),
native_widget_(NULL),
+ type_(InitParams::TYPE_WINDOW),
widget_delegate_(NULL),
+ non_client_view_(NULL),
dragged_view_(NULL),
ownership_(InitParams::NATIVE_WIDGET_OWNS_WIDGET),
- is_secondary_widget_(true) {
+ is_secondary_widget_(true),
+ frame_type_(FRAME_TYPE_DEFAULT) {
}
Widget::~Widget() {
@@ -104,7 +124,9 @@ Widget* Widget::GetWidgetForNativeView(gfx::NativeView native_view) {
}
void Widget::Init(const InitParams& params) {
- widget_delegate_ = params.delegate ? params.delegate : new WidgetDelegate;
+ type_ = params.type;
+ widget_delegate_ =
+ params.delegate ? params.delegate : new DefaultWidgetDelegate;
ownership_ = params.ownership;
native_widget_ =
params.native_widget ? params.native_widget
@@ -114,6 +136,10 @@ void Widget::Init(const InitParams& params) {
if (params.type == InitParams::TYPE_MENU)
is_mouse_button_pressed_ = native_widget_->IsMouseButtonDown();
native_widget_->InitNativeWidget(params);
+ if (type_ == InitParams::TYPE_WINDOW) {
+ non_client_view_ = new NonClientView;
+ non_client_view_->SetFrameView(CreateNonClientFrameView());
+ }
}
// Unconverted methods (see header) --------------------------------------------
@@ -381,6 +407,38 @@ void Widget::SetFocusTraversableParentView(View* parent_view) {
root_view_->SetFocusTraversableParentView(parent_view);
}
+void Widget::UpdateFrameAfterFrameChange() {
+ native_widget_->UpdateFrameAfterFrameChange();
+}
+
+NonClientFrameView* Widget::CreateNonClientFrameView() {
+ NonClientFrameView* frame_view = widget_delegate_->CreateNonClientFrameView();
+ if (!frame_view)
+ frame_view = native_widget_->CreateNonClientFrameView();
+ return frame_view ? frame_view : new CustomFrameView(this);
+}
+
+bool Widget::ShouldUseNativeFrame() const {
+ if (frame_type_ != FRAME_TYPE_DEFAULT)
+ return frame_type_ == FRAME_TYPE_FORCE_NATIVE;
+ return native_widget_->ShouldUseNativeFrame();
+}
+
+void Widget::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 Widget::FrameTypeChanged() {
+ native_widget_->FrameTypeChanged();
+}
+
void Widget::NotifyAccessibilityEvent(
View* view,
ui::AccessibilityTypes::Event event_type,
@@ -417,6 +475,11 @@ void Widget::OnNativeWidgetCreated() {
EnsureCompositor();
}
+void Widget::OnNativeWidgetDestroyed() {
+ widget_delegate_->DeleteDelegate();
+ widget_delegate_ = NULL;
+}
+
void Widget::OnSizeChanged(const gfx::Size& new_size) {
root_view_->SetSize(new_size);
}
diff --git a/views/widget/widget.h b/views/widget/widget.h
index 912cc76..19952eb 100644
--- a/views/widget/widget.h
+++ b/views/widget/widget.h
@@ -15,6 +15,8 @@
#include "ui/gfx/rect.h"
#include "views/focus/focus_manager.h"
#include "views/widget/native_widget_delegate.h"
+#include "views/window/client_view.h"
+#include "views/window/non_client_view.h"
#if defined(OS_WIN)
// Windows headers define macros for these function names which screw with us.
@@ -46,6 +48,7 @@ namespace views {
class DefaultThemeProvider;
class InputMethod;
class NativeWidget;
+class NonClientFrameView;
class TooltipManager;
class View;
class WidgetDelegate;
@@ -82,6 +85,12 @@ class RootView;
class Widget : public internal::NativeWidgetDelegate,
public FocusTraversable {
public:
+ 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.
+ };
+
struct InitParams {
enum Type {
TYPE_WINDOW, // A Window, like a frame window.
@@ -354,6 +363,44 @@ class Widget : public internal::NativeWidgetDelegate,
void SetFocusTraversableParent(FocusTraversable* parent);
void SetFocusTraversableParentView(View* parent_view);
+ // 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_; }
+
+ // Creates an appropriate NonClientFrameView for this widget. The
+ // WidgetDelegate is given the first opportunity to create one, followed by
+ // the NativeWidget implementation. If both return NULL, a default one is
+ // created.
+ virtual NonClientFrameView* CreateNonClientFrameView();
+
+ // 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();
+
+ NonClientView* non_client_view() {
+ return const_cast<NonClientView*>(
+ const_cast<const Widget*>(this)->non_client_view());
+ }
+ const NonClientView* non_client_view() const {
+ return non_client_view_;
+ }
+
+ ClientView* client_view() {
+ return const_cast<ClientView*>(
+ const_cast<const Widget*>(this)->client_view());
+ }
+ const ClientView* client_view() const {
+ return non_client_view()->client_view();
+ }
+
const ui::Compositor* compositor() const { return compositor_.get(); }
ui::Compositor* compositor() { return compositor_.get(); }
@@ -375,6 +422,7 @@ class Widget : public internal::NativeWidgetDelegate,
virtual void OnNativeFocus(gfx::NativeView focused_view) OVERRIDE;
virtual void OnNativeBlur(gfx::NativeView focused_view) OVERRIDE;
virtual void OnNativeWidgetCreated() OVERRIDE;
+ virtual void OnNativeWidgetDestroyed() OVERRIDE;
virtual void OnSizeChanged(const gfx::Size& new_size) OVERRIDE;
virtual bool HasFocusManager() const OVERRIDE;
virtual bool OnNativeWidgetPaintAccelerated(
@@ -430,6 +478,8 @@ class Widget : public internal::NativeWidgetDelegate,
NativeWidget* native_widget_;
+ InitParams::Type type_;
+
// Non-owned pointer to the Widget's delegate. May be NULL if no delegate is
// being used.
WidgetDelegate* widget_delegate_;
@@ -439,6 +489,12 @@ class Widget : public internal::NativeWidgetDelegate,
// this and tooltip_manager_.
scoped_ptr<internal::RootView> root_view_;
+ // 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 focus manager keeping track of focus for this Widget and any of its
// children. NULL for non top-level widgets.
// WARNING: RootView's destructor calls into the FocusManager. As such, this
@@ -461,6 +517,10 @@ class Widget : public internal::NativeWidgetDelegate,
// See set_is_secondary_widget().
bool is_secondary_widget_;
+ // The current frame type in use by this window. Defaults to
+ // FRAME_TYPE_DEFAULT.
+ FrameType frame_type_;
+
DISALLOW_COPY_AND_ASSIGN(Widget);
};
diff --git a/views/widget/widget_delegate.cc b/views/widget/widget_delegate.cc
index 5e86035..fa91e7b 100644
--- a/views/widget/widget_delegate.cc
+++ b/views/widget/widget_delegate.cc
@@ -140,5 +140,9 @@ ClientView* WidgetDelegate::CreateClientView(Window* window) {
return new ClientView(window, GetContentsView());
}
+NonClientFrameView* WidgetDelegate::CreateNonClientFrameView() {
+ return NULL;
+}
+
} // namespace views
diff --git a/views/widget/widget_delegate.h b/views/widget/widget_delegate.h
index a6aab4e..dac0253 100644
--- a/views/widget/widget_delegate.h
+++ b/views/widget/widget_delegate.h
@@ -20,6 +20,7 @@ class Rect;
namespace views {
class ClientView;
class DialogDelegate;
+class NonClientFrameView;
class View;
class Window;
@@ -139,6 +140,10 @@ class WidgetDelegate {
// of the window.
virtual ClientView* CreateClientView(Window* window);
+ // Called by the Widget to create the NonClient Frame View for this widget.
+ // Return NULL to use the default one.
+ virtual NonClientFrameView* CreateNonClientFrameView();
+
Window* window() const { return window_; }
protected:
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);
};