diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-28 17:58:09 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-28 17:58:09 +0000 |
commit | 0ef6c772205144c383c8956218425bb160a5ecd8 (patch) | |
tree | 052314732e2318bf090fbe631737e66ed79c87c5 /views | |
parent | d2ceb4e7fe001e55d540784abac24620dc6b4a4a (diff) | |
download | chromium_src-0ef6c772205144c383c8956218425bb160a5ecd8.zip chromium_src-0ef6c772205144c383c8956218425bb160a5ecd8.tar.gz chromium_src-0ef6c772205144c383c8956218425bb160a5ecd8.tar.bz2 |
Convert more WidgetWin/WidgetGtk creations to use a new cross-platform static ctor on Widget: CreateWidget().
BUG=72040
TEST=none
Review URL: http://codereview.chromium.org/6732028
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79586 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/controls/tabbed_pane/native_tabbed_pane_gtk.cc | 3 | ||||
-rw-r--r-- | views/controls/tabbed_pane/native_tabbed_pane_win.cc | 11 | ||||
-rw-r--r-- | views/controls/tabbed_pane/native_tabbed_pane_win.h | 9 | ||||
-rw-r--r-- | views/controls/textfield/native_textfield_views_unittest.cc | 2 | ||||
-rw-r--r-- | views/examples/widget_example.cc | 14 | ||||
-rw-r--r-- | views/focus/focus_manager_unittest.cc | 18 | ||||
-rw-r--r-- | views/view_unittest.cc | 7 | ||||
-rw-r--r-- | views/widget/widget.cc | 6 | ||||
-rw-r--r-- | views/widget/widget.h | 15 | ||||
-rw-r--r-- | views/widget/widget_gtk.cc | 28 | ||||
-rw-r--r-- | views/widget/widget_win.cc | 19 |
11 files changed, 75 insertions, 57 deletions
diff --git a/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc b/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc index 836d8f3..df935db 100644 --- a/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc +++ b/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc @@ -154,7 +154,8 @@ void NativeTabbedPaneGtk::DoAddTabAtIndex(int index, int tab_count = GetTabCount(); DCHECK(index <= tab_count); - WidgetGtk* page_container = new WidgetGtk(WidgetGtk::TYPE_CHILD); + Widget* page_container = Widget::CreateWidget( + Widget::CreateParams(Widget::CreateParams::TYPE_CONTROL)); page_container->Init(NULL, gfx::Rect()); page_container->SetContentsView(contents); page_container->SetFocusTraversableParent(GetWidget()->GetFocusTraversable()); diff --git a/views/controls/tabbed_pane/native_tabbed_pane_win.cc b/views/controls/tabbed_pane/native_tabbed_pane_win.cc index 5176fd9..333fff0 100644 --- a/views/controls/tabbed_pane/native_tabbed_pane_win.cc +++ b/views/controls/tabbed_pane/native_tabbed_pane_win.cc @@ -17,7 +17,7 @@ #include "views/controls/tabbed_pane/tabbed_pane_listener.h" #include "views/layout/fill_layout.h" #include "views/widget/root_view.h" -#include "views/widget/widget_win.h" +#include "views/widget/widget.h" namespace views { @@ -289,7 +289,8 @@ void NativeTabbedPaneWin::CreateNativeControl() { SendMessage(tab_control, WM_SETFONT, reinterpret_cast<WPARAM>(font), FALSE); // Create the view container which is a child of the TabControl. - content_window_ = new WidgetWin(); + content_window_ = Widget::CreateWidget( + Widget::CreateParams(Widget::CreateParams::TYPE_CONTROL)); content_window_->Init(tab_control, gfx::Rect()); // Explicitly setting the WS_EX_LAYOUTRTL property for the HWND (see above @@ -383,13 +384,11 @@ void NativeTabbedPaneWin::DoSelectTabAt(int index, boolean invoke_listener) { } void NativeTabbedPaneWin::ResizeContents() { - CRect content_bounds; + RECT content_bounds; if (!GetClientRect(native_view(), &content_bounds)) return; TabCtrl_AdjustRect(native_view(), FALSE, &content_bounds); - content_window_->MoveWindow(content_bounds.left, content_bounds.top, - content_bounds.Width(), content_bounds.Height(), - TRUE); + content_window_->SetBounds(gfx::Rect(content_bounds)); } //////////////////////////////////////////////////////////////////////////////// diff --git a/views/controls/tabbed_pane/native_tabbed_pane_win.h b/views/controls/tabbed_pane/native_tabbed_pane_win.h index 8eac285..6ffa867 100644 --- a/views/controls/tabbed_pane/native_tabbed_pane_win.h +++ b/views/controls/tabbed_pane/native_tabbed_pane_win.h @@ -13,7 +13,7 @@ namespace views { -class WidgetWin; +class Widget; class TabLayout; class NativeTabbedPaneWin : public NativeControlWin, @@ -50,9 +50,8 @@ class NativeTabbedPaneWin : public NativeControlWin, virtual FocusTraversable* GetFocusTraversable(); virtual void ViewHierarchyChanged(bool is_add, View *parent, View *child); - virtual Widget* child_widget() { - return reinterpret_cast<Widget*>(content_window_); - } + // TODO(beng): this method should not be unix_hacker + virtual Widget* child_widget() { return content_window_; } private: // Called upon creation of native control to initialize tabs that are added @@ -86,7 +85,7 @@ class NativeTabbedPaneWin : public NativeControlWin, int selected_index_; // The window displayed in the tab. - WidgetWin* content_window_; + Widget* content_window_; DISALLOW_COPY_AND_ASSIGN(NativeTabbedPaneWin); }; diff --git a/views/controls/textfield/native_textfield_views_unittest.cc b/views/controls/textfield/native_textfield_views_unittest.cc index 417a4b9..7e2bab4 100644 --- a/views/controls/textfield/native_textfield_views_unittest.cc +++ b/views/controls/textfield/native_textfield_views_unittest.cc @@ -78,7 +78,7 @@ class NativeTextfieldViewsTest : public ViewsTestBase, textfield_->SetController(this); Widget::CreateParams params(Widget::CreateParams::TYPE_POPUP); params.mirror_origin_in_rtl = false; - widget_ = Widget::CreatePopupWidget(params); + widget_ = Widget::CreateWidget(params); widget_->Init(NULL, gfx::Rect(100, 100, 100, 100)); View* container = new View(); widget_->SetContentsView(container); diff --git a/views/examples/widget_example.cc b/views/examples/widget_example.cc index 7b53a69..d72276c 100644 --- a/views/examples/widget_example.cc +++ b/views/examples/widget_example.cc @@ -8,10 +8,7 @@ #include "views/layout/box_layout.h" #include "views/layout/layout_manager.h" #include "views/view.h" - -#if defined(OS_LINUX) -#include "views/widget/widget_gtk.h" -#endif +#include "views/widget/widget.h" namespace { @@ -111,10 +108,9 @@ void WidgetExample::InitWidget(views::Widget* widget, bool transparent) { #if defined(OS_LINUX) void WidgetExample::CreateChild(views::View* parent, bool transparent) { - views::WidgetGtk* widget = - new views::WidgetGtk(views::WidgetGtk::TYPE_CHILD); - if (transparent) - widget->MakeTransparent(); + views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_CONTROL); + params.transparent = transparent; + views::Widget* widget = views::Widget::CreateWidget(params); // Compute where to place the child widget. // We'll place it at the center of the root widget. views::Widget* parent_widget = parent->GetWidget(); @@ -131,7 +127,7 @@ void WidgetExample::CreateChild(views::View* parent, bool transparent) { void WidgetExample::CreatePopup(views::View* parent, bool transparent) { views::Widget::CreateParams params(views::Widget::CreateParams::TYPE_POPUP); params.transparent = transparent; - views::Widget* widget = views::Widget::CreatePopupWidget(params); + views::Widget* widget = views::Widget::CreateWidget(params); // Compute where to place the popup widget. // We'll place it right below the create button. diff --git a/views/focus/focus_manager_unittest.cc b/views/focus/focus_manager_unittest.cc index 53f2527..1f54a13 100644 --- a/views/focus/focus_manager_unittest.cc +++ b/views/focus/focus_manager_unittest.cc @@ -290,18 +290,16 @@ class BorderView : public NativeViewHost { if (child == this && is_add) { if (!widget_) { + widget_ = Widget::CreateWidget( + Widget::CreateParams(Widget::CreateParams::TYPE_CONTROL)); #if defined(OS_WIN) - WidgetWin* widget_win = new WidgetWin(); - widget_win->Init(parent->GetRootView()->GetWidget()->GetNativeView(), - gfx::Rect(0, 0, 0, 0)); - widget_win->SetFocusTraversableParentView(this); - widget_ = widget_win; -#else - WidgetGtk* widget_gtk = new WidgetGtk(WidgetGtk::TYPE_CHILD); - widget_gtk->Init(native_view(), gfx::Rect(0, 0, 0, 0)); - widget_gtk->SetFocusTraversableParentView(this); - widget_ = widget_gtk; + gfx::NativeView parent_native_view = + parent->GetRootView()->GetWidget()->GetNativeView(); +#elif defined(TOOLKIT_USES_GTK) + gfx::NativeView parent_native_view = native_view(); #endif + widget_->Init(parent_native_view, gfx::Rect(0, 0, 0, 0)); + widget_->SetFocusTraversableParentView(this); widget_->SetContentsView(child_); } diff --git a/views/view_unittest.cc b/views/view_unittest.cc index 428f320..08666b5 100644 --- a/views/view_unittest.cc +++ b/views/view_unittest.cc @@ -54,11 +54,8 @@ class ViewTest : public ViewsTestBase { } Widget* CreateWidget() { -#if defined(OS_WIN) - return new WidgetWin(); -#elif defined(OS_LINUX) - return new WidgetGtk(WidgetGtk::TYPE_WINDOW); -#endif + return Widget::CreateWidget( + Widget::CreateParams(Widget::CreateParams::TYPE_WINDOW)); } }; diff --git a/views/widget/widget.cc b/views/widget/widget.cc index 4963ce6..65382c4 100644 --- a/views/widget/widget.cc +++ b/views/widget/widget.cc @@ -18,10 +18,12 @@ namespace views { // Widget, CreateParams: Widget::CreateParams::CreateParams() - : type(TYPE_TOPLEVEL), + : type(TYPE_WINDOW), + child(false), transparent(false), accept_events(true), can_activate(true), + keep_on_top(false), delete_on_destroy(true), mirror_origin_in_rtl(true), has_dropshadow(false), @@ -30,9 +32,11 @@ Widget::CreateParams::CreateParams() Widget::CreateParams::CreateParams(Type type) : type(type), + child(type == TYPE_CONTROL), transparent(false), accept_events(true), can_activate(type != TYPE_POPUP && type != TYPE_MENU), + keep_on_top(type == TYPE_MENU), delete_on_destroy(true), mirror_origin_in_rtl(true), has_dropshadow(false), diff --git a/views/widget/widget.h b/views/widget/widget.h index 71f33bf..b0e22a3 100644 --- a/views/widget/widget.h +++ b/views/widget/widget.h @@ -62,10 +62,11 @@ class Widget : public internal::NativeWidgetDelegate, public: struct CreateParams { enum Type { - TYPE_TOPLEVEL, - TYPE_CHILD, - TYPE_POPUP, - TYPE_MENU + TYPE_WINDOW, // A Window, like a frame window. + TYPE_CONTROL, // A control, like a button. + TYPE_POPUP, // An undecorated Window, with transient properties. + TYPE_MENU // An undecorated Window, with transient properties + // specialized to menus. }; CreateParams(); @@ -73,9 +74,11 @@ class Widget : public internal::NativeWidgetDelegate, Type type; + bool child; bool transparent; bool accept_events; bool can_activate; + bool keep_on_top; bool delete_on_destroy; bool mirror_origin_in_rtl; bool has_dropshadow; @@ -85,8 +88,8 @@ class Widget : public internal::NativeWidgetDelegate, Widget(); virtual ~Widget(); - // Creates a Widget instance suitable for use as a transient popup. - static Widget* CreatePopupWidget(const CreateParams& params); + // Creates a Widget instance with the supplied params. + static Widget* CreateWidget(const CreateParams& params); // Enumerates all windows pertaining to us and notifies their // view hierarchies that the locale has changed. diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc index b2371f8..a3f16d3 100644 --- a/views/widget/widget_gtk.cc +++ b/views/widget/widget_gtk.cc @@ -1547,10 +1547,30 @@ void WidgetGtk::DrawTransparentBackground(GtkWidget* widget, // Widget, public: // static -Widget* Widget::CreatePopupWidget(const CreateParams& params) { - WidgetGtk* popup = new WidgetGtk(WidgetGtk::TYPE_POPUP); - popup->SetCreateParams(params); - return popup; +Widget* Widget::CreateWidget(const CreateParams& params) { + // TODO(beng): coalesce with CreateParams::Type. + WidgetGtk::Type widget_gtk_type; + switch (params.type) { + case CreateParams::TYPE_CONTROL: + widget_gtk_type = WidgetGtk::TYPE_CHILD; + break; + case CreateParams::TYPE_MENU: + widget_gtk_type = WidgetGtk::TYPE_POPUP; + break; + case CreateParams::TYPE_POPUP: + widget_gtk_type = WidgetGtk::TYPE_POPUP; + break; + case CreateParams::TYPE_WINDOW: + widget_gtk_type = WidgetGtk::TYPE_DECORATED_WINDOW; + break; + default: + NOTREACHED(); + break; + } + + WidgetGtk* widget = new WidgetGtk(widget_gtk_type); + widget->SetCreateParams(params); + return widget; } // static diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc index 147c443..ebf3129 100644 --- a/views/widget/widget_win.cc +++ b/views/widget/widget_win.cc @@ -162,10 +162,14 @@ void WidgetWin::SetCreateParams(const CreateParams& params) { DWORD class_style = CS_DBLCLKS; // Set type-independent style attributes. + if (params.child) + style |= WS_CHILD; if (!params.accept_events) ex_style |= WS_EX_TRANSPARENT; if (!params.can_activate) ex_style |= WS_EX_NOACTIVATE; + if (params.keep_on_top) + ex_style |= WS_EX_TOPMOST; if (params.mirror_origin_in_rtl) ex_style |= l10n_util::GetExtendedTooltipStyles(); if (params.transparent) @@ -177,10 +181,8 @@ void WidgetWin::SetCreateParams(const CreateParams& params) { // Set type-dependent style attributes. switch (params.type) { - case CreateParams::TYPE_TOPLEVEL: - break; - case CreateParams::TYPE_CHILD: - style |= WS_CHILD; + case CreateParams::TYPE_WINDOW: + case CreateParams::TYPE_CONTROL: break; case CreateParams::TYPE_POPUP: style |= WS_POPUP; @@ -188,7 +190,6 @@ void WidgetWin::SetCreateParams(const CreateParams& params) { break; case CreateParams::TYPE_MENU: style |= WS_POPUP; - ex_style |= WS_EX_TOPMOST; is_mouse_down_ = ((GetKeyState(VK_LBUTTON) & 0x80) || (GetKeyState(VK_RBUTTON) & 0x80) || @@ -1201,10 +1202,10 @@ gfx::AcceleratedWidget WidgetWin::GetAcceleratedWidget() { // Widget, public: // static -Widget* Widget::CreatePopupWidget(const CreateParams& params) { - WidgetWin* popup = new WidgetWin; - popup->SetCreateParams(params); - return popup; +Widget* Widget::CreateWidget(const CreateParams& params) { + WidgetWin* widget = new WidgetWin; + widget->SetCreateParams(params); + return widget; } // static |