summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-31 16:55:41 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-31 16:55:41 +0000
commit95685c9c93543056a18adf176d657c77590fb9f6 (patch)
treeeb8f4cd894bfd84129989ee1dab8331f249e0ca8 /views
parentd9f43efd11eec33be6e146a5b36c1691d66b39ca (diff)
downloadchromium_src-95685c9c93543056a18adf176d657c77590fb9f6.zip
chromium_src-95685c9c93543056a18adf176d657c77590fb9f6.tar.gz
chromium_src-95685c9c93543056a18adf176d657c77590fb9f6.tar.bz2
Make MenuHost concrete, hide platform specific implementation behind NativeMenuHost.
This is the first step, creating this structure. Will consolidate common functionality and state next. BUG=72040 TEST=all menu tests for bookmark bar, wrench menu Review URL: http://codereview.chromium.org/6740022 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80015 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/menu/menu_host.cc56
-rw-r--r--views/controls/menu/menu_host.h35
-rw-r--r--views/controls/menu/menu_host_gtk.cc31
-rw-r--r--views/controls/menu/menu_host_gtk.h17
-rw-r--r--views/controls/menu/menu_host_win.cc25
-rw-r--r--views/controls/menu/menu_host_win.h48
-rw-r--r--views/controls/menu/native_menu_host.h56
-rw-r--r--views/controls/menu/native_menu_host_delegate.h19
-rw-r--r--views/controls/menu/submenu_view.cc4
-rw-r--r--views/views.gyp3
-rw-r--r--views/widget/widget_gtk.cc10
11 files changed, 234 insertions, 70 deletions
diff --git a/views/controls/menu/menu_host.cc b/views/controls/menu/menu_host.cc
new file mode 100644
index 0000000..30ba412
--- /dev/null
+++ b/views/controls/menu/menu_host.cc
@@ -0,0 +1,56 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "views/controls/menu/menu_host.h"
+#include "views/controls/menu/native_menu_host.h"
+
+namespace views {
+
+////////////////////////////////////////////////////////////////////////////////
+// MenuHost, public:
+
+MenuHost::MenuHost(SubmenuView* submenu)
+ : native_menu_host_(NativeMenuHost::CreateNativeMenuHost(submenu)) {
+}
+
+MenuHost::~MenuHost() {
+}
+
+void MenuHost::InitMenuHost(gfx::NativeWindow parent,
+ const gfx::Rect& bounds,
+ View* contents_view,
+ bool do_capture) {
+ native_menu_host_->InitMenuHost(parent, bounds, contents_view, do_capture);
+}
+
+bool MenuHost::IsMenuHostVisible() {
+ return native_menu_host_->IsMenuHostVisible();
+}
+
+void MenuHost::ShowMenuHost(bool do_capture) {
+ native_menu_host_->ShowMenuHost(do_capture);
+}
+
+void MenuHost::HideMenuHost() {
+ native_menu_host_->HideMenuHost();
+}
+
+void MenuHost::DestroyMenuHost() {
+ native_menu_host_->DestroyMenuHost();
+ delete this;
+}
+
+void MenuHost::SetMenuHostBounds(const gfx::Rect& bounds) {
+ native_menu_host_->SetMenuHostBounds(bounds);
+}
+
+void MenuHost::ReleaseMenuHostCapture() {
+ native_menu_host_->ReleaseMenuHostCapture();
+}
+
+gfx::NativeWindow MenuHost::GetMenuHostWindow() {
+ return native_menu_host_->GetMenuHostWindow();
+}
+
+} // namespace views
diff --git a/views/controls/menu/menu_host.h b/views/controls/menu/menu_host.h
index b6f7ee3..bc7e5b6 100644
--- a/views/controls/menu/menu_host.h
+++ b/views/controls/menu/menu_host.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,6 +11,7 @@
namespace views {
+class NativeMenuHost;
class SubmenuView;
class View;
@@ -25,39 +26,41 @@ class View;
// to the MenuHost.
class MenuHost {
public:
- // Creates the platform specific MenuHost. Ownership passes to the caller.
- static MenuHost* Create(SubmenuView* submenu_view);
+ explicit MenuHost(SubmenuView* submenu);
+ virtual ~MenuHost();
// Initializes and shows the MenuHost.
- virtual void InitMenuHost(gfx::NativeWindow parent,
- const gfx::Rect& bounds,
- View* contents_view,
- bool do_capture) = 0;
+ void InitMenuHost(gfx::NativeWindow parent,
+ const gfx::Rect& bounds,
+ View* contents_view,
+ bool do_capture);
// Returns true if the menu host is visible.
- virtual bool IsMenuHostVisible() = 0;
+ bool IsMenuHostVisible();
// Shows the menu host. If |do_capture| is true the menu host should do a
// mouse grab.
- virtual void ShowMenuHost(bool do_capture) = 0;
+ void ShowMenuHost(bool do_capture);
// Hides the menu host.
- virtual void HideMenuHost() = 0;
+ void HideMenuHost();
// Destroys and deletes the menu host.
- virtual void DestroyMenuHost() = 0;
+ void DestroyMenuHost();
// Sets the bounds of the menu host.
- virtual void SetMenuHostBounds(const gfx::Rect& bounds) = 0;
+ void SetMenuHostBounds(const gfx::Rect& bounds);
// Releases a mouse grab installed by |ShowMenuHost|.
- virtual void ReleaseMenuHostCapture() = 0;
+ void ReleaseMenuHostCapture();
// Returns the native window of the MenuHost.
- virtual gfx::NativeWindow GetMenuHostWindow() = 0;
+ gfx::NativeWindow GetMenuHostWindow();
- protected:
- virtual ~MenuHost() {}
+ private:
+ NativeMenuHost* native_menu_host_;
+
+ DISALLOW_COPY_AND_ASSIGN(MenuHost);
};
} // namespace views
diff --git a/views/controls/menu/menu_host_gtk.cc b/views/controls/menu/menu_host_gtk.cc
index 5552fbe..9ec992b9 100644
--- a/views/controls/menu/menu_host_gtk.cc
+++ b/views/controls/menu/menu_host_gtk.cc
@@ -22,24 +22,14 @@
namespace views {
-// static
-MenuHost* MenuHost::Create(SubmenuView* submenu_view) {
- return new MenuHostGtk(submenu_view);
-}
+////////////////////////////////////////////////////////////////////////////////
+// MenuHostGtk, public:
MenuHostGtk::MenuHostGtk(SubmenuView* submenu)
: WidgetGtk(WidgetGtk::TYPE_POPUP),
destroying_(false),
submenu_(submenu),
did_input_grab_(false) {
- GdkEvent* event = gtk_get_current_event();
- if (event) {
- if (event->type == GDK_BUTTON_PRESS || event->type == GDK_2BUTTON_PRESS ||
- event->type == GDK_3BUTTON_PRESS) {
- set_mouse_down(true);
- }
- gdk_event_free(event);
- }
CreateParams params;
params.type = CreateParams::TYPE_MENU;
params.has_dropshadow = true;
@@ -49,6 +39,9 @@ MenuHostGtk::MenuHostGtk(SubmenuView* submenu)
MenuHostGtk::~MenuHostGtk() {
}
+////////////////////////////////////////////////////////////////////////////////
+// MenuHostGtk, NativeMenuHost implementation:
+
void MenuHostGtk::InitMenuHost(gfx::NativeWindow parent,
const gfx::Rect& bounds,
View* contents_view,
@@ -103,6 +96,9 @@ gfx::NativeWindow MenuHostGtk::GetMenuHostWindow() {
return GTK_WINDOW(GetNativeView());
}
+////////////////////////////////////////////////////////////////////////////////
+// MenuHostGtk, WidgetGtk overrides:
+
RootView* MenuHostGtk::CreateRootView() {
return new MenuHostRootView(this, submenu_);
}
@@ -152,6 +148,9 @@ void MenuHostGtk::HandleGtkGrabBroke() {
WidgetGtk::HandleGtkGrabBroke();
}
+////////////////////////////////////////////////////////////////////////////////
+// MenuHostGtk, private:
+
void MenuHostGtk::DoCapture() {
DCHECK(!did_input_grab_);
@@ -201,4 +200,12 @@ void MenuHostGtk::CancelAllIfNoDrag() {
menu_controller->CancelAll();
}
+////////////////////////////////////////////////////////////////////////////////
+// NativeMenuHost, public:
+
+// static
+NativeMenuHost* NativeMenuHost::CreateNativeMenuHost(SubmenuView* submenu) {
+ return new MenuHostGtk(submenu);
+}
+
} // namespace views
diff --git a/views/controls/menu/menu_host_gtk.h b/views/controls/menu/menu_host_gtk.h
index 468a351..e0e56d0 100644
--- a/views/controls/menu/menu_host_gtk.h
+++ b/views/controls/menu/menu_host_gtk.h
@@ -7,20 +7,22 @@
#define VIEWS_CONTROLS_MENU_MENU_HOST_GTK_H_
#pragma once
-#include "views/controls/menu/menu_host.h"
+#include "views/controls/menu/native_menu_host.h"
#include "views/widget/widget_gtk.h"
namespace views {
class SubmenuView;
-// MenuHost implementation for Gtk.
-class MenuHostGtk : public WidgetGtk, public MenuHost {
+// NativeMenuHost implementation for Gtk.
+class MenuHostGtk : public WidgetGtk,
+ public NativeMenuHost {
public:
explicit MenuHostGtk(SubmenuView* submenu);
virtual ~MenuHostGtk();
- // MenuHost overrides.
+ private:
+ // Overridden from NativeMenuHost:
virtual void InitMenuHost(gfx::NativeWindow parent,
const gfx::Rect& bounds,
View* contents_view,
@@ -33,20 +35,17 @@ class MenuHostGtk : public WidgetGtk, public MenuHost {
virtual void ReleaseMenuHostCapture() OVERRIDE;
virtual gfx::NativeWindow GetMenuHostWindow() OVERRIDE;
- protected:
+ // Overridden from WidgetGtk:
virtual RootView* CreateRootView() OVERRIDE;
-
- // WidgetGtk overrides:
virtual bool ReleaseCaptureOnMouseReleased() OVERRIDE;
virtual void ReleaseNativeCapture() OVERRIDE;
virtual void OnDestroy(GtkWidget* object) OVERRIDE;
virtual void HandleGtkGrabBroke() OVERRIDE;
virtual void HandleXGrabBroke() OVERRIDE;
- private:
void DoCapture();
- // Cancell all menus unless drag is in progress.
+ // Cancel all menus unless drag is in progress.
void CancelAllIfNoDrag();
// If true, DestroyMenuHost has been invoked.
diff --git a/views/controls/menu/menu_host_win.cc b/views/controls/menu/menu_host_win.cc
index 3e77287..906dda5 100644
--- a/views/controls/menu/menu_host_win.cc
+++ b/views/controls/menu/menu_host_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -12,10 +12,8 @@
namespace views {
-// static
-MenuHost* MenuHost::Create(SubmenuView* submenu_view) {
- return new MenuHostWin(submenu_view);
-}
+////////////////////////////////////////////////////////////////////////////////
+// MenuHostWin, public:
MenuHostWin::MenuHostWin(SubmenuView* submenu)
: destroying_(false),
@@ -30,6 +28,9 @@ MenuHostWin::MenuHostWin(SubmenuView* submenu)
MenuHostWin::~MenuHostWin() {
}
+////////////////////////////////////////////////////////////////////////////////
+// MenuHostWin, NativeMenuHost implementation:
+
void MenuHostWin::InitMenuHost(HWND parent,
const gfx::Rect& bounds,
View* contents_view,
@@ -79,6 +80,9 @@ gfx::NativeWindow MenuHostWin::GetMenuHostWindow() {
return GetNativeView();
}
+////////////////////////////////////////////////////////////////////////////////
+// MenuHostWin, WidgetWin overrides:
+
void MenuHostWin::OnDestroy() {
if (!destroying_) {
// We weren't explicitly told to destroy ourselves, which means the menu was
@@ -107,9 +111,20 @@ bool MenuHostWin::ReleaseCaptureOnMouseReleased() {
return false;
}
+////////////////////////////////////////////////////////////////////////////////
+// MenuHostWin, private:
+
void MenuHostWin::DoCapture() {
owns_capture_ = true;
SetNativeCapture();
}
+////////////////////////////////////////////////////////////////////////////////
+// NativeMenuHost, public:
+
+// static
+NativeMenuHost* NativeMenuHost::CreateNativeMenuHost(SubmenuView* submenu) {
+ return new MenuHostWin(submenu);
+}
+
} // namespace views
diff --git a/views/controls/menu/menu_host_win.h b/views/controls/menu/menu_host_win.h
index 9b0451f..2300aab 100644
--- a/views/controls/menu/menu_host_win.h
+++ b/views/controls/menu/menu_host_win.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -7,7 +7,7 @@
#define VIEWS_CONTROLS_MENU_MENU_HOST_WIN_H_
#pragma once
-#include "views/controls/menu/menu_host.h"
+#include "views/controls/menu/native_menu_host.h"
#include "views/widget/widget_win.h"
namespace views {
@@ -15,37 +15,33 @@ namespace views {
class SubmenuView;
// MenuHost implementation for windows.
-class MenuHostWin : public WidgetWin, public MenuHost {
+class MenuHostWin : public WidgetWin,
+ public NativeMenuHost {
public:
explicit MenuHostWin(SubmenuView* submenu);
virtual ~MenuHostWin();
- // MenuHost overrides:
- virtual void InitMenuHost(HWND parent,
+ private:
+ // Overridden from NativeMenuHost:
+ virtual void InitMenuHost(gfx::NativeWindow parent,
const gfx::Rect& bounds,
View* contents_view,
- bool do_capture);
- virtual bool IsMenuHostVisible();
- virtual void ShowMenuHost(bool do_capture);
- virtual void HideMenuHost();
- virtual void DestroyMenuHost();
- virtual void SetMenuHostBounds(const gfx::Rect& bounds);
- virtual void ReleaseMenuHostCapture();
- virtual gfx::NativeWindow GetMenuHostWindow();
-
- // WidgetWin overrides:
- virtual void OnDestroy();
- virtual void OnCaptureChanged(HWND hwnd);
- virtual void OnCancelMode();
-
- protected:
- virtual RootView* CreateRootView();
+ bool do_capture) OVERRIDE;
+ virtual bool IsMenuHostVisible() OVERRIDE;
+ virtual void ShowMenuHost(bool do_capture) OVERRIDE;
+ virtual void HideMenuHost() OVERRIDE;
+ virtual void DestroyMenuHost() OVERRIDE;
+ virtual void SetMenuHostBounds(const gfx::Rect& bounds) OVERRIDE;
+ virtual void ReleaseMenuHostCapture() OVERRIDE;
+ virtual gfx::NativeWindow GetMenuHostWindow() OVERRIDE;
+
+ // Overridden from WidgetWin:
+ virtual void OnDestroy() OVERRIDE;
+ virtual void OnCaptureChanged(HWND hwnd) OVERRIDE;
+ virtual void OnCancelMode() OVERRIDE;
+ virtual RootView* CreateRootView() OVERRIDE;
+ virtual bool ReleaseCaptureOnMouseReleased() OVERRIDE;
- // Overriden to return false, we do NOT want to release capture on mouse
- // release.
- virtual bool ReleaseCaptureOnMouseReleased();
-
- private:
void DoCapture();
// If true, DestroyMenuHost has been invoked.
diff --git a/views/controls/menu/native_menu_host.h b/views/controls/menu/native_menu_host.h
new file mode 100644
index 0000000..34f5453
--- /dev/null
+++ b/views/controls/menu/native_menu_host.h
@@ -0,0 +1,56 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef VIEWS_CONTROLS_MENU_NATIVE_MENU_HOST_H_
+#define VIEWS_CONTROLS_MENU_NATIVE_MENU_HOST_H_
+
+#include "ui/gfx/native_widget_types.h"
+
+namespace gfx {
+class Rect;
+}
+
+namespace views {
+
+class SubmenuView;
+class View;
+
+class NativeMenuHost {
+ public:
+ virtual ~NativeMenuHost() {}
+
+ static NativeMenuHost* CreateNativeMenuHost(SubmenuView* submenu);
+
+ // Initializes and shows the MenuHost.
+ virtual void InitMenuHost(gfx::NativeWindow parent,
+ const gfx::Rect& bounds,
+ View* contents_view,
+ bool do_capture) = 0;
+
+ // Returns true if the menu host is visible.
+ virtual bool IsMenuHostVisible() = 0;
+
+ // Shows the menu host. If |do_capture| is true the menu host should do a
+ // mouse grab.
+ virtual void ShowMenuHost(bool do_capture) = 0;
+
+ // Hides the menu host.
+ virtual void HideMenuHost() = 0;
+
+ // Destroys and deletes the menu host.
+ virtual void DestroyMenuHost() = 0;
+
+ // Sets the bounds of the menu host.
+ virtual void SetMenuHostBounds(const gfx::Rect& bounds) = 0;
+
+ // Releases a mouse grab installed by |ShowMenuHost|.
+ virtual void ReleaseMenuHostCapture() = 0;
+
+ // Returns the native window of the MenuHost.
+ virtual gfx::NativeWindow GetMenuHostWindow() = 0;
+};
+
+} // namespace views
+
+#endif // VIEWS_CONTROLS_MENU_NATIVE_MENU_HOST_H_ \ No newline at end of file
diff --git a/views/controls/menu/native_menu_host_delegate.h b/views/controls/menu/native_menu_host_delegate.h
new file mode 100644
index 0000000..48b2084
--- /dev/null
+++ b/views/controls/menu/native_menu_host_delegate.h
@@ -0,0 +1,19 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef VIEWS_CONTROLS_MENU_NATIVE_MENU_HOST_DELEGATE_H_
+#define VIEWS_CONTROLS_MENU_NATIVE_MENU_HOST_DELEGATE_H_
+
+namespace views {
+namespace internal {
+
+class NativeMenuHostDelegate {
+ public:
+ virtual ~NativeMenuHostDelegate() {}
+};
+
+} // namespace internal
+} // namespace views
+
+#endif // VIEWS_CONTROLS_MENU_NATIVE_MENU_HOST_DELEGATE_H_ \ No newline at end of file
diff --git a/views/controls/menu/submenu_view.cc b/views/controls/menu/submenu_view.cc
index e6d11bd..3192529 100644
--- a/views/controls/menu/submenu_view.cc
+++ b/views/controls/menu/submenu_view.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -241,7 +241,7 @@ void SubmenuView::ShowAt(gfx::NativeWindow parent,
return;
}
- host_ = MenuHost::Create(this);
+ host_ = new MenuHost(this);
// Force construction of the scroll view container.
GetScrollViewContainer();
// Make sure the first row is visible.
diff --git a/views/views.gyp b/views/views.gyp
index c5706ad..9237634 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -139,6 +139,7 @@
'controls/menu/menu_delegate.h',
'controls/menu/menu_gtk.cc',
'controls/menu/menu_gtk.h',
+ 'controls/menu/menu_host.cc',
'controls/menu/menu_host.h',
'controls/menu/menu_host_root_view.cc',
'controls/menu/menu_host_root_view.h',
@@ -160,6 +161,8 @@
'controls/menu/menu_wrapper.h',
'controls/menu/native_menu_gtk.cc',
'controls/menu/native_menu_gtk.h',
+ 'controls/menu/native_menu_host.h',
+ 'controls/menu/native_menu_host_delegate.h',
'controls/menu/native_menu_win.cc',
'controls/menu/native_menu_win.h',
'controls/menu/native_menu_x.cc',
diff --git a/views/widget/widget_gtk.cc b/views/widget/widget_gtk.cc
index dd44ced..8972ad5 100644
--- a/views/widget/widget_gtk.cc
+++ b/views/widget/widget_gtk.cc
@@ -307,6 +307,16 @@ void WidgetGtk::SetCreateParams(const CreateParams& params) {
MakeTransparent();
if (!params.accept_events)
MakeIgnoreEvents();
+
+ if (params.type == CreateParams::TYPE_MENU) {
+ GdkEvent* event = gtk_get_current_event();
+ if (event) {
+ is_mouse_down_ = event->type == GDK_BUTTON_PRESS ||
+ event->type == GDK_2BUTTON_PRESS ||
+ event->type == GDK_3BUTTON_PRESS;
+ gdk_event_free(event);
+ }
+ }
}
GtkWindow* WidgetGtk::GetTransientParent() const {