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

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

Issue 539543002: Fix two bugs in the extension actions toolbar (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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/extension_util.h" 10 #include "chrome/browser/extensions/extension_util.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 StopShowFolderDropMenuTimer(); 185 StopShowFolderDropMenuTimer();
186 HideActivePopup(); 186 HideActivePopup();
187 DeleteBrowserActionViews(); 187 DeleteBrowserActionViews();
188 } 188 }
189 189
190 void BrowserActionsContainer::Init() { 190 void BrowserActionsContainer::Init() {
191 LoadImages(); 191 LoadImages();
192 192
193 // We wait to set the container width until now so that the chevron images 193 // We wait to set the container width until now so that the chevron images
194 // will be loaded. The width calculation needs to know the chevron size. 194 // will be loaded. The width calculation needs to know the chevron size.
195 if (model_ && model_->extensions_initialized()) 195 if (model_ && model_->extensions_initialized()) {
196 SetContainerWidth(); 196 container_width_ = GetPreferredWidth();
197 SetChevronVisibility();
198 }
197 } 199 }
198 200
199 BrowserActionView* BrowserActionsContainer::GetViewForExtension( 201 BrowserActionView* BrowserActionsContainer::GetViewForExtension(
200 const Extension* extension) { 202 const Extension* extension) {
201 for (BrowserActionViews::iterator view = browser_action_views_.begin(); 203 for (BrowserActionViews::iterator view = browser_action_views_.begin();
202 view != browser_action_views_.end(); ++view) { 204 view != browser_action_views_.end(); ++view) {
203 if ((*view)->extension() == extension) 205 if ((*view)->extension() == extension)
204 return *view; 206 return *view;
205 } 207 }
206 return NULL; 208 return NULL;
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
633 resize_amount_ = static_cast<int>(resize_animation_->GetCurrentValue() * 635 resize_amount_ = static_cast<int>(resize_animation_->GetCurrentValue() *
634 (container_width_ - animation_target_size_)); 636 (container_width_ - animation_target_size_));
635 OnBrowserActionVisibilityChanged(); 637 OnBrowserActionVisibilityChanged();
636 } 638 }
637 639
638 void BrowserActionsContainer::AnimationEnded(const gfx::Animation* animation) { 640 void BrowserActionsContainer::AnimationEnded(const gfx::Animation* animation) {
639 container_width_ = animation_target_size_; 641 container_width_ = animation_target_size_;
640 animation_target_size_ = 0; 642 animation_target_size_ = 0;
641 resize_amount_ = 0; 643 resize_amount_ = 0;
642 suppress_chevron_ = false; 644 suppress_chevron_ = false;
645 SetChevronVisibility();
643 OnBrowserActionVisibilityChanged(); 646 OnBrowserActionVisibilityChanged();
644 647
645 FOR_EACH_OBSERVER(BrowserActionsContainerObserver, 648 FOR_EACH_OBSERVER(BrowserActionsContainerObserver,
646 observers_, 649 observers_,
647 OnBrowserActionsContainerAnimationEnded()); 650 OnBrowserActionsContainerAnimationEnded());
648 } 651 }
649 652
650 void BrowserActionsContainer::NotifyMenuDeleted( 653 void BrowserActionsContainer::NotifyMenuDeleted(
651 BrowserActionOverflowMenuController* controller) { 654 BrowserActionOverflowMenuController* controller) {
652 DCHECK_EQ(overflow_menu_, controller); 655 DCHECK_EQ(overflow_menu_, controller);
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
796 GetExtensionAction(*extension), 799 GetExtensionAction(*extension),
797 browser_, 800 browser_,
798 this); 801 this);
799 browser_action_views_.insert(browser_action_views_.begin() + index, view); 802 browser_action_views_.insert(browser_action_views_.begin() + index, view);
800 AddChildViewAt(view, index); 803 AddChildViewAt(view, index);
801 804
802 // If we are still initializing the container, don't bother animating. 805 // If we are still initializing the container, don't bother animating.
803 if (!model_->extensions_initialized()) 806 if (!model_->extensions_initialized())
804 return; 807 return;
805 808
806 // Enlarge the container if it was already at maximum size and we're not in 809 // If this is just an upgrade, then don't worry about resizing.
807 // the middle of upgrading. 810 if (!extensions::ExtensionSystem::Get(profile_)->runtime_data()->
808 if ((model_->GetVisibleIconCount() < 0) &&
809 !extensions::ExtensionSystem::Get(profile_)->runtime_data()->
810 IsBeingUpgraded(extension)) { 811 IsBeingUpgraded(extension)) {
811 suppress_chevron_ = true; 812 // We need to resize if either:
812 Animate(gfx::Tween::LINEAR, browser_action_views_.size()); 813 // - The container is set to display all icons (visible count = -1), or
813 } else { 814 // - The container will need to expand to include the chevron. This can
814 // Just redraw the (possibly modified) visible icon set. 815 // happen when the container is set to display <n> icons, where <n> is
815 OnBrowserActionVisibilityChanged(); 816 // the number of icons before the new icon. With the new icon, the chevron
817 // will need to be displayed.
818 int model_icon_count = model_->GetVisibleIconCount();
819 if (model_icon_count == -1 ||
820 (static_cast<size_t>(model_icon_count) < browser_action_views_.size() &&
821 (chevron_ && !chevron_->visible()))) {
822 suppress_chevron_ = true;
823 Animate(gfx::Tween::LINEAR, GetIconCount());
824 return;
825 }
816 } 826 }
827
828 // Otherwise, we don't have to resize, so just redraw the (possibly modified)
829 // visible icon set.
830 OnBrowserActionVisibilityChanged();
817 } 831 }
818 832
819 void BrowserActionsContainer::ToolbarExtensionRemoved( 833 void BrowserActionsContainer::ToolbarExtensionRemoved(
820 const Extension* extension) { 834 const Extension* extension) {
821 CloseOverflowMenu(); 835 CloseOverflowMenu();
822 836
823 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); 837 size_t visible_actions = VisibleBrowserActionsAfterAnimation();
824 for (BrowserActionViews::iterator i(browser_action_views_.begin()); 838 for (BrowserActionViews::iterator i(browser_action_views_.begin());
825 i != browser_action_views_.end(); ++i) { 839 i != browser_action_views_.end(); ++i) {
826 if ((*i)->extension() == extension) { 840 if ((*i)->extension() == extension) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 // Don't override another popup, and only show in the active window. 909 // Don't override another popup, and only show in the active window.
896 if (popup_owner_ || !browser_->window()->IsActive()) 910 if (popup_owner_ || !browser_->window()->IsActive())
897 return false; 911 return false;
898 912
899 BrowserActionView* view = GetViewForExtension(extension); 913 BrowserActionView* view = GetViewForExtension(extension);
900 return view && view->view_controller()->ExecuteAction(ExtensionPopup::SHOW, 914 return view && view->view_controller()->ExecuteAction(ExtensionPopup::SHOW,
901 grant_active_tab); 915 grant_active_tab);
902 } 916 }
903 917
904 void BrowserActionsContainer::ToolbarVisibleCountChanged() { 918 void BrowserActionsContainer::ToolbarVisibleCountChanged() {
905 int old_container_width = container_width_; 919 if (GetPreferredWidth() != container_width_)
906 SetContainerWidth();
907 if (old_container_width != container_width_)
908 Animate(gfx::Tween::EASE_OUT, GetIconCount()); 920 Animate(gfx::Tween::EASE_OUT, GetIconCount());
909 } 921 }
910 922
911 void BrowserActionsContainer::ToolbarHighlightModeChanged( 923 void BrowserActionsContainer::ToolbarHighlightModeChanged(
912 bool is_highlighting) { 924 bool is_highlighting) {
913 // The visual highlighting is done in OnPaint(). It's a bit of a pain that 925 // The visual highlighting is done in OnPaint(). It's a bit of a pain that
914 // we delete and recreate everything here, but given everything else going on 926 // we delete and recreate everything here, but given everything else going on
915 // (the lack of highlight, n more extensions appearing, etc), it's not worth 927 // (the lack of highlight, n more extensions appearing, etc), it's not worth
916 // the extra complexity to create and insert only the new extensions. 928 // the extra complexity to create and insert only the new extensions.
917 DeleteBrowserActionViews(); 929 DeleteBrowserActionViews();
918 CreateBrowserActionViews(); 930 CreateBrowserActionViews();
919 Animate(gfx::Tween::LINEAR, browser_action_views_.size()); 931 Animate(gfx::Tween::LINEAR, GetIconCount());
920 } 932 }
921 933
922 Browser* BrowserActionsContainer::GetBrowser() { 934 Browser* BrowserActionsContainer::GetBrowser() {
923 return browser_; 935 return browser_;
924 } 936 }
925 937
926 void BrowserActionsContainer::LoadImages() { 938 void BrowserActionsContainer::LoadImages() {
927 ui::ThemeProvider* tp = GetThemeProvider(); 939 ui::ThemeProvider* tp = GetThemeProvider();
928 if (!tp || !chevron_) 940 if (!tp || !chevron_)
929 return; 941 return;
930 942
931 chevron_->SetImage(views::Button::STATE_NORMAL, 943 chevron_->SetImage(views::Button::STATE_NORMAL,
932 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW)); 944 *tp->GetImageSkiaNamed(IDR_BROWSER_ACTIONS_OVERFLOW));
933 945
934 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT); 946 const int kImages[] = IMAGE_GRID(IDR_DEVELOPER_MODE_HIGHLIGHT);
935 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages)); 947 highlight_painter_.reset(views::Painter::CreateImageGridPainter(kImages));
936 } 948 }
937 949
938 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() { 950 void BrowserActionsContainer::OnBrowserActionVisibilityChanged() {
939 SetVisible(!browser_action_views_.empty()); 951 SetVisible(!browser_action_views_.empty());
940 if (owner_view_) { 952 if (owner_view_) {
941 owner_view_->Layout(); 953 owner_view_->Layout();
942 owner_view_->SchedulePaint(); 954 owner_view_->SchedulePaint();
943 } 955 }
944 } 956 }
945 957
946 void BrowserActionsContainer::SetContainerWidth() { 958 int BrowserActionsContainer::GetPreferredWidth() {
947 int visible_actions = GetIconCount(); 959 size_t visible_actions = GetIconCount();
948 if (chevron_) { 960 return IconCountToWidth(
949 chevron_->SetVisible( 961 visible_actions,
950 static_cast<size_t>(visible_actions) < model_->toolbar_items().size()); 962 chevron_ && visible_actions < browser_action_views_.size());
951 } 963 }
952 container_width_ = 964
953 IconCountToWidth(visible_actions, chevron_ && chevron_->visible()); 965 void BrowserActionsContainer::SetChevronVisibility() {
966 if (chevron_)
967 chevron_->SetVisible(GetIconCount() < browser_action_views_.size());
954 } 968 }
955 969
956 void BrowserActionsContainer::CloseOverflowMenu() { 970 void BrowserActionsContainer::CloseOverflowMenu() {
957 if (overflow_menu_) 971 if (overflow_menu_)
958 overflow_menu_->CancelMenu(); 972 overflow_menu_->CancelMenu();
959 } 973 }
960 974
961 void BrowserActionsContainer::StopShowFolderDropMenuTimer() { 975 void BrowserActionsContainer::StopShowFolderDropMenuTimer() {
962 show_menu_task_factory_.InvalidateWeakPtrs(); 976 show_menu_task_factory_.InvalidateWeakPtrs();
963 } 977 }
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 size_t absolute_model_size = 1074 size_t absolute_model_size =
1061 model_size == -1 ? extensions.size() : model_size; 1075 model_size == -1 ? extensions.size() : model_size;
1062 1076
1063 // The main container will try to show |model_size| icons, but reduce if there 1077 // The main container will try to show |model_size| icons, but reduce if there
1064 // aren't enough displayable icons to do so. 1078 // aren't enough displayable icons to do so.
1065 size_t main_displayed = std::min(displayable_icon_count, absolute_model_size); 1079 size_t main_displayed = std::min(displayable_icon_count, absolute_model_size);
1066 // The overflow will display the extras, if any. 1080 // The overflow will display the extras, if any.
1067 return in_overflow_mode() ? 1081 return in_overflow_mode() ?
1068 displayable_icon_count - main_displayed : main_displayed; 1082 displayable_icon_count - main_displayed : main_displayed;
1069 } 1083 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698