summaryrefslogtreecommitdiffstats
path: root/chrome/browser
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
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')
-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
-rw-r--r--chrome/browser/browser.vcproj4
-rw-r--r--chrome/browser/gtk/bookmark_bar_gtk.cc6
-rw-r--r--chrome/browser/gtk/bookmark_bar_gtk.h4
-rw-r--r--chrome/browser/gtk/bookmark_context_menu_gtk.cc353
-rw-r--r--chrome/browser/gtk/bookmark_context_menu_gtk.h116
9 files changed, 178 insertions, 544 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);
+}
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj
index 4433269..a698e6f 100644
--- a/chrome/browser/browser.vcproj
+++ b/chrome/browser/browser.vcproj
@@ -562,6 +562,10 @@
>
</File>
<File
+ RelativePath=".\bookmarks\bookmark_context_menu_win.cc"
+ >
+ </File>
+ <File
RelativePath=".\bookmarks\bookmark_drag_data.cc"
>
</File>
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc
index 7819ad4..0c8346e 100644
--- a/chrome/browser/gtk/bookmark_bar_gtk.cc
+++ b/chrome/browser/gtk/bookmark_bar_gtk.cc
@@ -5,9 +5,9 @@
#include "chrome/browser/gtk/bookmark_bar_gtk.h"
#include "base/gfx/gtk_util.h"
+#include "chrome/browser/bookmarks/bookmark_context_menu.h"
#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/browser.h"
-#include "chrome/browser/gtk/bookmark_context_menu_gtk.h"
#include "chrome/browser/gtk/custom_button.h"
#include "chrome/browser/gtk/gtk_chrome_button.h"
#include "chrome/browser/metrics/user_metrics.h"
@@ -398,11 +398,11 @@ void BookmarkBarGtk::PopupMenuForNode(GtkWidget* sender, BookmarkNode* node,
nodes.push_back(parent);
}
- current_context_menu_.reset(new BookmarkContextMenuGtk(
+ current_context_menu_.reset(new BookmarkContextMenu(
GTK_WINDOW(gtk_widget_get_toplevel(sender)),
profile_, browser_, page_navigator_,
parent, nodes,
- BookmarkContextMenuGtk::BOOKMARK_BAR));
+ BookmarkContextMenu::BOOKMARK_BAR));
current_context_menu_->PopupAsContext(event->time);
}
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.h b/chrome/browser/gtk/bookmark_bar_gtk.h
index 930a26f..0a37d51 100644
--- a/chrome/browser/gtk/bookmark_bar_gtk.h
+++ b/chrome/browser/gtk/bookmark_bar_gtk.h
@@ -13,7 +13,7 @@
#include "chrome/common/owned_widget_gtk.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
-class BookmarkContextMenuGtk;
+class BookmarkContextMenu;
class Browser;
class CustomContainerButton;
class PageNavigator;
@@ -194,7 +194,7 @@ class BookmarkBarGtk : public BookmarkModelObserver {
// The last displayed right click menu, or NULL if no menus have been
// displayed yet.
- scoped_ptr<BookmarkContextMenuGtk> current_context_menu_;
+ scoped_ptr<BookmarkContextMenu> current_context_menu_;
};
#endif // CHROME_BROWSER_GTK_BOOKMARK_BAR_GTK_H_
diff --git a/chrome/browser/gtk/bookmark_context_menu_gtk.cc b/chrome/browser/gtk/bookmark_context_menu_gtk.cc
deleted file mode 100644
index f6fc56f..0000000
--- a/chrome/browser/gtk/bookmark_context_menu_gtk.cc
+++ /dev/null
@@ -1,353 +0,0 @@
-// 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/gtk/bookmark_context_menu_gtk.h"
-
-#include "chrome/browser/bookmarks/bookmark_model.h"
-#include "chrome/browser/bookmarks/bookmark_utils.h"
-#include "chrome/browser/browser.h"
-#include "chrome/browser/metrics/user_metrics.h"
-#include "chrome/browser/profile.h"
-#include "chrome/common/l10n_util.h"
-#include "grit/generated_resources.h"
-#include "grit/theme_resources.h"
-
-namespace {
-
-// Returns true if the specified node is of type URL, or has a descendant
-// of type URL.
-bool NodeHasURLs(BookmarkNode* node) {
- if (node->is_url())
- return true;
-
- for (int i = 0; i < node->GetChildCount(); ++i) {
- if (NodeHasURLs(node->GetChild(i)))
- return true;
- }
- return false;
-}
-
-} // namespace
-
-BookmarkContextMenuGtk::BookmarkContextMenuGtk(
- GtkWindow* window,
- Profile* profile,
- Browser* browser,
- PageNavigator* navigator,
- BookmarkNode* parent,
- const std::vector<BookmarkNode*>& selection,
- ConfigurationType configuration)
- : window_(window),
- profile_(profile),
- browser_(browser),
- navigator_(navigator),
- parent_(parent),
- selection_(selection),
- model_(profile->GetBookmarkModel()),
- configuration_(configuration),
- menu_(new MenuGtk(this, false)) {
- if (configuration != BOOKMARK_MANAGER_ORGANIZE_MENU) {
- if (selection.size() == 1 && selection[0]->is_url()) {
- 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 {
- 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);
- }
- AppendSeparator();
- }
-
- if (selection.size() == 1 && selection[0]->is_folder()) {
- AppendItem(IDS_BOOKMARK_BAR_RENAME_FOLDER);
- } else {
- AppendItem(IDS_BOOKMARK_BAR_EDIT);
- }
- 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) {
- AppendItem(IDS_BOOKMARK_MANAGER_SHOW_IN_FOLDER);
- }
-
- if (configuration == BOOKMARK_MANAGER_TABLE ||
- configuration == BOOKMARK_MANAGER_TABLE_OTHER ||
- configuration == BOOKMARK_MANAGER_TREE ||
- configuration == BOOKMARK_MANAGER_ORGANIZE_MENU ||
- configuration == BOOKMARK_MANAGER_ORGANIZE_MENU_OTHER) {
- AppendSeparator();
- AppendItem(IDS_CUT);
- AppendItem(IDS_COPY);
- AppendItem(IDS_PASTE);
- }
-
- if (configuration == BOOKMARK_MANAGER_ORGANIZE_MENU) {
- AppendSeparator();
- AppendItem(IDS_BOOKMARK_MANAGER_SORT);
- }
-
- AppendSeparator();
-
- AppendItem(IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK);
- AppendItem(IDS_BOOMARK_BAR_NEW_FOLDER);
-
- if (configuration == BOOKMARK_BAR) {
- AppendSeparator();
- AppendItem(IDS_BOOKMARK_MANAGER);
- AppendItem(IDS_BOOMARK_BAR_ALWAYS_SHOW);
- }
-
- model_->AddObserver(this);
-}
-
-BookmarkContextMenuGtk::~BookmarkContextMenuGtk() {
- if (model_)
- model_->RemoveObserver(this);
-}
-
-void BookmarkContextMenuGtk::PopupAsContext(guint32 event_time) {
- menu_->PopupAsContext(event_time);
-}
-
-bool BookmarkContextMenuGtk::IsCommandEnabled(int index) const {
- bool is_root_node =
- (selection_.size() == 1 &&
- selection_[0]->GetParent() == model_->root_node());
- switch (index) {
- case IDS_BOOMARK_BAR_OPEN_INCOGNITO:
- return !profile_->IsOffTheRecord();
-
- case IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO:
- return HasURLs() && !profile_->IsOffTheRecord();
-
- case IDS_BOOMARK_BAR_OPEN_ALL:
- case IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW:
- return HasURLs();
-
- case IDS_BOOKMARK_BAR_RENAME_FOLDER:
- case IDS_BOOKMARK_BAR_EDIT:
- return selection_.size() == 1 && !is_root_node;
-
- case IDS_BOOKMARK_BAR_REMOVE:
- return !selection_.empty() && !is_root_node;
-
- case IDS_BOOKMARK_MANAGER_SHOW_IN_FOLDER:
- return (configuration_ == BOOKMARK_MANAGER_TABLE_OTHER ||
- configuration_ == BOOKMARK_MANAGER_ORGANIZE_MENU_OTHER) &&
- selection_.size() == 1;
-
- case IDS_BOOKMARK_MANAGER_SORT:
- return parent_ && parent_ != model_->root_node();
-
- case IDS_BOOMARK_BAR_NEW_FOLDER:
- case IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK:
- return GetParentForNewNodes() != NULL;
-
- case IDS_COPY:
- case IDS_CUT:
- return selection_.size() > 0 && !is_root_node;
-
- // TODO(erg): Port boomark_utils::CanPasteFromClipboard
- // case IDS_PASTE:
- // // Always paste to parent.
- // return bookmark_utils::CanPasteFromClipboard(parent_);
- }
- return true;
-}
-
-void BookmarkContextMenuGtk::ExecuteCommand(int index) {
- switch (index) {
- case IDS_BOOMARK_BAR_OPEN_ALL:
- case IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO:
- case IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW: {
- PageNavigator* navigator = browser_ ?
- browser_->GetSelectedTabContents() : navigator_;
- WindowOpenDisposition initial_disposition;
- if (index == IDS_BOOMARK_BAR_OPEN_ALL) {
- initial_disposition = NEW_FOREGROUND_TAB;
- UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_OpenAll",
- profile_);
- } else if (index == IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW) {
- initial_disposition = NEW_WINDOW;
- UserMetrics::RecordAction(
- L"BookmarkBar_ContextMenu_OpenAllInNewWindow", profile_);
- } else {
- initial_disposition = OFF_THE_RECORD;
- UserMetrics::RecordAction(
- L"BookmarkBar_ContextMenu_OpenAllIncognito", profile_);
- }
-
- bookmark_utils::OpenAll(window_, profile_, navigator,
- selection_, initial_disposition);
- break;
- }
-
- case IDS_BOOKMARK_BAR_RENAME_FOLDER:
- case IDS_BOOKMARK_BAR_EDIT: {
- UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_Edit", profile_);
-
- if (selection_.size() != 1) {
- NOTREACHED();
- return;
- }
-
- if (selection_[0]->is_url()) {
- NOTIMPLEMENTED() << "Bookmark editor not implemented";
- } else {
- NOTIMPLEMENTED() << "Folder editor not implemented";
- }
- break;
- }
-
- case IDS_BOOKMARK_BAR_REMOVE: {
- UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_Remove", profile_);
- BookmarkModel* model = RemoveModelObserver();
-
- for (size_t i = 0; i < selection_.size(); ++i) {
- model->Remove(selection_[i]->GetParent(),
- selection_[i]->GetParent()->IndexOfChild(selection_[i]));
- }
- selection_.clear();
- break;
- }
-
- case IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK: {
- UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_Add", profile_);
- NOTIMPLEMENTED() << "Adding new bookmark not implemented";
- break;
- }
-
- case IDS_BOOMARK_BAR_NEW_FOLDER: {
- UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_NewFolder",
- profile_);
-
- NOTIMPLEMENTED() << "EditFolderController not implemented";
- break;
- }
-
- case IDS_BOOMARK_BAR_ALWAYS_SHOW: {
- bookmark_utils::ToggleWhenVisible(profile_);
- break;
- }
-
- case IDS_BOOKMARK_MANAGER_SHOW_IN_FOLDER: {
- UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_ShowInFolder",
- profile_);
-
- if (selection_.size() != 1) {
- NOTREACHED();
- return;
- }
-
- NOTIMPLEMENTED() << "Bookmark Manager not implemented";
- break;
- }
-
- case IDS_BOOKMARK_MANAGER: {
- UserMetrics::RecordAction(L"ShowBookmarkManager", profile_);
- NOTIMPLEMENTED() << "Bookmark Manager not implemented";
- break;
- }
-
- case IDS_BOOKMARK_MANAGER_SORT: {
- UserMetrics::RecordAction(L"BookmarkManager_Sort", profile_);
- model_->SortChildren(parent_);
- break;
- }
-
- case IDS_COPY:
- case IDS_CUT:
- case IDS_PASTE: {
- NOTIMPLEMENTED() << "Cut/Copy/Paste not implemented";
- break;
- }
-
- default:
- NOTREACHED();
- }
-}
-
-void BookmarkContextMenuGtk::AppendItem(int id) {
- menu_->AppendMenuItemWithLabel(
- id,
- MenuGtk::ConvertAcceleratorsFromWindowsStyle(
- l10n_util::GetStringUTF8(id)));
-}
-
-void BookmarkContextMenuGtk::AppendItem(int id, int localization_id) {
- menu_->AppendMenuItemWithLabel(
- id,
- MenuGtk::ConvertAcceleratorsFromWindowsStyle(
- l10n_util::GetStringUTF8(localization_id)));
-}
-
-void BookmarkContextMenuGtk::AppendSeparator() {
- menu_->AppendSeparator();
-}
-
-void BookmarkContextMenuGtk::BookmarkModelBeingDeleted(BookmarkModel* model) {
- ModelChanged();
-}
-
-void BookmarkContextMenuGtk::BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
- int old_index,
- BookmarkNode* new_parent,
- int new_index) {
- ModelChanged();
-}
-
-void BookmarkContextMenuGtk::BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
- int index) {
- ModelChanged();
-}
-
-void BookmarkContextMenuGtk::BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
- int index,
- BookmarkNode* node) {
- ModelChanged();
-}
-
-void BookmarkContextMenuGtk::BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node) {
- ModelChanged();
-}
-
-void BookmarkContextMenuGtk::BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node) {
- ModelChanged();
-}
-
-void BookmarkContextMenuGtk::ModelChanged() {
- menu_->Cancel();
-}
-
-BookmarkModel* BookmarkContextMenuGtk::RemoveModelObserver() {
- BookmarkModel* model = model_;
- model_->RemoveObserver(this);
- model_ = NULL;
- return model;
-}
-
-bool BookmarkContextMenuGtk::HasURLs() const {
- for (size_t i = 0; i < selection_.size(); ++i) {
- if (NodeHasURLs(selection_[i]))
- return true;
- }
- return false;
-}
-
-BookmarkNode* BookmarkContextMenuGtk::GetParentForNewNodes() const {
- return (selection_.size() == 1 && selection_[0]->is_folder()) ?
- selection_[0] : parent_;
-}
diff --git a/chrome/browser/gtk/bookmark_context_menu_gtk.h b/chrome/browser/gtk/bookmark_context_menu_gtk.h
deleted file mode 100644
index 26ecee1a..0000000
--- a/chrome/browser/gtk/bookmark_context_menu_gtk.h
+++ /dev/null
@@ -1,116 +0,0 @@
-// 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_GTK_BOOKMARK_CONTEXT_MENU_GTK_H_
-#define CHROME_BROWSER_GTK_BOOKMARK_CONTEXT_MENU_GTK_H_
-
-#include <vector>
-
-#include "base/gfx/native_widget_types.h"
-#include "chrome/browser/bookmarks/bookmark_model.h"
-#include "chrome/browser/gtk/menu_gtk.h"
-
-class Profile;
-class Browser;
-class PageNavigator;
-
-typedef struct _GtkWindow GtkWindow;
-
-// The context menu that opens or modifies bookmarks. (This is not the menu
-// that displays folders contents.)
-//
-// TODO(erg): This is a copy of
-// ./browser/bookmarks/bookmark_context_menu.{cc,h} and should be merged with
-// that file once it is sufficiently de-views-ed.
-class BookmarkContextMenuGtk : public MenuGtk::Delegate,
- public BookmarkModelObserver {
- public:
- // Used to configure what the context menu shows.
- enum ConfigurationType {
- BOOKMARK_BAR,
- BOOKMARK_MANAGER_TABLE,
- // Used when the source is the table in the bookmark manager and the table
- // is showing recently bookmarked or searched.
- BOOKMARK_MANAGER_TABLE_OTHER,
- BOOKMARK_MANAGER_TREE,
- BOOKMARK_MANAGER_ORGANIZE_MENU,
- // Used when the source is the bookmark manager and the table is showing
- // recently bookmarked or searched.
- BOOKMARK_MANAGER_ORGANIZE_MENU_OTHER
- };
-
- BookmarkContextMenuGtk(GtkWindow* window,
- Profile* profile,
- Browser* browser,
- PageNavigator* navigator,
- BookmarkNode* parent,
- const std::vector<BookmarkNode*>& selection,
- ConfigurationType configuration);
- virtual ~BookmarkContextMenuGtk();
-
- // Pops up this menu.
- void PopupAsContext(guint32 event_time);
-
- // Overridden from MenuGtk::Delegate:
- virtual bool IsCommandEnabled(int index) const;
- virtual void ExecuteCommand(int index);
-
- private:
- // BookmarkModelObserver method. Any change to the model results in closing
- // the menu.
- virtual void Loaded(BookmarkModel* model) {}
- virtual void BookmarkModelBeingDeleted(BookmarkModel* model);
- virtual void BookmarkNodeMoved(BookmarkModel* model,
- BookmarkNode* old_parent,
- int old_index,
- BookmarkNode* new_parent,
- int new_index);
- virtual void BookmarkNodeAdded(BookmarkModel* model,
- BookmarkNode* parent,
- int index);
- virtual void BookmarkNodeRemoved(BookmarkModel* model,
- BookmarkNode* parent,
- int index,
- BookmarkNode* node);
- virtual void BookmarkNodeChanged(BookmarkModel* model,
- BookmarkNode* node);
- virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
- BookmarkNode* node) {}
- virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
- BookmarkNode* node);
-
- // 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();
-
- // Invoked from the various bookmark model observer methods. Closes the menu.
- void ModelChanged();
-
- // Removes the observer from the model and NULLs out model_.
- BookmarkModel* RemoveModelObserver();
-
- // Returns true if selection_ has at least one bookmark of type url.
- bool HasURLs() const;
-
- // Returns the parent for newly created folders/bookmarks. If selection_
- // has one element and it is a folder, selection_[0] is returned, otherwise
- // parent_ is returned.
- BookmarkNode* GetParentForNewNodes() const;
-
- gfx::NativeWindow window_;
- Profile* profile_;
- Browser* browser_;
- PageNavigator* navigator_;
- BookmarkNode* parent_;
- std::vector<BookmarkNode*> selection_;
- BookmarkModel* model_;
- ConfigurationType configuration_;
-
- scoped_ptr<MenuGtk> menu_;
-};
-
-#endif // CHROME_BROWSER_GTK_BOOKMARK_CONTEXT_MENU_GTK_H_