summaryrefslogtreecommitdiffstats
path: root/chrome/browser/tab_contents
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-09 19:21:21 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-09 19:21:21 +0000
commit1d78e832493c2b6f27cdf50a7ad6bfcd65c6e206 (patch)
tree26ea2ce939e982135b14670f30f751c903afd1bd /chrome/browser/tab_contents
parentc557bc0c37f16d49d95ff46eb5691895007cc241 (diff)
downloadchromium_src-1d78e832493c2b6f27cdf50a7ad6bfcd65c6e206.zip
chromium_src-1d78e832493c2b6f27cdf50a7ad6bfcd65c6e206.tar.gz
chromium_src-1d78e832493c2b6f27cdf50a7ad6bfcd65c6e206.tar.bz2
Implement right click context menu on gtk.
Review URL: http://codereview.chromium.org/40266 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@11271 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/tab_contents')
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu_gtk.cc106
-rw-r--r--chrome/browser/tab_contents/render_view_context_menu_gtk.h57
-rw-r--r--chrome/browser/tab_contents/web_contents_view_gtk.cc4
-rw-r--r--chrome/browser/tab_contents/web_contents_view_gtk.h7
4 files changed, 173 insertions, 1 deletions
diff --git a/chrome/browser/tab_contents/render_view_context_menu_gtk.cc b/chrome/browser/tab_contents/render_view_context_menu_gtk.cc
new file mode 100644
index 0000000..dad440a
--- /dev/null
+++ b/chrome/browser/tab_contents/render_view_context_menu_gtk.cc
@@ -0,0 +1,106 @@
+// 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 "chrome/browser/tab_contents/render_view_context_menu_gtk.h"
+
+#include "base/string_util.h"
+#include "webkit/glue/context_menu.h"
+
+RenderViewContextMenuGtk::RenderViewContextMenuGtk(
+ WebContents* web_contents,
+ const ContextMenuParams& params)
+ : RenderViewContextMenu(web_contents, params),
+ making_submenu_(false) {
+ InitMenu(params.node);
+ DoneMakingMenu(&menu_);
+ gtk_menu_.reset(new MenuGtk(this, menu_.data(), NULL));
+}
+
+RenderViewContextMenuGtk::~RenderViewContextMenuGtk() {
+}
+
+void RenderViewContextMenuGtk::Popup() {
+ gtk_menu_->PopupAsContext();
+}
+
+bool RenderViewContextMenuGtk::IsCommandEnabled(int id) const {
+ return IsItemCommandEnabled(id);
+}
+
+bool RenderViewContextMenuGtk::IsItemChecked(int id) const {
+ return ItemIsChecked(id);
+}
+
+void RenderViewContextMenuGtk::ExecuteCommand(int id) {
+ ExecuteItemCommand(id);
+}
+
+std::string RenderViewContextMenuGtk::GetLabel(int id) const {
+ std::map<int, std::string>::const_iterator label = label_map_.find(id);
+
+ if (label != label_map_.end())
+ return label->second;
+
+ return std::string();
+}
+
+void RenderViewContextMenuGtk::AppendMenuItem(int id) {
+ AppendItem(id, std::wstring(), MENU_NORMAL);
+}
+
+void RenderViewContextMenuGtk::AppendMenuItem(int id,
+ const std::wstring& label) {
+ AppendItem(id, label, MENU_NORMAL);
+}
+
+void RenderViewContextMenuGtk::AppendRadioMenuItem(int id,
+ const std::wstring& label) {
+ AppendItem(id, label, MENU_RADIO);
+}
+
+void RenderViewContextMenuGtk::AppendCheckboxMenuItem(int id,
+ const std::wstring& label) {
+ AppendItem(id, label, MENU_CHECKBOX);
+}
+
+void RenderViewContextMenuGtk::AppendSeparator() {
+ AppendItem(0, std::wstring(), MENU_SEPARATOR);
+}
+
+void RenderViewContextMenuGtk::StartSubMenu(int id, const std::wstring& label) {
+ AppendItem(id, label, MENU_NORMAL);
+ making_submenu_ = true;
+}
+
+void RenderViewContextMenuGtk::FinishSubMenu() {
+ DoneMakingMenu(&submenu_);
+ menu_[menu_.size() - 1].submenu = submenu_.data();
+ making_submenu_ = false;
+}
+
+void RenderViewContextMenuGtk::AppendItem(
+ int id, const std::wstring& label, MenuItemType type) {
+ MenuCreateMaterial menu_create_material = {
+ type, id, 0, 0, NULL
+ };
+
+ if (label.empty())
+ menu_create_material.label_id = id;
+ else
+ label_map_[id] = WideToUTF8(label);
+
+ std::vector<MenuCreateMaterial>* menu =
+ making_submenu_ ? &submenu_ : &menu_;
+ menu->push_back(menu_create_material);
+}
+
+// static
+void RenderViewContextMenuGtk::DoneMakingMenu(
+ std::vector<MenuCreateMaterial>* menu) {
+ static MenuCreateMaterial end_menu_item = {
+ MENU_END, 0, 0, 0, NULL
+ };
+ menu->push_back(end_menu_item);
+}
+
diff --git a/chrome/browser/tab_contents/render_view_context_menu_gtk.h b/chrome/browser/tab_contents/render_view_context_menu_gtk.h
new file mode 100644
index 0000000..0776010
--- /dev/null
+++ b/chrome/browser/tab_contents/render_view_context_menu_gtk.h
@@ -0,0 +1,57 @@
+// 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.
+
+#ifndef CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_GTK_H_
+#define CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_GTK_H_
+
+#include <map>
+#include <string>
+#include <vector>
+
+#include "base/scoped_ptr.h"
+#include "chrome/browser/gtk/menu_gtk.h"
+#include "chrome/browser/tab_contents/render_view_context_menu.h"
+
+class ContextMenuParams;
+
+// TODO(port): we need accelerator support for this class.
+class RenderViewContextMenuGtk : public RenderViewContextMenu,
+ public MenuGtk::Delegate {
+ public:
+ RenderViewContextMenuGtk(WebContents* web_contents,
+ const ContextMenuParams& params);
+
+ ~RenderViewContextMenuGtk();
+
+ // Show the menu at the current cursor location.
+ void Popup();
+
+ // Menu::Delegate implementation ---------------------------------------------
+ virtual bool IsCommandEnabled(int id) const;
+ virtual bool IsItemChecked(int id) const;
+ virtual void ExecuteCommand(int id);
+ virtual std::string GetLabel(int id) const;
+
+ protected:
+ // RenderViewContextMenu implementation --------------------------------------
+ virtual void AppendMenuItem(int id);
+ virtual void AppendMenuItem(int id, const std::wstring& label);
+ virtual void AppendRadioMenuItem(int id, const std::wstring& label);
+ virtual void AppendCheckboxMenuItem(int id, const std::wstring& label);
+ virtual void AppendSeparator();
+ virtual void StartSubMenu(int id, const std::wstring& label);
+ virtual void FinishSubMenu();
+
+ private:
+ void AppendItem(int id, const std::wstring& label, MenuItemType type);
+ static void DoneMakingMenu(std::vector<MenuCreateMaterial>* menu);
+
+ scoped_ptr<MenuGtk> gtk_menu_;
+ std::map<int, std::string> label_map_;
+ std::vector<MenuCreateMaterial> menu_;
+ std::vector<MenuCreateMaterial> submenu_;
+ bool making_submenu_;
+};
+
+#endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_CONTEXT_MENU_GTK_H_
diff --git a/chrome/browser/tab_contents/web_contents_view_gtk.cc b/chrome/browser/tab_contents/web_contents_view_gtk.cc
index d90c9ae..7c86751 100644
--- a/chrome/browser/tab_contents/web_contents_view_gtk.cc
+++ b/chrome/browser/tab_contents/web_contents_view_gtk.cc
@@ -12,6 +12,7 @@
#include "base/gfx/rect.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_widget_host_view_gtk.h"
+#include "chrome/browser/tab_contents/render_view_context_menu_gtk.h"
#include "chrome/browser/tab_contents/tab_contents_delegate.h"
#include "chrome/browser/tab_contents/web_contents.h"
@@ -183,7 +184,8 @@ void WebContentsViewGtk::OnFindReply(int request_id,
}
void WebContentsViewGtk::ShowContextMenu(const ContextMenuParams& params) {
- NOTIMPLEMENTED();
+ context_menu_.reset(new RenderViewContextMenuGtk(web_contents_, params));
+ context_menu_->Popup();
}
void WebContentsViewGtk::StartDragging(const WebDropData& drop_data) {
diff --git a/chrome/browser/tab_contents/web_contents_view_gtk.h b/chrome/browser/tab_contents/web_contents_view_gtk.h
index 8975ce6..d920b89 100644
--- a/chrome/browser/tab_contents/web_contents_view_gtk.h
+++ b/chrome/browser/tab_contents/web_contents_view_gtk.h
@@ -5,8 +5,11 @@
#ifndef CHROME_BROWSER_TAB_CONTENTS_WEB_CONTENTS_VIEW_GTK_H_
#define CHROME_BROWSER_TAB_CONTENTS_WEB_CONTENTS_VIEW_GTK_H_
+#include "base/scoped_ptr.h"
#include "chrome/browser/tab_contents/web_contents_view.h"
+class RenderViewContextMenuGtk;
+
class WebContentsViewGtk : public WebContentsView {
public:
// The corresponding WebContents is passed in the constructor, and manages our
@@ -65,6 +68,10 @@ class WebContentsViewGtk : public WebContentsView {
GtkWidget* vbox_;
+ // The context menu is reset every time we show it, but we keep a pointer to
+ // between uses so that it won't go out of scope before we're done with it.
+ scoped_ptr<RenderViewContextMenuGtk> context_menu_;
+
DISALLOW_COPY_AND_ASSIGN(WebContentsViewGtk);
};