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/tab_helper.h" | 10 #include "chrome/browser/extensions/tab_helper.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
53 // TODO(devlin): We should move this to the model, once it supports component | 53 // TODO(devlin): We should move this to the model, once it supports component |
54 // actions. | 54 // actions. |
55 ScopedVector<ToolbarActionViewController> GetToolbarActions( | 55 ScopedVector<ToolbarActionViewController> GetToolbarActions( |
56 extensions::ExtensionToolbarModel* model, | 56 extensions::ExtensionToolbarModel* model, |
57 Browser* browser) { | 57 Browser* browser) { |
58 ScopedVector<ToolbarActionViewController> actions; | 58 ScopedVector<ToolbarActionViewController> actions; |
59 | 59 |
60 // Extension actions come first. | 60 // Extension actions come first. |
61 extensions::ExtensionActionManager* action_manager = | 61 extensions::ExtensionActionManager* action_manager = |
62 extensions::ExtensionActionManager::Get(browser->profile()); | 62 extensions::ExtensionActionManager::Get(browser->profile()); |
63 const extensions::ExtensionList& toolbar_items = model->toolbar_items(); | 63 const extensions::ExtensionList& toolbar_items = model->GetItemOrderForTab( |
64 browser->tab_strip_model()->GetActiveWebContents()); | |
64 for (const scoped_refptr<const Extension>& extension : toolbar_items) { | 65 for (const scoped_refptr<const Extension>& extension : toolbar_items) { |
65 actions.push_back(new ExtensionActionViewController( | 66 actions.push_back(new ExtensionActionViewController( |
66 extension.get(), | 67 extension.get(), |
67 browser, | 68 browser, |
68 action_manager->GetExtensionAction(*extension))); | 69 action_manager->GetExtensionAction(*extension))); |
69 } | 70 } |
70 | 71 |
71 // Component actions come second. | 72 // Component actions come second. |
72 ScopedVector<ToolbarActionViewController> component_actions = | 73 ScopedVector<ToolbarActionViewController> component_actions = |
73 ComponentToolbarActionsFactory::GetInstance()-> | 74 ComponentToolbarActionsFactory::GetInstance()-> |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 : initialized_(false), | 119 : initialized_(false), |
119 profile_(browser->profile()), | 120 profile_(browser->profile()), |
120 browser_(browser), | 121 browser_(browser), |
121 main_container_(main_container), | 122 main_container_(main_container), |
122 popup_owner_(NULL), | 123 popup_owner_(NULL), |
123 model_(extensions::ExtensionToolbarModel::Get(browser->profile())), | 124 model_(extensions::ExtensionToolbarModel::Get(browser->profile())), |
124 container_width_(0), | 125 container_width_(0), |
125 resize_area_(NULL), | 126 resize_area_(NULL), |
126 chevron_(NULL), | 127 chevron_(NULL), |
127 suppress_chevron_(false), | 128 suppress_chevron_(false), |
129 suppress_animation_(false), | |
130 suppress_layout_(false), | |
128 resize_amount_(0), | 131 resize_amount_(0), |
129 animation_target_size_(0) { | 132 animation_target_size_(0) { |
130 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); | 133 set_id(VIEW_ID_BROWSER_ACTION_TOOLBAR); |
131 if (model_) // |model_| can be NULL in views unittests. | 134 if (model_) // |model_| can be NULL in views unittests. |
132 model_->AddObserver(this); | 135 model_->AddObserver(this); |
133 | 136 |
134 bool overflow_experiment = | 137 bool overflow_experiment = |
135 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled(); | 138 extensions::FeatureSwitch::extension_action_redesign()->IsEnabled(); |
136 DCHECK(!in_overflow_mode() || overflow_experiment); | 139 DCHECK(!in_overflow_mode() || overflow_experiment); |
137 | 140 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 BrowserActionView* BrowserActionsContainer::GetViewForExtension( | 190 BrowserActionView* BrowserActionsContainer::GetViewForExtension( |
188 const Extension* extension) { | 191 const Extension* extension) { |
189 for (BrowserActionView* view : browser_action_views_) { | 192 for (BrowserActionView* view : browser_action_views_) { |
190 if (view->view_controller()->GetId() == extension->id()) | 193 if (view->view_controller()->GetId() == extension->id()) |
191 return view; | 194 return view; |
192 } | 195 } |
193 return NULL; | 196 return NULL; |
194 } | 197 } |
195 | 198 |
196 void BrowserActionsContainer::RefreshBrowserActionViews() { | 199 void BrowserActionsContainer::RefreshBrowserActionViews() { |
197 for (BrowserActionView* view : browser_action_views_) | 200 if (browser_action_views_.empty()) |
198 view->UpdateState(); | 201 return; // Nothing to do. |
202 | |
203 // When we do a bulk-refresh of views (such as when we switch tabs), we don't | |
204 // animate the difference. We only animate when it's a change driven by the | |
205 // action. | |
206 base::AutoReset<bool> animation_resetter(&suppress_animation_, true); | |
207 | |
208 { | |
209 // Don't layout until the end. | |
210 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); | |
211 for (BrowserActionView* view : browser_action_views_) | |
212 view->UpdateState(); | |
213 } | |
214 | |
215 ReorderViews(); // Also triggers a layout. | |
199 } | 216 } |
200 | 217 |
201 void BrowserActionsContainer::CreateBrowserActionViews() { | 218 void BrowserActionsContainer::CreateBrowserActionViews() { |
202 DCHECK(browser_action_views_.empty()); | 219 DCHECK(browser_action_views_.empty()); |
203 if (!model_) | 220 if (!model_) |
204 return; | 221 return; |
205 | 222 |
206 ScopedVector<ToolbarActionViewController> actions = | 223 { |
207 GetToolbarActions(model_, browser_); | 224 // We don't Layout while creating views. Instead, Layout() once at the end. |
208 for (ToolbarActionViewController* controller : actions) { | 225 base::AutoReset<bool> layout_resetter(&suppress_layout_, true); |
209 BrowserActionView* view = | 226 |
210 new BrowserActionView(make_scoped_ptr(controller), browser_, this); | 227 ScopedVector<ToolbarActionViewController> actions = |
211 browser_action_views_.push_back(view); | 228 GetToolbarActions(model_, browser_); |
212 AddChildView(view); | 229 for (ToolbarActionViewController* controller : actions) { |
230 BrowserActionView* view = | |
231 new BrowserActionView(make_scoped_ptr(controller), browser_, this); | |
232 browser_action_views_.push_back(view); | |
233 AddChildView(view); | |
234 } | |
235 actions.weak_clear(); | |
213 } | 236 } |
214 actions.weak_clear(); | 237 |
238 Layout(); | |
239 SchedulePaint(); | |
215 } | 240 } |
216 | 241 |
217 void BrowserActionsContainer::DeleteBrowserActionViews() { | 242 void BrowserActionsContainer::DeleteBrowserActionViews() { |
218 HideActivePopup(); | 243 HideActivePopup(); |
219 STLDeleteElements(&browser_action_views_); | 244 STLDeleteElements(&browser_action_views_); |
220 } | 245 } |
221 | 246 |
222 size_t BrowserActionsContainer::VisibleBrowserActions() const { | 247 size_t BrowserActionsContainer::VisibleBrowserActions() const { |
223 size_t visible_actions = 0; | 248 size_t visible_actions = 0; |
224 for (const BrowserActionView* view : browser_action_views_) { | 249 for (const BrowserActionView* view : browser_action_views_) { |
(...skipping 16 matching lines...) Expand all Loading... | |
241 // Global commands are handled by the ExtensionCommandsGlobalRegistry | 266 // Global commands are handled by the ExtensionCommandsGlobalRegistry |
242 // instance. | 267 // instance. |
243 DCHECK(!command.global()); | 268 DCHECK(!command.global()); |
244 extension_keybinding_registry_->ExecuteCommand(extension->id(), | 269 extension_keybinding_registry_->ExecuteCommand(extension->id(), |
245 command.accelerator()); | 270 command.accelerator()); |
246 } | 271 } |
247 | 272 |
248 void BrowserActionsContainer::NotifyActionMovedToOverflow() { | 273 void BrowserActionsContainer::NotifyActionMovedToOverflow() { |
249 // When an action is moved to overflow, we shrink the size of the container | 274 // When an action is moved to overflow, we shrink the size of the container |
250 // by 1. | 275 // by 1. |
251 int icon_count = model_->GetVisibleIconCount(); | 276 size_t icon_count = model_->visible_icon_count(); |
252 // Since this happens when an icon moves from the main bar to overflow, we | 277 // 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. | 278 // can't possibly have had no visible icons on the main bar. |
254 DCHECK_NE(0, icon_count); | 279 DCHECK_NE(0u, icon_count); |
255 if (icon_count == -1) | |
256 icon_count = browser_action_views_.size(); | |
257 model_->SetVisibleIconCount(icon_count - 1); | 280 model_->SetVisibleIconCount(icon_count - 1); |
258 } | 281 } |
259 | 282 |
260 bool BrowserActionsContainer::ShownInsideMenu() const { | 283 bool BrowserActionsContainer::ShownInsideMenu() const { |
261 return in_overflow_mode(); | 284 return in_overflow_mode(); |
262 } | 285 } |
263 | 286 |
264 void BrowserActionsContainer::OnBrowserActionViewDragDone() { | 287 void BrowserActionsContainer::OnBrowserActionViewDragDone() { |
265 ToolbarVisibleCountChanged(); | 288 ToolbarVisibleCountChanged(); |
266 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, | 289 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
350 icons_per_overflow_menu_row_ = (width - kItemSpacing) / IconWidth(true); | 373 icons_per_overflow_menu_row_ = (width - kItemSpacing) / IconWidth(true); |
351 return GetPreferredSize().height(); | 374 return GetPreferredSize().height(); |
352 } | 375 } |
353 | 376 |
354 gfx::Size BrowserActionsContainer::GetMinimumSize() const { | 377 gfx::Size BrowserActionsContainer::GetMinimumSize() const { |
355 int min_width = std::min(MinimumNonemptyWidth(), IconCountToWidth(-1)); | 378 int min_width = std::min(MinimumNonemptyWidth(), IconCountToWidth(-1)); |
356 return gfx::Size(min_width, IconHeight()); | 379 return gfx::Size(min_width, IconHeight()); |
357 } | 380 } |
358 | 381 |
359 void BrowserActionsContainer::Layout() { | 382 void BrowserActionsContainer::Layout() { |
383 if (suppress_layout_) | |
384 return; | |
385 | |
360 if (browser_action_views_.empty()) { | 386 if (browser_action_views_.empty()) { |
361 SetVisible(false); | 387 SetVisible(false); |
362 return; | 388 return; |
363 } | 389 } |
364 | 390 |
365 SetVisible(true); | 391 SetVisible(true); |
366 if (resize_area_) | 392 if (resize_area_) |
367 resize_area_->SetBounds(0, 0, kItemSpacing, height()); | 393 resize_area_->SetBounds(0, 0, kItemSpacing, height()); |
368 | 394 |
369 // If the icons don't all fit, show the chevron (unless suppressed). | 395 // If the icons don't all fit, show the chevron (unless suppressed). |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 // visible icons. | 569 // visible icons. |
544 bool drag_between_containers = | 570 bool drag_between_containers = |
545 !browser_action_views_[data.index()]->visible(); | 571 !browser_action_views_[data.index()]->visible(); |
546 model_->MoveExtensionIcon(GetIdAt(data.index()), i); | 572 model_->MoveExtensionIcon(GetIdAt(data.index()), i); |
547 | 573 |
548 if (drag_between_containers) { | 574 if (drag_between_containers) { |
549 // Let the main container update the model. | 575 // Let the main container update the model. |
550 if (in_overflow_mode()) | 576 if (in_overflow_mode()) |
551 main_container_->NotifyActionMovedToOverflow(); | 577 main_container_->NotifyActionMovedToOverflow(); |
552 else // This is the main container. | 578 else // This is the main container. |
553 model_->SetVisibleIconCount(model_->GetVisibleIconCount() + 1); | 579 model_->SetVisibleIconCount(model_->visible_icon_count() + 1); |
554 } | 580 } |
555 | 581 |
556 OnDragExited(); // Perform clean up after dragging. | 582 OnDragExited(); // Perform clean up after dragging. |
557 return ui::DragDropTypes::DRAG_MOVE; | 583 return ui::DragDropTypes::DRAG_MOVE; |
558 } | 584 } |
559 | 585 |
560 void BrowserActionsContainer::GetAccessibleState( | 586 void BrowserActionsContainer::GetAccessibleState( |
561 ui::AXViewState* state) { | 587 ui::AXViewState* state) { |
562 state->role = ui::AX_ROLE_GROUP; | 588 state->role = ui::AX_ROLE_GROUP; |
563 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS); | 589 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
774 AddChildViewAt(view, index); | 800 AddChildViewAt(view, index); |
775 | 801 |
776 // If we are still initializing the container, don't bother animating. | 802 // If we are still initializing the container, don't bother animating. |
777 if (!model_->extensions_initialized()) | 803 if (!model_->extensions_initialized()) |
778 return; | 804 return; |
779 | 805 |
780 // If this is just an upgrade, then don't worry about resizing. | 806 // If this is just an upgrade, then don't worry about resizing. |
781 if (!extensions::ExtensionSystem::Get(profile_)->runtime_data()-> | 807 if (!extensions::ExtensionSystem::Get(profile_)->runtime_data()-> |
782 IsBeingUpgraded(extension)) { | 808 IsBeingUpgraded(extension)) { |
783 // We need to resize if either: | 809 // We need to resize if either: |
784 // - The container is set to display all icons (visible count = -1), or | 810 // - The container is set to display all icons, or |
785 // - The container will need to expand to include the chevron. This can | 811 // - The container will need to expand to include the chevron. This can |
786 // happen when the container is set to display <n> icons, where <n> is | 812 // happen when the container is set to display <n> icons, where <n> is |
787 // the number of icons before the new icon. With the new icon, the chevron | 813 // the number of icons before the new icon. With the new icon, the chevron |
788 // will need to be displayed. | 814 // will need to be displayed. |
789 int model_icon_count = model_->GetVisibleIconCount(); | 815 if (model_->all_icons_visible() || |
790 if (model_icon_count == -1 || | 816 (model_->visible_icon_count() < browser_action_views_.size() && |
791 (static_cast<size_t>(model_icon_count) < browser_action_views_.size() && | |
792 (chevron_ && !chevron_->visible()))) { | 817 (chevron_ && !chevron_->visible()))) { |
793 suppress_chevron_ = true; | 818 suppress_chevron_ = true; |
794 Animate(gfx::Tween::LINEAR, GetIconCount()); | 819 Animate(gfx::Tween::LINEAR, GetIconCount()); |
795 return; | 820 return; |
796 } | 821 } |
797 } | 822 } |
798 | 823 |
799 // Otherwise, we don't have to resize, so just redraw the (possibly modified) | 824 // Otherwise, we don't have to resize, so just redraw the (possibly modified) |
800 // visible icon set. | 825 // visible icon set. |
801 OnBrowserActionVisibilityChanged(); | 826 OnBrowserActionVisibilityChanged(); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
873 bool grant_active_tab) { | 898 bool grant_active_tab) { |
874 // Don't override another popup, and only show in the active window. | 899 // Don't override another popup, and only show in the active window. |
875 if (popup_owner_ || !browser_->window()->IsActive()) | 900 if (popup_owner_ || !browser_->window()->IsActive()) |
876 return false; | 901 return false; |
877 | 902 |
878 BrowserActionView* view = GetViewForExtension(extension); | 903 BrowserActionView* view = GetViewForExtension(extension); |
879 return view && view->view_controller()->ExecuteAction(grant_active_tab); | 904 return view && view->view_controller()->ExecuteAction(grant_active_tab); |
880 } | 905 } |
881 | 906 |
882 void BrowserActionsContainer::ToolbarVisibleCountChanged() { | 907 void BrowserActionsContainer::ToolbarVisibleCountChanged() { |
883 if (GetPreferredWidth() != container_width_) | 908 if (GetPreferredWidth() != container_width_) { |
884 Animate(gfx::Tween::EASE_OUT, GetIconCount()); | 909 Animate(gfx::Tween::EASE_OUT, GetIconCount()); |
910 } else if (animation_target_size_ != 0) { | |
911 // It's possible that we're right where we're supposed to be in terms of | |
912 // icon count, but that we're also currently resizing. If this is the case, | |
913 // end the current animation with the current width. | |
914 animation_target_size_ = container_width_; | |
915 resize_animation_->Reset(); | |
916 } | |
885 } | 917 } |
886 | 918 |
887 void BrowserActionsContainer::ToolbarHighlightModeChanged( | 919 void BrowserActionsContainer::ToolbarHighlightModeChanged( |
888 bool is_highlighting) { | 920 bool is_highlighting) { |
889 // The visual highlighting is done in OnPaint(). It's a bit of a pain that | 921 // The visual highlighting is done in OnPaint(). It's a bit of a pain that |
890 // we delete and recreate everything here, but given everything else going on | 922 // we delete and recreate everything here, but given everything else going on |
891 // (the lack of highlight, n more extensions appearing, etc), it's not worth | 923 // (the lack of highlight, n more extensions appearing, etc), it's not worth |
892 // the extra complexity to create and insert only the new extensions. | 924 // the extra complexity to create and insert only the new extensions. |
893 DeleteBrowserActionViews(); | 925 DeleteBrowserActionViews(); |
894 CreateBrowserActionViews(); | 926 CreateBrowserActionViews(); |
895 Animate(gfx::Tween::LINEAR, GetIconCount()); | 927 Animate(gfx::Tween::LINEAR, GetIconCount()); |
896 } | 928 } |
897 | 929 |
930 void BrowserActionsContainer::OnToolbarReorderNecessary( | |
931 content::WebContents* web_contents) { | |
932 if (GetCurrentWebContents() == web_contents) | |
933 ReorderViews(); | |
934 } | |
935 | |
898 Browser* BrowserActionsContainer::GetBrowser() { | 936 Browser* BrowserActionsContainer::GetBrowser() { |
899 return browser_; | 937 return browser_; |
900 } | 938 } |
901 | 939 |
902 void BrowserActionsContainer::LoadImages() { | 940 void BrowserActionsContainer::LoadImages() { |
903 if (in_overflow_mode()) | 941 if (in_overflow_mode()) |
904 return; // Overflow mode has neither a chevron nor highlighting. | 942 return; // Overflow mode has neither a chevron nor highlighting. |
905 | 943 |
906 ui::ThemeProvider* tp = GetThemeProvider(); | 944 ui::ThemeProvider* tp = GetThemeProvider(); |
907 if (tp && chevron_) { | 945 if (tp && chevron_) { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
973 int BrowserActionsContainer::MinimumNonemptyWidth() const { | 1011 int BrowserActionsContainer::MinimumNonemptyWidth() const { |
974 if (!chevron_) | 1012 if (!chevron_) |
975 return ToolbarView::kStandardSpacing; | 1013 return ToolbarView::kStandardSpacing; |
976 return (ToolbarView::kStandardSpacing * 2) + kChevronSpacing + | 1014 return (ToolbarView::kStandardSpacing * 2) + kChevronSpacing + |
977 chevron_->GetPreferredSize().width(); | 1015 chevron_->GetPreferredSize().width(); |
978 } | 1016 } |
979 | 1017 |
980 void BrowserActionsContainer::Animate(gfx::Tween::Type tween_type, | 1018 void BrowserActionsContainer::Animate(gfx::Tween::Type tween_type, |
981 size_t num_visible_icons) { | 1019 size_t num_visible_icons) { |
982 int target_size = IconCountToWidth(num_visible_icons); | 1020 int target_size = IconCountToWidth(num_visible_icons); |
983 if (resize_animation_ && !disable_animations_during_testing_) { | 1021 if (resize_animation_ && !disable_animations_during_testing_ && |
1022 !suppress_animation_) { | |
984 // Animate! We have to set the animation_target_size_ after calling Reset(), | 1023 // Animate! We have to set the animation_target_size_ after calling Reset(), |
985 // because that could end up calling AnimationEnded which clears the value. | 1024 // because that could end up calling AnimationEnded which clears the value. |
986 resize_animation_->Reset(); | 1025 resize_animation_->Reset(); |
987 resize_animation_->SetTweenType(tween_type); | 1026 resize_animation_->SetTweenType(tween_type); |
988 animation_target_size_ = target_size; | 1027 animation_target_size_ = target_size; |
989 resize_animation_->Show(); | 1028 resize_animation_->Show(); |
990 } else { | 1029 } else { |
991 animation_target_size_ = target_size; | 1030 animation_target_size_ = target_size; |
992 AnimationEnded(resize_animation_.get()); | 1031 AnimationEnded(resize_animation_.get()); |
993 } | 1032 } |
994 } | 1033 } |
995 | 1034 |
1035 void BrowserActionsContainer::ReorderViews() { | |
1036 extensions::ExtensionList new_order = | |
1037 model_->GetItemOrderForTab(GetCurrentWebContents()); | |
1038 if (new_order.empty()) | |
1039 return; // Nothing to do. | |
1040 | |
1041 #if defined(DCHECK_IS_ON) | |
Peter Kasting
2014/10/31 19:01:08
I think you want "#if DCHECK_IS_ON", since I think
Devlin
2014/10/31 20:49:30
Ah, right. Done.
| |
1042 // Make sure the lists are in sync. | |
1043 DCHECK_EQ(new_order.size(), browser_action_views_.size()); | |
1044 for (const scoped_refptr<const Extension>& extension : new_order) | |
1045 DCHECK(GetViewForExtension(extension.get())); | |
1046 #endif | |
1047 | |
1048 // Run through the views and compare them to the desired order. If something | |
1049 // is out of place, find the correct spot for it. | |
1050 for (size_t i = 0; i < new_order.size() - 1; ++i) { | |
1051 if (new_order[i]->id() != | |
1052 browser_action_views_[i]->view_controller()->GetId()) { | |
1053 // Find where the correct view is (it's guaranteed to be after our current | |
1054 // index, since everything up to this point is correct). | |
1055 size_t j = i + 1; | |
1056 while (new_order[i]->id() != | |
1057 browser_action_views_[j]->view_controller()->GetId()) | |
1058 ++j; | |
1059 std::swap(browser_action_views_[i], browser_action_views_[j]); | |
1060 } | |
1061 } | |
1062 | |
1063 // Our visible browser actions may have changed - re-Layout() and check the | |
1064 // size. | |
1065 ToolbarVisibleCountChanged(); | |
1066 OnBrowserActionVisibilityChanged(); | |
1067 } | |
1068 | |
996 size_t BrowserActionsContainer::GetIconCount() const { | 1069 size_t BrowserActionsContainer::GetIconCount() const { |
997 if (!model_) | 1070 if (!model_) |
998 return 0u; | 1071 return 0u; |
999 | 1072 |
1000 // Find the absolute value for the model's visible count. | 1073 // Find the absolute value for the model's visible count. |
1001 int model_visible_size = model_->GetVisibleIconCount(); | 1074 size_t model_visible_size = model_->GetVisibleIconCountForTab( |
1002 size_t absolute_model_visible_size = model_visible_size == -1 ? | 1075 browser_->tab_strip_model()->GetActiveWebContents()); |
1003 model_->toolbar_items().size() : model_visible_size; | |
1004 | 1076 |
1005 #if !defined(NDEBUG) | 1077 #if defined(DCHECK_IS_ON) |
1006 // Good time for some sanity checks: We should never try to display more | 1078 // Good time for some sanity checks: We should never try to display more |
1007 // icons than we have, and we should always have a view per item in the model. | 1079 // icons than we have, and we should always have a view per item in the model. |
1008 // (The only exception is if this is in initialization.) | 1080 // (The only exception is if this is in initialization.) |
1009 if (initialized_) { | 1081 if (initialized_ && !suppress_layout_) { |
1010 size_t num_extension_actions = 0u; | 1082 size_t num_extension_actions = 0u; |
1011 for (BrowserActionView* view : browser_action_views_) { | 1083 for (BrowserActionView* view : browser_action_views_) { |
1012 // No component action should ever have a valid extension id, so we can | 1084 // No component action should ever have a valid extension id, so we can |
1013 // use this to check the extension amount. | 1085 // use this to check the extension amount. |
1014 // TODO(devlin): Fix this to just check model size when the model also | 1086 // TODO(devlin): Fix this to just check model size when the model also |
1015 // includes component actions. | 1087 // includes component actions. |
1016 if (crx_file::id_util::IdIsValid(view->view_controller()->GetId())) | 1088 if (crx_file::id_util::IdIsValid(view->view_controller()->GetId())) |
1017 ++num_extension_actions; | 1089 ++num_extension_actions; |
1018 } | 1090 } |
1019 DCHECK_LE(absolute_model_visible_size, num_extension_actions); | 1091 DCHECK_LE(model_visible_size, num_extension_actions); |
1020 DCHECK_EQ(model_->toolbar_items().size(), num_extension_actions); | 1092 DCHECK_EQ(model_->toolbar_items().size(), num_extension_actions); |
1021 } | 1093 } |
1022 #endif | 1094 #endif |
1023 | 1095 |
1024 // The overflow displays any icons not shown by the main bar. | 1096 // The overflow displays any icons not shown by the main bar. |
1025 return in_overflow_mode() ? | 1097 return in_overflow_mode() ? |
1026 model_->toolbar_items().size() - absolute_model_visible_size : | 1098 model_->toolbar_items().size() - model_visible_size : model_visible_size; |
1027 absolute_model_visible_size; | |
1028 } | 1099 } |
OLD | NEW |