OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/views/browser_actions_container.h" | 5 #include "chrome/browser/views/browser_actions_container.h" |
6 | 6 |
7 #include "app/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 return zero_inset; | 158 return zero_inset; |
159 } | 159 } |
160 | 160 |
161 void BrowserActionButton::ButtonPressed( | 161 void BrowserActionButton::ButtonPressed( |
162 views::Button* sender, const views::Event& event) { | 162 views::Button* sender, const views::Event& event) { |
163 panel_->OnBrowserActionExecuted(this); | 163 panel_->OnBrowserActionExecuted(this); |
164 } | 164 } |
165 | 165 |
166 void BrowserActionButton::OnImageLoaded(SkBitmap* image, size_t index) { | 166 void BrowserActionButton::OnImageLoaded(SkBitmap* image, size_t index) { |
167 DCHECK(index < browser_action_icons_.size()); | 167 DCHECK(index < browser_action_icons_.size()); |
168 browser_action_icons_[index] = *image; | 168 browser_action_icons_[index] = image ? *image : SkBitmap(); |
169 if (index == browser_action_icons_.size() - 1) { | 169 if (index == browser_action_icons_.size() - 1) { |
170 OnStateUpdated(); | 170 OnStateUpdated(); |
171 tracker_ = NULL; // The tracker object will delete itself when we return. | 171 tracker_ = NULL; // The tracker object will delete itself when we return. |
172 } | 172 } |
173 } | 173 } |
174 | 174 |
175 void BrowserActionButton::OnStateUpdated() { | 175 void BrowserActionButton::OnStateUpdated() { |
176 SkBitmap* image = browser_action_state_->icon(); | 176 SkBitmap* image = browser_action_state_->icon(); |
177 if (!image) | 177 if (!image) |
178 image = &browser_action_icons_[browser_action_state_->icon_index()]; | 178 image = &browser_action_icons_[browser_action_state_->icon_index()]; |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
475 toolbar_->browser(), | 475 toolbar_->browser(), |
476 rect, | 476 rect, |
477 browser_action.popup_height()); | 477 browser_action.popup_height()); |
478 popup_->set_delegate(this); | 478 popup_->set_delegate(this); |
479 popup_button_ = button; | 479 popup_button_ = button; |
480 popup_button_->PopupDidShow(); | 480 popup_button_->PopupDidShow(); |
481 return; | 481 return; |
482 } | 482 } |
483 | 483 |
484 // Otherwise, we send the action to the extension. | 484 // Otherwise, we send the action to the extension. |
485 int window_id = ExtensionTabUtil::GetWindowId(toolbar_->browser()); | |
486 ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted( | 485 ExtensionBrowserEventRouter::GetInstance()->BrowserActionExecuted( |
487 profile_, browser_action.extension_id(), window_id); | 486 profile_, browser_action.extension_id(), toolbar_->browser()); |
488 } | 487 } |
489 | 488 |
490 gfx::Size BrowserActionsContainer::GetPreferredSize() { | 489 gfx::Size BrowserActionsContainer::GetPreferredSize() { |
491 if (browser_action_views_.empty()) | 490 if (browser_action_views_.empty()) |
492 return gfx::Size(0, 0); | 491 return gfx::Size(0, 0); |
493 int width = kHorizontalPadding * 2 + | 492 int width = kHorizontalPadding * 2 + |
494 browser_action_views_.size() * kIconSize; | 493 browser_action_views_.size() * kIconSize; |
495 return gfx::Size(width, kIconSize); | 494 return gfx::Size(width, kIconSize); |
496 } | 495 } |
497 | 496 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 std::min(static_cast<int>(browser_action_views_.size()), | 551 std::min(static_cast<int>(browser_action_views_.size()), |
553 kMinimumNumberOfVisibleBrowserActions) * kIconSize; | 552 kMinimumNumberOfVisibleBrowserActions) * kIconSize; |
554 | 553 |
555 // Even if available_width is <= 0, we still return at least the |min_width|. | 554 // Even if available_width is <= 0, we still return at least the |min_width|. |
556 if (available_width <= 0) | 555 if (available_width <= 0) |
557 return min_width; | 556 return min_width; |
558 | 557 |
559 return std::max(min_width, available_width - available_width % kIconSize + | 558 return std::max(min_width, available_width - available_width % kIconSize + |
560 kHorizontalPadding * 2); | 559 kHorizontalPadding * 2); |
561 } | 560 } |
OLD | NEW |