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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
158 // might be hidden in an overflow menu. | 163 // might be hidden in an overflow menu. |
159 return controller_->extension_action()->action_type() == | 164 return controller_->extension_action()->action_type() == |
160 ActionInfo::TYPE_PAGE ? GetDelegateViews()->GetAsView()->visible() : | 165 ActionInfo::TYPE_PAGE ? GetDelegateViews()->GetAsView()->visible() : |
161 true; | 166 true; |
162 } | 167 } |
163 | 168 |
164 void ExtensionActionPlatformDelegateViews::ShowContextMenuForView( | 169 void ExtensionActionPlatformDelegateViews::ShowContextMenuForView( |
165 views::View* source, | 170 views::View* source, |
166 const gfx::Point& point, | 171 const gfx::Point& point, |
167 ui::MenuSourceType source_type) { | 172 ui::MenuSourceType source_type) { |
173 LOG(WARNING) << "Show context menu for view"; | |
Finnur
2015/04/27 14:39:00
Accidentally included?
Devlin
2015/04/28 00:35:56
Done.
| |
168 // If there's another active menu that won't be dismissed by opening this one, | 174 // If there's another active menu that won't be dismissed by opening this one, |
169 // then we can't show this one right away, since we can only show one nested | 175 // then we can't show this one right away, since we can only show one nested |
170 // menu at a time. | 176 // menu at a time. |
171 // If the other menu is an extension action's context menu, then we'll run | 177 // If the other menu is an extension action's context menu, then we'll run |
172 // this one after that one closes. If it's a different type of menu, then we | 178 // this one after that one closes. If it's a different type of menu, then we |
173 // close it and give up, for want of a better solution. (Luckily, this is | 179 // close it and give up, for want of a better solution. (Luckily, this is |
174 // rare). | 180 // rare). |
175 // TODO(devlin): Update this when views code no longer runs menus in a nested | 181 // TODO(devlin): Update this when views code no longer runs menus in a nested |
176 // loop. | 182 // loop. |
177 if (context_menu_owner) { | 183 if (context_menu_owner) { |
178 context_menu_owner->followup_context_menu_task_ = | 184 context_menu_owner->followup_context_menu_task_ = |
179 base::Bind(&ExtensionActionPlatformDelegateViews::DoShowContextMenu, | 185 base::Bind(&ExtensionActionPlatformDelegateViews::DoShowContextMenu, |
180 weak_factory_.GetWeakPtr(), | 186 weak_factory_.GetWeakPtr(), |
181 source_type); | 187 source_type); |
182 } | 188 } |
183 if (CloseActiveMenuIfNeeded()) | 189 if (CloseActiveMenuIfNeeded()) |
184 return; | 190 return; |
185 | 191 |
192 LOG(WARNING) << "Do Show"; | |
Finnur
2015/04/27 14:39:00
Accidentally included?
Devlin
2015/04/28 00:35:56
Done.
| |
186 // Otherwise, no other menu is showing, and we can proceed normally. | 193 // Otherwise, no other menu is showing, and we can proceed normally. |
187 DoShowContextMenu(source_type); | 194 DoShowContextMenu(source_type); |
188 } | 195 } |
189 | 196 |
190 void ExtensionActionPlatformDelegateViews::DoShowContextMenu( | 197 void ExtensionActionPlatformDelegateViews::DoShowContextMenu( |
191 ui::MenuSourceType source_type) { | 198 ui::MenuSourceType source_type) { |
192 ui::MenuModel* context_menu_model = controller_->GetContextMenu(); | 199 ui::MenuModel* context_menu_model = controller_->GetContextMenu(); |
193 // It's possible the extension doesn't have a context menu. | 200 // It's possible the extension doesn't have a context menu. |
194 if (!context_menu_model) | 201 if (!context_menu_model) |
195 return; | 202 return; |
196 | 203 |
197 DCHECK(!context_menu_owner); | 204 DCHECK(!context_menu_owner); |
198 context_menu_owner = this; | 205 context_menu_owner = this; |
199 | 206 |
200 // We shouldn't have both a popup and a context menu showing. | |
201 controller_->HideActivePopup(); | |
202 | |
203 gfx::Point screen_loc; | 207 gfx::Point screen_loc; |
204 views::View::ConvertPointToScreen(GetDelegateViews()->GetAsView(), | 208 views::View::ConvertPointToScreen(GetDelegateViews()->GetAsView(), |
205 &screen_loc); | 209 &screen_loc); |
206 | 210 |
207 int run_types = | 211 int run_types = |
208 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU; | 212 views::MenuRunner::HAS_MNEMONICS | views::MenuRunner::CONTEXT_MENU; |
209 if (GetDelegateViews()->IsShownInMenu()) | 213 if (GetDelegateViews()->IsShownInMenu()) |
210 run_types |= views::MenuRunner::IS_NESTED; | 214 run_types |= views::MenuRunner::IS_NESTED; |
211 | 215 |
212 views::Widget* parent = GetDelegateViews()->GetParentForContextMenu(); | 216 views::Widget* parent = GetDelegateViews()->GetParentForContextMenu(); |
213 | 217 |
214 menu_runner_.reset(new views::MenuRunner(context_menu_model, run_types)); | 218 menu_runner_.reset(new views::MenuRunner(context_menu_model, run_types)); |
215 | 219 |
220 // We shouldn't have both a popup and a context menu showing. | |
221 controller_->HideActivePopup(); | |
222 | |
216 if (menu_runner_->RunMenuAt( | 223 if (menu_runner_->RunMenuAt( |
217 parent, | 224 parent, |
218 GetDelegateViews()->GetContextMenuButton(), | 225 GetDelegateViews()->GetContextMenuButton(), |
219 gfx::Rect(screen_loc, GetDelegateViews()->GetAsView()->size()), | 226 gfx::Rect(screen_loc, GetDelegateViews()->GetAsView()->size()), |
220 views::MENU_ANCHOR_TOPLEFT, | 227 views::MENU_ANCHOR_TOPLEFT, |
221 source_type) == views::MenuRunner::MENU_DELETED) { | 228 source_type) == views::MenuRunner::MENU_DELETED) { |
222 return; | 229 return; |
223 } | 230 } |
224 | 231 |
232 LOG(WARNING) << "Ran"; | |
Finnur
2015/04/27 14:39:00
Accidentally included? ... or just checking to see
Devlin
2015/04/28 00:35:56
Nope, just those "rough edges" I mentioned. ;)
| |
225 context_menu_owner = NULL; | 233 context_menu_owner = NULL; |
226 menu_runner_.reset(); | 234 menu_runner_.reset(); |
235 controller_->OnMenuClosed(); | |
227 | 236 |
228 // If another extension action wants to show its context menu, allow it to. | 237 // If another extension action wants to show its context menu, allow it to. |
229 if (!followup_context_menu_task_.is_null()) { | 238 if (!followup_context_menu_task_.is_null()) { |
230 base::Closure task = followup_context_menu_task_; | 239 base::Closure task = followup_context_menu_task_; |
231 followup_context_menu_task_ = base::Closure(); | 240 followup_context_menu_task_ = base::Closure(); |
232 task.Run(); | 241 task.Run(); |
233 } | 242 } |
234 } | 243 } |
235 | 244 |
236 void ExtensionActionPlatformDelegateViews::UnregisterCommand( | 245 void ExtensionActionPlatformDelegateViews::UnregisterCommand( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 } | 280 } |
272 | 281 |
273 return false; | 282 return false; |
274 } | 283 } |
275 | 284 |
276 ToolbarActionViewDelegateViews* | 285 ToolbarActionViewDelegateViews* |
277 ExtensionActionPlatformDelegateViews::GetDelegateViews() const { | 286 ExtensionActionPlatformDelegateViews::GetDelegateViews() const { |
278 return static_cast<ToolbarActionViewDelegateViews*>( | 287 return static_cast<ToolbarActionViewDelegateViews*>( |
279 controller_->view_delegate()); | 288 controller_->view_delegate()); |
280 } | 289 } |
OLD | NEW |