]> khamidou — GitHub mirrors - electron.git/commitdiff
linux: Implement context menu with views.
authorCheng Zhao <zcbenz@gmail.com>
Thu, 10 Jul 2014 04:07:01 +0000 (12:07 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 10 Jul 2014 04:07:01 +0000 (12:07 +0800)
atom.gyp
atom/browser/api/atom_api_menu_gtk.cc [deleted file]
atom/browser/api/atom_api_menu_views.cc [new file with mode: 0644]
atom/browser/api/atom_api_menu_views.h [moved from atom/browser/api/atom_api_menu_gtk.h with 51% similarity]
atom/browser/native_window_views.h

index 85dacd9c389793e01c46b77136fc249362d6889a..a4f38b6f42a7c6166e9b82440f599061bfb0933e 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
@@ -54,8 +54,8 @@
       'atom/browser/api/atom_api_dialog.cc',
       'atom/browser/api/atom_api_menu.cc',
       'atom/browser/api/atom_api_menu.h',
-      'atom/browser/api/atom_api_menu_gtk.cc',
-      'atom/browser/api/atom_api_menu_gtk.h',
+      'atom/browser/api/atom_api_menu_views.cc',
+      'atom/browser/api/atom_api_menu_views.h',
       'atom/browser/api/atom_api_menu_mac.h',
       'atom/browser/api/atom_api_menu_mac.mm',
       'atom/browser/api/atom_api_menu_win.cc',
diff --git a/atom/browser/api/atom_api_menu_gtk.cc b/atom/browser/api/atom_api_menu_gtk.cc
deleted file mode 100644 (file)
index a21ce53..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-// Copyright (c) 2014 GitHub, Inc. All rights reserved.
-// Use of this source code is governed by the MIT license that can be
-// found in the LICENSE file.
-
-#include "atom/browser/api/atom_api_menu_gtk.h"
-
-#include "content/public/browser/render_widget_host_view.h"
-#include "ui/gfx/point.h"
-#include "ui/gfx/screen.h"
-
-#include "atom/common/node_includes.h"
-
-namespace atom {
-
-namespace api {
-
-MenuGtk::MenuGtk() {
-}
-
-void MenuGtk::Popup(Window* window) {
-  /*
-  uint32_t triggering_event_time;
-  gfx::Point point;
-
-  NativeWindow* native_window = window->window();
-  GdkEventButton* event = native_window->GetWebContents()->
-      GetRenderWidgetHostView()->GetLastMouseDown();
-  if (event) {
-    triggering_event_time = event->time;
-    point = gfx::Point(event->x_root, event->y_root);
-  } else {
-    triggering_event_time = GDK_CURRENT_TIME;
-    point = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
-  }
-
-  menu_gtk_.reset(new ::MenuGtk(this, model_.get()));
-  menu_gtk_->PopupAsContext(point, triggering_event_time);
-  */
-}
-
-// static
-mate::Wrappable* Menu::Create() {
-  return new MenuGtk();
-}
-
-}  // namespace api
-
-}  // namespace atom
diff --git a/atom/browser/api/atom_api_menu_views.cc b/atom/browser/api/atom_api_menu_views.cc
new file mode 100644 (file)
index 0000000..723b625
--- /dev/null
@@ -0,0 +1,40 @@
+// Copyright (c) 2014 GitHub, Inc. All rights reserved.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#include "atom/browser/api/atom_api_menu_views.h"
+
+#include "atom/browser/native_window_views.h"
+#include "ui/gfx/screen.h"
+#include "ui/views/controls/menu/menu_runner.h"
+
+namespace atom {
+
+namespace api {
+
+MenuViews::MenuViews() {
+}
+
+void MenuViews::Popup(Window* window) {
+  gfx::Point cursor = gfx::Screen::GetNativeScreen()->GetCursorScreenPoint();
+
+  menu_runner_.reset(new views::MenuRunner(model()));
+  views::MenuRunner::RunResult result = menu_runner_->RunMenuAt(
+      static_cast<NativeWindowViews*>(window->window())->widget(),
+      NULL,
+      gfx::Rect(cursor, gfx::Size()),
+      views::MenuItemView::TOPLEFT,
+      ui::MENU_SOURCE_MOUSE,
+      views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU);
+  if (result == views::MenuRunner::MENU_DELETED)
+    LOG(ERROR) << "Menu deleted when running";
+}
+
+// static
+mate::Wrappable* Menu::Create() {
+  return new MenuViews();
+}
+
+}  // namespace api
+
+}  // namespace atom
similarity index 51%
rename from atom/browser/api/atom_api_menu_gtk.h
rename to atom/browser/api/atom_api_menu_views.h
index 3c39fb730b7bd7939d6f0a7af834eb6d8fe8fe5c..13e5a905e359472628745752fc10aeb1c552124a 100644 (file)
@@ -2,32 +2,34 @@
 // Use of this source code is governed by the MIT license that can be
 // found in the LICENSE file.
 
-#ifndef ATOM_BROWSER_API_ATOM_API_MENU_GTK_H_
-#define ATOM_BROWSER_API_ATOM_API_MENU_GTK_H_
+#ifndef ATOM_BROWSER_API_ATOM_API_MENU_VIEWS_H_
+#define ATOM_BROWSER_API_ATOM_API_MENU_VIEWS_H_
 
 #include "atom/browser/api/atom_api_menu.h"
-#include "chrome/browser/ui/gtk/menu_gtk.h"
+
+namespace views {
+class MenuRunner;
+}
 
 namespace atom {
 
 namespace api {
 
-class MenuGtk : public Menu,
-                public ::MenuGtk::Delegate {
+class MenuViews : public Menu {
  public:
-  MenuGtk();
+  MenuViews();
 
  protected:
   virtual void Popup(Window* window) OVERRIDE;
 
  private:
-  scoped_ptr<::MenuGtk> menu_gtk_;
+  scoped_ptr<views::MenuRunner> menu_runner_;
 
-  DISALLOW_COPY_AND_ASSIGN(MenuGtk);
+  DISALLOW_COPY_AND_ASSIGN(MenuViews);
 };
 
 }  // namespace api
 
 }  // namespace atom
 
-#endif  // ATOM_BROWSER_API_ATOM_API_MENU_GTK_H_
+#endif  // ATOM_BROWSER_API_ATOM_API_MENU_VIEWS_H_
index 6fdb691d02b518d90d568d6b0c434a44b84dfa2f..63f69d61b50013e944a17c37c21da55e4a7df75a 100644 (file)
@@ -70,6 +70,7 @@ class NativeWindowViews : public NativeWindow,
   virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
 
   SkRegion* draggable_region() const { return draggable_region_.get(); }
+  views::Widget* widget() const { return window_.get(); }
 
  private:
   // NativeWindow: