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" |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
57 | 57 |
58 const ExtensionAction* action = button_->extension()->browser_action(); | 58 const ExtensionAction* action = button_->extension()->browser_action(); |
59 gfx::Size spacing(0, ToolbarView::kVertSpacing); | 59 gfx::Size spacing(0, ToolbarView::kVertSpacing); |
60 gfx::ImageSkia icon = *action->GetIcon(tab_id).ToImageSkia(); | 60 gfx::ImageSkia icon = *action->GetIcon(tab_id).ToImageSkia(); |
61 if (!button_->IsEnabled(tab_id)) | 61 if (!button_->IsEnabled(tab_id)) |
62 icon = gfx::ImageSkiaOperations::CreateTransparentImage(icon, .25); | 62 icon = gfx::ImageSkiaOperations::CreateTransparentImage(icon, .25); |
63 return action->GetIconWithBadge(icon, tab_id, spacing); | 63 return action->GetIconWithBadge(icon, tab_id, spacing); |
64 } | 64 } |
65 | 65 |
66 void BrowserActionView::Layout() { | 66 void BrowserActionView::Layout() { |
| 67 // |button_| is NULL if Layout() is invoked before we have a valid widget. |
| 68 if (!button_) |
| 69 return; |
| 70 |
67 // We can't rely on button_->GetPreferredSize() here because that's not set | 71 // We can't rely on button_->GetPreferredSize() here because that's not set |
68 // correctly until the first call to | 72 // correctly until the first call to |
69 // BrowserActionsContainer::RefreshBrowserActionViews(), whereas this can be | 73 // BrowserActionsContainer::RefreshBrowserActionViews(), whereas this can be |
70 // called before that when the initial bounds are set (and then not after, | 74 // called before that when the initial bounds are set (and then not after, |
71 // since the bounds don't change). So instead of setting the height from the | 75 // since the bounds don't change). So instead of setting the height from the |
72 // button's preferred size, we use IconHeight(), since that's how big the | 76 // button's preferred size, we use IconHeight(), since that's how big the |
73 // button should be regardless of what it's displaying. | 77 // button should be regardless of what it's displaying. |
74 gfx::Point offset = delegate_->GetViewContentOffset(); | 78 gfx::Point offset = delegate_->GetViewContentOffset(); |
75 button_->SetBounds(offset.x(), offset.y(), width() - offset.x(), | 79 button_->SetBounds(offset.x(), offset.y(), width() - offset.x(), |
76 BrowserActionsContainer::IconHeight()); | 80 BrowserActionsContainer::IconHeight()); |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 | 413 |
410 extensions::Command browser_action_command; | 414 extensions::Command browser_action_command; |
411 if (!only_if_active || !command_service->GetBrowserActionCommand( | 415 if (!only_if_active || !command_service->GetBrowserActionCommand( |
412 extension_->id(), | 416 extension_->id(), |
413 extensions::CommandService::ACTIVE_ONLY, | 417 extensions::CommandService::ACTIVE_ONLY, |
414 &browser_action_command, | 418 &browser_action_command, |
415 NULL)) { | 419 NULL)) { |
416 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); | 420 GetFocusManager()->UnregisterAccelerator(*keybinding_.get(), this); |
417 } | 421 } |
418 } | 422 } |
OLD | NEW |