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

Side by Side Diff: chrome/browser/views/browser_actions_container.cc

Issue 332021: Move page actions over to ExtensionAction2 (Closed)
Patch Set: Review feedback Created 11 years, 1 month 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
OLDNEW
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"
11 #include "chrome/browser/extensions/extension_browser_event_router.h" 11 #include "chrome/browser/extensions/extension_browser_event_router.h"
12 #include "chrome/browser/extensions/extensions_service.h" 12 #include "chrome/browser/extensions/extensions_service.h"
13 #include "chrome/browser/extensions/extension_tabs_module.h" 13 #include "chrome/browser/extensions/extension_tabs_module.h"
14 #include "chrome/browser/profile.h" 14 #include "chrome/browser/profile.h"
15 #include "chrome/browser/view_ids.h" 15 #include "chrome/browser/view_ids.h"
16 #include "chrome/browser/views/extensions/extension_popup.h" 16 #include "chrome/browser/views/extensions/extension_popup.h"
17 #include "chrome/browser/views/toolbar_view.h" 17 #include "chrome/browser/views/toolbar_view.h"
18 #include "chrome/common/extensions/extension_action.h"
19 #include "chrome/common/extensions/extension_action2.h"
20 #include "chrome/common/notification_source.h" 18 #include "chrome/common/notification_source.h"
21 #include "chrome/common/notification_type.h" 19 #include "chrome/common/notification_type.h"
22 #include "grit/app_resources.h" 20 #include "grit/app_resources.h"
23 #include "third_party/skia/include/core/SkBitmap.h" 21 #include "third_party/skia/include/core/SkBitmap.h"
24 #include "third_party/skia/include/core/SkTypeface.h" 22 #include "third_party/skia/include/core/SkTypeface.h"
25 #include "third_party/skia/include/effects/SkGradientShader.h" 23 #include "third_party/skia/include/effects/SkGradientShader.h"
26 #include "views/controls/button/text_button.h" 24 #include "views/controls/button/text_button.h"
27 25
28 // The size (both dimensions) of the buttons for page actions. 26 // The size (both dimensions) of the buttons for page actions.
29 static const int kButtonSize = 29; 27 static const int kButtonSize = 29;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 77
80 void BrowserActionButton::ButtonPressed( 78 void BrowserActionButton::ButtonPressed(
81 views::Button* sender, const views::Event& event) { 79 views::Button* sender, const views::Event& event) {
82 panel_->OnBrowserActionExecuted(this); 80 panel_->OnBrowserActionExecuted(this);
83 } 81 }
84 82
85 void BrowserActionButton::LoadImage() { 83 void BrowserActionButton::LoadImage() {
86 // Load the default image from the browser action asynchronously on the file 84 // Load the default image from the browser action asynchronously on the file
87 // thread. We'll get a call back into OnImageLoaded if the image loads 85 // thread. We'll get a call back into OnImageLoaded if the image loads
88 // successfully. 86 // successfully.
89 std::string relative_path = browser_action()->GetDefaultIconPath(); 87 std::string relative_path = browser_action()->default_icon_path();
90 if (relative_path.empty()) 88 if (relative_path.empty())
91 return; 89 return;
92 90
93 tracker_ = new ImageLoadingTracker(this, 1); 91 tracker_ = new ImageLoadingTracker(this, 1);
94 tracker_->PostLoadImageTask( 92 tracker_->PostLoadImageTask(
95 extension()->GetResource(relative_path), 93 extension()->GetResource(relative_path),
96 gfx::Size(Extension::kBrowserActionIconMaxSize, 94 gfx::Size(Extension::kBrowserActionIconMaxSize,
97 Extension::kBrowserActionIconMaxSize)); 95 Extension::kBrowserActionIconMaxSize));
98 } 96 }
99 97
100 void BrowserActionButton::OnImageLoaded(SkBitmap* image, size_t index) { 98 void BrowserActionButton::OnImageLoaded(SkBitmap* image, size_t index) {
101 SetIcon(*image); 99 if (image)
100 SetIcon(*image);
102 tracker_ = NULL; // The tracker object will delete itself when we return. 101 tracker_ = NULL; // The tracker object will delete itself when we return.
103 GetParent()->SchedulePaint(); 102 GetParent()->SchedulePaint();
104 } 103 }
105 104
106 void BrowserActionButton::UpdateState() { 105 void BrowserActionButton::UpdateState() {
107 int tab_id = panel_->GetCurrentTabId(); 106 int tab_id = panel_->GetCurrentTabId();
108 if (tab_id < 0) 107 if (tab_id < 0)
109 return; 108 return;
110 109
111 SkBitmap image = browser_action()->GetIcon(tab_id); 110 SkBitmap image = browser_action()->GetIcon(tab_id);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 button_->SetBounds(0, kControlVertOffset, width(), kButtonSize); 203 button_->SetBounds(0, kControlVertOffset, width(), kButtonSize);
205 } 204 }
206 205
207 void BrowserActionView::PaintChildren(gfx::Canvas* canvas) { 206 void BrowserActionView::PaintChildren(gfx::Canvas* canvas) {
208 View::PaintChildren(canvas); 207 View::PaintChildren(canvas);
209 ExtensionAction2* action = button()->browser_action(); 208 ExtensionAction2* action = button()->browser_action();
210 int tab_id = panel_->GetCurrentTabId(); 209 int tab_id = panel_->GetCurrentTabId();
211 if (tab_id < 0) 210 if (tab_id < 0)
212 return; 211 return;
213 212
214 ExtensionActionState::PaintBadge( 213 action->PaintBadge(canvas, gfx::Rect(width(), height()), tab_id);
215 canvas, gfx::Rect(width(), height()),
216 action->GetBadgeText(tab_id),
217 action->GetBadgeTextColor(tab_id),
218 action->GetBadgeBackgroundColor(tab_id));
219 } 214 }
220 215
221 216
222 //////////////////////////////////////////////////////////////////////////////// 217 ////////////////////////////////////////////////////////////////////////////////
223 // BrowserActionsContainer 218 // BrowserActionsContainer
224 219
225 BrowserActionsContainer::BrowserActionsContainer( 220 BrowserActionsContainer::BrowserActionsContainer(
226 Profile* profile, ToolbarView* toolbar) 221 Profile* profile, ToolbarView* toolbar)
227 : profile_(profile), 222 : profile_(profile),
228 toolbar_(toolbar), 223 toolbar_(toolbar),
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 std::min(static_cast<int>(browser_action_views_.size()), 452 std::min(static_cast<int>(browser_action_views_.size()),
458 kMinimumNumberOfVisibleBrowserActions) * kButtonSize; 453 kMinimumNumberOfVisibleBrowserActions) * kButtonSize;
459 454
460 // Even if available_width is <= 0, we still return at least the |min_width|. 455 // Even if available_width is <= 0, we still return at least the |min_width|.
461 if (available_width <= 0) 456 if (available_width <= 0)
462 return min_width; 457 return min_width;
463 458
464 return std::max(min_width, available_width - available_width % kButtonSize + 459 return std::max(min_width, available_width - available_width % kButtonSize +
465 kHorizontalPadding * 2); 460 kHorizontalPadding * 2);
466 } 461 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698