OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/extensions/extension_action_platform_delegate_
views.h" | 5 #include "chrome/browser/ui/views/extensions/extension_action_platform_delegate_
views.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "chrome/browser/extensions/extension_action.h" | 8 #include "chrome/browser/extensions/extension_action.h" |
| 9 #include "chrome/browser/extensions/extension_view_host.h" |
9 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/extensions/accelerator_priority.h" | 12 #include "chrome/browser/ui/extensions/accelerator_priority.h" |
12 #include "chrome/browser/ui/views/frame/browser_view.h" | 13 #include "chrome/browser/ui/views/frame/browser_view.h" |
13 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 14 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
14 #include "chrome/browser/ui/views/toolbar/toolbar_action_view_delegate_views.h" | 15 #include "chrome/browser/ui/views/toolbar/toolbar_action_view_delegate_views.h" |
15 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 16 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
16 #include "chrome/common/extensions/api/extension_action/action_info.h" | 17 #include "chrome/common/extensions/api/extension_action/action_info.h" |
17 #include "chrome/common/extensions/command.h" | 18 #include "chrome/common/extensions/command.h" |
18 #include "content/public/browser/notification_details.h" | 19 #include "content/public/browser/notification_details.h" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 GetAcceleratorPriority(extension_command.accelerator(), | 85 GetAcceleratorPriority(extension_command.accelerator(), |
85 controller_->extension()), | 86 controller_->extension()), |
86 this); | 87 this); |
87 } | 88 } |
88 } | 89 } |
89 | 90 |
90 void ExtensionActionPlatformDelegateViews::OnDelegateSet() { | 91 void ExtensionActionPlatformDelegateViews::OnDelegateSet() { |
91 GetDelegateViews()->GetAsView()->set_context_menu_controller(this); | 92 GetDelegateViews()->GetAsView()->set_context_menu_controller(this); |
92 } | 93 } |
93 | 94 |
94 extensions::ExtensionViewHost* | 95 void ExtensionActionPlatformDelegateViews::ShowPopup( |
95 ExtensionActionPlatformDelegateViews::ShowPopupWithUrl( | 96 scoped_ptr<extensions::ExtensionViewHost> host, |
96 ExtensionActionViewController::PopupShowAction show_action, | 97 bool grant_tab_permissions, |
97 const GURL& popup_url, | 98 ExtensionActionViewController::PopupShowAction show_action) { |
98 bool grant_tab_permissions) { | |
99 // TOP_RIGHT is correct for both RTL and LTR, because the views platform | 99 // TOP_RIGHT is correct for both RTL and LTR, because the views platform |
100 // performs the flipping in RTL cases. | 100 // performs the flipping in RTL cases. |
101 views::BubbleBorder::Arrow arrow = views::BubbleBorder::TOP_RIGHT; | 101 views::BubbleBorder::Arrow arrow = views::BubbleBorder::TOP_RIGHT; |
102 | 102 |
103 views::View* reference_view = GetDelegateViews()->GetReferenceViewForPopup(); | 103 views::View* reference_view = GetDelegateViews()->GetReferenceViewForPopup(); |
104 | 104 |
105 ExtensionPopup::ShowAction popup_show_action = | 105 ExtensionPopup::ShowAction popup_show_action = |
106 show_action == ExtensionActionViewController::SHOW_POPUP ? | 106 show_action == ExtensionActionViewController::SHOW_POPUP ? |
107 ExtensionPopup::SHOW : ExtensionPopup::SHOW_AND_INSPECT; | 107 ExtensionPopup::SHOW : ExtensionPopup::SHOW_AND_INSPECT; |
108 ExtensionPopup* popup = ExtensionPopup::ShowPopup(popup_url, | 108 ExtensionPopup::ShowPopup(host.Pass(), |
109 controller_->browser(), | 109 reference_view, |
110 reference_view, | 110 arrow, |
111 arrow, | 111 popup_show_action); |
112 popup_show_action); | 112 } |
113 return popup->host(); | 113 |
| 114 void ExtensionActionPlatformDelegateViews::CloseOverflowMenu() { |
| 115 ToolbarView* toolbar = |
| 116 BrowserView::GetBrowserViewForBrowser(controller_->browser())->toolbar(); |
| 117 if (toolbar->IsWrenchMenuShowing()) |
| 118 toolbar->CloseAppMenu(); |
114 } | 119 } |
115 | 120 |
116 void ExtensionActionPlatformDelegateViews::Observe( | 121 void ExtensionActionPlatformDelegateViews::Observe( |
117 int type, | 122 int type, |
118 const content::NotificationSource& source, | 123 const content::NotificationSource& source, |
119 const content::NotificationDetails& details) { | 124 const content::NotificationDetails& details) { |
120 DCHECK(type == extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED || | 125 DCHECK(type == extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED || |
121 type == extensions::NOTIFICATION_EXTENSION_COMMAND_REMOVED); | 126 type == extensions::NOTIFICATION_EXTENSION_COMMAND_REMOVED); |
122 extensions::ExtensionCommandRemovedDetails* payload = | 127 extensions::ExtensionCommandRemovedDetails* payload = |
123 content::Details<extensions::ExtensionCommandRemovedDetails>(details) | 128 content::Details<extensions::ExtensionCommandRemovedDetails>(details) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 void ExtensionActionPlatformDelegateViews::DoShowContextMenu( | 195 void ExtensionActionPlatformDelegateViews::DoShowContextMenu( |
191 ui::MenuSourceType source_type) { | 196 ui::MenuSourceType source_type) { |
192 ui::MenuModel* context_menu_model = controller_->GetContextMenu(); | 197 ui::MenuModel* context_menu_model = controller_->GetContextMenu(); |
193 // It's possible the extension doesn't have a context menu. | 198 // It's possible the extension doesn't have a context menu. |
194 if (!context_menu_model) | 199 if (!context_menu_model) |
195 return; | 200 return; |
196 | 201 |
197 DCHECK(!context_menu_owner); | 202 DCHECK(!context_menu_owner); |
198 context_menu_owner = this; | 203 context_menu_owner = this; |
199 | 204 |
200 // We shouldn't have both a popup and a context menu showing. | |
201 controller_->HideActivePopup(); | |
202 | |
203 gfx::Point screen_loc; | 205 gfx::Point screen_loc; |
204 views::View::ConvertPointToScreen(GetDelegateViews()->GetAsView(), | 206 views::View::ConvertPointToScreen(GetDelegateViews()->GetAsView(), |
205 &screen_loc); | 207 &screen_loc); |
206 | 208 |
207 int run_types = | 209 int run_types = |
208 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU; | 210 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU; |
209 if (GetDelegateViews()->IsShownInMenu()) | 211 if (GetDelegateViews()->IsShownInMenu()) |
210 run_types |= views::MenuRunner::IS_NESTED; | 212 run_types |= views::MenuRunner::IS_NESTED; |
211 | 213 |
212 views::Widget* parent = GetDelegateViews()->GetParentForContextMenu(); | 214 views::Widget* parent = GetDelegateViews()->GetParentForContextMenu(); |
213 | 215 |
214 menu_runner_.reset(new views::MenuRunner(context_menu_model, run_types)); | 216 menu_runner_.reset(new views::MenuRunner(context_menu_model, run_types)); |
215 | 217 |
| 218 // We shouldn't have both a popup and a context menu showing. |
| 219 controller_->HideActivePopup(); |
| 220 |
216 if (menu_runner_->RunMenuAt( | 221 if (menu_runner_->RunMenuAt( |
217 parent, | 222 parent, |
218 GetDelegateViews()->GetContextMenuButton(), | 223 GetDelegateViews()->GetContextMenuButton(), |
219 gfx::Rect(screen_loc, GetDelegateViews()->GetAsView()->size()), | 224 gfx::Rect(screen_loc, GetDelegateViews()->GetAsView()->size()), |
220 views::MENU_ANCHOR_TOPLEFT, | 225 views::MENU_ANCHOR_TOPLEFT, |
221 source_type) == views::MenuRunner::MENU_DELETED) { | 226 source_type) == views::MenuRunner::MENU_DELETED) { |
222 return; | 227 return; |
223 } | 228 } |
224 | 229 |
225 context_menu_owner = NULL; | 230 context_menu_owner = NULL; |
226 menu_runner_.reset(); | 231 menu_runner_.reset(); |
| 232 controller_->OnMenuClosed(); |
227 | 233 |
228 // If another extension action wants to show its context menu, allow it to. | 234 // If another extension action wants to show its context menu, allow it to. |
229 if (!followup_context_menu_task_.is_null()) { | 235 if (!followup_context_menu_task_.is_null()) { |
230 base::Closure task = followup_context_menu_task_; | 236 base::Closure task = followup_context_menu_task_; |
231 followup_context_menu_task_ = base::Closure(); | 237 followup_context_menu_task_ = base::Closure(); |
232 task.Run(); | 238 task.Run(); |
233 } | 239 } |
234 } | 240 } |
235 | 241 |
236 void ExtensionActionPlatformDelegateViews::UnregisterCommand( | 242 void ExtensionActionPlatformDelegateViews::UnregisterCommand( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 } | 277 } |
272 | 278 |
273 return false; | 279 return false; |
274 } | 280 } |
275 | 281 |
276 ToolbarActionViewDelegateViews* | 282 ToolbarActionViewDelegateViews* |
277 ExtensionActionPlatformDelegateViews::GetDelegateViews() const { | 283 ExtensionActionPlatformDelegateViews::GetDelegateViews() const { |
278 return static_cast<ToolbarActionViewDelegateViews*>( | 284 return static_cast<ToolbarActionViewDelegateViews*>( |
279 controller_->view_delegate()); | 285 controller_->view_delegate()); |
280 } | 286 } |
OLD | NEW |