diff options
author | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-06 21:06:48 +0000 |
---|---|---|
committer | viettrungluu@chromium.org <viettrungluu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-06 21:06:48 +0000 |
commit | 0568e6ca9cba8826a42eed080e569dba3fe6afec (patch) | |
tree | 855ac473db7b5ade1a4159953559edde7e6ef679 /chrome | |
parent | 90eeddb230b95ef7c31b072d60f4de0a9c0c875a (diff) | |
download | chromium_src-0568e6ca9cba8826a42eed080e569dba3fe6afec.zip chromium_src-0568e6ca9cba8826a42eed080e569dba3fe6afec.tar.gz chromium_src-0568e6ca9cba8826a42eed080e569dba3fe6afec.tar.bz2 |
Get rid of some dead bookmark context menu code.
(Continuing fallout of native bookmark manager deletion.)
More refactoring still to come.
BUG=38908
TEST=bookmark bar context menu still works as before
Review URL: http://codereview.chromium.org/1986003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46624 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
12 files changed, 84 insertions, 220 deletions
diff --git a/chrome/browser/bookmarks/bookmark_context_menu_controller.cc b/chrome/browser/bookmarks/bookmark_context_menu_controller.cc index 2e3f67e..0e5adf1f 100644 --- a/chrome/browser/bookmarks/bookmark_context_menu_controller.cc +++ b/chrome/browser/bookmarks/bookmark_context_menu_controller.cc @@ -42,15 +42,13 @@ BookmarkContextMenuController::BookmarkContextMenuController( Profile* profile, PageNavigator* navigator, const BookmarkNode* parent, - const std::vector<const BookmarkNode*>& selection, - ConfigurationType configuration) + const std::vector<const BookmarkNode*>& selection) : parent_window_(parent_window), delegate_(delegate), profile_(profile), navigator_(navigator), parent_(parent), selection_(selection), - configuration_(configuration), model_(profile->GetBookmarkModel()) { DCHECK(profile_); DCHECK(model_->IsLoaded()); @@ -66,22 +64,20 @@ BookmarkContextMenuController::~BookmarkContextMenuController() { } void BookmarkContextMenuController::BuildMenu() { - if (configuration_ != BOOKMARK_MANAGER_ORGANIZE_MENU) { - if (selection_.size() == 1 && selection_[0]->is_url()) { - AddItem(IDS_BOOMARK_BAR_OPEN_ALL, - IDS_BOOMARK_BAR_OPEN_IN_NEW_TAB); - AddItem(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW, - IDS_BOOMARK_BAR_OPEN_IN_NEW_WINDOW); - AddItem(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO, - IDS_BOOMARK_BAR_OPEN_INCOGNITO); - } else { - AddItem(IDS_BOOMARK_BAR_OPEN_ALL); - AddItem(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW); - AddItem(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO); - } - AddSeparator(); + if (selection_.size() == 1 && selection_[0]->is_url()) { + AddItem(IDS_BOOMARK_BAR_OPEN_ALL, + IDS_BOOMARK_BAR_OPEN_IN_NEW_TAB); + AddItem(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW, + IDS_BOOMARK_BAR_OPEN_IN_NEW_WINDOW); + AddItem(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO, + IDS_BOOMARK_BAR_OPEN_INCOGNITO); + } else { + AddItem(IDS_BOOMARK_BAR_OPEN_ALL); + AddItem(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW); + AddItem(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO); } + AddSeparator(); if (selection_.size() == 1 && selection_[0]->is_folder()) { AddItem(IDS_BOOKMARK_BAR_RENAME_FOLDER); } else { @@ -96,21 +92,13 @@ void BookmarkContextMenuController::BuildMenu() { AddSeparator(); AddItem(IDS_BOOKMARK_BAR_REMOVE); - if (configuration_ == BOOKMARK_MANAGER_ORGANIZE_MENU) { - AddSeparator(); - AddItem(IDS_BOOKMARK_MANAGER_SORT); - } - AddSeparator(); - AddItem(IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK); AddItem(IDS_BOOMARK_BAR_NEW_FOLDER); - if (configuration_ == BOOKMARK_BAR) { - AddSeparator(); - AddItem(IDS_BOOKMARK_MANAGER); - AddCheckboxItem(IDS_BOOMARK_BAR_ALWAYS_SHOW); - } + AddSeparator(); + AddItem(IDS_BOOKMARK_MANAGER); + AddCheckboxItem(IDS_BOOMARK_BAR_ALWAYS_SHOW); } void BookmarkContextMenuController::AddItem(int id) { @@ -171,14 +159,9 @@ void BookmarkContextMenuController::ExecuteCommand(int id) { } if (selection_[0]->is_url()) { - BookmarkEditor::Configuration editor_config; - if (configuration_ == BOOKMARK_BAR) - editor_config = BookmarkEditor::SHOW_TREE; - else - editor_config = BookmarkEditor::NO_TREE; BookmarkEditor::Show(parent_window_, profile_, parent_, BookmarkEditor::EditDetails(selection_[0]), - editor_config); + BookmarkEditor::SHOW_TREE); } else { BookmarkFolderEditorController::Show(profile_, parent_window_, selection_[0], -1, BookmarkFolderEditorController::NONE); @@ -203,14 +186,11 @@ void BookmarkContextMenuController::ExecuteCommand(int id) { UserMetricsAction("BookmarkBar_ContextMenu_Add"), profile_); - BookmarkEditor::Configuration editor_config = - (configuration_ == BOOKMARK_BAR) ? BookmarkEditor::SHOW_TREE : - BookmarkEditor::NO_TREE; // TODO: this should honor the index from GetParentForNewNodes. BookmarkEditor::Show( parent_window_, profile_, bookmark_utils::GetParentForNewNodes(parent_, selection_, NULL), - BookmarkEditor::EditDetails(), editor_config); + BookmarkEditor::EditDetails(), BookmarkEditor::SHOW_TREE); break; } @@ -221,11 +201,8 @@ void BookmarkContextMenuController::ExecuteCommand(int id) { int index; const BookmarkNode* parent = bookmark_utils::GetParentForNewNodes(parent_, selection_, &index); - uint32 details = BookmarkFolderEditorController::IS_NEW; - if (configuration_ != BOOKMARK_BAR) - details |= BookmarkFolderEditorController::SHOW_IN_MANAGER; BookmarkFolderEditorController::Show(profile_, parent_window_, parent, - index, details); + index, BookmarkFolderEditorController::IS_NEW); break; } @@ -245,12 +222,6 @@ void BookmarkContextMenuController::ExecuteCommand(int id) { } break; - case IDS_BOOKMARK_MANAGER_SORT: - UserMetrics::RecordAction(UserMetricsAction("BookmarkManager_Sort"), - profile_); - model_->SortChildren(parent_); - break; - case IDS_CUT: bookmark_utils::CopyToClipboard(model_, selection_, true); break; @@ -305,9 +276,6 @@ bool BookmarkContextMenuController::IsCommandIdEnabled(int command_id) const { case IDS_BOOKMARK_BAR_REMOVE: return !selection_.empty() && !is_root_node; - 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 bookmark_utils::GetParentForNewNodes( @@ -319,8 +287,8 @@ bool BookmarkContextMenuController::IsCommandIdEnabled(int command_id) const { case IDS_PASTE: // Paste to selection from the Bookmark Bar, to parent_ everywhere else - return (configuration_ == BOOKMARK_BAR && !selection_.empty() && - bookmark_utils::CanPasteFromClipboard(selection_[0])) || + return (!selection_.empty() && + bookmark_utils::CanPasteFromClipboard(selection_[0])) || bookmark_utils::CanPasteFromClipboard(parent_); } return true; diff --git a/chrome/browser/bookmarks/bookmark_context_menu_controller.h b/chrome/browser/bookmarks/bookmark_context_menu_controller.h index 3d3bebd..5169c63 100644 --- a/chrome/browser/bookmarks/bookmark_context_menu_controller.h +++ b/chrome/browser/bookmarks/bookmark_context_menu_controller.h @@ -37,50 +37,30 @@ class BookmarkContextMenuControllerDelegate { class BookmarkContextMenuController : public BaseBookmarkModelObserver, public menus::SimpleMenuModel::Delegate { 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 - }; - // Creates the bookmark context menu. // |profile| is used for opening urls as well as enabling 'open incognito'. // |browser| is used to determine the PageNavigator and may be null. // |navigator| is used if |browser| is null, and is provided for testing. // |parent| is the parent for newly created nodes if |selection| is empty. // |selection| is the nodes the context menu operates on and may be empty. - // |configuration| determines which items to show. BookmarkContextMenuController( gfx::NativeWindow parent_window, BookmarkContextMenuControllerDelegate* delegate, Profile* profile, PageNavigator* navigator, const BookmarkNode* parent, - const std::vector<const BookmarkNode*>& selection, - ConfigurationType configuration); + const std::vector<const BookmarkNode*>& selection); virtual ~BookmarkContextMenuController(); void BuildMenu(); - menus::SimpleMenuModel* menu_model() { - return menu_model_.get(); - } - + menus::SimpleMenuModel* menu_model() const { return menu_model_.get(); } // menus::SimpleMenuModel::Delegate implementation: virtual bool IsCommandIdChecked(int command_id) const; virtual bool IsCommandIdEnabled(int command_id) const; - virtual bool GetAcceleratorForCommandId( - int command_id, - menus::Accelerator* accelerator) { + virtual bool GetAcceleratorForCommandId(int command_id, + menus::Accelerator* accelerator) { return false; } virtual void ExecuteCommand(int command_id); @@ -112,7 +92,6 @@ class BookmarkContextMenuController : public BaseBookmarkModelObserver, PageNavigator* navigator_; const BookmarkNode* parent_; std::vector<const BookmarkNode*> selection_; - ConfigurationType configuration_; BookmarkModel* model_; scoped_ptr<menus::SimpleMenuModel> menu_model_; diff --git a/chrome/browser/bookmarks/bookmark_context_menu_controller_unittest.cc b/chrome/browser/bookmarks/bookmark_context_menu_controller_unittest.cc index db14a44..26dd65e 100644 --- a/chrome/browser/bookmarks/bookmark_context_menu_controller_unittest.cc +++ b/chrome/browser/bookmarks/bookmark_context_menu_controller_unittest.cc @@ -106,8 +106,7 @@ TEST_F(BookmarkContextMenuControllerTest, DeleteURL) { std::vector<const BookmarkNode*> nodes; nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0)); BookmarkContextMenuController controller( - NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes, - BookmarkContextMenuController::BOOKMARK_BAR); + NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); GURL url = model_->GetBookmarkBarNode()->GetChild(0)->GetURL(); ASSERT_TRUE(controller.IsCommandIdEnabled(IDS_BOOKMARK_BAR_REMOVE)); // Delete the URL. @@ -133,8 +132,7 @@ TEST_F(BookmarkContextMenuControllerTest, OpenAll) { TEST_F(BookmarkContextMenuControllerTest, EmptyNodes) { BookmarkContextMenuController controller( NULL, NULL, profile_.get(), NULL, model_->other_node(), - std::vector<const BookmarkNode*>(), - BookmarkContextMenuController::BOOKMARK_BAR); + std::vector<const BookmarkNode*>()); EXPECT_FALSE(controller.IsCommandIdEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); EXPECT_FALSE( controller.IsCommandIdEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); @@ -153,8 +151,7 @@ TEST_F(BookmarkContextMenuControllerTest, SingleURL) { std::vector<const BookmarkNode*> nodes; nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0)); BookmarkContextMenuController controller( - NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), - nodes, BookmarkContextMenuController::BOOKMARK_BAR); + NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); EXPECT_TRUE(controller.IsCommandIdEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); EXPECT_TRUE( controller.IsCommandIdEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); @@ -174,8 +171,7 @@ TEST_F(BookmarkContextMenuControllerTest, MultipleURLs) { nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0)); nodes.push_back(model_->GetBookmarkBarNode()->GetChild(1)->GetChild(0)); BookmarkContextMenuController controller( - NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), - nodes, BookmarkContextMenuController::BOOKMARK_BAR); + NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); EXPECT_TRUE(controller.IsCommandIdEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); EXPECT_TRUE( controller.IsCommandIdEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); @@ -194,8 +190,7 @@ TEST_F(BookmarkContextMenuControllerTest, SingleFolder) { std::vector<const BookmarkNode*> nodes; nodes.push_back(model_->GetBookmarkBarNode()->GetChild(2)); BookmarkContextMenuController controller( - NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), - nodes, BookmarkContextMenuController::BOOKMARK_BAR); + NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); EXPECT_FALSE(controller.IsCommandIdEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); EXPECT_FALSE( controller.IsCommandIdEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); @@ -215,8 +210,7 @@ TEST_F(BookmarkContextMenuControllerTest, MultipleEmptyFolders) { nodes.push_back(model_->GetBookmarkBarNode()->GetChild(2)); nodes.push_back(model_->GetBookmarkBarNode()->GetChild(3)); BookmarkContextMenuController controller( - NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), - nodes, BookmarkContextMenuController::BOOKMARK_BAR); + NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); EXPECT_FALSE(controller.IsCommandIdEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); EXPECT_FALSE( controller.IsCommandIdEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); @@ -236,8 +230,7 @@ TEST_F(BookmarkContextMenuControllerTest, MultipleFoldersWithURLs) { nodes.push_back(model_->GetBookmarkBarNode()->GetChild(3)); nodes.push_back(model_->GetBookmarkBarNode()->GetChild(4)); BookmarkContextMenuController controller( - NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), - nodes, BookmarkContextMenuController::BOOKMARK_BAR); + NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); EXPECT_TRUE(controller.IsCommandIdEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); EXPECT_TRUE( controller.IsCommandIdEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); @@ -255,8 +248,7 @@ TEST_F(BookmarkContextMenuControllerTest, DisableIncognito) { std::vector<const BookmarkNode*> nodes; nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0)); BookmarkContextMenuController controller( - NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), - nodes, BookmarkContextMenuController::BOOKMARK_BAR); + NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); profile_->set_off_the_record(true); EXPECT_FALSE(controller.IsCommandIdEnabled(IDS_BOOMARK_BAR_OPEN_INCOGNITO)); EXPECT_FALSE( @@ -268,8 +260,7 @@ TEST_F(BookmarkContextMenuControllerTest, DisabledItemsWithOtherNode) { std::vector<const BookmarkNode*> nodes; nodes.push_back(model_->other_node()); BookmarkContextMenuController controller( - NULL, NULL, profile_.get(), NULL, nodes[0], nodes, - BookmarkContextMenuController::BOOKMARK_BAR); + NULL, NULL, profile_.get(), NULL, nodes[0], nodes); EXPECT_FALSE(controller.IsCommandIdEnabled(IDS_BOOKMARK_BAR_EDIT)); EXPECT_FALSE(controller.IsCommandIdEnabled(IDS_BOOKMARK_BAR_REMOVE)); } @@ -279,8 +270,7 @@ TEST_F(BookmarkContextMenuControllerTest, DisabledItemsWithOtherNode) { TEST_F(BookmarkContextMenuControllerTest, EmptyNodesNullParent) { BookmarkContextMenuController controller( NULL, NULL, profile_.get(), NULL, NULL, - std::vector<const BookmarkNode*>(), - BookmarkContextMenuController::BOOKMARK_MANAGER_ORGANIZE_MENU); + std::vector<const BookmarkNode*>()); EXPECT_FALSE(controller.IsCommandIdEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); EXPECT_FALSE( controller.IsCommandIdEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); @@ -298,8 +288,7 @@ TEST_F(BookmarkContextMenuControllerTest, CutCopyPasteNode) { nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0)); scoped_ptr<BookmarkContextMenuController> controller( new BookmarkContextMenuController( - NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes, - BookmarkContextMenuController::BOOKMARK_BAR)); + NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes)); EXPECT_TRUE(controller->IsCommandIdEnabled(IDS_COPY)); EXPECT_TRUE(controller->IsCommandIdEnabled(IDS_CUT)); @@ -307,8 +296,7 @@ TEST_F(BookmarkContextMenuControllerTest, CutCopyPasteNode) { controller->ExecuteCommand(IDS_COPY); controller.reset(new BookmarkContextMenuController( - NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes, - BookmarkContextMenuController::BOOKMARK_BAR)); + NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes)); int old_count = model_->GetBookmarkBarNode()->GetChildCount(); controller->ExecuteCommand(IDS_PASTE); @@ -318,8 +306,7 @@ TEST_F(BookmarkContextMenuControllerTest, CutCopyPasteNode) { model_->GetBookmarkBarNode()->GetChild(1)->GetURL()); controller.reset(new BookmarkContextMenuController( - NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes, - BookmarkContextMenuController::BOOKMARK_BAR)); + NULL, NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes)); // Cut the URL. controller->ExecuteCommand(IDS_CUT); ASSERT_TRUE(model_->GetBookmarkBarNode()->GetChild(0)->is_url()); diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc index 89a48ae..f8d9808 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.cc +++ b/chrome/browser/gtk/bookmark_bar_gtk.cc @@ -960,8 +960,7 @@ void BookmarkBarGtk::PopupMenuForNode(GtkWidget* sender, GtkWindow* window = GTK_WINDOW(gtk_widget_get_toplevel(sender)); current_context_menu_controller_.reset( new BookmarkContextMenuController( - window, this, profile_, page_navigator_, parent, nodes, - BookmarkContextMenuController::BOOKMARK_BAR)); + window, this, profile_, page_navigator_, parent, nodes)); current_context_menu_.reset( new MenuGtk(NULL, current_context_menu_controller_->menu_model())); current_context_menu_->PopupAsContext(event->time); diff --git a/chrome/browser/gtk/bookmark_menu_controller_gtk.cc b/chrome/browser/gtk/bookmark_menu_controller_gtk.cc index 491c885..eff5391 100644 --- a/chrome/browser/gtk/bookmark_menu_controller_gtk.cc +++ b/chrome/browser/gtk/bookmark_menu_controller_gtk.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -241,8 +241,7 @@ gboolean BookmarkMenuController::OnButtonPressed( context_menu_controller_.reset( new BookmarkContextMenuController( parent_window_, this, profile_, - page_navigator_, parent, nodes, - BookmarkContextMenuController::BOOKMARK_BAR)); + page_navigator_, parent, nodes)); context_menu_.reset( new MenuGtk(NULL, context_menu_controller_->menu_model())); diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc index d6b1690..400b63e 100644 --- a/chrome/browser/views/bookmark_bar_view.cc +++ b/chrome/browser/views/bookmark_bar_view.cc @@ -1243,8 +1243,7 @@ void BookmarkBarView::ShowContextMenu(View* source, PageNavigator* navigator = browser() ? browser()->GetSelectedTabContents() : NULL; BookmarkContextMenu controller(GetWindow()->GetNativeWindow(), GetProfile(), - navigator, parent, nodes, - BookmarkContextMenuControllerViews::BOOKMARK_BAR); + navigator, parent, nodes); controller.RunMenuAt(p); } diff --git a/chrome/browser/views/bookmark_context_menu.cc b/chrome/browser/views/bookmark_context_menu.cc index 9ef9506..cdd778a 100644 --- a/chrome/browser/views/bookmark_context_menu.cc +++ b/chrome/browser/views/bookmark_context_menu.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -19,13 +19,10 @@ BookmarkContextMenu::BookmarkContextMenu( Profile* profile, PageNavigator* page_navigator, const BookmarkNode* parent, - const std::vector<const BookmarkNode*>& selection, - BookmarkContextMenuControllerViews::ConfigurationType configuration) + const std::vector<const BookmarkNode*>& selection) : ALLOW_THIS_IN_INITIALIZER_LIST( - controller_(new BookmarkContextMenuControllerViews(parent_window, this, - profile, page_navigator, - parent, selection, - configuration))), + controller_(new BookmarkContextMenuControllerViews(parent_window, + this, profile, page_navigator, parent, selection))), parent_window_(parent_window), ALLOW_THIS_IN_INITIALIZER_LIST(menu_(new views::MenuItemView(this))), observer_(NULL) { diff --git a/chrome/browser/views/bookmark_context_menu.h b/chrome/browser/views/bookmark_context_menu.h index fe4da5b..d141277 100644 --- a/chrome/browser/views/bookmark_context_menu.h +++ b/chrome/browser/views/bookmark_context_menu.h @@ -27,8 +27,7 @@ class BookmarkContextMenu : public BookmarkContextMenuControllerViewsDelegate, Profile* profile, PageNavigator* page_navigator, const BookmarkNode* parent, - const std::vector<const BookmarkNode*>& selection, - BookmarkContextMenuControllerViews::ConfigurationType configuration); + const std::vector<const BookmarkNode*>& selection); virtual ~BookmarkContextMenu(); // Shows the context menu at the specified point. diff --git a/chrome/browser/views/bookmark_context_menu_controller_views.cc b/chrome/browser/views/bookmark_context_menu_controller_views.cc index 8eda213..9d13c3e 100644 --- a/chrome/browser/views/bookmark_context_menu_controller_views.cc +++ b/chrome/browser/views/bookmark_context_menu_controller_views.cc @@ -42,15 +42,13 @@ BookmarkContextMenuControllerViews::BookmarkContextMenuControllerViews( Profile* profile, PageNavigator* navigator, const BookmarkNode* parent, - const std::vector<const BookmarkNode*>& selection, - ConfigurationType configuration) + const std::vector<const BookmarkNode*>& selection) : parent_window_(parent_window), delegate_(delegate), profile_(profile), navigator_(navigator), parent_(parent), selection_(selection), - configuration_(configuration), model_(profile->GetBookmarkModel()) { DCHECK(profile_); DCHECK(model_->IsLoaded()); @@ -63,22 +61,20 @@ BookmarkContextMenuControllerViews::~BookmarkContextMenuControllerViews() { } void BookmarkContextMenuControllerViews::BuildMenu() { - if (configuration_ != BOOKMARK_MANAGER_ORGANIZE_MENU) { - if (selection_.size() == 1 && selection_[0]->is_url()) { - delegate_->AddItemWithStringId(IDS_BOOMARK_BAR_OPEN_ALL, - IDS_BOOMARK_BAR_OPEN_IN_NEW_TAB); - delegate_->AddItemWithStringId(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW, - IDS_BOOMARK_BAR_OPEN_IN_NEW_WINDOW); - delegate_->AddItemWithStringId(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO, - IDS_BOOMARK_BAR_OPEN_INCOGNITO); - } else { - delegate_->AddItem(IDS_BOOMARK_BAR_OPEN_ALL); - delegate_->AddItem(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW); - delegate_->AddItem(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO); - } - delegate_->AddSeparator(); + if (selection_.size() == 1 && selection_[0]->is_url()) { + delegate_->AddItemWithStringId(IDS_BOOMARK_BAR_OPEN_ALL, + IDS_BOOMARK_BAR_OPEN_IN_NEW_TAB); + delegate_->AddItemWithStringId(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW, + IDS_BOOMARK_BAR_OPEN_IN_NEW_WINDOW); + delegate_->AddItemWithStringId(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO, + IDS_BOOMARK_BAR_OPEN_INCOGNITO); + } else { + delegate_->AddItem(IDS_BOOMARK_BAR_OPEN_ALL); + delegate_->AddItem(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW); + delegate_->AddItem(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO); } + delegate_->AddSeparator(); if (selection_.size() == 1 && selection_[0]->is_folder()) { delegate_->AddItem(IDS_BOOKMARK_BAR_RENAME_FOLDER); } else { @@ -93,21 +89,13 @@ void BookmarkContextMenuControllerViews::BuildMenu() { delegate_->AddSeparator(); delegate_->AddItem(IDS_BOOKMARK_BAR_REMOVE); - if (configuration_ == BOOKMARK_MANAGER_ORGANIZE_MENU) { - delegate_->AddSeparator(); - delegate_->AddItem(IDS_BOOKMARK_MANAGER_SORT); - } - delegate_->AddSeparator(); - delegate_->AddItem(IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK); delegate_->AddItem(IDS_BOOMARK_BAR_NEW_FOLDER); - if (configuration_ == BOOKMARK_BAR) { - delegate_->AddSeparator(); - delegate_->AddItem(IDS_BOOKMARK_MANAGER); - delegate_->AddCheckboxItem(IDS_BOOMARK_BAR_ALWAYS_SHOW); - } + delegate_->AddSeparator(); + delegate_->AddItem(IDS_BOOKMARK_MANAGER); + delegate_->AddCheckboxItem(IDS_BOOMARK_BAR_ALWAYS_SHOW); } void BookmarkContextMenuControllerViews::ExecuteCommand(int id) { @@ -150,14 +138,9 @@ void BookmarkContextMenuControllerViews::ExecuteCommand(int id) { } if (selection_[0]->is_url()) { - BookmarkEditor::Configuration editor_config; - if (configuration_ == BOOKMARK_BAR) - editor_config = BookmarkEditor::SHOW_TREE; - else - editor_config = BookmarkEditor::NO_TREE; BookmarkEditor::Show(parent_window_, profile_, parent_, BookmarkEditor::EditDetails(selection_[0]), - editor_config); + BookmarkEditor::SHOW_TREE); } else { BookmarkFolderEditorController::Show(profile_, parent_window_, selection_[0], -1, BookmarkFolderEditorController::NONE); @@ -182,14 +165,11 @@ void BookmarkContextMenuControllerViews::ExecuteCommand(int id) { UserMetrics::RecordAction( UserMetricsAction("BookmarkBar_ContextMenu_Add"), profile_); - BookmarkEditor::Configuration editor_config = - (configuration_ == BOOKMARK_BAR) ? BookmarkEditor::SHOW_TREE : - BookmarkEditor::NO_TREE; // TODO: this should honor the index from GetParentForNewNodes. BookmarkEditor::Show( parent_window_, profile_, bookmark_utils::GetParentForNewNodes(parent_, selection_, NULL), - BookmarkEditor::EditDetails(), editor_config); + BookmarkEditor::EditDetails(), BookmarkEditor::SHOW_TREE); break; } @@ -200,11 +180,8 @@ void BookmarkContextMenuControllerViews::ExecuteCommand(int id) { int index; const BookmarkNode* parent = bookmark_utils::GetParentForNewNodes(parent_, selection_, &index); - uint32 details = BookmarkFolderEditorController::IS_NEW; - if (configuration_ != BOOKMARK_BAR) - details |= BookmarkFolderEditorController::SHOW_IN_MANAGER; BookmarkFolderEditorController::Show(profile_, parent_window_, parent, - index, details); + index, BookmarkFolderEditorController::IS_NEW); break; } @@ -224,12 +201,6 @@ void BookmarkContextMenuControllerViews::ExecuteCommand(int id) { } break; - case IDS_BOOKMARK_MANAGER_SORT: - UserMetrics::RecordAction(UserMetricsAction("BookmarkManager_Sort"), - profile_); - model->SortChildren(parent_); - break; - case IDS_CUT: delegate_->WillRemoveBookmarks(selection_); bookmark_utils::CopyToClipboard(model, selection_, true); @@ -283,9 +254,6 @@ bool BookmarkContextMenuControllerViews::IsCommandEnabled(int id) const { case IDS_BOOKMARK_BAR_REMOVE: return !selection_.empty() && !is_root_node; - 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 bookmark_utils::GetParentForNewNodes( @@ -297,9 +265,9 @@ bool BookmarkContextMenuControllerViews::IsCommandEnabled(int id) const { case IDS_PASTE: // Paste to selection from the Bookmark Bar, to parent_ everywhere else - return (configuration_ == BOOKMARK_BAR && !selection_.empty() && + return (!selection_.empty() && bookmark_utils::CanPasteFromClipboard(selection_[0])) || - bookmark_utils::CanPasteFromClipboard(parent_); + bookmark_utils::CanPasteFromClipboard(parent_); } return true; } diff --git a/chrome/browser/views/bookmark_context_menu_controller_views.h b/chrome/browser/views/bookmark_context_menu_controller_views.h index ec84294..41433dc 100644 --- a/chrome/browser/views/bookmark_context_menu_controller_views.h +++ b/chrome/browser/views/bookmark_context_menu_controller_views.h @@ -42,35 +42,19 @@ class BookmarkContextMenuControllerViewsDelegate { // menu shown for any bookmark item. class BookmarkContextMenuControllerViews : public BaseBookmarkModelObserver { 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 - }; - // Creates the bookmark context menu. // |profile| is used for opening urls as well as enabling 'open incognito'. // |browser| is used to determine the PageNavigator and may be null. // |navigator| is used if |browser| is null, and is provided for testing. // |parent| is the parent for newly created nodes if |selection| is empty. // |selection| is the nodes the context menu operates on and may be empty. - // |configuration| determines which items to show. BookmarkContextMenuControllerViews( gfx::NativeWindow parent_window, BookmarkContextMenuControllerViewsDelegate* delegate, Profile* profile, PageNavigator* navigator, const BookmarkNode* parent, - const std::vector<const BookmarkNode*>& selection, - ConfigurationType configuration); + const std::vector<const BookmarkNode*>& selection); virtual ~BookmarkContextMenuControllerViews(); void BuildMenu(); @@ -100,7 +84,6 @@ class BookmarkContextMenuControllerViews : public BaseBookmarkModelObserver { PageNavigator* navigator_; const BookmarkNode* parent_; std::vector<const BookmarkNode*> selection_; - ConfigurationType configuration_; BookmarkModel* model_; DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenuControllerViews); diff --git a/chrome/browser/views/bookmark_context_menu_test.cc b/chrome/browser/views/bookmark_context_menu_test.cc index 09a56e2..97a2397 100644 --- a/chrome/browser/views/bookmark_context_menu_test.cc +++ b/chrome/browser/views/bookmark_context_menu_test.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2010 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. @@ -110,8 +110,7 @@ TEST_F(BookmarkContextMenuTest, DeleteURL) { std::vector<const BookmarkNode*> nodes; nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0)); BookmarkContextMenu controller( - NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes, - BookmarkContextMenuControllerViews::BOOKMARK_BAR); + NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); GURL url = model_->GetBookmarkBarNode()->GetChild(0)->GetURL(); ASSERT_TRUE(controller.IsCommandEnabled(IDS_BOOKMARK_BAR_REMOVE)); // Delete the URL. @@ -137,8 +136,7 @@ TEST_F(BookmarkContextMenuTest, OpenAll) { TEST_F(BookmarkContextMenuTest, EmptyNodes) { BookmarkContextMenu controller( NULL, profile_.get(), NULL, model_->other_node(), - std::vector<const BookmarkNode*>(), - BookmarkContextMenuControllerViews::BOOKMARK_BAR); + std::vector<const BookmarkNode*>()); EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); EXPECT_FALSE( controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); @@ -156,8 +154,7 @@ TEST_F(BookmarkContextMenuTest, SingleURL) { std::vector<const BookmarkNode*> nodes; nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0)); BookmarkContextMenu controller( - NULL, profile_.get(), NULL, nodes[0]->GetParent(), - nodes, BookmarkContextMenuControllerViews::BOOKMARK_BAR); + NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); EXPECT_TRUE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); EXPECT_TRUE( controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); @@ -176,8 +173,7 @@ TEST_F(BookmarkContextMenuTest, MultipleURLs) { nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0)); nodes.push_back(model_->GetBookmarkBarNode()->GetChild(1)->GetChild(0)); BookmarkContextMenu controller( - NULL, profile_.get(), NULL, nodes[0]->GetParent(), - nodes, BookmarkContextMenuControllerViews::BOOKMARK_BAR); + NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); EXPECT_TRUE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); EXPECT_TRUE( controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); @@ -195,8 +191,7 @@ TEST_F(BookmarkContextMenuTest, SingleFolder) { std::vector<const BookmarkNode*> nodes; nodes.push_back(model_->GetBookmarkBarNode()->GetChild(2)); BookmarkContextMenu controller( - NULL, profile_.get(), NULL, nodes[0]->GetParent(), - nodes, BookmarkContextMenuControllerViews::BOOKMARK_BAR); + NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); EXPECT_FALSE( controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); @@ -215,8 +210,7 @@ TEST_F(BookmarkContextMenuTest, MultipleEmptyFolders) { nodes.push_back(model_->GetBookmarkBarNode()->GetChild(2)); nodes.push_back(model_->GetBookmarkBarNode()->GetChild(3)); BookmarkContextMenu controller( - NULL, profile_.get(), NULL, nodes[0]->GetParent(), - nodes, BookmarkContextMenuControllerViews::BOOKMARK_BAR); + NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); EXPECT_FALSE( controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); @@ -235,8 +229,7 @@ TEST_F(BookmarkContextMenuTest, MultipleFoldersWithURLs) { nodes.push_back(model_->GetBookmarkBarNode()->GetChild(3)); nodes.push_back(model_->GetBookmarkBarNode()->GetChild(4)); BookmarkContextMenu controller( - NULL, profile_.get(), NULL, nodes[0]->GetParent(), - nodes, BookmarkContextMenuControllerViews::BOOKMARK_BAR); + NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); EXPECT_TRUE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); EXPECT_TRUE( controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); @@ -253,8 +246,7 @@ TEST_F(BookmarkContextMenuTest, DisableIncognito) { std::vector<const BookmarkNode*> nodes; nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0)); BookmarkContextMenu controller( - NULL, profile_.get(), NULL, nodes[0]->GetParent(), - nodes, BookmarkContextMenuControllerViews::BOOKMARK_BAR); + NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes); profile_->set_off_the_record(true); EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_INCOGNITO)); EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_INCOGNITO)); @@ -265,8 +257,7 @@ TEST_F(BookmarkContextMenuTest, DisabledItemsWithOtherNode) { std::vector<const BookmarkNode*> nodes; nodes.push_back(model_->other_node()); BookmarkContextMenu controller( - NULL, profile_.get(), NULL, nodes[0], nodes, - BookmarkContextMenuControllerViews::BOOKMARK_BAR); + NULL, profile_.get(), NULL, nodes[0], nodes); EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOKMARK_BAR_EDIT)); EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOKMARK_BAR_REMOVE)); } @@ -275,8 +266,7 @@ TEST_F(BookmarkContextMenuTest, DisabledItemsWithOtherNode) { // parent. TEST_F(BookmarkContextMenuTest, EmptyNodesNullParent) { BookmarkContextMenu controller( - NULL, profile_.get(), NULL, NULL, std::vector<const BookmarkNode*>(), - BookmarkContextMenuControllerViews::BOOKMARK_MANAGER_ORGANIZE_MENU); + NULL, profile_.get(), NULL, NULL, std::vector<const BookmarkNode*>()); EXPECT_FALSE(controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL)); EXPECT_FALSE( controller.IsCommandEnabled(IDS_BOOMARK_BAR_OPEN_ALL_NEW_WINDOW)); @@ -292,8 +282,7 @@ TEST_F(BookmarkContextMenuTest, CutCopyPasteNode) { std::vector<const BookmarkNode*> nodes; nodes.push_back(model_->GetBookmarkBarNode()->GetChild(0)); scoped_ptr<BookmarkContextMenu> controller(new BookmarkContextMenu( - NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes, - BookmarkContextMenuControllerViews::BOOKMARK_BAR)); + NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes)); EXPECT_TRUE(controller->IsCommandEnabled(IDS_COPY)); EXPECT_TRUE(controller->IsCommandEnabled(IDS_CUT)); @@ -301,8 +290,7 @@ TEST_F(BookmarkContextMenuTest, CutCopyPasteNode) { controller->ExecuteCommand(IDS_COPY); controller.reset(new BookmarkContextMenu( - NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes, - BookmarkContextMenuControllerViews::BOOKMARK_BAR)); + NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes)); int old_count = model_->GetBookmarkBarNode()->GetChildCount(); controller->ExecuteCommand(IDS_PASTE); @@ -312,8 +300,7 @@ TEST_F(BookmarkContextMenuTest, CutCopyPasteNode) { model_->GetBookmarkBarNode()->GetChild(1)->GetURL()); controller.reset(new BookmarkContextMenu( - NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes, - BookmarkContextMenuControllerViews::BOOKMARK_BAR)); + NULL, profile_.get(), NULL, nodes[0]->GetParent(), nodes)); // Cut the URL. controller->ExecuteCommand(IDS_CUT); ASSERT_TRUE(model_->GetBookmarkBarNode()->GetChild(0)->is_url()); diff --git a/chrome/browser/views/bookmark_menu_controller_views.cc b/chrome/browser/views/bookmark_menu_controller_views.cc index a5b9b03..09e5e48 100644 --- a/chrome/browser/views/bookmark_menu_controller_views.cc +++ b/chrome/browser/views/bookmark_menu_controller_views.cc @@ -205,8 +205,7 @@ bool BookmarkMenuController::ShowContextMenu(MenuItemView* source, profile_, page_navigator_, nodes[0]->GetParent(), - nodes, - BookmarkContextMenuControllerViews::BOOKMARK_BAR)); + nodes)); context_menu_->set_observer(this); context_menu_->RunMenuAt(p); context_menu_.reset(NULL); |