diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-05 00:58:06 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-06-05 00:58:06 +0000 |
commit | a55bfd3d8f23c22003cf6a0754aa320fe7b7d3e4 (patch) | |
tree | f90c20acb5701e17d66fabfce5ca90c827ca9c2e /views | |
parent | bd205617c4f7eca4bb28c0343ed2f071189393c3 (diff) | |
download | chromium_src-a55bfd3d8f23c22003cf6a0754aa320fe7b7d3e4.zip chromium_src-a55bfd3d8f23c22003cf6a0754aa320fe7b7d3e4.tar.gz chromium_src-a55bfd3d8f23c22003cf6a0754aa320fe7b7d3e4.tar.bz2 |
Add cross platform Widget::InitWithWidget(parent, const gfx::Rect& bounds);
On linux, native parent has to be either window_contents or widget depending of the type of wiget. InitWithWidget takes a parent Widget instead of native and hides these details.
I also cleaned up a few dead/duplicated code.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/2355003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@48990 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/examples/widget_example.h | 7 | ||||
-rw-r--r-- | views/view_unittest.cc | 7 | ||||
-rw-r--r-- | views/widget/widget.h | 7 | ||||
-rw-r--r-- | views/widget/widget_gtk.cc | 15 | ||||
-rw-r--r-- | views/widget/widget_gtk.h | 1 | ||||
-rw-r--r-- | views/widget/widget_win.cc | 4 | ||||
-rw-r--r-- | views/widget/widget_win.h | 1 |
7 files changed, 32 insertions, 10 deletions
diff --git a/views/examples/widget_example.h b/views/examples/widget_example.h index 7546ba4..1897b53 100644 --- a/views/examples/widget_example.h +++ b/views/examples/widget_example.h @@ -128,15 +128,14 @@ class WidgetExample : public ExampleBase, public views::ButtonListener { widget->MakeTransparent(); // Compute where to place the child widget. // We'll place it at the center of the root widget. - views::WidgetGtk* parent_widget = - static_cast<views::WidgetGtk*>(parent->GetWidget()); + views::Widget* parent_widget = parent->GetWidget(); gfx::Rect bounds; parent_widget->GetBounds(&bounds, false); // Child widget is 200x200 square. bounds.SetRect((bounds.width() - 200) / 2, (bounds.height() - 200) / 2, 200, 200); // Initialize the child widget with the computed bounds. - widget->Init(parent_widget->window_contents(), bounds); + widget->InitWithWidget(parent_widget, bounds); InitWidget(widget, transparency); } #endif @@ -155,7 +154,7 @@ class WidgetExample : public ExampleBase, public views::ButtonListener { point.Offset(0, parent->size().height()); gfx::Rect bounds(point.x(), point.y(), 200, 300); // Initialize the popup widget with the computed bounds. - widget->Init(NULL, bounds); + widget->InitWithWidget(parent->GetWidget(), bounds); InitWidget(widget, transparency); } diff --git a/views/view_unittest.cc b/views/view_unittest.cc index ec9790a..b5e1091 100644 --- a/views/view_unittest.cc +++ b/views/view_unittest.cc @@ -637,11 +637,7 @@ TEST_F(ViewTest, Textfield) { Clipboard clipboard; Widget* window = CreateWidget(); -#if defined(OS_WIN) - static_cast<WidgetWin*>(window)->Init(NULL, gfx::Rect(0, 0, 100, 100)); -#else - static_cast<WidgetGtk*>(window)->Init(NULL, gfx::Rect(0, 0, 100, 100)); -#endif + window->Init(NULL, gfx::Rect(0, 0, 100, 100)); RootView* root_view = window->GetRootView(); Textfield* textfield = new Textfield(); @@ -1353,4 +1349,3 @@ TEST_F(ViewTest, ChangeNativeViewHierarchyChangeHierarchy) { test.CheckChangingHierarhy(); #endif } - diff --git a/views/widget/widget.h b/views/widget/widget.h index d4ddcfc..cf893ee 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -97,6 +97,13 @@ class Widget { // contents as the window is sized. virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds) = 0; + // Initialize the widget with a views::Widget parent and an initial + // desired size. This internally invokes |Init(gfx::NativeView, + // const gfx::Rect&)| but it determines the correct native view + // for each platform and the type of widget. Passing NULL to + // |parent| is same as invoking |Init(NULL, bounds)|. + virtual void InitWithWidget(Widget* parent, const gfx::Rect& bounds) = 0; + // Returns the WidgetDelegate for delegating certain events. virtual WidgetDelegate* GetWidgetDelegate() = 0; diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index 055c855..78137c5 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -456,6 +456,21 @@ void WidgetGtk::ActiveWindowChanged(GdkWindow* active_window) { //////////////////////////////////////////////////////////////////////////////// // WidgetGtk, Widget implementation: +void WidgetGtk::InitWithWidget(Widget* parent, + const gfx::Rect& bounds) { + WidgetGtk* parent_gtk = static_cast<WidgetGtk*>(parent); + GtkWidget* native_parent = NULL; + if (parent != NULL) { + if (type_ != TYPE_CHILD) { + // window's parent has to be window. + native_parent = parent_gtk->GetNativeView(); + } else { + native_parent = parent_gtk->window_contents(); + } + } + Init(native_parent, bounds); +} + void WidgetGtk::Init(GtkWidget* parent, const gfx::Rect& bounds) { if (type_ != TYPE_CHILD) diff --git a/views/widget/widget_gtk.h b/views/widget/widget_gtk.h index 980baaf..beb629f 100644 --- a/views/widget/widget_gtk.h +++ b/views/widget/widget_gtk.h @@ -152,6 +152,7 @@ class WidgetGtk // Overridden from Widget: virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds); + virtual void InitWithWidget(Widget* parent, const gfx::Rect& bounds); virtual WidgetDelegate* GetWidgetDelegate(); virtual void SetWidgetDelegate(WidgetDelegate* delegate); virtual void SetContentsView(View* view); diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc index 2b4c649..72431b0 100644 --- a/views/widget/widget_win.cc +++ b/views/widget/widget_win.cc @@ -170,6 +170,10 @@ void WidgetWin::Init(gfx::NativeView parent, const gfx::Rect& bounds) { ImmAssociateContextEx(hwnd(), NULL, 0); } +void WidgetWin::InitWithWidget(Widget* parent, const gfx::Rect& bounds) { + Init(parent->GetNativeView(), bounds); +} + WidgetDelegate* WidgetWin::GetWidgetDelegate() { return delegate_; } diff --git a/views/widget/widget_win.h b/views/widget/widget_win.h index f5ac2d1..e0cdc44d 100644 --- a/views/widget/widget_win.h +++ b/views/widget/widget_win.h @@ -181,6 +181,7 @@ class WidgetWin : public app::WindowImpl, // Overridden from Widget: virtual void Init(gfx::NativeView parent, const gfx::Rect& bounds); + virtual void InitWithWidget(Widget* parent, const gfx::Rect& bounds); virtual WidgetDelegate* GetWidgetDelegate(); virtual void SetWidgetDelegate(WidgetDelegate* delegate); virtual void SetContentsView(View* view); |