OLD | NEW |
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 Loading... |
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 menu_runner_->RunMenuAt(parent_widget_, nullptr, |
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, source_type); |
78 views::MENU_ANCHOR_TOPLEFT, | |
79 source_type) == views::MenuRunner::MENU_DELETED) { | |
80 return; | |
81 } | |
82 } | 84 } |
83 | 85 |
84 void BookmarkContextMenu::SetPageNavigator(PageNavigator* navigator) { | 86 void BookmarkContextMenu::SetPageNavigator(PageNavigator* navigator) { |
85 controller_->set_navigator(navigator); | 87 controller_->set_navigator(navigator); |
86 } | 88 } |
87 | 89 |
88 //////////////////////////////////////////////////////////////////////////////// | 90 //////////////////////////////////////////////////////////////////////////////// |
89 // BookmarkContextMenu, views::MenuDelegate implementation: | 91 // BookmarkContextMenu, views::MenuDelegate implementation: |
90 | 92 |
91 void BookmarkContextMenu::ExecuteCommand(int command_id, int event_flags) { | 93 void BookmarkContextMenu::ExecuteCommand(int command_id, int event_flags) { |
92 controller_->ExecuteCommand(command_id, event_flags); | 94 controller_->ExecuteCommand(command_id, event_flags); |
93 } | 95 } |
94 | 96 |
95 bool BookmarkContextMenu::IsItemChecked(int command_id) const { | 97 bool BookmarkContextMenu::IsItemChecked(int command_id) const { |
96 return controller_->IsCommandIdChecked(command_id); | 98 return controller_->IsCommandIdChecked(command_id); |
97 } | 99 } |
98 | 100 |
99 bool BookmarkContextMenu::IsCommandEnabled(int command_id) const { | 101 bool BookmarkContextMenu::IsCommandEnabled(int command_id) const { |
100 return controller_->IsCommandIdEnabled(command_id); | 102 return controller_->IsCommandIdEnabled(command_id); |
101 } | 103 } |
102 | 104 |
103 bool BookmarkContextMenu::IsCommandVisible(int command_id) const { | 105 bool BookmarkContextMenu::IsCommandVisible(int command_id) const { |
104 return controller_->IsCommandIdVisible(command_id); | 106 return controller_->IsCommandIdVisible(command_id); |
105 } | 107 } |
106 | 108 |
107 bool BookmarkContextMenu::ShouldCloseAllMenusOnExecute(int id) { | 109 bool BookmarkContextMenu::ShouldCloseAllMenusOnExecute(int id) { |
108 return (id != IDC_BOOKMARK_BAR_REMOVE) || close_on_remove_; | 110 return (id != IDC_BOOKMARK_BAR_REMOVE) || close_on_remove_; |
109 } | 111 } |
110 | 112 |
| 113 void BookmarkContextMenu::OnMenuClosed(views::MenuItemView* menu, |
| 114 views::MenuRunner::RunResult result) { |
| 115 if (observer_) |
| 116 observer_->OnContextMenuClosed(); |
| 117 } |
| 118 |
111 //////////////////////////////////////////////////////////////////////////////// | 119 //////////////////////////////////////////////////////////////////////////////// |
112 // BookmarkContextMenuControllerDelegate | 120 // BookmarkContextMenuControllerDelegate |
113 // implementation: | 121 // implementation: |
114 | 122 |
115 void BookmarkContextMenu::CloseMenu() { | 123 void BookmarkContextMenu::CloseMenu() { |
116 menu_->Cancel(); | 124 menu_->Cancel(); |
117 } | 125 } |
118 | 126 |
119 void BookmarkContextMenu::WillExecuteCommand( | 127 void BookmarkContextMenu::WillExecuteCommand( |
120 int command_id, | 128 int command_id, |
121 const std::vector<const BookmarkNode*>& bookmarks) { | 129 const std::vector<const BookmarkNode*>& bookmarks) { |
122 if (observer_ && IsRemoveBookmarksCommand(command_id)) | 130 if (observer_ && IsRemoveBookmarksCommand(command_id)) |
123 observer_->WillRemoveBookmarks(bookmarks); | 131 observer_->WillRemoveBookmarks(bookmarks); |
124 } | 132 } |
125 | 133 |
126 void BookmarkContextMenu::DidExecuteCommand(int command_id) { | 134 void BookmarkContextMenu::DidExecuteCommand(int command_id) { |
127 if (observer_ && IsRemoveBookmarksCommand(command_id)) | 135 if (observer_ && IsRemoveBookmarksCommand(command_id)) |
128 observer_->DidRemoveBookmarks(); | 136 observer_->DidRemoveBookmarks(); |
129 } | 137 } |
OLD | NEW |