diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-08 16:38:08 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-08 16:38:08 +0000 |
commit | 74bcb49df27ecc297937732876c2dd03c5dc29e3 (patch) | |
tree | 085f72579a5f60ab78fa1f8547a33a1c33090521 /chrome | |
parent | d818504aeb1f5ed305df803a4cf3e3c209b9554f (diff) | |
download | chromium_src-74bcb49df27ecc297937732876c2dd03c5dc29e3.zip chromium_src-74bcb49df27ecc297937732876c2dd03c5dc29e3.tar.gz chromium_src-74bcb49df27ecc297937732876c2dd03c5dc29e3.tar.bz2 |
Renames browser/gtk/bookmark_context_menu to
BoookmarkContextMenuGtk. I need to do this so that views/gtk can use
both BookmarkContextMenu and BookmarkContextMenuGtk.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/261013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28400 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.cc | 6 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.h | 4 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_context_menu.cc | 567 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_context_menu_gtk.cc | 547 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_context_menu_gtk.h (renamed from chrome/browser/gtk/bookmark_context_menu.h) | 50 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_manager_gtk.cc | 21 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_manager_gtk.h | 6 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_menu_controller_gtk.cc | 6 | ||||
-rw-r--r-- | chrome/browser/gtk/bookmark_menu_controller_gtk.h | 8 | ||||
-rwxr-xr-x | chrome/chrome.gyp | 5 |
10 files changed, 572 insertions, 648 deletions
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc index c7cb635..17f7383 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.cc +++ b/chrome/browser/gtk/bookmark_bar_gtk.cc @@ -17,7 +17,7 @@ #include "chrome/browser/bookmarks/bookmark_model.h" #include "chrome/browser/bookmarks/bookmark_utils.h" #include "chrome/browser/browser.h" -#include "chrome/browser/gtk/bookmark_context_menu.h" +#include "chrome/browser/gtk/bookmark_context_menu_gtk.h" #include "chrome/browser/gtk/bookmark_menu_controller_gtk.h" #include "chrome/browser/gtk/bookmark_tree_model.h" #include "chrome/browser/gtk/bookmark_utils_gtk.h" @@ -754,10 +754,10 @@ void BookmarkBarGtk::PopupMenuForNode(GtkWidget* sender, nodes.push_back(parent); } - current_context_menu_.reset(new BookmarkContextMenu( + current_context_menu_.reset(new BookmarkContextMenuGtk( sender, profile_, browser_, page_navigator_, parent, nodes, - BookmarkContextMenu::BOOKMARK_BAR, NULL)); + BookmarkContextMenuGtk::BOOKMARK_BAR, NULL)); 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 3ff93cb..702bee2 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.h +++ b/chrome/browser/gtk/bookmark_bar_gtk.h @@ -20,7 +20,7 @@ #include "chrome/common/owned_widget_gtk.h" #include "testing/gtest/include/gtest/gtest_prod.h" -class BookmarkContextMenu; +class BookmarkContextMenuGtk; class BookmarkMenuController; class Browser; class BrowserWindowGtk; @@ -302,7 +302,7 @@ class BookmarkBarGtk : public AnimationDelegate, // The last displayed right click menu, or NULL if no menus have been // displayed yet. - scoped_ptr<BookmarkContextMenu> current_context_menu_; + scoped_ptr<BookmarkContextMenuGtk> current_context_menu_; // The last displayed left click menu, or NULL if no menus have been // displayed yet. diff --git a/chrome/browser/gtk/bookmark_context_menu.cc b/chrome/browser/gtk/bookmark_context_menu.cc deleted file mode 100644 index c282a5e..0000000 --- a/chrome/browser/gtk/bookmark_context_menu.cc +++ /dev/null @@ -1,567 +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.h" - -#include "app/l10n_util.h" -#include "base/compiler_specific.h" -#include "chrome/browser/bookmarks/bookmark_editor.h" -#include "chrome/browser/bookmarks/bookmark_manager.h" -#include "chrome/browser/bookmarks/bookmark_model.h" -#include "chrome/browser/bookmarks/bookmark_utils.h" -#include "chrome/browser/browser.h" -#include "chrome/browser/browser_list.h" -#include "chrome/browser/input_window_dialog.h" -#include "chrome/browser/metrics/user_metrics.h" -#include "chrome/browser/profile.h" -#include "chrome/browser/tab_contents/page_navigator.h" -#include "chrome/browser/tab_contents/tab_contents.h" -#include "chrome/common/pref_names.h" -#include "chrome/common/pref_service.h" -#include "grit/generated_resources.h" - -// TODO(port): Port these files. -#if defined(OS_WIN) -#include "views/window/window.h" -#endif - -namespace { - -// Returns true if the specified node is of type URL, or has a descendant -// of type URL. -bool NodeHasURLs(const 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; -} - -// EditFolderController ------------------------------------------------------- - -// EditFolderController manages the editing and/or creation of a folder. If the -// user presses ok, the name change is committed to the model. -// -// EditFolderController deletes itself when the window is closed. -class EditFolderController : public InputWindowDialog::Delegate, - public BookmarkModelObserver { - public: - virtual ~EditFolderController() { - if (model_) - model_->RemoveObserver(this); - } - - static void Show(Profile* profile, - gfx::NativeView wnd, - const BookmarkNode* node, - bool is_new, - bool show_in_manager) { - // EditFolderController deletes itself when done. - EditFolderController* controller = - new EditFolderController(profile, wnd, node, is_new, show_in_manager); - controller->Show(); - } - - private: - EditFolderController(Profile* profile, - gfx::NativeView wnd, - const BookmarkNode* node, - bool is_new, - bool show_in_manager) - : profile_(profile), - model_(profile->GetBookmarkModel()), - node_(node), - is_new_(is_new), - show_in_manager_(show_in_manager) { - DCHECK(is_new_ || node); - - std::wstring title = is_new_ ? - l10n_util::GetString(IDS_BOOMARK_FOLDER_EDITOR_WINDOW_TITLE_NEW) : - l10n_util::GetString(IDS_BOOMARK_FOLDER_EDITOR_WINDOW_TITLE); - std::wstring label = - l10n_util::GetString(IDS_BOOMARK_BAR_EDIT_FOLDER_LABEL); - std::wstring contents = is_new_ ? - l10n_util::GetString(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME) : - node_->GetTitle(); - - dialog_ = InputWindowDialog::Create(wnd, title, label, contents, this); - model_->AddObserver(this); - } - - void Show() { - dialog_->Show(); - } - - // InputWindowDialog::Delegate methods. - virtual bool IsValid(const std::wstring& text) { - return !text.empty(); - } - - virtual void InputAccepted(const std::wstring& text) { - if (is_new_) { - ALLOW_UNUSED const BookmarkNode* node = - model_->AddGroup(node_, node_->GetChildCount(), text); - if (show_in_manager_) { -#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)) - BookmarkManager::SelectInTree(profile_, node); -#else - NOTIMPLEMENTED() << "BookmarkManager not yet implemented"; -#endif - } - } else { - model_->SetTitle(node_, text); - } - } - - virtual void InputCanceled() { - } - - // BookmarkModelObserver methods, all invoke ModelChanged and close the - // dialog. - virtual void Loaded(BookmarkModel* model) {} - virtual void BookmarkModelBeingDeleted(BookmarkModel* model) { - model_->RemoveObserver(this); - model_ = NULL; - ModelChanged(); - } - - virtual void BookmarkNodeMoved(BookmarkModel* model, - const BookmarkNode* old_parent, - int old_index, - const BookmarkNode* new_parent, - int new_index) { - ModelChanged(); - } - - virtual void BookmarkNodeAdded(BookmarkModel* model, - const BookmarkNode* parent, - int index) { - ModelChanged(); - } - - virtual void BookmarkNodeRemoved(BookmarkModel* model, - const BookmarkNode* parent, - int index, - const BookmarkNode* node) { - ModelChanged(); - } - - virtual void BookmarkNodeChanged(BookmarkModel* model, - const BookmarkNode* node) { - ModelChanged(); - } - - virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, - const BookmarkNode* node) {} - - virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, - const BookmarkNode* node) { - ModelChanged(); - } - - void ModelChanged() { - dialog_->Close(); - } - - Profile* profile_; - BookmarkModel* model_; - // If is_new is true, this is the parent to create the new node under. - // Otherwise this is the node to change the title of. - const BookmarkNode* node_; - - bool is_new_; - - // If is_new_ is true and a new node is created, it is selected in the - // bookmark manager. - bool show_in_manager_; - InputWindowDialog* dialog_; - - DISALLOW_COPY_AND_ASSIGN(EditFolderController); -}; - -#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)) -// SelectOnCreationHandler ---------------------------------------------------- - -// Used when adding a new bookmark. If a new bookmark is created it is selected -// in the bookmark manager. -class SelectOnCreationHandler : public BookmarkEditor::Handler { - public: - explicit SelectOnCreationHandler(Profile* profile) : profile_(profile) { - } - - virtual void NodeCreated(const BookmarkNode* new_node) { - BookmarkManager::SelectInTree(profile_, new_node); - } - - private: - Profile* profile_; - - DISALLOW_COPY_AND_ASSIGN(SelectOnCreationHandler); -}; -#endif // #if defined(OS_WIN) || (defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)) - -} // namespace - -// BookmarkContextMenu ------------------------------------------- - -BookmarkContextMenu::BookmarkContextMenu( - gfx::NativeView wnd, - Profile* profile, - Browser* browser, - PageNavigator* navigator, - const BookmarkNode* parent, - const std::vector<const BookmarkNode*>& selection, - ConfigurationType configuration, - Delegate* delegate) - : wnd_(wnd), - profile_(profile), - browser_(browser), - navigator_(navigator), - parent_(parent), - selection_(selection), - model_(profile->GetBookmarkModel()), - configuration_(configuration), - delegate_(delegate) { - DCHECK(profile_); - DCHECK(model_->IsLoaded()); - CreateMenuObject(); - - 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); - AppendCheckboxItem(IDS_BOOMARK_BAR_ALWAYS_SHOW); - } - - model_->AddObserver(this); -} - -BookmarkContextMenu::~BookmarkContextMenu() { - if (model_) - model_->RemoveObserver(this); -} - -void BookmarkContextMenu::DelegateDestroyed() { - delegate_ = NULL; -} - -void BookmarkContextMenu::ExecuteCommand(int id) { - if (delegate_) - delegate_->WillExecuteCommand(); - - switch (id) { - 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 (id == IDS_BOOMARK_BAR_OPEN_ALL) { - initial_disposition = NEW_FOREGROUND_TAB; - UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_OpenAll", - profile_); - } else if (id == 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(wnd_, 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()) { -#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)) - BookmarkEditor::Configuration editor_config; - if (configuration_ == BOOKMARK_BAR) - editor_config = BookmarkEditor::SHOW_TREE; - else - editor_config = BookmarkEditor::NO_TREE; - BookmarkEditor::Show(wnd_, profile_, parent_, selection_[0], - editor_config, NULL); -#else - NOTIMPLEMENTED(); -#endif - } else { - EditFolderController::Show(profile_, wnd_, selection_[0], false, - false); - } - 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_); - -#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)) - BookmarkEditor::Configuration editor_config; - BookmarkEditor::Handler* handler = NULL; - if (configuration_ == BOOKMARK_BAR) { - editor_config = BookmarkEditor::SHOW_TREE; - } else { - editor_config = BookmarkEditor::NO_TREE; - // This is owned by the BookmarkEditorView. - handler = new SelectOnCreationHandler(profile_); - } - BookmarkEditor::Show(wnd_, profile_, GetParentForNewNodes(), NULL, - editor_config, handler); -#else - NOTIMPLEMENTED(); -#endif - break; - } - - case IDS_BOOMARK_BAR_NEW_FOLDER: { - UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_NewFolder", - profile_); - EditFolderController::Show(profile_, wnd_, GetParentForNewNodes(), - true, (configuration_ != BOOKMARK_BAR)); - 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; - } - -#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)) - BookmarkManager::SelectInTree(profile_, selection_[0]); -#else - NOTIMPLEMENTED() << "Bookmark Manager not implemented"; -#endif - break; - - case IDS_BOOKMARK_MANAGER: - UserMetrics::RecordAction(L"ShowBookmarkManager", profile_); -#if defined(OS_WIN) || (defined(OS_LINUX) && !defined(TOOLKIT_VIEWS)) - BookmarkManager::Show(profile_); -#else - NOTIMPLEMENTED() << "Bookmark Manager not implemented"; -#endif - break; - - case IDS_BOOKMARK_MANAGER_SORT: - UserMetrics::RecordAction(L"BookmarkManager_Sort", profile_); - model_->SortChildren(parent_); - break; - - case IDS_COPY: - case IDS_CUT: - bookmark_utils::CopyToClipboard(profile_->GetBookmarkModel(), - selection_, id == IDS_CUT); - break; - - case IDS_PASTE: { - // Always paste to parent. - if (!parent_) - return; - - int index = (selection_.size() == 1) ? - parent_->IndexOfChild(selection_[0]) : -1; - if (index != -1) - index++; - bookmark_utils::PasteFromClipboard(profile_->GetBookmarkModel(), - parent_, index); - break; - } - - default: - NOTREACHED(); - } -} - -bool BookmarkContextMenu::IsItemChecked(int id) const { - DCHECK(id == IDS_BOOMARK_BAR_ALWAYS_SHOW); - return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); -} - -bool BookmarkContextMenu::IsCommandEnabled(int id) const { - bool is_root_node = - (selection_.size() == 1 && - selection_[0]->GetParent() == model_->root_node()); - switch (id) { - 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; - - case IDS_PASTE: - // Always paste to parent. - return bookmark_utils::CanPasteFromClipboard(parent_); - } - return true; -} - -void BookmarkContextMenu::BookmarkModelBeingDeleted(BookmarkModel* model) { - ModelChanged(); -} - -void BookmarkContextMenu::BookmarkNodeMoved(BookmarkModel* model, - const BookmarkNode* old_parent, - int old_index, - const BookmarkNode* new_parent, - int new_index) { - ModelChanged(); -} - -void BookmarkContextMenu::BookmarkNodeAdded(BookmarkModel* model, - const BookmarkNode* parent, - int index) { - ModelChanged(); -} - -void BookmarkContextMenu::BookmarkNodeRemoved(BookmarkModel* model, - const BookmarkNode* parent, - int index, - const BookmarkNode* node) { - ModelChanged(); -} - -void BookmarkContextMenu::BookmarkNodeChanged(BookmarkModel* model, - const BookmarkNode* node) { - ModelChanged(); -} - -void BookmarkContextMenu::BookmarkNodeChildrenReordered( - BookmarkModel* model, const BookmarkNode* node) { - ModelChanged(); -} - -void BookmarkContextMenu::ModelChanged() { - menu_->Cancel(); -} - -BookmarkModel* BookmarkContextMenu::RemoveModelObserver() { - BookmarkModel* model = model_; - model_->RemoveObserver(this); - model_ = NULL; - return model; -} - -bool BookmarkContextMenu::HasURLs() const { - for (size_t i = 0; i < selection_.size(); ++i) { - if (NodeHasURLs(selection_[i])) - return true; - } - return false; -} - -const BookmarkNode* BookmarkContextMenu::GetParentForNewNodes() const { - return (selection_.size() == 1 && selection_[0]->is_folder()) ? - selection_[0] : parent_; -} diff --git a/chrome/browser/gtk/bookmark_context_menu_gtk.cc b/chrome/browser/gtk/bookmark_context_menu_gtk.cc index fc8f73b..8eb032d 100644 --- a/chrome/browser/gtk/bookmark_context_menu_gtk.cc +++ b/chrome/browser/gtk/bookmark_context_menu_gtk.cc @@ -2,30 +2,563 @@ // 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.h" +#include "chrome/browser/gtk/bookmark_context_menu_gtk.h" #include "app/l10n_util.h" +#include "base/compiler_specific.h" +#include "chrome/browser/bookmarks/bookmark_editor.h" +#include "chrome/browser/bookmarks/bookmark_manager.h" +#include "chrome/browser/bookmarks/bookmark_model.h" +#include "chrome/browser/bookmarks/bookmark_utils.h" +#include "chrome/browser/browser.h" +#include "chrome/browser/browser_list.h" +#include "chrome/browser/input_window_dialog.h" +#include "chrome/browser/metrics/user_metrics.h" +#include "chrome/browser/profile.h" +#include "chrome/browser/tab_contents/page_navigator.h" +#include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/pref_names.h" +#include "chrome/common/pref_service.h" +#include "grit/generated_resources.h" -void BookmarkContextMenu::PopupAsContext(guint32 event_time) { +namespace { + +// Returns true if the specified node is of type URL, or has a descendant +// of type URL. +bool NodeHasURLs(const 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; +} + +// EditFolderController ------------------------------------------------------- + +// EditFolderController manages the editing and/or creation of a folder. If the +// user presses ok, the name change is committed to the model. +// +// EditFolderController deletes itself when the window is closed. +class EditFolderController : public InputWindowDialog::Delegate, + public BookmarkModelObserver { + public: + virtual ~EditFolderController() { + if (model_) + model_->RemoveObserver(this); + } + + static void Show(Profile* profile, + gfx::NativeView wnd, + const BookmarkNode* node, + bool is_new, + bool show_in_manager) { + // EditFolderController deletes itself when done. + EditFolderController* controller = + new EditFolderController(profile, wnd, node, is_new, show_in_manager); + controller->Show(); + } + + private: + EditFolderController(Profile* profile, + gfx::NativeView wnd, + const BookmarkNode* node, + bool is_new, + bool show_in_manager) + : profile_(profile), + model_(profile->GetBookmarkModel()), + node_(node), + is_new_(is_new), + show_in_manager_(show_in_manager) { + DCHECK(is_new_ || node); + + std::wstring title = is_new_ ? + l10n_util::GetString(IDS_BOOMARK_FOLDER_EDITOR_WINDOW_TITLE_NEW) : + l10n_util::GetString(IDS_BOOMARK_FOLDER_EDITOR_WINDOW_TITLE); + std::wstring label = + l10n_util::GetString(IDS_BOOMARK_BAR_EDIT_FOLDER_LABEL); + std::wstring contents = is_new_ ? + l10n_util::GetString(IDS_BOOMARK_EDITOR_NEW_FOLDER_NAME) : + node_->GetTitle(); + + dialog_ = InputWindowDialog::Create(wnd, title, label, contents, this); + model_->AddObserver(this); + } + + void Show() { + dialog_->Show(); + } + + // InputWindowDialog::Delegate methods. + virtual bool IsValid(const std::wstring& text) { + return !text.empty(); + } + + virtual void InputAccepted(const std::wstring& text) { + if (is_new_) { + ALLOW_UNUSED const BookmarkNode* node = + model_->AddGroup(node_, node_->GetChildCount(), text); + if (show_in_manager_) { + BookmarkManager::SelectInTree(profile_, node); + } + } else { + model_->SetTitle(node_, text); + } + } + + virtual void InputCanceled() { + } + + // BookmarkModelObserver methods, all invoke ModelChanged and close the + // dialog. + virtual void Loaded(BookmarkModel* model) {} + virtual void BookmarkModelBeingDeleted(BookmarkModel* model) { + model_->RemoveObserver(this); + model_ = NULL; + ModelChanged(); + } + + virtual void BookmarkNodeMoved(BookmarkModel* model, + const BookmarkNode* old_parent, + int old_index, + const BookmarkNode* new_parent, + int new_index) { + ModelChanged(); + } + + virtual void BookmarkNodeAdded(BookmarkModel* model, + const BookmarkNode* parent, + int index) { + ModelChanged(); + } + + virtual void BookmarkNodeRemoved(BookmarkModel* model, + const BookmarkNode* parent, + int index, + const BookmarkNode* node) { + ModelChanged(); + } + + virtual void BookmarkNodeChanged(BookmarkModel* model, + const BookmarkNode* node) { + ModelChanged(); + } + + virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, + const BookmarkNode* node) {} + + virtual void BookmarkNodeChildrenReordered(BookmarkModel* model, + const BookmarkNode* node) { + ModelChanged(); + } + + void ModelChanged() { + dialog_->Close(); + } + + Profile* profile_; + BookmarkModel* model_; + // If is_new is true, this is the parent to create the new node under. + // Otherwise this is the node to change the title of. + const BookmarkNode* node_; + + bool is_new_; + + // If is_new_ is true and a new node is created, it is selected in the + // bookmark manager. + bool show_in_manager_; + InputWindowDialog* dialog_; + + DISALLOW_COPY_AND_ASSIGN(EditFolderController); +}; + +// SelectOnCreationHandler ---------------------------------------------------- + +// Used when adding a new bookmark. If a new bookmark is created it is selected +// in the bookmark manager. +class SelectOnCreationHandler : public BookmarkEditor::Handler { + public: + explicit SelectOnCreationHandler(Profile* profile) : profile_(profile) { + } + + virtual void NodeCreated(const BookmarkNode* new_node) { + BookmarkManager::SelectInTree(profile_, new_node); + } + + private: + Profile* profile_; + + DISALLOW_COPY_AND_ASSIGN(SelectOnCreationHandler); +}; + +} // namespace + +// BookmarkContextMenuGtk ------------------------------------------- + +BookmarkContextMenuGtk::BookmarkContextMenuGtk( + gfx::NativeView wnd, + Profile* profile, + Browser* browser, + PageNavigator* navigator, + const BookmarkNode* parent, + const std::vector<const BookmarkNode*>& selection, + ConfigurationType configuration, + Delegate* delegate) + : wnd_(wnd), + profile_(profile), + browser_(browser), + navigator_(navigator), + parent_(parent), + selection_(selection), + model_(profile->GetBookmarkModel()), + configuration_(configuration), + delegate_(delegate) { + DCHECK(profile_); + DCHECK(model_->IsLoaded()); + CreateMenuObject(); + + 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); + AppendCheckboxItem(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); } -void BookmarkContextMenu::CreateMenuObject() { +void BookmarkContextMenuGtk::DelegateDestroyed() { + delegate_ = NULL; +} + +void BookmarkContextMenuGtk::ExecuteCommand(int id) { + if (delegate_) + delegate_->WillExecuteCommand(); + + switch (id) { + 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 (id == IDS_BOOMARK_BAR_OPEN_ALL) { + initial_disposition = NEW_FOREGROUND_TAB; + UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_OpenAll", + profile_); + } else if (id == 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(wnd_, 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()) { + BookmarkEditor::Configuration editor_config; + if (configuration_ == BOOKMARK_BAR) + editor_config = BookmarkEditor::SHOW_TREE; + else + editor_config = BookmarkEditor::NO_TREE; + BookmarkEditor::Show(wnd_, profile_, parent_, selection_[0], + editor_config, NULL); + } else { + EditFolderController::Show(profile_, wnd_, selection_[0], false, + false); + } + 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_); + + BookmarkEditor::Configuration editor_config; + BookmarkEditor::Handler* handler = NULL; + if (configuration_ == BOOKMARK_BAR) { + editor_config = BookmarkEditor::SHOW_TREE; + } else { + editor_config = BookmarkEditor::NO_TREE; + // This is owned by the BookmarkEditorView. + handler = new SelectOnCreationHandler(profile_); + } + BookmarkEditor::Show(wnd_, profile_, GetParentForNewNodes(), NULL, + editor_config, handler); + break; + } + + case IDS_BOOMARK_BAR_NEW_FOLDER: { + UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_NewFolder", + profile_); + EditFolderController::Show(profile_, wnd_, GetParentForNewNodes(), + true, (configuration_ != BOOKMARK_BAR)); + 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; + } + + BookmarkManager::SelectInTree(profile_, selection_[0]); + break; + + case IDS_BOOKMARK_MANAGER: + UserMetrics::RecordAction(L"ShowBookmarkManager", profile_); + BookmarkManager::Show(profile_); + break; + + case IDS_BOOKMARK_MANAGER_SORT: + UserMetrics::RecordAction(L"BookmarkManager_Sort", profile_); + model_->SortChildren(parent_); + break; + + case IDS_COPY: + case IDS_CUT: + bookmark_utils::CopyToClipboard(profile_->GetBookmarkModel(), + selection_, id == IDS_CUT); + break; + + case IDS_PASTE: { + // Always paste to parent. + if (!parent_) + return; + + int index = (selection_.size() == 1) ? + parent_->IndexOfChild(selection_[0]) : -1; + if (index != -1) + index++; + bookmark_utils::PasteFromClipboard(profile_->GetBookmarkModel(), + parent_, index); + break; + } + + default: + NOTREACHED(); + } +} + +bool BookmarkContextMenuGtk::IsItemChecked(int id) const { + DCHECK(id == IDS_BOOMARK_BAR_ALWAYS_SHOW); + return profile_->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); +} + +bool BookmarkContextMenuGtk::IsCommandEnabled(int id) const { + bool is_root_node = + (selection_.size() == 1 && + selection_[0]->GetParent() == model_->root_node()); + switch (id) { + 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; + + case IDS_PASTE: + // Always paste to parent. + return bookmark_utils::CanPasteFromClipboard(parent_); + } + return true; +} + +void BookmarkContextMenuGtk::BookmarkModelBeingDeleted(BookmarkModel* model) { + ModelChanged(); +} + +void BookmarkContextMenuGtk::BookmarkNodeMoved(BookmarkModel* model, + const BookmarkNode* old_parent, + int old_index, + const BookmarkNode* new_parent, + int new_index) { + ModelChanged(); +} + +void BookmarkContextMenuGtk::BookmarkNodeAdded(BookmarkModel* model, + const BookmarkNode* parent, + int index) { + ModelChanged(); +} + +void BookmarkContextMenuGtk::BookmarkNodeRemoved(BookmarkModel* model, + const BookmarkNode* parent, + int index, + const BookmarkNode* node) { + ModelChanged(); +} + +void BookmarkContextMenuGtk::BookmarkNodeChanged(BookmarkModel* model, + const BookmarkNode* node) { + ModelChanged(); +} + +void BookmarkContextMenuGtk::BookmarkNodeChildrenReordered( + BookmarkModel* model, const BookmarkNode* node) { + ModelChanged(); +} + +void BookmarkContextMenuGtk::ModelChanged() { + menu_->Cancel(); +} + +void BookmarkContextMenuGtk::CreateMenuObject() { menu_.reset(new MenuGtk(this, false)); } -void BookmarkContextMenu::AppendItem(int id) { +void BookmarkContextMenuGtk::AppendItem(int id) { menu_->AppendMenuItemWithLabel(id, l10n_util::GetStringUTF8(id)); } -void BookmarkContextMenu::AppendItem(int id, int localization_id) { +void BookmarkContextMenuGtk::AppendItem(int id, int localization_id) { menu_->AppendMenuItemWithLabel(id, l10n_util::GetStringUTF8(localization_id)); } -void BookmarkContextMenu::AppendSeparator() { +void BookmarkContextMenuGtk::AppendSeparator() { menu_->AppendSeparator(); } -void BookmarkContextMenu::AppendCheckboxItem(int id) { +void BookmarkContextMenuGtk::AppendCheckboxItem(int id) { menu_->AppendCheckMenuItemWithLabel(id, l10n_util::GetStringUTF8(id)); } + +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; +} + +const BookmarkNode* BookmarkContextMenuGtk::GetParentForNewNodes() const { + return (selection_.size() == 1 && selection_[0]->is_folder()) ? + selection_[0] : parent_; +} diff --git a/chrome/browser/gtk/bookmark_context_menu.h b/chrome/browser/gtk/bookmark_context_menu_gtk.h index ca949f6..a84db53 100644 --- a/chrome/browser/gtk/bookmark_context_menu.h +++ b/chrome/browser/gtk/bookmark_context_menu_gtk.h @@ -11,15 +11,7 @@ #include "base/gfx/native_widget_types.h" #include "base/scoped_ptr.h" #include "chrome/browser/bookmarks/bookmark_model_observer.h" - -// TODO(port): Port this file. -#if defined(TOOLKIT_VIEWS) -#include "views/controls/menu/menu_delegate.h" -#elif defined(OS_LINUX) #include "chrome/browser/gtk/menu_gtk.h" -#else -#include "chrome/common/temp_scaffolding_stubs.h" -#endif class Browser; class PageNavigator; @@ -28,13 +20,8 @@ class Profile; // 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 BookmarkModelObserver, -#if defined(TOOLKIT_VIEWS) - public views::MenuDelegate -#elif defined(OS_LINUX) - public MenuGtk::Delegate -#endif -{ +class BookmarkContextMenuGtk : public BookmarkModelObserver, + public MenuGtk::Delegate { public: // Used to configure what the context menu shows. enum ConfigurationType { @@ -63,29 +50,21 @@ class BookmarkContextMenu : public BookmarkModelObserver, // |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. - BookmarkContextMenu(gfx::NativeView hwnd, - Profile* profile, - Browser* browser, - PageNavigator* navigator, - const BookmarkNode* parent, - const std::vector<const BookmarkNode*>& selection, - ConfigurationType configuration, - Delegate* delegate); - virtual ~BookmarkContextMenu(); - -#if defined(TOOLKIT_VIEWS) - // Shows the menu at the specified place. - void RunMenuAt(int x, int y); + BookmarkContextMenuGtk(gfx::NativeView hwnd, + Profile* profile, + Browser* browser, + PageNavigator* navigator, + const BookmarkNode* parent, + const std::vector<const BookmarkNode*>& selection, + ConfigurationType configuration, + Delegate* delegate); + virtual ~BookmarkContextMenuGtk(); - // 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); // Returns the menu. GtkWidget* menu() const { return menu_->widget(); } -#endif // Should be called by the delegate when it is no longer valid. void DelegateDestroyed(); @@ -154,14 +133,9 @@ class BookmarkContextMenu : public BookmarkModelObserver, BookmarkModel* model_; ConfigurationType configuration_; Delegate* delegate_; - -#if defined(OS_WIN) || defined(TOOLKIT_VIEWS) - scoped_ptr<views::MenuItemView> menu_; -#elif defined(OS_LINUX) scoped_ptr<MenuGtk> menu_; -#endif - DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenu); + DISALLOW_COPY_AND_ASSIGN(BookmarkContextMenuGtk); }; #endif // CHROME_BROWSER_GTK_BOOKMARK_CONTEXT_MENU_H_ diff --git a/chrome/browser/gtk/bookmark_manager_gtk.cc b/chrome/browser/gtk/bookmark_manager_gtk.cc index 0e54ccd..6277690 100644 --- a/chrome/browser/gtk/bookmark_manager_gtk.cc +++ b/chrome/browser/gtk/bookmark_manager_gtk.cc @@ -600,21 +600,16 @@ void BookmarkManagerGtk::ResetOrganizeMenu(bool left) { else if (parent) nodes.push_back(parent); -#if defined(TOOLKIT_GTK) // We DeleteSoon on the old one to give any reference holders (e.g. // the event that caused this reset) a chance to release their refs. - BookmarkContextMenu* old_menu = organize_menu_.release(); + BookmarkContextMenuGtk* old_menu = organize_menu_.release(); if (old_menu) MessageLoop::current()->DeleteSoon(FROM_HERE, old_menu); - organize_menu_.reset(new BookmarkContextMenu(window_, profile_, NULL, NULL, - parent, nodes, BookmarkContextMenu::BOOKMARK_MANAGER_ORGANIZE_MENU, + organize_menu_.reset(new BookmarkContextMenuGtk(window_, profile_, NULL, NULL, + parent, nodes, BookmarkContextMenuGtk::BOOKMARK_MANAGER_ORGANIZE_MENU, NULL)); gtk_menu_item_set_submenu(GTK_MENU_ITEM(organize_), organize_menu_->menu()); -#else - // GTK+Views should implement this somehow. - NOTIMPLEMENTED(); -#endif } void BookmarkManagerGtk::BuildLeftStore() { @@ -1242,7 +1237,6 @@ gboolean BookmarkManagerGtk::OnTreeViewButtonPress( if (button->button != 3) return FALSE; -#if defined(TOOLKIT_GTK) if (bm->ignore_rightclicks_) return FALSE; @@ -1256,11 +1250,6 @@ gboolean BookmarkManagerGtk::OnTreeViewButtonPress( bm->organize_menu_->PopupAsContext(button->time); return TRUE; -#else - // Implement on GTK+views. - NOTIMPLEMENTED(); - return FALSE; -#endif } // static @@ -1306,15 +1295,11 @@ gboolean BookmarkManagerGtk::OnTreeViewKeyPress( if (command == -1) return FALSE; -#if defined(TOOLKIT_GTK) if (bm->organize_menu_.get() && bm->organize_menu_->IsCommandEnabled(command)) { bm->organize_menu_->ExecuteCommand(command); return TRUE; } -#else - NOTIMPLEMENTED(); -#endif return FALSE; } diff --git a/chrome/browser/gtk/bookmark_manager_gtk.h b/chrome/browser/gtk/bookmark_manager_gtk.h index 4c19ba3..8f5fc4c 100644 --- a/chrome/browser/gtk/bookmark_manager_gtk.h +++ b/chrome/browser/gtk/bookmark_manager_gtk.h @@ -13,7 +13,7 @@ #include "base/ref_counted.h" #include "base/task.h" #include "chrome/browser/bookmarks/bookmark_model_observer.h" -#include "chrome/browser/gtk/bookmark_context_menu.h" +#include "chrome/browser/gtk/bookmark_context_menu_gtk.h" #include "chrome/browser/shell_dialogs.h" #include "chrome/common/gtk_tree.h" #include "testing/gtest/include/gtest/gtest_prod.h" @@ -327,9 +327,7 @@ class BookmarkManagerGtk : public BookmarkModelObserver, // The Organize menu item. GtkWidget* organize_; // The submenu the item pops up. -#if defined(TOOLKIT_GTK) - scoped_ptr<BookmarkContextMenu> organize_menu_; -#endif + scoped_ptr<BookmarkContextMenuGtk> organize_menu_; // Whether the menu refers to the left selection. bool organize_is_for_left_; diff --git a/chrome/browser/gtk/bookmark_menu_controller_gtk.cc b/chrome/browser/gtk/bookmark_menu_controller_gtk.cc index b16fad3..ed436a7 100644 --- a/chrome/browser/gtk/bookmark_menu_controller_gtk.cc +++ b/chrome/browser/gtk/bookmark_menu_controller_gtk.cc @@ -12,7 +12,7 @@ #include "app/resource_bundle.h" #include "base/string_util.h" #include "chrome/browser/bookmarks/bookmark_model.h" -#include "chrome/browser/gtk/bookmark_context_menu.h" +#include "chrome/browser/gtk/bookmark_context_menu_gtk.h" #include "chrome/browser/gtk/bookmark_utils_gtk.h" #include "chrome/browser/gtk/gtk_chrome_button.h" #include "chrome/browser/gtk/gtk_theme_provider.h" @@ -250,10 +250,10 @@ gboolean BookmarkMenuController::OnButtonPressed( if (node) nodes.push_back(node); controller->context_menu_.reset( - new BookmarkContextMenu( + new BookmarkContextMenuGtk( GTK_WIDGET(controller->parent_window_), controller->profile_, controller->browser_, controller->page_navigator_, parent, nodes, - BookmarkContextMenu::BOOKMARK_BAR, controller)); + BookmarkContextMenuGtk::BOOKMARK_BAR, controller)); // Our bookmark folder menu loses the grab to the context menu. When the // context menu is hidden, re-assert our grab. diff --git a/chrome/browser/gtk/bookmark_menu_controller_gtk.h b/chrome/browser/gtk/bookmark_menu_controller_gtk.h index f6f0389f..dbd0c3e 100644 --- a/chrome/browser/gtk/bookmark_menu_controller_gtk.h +++ b/chrome/browser/gtk/bookmark_menu_controller_gtk.h @@ -11,7 +11,7 @@ #include "base/scoped_ptr.h" #include "chrome/browser/bookmarks/base_bookmark_model_observer.h" -#include "chrome/browser/gtk/bookmark_context_menu.h" +#include "chrome/browser/gtk/bookmark_context_menu_gtk.h" #include "chrome/common/owned_widget_gtk.h" #include "webkit/glue/window_open_disposition.h" @@ -23,7 +23,7 @@ class BookmarkModel; class BookmarkNode; class BookmarkMenuController : public BaseBookmarkModelObserver, - public BookmarkContextMenu::Delegate { + public BookmarkContextMenuGtk::Delegate { public: // Creates a BookmarkMenuController showing the children of |node| starting // at index |start_child_index|. @@ -46,7 +46,7 @@ class BookmarkMenuController : public BaseBookmarkModelObserver, virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model, const BookmarkNode* node); - // Overridden from BookmarkContextMenu::Delegate: + // Overridden from BookmarkContextMenuGtk::Delegate: virtual void WillExecuteCommand(); private: @@ -124,7 +124,7 @@ class BookmarkMenuController : public BaseBookmarkModelObserver, std::map<const BookmarkNode*, GtkWidget*> node_to_menu_widget_map_; // Owns our right click context menu. - scoped_ptr<BookmarkContextMenu> context_menu_; + scoped_ptr<BookmarkContextMenuGtk> context_menu_; DISALLOW_COPY_AND_ASSIGN(BookmarkMenuController); }; diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp index 40dad76..50796ff 100755 --- a/chrome/chrome.gyp +++ b/chrome/chrome.gyp @@ -1353,9 +1353,8 @@ 'browser/gtk/bookmark_bar_gtk.h', 'browser/gtk/bookmark_bubble_gtk.cc', 'browser/gtk/bookmark_bubble_gtk.h', - 'browser/gtk/bookmark_context_menu.cc', - 'browser/gtk/bookmark_context_menu.h', 'browser/gtk/bookmark_context_menu_gtk.cc', + 'browser/gtk/bookmark_context_menu_gtk.h', 'browser/gtk/bookmark_editor_gtk.cc', 'browser/gtk/bookmark_editor_gtk.h', 'browser/gtk/bookmark_manager_gtk.cc', @@ -2706,6 +2705,8 @@ ['include', '^browser/gtk/about_chrome_dialog.h'], ['include', '^browser/gtk/autocomplete_edit_gtk.cc'], ['include', '^browser/gtk/autocomplete_edit_gtk.h'], + ['include', '^browser/gtk/bookmark_context_menu_gtk.cc'], + ['include', '^browser/gtk/bookmark_context_menu_gtk.h'], ['include', '^browser/gtk/bookmark_editor_gtk.cc'], ['include', '^browser/gtk/bookmark_editor_gtk.h'], ['include', '^browser/gtk/bookmark_manager_gtk.cc'], |