OLD | NEW |
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/extension_util.h" | 10 #include "chrome/browser/extensions/extension_util.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 //////////////////////////////////////////////////////////////////////////////// | 119 //////////////////////////////////////////////////////////////////////////////// |
120 // BrowserActionsContainer | 120 // BrowserActionsContainer |
121 | 121 |
122 // static | 122 // static |
123 bool BrowserActionsContainer::disable_animations_during_testing_ = false; | 123 bool BrowserActionsContainer::disable_animations_during_testing_ = false; |
124 | 124 |
125 BrowserActionsContainer::BrowserActionsContainer( | 125 BrowserActionsContainer::BrowserActionsContainer( |
126 Browser* browser, | 126 Browser* browser, |
127 View* owner_view, | 127 View* owner_view, |
128 BrowserActionsContainer* main_container) | 128 BrowserActionsContainer* main_container) |
129 : profile_(browser->profile()), | 129 : initialized_(false), |
| 130 profile_(browser->profile()), |
130 browser_(browser), | 131 browser_(browser), |
131 owner_view_(owner_view), | 132 owner_view_(owner_view), |
132 main_container_(main_container), | 133 main_container_(main_container), |
133 popup_owner_(NULL), | 134 popup_owner_(NULL), |
134 model_(NULL), | 135 model_(NULL), |
135 container_width_(0), | 136 container_width_(0), |
136 resize_area_(NULL), | 137 resize_area_(NULL), |
137 chevron_(NULL), | 138 chevron_(NULL), |
138 overflow_menu_(NULL), | 139 overflow_menu_(NULL), |
139 suppress_chevron_(false), | 140 suppress_chevron_(false), |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 | 191 |
191 void BrowserActionsContainer::Init() { | 192 void BrowserActionsContainer::Init() { |
192 LoadImages(); | 193 LoadImages(); |
193 | 194 |
194 // We wait to set the container width until now so that the chevron images | 195 // We wait to set the container width until now so that the chevron images |
195 // will be loaded. The width calculation needs to know the chevron size. | 196 // will be loaded. The width calculation needs to know the chevron size. |
196 if (model_ && model_->extensions_initialized()) { | 197 if (model_ && model_->extensions_initialized()) { |
197 container_width_ = GetPreferredWidth(); | 198 container_width_ = GetPreferredWidth(); |
198 SetChevronVisibility(); | 199 SetChevronVisibility(); |
199 } | 200 } |
| 201 |
| 202 initialized_ = true; |
200 } | 203 } |
201 | 204 |
202 BrowserActionView* BrowserActionsContainer::GetViewForExtension( | 205 BrowserActionView* BrowserActionsContainer::GetViewForExtension( |
203 const Extension* extension) { | 206 const Extension* extension) { |
204 for (BrowserActionViews::iterator view = browser_action_views_.begin(); | 207 for (BrowserActionViews::iterator view = browser_action_views_.begin(); |
205 view != browser_action_views_.end(); ++view) { | 208 view != browser_action_views_.end(); ++view) { |
206 if ((*view)->extension() == extension) | 209 if ((*view)->extension() == extension) |
207 return *view; | 210 return *view; |
208 } | 211 } |
209 return NULL; | 212 return NULL; |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 void BrowserActionsContainer::ExecuteExtensionCommand( | 266 void BrowserActionsContainer::ExecuteExtensionCommand( |
264 const extensions::Extension* extension, | 267 const extensions::Extension* extension, |
265 const extensions::Command& command) { | 268 const extensions::Command& command) { |
266 // Global commands are handled by the ExtensionCommandsGlobalRegistry | 269 // Global commands are handled by the ExtensionCommandsGlobalRegistry |
267 // instance. | 270 // instance. |
268 DCHECK(!command.global()); | 271 DCHECK(!command.global()); |
269 extension_keybinding_registry_->ExecuteCommand(extension->id(), | 272 extension_keybinding_registry_->ExecuteCommand(extension->id(), |
270 command.accelerator()); | 273 command.accelerator()); |
271 } | 274 } |
272 | 275 |
| 276 void BrowserActionsContainer::NotifyActionMovedToOverflow() { |
| 277 // When an action is moved to overflow, we shrink the size of the container |
| 278 // by 1. |
| 279 if (!profile_->IsOffTheRecord()) |
| 280 model_->SetVisibleIconCount(model_->GetVisibleIconCount() - 1); |
| 281 Animate(gfx::Tween::EASE_OUT, |
| 282 VisibleBrowserActionsAfterAnimation() - 1); |
| 283 } |
| 284 |
273 bool BrowserActionsContainer::ShownInsideMenu() const { | 285 bool BrowserActionsContainer::ShownInsideMenu() const { |
274 return in_overflow_mode(); | 286 return in_overflow_mode(); |
275 } | 287 } |
276 | 288 |
277 void BrowserActionsContainer::OnBrowserActionViewDragDone() { | 289 void BrowserActionsContainer::OnBrowserActionViewDragDone() { |
278 // We notify here as well as in OnPerformDrop because the dragged view is | 290 ToolbarVisibleCountChanged(); |
279 // removed in OnPerformDrop, so it will never get its OnDragDone() call. | |
280 // TODO(devlin): we should see about fixing that. | |
281 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 291 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
282 observers_, | 292 observers_, |
283 OnBrowserActionDragDone()); | 293 OnBrowserActionDragDone()); |
284 } | 294 } |
285 | 295 |
286 views::View* BrowserActionsContainer::GetOverflowReferenceView() { | 296 views::View* BrowserActionsContainer::GetOverflowReferenceView() { |
287 // With traditional overflow, the reference is the chevron. With the | 297 // With traditional overflow, the reference is the chevron. With the |
288 // redesign, we use the wrench menu instead. | 298 // redesign, we use the wrench menu instead. |
289 return chevron_ ? | 299 return chevron_ ? |
290 chevron_ : | 300 chevron_ : |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 return BrowserActionDragData::AreDropTypesRequired(); | 436 return BrowserActionDragData::AreDropTypesRequired(); |
427 } | 437 } |
428 | 438 |
429 bool BrowserActionsContainer::CanDrop(const OSExchangeData& data) { | 439 bool BrowserActionsContainer::CanDrop(const OSExchangeData& data) { |
430 return BrowserActionDragData::CanDrop(data, profile_); | 440 return BrowserActionDragData::CanDrop(data, profile_); |
431 } | 441 } |
432 | 442 |
433 int BrowserActionsContainer::OnDragUpdated( | 443 int BrowserActionsContainer::OnDragUpdated( |
434 const ui::DropTargetEvent& event) { | 444 const ui::DropTargetEvent& event) { |
435 // First check if we are above the chevron (overflow) menu. | 445 // First check if we are above the chevron (overflow) menu. |
436 if (GetEventHandlerForPoint(event.location()) == chevron_) { | 446 if (chevron_ && GetEventHandlerForPoint(event.location()) == chevron_) { |
437 if (!show_menu_task_factory_.HasWeakPtrs() && !overflow_menu_) | 447 if (!show_menu_task_factory_.HasWeakPtrs() && !overflow_menu_) |
438 StartShowFolderDropMenuTimer(); | 448 StartShowFolderDropMenuTimer(); |
439 return ui::DragDropTypes::DRAG_MOVE; | 449 return ui::DragDropTypes::DRAG_MOVE; |
440 } | 450 } |
441 StopShowFolderDropMenuTimer(); | 451 StopShowFolderDropMenuTimer(); |
442 | 452 |
443 // Figure out where to display the indicator. This is a complex calculation: | 453 // Figure out where to display the indicator. This is a complex calculation: |
444 | 454 |
445 // First, we figure out how much space is to the left of the icon area, so we | 455 // First, we figure out how much space is to the left of the icon area, so we |
446 // can calculate the true offset into the icon area. The easiest way to do | 456 // can calculate the true offset into the icon area. The easiest way to do |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 // correct when dragging an icon to the left. When dragging to the right, | 549 // correct when dragging an icon to the left. When dragging to the right, |
540 // however, we want the icon being dragged to get the index of the item to | 550 // however, we want the icon being dragged to get the index of the item to |
541 // the left of the drop indicator, so we subtract one. | 551 // the left of the drop indicator, so we subtract one. |
542 // * Well, it can also point to the end, but not when dragging to the left. :) | 552 // * Well, it can also point to the end, but not when dragging to the left. :) |
543 if (i > data.index()) | 553 if (i > data.index()) |
544 --i; | 554 --i; |
545 | 555 |
546 if (profile_->IsOffTheRecord()) | 556 if (profile_->IsOffTheRecord()) |
547 i = model_->IncognitoIndexToOriginal(i); | 557 i = model_->IncognitoIndexToOriginal(i); |
548 | 558 |
| 559 // If this was a drag between containers, we will have to adjust the number of |
| 560 // visible icons. |
| 561 bool drag_between_containers = |
| 562 !browser_action_views_[data.index()]->visible(); |
549 model_->MoveExtensionIcon( | 563 model_->MoveExtensionIcon( |
550 browser_action_views_[data.index()]->extension(), i); | 564 browser_action_views_[data.index()]->extension(), i); |
551 | 565 |
| 566 if (drag_between_containers) { |
| 567 // Add one for the dropped icon. |
| 568 size_t new_icon_count = VisibleBrowserActionsAfterAnimation() + 1; |
| 569 |
| 570 // Let the main container update the model. |
| 571 if (in_overflow_mode()) |
| 572 main_container_->NotifyActionMovedToOverflow(); |
| 573 else if (!profile_->IsOffTheRecord()) // This is the main container. |
| 574 model_->SetVisibleIconCount(model_->GetVisibleIconCount() + 1); |
| 575 |
| 576 // The size changed, so we need to animate. |
| 577 Animate(gfx::Tween::EASE_OUT, new_icon_count); |
| 578 } |
| 579 |
552 OnDragExited(); // Perform clean up after dragging. | 580 OnDragExited(); // Perform clean up after dragging. |
553 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | |
554 observers_, | |
555 OnBrowserActionDragDone()); | |
556 return ui::DragDropTypes::DRAG_MOVE; | 581 return ui::DragDropTypes::DRAG_MOVE; |
557 } | 582 } |
558 | 583 |
559 void BrowserActionsContainer::GetAccessibleState( | 584 void BrowserActionsContainer::GetAccessibleState( |
560 ui::AXViewState* state) { | 585 ui::AXViewState* state) { |
561 state->role = ui::AX_ROLE_GROUP; | 586 state->role = ui::AX_ROLE_GROUP; |
562 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS); | 587 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS); |
563 } | 588 } |
564 | 589 |
565 void BrowserActionsContainer::OnMenuButtonClicked(views::View* source, | 590 void BrowserActionsContainer::OnMenuButtonClicked(views::View* source, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
627 | 652 |
628 // Save off the desired number of visible icons. We do this now instead of at | 653 // Save off the desired number of visible icons. We do this now instead of at |
629 // the end of the animation so that even if the browser is shut down while | 654 // the end of the animation so that even if the browser is shut down while |
630 // animating, the right value will be restored on next run. | 655 // animating, the right value will be restored on next run. |
631 // NOTE: Don't save the icon count in incognito because there may be fewer | 656 // NOTE: Don't save the icon count in incognito because there may be fewer |
632 // icons in that mode. The result is that the container in a normal window is | 657 // icons in that mode. The result is that the container in a normal window is |
633 // always at least as wide as in an incognito window. | 658 // always at least as wide as in an incognito window. |
634 int visible_icons = WidthToIconCount(container_width_); | 659 int visible_icons = WidthToIconCount(container_width_); |
635 if (!profile_->IsOffTheRecord()) | 660 if (!profile_->IsOffTheRecord()) |
636 model_->SetVisibleIconCount(visible_icons); | 661 model_->SetVisibleIconCount(visible_icons); |
637 | |
638 Animate(gfx::Tween::EASE_OUT, visible_icons); | 662 Animate(gfx::Tween::EASE_OUT, visible_icons); |
639 } | 663 } |
640 | 664 |
641 void BrowserActionsContainer::AnimationProgressed( | 665 void BrowserActionsContainer::AnimationProgressed( |
642 const gfx::Animation* animation) { | 666 const gfx::Animation* animation) { |
643 DCHECK_EQ(resize_animation_.get(), animation); | 667 DCHECK_EQ(resize_animation_.get(), animation); |
644 resize_amount_ = static_cast<int>(resize_animation_->GetCurrentValue() * | 668 resize_amount_ = static_cast<int>(resize_animation_->GetCurrentValue() * |
645 (container_width_ - animation_target_size_)); | 669 (container_width_ - animation_target_size_)); |
646 OnBrowserActionVisibilityChanged(); | 670 OnBrowserActionVisibilityChanged(); |
647 } | 671 } |
(...skipping 25 matching lines...) Expand all Loading... |
673 BrowserActionsContainer::GetActiveTabPermissionGranter() { | 697 BrowserActionsContainer::GetActiveTabPermissionGranter() { |
674 content::WebContents* web_contents = | 698 content::WebContents* web_contents = |
675 browser_->tab_strip_model()->GetActiveWebContents(); | 699 browser_->tab_strip_model()->GetActiveWebContents(); |
676 if (!web_contents) | 700 if (!web_contents) |
677 return NULL; | 701 return NULL; |
678 return extensions::TabHelper::FromWebContents(web_contents)-> | 702 return extensions::TabHelper::FromWebContents(web_contents)-> |
679 active_tab_permission_granter(); | 703 active_tab_permission_granter(); |
680 } | 704 } |
681 | 705 |
682 size_t BrowserActionsContainer::GetFirstVisibleIconIndex() const { | 706 size_t BrowserActionsContainer::GetFirstVisibleIconIndex() const { |
683 return in_overflow_mode() ? model_->GetVisibleIconCount() : 0; | 707 return in_overflow_mode() ? |
| 708 main_container_->VisibleBrowserActionsAfterAnimation() : 0; |
684 } | 709 } |
685 | 710 |
686 ExtensionPopup* BrowserActionsContainer::TestGetPopup() { | 711 ExtensionPopup* BrowserActionsContainer::TestGetPopup() { |
687 return popup_owner_ ? popup_owner_->view_controller()->popup() : NULL; | 712 return popup_owner_ ? popup_owner_->view_controller()->popup() : NULL; |
688 } | 713 } |
689 | 714 |
690 void BrowserActionsContainer::TestSetIconVisibilityCount(size_t icons) { | 715 void BrowserActionsContainer::TestSetIconVisibilityCount(size_t icons) { |
691 model_->SetVisibleIconCount(icons); | 716 model_->SetVisibleIconCountForTest(icons); |
692 chevron_->SetVisible(icons < browser_action_views_.size()); | |
693 container_width_ = IconCountToWidth(icons, chevron_->visible()); | |
694 Layout(); | |
695 SchedulePaint(); | |
696 } | 717 } |
697 | 718 |
698 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { | 719 void BrowserActionsContainer::OnPaint(gfx::Canvas* canvas) { |
699 // If the views haven't been initialized yet, wait for the next call to | 720 // If the views haven't been initialized yet, wait for the next call to |
700 // paint (one will be triggered by entering highlight mode). | 721 // paint (one will be triggered by entering highlight mode). |
701 if (model_->is_highlighting() && !browser_action_views_.empty()) { | 722 if (model_->is_highlighting() && !browser_action_views_.empty()) { |
702 views::Painter::PaintPainterAt( | 723 views::Painter::PaintPainterAt( |
703 canvas, highlight_painter_.get(), GetLocalBounds()); | 724 canvas, highlight_painter_.get(), GetLocalBounds()); |
704 } | 725 } |
705 | 726 |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 | 975 |
955 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); | 976 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); |
956 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); | 977 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); |
957 } | 978 } |
958 | 979 |
959 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { | 980 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { |
960 SetVisible(!browser_action_views_.empty()); | 981 SetVisible(!browser_action_views_.empty()); |
961 if (owner_view_) { | 982 if (owner_view_) { |
962 owner_view_->Layout(); | 983 owner_view_->Layout(); |
963 owner_view_->SchedulePaint(); | 984 owner_view_->SchedulePaint(); |
| 985 } else { |
| 986 // In overflow mode, we don't have an owner view, but we still have to |
| 987 // update ourselves. |
| 988 Layout(); |
| 989 SchedulePaint(); |
964 } | 990 } |
965 } | 991 } |
966 | 992 |
967 int BrowserActionsContainer::GetPreferredWidth() { | 993 int BrowserActionsContainer::GetPreferredWidth() { |
968 size_t visible_actions = GetIconCount(); | 994 size_t visible_actions = GetIconCount(); |
969 return IconCountToWidth( | 995 return IconCountToWidth( |
970 visible_actions, | 996 visible_actions, |
971 chevron_ && visible_actions < browser_action_views_.size()); | 997 chevron_ && visible_actions < browser_action_views_.size()); |
972 } | 998 } |
973 | 999 |
974 void BrowserActionsContainer::SetChevronVisibility() { | 1000 void BrowserActionsContainer::SetChevronVisibility() { |
975 if (chevron_) | 1001 if (chevron_) { |
976 chevron_->SetVisible(GetIconCount() < browser_action_views_.size()); | 1002 chevron_->SetVisible( |
| 1003 VisibleBrowserActionsAfterAnimation() < browser_action_views_.size()); |
| 1004 } |
977 } | 1005 } |
978 | 1006 |
979 void BrowserActionsContainer::CloseOverflowMenu() { | 1007 void BrowserActionsContainer::CloseOverflowMenu() { |
980 if (overflow_menu_) | 1008 if (overflow_menu_) |
981 overflow_menu_->CancelMenu(); | 1009 overflow_menu_->CancelMenu(); |
982 } | 1010 } |
983 | 1011 |
984 void BrowserActionsContainer::StopShowFolderDropMenuTimer() { | 1012 void BrowserActionsContainer::StopShowFolderDropMenuTimer() { |
985 show_menu_task_factory_.InvalidateWeakPtrs(); | 1013 show_menu_task_factory_.InvalidateWeakPtrs(); |
986 } | 1014 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1019 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; | 1047 (kChevronSpacing + chevron_->GetPreferredSize().width()) : 0; |
1020 return ToolbarView::kStandardSpacing + icons_size + chevron_size + | 1048 return ToolbarView::kStandardSpacing + icons_size + chevron_size + |
1021 ToolbarView::kStandardSpacing; | 1049 ToolbarView::kStandardSpacing; |
1022 } | 1050 } |
1023 | 1051 |
1024 size_t BrowserActionsContainer::WidthToIconCount(int pixels) const { | 1052 size_t BrowserActionsContainer::WidthToIconCount(int pixels) const { |
1025 // Check for widths large enough to show the entire icon set. | 1053 // Check for widths large enough to show the entire icon set. |
1026 if (pixels >= IconCountToWidth(-1, false)) | 1054 if (pixels >= IconCountToWidth(-1, false)) |
1027 return browser_action_views_.size(); | 1055 return browser_action_views_.size(); |
1028 | 1056 |
1029 // We need to reserve space for the resize area, chevron, and the spacing on | 1057 // We reserve space for the padding on either side of the toolbar... |
1030 // either side of the chevron. | 1058 int available_space = pixels - (ToolbarView::kStandardSpacing * 2); |
1031 int available_space = pixels - ToolbarView::kStandardSpacing - | 1059 // ... and, if the chevron is enabled, the chevron. |
1032 (chevron_ ? chevron_->GetPreferredSize().width() : 0) - | 1060 if (chevron_) |
1033 kChevronSpacing - ToolbarView::kStandardSpacing; | 1061 available_space -= (chevron_->GetPreferredSize().width() + kChevronSpacing); |
| 1062 |
1034 // Now we add an extra between-item padding value so the space can be divided | 1063 // Now we add an extra between-item padding value so the space can be divided |
1035 // evenly by (size of icon with padding). | 1064 // evenly by (size of icon with padding). |
1036 return static_cast<size_t>( | 1065 return static_cast<size_t>( |
1037 std::max(0, available_space + kItemSpacing) / IconWidth(true)); | 1066 std::max(0, available_space + kItemSpacing) / IconWidth(true)); |
1038 } | 1067 } |
1039 | 1068 |
1040 int BrowserActionsContainer::MinimumNonemptyWidth() const { | 1069 int BrowserActionsContainer::MinimumNonemptyWidth() const { |
1041 if (!chevron_) | 1070 if (!chevron_) |
1042 return ToolbarView::kStandardSpacing; | 1071 return ToolbarView::kStandardSpacing; |
1043 return (ToolbarView::kStandardSpacing * 2) + kChevronSpacing + | 1072 return (ToolbarView::kStandardSpacing * 2) + kChevronSpacing + |
(...skipping 20 matching lines...) Expand all Loading... |
1064 bool BrowserActionsContainer::ShouldDisplayBrowserAction( | 1093 bool BrowserActionsContainer::ShouldDisplayBrowserAction( |
1065 const Extension* extension) const { | 1094 const Extension* extension) const { |
1066 // Only display incognito-enabled extensions while in incognito mode. | 1095 // Only display incognito-enabled extensions while in incognito mode. |
1067 return !profile_->IsOffTheRecord() || | 1096 return !profile_->IsOffTheRecord() || |
1068 extensions::util::IsIncognitoEnabled(extension->id(), profile_); | 1097 extensions::util::IsIncognitoEnabled(extension->id(), profile_); |
1069 } | 1098 } |
1070 | 1099 |
1071 size_t BrowserActionsContainer::GetIconCount() const { | 1100 size_t BrowserActionsContainer::GetIconCount() const { |
1072 if (!model_) | 1101 if (!model_) |
1073 return 0u; | 1102 return 0u; |
| 1103 |
| 1104 const extensions::ExtensionList& extensions = model_->toolbar_items(); |
| 1105 |
| 1106 // Find the absolute value for the model's visible count. |
| 1107 int model_visible_size = model_->GetVisibleIconCount(); |
| 1108 size_t absolute_model_visible_size = |
| 1109 model_visible_size == -1 ? extensions.size() : model_visible_size; |
| 1110 |
1074 // Find the number of icons which could be displayed. | 1111 // Find the number of icons which could be displayed. |
1075 size_t displayable_icon_count = 0u; | 1112 size_t displayable_icon_count = 0u; |
1076 const extensions::ExtensionList& extensions = model_->toolbar_items(); | 1113 size_t main_displayed = 0u; |
1077 for (extensions::ExtensionList::const_iterator iter = extensions.begin(); | 1114 for (size_t i = 0; i < extensions.size(); ++i) { |
1078 iter != extensions.end(); ++iter) { | 1115 // Should there be an icon for this extension at all? |
1079 displayable_icon_count += ShouldDisplayBrowserAction(iter->get()) ? 1u : 0u; | 1116 if (ShouldDisplayBrowserAction(extensions[i].get())) { |
| 1117 ++displayable_icon_count; |
| 1118 // Should we display it on the main bar? If this is an incognito window, |
| 1119 // icons have the same overflow status they do in a regular window. |
| 1120 main_displayed += i < absolute_model_visible_size ? 1u : 0u; |
| 1121 } |
1080 } | 1122 } |
1081 // Find the absolute value for the model's visible count. | |
1082 int model_size = model_->GetVisibleIconCount(); | |
1083 size_t absolute_model_size = | |
1084 model_size == -1 ? extensions.size() : model_size; | |
1085 | 1123 |
1086 // The main container will try to show |model_size| icons, but reduce if there | 1124 // If this is an existing (initialized) container from an incognito profile, |
1087 // aren't enough displayable icons to do so. | 1125 // we can't trust the model (because the incognito bars don't adjust model |
1088 size_t main_displayed = std::min(displayable_icon_count, absolute_model_size); | 1126 // settings). Instead, we go off what we currently have displayed. |
1089 // The overflow will display the extras, if any. | 1127 if (initialized_ && profile_->IsOffTheRecord()) { |
| 1128 main_displayed = in_overflow_mode() ? |
| 1129 main_container_->VisibleBrowserActionsAfterAnimation() : |
| 1130 VisibleBrowserActionsAfterAnimation(); |
| 1131 } |
| 1132 |
| 1133 // The overflow displays any (displayable) icons not shown by the main bar. |
1090 return in_overflow_mode() ? | 1134 return in_overflow_mode() ? |
1091 displayable_icon_count - main_displayed : main_displayed; | 1135 displayable_icon_count - main_displayed : main_displayed; |
1092 } | 1136 } |
OLD | NEW |