Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(271)

Side by Side Diff: chrome/browser/ui/views/browser_action_view.cc

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

Powered by Google App Engine
This is Rietveld 408576698