Commit e0ff4deb authored by tfarina@chromium.org's avatar tfarina@chromium.org

views/bookmarks: Convert BookmarkEditorView from Menu2 API to MenuModelApdater/MenuRunner API.

This patches removes the usage of the deprecated Menu2 API and makes it work under use_aura=1.

BUG=117092
TEST=chromeos=1, open the bookmark editor dialog, right click on any folder, you
should see the context menu with 3 items, and everything should work as before.
R=sky@chromium.org

Review URL: https://chromiumcodereview.appspot.com/9814031

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128264 0039d316-1c4b-4281-b951-d872f2087c98
parent 446c1a30
......@@ -26,7 +26,8 @@
#include "ui/views/background.h"
#include "ui/views/controls/button/text_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/menu/menu_2.h"
#include "ui/views/controls/menu/menu_model_adapter.h"
#include "ui/views/controls/menu/menu_runner.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/controls/tree/tree_view.h"
#include "ui/views/focus/focus_manager.h"
......@@ -287,20 +288,14 @@ void BookmarkEditorView::ShowContextMenuForView(views::View* source,
running_menu_for_root_ =
(tree_model_->GetParent(tree_view_->GetSelectedNode()) ==
tree_model_->GetRoot());
#if defined(USE_AURA)
NOTIMPLEMENTED();
#else
if (!context_menu_contents_.get()) {
context_menu_contents_.reset(new ui::SimpleMenuModel(this));
context_menu_contents_->AddItemWithStringId(IDS_EDIT, IDS_EDIT);
context_menu_contents_->AddItemWithStringId(IDS_DELETE, IDS_DELETE);
context_menu_contents_->AddItemWithStringId(
IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM,
IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM);
context_menu_.reset(new views::Menu2(context_menu_contents_.get()));
}
context_menu_->RunContextMenuAt(point);
#endif
views::MenuModelAdapter adapter(GetMenuModel());
context_menu_runner_.reset(new views::MenuRunner(adapter.CreateMenu()));
if (context_menu_runner_->RunMenuAt(source->GetWidget()->GetTopLevelWidget(),
NULL, gfx::Rect(point, gfx::Size()), views::MenuItemView::TOPRIGHT,
views::MenuRunner::HAS_MNEMONICS) == views::MenuRunner::MENU_DELETED)
return;
}
void BookmarkEditorView::Init() {
......@@ -467,9 +462,7 @@ void BookmarkEditorView::Reset() {
tree_view_->SetModel(tree_model_.get());
tree_view_->SetController(this);
#if !defined(USE_AURA)
context_menu_.reset();
#endif
context_menu_runner_.reset();
if (parent())
ExpandAndSelect();
......@@ -669,6 +662,18 @@ void BookmarkEditorView::UpdateExpandedNodes(
UpdateExpandedNodes(editor_node->GetChild(i), expanded_nodes);
}
ui::SimpleMenuModel* BookmarkEditorView::GetMenuModel() {
if (!context_menu_model_.get()) {
context_menu_model_.reset(new ui::SimpleMenuModel(this));
context_menu_model_->AddItemWithStringId(IDS_EDIT, IDS_EDIT);
context_menu_model_->AddItemWithStringId(IDS_DELETE, IDS_DELETE);
context_menu_model_->AddItemWithStringId(
IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM,
IDS_BOOKMARK_EDITOR_NEW_FOLDER_MENU_ITEM);
}
return context_menu_model_.get();
}
void BookmarkEditorView::EditorTreeModel::SetTitle(ui::TreeModelNode* node,
const string16& title) {
if (!title.empty())
......
......@@ -25,7 +25,7 @@
namespace views {
class Label;
class Menu2;
class MenuRunner;
class TextButton;
class TreeView;
}
......@@ -224,6 +224,8 @@ class BookmarkEditorView : public BookmarkEditor,
void UpdateExpandedNodes(EditorNode* editor_node,
BookmarkExpandedStateTracker::Nodes* expanded_nodes);
ui::SimpleMenuModel* GetMenuModel();
// Profile the entry is from.
Profile* profile_;
......@@ -255,10 +257,8 @@ class BookmarkEditorView : public BookmarkEditor,
const EditDetails details_;
// The context menu.
scoped_ptr<ui::SimpleMenuModel> context_menu_contents_;
#if !defined(USE_AURA)
scoped_ptr<views::Menu2> context_menu_;
#endif
scoped_ptr<ui::SimpleMenuModel> context_menu_model_;
scoped_ptr<views::MenuRunner> context_menu_runner_;
// Mode used to create nodes from.
BookmarkModel* bb_model_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment