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/browser_action_view.h" | 5 #include "chrome/browser/ui/views/browser_action_view.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "chrome/browser/extensions/api/commands/command_service.h" | 8 #include "chrome/browser/extensions/api/commands/command_service.h" |
9 #include "chrome/browser/extensions/api/commands/command_service_factory.h" | 9 #include "chrome/browser/extensions/api/commands/command_service_factory.h" |
10 #include "chrome/browser/extensions/extension_context_menu_model.h" | 10 #include "chrome/browser/extensions/extension_context_menu_model.h" |
11 #include "chrome/browser/ui/browser.h" | 11 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/views/browser_actions_container.h" | 12 #include "chrome/browser/ui/views/browser_actions_container.h" |
13 #include "chrome/browser/ui/views/browser_action_view.h" | |
13 #include "chrome/browser/ui/views/toolbar_view.h" | 14 #include "chrome/browser/ui/views/toolbar_view.h" |
14 #include "chrome/common/chrome_notification_types.h" | 15 #include "chrome/common/chrome_notification_types.h" |
15 #include "chrome/common/extensions/extension.h" | 16 #include "chrome/common/extensions/extension.h" |
16 #include "chrome/common/extensions/extension_manifest_constants.h" | 17 #include "chrome/common/extensions/extension_manifest_constants.h" |
17 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
18 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
19 #include "grit/theme_resources_standard.h" | 20 #include "grit/theme_resources_standard.h" |
20 #include "ui/base/accessibility/accessible_view_state.h" | 21 #include "ui/base/accessibility/accessible_view_state.h" |
21 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
22 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
23 #include "ui/gfx/canvas.h" | 24 #include "ui/gfx/canvas.h" |
24 #include "ui/views/controls/menu/menu_model_adapter.h" | 25 #include "ui/views/controls/menu/menu_model_adapter.h" |
25 #include "ui/views/controls/menu/menu_runner.h" | 26 #include "ui/views/controls/menu/menu_runner.h" |
26 | 27 |
27 using extensions::Extension; | 28 using extensions::Extension; |
28 | 29 |
29 //////////////////////////////////////////////////////////////////////////////// | 30 //////////////////////////////////////////////////////////////////////////////// |
30 // BrowserActionButton | 31 // BrowserActionButton |
31 | 32 |
32 BrowserActionButton::BrowserActionButton(const Extension* extension, | 33 BrowserActionButton::BrowserActionButton(const Extension* extension, |
33 BrowserActionsContainer* panel) | 34 BrowserActionView::Delegate* delegate) |
34 : ALLOW_THIS_IN_INITIALIZER_LIST( | 35 : ALLOW_THIS_IN_INITIALIZER_LIST( |
35 MenuButton(this, string16(), NULL, false)), | 36 MenuButton(this, string16(), NULL, false)), |
36 browser_action_(extension->browser_action()), | 37 browser_action_(extension->browser_action()), |
37 extension_(extension), | 38 extension_(extension), |
38 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), | 39 ALLOW_THIS_IN_INITIALIZER_LIST(tracker_(this)), |
39 panel_(panel), | 40 delegate_(delegate), |
40 context_menu_(NULL) { | 41 context_menu_(NULL), |
42 disable_tooltip_(false) { | |
41 set_border(NULL); | 43 set_border(NULL); |
42 set_alignment(TextButton::ALIGN_CENTER); | 44 set_alignment(TextButton::ALIGN_CENTER); |
43 | 45 |
44 // No UpdateState() here because View hierarchy not setup yet. Our parent | 46 // No UpdateState() here because View hierarchy not setup yet. Our parent |
45 // should call UpdateState() after creation. | 47 // should call UpdateState() after creation. |
46 | 48 |
47 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, | 49 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED, |
48 content::Source<ExtensionAction>(browser_action_)); | 50 content::Source<ExtensionAction>(browser_action_)); |
49 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED, | 51 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED, |
50 content::Source<Profile>( | 52 content::Source<Profile>( |
51 panel_->profile()->GetOriginalProfile())); | 53 delegate_->GetBrowser()->profile()->GetOriginalProfile())); |
52 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED, | 54 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED, |
53 content::Source<Profile>( | 55 content::Source<Profile>( |
54 panel_->profile()->GetOriginalProfile())); | 56 delegate_->GetBrowser()->profile()->GetOriginalProfile())); |
55 } | 57 } |
56 | 58 |
57 void BrowserActionButton::Destroy() { | 59 void BrowserActionButton::Destroy() { |
58 MaybeUnregisterExtensionCommand(false); | 60 MaybeUnregisterExtensionCommand(false); |
59 | 61 |
60 if (context_menu_) { | 62 if (context_menu_) { |
61 context_menu_->Cancel(); | 63 context_menu_->Cancel(); |
62 MessageLoop::current()->DeleteSoon(FROM_HERE, this); | 64 MessageLoop::current()->DeleteSoon(FROM_HERE, this); |
63 } else { | 65 } else { |
64 delete this; | 66 delete this; |
(...skipping 30 matching lines...) Expand all Loading... | |
95 | 97 |
96 bool BrowserActionButton::CanHandleAccelerators() const { | 98 bool BrowserActionButton::CanHandleAccelerators() const { |
97 // View::CanHandleAccelerators() checks to see if the view is visible before | 99 // View::CanHandleAccelerators() checks to see if the view is visible before |
98 // allowing it to process accelerators. This is not appropriate for browser | 100 // allowing it to process accelerators. This is not appropriate for browser |
99 // actions buttons, which can be hidden inside the overflow area. | 101 // actions buttons, which can be hidden inside the overflow area. |
100 return true; | 102 return true; |
101 } | 103 } |
102 | 104 |
103 void BrowserActionButton::ButtonPressed(views::Button* sender, | 105 void BrowserActionButton::ButtonPressed(views::Button* sender, |
104 const views::Event& event) { | 106 const views::Event& event) { |
105 panel_->OnBrowserActionExecuted(this); | 107 delegate_->OnBrowserActionExecuted(this); |
106 } | 108 } |
107 | 109 |
108 void BrowserActionButton::OnImageLoaded(const gfx::Image& image, | 110 void BrowserActionButton::OnImageLoaded(const gfx::Image& image, |
109 const std::string& extension_id, | 111 const std::string& extension_id, |
110 int index) { | 112 int index) { |
111 if (!image.IsEmpty()) | 113 if (!image.IsEmpty()) |
112 default_icon_ = *image.ToSkBitmap(); | 114 default_icon_ = *image.ToSkBitmap(); |
113 | 115 |
114 // Call back to UpdateState() because a more specific icon might have been set | 116 // Call back to UpdateState() because a more specific icon might have been set |
115 // while the load was outstanding. | 117 // while the load was outstanding. |
116 UpdateState(); | 118 UpdateState(); |
117 } | 119 } |
118 | 120 |
119 void BrowserActionButton::UpdateState() { | 121 void BrowserActionButton::UpdateState() { |
120 int tab_id = panel_->GetCurrentTabId(); | 122 int tab_id = delegate_->GetCurrentTabId(); |
121 if (tab_id < 0) | 123 if (tab_id < 0) |
122 return; | 124 return; |
123 | 125 |
124 SkBitmap icon(browser_action()->GetIcon(tab_id)); | 126 SkBitmap icon(browser_action()->GetIcon(tab_id)); |
125 if (icon.isNull()) | 127 if (icon.isNull()) |
126 icon = default_icon_; | 128 icon = default_icon_; |
127 if (!icon.isNull()) { | 129 if (!icon.isNull()) { |
128 SkPaint paint; | 130 SkPaint paint; |
129 paint.setXfermode(SkXfermode::Create(SkXfermode::kSrcOver_Mode)); | 131 paint.setXfermode(SkXfermode::Create(SkXfermode::kSrcOver_Mode)); |
130 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 132 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
(...skipping 22 matching lines...) Expand all Loading... | |
153 bg_p_canvas.drawBitmap(icon, | 155 bg_p_canvas.drawBitmap(icon, |
154 SkIntToScalar((bg_p.width() - icon.width()) / 2), | 156 SkIntToScalar((bg_p.width() - icon.width()) / 2), |
155 SkIntToScalar((bg_p.height() - icon.height()) / 2), &paint); | 157 SkIntToScalar((bg_p.height() - icon.height()) / 2), &paint); |
156 SetPushedIcon(bg_p); | 158 SetPushedIcon(bg_p); |
157 } | 159 } |
158 | 160 |
159 // If the browser action name is empty, show the extension name instead. | 161 // If the browser action name is empty, show the extension name instead. |
160 string16 name = UTF8ToUTF16(browser_action()->GetTitle(tab_id)); | 162 string16 name = UTF8ToUTF16(browser_action()->GetTitle(tab_id)); |
161 if (name.empty()) | 163 if (name.empty()) |
162 name = UTF8ToUTF16(extension()->name()); | 164 name = UTF8ToUTF16(extension()->name()); |
165 if (!disable_tooltip_) | |
163 SetTooltipText(name); | 166 SetTooltipText(name); |
Aaron Boodman
2012/07/02 22:41:34
!?
yefimt
2012/07/11 22:34:34
Done.
| |
164 SetAccessibleName(name); | 167 SetAccessibleName(name); |
165 parent()->SchedulePaint(); | 168 parent()->SchedulePaint(); |
166 } | 169 } |
167 | 170 |
168 bool BrowserActionButton::IsPopup() { | 171 bool BrowserActionButton::IsPopup() { |
169 int tab_id = panel_->GetCurrentTabId(); | 172 int tab_id = delegate_->GetCurrentTabId(); |
170 return (tab_id < 0) ? false : browser_action_->HasPopup(tab_id); | 173 return (tab_id < 0) ? false : browser_action_->HasPopup(tab_id); |
171 } | 174 } |
172 | 175 |
173 GURL BrowserActionButton::GetPopupUrl() { | 176 GURL BrowserActionButton::GetPopupUrl() { |
174 int tab_id = panel_->GetCurrentTabId(); | 177 int tab_id = delegate_->GetCurrentTabId(); |
175 return (tab_id < 0) ? GURL() : browser_action_->GetPopupUrl(tab_id); | 178 return (tab_id < 0) ? GURL() : browser_action_->GetPopupUrl(tab_id); |
176 } | 179 } |
177 | 180 |
178 void BrowserActionButton::Observe(int type, | 181 void BrowserActionButton::Observe(int type, |
179 const content::NotificationSource& source, | 182 const content::NotificationSource& source, |
180 const content::NotificationDetails& details) { | 183 const content::NotificationDetails& details) { |
181 switch (type) { | 184 switch (type) { |
182 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED: | 185 case chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED: |
183 UpdateState(); | 186 UpdateState(); |
184 // The browser action may have become visible/hidden so we need to make | 187 // The browser action may have become visible/hidden so we need to make |
185 // sure the state gets updated. | 188 // sure the state gets updated. |
186 panel_->OnBrowserActionVisibilityChanged(); | 189 delegate_->OnBrowserActionVisibilityChanged(); |
187 break; | 190 break; |
188 case chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED: | 191 case chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED: |
189 case chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED: { | 192 case chrome::NOTIFICATION_EXTENSION_COMMAND_REMOVED: { |
190 std::pair<const std::string, const std::string>* payload = | 193 std::pair<const std::string, const std::string>* payload = |
191 content::Details<std::pair<const std::string, const std::string> >( | 194 content::Details<std::pair<const std::string, const std::string> >( |
192 details).ptr(); | 195 details).ptr(); |
193 if (extension_->id() == payload->first && | 196 if (extension_->id() == payload->first && |
194 payload->second == | 197 payload->second == |
195 extension_manifest_values::kBrowserActionKeybindingEvent) { | 198 extension_manifest_values::kBrowserActionKeybindingEvent) { |
196 if (type == chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED) | 199 if (type == chrome::NOTIFICATION_EXTENSION_COMMAND_ADDED) |
197 MaybeRegisterExtensionCommand(); | 200 MaybeRegisterExtensionCommand(); |
198 else | 201 else |
199 MaybeUnregisterExtensionCommand(true); | 202 MaybeUnregisterExtensionCommand(true); |
200 } | 203 } |
201 break; | 204 break; |
202 } | 205 } |
203 default: | 206 default: |
204 NOTREACHED(); | 207 NOTREACHED(); |
205 break; | 208 break; |
206 } | 209 } |
207 } | 210 } |
208 | 211 |
209 bool BrowserActionButton::Activate() { | 212 bool BrowserActionButton::Activate() { |
210 if (!IsPopup()) | 213 if (!IsPopup()) |
211 return true; | 214 return true; |
212 | 215 |
213 panel_->OnBrowserActionExecuted(this); | 216 delegate_->OnBrowserActionExecuted(this); |
214 | 217 |
215 // TODO(erikkay): Run a nested modal loop while the mouse is down to | 218 // TODO(erikkay): Run a nested modal loop while the mouse is down to |
216 // enable menu-like drag-select behavior. | 219 // enable menu-like drag-select behavior. |
217 | 220 |
218 // The return value of this method is returned via OnMousePressed. | 221 // The return value of this method is returned via OnMousePressed. |
219 // We need to return false here since we're handing off focus to another | 222 // We need to return false here since we're handing off focus to another |
220 // widget/view, and true will grab it right back and try to send events | 223 // widget/view, and true will grab it right back and try to send events |
221 // to us. | 224 // to us. |
222 return false; | 225 return false; |
223 } | 226 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 | 262 |
260 void BrowserActionButton::ShowContextMenu(const gfx::Point& p, | 263 void BrowserActionButton::ShowContextMenu(const gfx::Point& p, |
261 bool is_mouse_gesture) { | 264 bool is_mouse_gesture) { |
262 if (!extension()->ShowConfigureContextMenus()) | 265 if (!extension()->ShowConfigureContextMenus()) |
263 return; | 266 return; |
264 | 267 |
265 SetButtonPushed(); | 268 SetButtonPushed(); |
266 | 269 |
267 // Reconstructs the menu every time because the menu's contents are dynamic. | 270 // Reconstructs the menu every time because the menu's contents are dynamic. |
268 scoped_refptr<ExtensionContextMenuModel> context_menu_contents_( | 271 scoped_refptr<ExtensionContextMenuModel> context_menu_contents_( |
269 new ExtensionContextMenuModel(extension(), panel_->browser())); | 272 new ExtensionContextMenuModel(extension(), delegate_->GetBrowser())); |
270 views::MenuModelAdapter menu_model_adapter(context_menu_contents_.get()); | 273 views::MenuModelAdapter menu_model_adapter(context_menu_contents_.get()); |
271 views::MenuRunner menu_runner(menu_model_adapter.CreateMenu()); | 274 views::MenuRunner menu_runner(menu_model_adapter.CreateMenu()); |
272 | 275 |
273 context_menu_ = menu_runner.GetMenu(); | 276 context_menu_ = menu_runner.GetMenu(); |
274 gfx::Point screen_loc; | 277 gfx::Point screen_loc; |
275 views::View::ConvertPointToScreen(this, &screen_loc); | 278 views::View::ConvertPointToScreen(this, &screen_loc); |
276 if (menu_runner.RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), | 279 if (menu_runner.RunMenuAt(GetWidget(), NULL, gfx::Rect(screen_loc, size()), |
277 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == | 280 views::MenuItemView::TOPLEFT, views::MenuRunner::HAS_MNEMONICS) == |
278 views::MenuRunner::MENU_DELETED) | 281 views::MenuRunner::MENU_DELETED) |
279 return; | 282 return; |
280 | 283 |
281 SetButtonNotPushed(); | 284 SetButtonNotPushed(); |
282 context_menu_ = NULL; | 285 context_menu_ = NULL; |
283 } | 286 } |
284 | 287 |
285 bool BrowserActionButton::AcceleratorPressed( | 288 bool BrowserActionButton::AcceleratorPressed( |
286 const ui::Accelerator& accelerator) { | 289 const ui::Accelerator& accelerator) { |
287 panel_->OnBrowserActionExecuted(this); | 290 delegate_->OnBrowserActionExecuted(this); |
288 return true; | 291 return true; |
289 } | 292 } |
290 | 293 |
291 void BrowserActionButton::SetButtonPushed() { | 294 void BrowserActionButton::SetButtonPushed() { |
292 SetState(views::CustomButton::BS_PUSHED); | 295 SetState(views::CustomButton::BS_PUSHED); |
293 menu_visible_ = true; | 296 menu_visible_ = true; |
294 } | 297 } |
295 | 298 |
296 void BrowserActionButton::SetButtonNotPushed() { | 299 void BrowserActionButton::SetButtonNotPushed() { |
297 SetState(views::CustomButton::BS_NORMAL); | 300 SetState(views::CustomButton::BS_NORMAL); |
298 menu_visible_ = false; | 301 menu_visible_ = false; |
299 } | 302 } |
300 | 303 |
304 void BrowserActionButton::DisableTooltip(bool disable_tooltip) { | |
Aaron Boodman
2012/07/02 22:41:34
If this method is going to accept a value, it shou
yefimt
2012/07/11 22:34:34
Renamed to SetTooltipDisabled(...)
On 2012/07/02
| |
305 disable_tooltip_ = disable_tooltip; | |
306 if (disable_tooltip_) | |
307 SetTooltipText(string16()); | |
Aaron Boodman
2012/07/02 22:41:34
Don't you need to reset it to the string in the ca
yefimt
2012/07/11 22:34:34
Done.
| |
308 } | |
309 | |
301 BrowserActionButton::~BrowserActionButton() { | 310 BrowserActionButton::~BrowserActionButton() { |
302 } | 311 } |
303 | 312 |
304 void BrowserActionButton::MaybeRegisterExtensionCommand() { | 313 void BrowserActionButton::MaybeRegisterExtensionCommand() { |
305 extensions::CommandService* command_service = | 314 extensions::CommandService* command_service = |
306 extensions::CommandServiceFactory::GetForProfile( | 315 extensions::CommandServiceFactory::GetForProfile( |
307 panel_->browser()->profile()); | 316 delegate_->GetBrowser()->profile()); |
308 extensions::Command browser_action_command; | 317 extensions::Command browser_action_command; |
309 if (command_service->GetBrowserActionCommand( | 318 if (command_service->GetBrowserActionCommand( |
310 extension_->id(), | 319 extension_->id(), |
311 extensions::CommandService::ACTIVE_ONLY, | 320 extensions::CommandService::ACTIVE_ONLY, |
312 &browser_action_command, | 321 &browser_action_command, |
313 NULL)) { | 322 NULL)) { |
314 keybinding_.reset(new ui::Accelerator( | 323 keybinding_.reset(new ui::Accelerator( |
315 browser_action_command.accelerator())); | 324 browser_action_command.accelerator())); |
316 panel_->GetFocusManager()->RegisterAccelerator( | 325 GetFocusManager()->RegisterAccelerator( |
317 *keybinding_.get(), ui::AcceleratorManager::kHighPriority, this); | 326 *keybinding_.get(), ui::AcceleratorManager::kHighPriority, this); |
318 } | 327 } |
319 } | 328 } |
320 | 329 |
321 void BrowserActionButton::MaybeUnregisterExtensionCommand(bool only_if_active) { | 330 void BrowserActionButton::MaybeUnregisterExtensionCommand(bool only_if_active) { |
322 if (!keybinding_.get() || !panel_->GetFocusManager()) | 331 if (!keybinding_.get() || !GetFocusManager()) |
323 return; | 332 return; |
324 | 333 |
325 extensions::CommandService* command_service = | 334 extensions::CommandService* command_service = |
326 extensions::CommandServiceFactory::GetForProfile( | 335 extensions::CommandServiceFactory::GetForProfile( |
327 panel_->browser()->profile()); | 336 delegate_->GetBrowser()->profile()); |
328 | 337 |
329 extensions::Command browser_action_command; | 338 extensions::Command browser_action_command; |
330 if (!only_if_active || !command_service->GetBrowserActionCommand( | 339 if (!only_if_active || !command_service->GetBrowserActionCommand( |
331 extension_->id(), | 340 extension_->id(), |
332 extensions::CommandService::ACTIVE_ONLY, | 341 extensions::CommandService::ACTIVE_ONLY, |
333 &browser_action_command, | 342 &browser_action_command, |
334 NULL)) { | 343 NULL)) { |
335 panel_->GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); | 344 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); |
336 } | 345 } |
337 } | 346 } |
338 | 347 |
339 | 348 |
340 //////////////////////////////////////////////////////////////////////////////// | 349 //////////////////////////////////////////////////////////////////////////////// |
341 // BrowserActionView | 350 // BrowserActionView |
342 | 351 |
343 BrowserActionView::BrowserActionView(const Extension* extension, | 352 BrowserActionView::BrowserActionView(const Extension* extension, |
344 BrowserActionsContainer* panel) | 353 BrowserActionView::Delegate* delegate) |
345 : panel_(panel) { | 354 : delegate_(delegate) { |
346 button_ = new BrowserActionButton(extension, panel); | 355 button_ = new BrowserActionButton(extension, delegate_); |
347 button_->set_drag_controller(panel_); | 356 button_->set_drag_controller(delegate_); |
348 AddChildView(button_); | 357 AddChildView(button_); |
349 button_->UpdateState(); | 358 button_->UpdateState(); |
350 } | 359 } |
351 | 360 |
352 BrowserActionView::~BrowserActionView() { | 361 BrowserActionView::~BrowserActionView() { |
353 RemoveChildView(button_); | 362 RemoveChildView(button_); |
354 button_->Destroy(); | 363 button_->Destroy(); |
355 } | 364 } |
356 | 365 |
357 gfx::Canvas* BrowserActionView::GetIconWithBadge() { | 366 gfx::Canvas* BrowserActionView::GetIconWithBadge() { |
358 int tab_id = panel_->GetCurrentTabId(); | 367 int tab_id = delegate_->GetCurrentTabId(); |
359 | 368 |
360 SkBitmap icon = button_->extension()->browser_action()->GetIcon(tab_id); | 369 SkBitmap icon = button_->extension()->browser_action()->GetIcon(tab_id); |
361 if (icon.isNull()) | 370 if (icon.isNull()) |
362 icon = button_->default_icon(); | 371 icon = button_->default_icon(); |
363 | 372 |
364 gfx::Canvas* canvas = new gfx::Canvas(icon, false); | 373 gfx::Canvas* canvas = new gfx::Canvas(icon, false); |
365 | 374 |
366 if (tab_id >= 0) { | 375 if (tab_id >= 0) { |
367 gfx::Rect bounds(icon.width(), icon.height() + ToolbarView::kVertSpacing); | 376 gfx::Rect bounds(icon.width(), icon.height() + ToolbarView::kVertSpacing); |
368 button_->extension()->browser_action()->PaintBadge(canvas, bounds, tab_id); | 377 button_->extension()->browser_action()->PaintBadge(canvas, bounds, tab_id); |
369 } | 378 } |
370 | 379 |
371 return canvas; | 380 return canvas; |
372 } | 381 } |
373 | 382 |
374 void BrowserActionView::Layout() { | 383 void BrowserActionView::Layout() { |
375 // We can't rely on button_->GetPreferredSize() here because that's not set | 384 // We can't rely on button_->GetPreferredSize() here because that's not set |
376 // correctly until the first call to | 385 // correctly until the first call to |
377 // BrowserActionsContainer::RefreshBrowserActionViews(), whereas this can be | 386 // BrowserActionsContainer::RefreshBrowserActionViews(), whereas this can be |
378 // called before that when the initial bounds are set (and then not after, | 387 // called before that when the initial bounds are set (and then not after, |
379 // since the bounds don't change). So instead of setting the height from the | 388 // since the bounds don't change). So instead of setting the height from the |
380 // button's preferred size, we use IconHeight(), since that's how big the | 389 // button's preferred size, we use IconHeight(), since that's how big the |
381 // button should be regardless of what it's displaying. | 390 // button should be regardless of what it's displaying. |
382 button_->SetBounds(0, ToolbarView::kVertSpacing, width(), | 391 gfx::Size size = delegate_->GetViewContentOffset(); |
Aaron Boodman
2012/07/02 22:41:34
offset?
yefimt
2012/07/11 22:34:34
I know it is coming back over and over:)
Button in
| |
392 button_->SetBounds(size.width(), size.height(), width(), | |
383 BrowserActionsContainer::IconHeight()); | 393 BrowserActionsContainer::IconHeight()); |
384 } | 394 } |
385 | 395 |
386 void BrowserActionView::GetAccessibleState(ui::AccessibleViewState* state) { | 396 void BrowserActionView::GetAccessibleState(ui::AccessibleViewState* state) { |
387 state->name = l10n_util::GetStringUTF16( | 397 state->name = l10n_util::GetStringUTF16( |
388 IDS_ACCNAME_EXTENSIONS_BROWSER_ACTION); | 398 IDS_ACCNAME_EXTENSIONS_BROWSER_ACTION); |
389 state->role = ui::AccessibilityTypes::ROLE_GROUPING; | 399 state->role = ui::AccessibilityTypes::ROLE_GROUPING; |
390 } | 400 } |
391 | 401 |
402 gfx::Size BrowserActionView::GetPreferredSize() { | |
403 return gfx::Size(Extension::kBrowserActionIconMaxSize+10, // FIXME | |
Aaron Boodman
2012/07/02 22:41:34
Fix before checking in.
yefimt
2012/07/11 22:34:34
Done.
| |
404 Extension::kBrowserActionIconMaxSize+10); | |
405 } | |
406 | |
392 void BrowserActionView::PaintChildren(gfx::Canvas* canvas) { | 407 void BrowserActionView::PaintChildren(gfx::Canvas* canvas) { |
393 View::PaintChildren(canvas); | 408 View::PaintChildren(canvas); |
394 ExtensionAction* action = button()->browser_action(); | 409 ExtensionAction* action = button()->browser_action(); |
395 int tab_id = panel_->GetCurrentTabId(); | 410 int tab_id = delegate_->GetCurrentTabId(); |
396 if (tab_id >= 0) | 411 if (tab_id >= 0) |
397 action->PaintBadge(canvas, gfx::Rect(width(), height()), tab_id); | 412 action->PaintBadge(canvas, gfx::Rect(width(), height()), tab_id); |
398 } | 413 } |
OLD | NEW |