summaryrefslogtreecommitdiffstats
path: root/views/window
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-28 20:09:45 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-28 20:09:45 +0000
commit7d71ca7449a9a153b473d168952a10bf149981f7 (patch)
tree4795f3d2b4f8038ffe5fb7101e82c280b5fd83ea /views/window
parent8627b931067a72a20aeb31473d9f4348b7d78528 (diff)
downloadchromium_src-7d71ca7449a9a153b473d168952a10bf149981f7.zip
chromium_src-7d71ca7449a9a153b473d168952a10bf149981f7.tar.gz
chromium_src-7d71ca7449a9a153b473d168952a10bf149981f7.tar.bz2
Create InitParams for Window.
http://crbug.com/72040 TEST=none Review URL: http://codereview.chromium.org/6902049 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83384 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/window')
-rw-r--r--views/window/custom_frame_view.cc3
-rw-r--r--views/window/native_window.h3
-rw-r--r--views/window/window.cc39
-rw-r--r--views/window/window.h19
-rw-r--r--views/window/window_gtk.cc62
-rw-r--r--views/window/window_gtk.h9
-rw-r--r--views/window/window_win.cc29
-rw-r--r--views/window/window_win.h4
8 files changed, 92 insertions, 76 deletions
diff --git a/views/window/custom_frame_view.cc b/views/window/custom_frame_view.cc
index 97e7f21..e86cd10 100644
--- a/views/window/custom_frame_view.cc
+++ b/views/window/custom_frame_view.cc
@@ -64,8 +64,7 @@ const int kTitleCaptionSpacing = 5;
// CustomFrameView, public:
CustomFrameView::CustomFrameView(Window* frame)
- : NonClientFrameView(),
- ALLOW_THIS_IN_INITIALIZER_LIST(close_button_(new ImageButton(this))),
+ : 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))),
ALLOW_THIS_IN_INITIALIZER_LIST(minimize_button_(new ImageButton(this))),
diff --git a/views/window/native_window.h b/views/window/native_window.h
index 682dd94..63da12a 100644
--- a/views/window/native_window.h
+++ b/views/window/native_window.h
@@ -8,6 +8,7 @@
#include "ui/base/accessibility/accessibility_types.h"
#include "ui/gfx/native_widget_types.h"
+#include "views/window/window.h"
class SkBitmap;
@@ -36,6 +37,8 @@ class NativeWindow {
virtual ~NativeWindow() {}
+ static Window* CreateNativeWindow();
+
virtual Window* GetWindow() = 0;
virtual NativeWidget* AsNativeWidget() = 0;
diff --git a/views/window/window.cc b/views/window/window.cc
index c10e569..ae9e155 100644
--- a/views/window/window.cc
+++ b/views/window/window.cc
@@ -22,24 +22,40 @@ namespace views {
////////////////////////////////////////////////////////////////////////////////
// Window, public:
-Window::Window(WindowDelegate* window_delegate)
+Window::InitParams::InitParams(WindowDelegate* window_delegate)
+ : window_delegate(window_delegate),
+ parent_window(NULL),
+ native_window(NULL),
+ widget_init_params(Widget::InitParams::TYPE_WINDOW) {
+}
+
+Window::Window()
: native_window_(NULL),
- window_delegate_(window_delegate),
+ 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) {
- DCHECK(window_delegate_);
- DCHECK(!window_delegate_->window_);
- window_delegate_->window_ = this;
}
Window::~Window() {
}
// static
+Window* Window::CreateChromeWindow(gfx::NativeWindow parent,
+ const gfx::Rect& bounds,
+ WindowDelegate* window_delegate) {
+ Window* window = NativeWindow::CreateNativeWindow();
+ Window::InitParams params(window_delegate);
+ params.parent_window = parent;
+ params.widget_init_params.bounds = bounds;
+ window->InitWindow(params);
+ return window;
+}
+
+// static
int Window::GetLocalizedContentsWidth(int col_resource_id) {
return ui::GetLocalizedContentsWidthForFont(col_resource_id,
ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont));
@@ -75,6 +91,17 @@ void Window::CloseSecondaryWidget(Widget* widget) {
}
}
+void Window::InitWindow(const InitParams& params) {
+ window_delegate_ = params.window_delegate;
+ AsWidget()->set_widget_delegate(window_delegate_);
+ DCHECK(window_delegate_);
+ DCHECK(!window_delegate_->window_);
+ window_delegate_->window_ = this;
+ non_client_view()->SetFrameView(CreateFrameViewForWindow());
+ AsWidget()->Init(params.widget_init_params);
+ OnNativeWindowCreated(params.widget_init_params.bounds);
+}
+
gfx::Rect Window::GetBounds() const {
// TODO(beng): Clean this up once Window subclasses Widget.
return native_window_->AsNativeWidget()->GetWidget()->GetWindowScreenBounds();
@@ -245,8 +272,6 @@ const Widget* Window::AsWidget() const {
void Window::SetNativeWindow(NativeWindow* native_window) {
native_window_ = native_window;
- native_window->AsNativeWidget()->GetWidget()->set_widget_delegate(
- window_delegate_);
}
////////////////////////////////////////////////////////////////////////////////
diff --git a/views/window/window.h b/views/window/window.h
index ebda6f7..76fdb76 100644
--- a/views/window/window.h
+++ b/views/window/window.h
@@ -7,6 +7,7 @@
#pragma once
#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"
@@ -40,7 +41,17 @@ class WindowDelegate;
//
class Window : public internal::NativeWindowDelegate {
public:
- explicit Window(WindowDelegate* window_delegate);
+ struct InitParams {
+ // |window_delegate| cannot be NULL.
+ explicit InitParams(WindowDelegate* window_delegate);
+
+ WindowDelegate* window_delegate;
+ gfx::NativeWindow parent_window;
+ NativeWindow* native_window;
+ Widget::InitParams widget_init_params;
+ };
+
+ Window();
virtual ~Window();
// Creates an instance of an object implementing this interface.
@@ -70,6 +81,10 @@ class Window : public internal::NativeWindowDelegate {
// Does nothing if |widget| is null.
static void CloseSecondaryWidget(Widget* widget);
+ // Initializes the window. Must be called before any post-configuration
+ // operations are performed.
+ void InitWindow(const InitParams& params);
+
// Retrieves the window's bounds, including its frame.
gfx::Rect GetBounds() const;
@@ -221,8 +236,6 @@ class Window : public internal::NativeWindowDelegate {
virtual void OnNativeWindowBoundsChanged() OVERRIDE;
private:
- Window();
-
// Sizes and positions the window just after it is created.
void SetInitialBounds(const gfx::Rect& bounds);
diff --git a/views/window/window_gtk.cc b/views/window/window_gtk.cc
index d7c2187..1fee254a 100644
--- a/views/window/window_gtk.cc
+++ b/views/window/window_gtk.cc
@@ -79,17 +79,15 @@ GdkCursorType HitTestCodeToGdkCursorType(int hittest_code) {
namespace views {
-WindowGtk::~WindowGtk() {
+WindowGtk::WindowGtk()
+ : ALLOW_THIS_IN_INITIALIZER_LIST(delegate_(this)),
+ window_state_(GDK_WINDOW_STATE_WITHDRAWN),
+ window_closed_(false) {
+ SetNativeWindow(this);
+ is_window_ = true;
}
-// static
-Window* Window::CreateChromeWindow(gfx::NativeWindow parent,
- const gfx::Rect& bounds,
- WindowDelegate* window_delegate) {
- WindowGtk* window = new WindowGtk(window_delegate);
- window->non_client_view()->SetFrameView(window->CreateFrameViewForWindow());
- window->InitWindow(parent, bounds);
- return window;
+WindowGtk::~WindowGtk() {
}
// static
@@ -222,6 +220,17 @@ void WindowGtk::IsActiveChanged() {
delegate_->OnNativeWindowActivationChanged(IsActive());
}
+void WindowGtk::InitNativeWidget(const Widget::InitParams& params) {
+ if (params.parent)
+ make_transient_to_parent();
+
+ WidgetGtk::InitNativeWidget(params);
+
+ g_signal_connect(G_OBJECT(GetNativeWindow()), "configure-event",
+ G_CALLBACK(CallConfigureEvent), this);
+ g_signal_connect(G_OBJECT(GetNativeWindow()), "window-state-event",
+ G_CALLBACK(CallWindowStateEvent), this);
+}
////////////////////////////////////////////////////////////////////////////////
// WindowGtk, NativeWindow implementation:
@@ -405,33 +414,6 @@ void WindowGtk::FrameTypeChanged() {
}
////////////////////////////////////////////////////////////////////////////////
-// WindowGtk, protected:
-
-WindowGtk::WindowGtk(WindowDelegate* window_delegate)
- : Window(window_delegate),
- ALLOW_THIS_IN_INITIALIZER_LIST(delegate_(this)),
- window_state_(GDK_WINDOW_STATE_WITHDRAWN),
- window_closed_(false) {
- SetNativeWindow(this);
- is_window_ = true;
-}
-
-void WindowGtk::InitWindow(GtkWindow* parent, const gfx::Rect& bounds) {
- if (parent)
- make_transient_to_parent();
- Widget::InitParams params(Widget::InitParams::TYPE_WINDOW);
- params.parent = GTK_WIDGET(parent);
- params.bounds = bounds;
- GetWidget()->Init(params);
- delegate_->OnNativeWindowCreated(bounds);
-
- g_signal_connect(G_OBJECT(GetNativeWindow()), "configure-event",
- G_CALLBACK(CallConfigureEvent), this);
- g_signal_connect(G_OBJECT(GetNativeWindow()), "window-state-event",
- G_CALLBACK(CallWindowStateEvent), this);
-}
-
-////////////////////////////////////////////////////////////////////////////////
// WindowGtk, private:
// static
@@ -463,4 +445,12 @@ void WindowGtk::OnDestroy(GtkWidget* widget) {
delegate_->OnNativeWindowDestroyed();
}
+////////////////////////////////////////////////////////////////////////////////
+// NativeWindow, public:
+
+// static
+Window* NativeWindow::CreateNativeWindow() {
+ return new WindowGtk;
+}
+
} // namespace views
diff --git a/views/window/window_gtk.h b/views/window/window_gtk.h
index 7114332..e659e4a 100644
--- a/views/window/window_gtk.h
+++ b/views/window/window_gtk.h
@@ -27,6 +27,7 @@ class WindowDelegate;
// Window implementation for GTK.
class WindowGtk : public WidgetGtk, public NativeWindow, public Window {
public:
+ WindowGtk();
virtual ~WindowGtk();
virtual Window* AsWindow();
@@ -44,6 +45,8 @@ class WindowGtk : public WidgetGtk, public NativeWindow, public Window {
virtual void IsActiveChanged();
protected:
+ virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE;
+
// Overridden from NativeWindow:
virtual NativeWidget* AsNativeWidget() OVERRIDE;
virtual const NativeWidget* AsNativeWidget() const OVERRIDE;
@@ -87,12 +90,6 @@ class WindowGtk : public WidgetGtk, public NativeWindow, public Window {
// For the constructor.
friend class Window;
- // Constructs the WindowGtk. |window_delegate| cannot be NULL.
- explicit WindowGtk(WindowDelegate* window_delegate);
-
- // Initializes the window to the passed in bounds.
- virtual void InitWindow(GtkWindow* parent, const gfx::Rect& bounds);
-
virtual void OnDestroy(GtkWidget* widget);
private:
diff --git a/views/window/window_win.cc b/views/window/window_win.cc
index 8814e75..be8db6d 100644
--- a/views/window/window_win.cc
+++ b/views/window/window_win.cc
@@ -236,19 +236,6 @@ class WindowWin::ScopedRedrawLock {
WindowWin::~WindowWin() {
}
-// static
-Window* Window::CreateChromeWindow(gfx::NativeWindow parent,
- const gfx::Rect& bounds,
- WindowDelegate* window_delegate) {
- Window* window = new WindowWin(window_delegate);
- window->non_client_view()->SetFrameView(window->CreateFrameViewForWindow());
- Widget::InitParams params(Widget::WindowInitParams());
- params.parent = parent;
- params.bounds = bounds;
- window->AsWidget()->Init(params);
- return window;
-}
-
void WindowWin::Show(int show_state) {
ShowWindow(show_state);
// When launched from certain programs like bash and Windows Live Messenger,
@@ -296,10 +283,8 @@ gfx::Font WindowWin::GetWindowTitleFont() {
///////////////////////////////////////////////////////////////////////////////
// WindowWin, protected:
-WindowWin::WindowWin(WindowDelegate* window_delegate)
- : WidgetWin(),
- Window(window_delegate),
- ALLOW_THIS_IN_INITIALIZER_LIST(delegate_(this)),
+WindowWin::WindowWin()
+ : ALLOW_THIS_IN_INITIALIZER_LIST(delegate_(this)),
focus_on_creation_(true),
restored_enabled_(false),
fullscreen_(false),
@@ -364,8 +349,6 @@ void WindowWin::InitNativeWidget(const Widget::InitParams& params) {
&last_monitor_rect_, &last_work_area_);
WidgetWin::InitNativeWidget(params);
-
- delegate_->OnNativeWindowCreated(params.bounds);
}
void WindowWin::OnActivateApp(BOOL active, DWORD thread_id) {
@@ -1375,4 +1358,12 @@ void Window::CloseAllSecondaryWindows() {
EnumThreadWindows(GetCurrentThreadId(), WindowCallbackProc, 0);
}
+////////////////////////////////////////////////////////////////////////////////
+// NativeWindow, public:
+
+// static
+Window* NativeWindow::CreateNativeWindow() {
+ return new WindowWin;
+}
+
} // namespace views
diff --git a/views/window/window_win.h b/views/window/window_win.h
index f998d31..5ade949 100644
--- a/views/window/window_win.h
+++ b/views/window/window_win.h
@@ -44,6 +44,7 @@ class WindowWin : public WidgetWin,
public NativeWindow,
public Window {
public:
+ WindowWin();
virtual ~WindowWin();
// Show the window with the specified show command.
@@ -69,9 +70,6 @@ class WindowWin : public WidgetWin,
protected:
friend Window;
- // Constructs the WindowWin. |window_delegate| cannot be NULL.
- explicit WindowWin(WindowDelegate* window_delegate);
-
// Returns the insets of the client area relative to the non-client area of
// the window. Override this function instead of OnNCCalcSize, which is
// crazily complicated.