summaryrefslogtreecommitdiffstats
path: root/chrome/browser/bookmarks
diff options
context:
space:
mode:
authorerg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-21 23:20:18 +0000
committererg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-21 23:20:18 +0000
commited04d9617d5f244efae81b237df7db41bc142cca (patch)
treeae76f5071fce9e2d3d60086b670f82e6c30cecb4 /chrome/browser/bookmarks
parenta97f2b462ac8062e59849bfa2323d90f461fd5ff (diff)
downloadchromium_src-ed04d9617d5f244efae81b237df7db41bc142cca.zip
chromium_src-ed04d9617d5f244efae81b237df7db41bc142cca.tar.gz
chromium_src-ed04d9617d5f244efae81b237df7db41bc142cca.tar.bz2
Merge BookmarkContextMenuGtk back into BookmarkContextMenu.
Review URL: http://codereview.chromium.org/87038 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14155 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/bookmarks')
-rw-r--r--chrome/browser/bookmarks/bookmark_context_menu.cc118
-rw-r--r--chrome/browser/bookmarks/bookmark_context_menu.h37
-rw-r--r--chrome/browser/bookmarks/bookmark_context_menu_gtk.cc41
-rw-r--r--chrome/browser/bookmarks/bookmark_context_menu_win.cc43
4 files changed, 169 insertions, 70 deletions
diff --git a/chrome/browser/bookmarks/bookmark_context_menu.cc b/chrome/browser/bookmarks/bookmark_context_menu.cc
index 0730d1f..ae0e22c 100644
--- a/chrome/browser/bookmarks/bookmark_context_menu.cc
+++ b/chrome/browser/bookmarks/bookmark_context_menu.cc
@@ -40,6 +40,7 @@ bool NodeHasURLs(BookmarkNode* node) {
return false;
}
+#if defined(OS_WIN)
// EditFolderController -------------------------------------------------------
// EditFolderController manages the editing and/or creation of a folder. If the
@@ -211,6 +212,7 @@ class SelectOnCreationHandler : public BookmarkEditorView::Handler {
DISALLOW_COPY_AND_ASSIGN(SelectOnCreationHandler);
};
+#endif // #if defined(OS_WIN)
} // namespace
@@ -234,50 +236,37 @@ BookmarkContextMenu::BookmarkContextMenu(
configuration_(configuration) {
DCHECK(profile_);
DCHECK(model_->IsLoaded());
- menu_.reset(new views::MenuItemView(this));
+ CreateMenuObject();
+
if (configuration != BOOKMARK_MANAGER_ORGANIZE_MENU) {
if (selection.size() == 1 && selection[0]->is_url()) {
- menu_->AppendMenuItemWithLabel(
- IDS_BOOMARK_BAR_OPEN_ALL,
- l10n_util::GetString(IDS_BOOMARK_BAR_OPEN_IN_NEW_TAB));
- menu_->AppendMenuItemWithLabel(
- IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW,
- l10n_util::GetString(IDS_BOOMARK_BAR_OPEN_IN_NEW_WINDOW));
- menu_->AppendMenuItemWithLabel(
- IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO,
- l10n_util::GetString(IDS_BOOMARK_BAR_OPEN_INCOGNITO));
+ AppendItem(IDS_BOOMARK_BAR_OPEN_ALL, IDS_BOOMARK_BAR_OPEN_IN_NEW_TAB);
+ AppendItem(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW,
+ IDS_BOOMARK_BAR_OPEN_IN_NEW_WINDOW);
+ AppendItem(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO,
+ IDS_BOOMARK_BAR_OPEN_INCOGNITO);
} else {
- menu_->AppendMenuItemWithLabel(
- IDS_BOOMARK_BAR_OPEN_ALL,
- l10n_util::GetString(IDS_BOOMARK_BAR_OPEN_ALL));
- menu_->AppendMenuItemWithLabel(
- IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW,
- l10n_util::GetString(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW));
- menu_->AppendMenuItemWithLabel(
- IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO,
- l10n_util::GetString(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO));
+ AppendItem(IDS_BOOMARK_BAR_OPEN_ALL, IDS_BOOMARK_BAR_OPEN_ALL);
+ AppendItem(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW,
+ IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW);
+ AppendItem(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO,
+ IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO);
}
- menu_->AppendSeparator();
+ AppendSeparator();
}
if (selection.size() == 1 && selection[0]->is_folder()) {
- menu_->AppendMenuItemWithLabel(IDS_BOOKMARK_BAR_RENAME_FOLDER,
- l10n_util::GetString(IDS_BOOKMARK_BAR_RENAME_FOLDER));
+ AppendItem(IDS_BOOKMARK_BAR_RENAME_FOLDER);
} else {
- menu_->AppendMenuItemWithLabel(IDS_BOOKMARK_BAR_EDIT,
- l10n_util::GetString(IDS_BOOKMARK_BAR_EDIT));
+ AppendItem(IDS_BOOKMARK_BAR_EDIT);
}
- menu_->AppendMenuItemWithLabel(
- IDS_BOOKMARK_BAR_REMOVE,
- l10n_util::GetString(IDS_BOOKMARK_BAR_REMOVE));
+ AppendItem(IDS_BOOKMARK_BAR_REMOVE);
if (configuration == BOOKMARK_MANAGER_TABLE ||
configuration == BOOKMARK_MANAGER_TABLE_OTHER ||
configuration == BOOKMARK_MANAGER_ORGANIZE_MENU ||
configuration == BOOKMARK_MANAGER_ORGANIZE_MENU_OTHER) {
- menu_->AppendMenuItemWithLabel(
- IDS_BOOKMARK_MANAGER_SHOW_IN_FOLDER,
- l10n_util::GetString(IDS_BOOKMARK_MANAGER_SHOW_IN_FOLDER));
+ AppendItem(IDS_BOOKMARK_MANAGER_SHOW_IN_FOLDER);
}
if (configuration == BOOKMARK_MANAGER_TABLE ||
@@ -285,39 +274,28 @@ BookmarkContextMenu::BookmarkContextMenu(
configuration == BOOKMARK_MANAGER_TREE ||
configuration == BOOKMARK_MANAGER_ORGANIZE_MENU ||
configuration == BOOKMARK_MANAGER_ORGANIZE_MENU_OTHER) {
- menu_->AppendSeparator();
- menu_->AppendMenuItemWithLabel(
- IDS_CUT, l10n_util::GetString(IDS_CUT));
- menu_->AppendMenuItemWithLabel(
- IDS_COPY, l10n_util::GetString(IDS_COPY));
- menu_->AppendMenuItemWithLabel(
- IDS_PASTE, l10n_util::GetString(IDS_PASTE));
+ AppendSeparator();
+ AppendItem(IDS_CUT);
+ AppendItem(IDS_COPY);
+ AppendItem(IDS_PASTE);
}
if (configuration == BOOKMARK_MANAGER_ORGANIZE_MENU) {
- menu_->AppendSeparator();
- menu_->AppendMenuItemWithLabel(
- IDS_BOOKMARK_MANAGER_SORT,
- l10n_util::GetString(IDS_BOOKMARK_MANAGER_SORT));
+ AppendSeparator();
+ AppendItem(IDS_BOOKMARK_MANAGER_SORT);
}
- menu_->AppendSeparator();
+ AppendSeparator();
- menu_->AppendMenuItemWithLabel(
- IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK,
- l10n_util::GetString(IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK));
- menu_->AppendMenuItemWithLabel(
- IDS_BOOMARK_BAR_NEW_FOLDER,
- l10n_util::GetString(IDS_BOOMARK_BAR_NEW_FOLDER));
+ AppendItem(IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK);
+ AppendItem(IDS_BOOMARK_BAR_NEW_FOLDER);
if (configuration == BOOKMARK_BAR) {
- menu_->AppendSeparator();
- menu_->AppendMenuItemWithLabel(IDS_BOOKMARK_MANAGER,
- l10n_util::GetString(IDS_BOOKMARK_MANAGER));
- menu_->AppendMenuItem(IDS_BOOMARK_BAR_ALWAYS_SHOW,
- l10n_util::GetString(IDS_BOOMARK_BAR_ALWAYS_SHOW),
- views::MenuItemView::CHECKBOX);
+ AppendSeparator();
+ AppendItem(IDS_BOOKMARK_MANAGER);
+ AppendCheckboxItem(IDS_BOOMARK_BAR_ALWAYS_SHOW);
}
+
model_->AddObserver(this);
}
@@ -326,18 +304,6 @@ BookmarkContextMenu::~BookmarkContextMenu() {
model_->RemoveObserver(this);
}
-void BookmarkContextMenu::RunMenuAt(int x, int y) {
- if (!model_->IsLoaded()) {
- NOTREACHED();
- return;
- }
- // width/height don't matter here.
- views::MenuItemView::AnchorPosition anchor =
- (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
- views::MenuItemView::TOPRIGHT : views::MenuItemView::TOPLEFT;
- menu_->RunMenuAt(wnd_, gfx::Rect(x, y, 0, 0), anchor, true);
-}
-
void BookmarkContextMenu::ExecuteCommand(int id) {
switch (id) {
case IDS_BOOMARK_BAR_OPEN_ALL:
@@ -374,6 +340,7 @@ void BookmarkContextMenu::ExecuteCommand(int id) {
return;
}
+#if defined(OS_WIN)
if (selection_[0]->is_url()) {
BookmarkEditorView::Configuration editor_config;
if (configuration_ == BOOKMARK_BAR)
@@ -386,6 +353,9 @@ void BookmarkContextMenu::ExecuteCommand(int id) {
EditFolderController::Show(profile_, wnd_, selection_[0], false,
false);
}
+#else
+ NOTIMPLEMENTED() << "IDS_BOOKMARK_BAR_RENAME_FOLDER / BAR_EDIT";
+#endif
break;
case IDS_BOOKMARK_BAR_REMOVE: {
@@ -403,6 +373,7 @@ void BookmarkContextMenu::ExecuteCommand(int id) {
case IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK: {
UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_Add", profile_);
+#if defined(OS_WIN)
BookmarkEditorView::Configuration editor_config;
BookmarkEditorView::Handler* handler = NULL;
if (configuration_ == BOOKMARK_BAR) {
@@ -414,6 +385,9 @@ void BookmarkContextMenu::ExecuteCommand(int id) {
}
BookmarkEditorView::Show(wnd_, profile_, GetParentForNewNodes(), NULL,
editor_config, handler);
+#else
+ NOTIMPLEMENTED() << "Adding new bookmark not implemented";
+#endif
break;
}
@@ -421,8 +395,12 @@ void BookmarkContextMenu::ExecuteCommand(int id) {
UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_NewFolder",
profile_);
+#if defined(OS_WIN)
EditFolderController::Show(profile_, wnd_, GetParentForNewNodes(),
true, (configuration_ != BOOKMARK_BAR));
+#else
+ NOTIMPLEMENTED() << "New Folder not implemented";
+#endif
break;
}
@@ -439,13 +417,21 @@ void BookmarkContextMenu::ExecuteCommand(int id) {
return;
}
+#if defined(OS_WIN)
if (BookmarkManagerView::current())
BookmarkManagerView::current()->SelectInTree(selection_[0]);
+#else
+ NOTIMPLEMENTED() << "Bookmark Manager not implemented";
+#endif
break;
case IDS_BOOKMARK_MANAGER:
UserMetrics::RecordAction(L"ShowBookmarkManager", profile_);
+#if defined(OS_WIN)
BookmarkManagerView::Show(profile_);
+#else
+ NOTIMPLEMENTED() << "Bookmark Manager not implemented";
+#endif
break;
case IDS_BOOKMARK_MANAGER_SORT:
diff --git a/chrome/browser/bookmarks/bookmark_context_menu.h b/chrome/browser/bookmarks/bookmark_context_menu.h
index 464e0e0..b015f6c 100644
--- a/chrome/browser/bookmarks/bookmark_context_menu.h
+++ b/chrome/browser/bookmarks/bookmark_context_menu.h
@@ -14,6 +14,8 @@
// TODO(port): Port this file.
#if defined(OS_WIN)
#include "chrome/views/controls/menu/chrome_menu.h"
+#elif defined(OS_LINUX)
+#include "chrome/browser/gtk/menu_gtk.h"
#else
#include "chrome/common/temp_scaffolding_stubs.h"
#endif
@@ -24,8 +26,13 @@ class PageNavigator;
// BookmarkContextMenu manages the context menu shown for the
// bookmark bar, items on the bookmark bar, submenus of the bookmark bar and
// the bookmark manager.
-class BookmarkContextMenu : public views::MenuDelegate,
- public BookmarkModelObserver {
+class BookmarkContextMenu : public BookmarkModelObserver,
+#if defined(OS_WIN)
+ public views::MenuDelegate
+#elif defined(OS_LINUX)
+ public MenuGtk::Delegate
+#endif
+{
public:
// Used to configure what the context menu shows.
enum ConfigurationType {
@@ -57,13 +64,18 @@ class BookmarkContextMenu : public views::MenuDelegate,
ConfigurationType configuration);
virtual ~BookmarkContextMenu();
+#if defined(OS_WIN)
// Shows the menu at the specified place.
void RunMenuAt(int x, int y);
// Returns the menu.
views::MenuItemView* menu() const { return menu_.get(); }
+#elif defined(OS_LINUX)
+ // Pops up this menu. This call doesn't block.
+ void PopupAsContext(guint32 event_time);
+#endif
- // Menu::Delegate methods.
+ // Menu::Delegate / MenuGtk::Delegate methods.
virtual void ExecuteCommand(int id);
virtual bool IsItemChecked(int id) const;
virtual bool IsCommandEnabled(int id) const;
@@ -95,6 +107,18 @@ class BookmarkContextMenu : public views::MenuDelegate,
// Invoked from the various bookmark model observer methods. Closes the menu.
void ModelChanged();
+ // Builds the platform specific menu object.
+ void CreateMenuObject();
+
+ // Adds a IDS_* style command to the menu.
+ void AppendItem(int id);
+ // Adds a IDS_* style command to the menu with a different localized string.
+ void AppendItem(int id, int localization_id);
+ // Adds a separator to the menu.
+ void AppendSeparator();
+ // Adds a checkable item to the menu.
+ void AppendCheckboxItem(int id);
+
// Removes the observer from the model and NULLs out model_.
BookmarkModel* RemoveModelObserver();
@@ -112,10 +136,15 @@ class BookmarkContextMenu : public views::MenuDelegate,
PageNavigator* navigator_;
BookmarkNode* parent_;
std::vector<BookmarkNode*> selection_;
- scoped_ptr<views::MenuItemView> menu_;
BookmarkModel* model_;
ConfigurationType configuration_;
+#if defined(OS_WIN)
+ scoped_ptr<views::MenuItemView> menu_;
+#elif defined(OS_LINUX)
+ scoped_ptr<MenuGtk> menu_;
+#endif
+
DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenu);
};
diff --git a/chrome/browser/bookmarks/bookmark_context_menu_gtk.cc b/chrome/browser/bookmarks/bookmark_context_menu_gtk.cc
new file mode 100644
index 0000000..e984ee0
--- /dev/null
+++ b/chrome/browser/bookmarks/bookmark_context_menu_gtk.cc
@@ -0,0 +1,41 @@
+// 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/bookmarks/bookmark_context_menu.h"
+
+#include "chrome/common/l10n_util.h"
+
+void BookmarkContextMenu::PopupAsContext(guint32 event_time) {
+ menu_->PopupAsContext(event_time);
+}
+
+void BookmarkContextMenu::CreateMenuObject() {
+ menu_.reset(new MenuGtk(this, false));
+}
+
+void BookmarkContextMenu::AppendItem(int id) {
+ menu_->AppendMenuItemWithLabel(
+ id,
+ MenuGtk::ConvertAcceleratorsFromWindowsStyle(
+ l10n_util::GetStringUTF8(id)));
+}
+
+void BookmarkContextMenu::AppendItem(int id, int localization_id) {
+ menu_->AppendMenuItemWithLabel(
+ id,
+ MenuGtk::ConvertAcceleratorsFromWindowsStyle(
+ l10n_util::GetStringUTF8(localization_id)));
+}
+
+void BookmarkContextMenu::AppendSeparator() {
+ menu_->AppendSeparator();
+}
+
+void BookmarkContextMenu::AppendCheckboxItem(int id) {
+ // TODO(erg): Add support for checkbox items to gtk.
+ menu_->AppendMenuItemWithLabel(
+ id,
+ MenuGtk::ConvertAcceleratorsFromWindowsStyle(
+ l10n_util::GetStringUTF8(id)));
+}
diff --git a/chrome/browser/bookmarks/bookmark_context_menu_win.cc b/chrome/browser/bookmarks/bookmark_context_menu_win.cc
new file mode 100644
index 0000000..705a55f
--- /dev/null
+++ b/chrome/browser/bookmarks/bookmark_context_menu_win.cc
@@ -0,0 +1,43 @@
+// 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/bookmarks/bookmark_context_menu.h"
+
+#include "chrome/common/l10n_util.h"
+
+void BookmarkContextMenu::RunMenuAt(int x, int y) {
+ if (!model_->IsLoaded()) {
+ NOTREACHED();
+ return;
+ }
+ // width/height don't matter here.
+ views::MenuItemView::AnchorPosition anchor =
+ (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) ?
+ views::MenuItemView::TOPRIGHT : views::MenuItemView::TOPLEFT;
+ menu_->RunMenuAt(wnd_, gfx::Rect(x, y, 0, 0), anchor, true);
+}
+
+void BookmarkContextMenu::CreateMenuObject() {
+ menu_.reset(new views::MenuItemView(this));
+}
+
+void BookmarkContextMenu::AppendItem(int id) {
+ menu_->AppendMenuItemWithLabel(
+ id, l10n_util::GetString(id));
+}
+
+void BookmarkContextMenu::AppendItem(int id, int localization_id) {
+ menu_->AppendMenuItemWithLabel(
+ id, l10n_util::GetString(localization_id));
+}
+
+void BookmarkContextMenu::AppendSeparator() {
+ menu_->AppendSeparator();
+}
+
+void BookmarkContextMenu::AppendCheckboxItem(int id) {
+ menu_->AppendMenuItem(id,
+ l10n_util::GetString(id),
+ views::MenuItemView::CHECKBOX);
+}