diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-13 16:03:53 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-05-13 16:03:53 +0000 |
commit | 4672de6247fe7a865b2abeaac1b4a76c9369b7a3 (patch) | |
tree | eaa314bbb797dae5152877b1ad170f44d1eb51b4 /views/controls/menu | |
parent | 37ae86f0c4b50dc83b13da17ae1a9ef7083fa76f (diff) | |
download | chromium_src-4672de6247fe7a865b2abeaac1b4a76c9369b7a3.zip chromium_src-4672de6247fe7a865b2abeaac1b4a76c9369b7a3.tar.gz chromium_src-4672de6247fe7a865b2abeaac1b4a76c9369b7a3.tar.bz2 |
Split the hierarchy.
* Widget ----
Now recognizes a supplied NativeWidget via InitParams. If this is specified then a default one is not created.
Is now created directly rather than using a factory. NativeWidget creation is not performed until Init() is called. This means some functions that rely on a NativeWidget must not be called until _AFTER_ Init() (explains some of the function call reordering in this CL, e.g. moving SetOpacity() until after Init()).
ResetLastMouseMovedFlag() moved to this API so that BaseTabStrip can call it in a cross-platform way.
Made last remaining unimplemented methods on Widget pass-thru to NativeWidget implementations.
* WidgetWin/WidgetGtk ----
The NativeWidget implementations now both require a NativeWidgetDelegate implementation upon construction. This is passed through the constructor by the static factory method NativeWidget::CreateNativeWidget and by subclasses such as WindowWin, BubbleWidgetWin, etc.
Some classes that are constructed directly (e.g. LockWindow, in ChromeOS) never have a Widget created for them, so they create the Widget themselves in their base class initializer.
Code in these classes (and their WindowWin/WindowGtk, BrowserFrameWin, BrowserFrameGtk subclasses) must now call GetWidget() etc to call Widget API methods since they are no longer subclasses.
static_casting to this (and derived) types must now be done on the Widget's native_widget().
GetWindow() is renamed to GetContainingWindow() to avoid naming conflicts.
* Window ----
Window is now a subclass of Widget.
Now recognizes a supplied NativeWindow via InitParams. If this is specified then a default one is not created.
Window::CloseWindow becomes an override of Widget::Close.
CloseAllSecondaryWindows() becomes CloseAllSecondaryWidgets() and moves to widget.h
IsAppWindow() is removed and replaced by set_is_secondary_widget on Widget.
* MenuHost ----
Subclasses Widget now.
* TabContentsViewViews ----
It looks like the Gtk-views code here was still using the old implementation of the Native version of this class - i.e. a class that subclassed TabContentsView AND WidgetGtk. A no-no. I had to write NativeTabContentsViewGtk, which is almost identical to NativeTabContentsViewWin with the Gtk bits of TabContentsViewGtk thrown in.
* BrowserFrame ----
Platform-specific functionality is now restricted to BrowserFrameWin/BrowserFrameGtk behind a NativeBrowserFrame interface. Construction is exposed via a static factory method on NativeBrowserFrame.
BrowserFrame becomes a concrete class that now subclasses Window.
As a result, it no longer needs a GetWindow() accessor method, so people with a BrowserFrame* can just call Window methods directly on it.
It is constructed directly, replacing the BrowserFrame::Create() method.
NativeBrowserFrameDelegate is no longer needed.
BrowserFrameChromeos is simpler as a couple of #ifdefs in BrowserFrame, so I got rid of that too.
* AutocompletePopupWin/Gtk ----
No longer required. AutocompletePopupContentsView now just uses a Widget directly.
* There is some lingering ugliness:
- If you set a native_window field on Window::InitParams you must also manually set widget_init_params.native_widget. I will make InitParams do more of this automatically later.
- It'd be nice for the ContentsView to be specified via InitParams. I'll get to this later.
- NativeBrowserFrame could probably disappear as an interface. It only exists to provide a couple of methods that may be implemented in other ways.
- delete_on_destroy should now be an ownership directionality enum. I will do this later.
- Secondary-widgetness should somehow be inferred from transience. Later.
- set_focus_on_creation for both the NativeWidgets should probably move to Widget if it is really needed.
- WidgetWin/Gtk::SetInitialFocus seems like it could move to Widget.
- I need to clean up function order in some cases.
BUG=72040
TEST=none
Review URL: http://codereview.chromium.org/7012006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@85269 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/menu')
-rw-r--r-- | views/controls/menu/menu_host.cc | 24 | ||||
-rw-r--r-- | views/controls/menu/menu_host.h | 11 | ||||
-rw-r--r-- | views/controls/menu/menu_host_gtk.cc | 13 | ||||
-rw-r--r-- | views/controls/menu/menu_host_gtk.h | 4 | ||||
-rw-r--r-- | views/controls/menu/menu_host_win.cc | 13 | ||||
-rw-r--r-- | views/controls/menu/menu_host_win.h | 4 | ||||
-rw-r--r-- | views/controls/menu/native_menu_host_delegate.h | 6 |
7 files changed, 32 insertions, 43 deletions
diff --git a/views/controls/menu/menu_host.cc b/views/controls/menu/menu_host.cc index 1b0f3a6..abebdce 100644 --- a/views/controls/menu/menu_host.cc +++ b/views/controls/menu/menu_host.cc @@ -31,8 +31,7 @@ void MenuHost::InitMenuHost(gfx::NativeWindow parent, const gfx::Rect& bounds, View* contents_view, bool do_capture) { - Widget::InitParams params; - params.type = Widget::InitParams::TYPE_MENU; + Widget::InitParams params(Widget::InitParams::TYPE_MENU); params.has_dropshadow = true; #if defined(OS_WIN) params.parent = parent; @@ -40,6 +39,7 @@ void MenuHost::InitMenuHost(gfx::NativeWindow parent, params.parent = GTK_WIDGET(parent); #endif params.bounds = bounds; + params.native_widget = native_menu_host_->AsNativeWidget(); GetWidget()->Init(params); GetWidget()->SetContentsView(contents_view); ShowMenuHost(do_capture); @@ -85,6 +85,18 @@ NativeWidget* MenuHost::GetNativeWidget() { } //////////////////////////////////////////////////////////////////////////////// +// MenuHost, Widget overrides: + + +RootView* MenuHost::CreateRootView() { + return new MenuHostRootView(GetWidget(), submenu_); +} + +bool MenuHost::ShouldReleaseCaptureOnMouseReleased() const { + return false; +} + +//////////////////////////////////////////////////////////////////////////////// // MenuHost, internal::NativeMenuHostDelegate implementation: void MenuHost::OnNativeMenuHostDestroy() { @@ -105,12 +117,8 @@ void MenuHost::OnNativeMenuHostCancelCapture() { menu_controller->CancelAll(); } -RootView* MenuHost::CreateRootView() { - return new MenuHostRootView(GetWidget(), submenu_); -} - -bool MenuHost::ShouldReleaseCaptureOnMouseRelease() const { - return false; +internal::NativeWidgetDelegate* MenuHost::AsNativeWidgetDelegate() { + return this; } } // namespace views diff --git a/views/controls/menu/menu_host.h b/views/controls/menu/menu_host.h index 41ecf8e..0ebd1ac 100644 --- a/views/controls/menu/menu_host.h +++ b/views/controls/menu/menu_host.h @@ -10,6 +10,7 @@ #include "ui/gfx/native_widget_types.h" #include "ui/gfx/rect.h" #include "views/controls/menu/native_menu_host_delegate.h" +#include "views/widget/widget.h" namespace views { @@ -28,7 +29,8 @@ class Widget; // OS destroys the widget out from under us, in which case |MenuHostDestroyed| // is invoked back on the SubmenuView and the SubmenuView then drops references // to the MenuHost. -class MenuHost : public internal::NativeMenuHostDelegate { +class MenuHost : public Widget, + public internal::NativeMenuHostDelegate { public: explicit MenuHost(SubmenuView* submenu); virtual ~MenuHost(); @@ -65,11 +67,14 @@ class MenuHost : public internal::NativeMenuHostDelegate { NativeWidget* GetNativeWidget(); private: + // Overridden from Widget: + virtual RootView* CreateRootView() OVERRIDE; + virtual bool ShouldReleaseCaptureOnMouseReleased() const OVERRIDE; + // Overridden from NativeMenuHostDelegate: virtual void OnNativeMenuHostDestroy() OVERRIDE; virtual void OnNativeMenuHostCancelCapture() OVERRIDE; - virtual RootView* CreateRootView() OVERRIDE; - virtual bool ShouldReleaseCaptureOnMouseRelease() const OVERRIDE; + virtual internal::NativeWidgetDelegate* AsNativeWidgetDelegate() OVERRIDE; NativeMenuHost* native_menu_host_; diff --git a/views/controls/menu/menu_host_gtk.cc b/views/controls/menu/menu_host_gtk.cc index 201d17f..553bca3 100644 --- a/views/controls/menu/menu_host_gtk.cc +++ b/views/controls/menu/menu_host_gtk.cc @@ -23,7 +23,8 @@ namespace views { // MenuHostGtk, public: MenuHostGtk::MenuHostGtk(internal::NativeMenuHostDelegate* delegate) - : did_input_grab_(false), + : WidgetGtk(delegate->AsNativeWidgetDelegate()), + did_input_grab_(false), delegate_(delegate) { } @@ -82,7 +83,6 @@ NativeWidget* MenuHostGtk::AsNativeWidget() { // MenuHostGtk, WidgetGtk overrides: void MenuHostGtk::InitNativeWidget(const Widget::InitParams& params) { - make_transient_to_parent(); WidgetGtk::InitNativeWidget(params); // Make sure we get destroyed when the parent is destroyed. gtk_window_set_destroy_with_parent(GTK_WINDOW(GetNativeView()), TRUE); @@ -90,15 +90,6 @@ void MenuHostGtk::InitNativeWidget(const Widget::InitParams& params) { GDK_WINDOW_TYPE_HINT_MENU); } -// TODO(beng): remove once MenuHost is-a Widget -RootView* MenuHostGtk::CreateRootView() { - return delegate_->CreateRootView(); -} - -bool MenuHostGtk::ShouldReleaseCaptureOnMouseReleased() const { - return delegate_->ShouldReleaseCaptureOnMouseRelease(); -} - void MenuHostGtk::ReleaseMouseCapture() { WidgetGtk::ReleaseMouseCapture(); if (did_input_grab_) { diff --git a/views/controls/menu/menu_host_gtk.h b/views/controls/menu/menu_host_gtk.h index d0378c3..ac1e588 100644 --- a/views/controls/menu/menu_host_gtk.h +++ b/views/controls/menu/menu_host_gtk.h @@ -29,8 +29,6 @@ class MenuHostGtk : public WidgetGtk, // Overridden from WidgetGtk: virtual void InitNativeWidget(const Widget::InitParams& params) OVERRIDE; - virtual RootView* CreateRootView() OVERRIDE; - virtual bool ShouldReleaseCaptureOnMouseReleased() const OVERRIDE; virtual void ReleaseMouseCapture() OVERRIDE; virtual void OnDestroy(GtkWidget* object) OVERRIDE; virtual void HandleGtkGrabBroke() OVERRIDE; @@ -39,7 +37,7 @@ class MenuHostGtk : public WidgetGtk, // Have we done input grab? bool did_input_grab_; - scoped_ptr<internal::NativeMenuHostDelegate> delegate_; + internal::NativeMenuHostDelegate* delegate_; DISALLOW_COPY_AND_ASSIGN(MenuHostGtk); }; diff --git a/views/controls/menu/menu_host_win.cc b/views/controls/menu/menu_host_win.cc index 5c2435d..cba5595 100644 --- a/views/controls/menu/menu_host_win.cc +++ b/views/controls/menu/menu_host_win.cc @@ -12,7 +12,8 @@ namespace views { // MenuHostWin, public: MenuHostWin::MenuHostWin(internal::NativeMenuHostDelegate* delegate) - : delegate_(delegate) { + : WidgetWin(delegate->AsNativeWidgetDelegate()), + delegate_(delegate) { } MenuHostWin::~MenuHostWin() { @@ -42,16 +43,6 @@ void MenuHostWin::OnCancelMode() { WidgetWin::OnCancelMode(); } -// TODO(beng): remove once MenuHost is-a Widget -RootView* MenuHostWin::CreateRootView() { - return delegate_->CreateRootView(); -} - -// TODO(beng): remove once MenuHost is-a Widget -bool MenuHostWin::ShouldReleaseCaptureOnMouseReleased() const { - return delegate_->ShouldReleaseCaptureOnMouseRelease(); -} - //////////////////////////////////////////////////////////////////////////////// // NativeMenuHost, public: diff --git a/views/controls/menu/menu_host_win.h b/views/controls/menu/menu_host_win.h index 01a1419..7dfc8e8 100644 --- a/views/controls/menu/menu_host_win.h +++ b/views/controls/menu/menu_host_win.h @@ -29,10 +29,8 @@ class MenuHostWin : public WidgetWin, // Overridden from WidgetWin: virtual void OnDestroy() OVERRIDE; virtual void OnCancelMode() OVERRIDE; - virtual RootView* CreateRootView() OVERRIDE; - virtual bool ShouldReleaseCaptureOnMouseReleased() const OVERRIDE; - scoped_ptr<internal::NativeMenuHostDelegate> delegate_; + internal::NativeMenuHostDelegate* delegate_; DISALLOW_COPY_AND_ASSIGN(MenuHostWin); }; diff --git a/views/controls/menu/native_menu_host_delegate.h b/views/controls/menu/native_menu_host_delegate.h index e6d3de8..8baf714 100644 --- a/views/controls/menu/native_menu_host_delegate.h +++ b/views/controls/menu/native_menu_host_delegate.h @@ -9,6 +9,7 @@ namespace views { class MenuHost; class RootView; namespace internal { +class NativeWidgetDelegate; class NativeMenuHostDelegate { public: @@ -20,10 +21,7 @@ class NativeMenuHostDelegate { // Called when the NativeMenuHost is losing input capture. virtual void OnNativeMenuHostCancelCapture() = 0; - // Pass-thrus for Widget overrides. - // TODO(beng): Remove once MenuHost is-a Widget. - virtual RootView* CreateRootView() = 0; - virtual bool ShouldReleaseCaptureOnMouseRelease() const = 0; + virtual NativeWidgetDelegate* AsNativeWidgetDelegate() = 0; }; } // namespace internal |