OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/toolbar/browser_action_view.h" | 5 #include "chrome/browser/ui/views/toolbar/browser_action_view.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | |
10 #include "chrome/browser/chrome_notification_types.h" | 9 #include "chrome/browser/chrome_notification_types.h" |
11 #include "chrome/browser/extensions/extension_action.h" | |
12 #include "chrome/browser/profiles/profile.h" | 10 #include "chrome/browser/profiles/profile.h" |
11 #include "chrome/browser/sessions/session_tab_helper.h" | |
13 #include "chrome/browser/themes/theme_service.h" | 12 #include "chrome/browser/themes/theme_service.h" |
14 #include "chrome/browser/themes/theme_service_factory.h" | 13 #include "chrome/browser/themes/theme_service_factory.h" |
15 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/toolbar/toolbar_action_view_controller.h" | |
16 #include "chrome/browser/ui/view_ids.h" | 16 #include "chrome/browser/ui/view_ids.h" |
17 #include "chrome/browser/ui/views/extensions/extension_action_view_controller.h" | |
17 #include "chrome/browser/ui/views/frame/browser_view.h" | 18 #include "chrome/browser/ui/views/frame/browser_view.h" |
18 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" | 19 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h" |
19 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" | 20 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" |
20 #include "chrome/grit/generated_resources.h" | 21 #include "chrome/grit/generated_resources.h" |
21 #include "extensions/common/extension.h" | |
22 #include "extensions/common/manifest_constants.h" | |
23 #include "grit/theme_resources.h" | 22 #include "grit/theme_resources.h" |
24 #include "ui/accessibility/ax_view_state.h" | 23 #include "ui/accessibility/ax_view_state.h" |
25 #include "ui/base/l10n/l10n_util.h" | |
26 #include "ui/base/resource/resource_bundle.h" | |
27 #include "ui/events/event.h" | 24 #include "ui/events/event.h" |
28 #include "ui/gfx/image/image_skia.h" | 25 #include "ui/gfx/image/image_skia.h" |
29 #include "ui/gfx/image/image_skia_operations.h" | 26 #include "ui/gfx/image/image_skia_operations.h" |
30 #include "ui/gfx/image/image_skia_source.h" | 27 #include "ui/gfx/image/image_skia_source.h" |
31 #include "ui/views/controls/button/label_button_border.h" | 28 #include "ui/views/controls/button/label_button_border.h" |
32 | 29 |
33 using extensions::Extension; | |
34 using views::LabelButtonBorder; | 30 using views::LabelButtonBorder; |
35 | 31 |
36 namespace { | 32 namespace { |
37 | 33 |
38 // We have smaller insets than normal STYLE_TEXTBUTTON buttons so that we can | 34 // We have smaller insets than normal STYLE_TEXTBUTTON buttons so that we can |
39 // fit user supplied icons in without clipping them. | 35 // fit user supplied icons in without clipping them. |
40 const int kBorderInset = 4; | 36 const int kBorderInset = 4; |
41 | 37 |
42 } // namespace | 38 } // namespace |
43 | 39 |
44 //////////////////////////////////////////////////////////////////////////////// | 40 //////////////////////////////////////////////////////////////////////////////// |
45 // BrowserActionView | 41 // BrowserActionView |
46 | 42 |
47 BrowserActionView::BrowserActionView(const Extension* extension, | 43 BrowserActionView::BrowserActionView( |
48 ExtensionAction* extension_action, | 44 scoped_ptr<ToolbarActionViewController> view_controller, |
49 Browser* browser, | 45 Browser* browser, |
50 BrowserActionView::Delegate* delegate) | 46 BrowserActionView::Delegate* delegate) |
51 : MenuButton(this, base::string16(), NULL, false), | 47 : MenuButton(this, base::string16(), NULL, false), |
52 view_controller_(new ExtensionActionViewController( | 48 view_controller_(view_controller.Pass()), |
53 extension, | 49 browser_(browser), |
54 browser, | |
55 extension_action, | |
56 this)), | |
57 delegate_(delegate), | 50 delegate_(delegate), |
58 called_registered_extension_command_(false), | 51 called_register_command_(false) { |
59 icon_observer_(NULL) { | |
60 set_id(VIEW_ID_BROWSER_ACTION); | 52 set_id(VIEW_ID_BROWSER_ACTION); |
53 view_controller_->SetDelegate(this); | |
61 SetHorizontalAlignment(gfx::ALIGN_CENTER); | 54 SetHorizontalAlignment(gfx::ALIGN_CENTER); |
62 set_context_menu_controller(view_controller_.get()); | 55 if (view_controller_->GetType() == |
63 set_drag_controller(delegate_); | 56 ToolbarActionViewController::TYPE_EXTENSION_ACTION) { |
64 | 57 // Right now, only support dragging for extension actions (because the |
65 content::NotificationSource notification_source = | 58 // underlying model doesn't support component actions). |
66 content::Source<Profile>(browser->profile()->GetOriginalProfile()); | 59 // TODO(devlin): |
Finnur
2014/10/17 09:57:02
TODO(devlin): Finish that thought? :)
Devlin
2014/10/17 16:33:33
Haha whoops. :) Done (though this comment actuall
| |
67 registrar_.Add(this, | 60 set_drag_controller(delegate_); |
68 extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED, | 61 } |
69 notification_source); | |
70 registrar_.Add(this, | |
71 extensions::NOTIFICATION_EXTENSION_COMMAND_REMOVED, | |
72 notification_source); | |
73 | 62 |
74 // We also listen for browser theme changes on linux because a switch from or | 63 // We also listen for browser theme changes on linux because a switch from or |
75 // to GTK requires that we regrab our browser action images. | 64 // to GTK requires that we regrab our browser action images. |
76 registrar_.Add( | 65 registrar_.Add( |
77 this, | 66 this, |
78 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | 67 chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
79 content::Source<ThemeService>( | 68 content::Source<ThemeService>( |
80 ThemeServiceFactory::GetForProfile(browser->profile()))); | 69 ThemeServiceFactory::GetForProfile(browser->profile()))); |
81 | 70 |
82 UpdateState(); | 71 UpdateState(); |
83 } | 72 } |
84 | 73 |
85 BrowserActionView::~BrowserActionView() { | 74 BrowserActionView::~BrowserActionView() { |
86 } | 75 } |
87 | 76 |
88 void BrowserActionView::ViewHierarchyChanged( | 77 void BrowserActionView::ViewHierarchyChanged( |
89 const ViewHierarchyChangedDetails& details) { | 78 const ViewHierarchyChangedDetails& details) { |
90 if (details.is_add && !called_registered_extension_command_ && | 79 if (details.is_add && !called_register_command_ && GetFocusManager()) { |
91 GetFocusManager()) { | |
92 view_controller_->RegisterCommand(); | 80 view_controller_->RegisterCommand(); |
93 called_registered_extension_command_ = true; | 81 called_register_command_ = true; |
94 } | 82 } |
95 | 83 |
96 MenuButton::ViewHierarchyChanged(details); | 84 MenuButton::ViewHierarchyChanged(details); |
97 } | 85 } |
98 | 86 |
99 void BrowserActionView::OnDragDone() { | 87 void BrowserActionView::OnDragDone() { |
100 delegate_->OnBrowserActionViewDragDone(); | 88 delegate_->OnBrowserActionViewDragDone(); |
101 } | 89 } |
102 | 90 |
103 gfx::Size BrowserActionView::GetPreferredSize() const { | 91 gfx::Size BrowserActionView::GetPreferredSize() const { |
104 return gfx::Size(BrowserActionsContainer::IconWidth(false), | 92 return gfx::Size(BrowserActionsContainer::IconWidth(false), |
105 BrowserActionsContainer::IconHeight()); | 93 BrowserActionsContainer::IconHeight()); |
106 } | 94 } |
107 | 95 |
108 void BrowserActionView::PaintChildren(gfx::Canvas* canvas, | 96 void BrowserActionView::PaintChildren(gfx::Canvas* canvas, |
109 const views::CullSet& cull_set) { | 97 const views::CullSet& cull_set) { |
110 View::PaintChildren(canvas, cull_set); | 98 View::PaintChildren(canvas, cull_set); |
111 int tab_id = view_controller_->GetCurrentTabId(); | 99 view_controller_->PaintExtra( |
112 if (tab_id >= 0) | 100 canvas, GetLocalBounds(), GetCurrentWebContents()); |
113 extension_action()->PaintBadge(canvas, GetLocalBounds(), tab_id); | |
114 } | 101 } |
115 | 102 |
116 void BrowserActionView::GetAccessibleState(ui::AXViewState* state) { | 103 void BrowserActionView::GetAccessibleState(ui::AXViewState* state) { |
117 views::MenuButton::GetAccessibleState(state); | 104 views::MenuButton::GetAccessibleState(state); |
118 state->role = ui::AX_ROLE_BUTTON; | 105 state->role = ui::AX_ROLE_BUTTON; |
119 } | 106 } |
120 | 107 |
121 void BrowserActionView::ButtonPressed(views::Button* sender, | 108 void BrowserActionView::ButtonPressed(views::Button* sender, |
122 const ui::Event& event) { | 109 const ui::Event& event) { |
123 view_controller_->ExecuteActionByUser(); | 110 view_controller_->ExecuteActionByUser(); |
124 } | 111 } |
125 | 112 |
126 void BrowserActionView::UpdateState() { | 113 void BrowserActionView::UpdateState() { |
127 int tab_id = view_controller_->GetCurrentTabId(); | 114 content::WebContents* web_contents = GetCurrentWebContents(); |
128 if (tab_id < 0) | 115 if (!web_contents || SessionTabHelper::IdForTab(web_contents) < 0) |
129 return; | 116 return; |
130 | 117 |
131 if (!IsEnabled(tab_id)) | 118 bool enabled = view_controller_->IsEnabled(web_contents); |
119 if (!enabled) | |
132 SetState(views::CustomButton::STATE_DISABLED); | 120 SetState(views::CustomButton::STATE_DISABLED); |
133 | 121 |
134 gfx::ImageSkia icon = *view_controller_->GetIcon(tab_id).ToImageSkia(); | 122 gfx::ImageSkia icon = *view_controller_->GetIcon(web_contents).ToImageSkia(); |
135 | 123 |
136 if (!icon.isNull()) { | 124 if (!icon.isNull()) { |
137 if (!extension_action()->GetIsVisible(tab_id)) | 125 if (!enabled) |
138 icon = gfx::ImageSkiaOperations::CreateTransparentImage(icon, .25); | 126 icon = gfx::ImageSkiaOperations::CreateTransparentImage(icon, .25); |
139 | 127 |
140 ThemeService* theme = ThemeServiceFactory::GetForProfile( | 128 ThemeService* theme = |
141 view_controller_->browser()->profile()); | 129 ThemeServiceFactory::GetForProfile(browser_->profile()); |
142 | 130 |
143 gfx::ImageSkia bg = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION); | 131 gfx::ImageSkia bg = *theme->GetImageSkiaNamed(IDR_BROWSER_ACTION); |
144 SetImage(views::Button::STATE_NORMAL, | 132 SetImage(views::Button::STATE_NORMAL, |
145 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon)); | 133 gfx::ImageSkiaOperations::CreateSuperimposedImage(bg, icon)); |
146 } | 134 } |
147 | 135 |
148 // If the browser action name is empty, show the extension name instead. | 136 SetTooltipText(view_controller_->GetTooltip(web_contents)); |
149 std::string title = extension_action()->GetTitle(tab_id); | 137 SetAccessibleName(view_controller_->GetAccessibleName(web_contents)); |
150 base::string16 name = | |
151 base::UTF8ToUTF16(title.empty() ? extension()->name() : title); | |
152 SetTooltipText(name); | |
153 SetAccessibleName(name); | |
154 | 138 |
155 Layout(); // We need to layout since we may have added an icon as a result. | 139 Layout(); // We need to layout since we may have added an icon as a result. |
156 SchedulePaint(); | 140 SchedulePaint(); |
157 } | 141 } |
158 | 142 |
159 bool BrowserActionView::IsPopup() { | |
160 int tab_id = view_controller_->GetCurrentTabId(); | |
161 return (tab_id < 0) ? false : extension_action()->HasPopup(tab_id); | |
162 } | |
163 | |
164 void BrowserActionView::Observe(int type, | 143 void BrowserActionView::Observe(int type, |
165 const content::NotificationSource& source, | 144 const content::NotificationSource& source, |
166 const content::NotificationDetails& details) { | 145 const content::NotificationDetails& details) { |
167 switch (type) { | 146 DCHECK_EQ(chrome::NOTIFICATION_BROWSER_THEME_CHANGED, type); |
168 case extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED: | 147 UpdateState(); |
169 case extensions::NOTIFICATION_EXTENSION_COMMAND_REMOVED: { | |
170 std::pair<const std::string, const std::string>* payload = | |
171 content::Details<std::pair<const std::string, const std::string> >( | |
172 details).ptr(); | |
173 if (extension()->id() == payload->first && | |
174 payload->second == | |
175 extensions::manifest_values::kBrowserActionCommandEvent) { | |
176 if (type == extensions::NOTIFICATION_EXTENSION_COMMAND_ADDED) | |
177 view_controller_->RegisterCommand(); | |
178 else | |
179 view_controller_->UnregisterCommand(true); | |
180 } | |
181 break; | |
182 } | |
183 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: | |
184 UpdateState(); | |
185 break; | |
186 default: | |
187 NOTREACHED(); | |
188 break; | |
189 } | |
190 } | 148 } |
191 | 149 |
192 bool BrowserActionView::Activate() { | 150 bool BrowserActionView::Activate() { |
193 if (!IsPopup()) | 151 if (!view_controller_->HasPopup(GetCurrentWebContents())) |
194 return true; | 152 return true; |
195 | 153 |
196 view_controller_->ExecuteActionByUser(); | 154 view_controller_->ExecuteActionByUser(); |
197 | 155 |
198 // TODO(erikkay): Run a nested modal loop while the mouse is down to | 156 // TODO(erikkay): Run a nested modal loop while the mouse is down to |
199 // enable menu-like drag-select behavior. | 157 // enable menu-like drag-select behavior. |
200 | 158 |
201 // The return value of this method is returned via OnMousePressed. | 159 // The return value of this method is returned via OnMousePressed. |
202 // We need to return false here since we're handing off focus to another | 160 // We need to return false here since we're handing off focus to another |
203 // widget/view, and true will grab it right back and try to send events | 161 // widget/view, and true will grab it right back and try to send events |
204 // to us. | 162 // to us. |
205 return false; | 163 return false; |
206 } | 164 } |
207 | 165 |
208 bool BrowserActionView::OnMousePressed(const ui::MouseEvent& event) { | 166 bool BrowserActionView::OnMousePressed(const ui::MouseEvent& event) { |
209 if (!event.IsRightMouseButton()) { | 167 if (!event.IsRightMouseButton()) { |
210 return IsPopup() ? MenuButton::OnMousePressed(event) : | 168 return view_controller_->HasPopup(GetCurrentWebContents()) ? |
211 LabelButton::OnMousePressed(event); | 169 MenuButton::OnMousePressed(event) : LabelButton::OnMousePressed(event); |
212 } | 170 } |
213 return false; | 171 return false; |
214 } | 172 } |
215 | 173 |
216 void BrowserActionView::OnMouseReleased(const ui::MouseEvent& event) { | 174 void BrowserActionView::OnMouseReleased(const ui::MouseEvent& event) { |
217 if (IsPopup() || view_controller_->is_menu_running()) { | 175 if (view_controller_->HasPopup(GetCurrentWebContents()) || |
176 view_controller_->IsMenuRunning()) { | |
218 // TODO(erikkay) this never actually gets called (probably because of the | 177 // TODO(erikkay) this never actually gets called (probably because of the |
219 // loss of focus). | 178 // loss of focus). |
220 MenuButton::OnMouseReleased(event); | 179 MenuButton::OnMouseReleased(event); |
221 } else { | 180 } else { |
222 LabelButton::OnMouseReleased(event); | 181 LabelButton::OnMouseReleased(event); |
223 } | 182 } |
224 } | 183 } |
225 | 184 |
226 void BrowserActionView::OnMouseExited(const ui::MouseEvent& event) { | 185 void BrowserActionView::OnMouseExited(const ui::MouseEvent& event) { |
227 if (IsPopup() || view_controller_->is_menu_running()) | 186 if (view_controller_->HasPopup(GetCurrentWebContents()) || |
187 view_controller_->IsMenuRunning()) | |
228 MenuButton::OnMouseExited(event); | 188 MenuButton::OnMouseExited(event); |
229 else | 189 else |
230 LabelButton::OnMouseExited(event); | 190 LabelButton::OnMouseExited(event); |
231 } | 191 } |
232 | 192 |
233 bool BrowserActionView::OnKeyReleased(const ui::KeyEvent& event) { | 193 bool BrowserActionView::OnKeyReleased(const ui::KeyEvent& event) { |
234 return IsPopup() ? MenuButton::OnKeyReleased(event) : | 194 return view_controller_->HasPopup(GetCurrentWebContents()) ? |
235 LabelButton::OnKeyReleased(event); | 195 MenuButton::OnKeyReleased(event) : LabelButton::OnKeyReleased(event); |
236 } | 196 } |
237 | 197 |
238 void BrowserActionView::OnGestureEvent(ui::GestureEvent* event) { | 198 void BrowserActionView::OnGestureEvent(ui::GestureEvent* event) { |
239 if (IsPopup()) | 199 if (view_controller_->HasPopup(GetCurrentWebContents())) |
240 MenuButton::OnGestureEvent(event); | 200 MenuButton::OnGestureEvent(event); |
241 else | 201 else |
242 LabelButton::OnGestureEvent(event); | 202 LabelButton::OnGestureEvent(event); |
243 } | 203 } |
244 | 204 |
245 scoped_ptr<LabelButtonBorder> BrowserActionView::CreateDefaultBorder() const { | 205 scoped_ptr<LabelButtonBorder> BrowserActionView::CreateDefaultBorder() const { |
246 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); | 206 scoped_ptr<LabelButtonBorder> border = LabelButton::CreateDefaultBorder(); |
247 border->set_insets(gfx::Insets(kBorderInset, kBorderInset, | 207 border->set_insets(gfx::Insets(kBorderInset, kBorderInset, |
248 kBorderInset, kBorderInset)); | 208 kBorderInset, kBorderInset)); |
249 return border.Pass(); | 209 return border.Pass(); |
250 } | 210 } |
251 | 211 |
252 bool BrowserActionView::IsEnabled(int tab_id) const { | 212 ExtensionActionViewController* |
253 return view_controller_->extension_action()->GetIsVisible(tab_id); | 213 BrowserActionView::GetExtensionActionViewController() { |
254 } | 214 CHECK_EQ(ToolbarActionViewController::TYPE_EXTENSION_ACTION, |
255 | 215 view_controller_->GetType()); |
256 gfx::ImageSkia BrowserActionView::GetIconWithBadge() { | 216 return static_cast<ExtensionActionViewController*>(view_controller()); |
257 int tab_id = view_controller_->GetCurrentTabId(); | |
258 gfx::Size spacing(0, ToolbarView::kVertSpacing); | |
259 gfx::ImageSkia icon = *view_controller_->GetIcon(tab_id).ToImageSkia(); | |
260 if (!IsEnabled(tab_id)) | |
261 icon = gfx::ImageSkiaOperations::CreateTransparentImage(icon, .25); | |
262 return extension_action()->GetIconWithBadge(icon, tab_id, spacing); | |
263 } | 217 } |
264 | 218 |
265 gfx::ImageSkia BrowserActionView::GetIconForTest() { | 219 gfx::ImageSkia BrowserActionView::GetIconForTest() { |
266 return GetImage(views::Button::STATE_NORMAL); | 220 return GetImage(views::Button::STATE_NORMAL); |
267 } | 221 } |
268 | 222 |
269 void BrowserActionView::OnIconUpdated() { | 223 void BrowserActionView::OnIconUpdated() { |
270 UpdateState(); | 224 UpdateState(); |
271 if (icon_observer_) | |
272 icon_observer_->OnIconUpdated(GetIconWithBadge()); | |
273 } | 225 } |
274 | 226 |
275 views::View* BrowserActionView::GetAsView() { | 227 views::View* BrowserActionView::GetAsView() { |
276 return this; | 228 return this; |
277 } | 229 } |
278 | 230 |
279 bool BrowserActionView::IsShownInMenu() { | 231 bool BrowserActionView::IsShownInMenu() { |
280 return delegate_->ShownInsideMenu(); | 232 return delegate_->ShownInsideMenu(); |
281 } | 233 } |
282 | 234 |
283 views::FocusManager* BrowserActionView::GetFocusManagerForAccelerator() { | 235 views::FocusManager* BrowserActionView::GetFocusManagerForAccelerator() { |
284 return GetFocusManager(); | 236 return GetFocusManager(); |
285 } | 237 } |
286 | 238 |
287 views::Widget* BrowserActionView::GetParentForContextMenu() { | 239 views::Widget* BrowserActionView::GetParentForContextMenu() { |
288 // RunMenuAt expects a nested menu to be parented by the same widget as the | 240 // RunMenuAt expects a nested menu to be parented by the same widget as the |
289 // already visible menu, in this case the Chrome menu. | 241 // already visible menu, in this case the Chrome menu. |
290 return delegate_->ShownInsideMenu() ? | 242 return delegate_->ShownInsideMenu() ? |
291 BrowserView::GetBrowserViewForBrowser(view_controller_->browser()) | 243 BrowserView::GetBrowserViewForBrowser(browser_) |
292 ->toolbar()->app_menu()->GetWidget() : | 244 ->toolbar()->app_menu()->GetWidget() : |
293 GetWidget(); | 245 GetWidget(); |
294 } | 246 } |
295 | 247 |
296 ExtensionActionViewController* | 248 ToolbarActionViewController* |
297 BrowserActionView::GetPreferredPopupViewController() { | 249 BrowserActionView::GetPreferredPopupViewController() { |
298 return delegate_->ShownInsideMenu() ? | 250 return delegate_->ShownInsideMenu() ? |
299 delegate_->GetMainViewForExtension(extension())->view_controller() : | 251 delegate_->GetMainViewForAction(this)->view_controller() : |
300 view_controller(); | 252 view_controller(); |
301 } | 253 } |
302 | 254 |
303 views::View* BrowserActionView::GetReferenceViewForPopup() { | 255 views::View* BrowserActionView::GetReferenceViewForPopup() { |
304 // Browser actions in the overflow menu can still show popups, so we may need | 256 // Browser actions in the overflow menu can still show popups, so we may need |
305 // a reference view other than this button's parent. If so, use the overflow | 257 // a reference view other than this button's parent. If so, use the overflow |
306 // view. | 258 // view. |
307 return visible() ? this : delegate_->GetOverflowReferenceView(); | 259 return visible() ? this : delegate_->GetOverflowReferenceView(); |
308 } | 260 } |
309 | 261 |
310 views::MenuButton* BrowserActionView::GetContextMenuButton() { | 262 views::MenuButton* BrowserActionView::GetContextMenuButton() { |
311 DCHECK(visible()); // We should never show a context menu for a hidden item. | 263 DCHECK(visible()); // We should never show a context menu for a hidden item. |
312 return this; | 264 return this; |
313 } | 265 } |
314 | 266 |
315 content::WebContents* BrowserActionView::GetCurrentWebContents() { | 267 content::WebContents* BrowserActionView::GetCurrentWebContents() const { |
316 return delegate_->GetCurrentWebContents(); | 268 return delegate_->GetCurrentWebContents(); |
317 } | 269 } |
318 | 270 |
319 void BrowserActionView::HideActivePopup() { | 271 void BrowserActionView::HideActivePopup() { |
320 delegate_->HideActivePopup(); | 272 delegate_->HideActivePopup(); |
321 } | 273 } |
322 | 274 |
323 void BrowserActionView::OnPopupShown(bool grant_tab_permissions) { | 275 void BrowserActionView::OnPopupShown(bool grant_tab_permissions) { |
324 delegate_->SetPopupOwner(this); | 276 delegate_->SetPopupOwner(this); |
325 // If this was through direct user action, we press the menu button. | 277 // If this was through direct user action, we press the menu button. |
326 if (grant_tab_permissions) { | 278 if (grant_tab_permissions) { |
327 // We set the state of the menu button we're using as a reference view, | 279 // We set the state of the menu button we're using as a reference view, |
328 // which is either this or the overflow reference view. | 280 // which is either this or the overflow reference view. |
329 // This cast is safe because GetReferenceViewForPopup returns either |this| | 281 // This cast is safe because GetReferenceViewForPopup returns either |this| |
330 // or delegate_->GetOverflowReferenceView(), which returns a MenuButton. | 282 // or delegate_->GetOverflowReferenceView(), which returns a MenuButton. |
331 views::MenuButton* reference_view = | 283 views::MenuButton* reference_view = |
332 static_cast<views::MenuButton*>(GetReferenceViewForPopup()); | 284 static_cast<views::MenuButton*>(GetReferenceViewForPopup()); |
333 pressed_lock_.reset(new views::MenuButton::PressedLock(reference_view)); | 285 pressed_lock_.reset(new views::MenuButton::PressedLock(reference_view)); |
334 } | 286 } |
335 } | 287 } |
336 | 288 |
337 void BrowserActionView::CleanupPopup() { | 289 void BrowserActionView::CleanupPopup() { |
338 // We need to do these actions synchronously (instead of closing and then | 290 // We need to do these actions synchronously (instead of closing and then |
339 // performing the rest of the cleanup in OnWidgetDestroyed()) because | 291 // performing the rest of the cleanup in OnWidgetDestroyed()) because |
340 // OnWidgetDestroyed() can be called asynchronously from Close(), and we need | 292 // OnWidgetDestroyed() can be called asynchronously from Close(), and we need |
341 // to keep the delegate's popup owner up-to-date. | 293 // to keep the delegate's popup owner up-to-date. |
342 delegate_->SetPopupOwner(NULL); | 294 delegate_->SetPopupOwner(NULL); |
343 pressed_lock_.reset(); // Unpress the menu button if it was pressed. | 295 pressed_lock_.reset(); // Unpress the menu button if it was pressed. |
344 } | 296 } |
OLD | NEW |