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

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

Issue 675893002: Revert of Rename BrowserActionView to ToolbarActionView (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/toolbar/browser_actions_container.h" 5 #include "chrome/browser/ui/views/toolbar/browser_actions_container.h"
6 6
7 #include "base/compiler_specific.h" 7 #include "base/compiler_specific.h"
8 #include "base/stl_util.h" 8 #include "base/stl_util.h"
9 #include "chrome/browser/extensions/extension_action_manager.h" 9 #include "chrome/browser/extensions/extension_action_manager.h"
10 #include "chrome/browser/extensions/tab_helper.h" 10 #include "chrome/browser/extensions/tab_helper.h"
11 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_window.h" 13 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/tabs/tab_strip_model.h" 14 #include "chrome/browser/ui/tabs/tab_strip_model.h"
15 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h" 15 #include "chrome/browser/ui/toolbar/component_toolbar_actions_factory.h"
16 #include "chrome/browser/ui/view_ids.h" 16 #include "chrome/browser/ui/view_ids.h"
17 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" 17 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h"
18 #include "chrome/browser/ui/views/extensions/extension_action_view_controller.h" 18 #include "chrome/browser/ui/views/extensions/extension_action_view_controller.h"
19 #include "chrome/browser/ui/views/extensions/extension_popup.h" 19 #include "chrome/browser/ui/views/extensions/extension_popup.h"
20 #include "chrome/browser/ui/views/frame/browser_view.h" 20 #include "chrome/browser/ui/views/frame/browser_view.h"
21 #include "chrome/browser/ui/views/toolbar/browser_actions_container_observer.h" 21 #include "chrome/browser/ui/views/toolbar/browser_actions_container_observer.h"
22 #include "chrome/browser/ui/views/toolbar/toolbar_view.h" 22 #include "chrome/browser/ui/views/toolbar/toolbar_view.h"
23 #include "chrome/common/extensions/command.h" 23 #include "chrome/common/extensions/command.h"
24 #include "chrome/grit/generated_resources.h" 24 #include "chrome/grit/generated_resources.h"
25 #include "components/crx_file/id_util.h"
26 #include "extensions/browser/extension_system.h" 25 #include "extensions/browser/extension_system.h"
27 #include "extensions/browser/runtime_data.h" 26 #include "extensions/browser/runtime_data.h"
28 #include "extensions/common/feature_switch.h" 27 #include "extensions/common/feature_switch.h"
29 #include "grit/theme_resources.h" 28 #include "grit/theme_resources.h"
30 #include "third_party/skia/include/core/SkColor.h" 29 #include "third_party/skia/include/core/SkColor.h"
31 #include "ui/accessibility/ax_view_state.h" 30 #include "ui/accessibility/ax_view_state.h"
32 #include "ui/base/dragdrop/drag_utils.h" 31 #include "ui/base/dragdrop/drag_utils.h"
33 #include "ui/base/l10n/l10n_util.h" 32 #include "ui/base/l10n/l10n_util.h"
34 #include "ui/base/nine_image_painter_factory.h" 33 #include "ui/base/nine_image_painter_factory.h"
35 #include "ui/base/resource/resource_bundle.h" 34 #include "ui/base/resource/resource_bundle.h"
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 } 156 }
158 157
159 BrowserActionsContainer::~BrowserActionsContainer() { 158 BrowserActionsContainer::~BrowserActionsContainer() {
160 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, 159 FOR_EACH_OBSERVER(BrowserActionsContainerObserver,
161 observers_, 160 observers_,
162 OnBrowserActionsContainerDestroyed()); 161 OnBrowserActionsContainerDestroyed());
163 162
164 if (model_) 163 if (model_)
165 model_->RemoveObserver(this); 164 model_->RemoveObserver(this);
166 HideActivePopup(); 165 HideActivePopup();
167 DeleteToolbarActionViews(); 166 DeleteBrowserActionViews();
168 } 167 }
169 168
170 void BrowserActionsContainer::Init() { 169 void BrowserActionsContainer::Init() {
171 LoadImages(); 170 LoadImages();
172 171
173 // We wait to set the container width until now so that the chevron images 172 // We wait to set the container width until now so that the chevron images
174 // will be loaded. The width calculation needs to know the chevron size. 173 // will be loaded. The width calculation needs to know the chevron size.
175 if (model_ && model_->extensions_initialized()) { 174 if (model_ && model_->extensions_initialized()) {
176 container_width_ = GetPreferredWidth(); 175 container_width_ = GetPreferredWidth();
177 SetChevronVisibility(); 176 SetChevronVisibility();
178 } 177 }
179 178
180 initialized_ = true; 179 initialized_ = true;
181 } 180 }
182 181
183 const std::string& BrowserActionsContainer::GetIdAt(size_t index) { 182 const std::string& BrowserActionsContainer::GetIdAt(size_t index) {
184 return toolbar_action_views_[index]->view_controller()->GetId(); 183 return browser_action_views_[index]->view_controller()->GetId();
185 } 184 }
186 185
187 ToolbarActionView* BrowserActionsContainer::GetViewForExtension( 186 BrowserActionView* BrowserActionsContainer::GetViewForExtension(
188 const Extension* extension) { 187 const Extension* extension) {
189 for (ToolbarActionView* view : toolbar_action_views_) { 188 for (BrowserActionView* view : browser_action_views_) {
190 if (view->view_controller()->GetId() == extension->id()) 189 if (view->view_controller()->GetId() == extension->id())
191 return view; 190 return view;
192 } 191 }
193 return nullptr; 192 return NULL;
194 } 193 }
195 194
196 void BrowserActionsContainer::RefreshToolbarActionViews() { 195 void BrowserActionsContainer::RefreshBrowserActionViews() {
197 for (ToolbarActionView* view : toolbar_action_views_) 196 for (BrowserActionView* view : browser_action_views_)
198 view->UpdateState(); 197 view->UpdateState();
199 } 198 }
200 199
201 void BrowserActionsContainer::CreateToolbarActionViews() { 200 void BrowserActionsContainer::CreateBrowserActionViews() {
202 DCHECK(toolbar_action_views_.empty()); 201 DCHECK(browser_action_views_.empty());
203 if (!model_) 202 if (!model_)
204 return; 203 return;
205 204
206 ScopedVector<ToolbarActionViewController> actions = 205 ScopedVector<ToolbarActionViewController> actions =
207 GetToolbarActions(model_, browser_); 206 GetToolbarActions(model_, browser_);
208 for (ToolbarActionViewController* controller : actions) { 207 for (ToolbarActionViewController* controller : actions) {
209 ToolbarActionView* view = 208 BrowserActionView* view =
210 new ToolbarActionView(make_scoped_ptr(controller), browser_, this); 209 new BrowserActionView(make_scoped_ptr(controller), browser_, this);
211 toolbar_action_views_.push_back(view); 210 browser_action_views_.push_back(view);
212 AddChildView(view); 211 AddChildView(view);
213 } 212 }
214 actions.weak_clear(); 213 actions.weak_clear();
215 } 214 }
216 215
217 void BrowserActionsContainer::DeleteToolbarActionViews() { 216 void BrowserActionsContainer::DeleteBrowserActionViews() {
218 HideActivePopup(); 217 HideActivePopup();
219 STLDeleteElements(&toolbar_action_views_); 218 STLDeleteElements(&browser_action_views_);
220 } 219 }
221 220
222 size_t BrowserActionsContainer::VisibleBrowserActions() const { 221 size_t BrowserActionsContainer::VisibleBrowserActions() const {
223 size_t visible_actions = 0; 222 size_t visible_actions = 0;
224 for (const ToolbarActionView* view : toolbar_action_views_) { 223 for (const BrowserActionView* view : browser_action_views_) {
225 if (view->visible()) 224 if (view->visible())
226 ++visible_actions; 225 ++visible_actions;
227 } 226 }
228 return visible_actions; 227 return visible_actions;
229 } 228 }
230 229
231 size_t BrowserActionsContainer::VisibleBrowserActionsAfterAnimation() const { 230 size_t BrowserActionsContainer::VisibleBrowserActionsAfterAnimation() const {
232 if (!animating()) 231 if (!animating())
233 return VisibleBrowserActions(); 232 return VisibleBrowserActions();
234 233
(...skipping 11 matching lines...) Expand all
246 } 245 }
247 246
248 void BrowserActionsContainer::NotifyActionMovedToOverflow() { 247 void BrowserActionsContainer::NotifyActionMovedToOverflow() {
249 // When an action is moved to overflow, we shrink the size of the container 248 // When an action is moved to overflow, we shrink the size of the container
250 // by 1. 249 // by 1.
251 int icon_count = model_->GetVisibleIconCount(); 250 int icon_count = model_->GetVisibleIconCount();
252 // Since this happens when an icon moves from the main bar to overflow, we 251 // Since this happens when an icon moves from the main bar to overflow, we
253 // can't possibly have had no visible icons on the main bar. 252 // can't possibly have had no visible icons on the main bar.
254 DCHECK_NE(0, icon_count); 253 DCHECK_NE(0, icon_count);
255 if (icon_count == -1) 254 if (icon_count == -1)
256 icon_count = toolbar_action_views_.size(); 255 icon_count = browser_action_views_.size();
257 model_->SetVisibleIconCount(icon_count - 1); 256 model_->SetVisibleIconCount(icon_count - 1);
258 } 257 }
259 258
260 bool BrowserActionsContainer::ShownInsideMenu() const { 259 bool BrowserActionsContainer::ShownInsideMenu() const {
261 return in_overflow_mode(); 260 return in_overflow_mode();
262 } 261 }
263 262
264 void BrowserActionsContainer::OnToolbarActionViewDragDone() { 263 void BrowserActionsContainer::OnBrowserActionViewDragDone() {
265 ToolbarVisibleCountChanged(); 264 ToolbarVisibleCountChanged();
266 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, 265 FOR_EACH_OBSERVER(BrowserActionsContainerObserver,
267 observers_, 266 observers_,
268 OnBrowserActionDragDone()); 267 OnBrowserActionDragDone());
269 } 268 }
270 269
271 views::MenuButton* BrowserActionsContainer::GetOverflowReferenceView() { 270 views::MenuButton* BrowserActionsContainer::GetOverflowReferenceView() {
272 // With traditional overflow, the reference is the chevron. With the 271 // With traditional overflow, the reference is the chevron. With the
273 // redesign, we use the wrench menu instead. 272 // redesign, we use the wrench menu instead.
274 return chevron_ ? 273 return chevron_ ?
275 chevron_ : 274 chevron_ :
276 BrowserView::GetBrowserViewForBrowser(browser_)->toolbar()->app_menu(); 275 BrowserView::GetBrowserViewForBrowser(browser_)->toolbar()->app_menu();
277 } 276 }
278 277
279 void BrowserActionsContainer::SetPopupOwner(ToolbarActionView* popup_owner) { 278 void BrowserActionsContainer::SetPopupOwner(BrowserActionView* popup_owner) {
280 // We should never be setting a popup owner when one already exists, and 279 // We should never be setting a popup owner when one already exists, and
281 // never unsetting one when one wasn't set. 280 // never unsetting one when one wasn't set.
282 DCHECK((!popup_owner_ && popup_owner) || 281 DCHECK((!popup_owner_ && popup_owner) ||
283 (popup_owner_ && !popup_owner)); 282 (popup_owner_ && !popup_owner));
284 popup_owner_ = popup_owner; 283 popup_owner_ = popup_owner;
285 } 284 }
286 285
287 void BrowserActionsContainer::HideActivePopup() { 286 void BrowserActionsContainer::HideActivePopup() {
288 if (popup_owner_) 287 if (popup_owner_)
289 popup_owner_->view_controller()->HidePopup(); 288 popup_owner_->view_controller()->HidePopup();
290 } 289 }
291 290
292 ToolbarActionView* BrowserActionsContainer::GetMainViewForAction( 291 BrowserActionView* BrowserActionsContainer::GetMainViewForAction(
293 ToolbarActionView* view) { 292 BrowserActionView* view) {
294 if (!in_overflow_mode()) 293 if (!in_overflow_mode())
295 return view; // This is the main view. 294 return view; // This is the main view.
296 295
297 // The overflow container and main container each have the same views and 296 // The overflow container and main container each have the same views and
298 // view indices, so we can return the view of the index that |view| has in 297 // view indices, so we can return the view of the index that |view| has in
299 // this container. 298 // this container.
300 ToolbarActionViews::const_iterator iter = 299 BrowserActionViews::const_iterator iter =
301 std::find(toolbar_action_views_.begin(), 300 std::find(browser_action_views_.begin(),
302 toolbar_action_views_.end(), 301 browser_action_views_.end(),
303 view); 302 view);
304 DCHECK(iter != toolbar_action_views_.end()); 303 DCHECK(iter != browser_action_views_.end());
305 size_t index = iter - toolbar_action_views_.begin(); 304 size_t index = iter - browser_action_views_.begin();
306 return main_container_->toolbar_action_views_[index]; 305 return main_container_->browser_action_views_[index];
307 } 306 }
308 307
309 void BrowserActionsContainer::AddObserver( 308 void BrowserActionsContainer::AddObserver(
310 BrowserActionsContainerObserver* observer) { 309 BrowserActionsContainerObserver* observer) {
311 observers_.AddObserver(observer); 310 observers_.AddObserver(observer);
312 } 311 }
313 312
314 void BrowserActionsContainer::RemoveObserver( 313 void BrowserActionsContainer::RemoveObserver(
315 BrowserActionsContainerObserver* observer) { 314 BrowserActionsContainerObserver* observer) {
316 observers_.RemoveObserver(observer); 315 observers_.RemoveObserver(observer);
317 } 316 }
318 317
319 gfx::Size BrowserActionsContainer::GetPreferredSize() const { 318 gfx::Size BrowserActionsContainer::GetPreferredSize() const {
320 if (in_overflow_mode()) { 319 if (in_overflow_mode()) {
321 int icon_count = GetIconCount(); 320 int icon_count = GetIconCount();
322 // In overflow, we always have a preferred size of a full row (even if we 321 // In overflow, we always have a preferred size of a full row (even if we
323 // don't use it), and always of at least one row. The parent may decide to 322 // don't use it), and always of at least one row. The parent may decide to
324 // show us even when empty, e.g. as a drag target for dragging in icons from 323 // show us even when empty, e.g. as a drag target for dragging in icons from
325 // the main container. 324 // the main container.
326 int row_count = 325 int row_count =
327 ((std::max(0, icon_count - 1)) / icons_per_overflow_menu_row_) + 1; 326 ((std::max(0, icon_count - 1)) / icons_per_overflow_menu_row_) + 1;
328 return gfx::Size(IconCountToWidth(icons_per_overflow_menu_row_), 327 return gfx::Size(IconCountToWidth(icons_per_overflow_menu_row_),
329 row_count * IconHeight()); 328 row_count * IconHeight());
330 } 329 }
331 330
332 // If there are no actions to show, then don't show the container at all. 331 // If there are no actions to show, then don't show the container at all.
333 if (toolbar_action_views_.empty()) 332 if (browser_action_views_.empty())
334 return gfx::Size(); 333 return gfx::Size();
335 334
336 // We calculate the size of the view by taking the current width and 335 // We calculate the size of the view by taking the current width and
337 // subtracting resize_amount_ (the latter represents how far the user is 336 // subtracting resize_amount_ (the latter represents how far the user is
338 // resizing the view or, if animating the snapping, how far to animate it). 337 // resizing the view or, if animating the snapping, how far to animate it).
339 // But we also clamp it to a minimum size and the maximum size, so that the 338 // But we also clamp it to a minimum size and the maximum size, so that the
340 // container can never shrink too far or take up more space than it needs. 339 // container can never shrink too far or take up more space than it needs.
341 // In other words: MinimumNonemptyWidth() < width() - resize < ClampTo(MAX). 340 // In other words: MinimumNonemptyWidth() < width() - resize < ClampTo(MAX).
342 int preferred_width = std::min( 341 int preferred_width = std::min(
343 std::max(MinimumNonemptyWidth(), container_width_ - resize_amount_), 342 std::max(MinimumNonemptyWidth(), container_width_ - resize_amount_),
344 IconCountToWidth(-1)); 343 IconCountToWidth(-1));
345 return gfx::Size(preferred_width, IconHeight()); 344 return gfx::Size(preferred_width, IconHeight());
346 } 345 }
347 346
348 int BrowserActionsContainer::GetHeightForWidth(int width) const { 347 int BrowserActionsContainer::GetHeightForWidth(int width) const {
349 if (in_overflow_mode()) 348 if (in_overflow_mode())
350 icons_per_overflow_menu_row_ = (width - kItemSpacing) / IconWidth(true); 349 icons_per_overflow_menu_row_ = (width - kItemSpacing) / IconWidth(true);
351 return GetPreferredSize().height(); 350 return GetPreferredSize().height();
352 } 351 }
353 352
354 gfx::Size BrowserActionsContainer::GetMinimumSize() const { 353 gfx::Size BrowserActionsContainer::GetMinimumSize() const {
355 int min_width = std::min(MinimumNonemptyWidth(), IconCountToWidth(-1)); 354 int min_width = std::min(MinimumNonemptyWidth(), IconCountToWidth(-1));
356 return gfx::Size(min_width, IconHeight()); 355 return gfx::Size(min_width, IconHeight());
357 } 356 }
358 357
359 void BrowserActionsContainer::Layout() { 358 void BrowserActionsContainer::Layout() {
360 if (toolbar_action_views_.empty()) { 359 if (browser_action_views_.empty()) {
361 SetVisible(false); 360 SetVisible(false);
362 return; 361 return;
363 } 362 }
364 363
365 SetVisible(true); 364 SetVisible(true);
366 if (resize_area_) 365 if (resize_area_)
367 resize_area_->SetBounds(0, 0, kItemSpacing, height()); 366 resize_area_->SetBounds(0, 0, kItemSpacing, height());
368 367
369 // If the icons don't all fit, show the chevron (unless suppressed). 368 // If the icons don't all fit, show the chevron (unless suppressed).
370 int max_x = GetPreferredSize().width(); 369 int max_x = GetPreferredSize().width();
(...skipping 14 matching lines...) Expand all
385 int container_padding = 384 int container_padding =
386 in_overflow_mode() ? kItemSpacing : ToolbarView::kStandardSpacing; 385 in_overflow_mode() ? kItemSpacing : ToolbarView::kStandardSpacing;
387 // The range of visible icons, from start_index (inclusive) to end_index 386 // The range of visible icons, from start_index (inclusive) to end_index
388 // (exclusive). 387 // (exclusive).
389 size_t start_index = in_overflow_mode() ? 388 size_t start_index = in_overflow_mode() ?
390 main_container_->VisibleBrowserActionsAfterAnimation() : 0u; 389 main_container_->VisibleBrowserActionsAfterAnimation() : 0u;
391 // For the main container's last visible icon, we calculate how many icons we 390 // For the main container's last visible icon, we calculate how many icons we
392 // can display with the given width. We add an extra kItemSpacing because the 391 // can display with the given width. We add an extra kItemSpacing because the
393 // last icon doesn't need padding, but we want it to divide easily. 392 // last icon doesn't need padding, but we want it to divide easily.
394 size_t end_index = in_overflow_mode() ? 393 size_t end_index = in_overflow_mode() ?
395 toolbar_action_views_.size() : 394 browser_action_views_.size() :
396 (max_x - 2 * container_padding + kItemSpacing) / IconWidth(true); 395 (max_x - 2 * container_padding + kItemSpacing) / IconWidth(true);
397 // The maximum length for one row of icons. 396 // The maximum length for one row of icons.
398 size_t row_length = 397 size_t row_length =
399 in_overflow_mode() ? icons_per_overflow_menu_row_ : end_index; 398 in_overflow_mode() ? icons_per_overflow_menu_row_ : end_index;
400 399
401 // Now draw the icons for the actions in the available space. Once all the 400 // Now draw the icons for the browser actions in the available space. Once
402 // variables are in place, the layout works equally well for the main and 401 // all the variables are in place, the layout works equally well for the main
403 // overflow container. 402 // and overflow container.
404 for (size_t i = 0u; i < toolbar_action_views_.size(); ++i) { 403 for (size_t i = 0u; i < browser_action_views_.size(); ++i) {
405 ToolbarActionView* view = toolbar_action_views_[i]; 404 BrowserActionView* view = browser_action_views_[i];
406 if (i < start_index || i >= end_index) { 405 if (i < start_index || i >= end_index) {
407 view->SetVisible(false); 406 view->SetVisible(false);
408 } else { 407 } else {
409 size_t relative_index = i - start_index; 408 size_t relative_index = i - start_index;
410 size_t index_in_row = relative_index % row_length; 409 size_t index_in_row = relative_index % row_length;
411 size_t row_index = relative_index / row_length; 410 size_t row_index = relative_index / row_length;
412 view->SetBounds(container_padding + index_in_row * IconWidth(true), 411 view->SetBounds(container_padding + index_in_row * IconWidth(true),
413 row_index * IconHeight(), 412 row_index * IconHeight(),
414 IconWidth(false), 413 IconWidth(false),
415 IconHeight()); 414 IconHeight());
(...skipping 13 matching lines...) Expand all
429 } 428 }
430 429
431 bool BrowserActionsContainer::CanDrop(const OSExchangeData& data) { 430 bool BrowserActionsContainer::CanDrop(const OSExchangeData& data) {
432 return BrowserActionDragData::CanDrop(data, profile_); 431 return BrowserActionDragData::CanDrop(data, profile_);
433 } 432 }
434 433
435 int BrowserActionsContainer::OnDragUpdated( 434 int BrowserActionsContainer::OnDragUpdated(
436 const ui::DropTargetEvent& event) { 435 const ui::DropTargetEvent& event) {
437 size_t row_index = 0; 436 size_t row_index = 0;
438 size_t before_icon_in_row = 0; 437 size_t before_icon_in_row = 0;
439 // If there are no visible actions (such as when dragging an icon to an empty 438 // If there are no visible browser actions (such as when dragging an icon to
440 // overflow/main container), then 0, 0 for row, column is correct. 439 // an empty overflow/main container), then 0, 0 for row, column is correct.
441 if (VisibleBrowserActions() != 0) { 440 if (VisibleBrowserActions() != 0) {
442 // Figure out where to display the indicator. This is a complex calculation: 441 // Figure out where to display the indicator. This is a complex calculation:
443 442
444 // First, we subtract out the padding to the left of the icon area, which is 443 // First, we subtract out the padding to the left of the icon area, which is
445 // ToolbarView::kStandardSpacing. If we're right-to-left, we also mirror the 444 // ToolbarView::kStandardSpacing. If we're right-to-left, we also mirror the
446 // event.x() so that our calculations are consistent with left-to-right. 445 // event.x() so that our calculations are consistent with left-to-right.
447 int offset_into_icon_area = 446 int offset_into_icon_area =
448 GetMirroredXInView(event.x()) - ToolbarView::kStandardSpacing; 447 GetMirroredXInView(event.x()) - ToolbarView::kStandardSpacing;
449 448
450 // Next, figure out what row we're on. This only matters for overflow mode, 449 // Next, figure out what row we're on. This only matters for overflow mode,
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 // correct when dragging an icon to the left. When dragging to the right, 534 // correct when dragging an icon to the left. When dragging to the right,
536 // however, we want the icon being dragged to get the index of the item to 535 // however, we want the icon being dragged to get the index of the item to
537 // the left of the drop indicator, so we subtract one. 536 // the left of the drop indicator, so we subtract one.
538 // * Well, it can also point to the end, but not when dragging to the left. :) 537 // * Well, it can also point to the end, but not when dragging to the left. :)
539 if (i > data.index()) 538 if (i > data.index())
540 --i; 539 --i;
541 540
542 // If this was a drag between containers, we will have to adjust the number of 541 // If this was a drag between containers, we will have to adjust the number of
543 // visible icons. 542 // visible icons.
544 bool drag_between_containers = 543 bool drag_between_containers =
545 !toolbar_action_views_[data.index()]->visible(); 544 !browser_action_views_[data.index()]->visible();
546 model_->MoveExtensionIcon(GetIdAt(data.index()), i); 545 model_->MoveExtensionIcon(GetIdAt(data.index()), i);
547 546
548 if (drag_between_containers) { 547 if (drag_between_containers) {
549 // Let the main container update the model. 548 // Let the main container update the model.
550 if (in_overflow_mode()) 549 if (in_overflow_mode())
551 main_container_->NotifyActionMovedToOverflow(); 550 main_container_->NotifyActionMovedToOverflow();
552 else // This is the main container. 551 else // This is the main container.
553 model_->SetVisibleIconCount(model_->GetVisibleIconCount() + 1); 552 model_->SetVisibleIconCount(model_->GetVisibleIconCount() + 1);
554 } 553 }
555 554
556 OnDragExited(); // Perform clean up after dragging. 555 OnDragExited(); // Perform clean up after dragging.
557 return ui::DragDropTypes::DRAG_MOVE; 556 return ui::DragDropTypes::DRAG_MOVE;
558 } 557 }
559 558
560 void BrowserActionsContainer::GetAccessibleState( 559 void BrowserActionsContainer::GetAccessibleState(
561 ui::AXViewState* state) { 560 ui::AXViewState* state) {
562 state->role = ui::AX_ROLE_GROUP; 561 state->role = ui::AX_ROLE_GROUP;
563 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS); 562 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS);
564 } 563 }
565 564
566 void BrowserActionsContainer::WriteDragDataForView(View* sender, 565 void BrowserActionsContainer::WriteDragDataForView(View* sender,
567 const gfx::Point& press_pt, 566 const gfx::Point& press_pt,
568 OSExchangeData* data) { 567 OSExchangeData* data) {
569 DCHECK(data); 568 DCHECK(data);
570 569
571 ToolbarActionViews::iterator iter = std::find(toolbar_action_views_.begin(), 570 BrowserActionViews::iterator iter = std::find(browser_action_views_.begin(),
572 toolbar_action_views_.end(), 571 browser_action_views_.end(),
573 sender); 572 sender);
574 DCHECK(iter != toolbar_action_views_.end()); 573 DCHECK(iter != browser_action_views_.end());
575 ToolbarActionViewController* view_controller = (*iter)->view_controller(); 574 ToolbarActionViewController* view_controller = (*iter)->view_controller();
576 drag_utils::SetDragImageOnDataObject( 575 drag_utils::SetDragImageOnDataObject(
577 view_controller->GetIconWithBadge(), 576 view_controller->GetIconWithBadge(),
578 press_pt.OffsetFromOrigin(), 577 press_pt.OffsetFromOrigin(),
579 data); 578 data);
580 // Fill in the remaining info. 579 // Fill in the remaining info.
581 BrowserActionDragData drag_data(view_controller->GetId(), 580 BrowserActionDragData drag_data(view_controller->GetId(),
582 iter - toolbar_action_views_.begin()); 581 iter - browser_action_views_.begin());
583 drag_data.Write(profile_, data); 582 drag_data.Write(profile_, data);
584 } 583 }
585 584
586 int BrowserActionsContainer::GetDragOperationsForView(View* sender, 585 int BrowserActionsContainer::GetDragOperationsForView(View* sender,
587 const gfx::Point& p) { 586 const gfx::Point& p) {
588 return ui::DragDropTypes::DRAG_MOVE; 587 return ui::DragDropTypes::DRAG_MOVE;
589 } 588 }
590 589
591 bool BrowserActionsContainer::CanStartDragForView(View* sender, 590 bool BrowserActionsContainer::CanStartDragForView(View* sender,
592 const gfx::Point& press_pt, 591 const gfx::Point& press_pt,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 651
653 gfx::NativeView BrowserActionsContainer::TestGetPopup() { 652 gfx::NativeView BrowserActionsContainer::TestGetPopup() {
654 return popup_owner_ ? 653 return popup_owner_ ?
655 popup_owner_->view_controller()->GetPopupNativeView() : 654 popup_owner_->view_controller()->GetPopupNativeView() :
656 NULL; 655 NULL;
657 } 656 }
658 657
659 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { 658 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) {
660 // If the views haven't been initialized yet, wait for the next call to 659 // If the views haven't been initialized yet, wait for the next call to
661 // paint (one will be triggered by entering highlight mode). 660 // paint (one will be triggered by entering highlight mode).
662 if (model_->is_highlighting() && !toolbar_action_views_.empty() && 661 if (model_->is_highlighting() && !browser_action_views_.empty() &&
663 !in_overflow_mode()) { 662 !in_overflow_mode()) {
664 views::Painter::PaintPainterAt( 663 views::Painter::PaintPainterAt(
665 canvas, highlight_painter_.get(), GetLocalBounds()); 664 canvas, highlight_painter_.get(), GetLocalBounds());
666 } 665 }
667 666
668 // TODO(sky/glen): Instead of using a drop indicator, animate the icons while 667 // TODO(sky/glen): Instead of using a drop indicator, animate the icons while
669 // dragging (like we do for tab dragging). 668 // dragging (like we do for tab dragging).
670 if (drop_position_.get()) { 669 if (drop_position_.get()) {
671 // The two-pixel width drop indicator. 670 // The two-pixel width drop indicator.
672 static const int kDropIndicatorWidth = 2; 671 static const int kDropIndicatorWidth = 2;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 browser_->profile(), 718 browser_->profile(),
720 parent()->GetFocusManager(), 719 parent()->GetFocusManager(),
721 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, 720 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS,
722 this)); 721 this));
723 } 722 }
724 723
725 // Initial toolbar button creation and placement in the widget hierarchy. 724 // Initial toolbar button creation and placement in the widget hierarchy.
726 // We do this here instead of in the constructor because AddBrowserAction 725 // We do this here instead of in the constructor because AddBrowserAction
727 // calls Layout on the Toolbar, which needs this object to be constructed 726 // calls Layout on the Toolbar, which needs this object to be constructed
728 // before its Layout function is called. 727 // before its Layout function is called.
729 CreateToolbarActionViews(); 728 CreateBrowserActionViews();
730 } 729 }
731 } 730 }
732 731
733 // static 732 // static
734 int BrowserActionsContainer::IconWidth(bool include_padding) { 733 int BrowserActionsContainer::IconWidth(bool include_padding) {
735 static bool initialized = false; 734 static bool initialized = false;
736 static int icon_width = 0; 735 static int icon_width = 0;
737 if (!initialized) { 736 if (!initialized) {
738 initialized = true; 737 initialized = true;
739 icon_width = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 738 icon_width = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
740 IDR_BROWSER_ACTION)->width(); 739 IDR_BROWSER_ACTION)->width();
741 } 740 }
742 return icon_width + (include_padding ? kItemSpacing : 0); 741 return icon_width + (include_padding ? kItemSpacing : 0);
743 } 742 }
744 743
745 // static 744 // static
746 int BrowserActionsContainer::IconHeight() { 745 int BrowserActionsContainer::IconHeight() {
747 static bool initialized = false; 746 static bool initialized = false;
748 static int icon_height = 0; 747 static int icon_height = 0;
749 if (!initialized) { 748 if (!initialized) {
750 initialized = true; 749 initialized = true;
751 icon_height = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( 750 icon_height = ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
752 IDR_BROWSER_ACTION)->height(); 751 IDR_BROWSER_ACTION)->height();
753 } 752 }
754 return icon_height; 753 return icon_height;
755 } 754 }
756 755
757 void BrowserActionsContainer::ToolbarExtensionAdded(const Extension* extension, 756 void BrowserActionsContainer::ToolbarExtensionAdded(const Extension* extension,
758 int index) { 757 int index) {
759 #if !defined(NDEBUG) 758 #if defined(DEBUG)
760 for (size_t i = 0; i < toolbar_action_views_.size(); ++i) { 759 for (size_t i = 0; i < browser_action_views_.size(); ++i) {
761 DCHECK(GetViewForExtension(extension) == nullptr) << 760 DCHECK(browser_action_views_[i]->extension() != extension) <<
762 "Asked to add an action view for an extension that already exists"; 761 "Asked to add a browser action view for an extension that already "
762 "exists.";
763 } 763 }
764 #endif 764 #endif
765 if (chevron_) 765 if (chevron_)
766 chevron_->CloseMenu(); 766 chevron_->CloseMenu();
767 767
768 // Add the new action to the vector and the view hierarchy. 768 // Add the new browser action to the vector and the view hierarchy.
769 ToolbarActionView* view = new ToolbarActionView( 769 BrowserActionView* view = new BrowserActionView(
770 make_scoped_ptr(new ExtensionActionViewController( 770 make_scoped_ptr(new ExtensionActionViewController(
771 extension, 771 extension,
772 browser_, 772 browser_,
773 extensions::ExtensionActionManager::Get(profile_)-> 773 extensions::ExtensionActionManager::Get(profile_)->
774 GetExtensionAction(*extension))), 774 GetExtensionAction(*extension))),
775 browser_, 775 browser_,
776 this); 776 this);
777 toolbar_action_views_.insert(toolbar_action_views_.begin() + index, view); 777 browser_action_views_.insert(browser_action_views_.begin() + index, view);
778 AddChildViewAt(view, index); 778 AddChildViewAt(view, index);
779 779
780 // If we are still initializing the container, don't bother animating. 780 // If we are still initializing the container, don't bother animating.
781 if (!model_->extensions_initialized()) 781 if (!model_->extensions_initialized())
782 return; 782 return;
783 783
784 // If this is just an upgrade, then don't worry about resizing. 784 // If this is just an upgrade, then don't worry about resizing.
785 if (!extensions::ExtensionSystem::Get(profile_)->runtime_data()-> 785 if (!extensions::ExtensionSystem::Get(profile_)->runtime_data()->
786 IsBeingUpgraded(extension)) { 786 IsBeingUpgraded(extension)) {
787 // We need to resize if either: 787 // We need to resize if either:
788 // - The container is set to display all icons (visible count = -1), or 788 // - The container is set to display all icons (visible count = -1), or
789 // - The container will need to expand to include the chevron. This can 789 // - The container will need to expand to include the chevron. This can
790 // happen when the container is set to display <n> icons, where <n> is 790 // happen when the container is set to display <n> icons, where <n> is
791 // the number of icons before the new icon. With the new icon, the chevron 791 // the number of icons before the new icon. With the new icon, the chevron
792 // will need to be displayed. 792 // will need to be displayed.
793 int model_icon_count = model_->GetVisibleIconCount(); 793 int model_icon_count = model_->GetVisibleIconCount();
794 if (model_icon_count == -1 || 794 if (model_icon_count == -1 ||
795 (static_cast<size_t>(model_icon_count) < toolbar_action_views_.size() && 795 (static_cast<size_t>(model_icon_count) < browser_action_views_.size() &&
796 (chevron_ && !chevron_->visible()))) { 796 (chevron_ && !chevron_->visible()))) {
797 suppress_chevron_ = true; 797 suppress_chevron_ = true;
798 Animate(gfx::Tween::LINEAR, GetIconCount()); 798 Animate(gfx::Tween::LINEAR, GetIconCount());
799 return; 799 return;
800 } 800 }
801 } 801 }
802 802
803 // Otherwise, we don't have to resize, so just redraw the (possibly modified) 803 // Otherwise, we don't have to resize, so just redraw the (possibly modified)
804 // visible icon set. 804 // visible icon set.
805 OnBrowserActionVisibilityChanged(); 805 OnBrowserActionVisibilityChanged();
806 } 806 }
807 807
808 void BrowserActionsContainer::ToolbarExtensionRemoved( 808 void BrowserActionsContainer::ToolbarExtensionRemoved(
809 const Extension* extension) { 809 const Extension* extension) {
810 if (chevron_) 810 if (chevron_)
811 chevron_->CloseMenu(); 811 chevron_->CloseMenu();
812 812
813 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); 813 size_t visible_actions = VisibleBrowserActionsAfterAnimation();
814 for (ToolbarActionViews::iterator i(toolbar_action_views_.begin()); 814 for (BrowserActionViews::iterator i(browser_action_views_.begin());
815 i != toolbar_action_views_.end(); ++i) { 815 i != browser_action_views_.end(); ++i) {
816 if ((*i)->view_controller()->GetId() == extension->id()) { 816 if ((*i)->view_controller()->GetId() == extension->id()) {
817 delete *i; 817 delete *i;
818 toolbar_action_views_.erase(i); 818 browser_action_views_.erase(i);
819 819
820 // If the extension is being upgraded we don't want the bar to shrink 820 // If the extension is being upgraded we don't want the bar to shrink
821 // because the icon is just going to get re-added to the same location. 821 // because the icon is just going to get re-added to the same location.
822 if (extensions::ExtensionSystem::Get(profile_)->runtime_data()-> 822 if (extensions::ExtensionSystem::Get(profile_)->runtime_data()->
823 IsBeingUpgraded(extension)) 823 IsBeingUpgraded(extension))
824 return; 824 return;
825 825
826 if (toolbar_action_views_.size() > visible_actions) { 826 if (browser_action_views_.size() > visible_actions) {
827 // If we have more icons than we can show, then we must not be changing 827 // If we have more icons than we can show, then we must not be changing
828 // the container size (since we either removed an icon from the main 828 // the container size (since we either removed an icon from the main
829 // area and one from the overflow list will have shifted in, or we 829 // area and one from the overflow list will have shifted in, or we
830 // removed an entry directly from the overflow list). 830 // removed an entry directly from the overflow list).
831 OnBrowserActionVisibilityChanged(); 831 OnBrowserActionVisibilityChanged();
832 } else { 832 } else {
833 // Either we went from overflow to no-overflow, or we shrunk the no- 833 // Either we went from overflow to no-overflow, or we shrunk the no-
834 // overflow container by 1. Either way the size changed, so animate. 834 // overflow container by 1. Either way the size changed, so animate.
835 if (chevron_) 835 if (chevron_)
836 chevron_->SetVisible(false); 836 chevron_->SetVisible(false);
837 Animate(gfx::Tween::EASE_OUT, toolbar_action_views_.size()); 837 Animate(gfx::Tween::EASE_OUT, browser_action_views_.size());
838 } 838 }
839 return; // We have found the action to remove, bail out. 839 return; // We have found the action to remove, bail out.
840 } 840 }
841 } 841 }
842 } 842 }
843 843
844 void BrowserActionsContainer::ToolbarExtensionMoved(const Extension* extension, 844 void BrowserActionsContainer::ToolbarExtensionMoved(const Extension* extension,
845 int index) { 845 int index) {
846 DCHECK(index >= 0 && index < static_cast<int>(toolbar_action_views_.size())); 846 DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size()));
847 847
848 ToolbarActionViews::iterator iter = toolbar_action_views_.begin(); 848 BrowserActionViews::iterator iter = browser_action_views_.begin();
849 while (iter != toolbar_action_views_.end() && 849 while (iter != browser_action_views_.end() &&
850 (*iter)->view_controller()->GetId() != extension->id()) 850 (*iter)->view_controller()->GetId() != extension->id())
851 ++iter; 851 ++iter;
852 852
853 DCHECK(iter != toolbar_action_views_.end()); 853 DCHECK(iter != browser_action_views_.end());
854 if (iter - toolbar_action_views_.begin() == index) 854 if (iter - browser_action_views_.begin() == index)
855 return; // Already in place. 855 return; // Already in place.
856 856
857 ToolbarActionView* moved_view = *iter; 857 BrowserActionView* moved_view = *iter;
858 toolbar_action_views_.erase(iter); 858 browser_action_views_.erase(iter);
859 toolbar_action_views_.insert( 859 browser_action_views_.insert(
860 toolbar_action_views_.begin() + index, moved_view); 860 browser_action_views_.begin() + index, moved_view);
861 861
862 Layout(); 862 Layout();
863 SchedulePaint(); 863 SchedulePaint();
864 } 864 }
865 865
866 void BrowserActionsContainer::ToolbarExtensionUpdated( 866 void BrowserActionsContainer::ToolbarExtensionUpdated(
867 const Extension* extension) { 867 const Extension* extension) {
868 ToolbarActionView* view = GetViewForExtension(extension); 868 BrowserActionView* view = GetViewForExtension(extension);
869 // There might not be a view in cases where we are highlighting or if we 869 // There might not be a view in cases where we are highlighting or if we
870 // haven't fully initialized extensions. 870 // haven't fully initialized extensions.
871 if (view) 871 if (view)
872 view->UpdateState(); 872 view->UpdateState();
873 } 873 }
874 874
875 bool BrowserActionsContainer::ShowExtensionActionPopup( 875 bool BrowserActionsContainer::ShowExtensionActionPopup(
876 const Extension* extension, 876 const Extension* extension,
877 bool grant_active_tab) { 877 bool grant_active_tab) {
878 // Don't override another popup, and only show in the active window. 878 // Don't override another popup, and only show in the active window.
879 if (popup_owner_ || !browser_->window()->IsActive()) 879 if (popup_owner_ || !browser_->window()->IsActive())
880 return false; 880 return false;
881 881
882 ToolbarActionView* view = GetViewForExtension(extension); 882 BrowserActionView* view = GetViewForExtension(extension);
883 return view && view->view_controller()->ExecuteAction(grant_active_tab); 883 return view && view->view_controller()->ExecuteAction(grant_active_tab);
884 } 884 }
885 885
886 void BrowserActionsContainer::ToolbarVisibleCountChanged() { 886 void BrowserActionsContainer::ToolbarVisibleCountChanged() {
887 if (GetPreferredWidth() != container_width_) 887 if (GetPreferredWidth() != container_width_)
888 Animate(gfx::Tween::EASE_OUT, GetIconCount()); 888 Animate(gfx::Tween::EASE_OUT, GetIconCount());
889 } 889 }
890 890
891 void BrowserActionsContainer::ToolbarHighlightModeChanged( 891 void BrowserActionsContainer::ToolbarHighlightModeChanged(
892 bool is_highlighting) { 892 bool is_highlighting) {
893 // The visual highlighting is done in OnPaint(). It's a bit of a pain that 893 // The visual highlighting is done in OnPaint(). It's a bit of a pain that
894 // we delete and recreate everything here, but given everything else going on 894 // we delete and recreate everything here, but given everything else going on
895 // (the lack of highlight, n more extensions appearing, etc), it's not worth 895 // (the lack of highlight, n more extensions appearing, etc), it's not worth
896 // the extra complexity to create and insert only the new extensions. 896 // the extra complexity to create and insert only the new extensions.
897 DeleteToolbarActionViews(); 897 DeleteBrowserActionViews();
898 CreateToolbarActionViews(); 898 CreateBrowserActionViews();
899 Animate(gfx::Tween::LINEAR, GetIconCount()); 899 Animate(gfx::Tween::LINEAR, GetIconCount());
900 } 900 }
901 901
902 Browser* BrowserActionsContainer::GetBrowser() { 902 Browser* BrowserActionsContainer::GetBrowser() {
903 return browser_; 903 return browser_;
904 } 904 }
905 905
906 void BrowserActionsContainer::LoadImages() { 906 void BrowserActionsContainer::LoadImages() {
907 if (in_overflow_mode()) 907 if (in_overflow_mode())
908 return; // Overflow mode has neither a chevron nor highlighting. 908 return; // Overflow mode has neither a chevron nor highlighting.
909 909
910 ui::ThemeProvider* tp = GetThemeProvider(); 910 ui::ThemeProvider* tp = GetThemeProvider();
911 if (tp && chevron_) { 911 if (tp && chevron_) {
912 chevron_->SetImage(views::Button::STATE_NORMAL, 912 chevron_->SetImage(views::Button::STATE_NORMAL,
913 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); 913 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW));
914 } 914 }
915 915
916 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); 916 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT);
917 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); 917 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages));
918 } 918 }
919 919
920 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { 920 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() {
921 SetVisible(!toolbar_action_views_.empty()); 921 SetVisible(!browser_action_views_.empty());
922 if (parent()) { // Parent can be null in testing. 922 if (parent()) { // Parent can be null in testing.
923 parent()->Layout(); 923 parent()->Layout();
924 parent()->SchedulePaint(); 924 parent()->SchedulePaint();
925 } 925 }
926 } 926 }
927 927
928 int BrowserActionsContainer::GetPreferredWidth() { 928 int BrowserActionsContainer::GetPreferredWidth() {
929 return IconCountToWidth(GetIconCount()); 929 return IconCountToWidth(GetIconCount());
930 } 930 }
931 931
932 void BrowserActionsContainer::SetChevronVisibility() { 932 void BrowserActionsContainer::SetChevronVisibility() {
933 if (chevron_) { 933 if (chevron_) {
934 chevron_->SetVisible( 934 chevron_->SetVisible(
935 VisibleBrowserActionsAfterAnimation() < toolbar_action_views_.size()); 935 VisibleBrowserActionsAfterAnimation() < browser_action_views_.size());
936 } 936 }
937 } 937 }
938 938
939 int BrowserActionsContainer::IconCountToWidth(int icons) const { 939 int BrowserActionsContainer::IconCountToWidth(int icons) const {
940 if (icons < 0) 940 if (icons < 0)
941 icons = toolbar_action_views_.size(); 941 icons = browser_action_views_.size();
942 bool display_chevron = 942 bool display_chevron =
943 chevron_ && static_cast<size_t>(icons) < toolbar_action_views_.size(); 943 chevron_ && static_cast<size_t>(icons) < browser_action_views_.size();
944 if (icons == 0 && !display_chevron) 944 if (icons == 0 && !display_chevron)
945 return ToolbarView::kStandardSpacing; 945 return ToolbarView::kStandardSpacing;
946 int icons_size = 946 int icons_size =
947 (icons == 0) ? 0 : ((icons * IconWidth(true)) - kItemSpacing); 947 (icons == 0) ? 0 : ((icons * IconWidth(true)) - kItemSpacing);
948 int chevron_size = display_chevron ? 948 int chevron_size = display_chevron ?
949 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; 949 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0;
950 // In overflow mode, our padding is to use item spacing on either end (just so 950 // In overflow mode, our padding is to use item spacing on either end (just so
951 // we can see the drop indicator). Otherwise we use the standard toolbar 951 // we can see the drop indicator). Otherwise we use the standard toolbar
952 // spacing. 952 // spacing.
953 // Note: These are actually the same thing, but, on the offchance one 953 // Note: These are actually the same thing, but, on the offchance one
954 // changes, let's get it right. 954 // changes, let's get it right.
955 int padding = 955 int padding =
956 2 * (in_overflow_mode() ? kItemSpacing : ToolbarView::kStandardSpacing); 956 2 * (in_overflow_mode() ? kItemSpacing : ToolbarView::kStandardSpacing);
957 return icons_size + chevron_size + padding; 957 return icons_size + chevron_size + padding;
958 } 958 }
959 959
960 size_t BrowserActionsContainer::WidthToIconCount(int pixels) const { 960 size_t BrowserActionsContainer::WidthToIconCount(int pixels) const {
961 // Check for widths large enough to show the entire icon set. 961 // Check for widths large enough to show the entire icon set.
962 if (pixels >= IconCountToWidth(-1)) 962 if (pixels >= IconCountToWidth(-1))
963 return toolbar_action_views_.size(); 963 return browser_action_views_.size();
964 964
965 // We reserve space for the padding on either side of the toolbar... 965 // We reserve space for the padding on either side of the toolbar...
966 int available_space = pixels - (ToolbarView::kStandardSpacing * 2); 966 int available_space = pixels - (ToolbarView::kStandardSpacing * 2);
967 // ... and, if the chevron is enabled, the chevron. 967 // ... and, if the chevron is enabled, the chevron.
968 if (chevron_) 968 if (chevron_)
969 available_space -= (chevron_->GetPreferredSize().width() + kChevronSpacing); 969 available_space -= (chevron_->GetPreferredSize().width() + kChevronSpacing);
970 970
971 // Now we add an extra between-item padding value so the space can be divided 971 // Now we add an extra between-item padding value so the space can be divided
972 // evenly by (size of icon with padding). 972 // evenly by (size of icon with padding).
973 return static_cast<size_t>( 973 return static_cast<size_t>(
(...skipping 25 matching lines...) Expand all
999 999
1000 size_t BrowserActionsContainer::GetIconCount() const { 1000 size_t BrowserActionsContainer::GetIconCount() const {
1001 if (!model_) 1001 if (!model_)
1002 return 0u; 1002 return 0u;
1003 1003
1004 // Find the absolute value for the model's visible count. 1004 // Find the absolute value for the model's visible count.
1005 int model_visible_size = model_->GetVisibleIconCount(); 1005 int model_visible_size = model_->GetVisibleIconCount();
1006 size_t absolute_model_visible_size = model_visible_size == -1 ? 1006 size_t absolute_model_visible_size = model_visible_size == -1 ?
1007 model_->toolbar_items().size() : model_visible_size; 1007 model_->toolbar_items().size() : model_visible_size;
1008 1008
1009 #if !defined(NDEBUG) 1009 #if defined(DEBUG)
1010 // Good time for some sanity checks: We should never try to display more 1010 // Good time for some sanity checks: We should never try to display more
1011 // icons than we have, and we should always have a view per item in the model. 1011 // icons than we have, and we should always have a view per item in the model.
1012 // (The only exception is if this is in initialization.) 1012 // (The only exception is if this is in initialization.)
1013 if (initialized_) { 1013 if (initialized_) {
1014 size_t num_extension_actions = 0u; 1014 size_t num_extension_actions = 0u;
1015 for (ToolbarActionView* view : toolbar_action_views_) { 1015 for (const BrowserActionView* view : browser_action_views_) {
1016 num_extension_actions += 1016 num_extension_actions +=
1017 crx_file::id_util::IdIsValid(view->view_controller()->GetId()) ? 1017 view->view_controller()->GetType() ==
1018 1 : 0; 1018 ToolbarActionViewController::TYPE_EXTENSION_ACTION ? 1 : 0;
1019 } 1019 }
1020 DCHECK_LE(absolute_model_visible_size, toolbar_action_views_.size()); 1020 DCHECK_LE(absolute_model_visible_size, browser_action_views_.size());
1021 DCHECK_EQ(model_->toolbar_items().size(), toolbar_action_views_.size()); 1021 DCHECK_EQ(model_->toolbar_items().size(), browser_action_views_.size());
1022 } 1022 }
1023 #endif 1023 #endif
1024 1024
1025 // The overflow displays any icons not shown by the main bar. 1025 // The overflow displays any icons not shown by the main bar.
1026 return in_overflow_mode() ? 1026 return in_overflow_mode() ?
1027 model_->toolbar_items().size() - absolute_model_visible_size : 1027 model_->toolbar_items().size() - absolute_model_visible_size :
1028 absolute_model_visible_size; 1028 absolute_model_visible_size;
1029 } 1029 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698