summaryrefslogtreecommitdiffstats
path: root/views/controls/menu/menu_host_gtk.cc
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-24 15:46:45 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-24 15:46:45 +0000
commita87ecb3c7170caa40810def524fbae1aee4d3533 (patch)
tree947732a745f124feda7ace8ac466cf75c746db62 /views/controls/menu/menu_host_gtk.cc
parentde1b764f404e5fb6975e7cc9de7120d46e28dcfd (diff)
downloadchromium_src-a87ecb3c7170caa40810def524fbae1aee4d3533.zip
chromium_src-a87ecb3c7170caa40810def524fbae1aee4d3533.tar.gz
chromium_src-a87ecb3c7170caa40810def524fbae1aee4d3533.tar.bz2
Further refactoring of menus for GTK. I've now separated out
everything and menus some what work on GTK. I need to get painting working and I'm sure there will be fine tuning, but I want to check in all this splitting of files before someone else needs change one of these files. Thankfully I wrote an interactive ui test that exercises much of this code, and it still passes:) BUG=none TEST=thoroughly test bookmark menus on windows to make sure I didn't break them. Review URL: http://codereview.chromium.org/174274 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@24098 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/menu/menu_host_gtk.cc')
-rw-r--r--views/controls/menu/menu_host_gtk.cc99
1 files changed, 99 insertions, 0 deletions
diff --git a/views/controls/menu/menu_host_gtk.cc b/views/controls/menu/menu_host_gtk.cc
new file mode 100644
index 0000000..b87aa23
--- /dev/null
+++ b/views/controls/menu/menu_host_gtk.cc
@@ -0,0 +1,99 @@
+// Copyright (c) 2009 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_gtk.h"
+
+#include <gdk/gdk.h>
+
+#include "views/controls/menu/menu_controller.h"
+#include "views/controls/menu/menu_host_root_view.h"
+#include "views/controls/menu/menu_item_view.h"
+#include "views/controls/menu/submenu_view.h"
+
+namespace views {
+
+MenuHost::MenuHost(SubmenuView* submenu)
+ : WidgetGtk(WidgetGtk::TYPE_POPUP),
+ closed_(false),
+ submenu_(submenu) {
+ // TODO(sky): make sure this is needed.
+ GdkModifierType current_event_mod;
+ if (gtk_get_current_event_state(&current_event_mod)) {
+ set_mouse_down(
+ (current_event_mod & GDK_BUTTON1_MASK) ||
+ (current_event_mod & GDK_BUTTON2_MASK) ||
+ (current_event_mod & GDK_BUTTON3_MASK) ||
+ (current_event_mod & GDK_BUTTON4_MASK) ||
+ (current_event_mod & GDK_BUTTON5_MASK));
+ }
+}
+
+void MenuHost::Init(gfx::NativeView parent,
+ const gfx::Rect& bounds,
+ View* contents_view,
+ bool do_capture) {
+ WidgetGtk::Init(parent, bounds);
+ SetContentsView(contents_view);
+ // TODO(sky): see if there is some way to show without changing focus.
+ Show();
+ if (do_capture) {
+ DoGrab();
+#ifdef DEBUG_MENU
+ DLOG(INFO) << "Doing capture";
+#endif
+ }
+}
+
+void MenuHost::Show() {
+ WidgetGtk::Show();
+}
+
+void MenuHost::Hide() {
+ if (closed_) {
+ // We're already closed, nothing to do.
+ // This is invoked twice if the first time just hid us, and the second
+ // time deleted Closed (deleted) us.
+ return;
+ }
+ // The menus are freed separately, and possibly before the window is closed,
+ // remove them so that View doesn't try to access deleted objects.
+ static_cast<MenuHostRootView*>(GetRootView())->suspend_events();
+ GetRootView()->RemoveAllChildViews(false);
+ closed_ = true;
+ ReleaseGrab();
+ WidgetGtk::Hide();
+}
+
+void MenuHost::HideWindow() {
+ // Make sure we release capture before hiding.
+ ReleaseGrab();
+ WidgetGtk::Hide();
+}
+
+void MenuHost::ReleaseCapture() {
+ ReleaseGrab();
+}
+
+RootView* MenuHost::CreateRootView() {
+ return new MenuHostRootView(this, submenu_);
+}
+
+void MenuHost::OnCancelMode() {
+ // TODO(sky): see if there is an equivalent to this.
+ if (!closed_) {
+#ifdef DEBUG_MENU
+ DLOG(INFO) << "OnCanceMode, closing menu";
+#endif
+ submenu_->GetMenuItem()->GetMenuController()->Cancel(true);
+ }
+}
+
+// Overriden to return false, we do NOT want to release capture on mouse
+// release.
+bool MenuHost::ReleaseCaptureOnMouseReleased() {
+ return false;
+}
+
+} // namespace views