Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Side by Side Diff: chrome/browser/ui/views/bookmarks/bookmark_context_menu.cc

Issue 1647003002: Make bookmark context menu asynchronous (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@b564255_move_key_handler_out_of_message_loop
Patch Set: Removed loggings Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h" 5 #include "chrome/browser/ui/views/bookmarks/bookmark_context_menu.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/i18n/rtl.h" 8 #include "base/i18n/rtl.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
(...skipping 24 matching lines...) Expand all
35 35
36 BookmarkContextMenu::BookmarkContextMenu( 36 BookmarkContextMenu::BookmarkContextMenu(
37 views::Widget* parent_widget, 37 views::Widget* parent_widget,
38 Browser* browser, 38 Browser* browser,
39 Profile* profile, 39 Profile* profile,
40 PageNavigator* page_navigator, 40 PageNavigator* page_navigator,
41 const BookmarkNode* parent, 41 const BookmarkNode* parent,
42 const std::vector<const BookmarkNode*>& selection, 42 const std::vector<const BookmarkNode*>& selection,
43 bool close_on_remove) 43 bool close_on_remove)
44 : controller_(new BookmarkContextMenuController( 44 : controller_(new BookmarkContextMenuController(
45 parent_widget ? parent_widget->GetNativeWindow() : NULL, this, 45 parent_widget ? parent_widget->GetNativeWindow() : nullptr,
46 browser, profile, page_navigator, parent, selection)), 46 this,
47 browser,
48 profile,
49 page_navigator,
50 parent,
51 selection)),
47 parent_widget_(parent_widget), 52 parent_widget_(parent_widget),
48 menu_(new views::MenuItemView(this)), 53 menu_(new views::MenuItemView(this)),
49 menu_runner_(new views::MenuRunner(menu_, 54 menu_runner_(new views::MenuRunner(menu_,
50 views::MenuRunner::HAS_MNEMONICS | 55 views::MenuRunner::HAS_MNEMONICS |
51 views::MenuRunner::IS_NESTED | 56 views::MenuRunner::IS_NESTED |
52 views::MenuRunner::CONTEXT_MENU)), 57 views::MenuRunner::CONTEXT_MENU |
58 views::MenuRunner::ASYNC)),
53 observer_(NULL), 59 observer_(NULL),
54 close_on_remove_(close_on_remove) { 60 close_on_remove_(close_on_remove) {
55 ui::SimpleMenuModel* menu_model = controller_->menu_model(); 61 ui::SimpleMenuModel* menu_model = controller_->menu_model();
56 for (int i = 0; i < menu_model->GetItemCount(); ++i) { 62 for (int i = 0; i < menu_model->GetItemCount(); ++i) {
57 views::MenuModelAdapter::AppendMenuItemFromModel( 63 views::MenuModelAdapter::AppendMenuItemFromModel(
58 menu_model, i, menu_, menu_model->GetCommandIdAt(i)); 64 menu_model, i, menu_, menu_model->GetCommandIdAt(i));
59 } 65 }
60 } 66 }
61 67
62 BookmarkContextMenu::~BookmarkContextMenu() { 68 BookmarkContextMenu::~BookmarkContextMenu() {
63 } 69 }
64 70
65 void BookmarkContextMenu::RunMenuAt(const gfx::Point& point, 71 void BookmarkContextMenu::RunMenuAt(const gfx::Point& point,
66 ui::MenuSourceType source_type) { 72 ui::MenuSourceType source_type) {
67 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode)) 73 if (base::CommandLine::ForCurrentProcess()->HasSwitch(switches::kKioskMode))
68 return; 74 return;
69 75
70 content::NotificationService::current()->Notify( 76 content::NotificationService::current()->Notify(
71 chrome::NOTIFICATION_BOOKMARK_CONTEXT_MENU_SHOWN, 77 chrome::NOTIFICATION_BOOKMARK_CONTEXT_MENU_SHOWN,
72 content::Source<BookmarkContextMenu>(this), 78 content::Source<BookmarkContextMenu>(this),
73 content::NotificationService::NoDetails()); 79 content::NotificationService::NoDetails());
74 // width/height don't matter here. 80 // width/height don't matter here.
75 if (menu_runner_->RunMenuAt(parent_widget_, 81 ignore_result(menu_runner_->RunMenuAt(parent_widget_, nullptr,
sky 2016/02/03 16:51:56 As the return value is no longer important I say w
mohsen 2016/02/03 22:14:12 Done.
76 NULL, 82 gfx::Rect(point.x(), point.y(), 0, 0),
77 gfx::Rect(point.x(), point.y(), 0, 0), 83 views::MENU_ANCHOR_TOPLEFT,
78 views::MENU_ANCHOR_TOPLEFT, 84 source_type));
79 source_type) == views::MenuRunner::MENU_DELETED) {
80 return;
81 }
82 } 85 }
83 86
84 void BookmarkContextMenu::SetPageNavigator(PageNavigator* navigator) { 87 void BookmarkContextMenu::SetPageNavigator(PageNavigator* navigator) {
85 controller_->set_navigator(navigator); 88 controller_->set_navigator(navigator);
86 } 89 }
87 90
88 //////////////////////////////////////////////////////////////////////////////// 91 ////////////////////////////////////////////////////////////////////////////////
89 // BookmarkContextMenu, views::MenuDelegate implementation: 92 // BookmarkContextMenu, views::MenuDelegate implementation:
90 93
91 void BookmarkContextMenu::ExecuteCommand(int command_id, int event_flags) { 94 void BookmarkContextMenu::ExecuteCommand(int command_id, int event_flags) {
92 controller_->ExecuteCommand(command_id, event_flags); 95 controller_->ExecuteCommand(command_id, event_flags);
93 } 96 }
94 97
95 bool BookmarkContextMenu::IsItemChecked(int command_id) const { 98 bool BookmarkContextMenu::IsItemChecked(int command_id) const {
96 return controller_->IsCommandIdChecked(command_id); 99 return controller_->IsCommandIdChecked(command_id);
97 } 100 }
98 101
99 bool BookmarkContextMenu::IsCommandEnabled(int command_id) const { 102 bool BookmarkContextMenu::IsCommandEnabled(int command_id) const {
100 return controller_->IsCommandIdEnabled(command_id); 103 return controller_->IsCommandIdEnabled(command_id);
101 } 104 }
102 105
103 bool BookmarkContextMenu::IsCommandVisible(int command_id) const { 106 bool BookmarkContextMenu::IsCommandVisible(int command_id) const {
104 return controller_->IsCommandIdVisible(command_id); 107 return controller_->IsCommandIdVisible(command_id);
105 } 108 }
106 109
107 bool BookmarkContextMenu::ShouldCloseAllMenusOnExecute(int id) { 110 bool BookmarkContextMenu::ShouldCloseAllMenusOnExecute(int id) {
108 return (id != IDC_BOOKMARK_BAR_REMOVE) || close_on_remove_; 111 return (id != IDC_BOOKMARK_BAR_REMOVE) || close_on_remove_;
109 } 112 }
110 113
114 void BookmarkContextMenu::OnMenuClosed(views::MenuItemView* menu,
115 views::MenuRunner::RunResult result) {
116 if (observer_)
117 observer_->OnContextMenuClosed();
118 }
119
111 //////////////////////////////////////////////////////////////////////////////// 120 ////////////////////////////////////////////////////////////////////////////////
112 // BookmarkContextMenuControllerDelegate 121 // BookmarkContextMenuControllerDelegate
113 // implementation: 122 // implementation:
114 123
115 void BookmarkContextMenu::CloseMenu() { 124 void BookmarkContextMenu::CloseMenu() {
116 menu_->Cancel(); 125 menu_->Cancel();
117 } 126 }
118 127
119 void BookmarkContextMenu::WillExecuteCommand( 128 void BookmarkContextMenu::WillExecuteCommand(
120 int command_id, 129 int command_id,
121 const std::vector<const BookmarkNode*>& bookmarks) { 130 const std::vector<const BookmarkNode*>& bookmarks) {
122 if (observer_ && IsRemoveBookmarksCommand(command_id)) 131 if (observer_ && IsRemoveBookmarksCommand(command_id))
123 observer_->WillRemoveBookmarks(bookmarks); 132 observer_->WillRemoveBookmarks(bookmarks);
124 } 133 }
125 134
126 void BookmarkContextMenu::DidExecuteCommand(int command_id) { 135 void BookmarkContextMenu::DidExecuteCommand(int command_id) {
127 if (observer_ && IsRemoveBookmarksCommand(command_id)) 136 if (observer_ && IsRemoveBookmarksCommand(command_id))
128 observer_->DidRemoveBookmarks(); 137 observer_->DidRemoveBookmarks();
129 } 138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698