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

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

Issue 276010: Remove the implicit wrench menu items for browser actions. (Closed)
Patch Set: Rebase Created 11 years, 2 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
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"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 : MenuButton(this, L"", NULL, false), 126 : MenuButton(this, L"", NULL, false),
127 browser_action_(browser_action), 127 browser_action_(browser_action),
128 browser_action_state_(extension->browser_action_state()), 128 browser_action_state_(extension->browser_action_state()),
129 tracker_(NULL), 129 tracker_(NULL),
130 panel_(panel) { 130 panel_(panel) {
131 set_alignment(TextButton::ALIGN_CENTER); 131 set_alignment(TextButton::ALIGN_CENTER);
132 132
133 // Load the images this view needs asynchronously on the file thread. We'll 133 // Load the images this view needs asynchronously on the file thread. We'll
134 // get a call back into OnImageLoaded if the image loads successfully. If not, 134 // get a call back into OnImageLoaded if the image loads successfully. If not,
135 // the ImageView will have no image and will not appear in the browser chrome. 135 // the ImageView will have no image and will not appear in the browser chrome.
136 DCHECK(!browser_action->icon_paths().empty()); 136 if (!browser_action->icon_paths().empty()) {
137 const std::vector<std::string>& icon_paths = browser_action->icon_paths(); 137 const std::vector<std::string>& icon_paths = browser_action->icon_paths();
138 browser_action_icons_.resize(icon_paths.size()); 138 browser_action_icons_.resize(icon_paths.size());
139 tracker_ = new ImageLoadingTracker(this, icon_paths.size()); 139 tracker_ = new ImageLoadingTracker(this, icon_paths.size());
140 for (std::vector<std::string>::const_iterator iter = icon_paths.begin(); 140 for (std::vector<std::string>::const_iterator iter = icon_paths.begin();
141 iter != icon_paths.end(); ++iter) { 141 iter != icon_paths.end(); ++iter) {
142 tracker_->PostLoadImageTask(extension->GetResource(*iter)); 142 tracker_->PostLoadImageTask(extension->GetResource(*iter));
143 }
143 } 144 }
144 145
145 registrar_.Add(this, NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, 146 registrar_.Add(this, NotificationType::EXTENSION_BROWSER_ACTION_UPDATED,
146 Source<ExtensionAction>(browser_action_)); 147 Source<ExtensionAction>(browser_action_));
147 } 148 }
148 149
149 BrowserActionButton::~BrowserActionButton() { 150 BrowserActionButton::~BrowserActionButton() {
150 if (tracker_) { 151 if (tracker_) {
151 tracker_->StopTrackingImageLoad(); 152 tracker_->StopTrackingImageLoad();
152 tracker_ = NULL; // The tracker object will be deleted when we return. 153 tracker_ = NULL; // The tracker object will be deleted when we return.
(...skipping 14 matching lines...) Expand all
167 DCHECK(index < browser_action_icons_.size()); 168 DCHECK(index < browser_action_icons_.size());
168 browser_action_icons_[index] = image ? *image : SkBitmap(); 169 browser_action_icons_[index] = image ? *image : SkBitmap();
169 if (index == browser_action_icons_.size() - 1) { 170 if (index == browser_action_icons_.size() - 1) {
170 OnStateUpdated(); 171 OnStateUpdated();
171 tracker_ = NULL; // The tracker object will delete itself when we return. 172 tracker_ = NULL; // The tracker object will delete itself when we return.
172 } 173 }
173 } 174 }
174 175
175 void BrowserActionButton::OnStateUpdated() { 176 void BrowserActionButton::OnStateUpdated() {
176 SkBitmap* image = browser_action_state_->icon(); 177 SkBitmap* image = browser_action_state_->icon();
177 if (!image) 178 if (!image) {
178 image = &browser_action_icons_[browser_action_state_->icon_index()]; 179 if (static_cast<size_t>(browser_action_state_->icon_index()) <
179 SetIcon(*image); 180 browser_action_icons_.size()) {
181 image = &browser_action_icons_[browser_action_state_->icon_index()];
182 }
183 }
184
185 if (image)
186 SetIcon(*image);
187
180 SetTooltipText(ASCIIToWide(browser_action_state_->title())); 188 SetTooltipText(ASCIIToWide(browser_action_state_->title()));
181 panel_->OnBrowserActionVisibilityChanged(); 189 panel_->OnBrowserActionVisibilityChanged();
182 GetParent()->SchedulePaint(); 190 GetParent()->SchedulePaint();
183 } 191 }
184 192
185 void BrowserActionButton::Observe(NotificationType type, 193 void BrowserActionButton::Observe(NotificationType type,
186 const NotificationSource& source, 194 const NotificationSource& source,
187 const NotificationDetails& details) { 195 const NotificationDetails& details) {
188 if (type == NotificationType::EXTENSION_BROWSER_ACTION_UPDATED) { 196 if (type == NotificationType::EXTENSION_BROWSER_ACTION_UPDATED) {
189 OnStateUpdated(); 197 OnStateUpdated();
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
407 // Get all browser actions, including those with popups. 415 // Get all browser actions, including those with popups.
408 std::vector<ExtensionAction*> browser_actions; 416 std::vector<ExtensionAction*> browser_actions;
409 browser_actions = extension_service->GetBrowserActions(true); 417 browser_actions = extension_service->GetBrowserActions(true);
410 418
411 DeleteBrowserActionViews(); 419 DeleteBrowserActionViews();
412 for (size_t i = 0; i < browser_actions.size(); ++i) { 420 for (size_t i = 0; i < browser_actions.size(); ++i) {
413 Extension* extension = extension_service->GetExtensionById( 421 Extension* extension = extension_service->GetExtensionById(
414 browser_actions[i]->extension_id()); 422 browser_actions[i]->extension_id());
415 DCHECK(extension); 423 DCHECK(extension);
416 424
417 // Only show browser actions that have an icon. 425 BrowserActionView* view =
418 if (browser_actions[i]->icon_paths().size() > 0) { 426 new BrowserActionView(browser_actions[i], extension, this);
419 BrowserActionView* view = 427 browser_action_views_.push_back(view);
420 new BrowserActionView(browser_actions[i], extension, this); 428 AddChildView(view);
421 browser_action_views_.push_back(view);
422 AddChildView(view);
423 }
424 } 429 }
425 } 430 }
426 431
427 void BrowserActionsContainer::DeleteBrowserActionViews() { 432 void BrowserActionsContainer::DeleteBrowserActionViews() {
428 if (!browser_action_views_.empty()) { 433 if (!browser_action_views_.empty()) {
429 for (size_t i = 0; i < browser_action_views_.size(); ++i) 434 for (size_t i = 0; i < browser_action_views_.size(); ++i)
430 RemoveChildView(browser_action_views_[i]); 435 RemoveChildView(browser_action_views_[i]);
431 STLDeleteContainerPointers(browser_action_views_.begin(), 436 STLDeleteContainerPointers(browser_action_views_.begin(),
432 browser_action_views_.end()); 437 browser_action_views_.end());
433 browser_action_views_.clear(); 438 browser_action_views_.clear();
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 std::min(static_cast<int>(browser_action_views_.size()), 556 std::min(static_cast<int>(browser_action_views_.size()),
552 kMinimumNumberOfVisibleBrowserActions) * kIconSize; 557 kMinimumNumberOfVisibleBrowserActions) * kIconSize;
553 558
554 // Even if available_width is <= 0, we still return at least the |min_width|. 559 // Even if available_width is <= 0, we still return at least the |min_width|.
555 if (available_width <= 0) 560 if (available_width <= 0)
556 return min_width; 561 return min_width;
557 562
558 return std::max(min_width, available_width - available_width % kIconSize + 563 return std::max(min_width, available_width - available_width % kIconSize +
559 kHorizontalPadding * 2); 564 kHorizontalPadding * 2);
560 } 565 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_browser_actions_api.cc ('k') | chrome/browser/views/toolbar_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698