| 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/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 HidePopup(); | 177 HidePopup(); |
| 178 STLDeleteElements(&browser_action_views_); | 178 STLDeleteElements(&browser_action_views_); |
| 179 } | 179 } |
| 180 | 180 |
| 181 size_t BrowserActionsContainer::VisibleBrowserActions() const { | 181 size_t BrowserActionsContainer::VisibleBrowserActions() const { |
| 182 size_t visible_actions = 0; | 182 size_t visible_actions = 0; |
| 183 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 183 for (size_t i = 0; i < browser_action_views_.size(); ++i) { |
| 184 if (browser_action_views_[i]->visible()) | 184 if (browser_action_views_[i]->visible()) |
| 185 ++visible_actions; | 185 ++visible_actions; |
| 186 } | 186 } |
| 187 VLOG(4) << "BAC::VisibleBrowserActions() returns " << visible_actions | |
| 188 << " with size=" << browser_action_views_.size(); | |
| 189 return visible_actions; | 187 return visible_actions; |
| 190 } | 188 } |
| 191 | 189 |
| 192 size_t BrowserActionsContainer::VisibleBrowserActionsAfterAnimation() const { | 190 size_t BrowserActionsContainer::VisibleBrowserActionsAfterAnimation() const { |
| 193 if (!animating()) | 191 if (!animating()) |
| 194 return VisibleBrowserActions(); | 192 return VisibleBrowserActions(); |
| 195 | 193 |
| 196 size_t visible_actions = WidthToIconCount(animation_target_size_); | 194 return WidthToIconCount(animation_target_size_); |
| 197 VLOG(4) << "BAC::VisibleBrowserActionsAfterAnimation() returns " | |
| 198 << visible_actions | |
| 199 << " with size=" << browser_action_views_.size(); | |
| 200 return visible_actions; | |
| 201 } | 195 } |
| 202 | 196 |
| 203 void BrowserActionsContainer::ExecuteExtensionCommand( | 197 void BrowserActionsContainer::ExecuteExtensionCommand( |
| 204 const extensions::Extension* extension, | 198 const extensions::Extension* extension, |
| 205 const extensions::Command& command) { | 199 const extensions::Command& command) { |
| 206 // Global commands are handled by the ExtensionCommandsGlobalRegistry | 200 // Global commands are handled by the ExtensionCommandsGlobalRegistry |
| 207 // instance. | 201 // instance. |
| 208 DCHECK(!command.global()); | 202 DCHECK(!command.global()); |
| 209 extension_keybinding_registry_->ExecuteCommand(extension->id(), | 203 extension_keybinding_registry_->ExecuteCommand(extension->id(), |
| 210 command.accelerator()); | 204 command.accelerator()); |
| (...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 int index) { | 672 int index) { |
| 679 #if defined(DEBUG) | 673 #if defined(DEBUG) |
| 680 for (size_t i = 0; i < browser_action_views_.size(); ++i) { | 674 for (size_t i = 0; i < browser_action_views_.size(); ++i) { |
| 681 DCHECK(browser_action_views_[i]->button()->extension() != extension) << | 675 DCHECK(browser_action_views_[i]->button()->extension() != extension) << |
| 682 "Asked to add a browser action view for an extension that already " | 676 "Asked to add a browser action view for an extension that already " |
| 683 "exists."; | 677 "exists."; |
| 684 } | 678 } |
| 685 #endif | 679 #endif |
| 686 CloseOverflowMenu(); | 680 CloseOverflowMenu(); |
| 687 | 681 |
| 688 if (!ShouldDisplayBrowserAction(extension)) { | 682 if (!ShouldDisplayBrowserAction(extension)) |
| 689 VLOG(4) << "Should not display: " << extension->name().c_str(); | |
| 690 return; | 683 return; |
| 691 } | |
| 692 | 684 |
| 693 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); | 685 size_t visible_actions = VisibleBrowserActionsAfterAnimation(); |
| 694 VLOG(4) << "Got back " << visible_actions << " visible."; | |
| 695 | 686 |
| 696 // Add the new browser action to the vector and the view hierarchy. | 687 // Add the new browser action to the vector and the view hierarchy. |
| 697 if (profile_->IsOffTheRecord()) | 688 if (profile_->IsOffTheRecord()) |
| 698 index = model_->OriginalIndexToIncognito(index); | 689 index = model_->OriginalIndexToIncognito(index); |
| 699 BrowserActionView* view = new BrowserActionView(extension, browser_, this); | 690 BrowserActionView* view = new BrowserActionView(extension, browser_, this); |
| 700 browser_action_views_.insert(browser_action_views_.begin() + index, view); | 691 browser_action_views_.insert(browser_action_views_.begin() + index, view); |
| 701 AddChildViewAt(view, index); | 692 AddChildViewAt(view, index); |
| 702 | 693 |
| 703 // If we are still initializing the container, don't bother animating. | 694 // If we are still initializing the container, don't bother animating. |
| 704 if (!model_->extensions_initialized()) { | 695 if (!model_->extensions_initialized()) |
| 705 VLOG(4) << "Still initializing"; | |
| 706 return; | 696 return; |
| 707 } | |
| 708 | 697 |
| 709 // Enlarge the container if it was already at maximum size and we're not in | 698 // Enlarge the container if it was already at maximum size and we're not in |
| 710 // the middle of upgrading. | 699 // the middle of upgrading. |
| 711 if ((model_->GetVisibleIconCount() < 0) && | 700 if ((model_->GetVisibleIconCount() < 0) && |
| 712 !extensions::ExtensionSystem::Get(profile_)->runtime_data()-> | 701 !extensions::ExtensionSystem::Get(profile_)->runtime_data()-> |
| 713 IsBeingUpgraded(extension)) { | 702 IsBeingUpgraded(extension)) { |
| 714 VLOG(4) << "At max, Save and animate"; | |
| 715 suppress_chevron_ = true; | 703 suppress_chevron_ = true; |
| 716 SaveDesiredSizeAndAnimate(gfx::Tween::LINEAR, visible_actions + 1); | 704 SaveDesiredSizeAndAnimate(gfx::Tween::LINEAR, visible_actions + 1); |
| 717 } else { | 705 } else { |
| 718 VLOG(4) << "Not at max"; | |
| 719 // Just redraw the (possibly modified) visible icon set. | 706 // Just redraw the (possibly modified) visible icon set. |
| 720 OnBrowserActionVisibilityChanged(); | 707 OnBrowserActionVisibilityChanged(); |
| 721 } | 708 } |
| 722 } | 709 } |
| 723 | 710 |
| 724 void BrowserActionsContainer::BrowserActionRemoved(const Extension* extension) { | 711 void BrowserActionsContainer::BrowserActionRemoved(const Extension* extension) { |
| 725 CloseOverflowMenu(); | 712 CloseOverflowMenu(); |
| 726 | 713 |
| 727 if (popup_ && popup_->host()->extension() == extension) | 714 if (popup_ && popup_->host()->extension() == extension) |
| 728 HidePopup(); | 715 HidePopup(); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 884 | 871 |
| 885 void BrowserActionsContainer::SaveDesiredSizeAndAnimate( | 872 void BrowserActionsContainer::SaveDesiredSizeAndAnimate( |
| 886 gfx::Tween::Type tween_type, | 873 gfx::Tween::Type tween_type, |
| 887 size_t num_visible_icons) { | 874 size_t num_visible_icons) { |
| 888 // Save off the desired number of visible icons. We do this now instead of at | 875 // Save off the desired number of visible icons. We do this now instead of at |
| 889 // the end of the animation so that even if the browser is shut down while | 876 // the end of the animation so that even if the browser is shut down while |
| 890 // animating, the right value will be restored on next run. | 877 // animating, the right value will be restored on next run. |
| 891 // NOTE: Don't save the icon count in incognito because there may be fewer | 878 // NOTE: Don't save the icon count in incognito because there may be fewer |
| 892 // icons in that mode. The result is that the container in a normal window is | 879 // icons in that mode. The result is that the container in a normal window is |
| 893 // always at least as wide as in an incognito window. | 880 // always at least as wide as in an incognito window. |
| 894 if (!profile_->IsOffTheRecord()) { | 881 if (!profile_->IsOffTheRecord()) |
| 895 model_->SetVisibleIconCount(num_visible_icons); | 882 model_->SetVisibleIconCount(num_visible_icons); |
| 896 VLOG(4) << "Setting visible count: " << num_visible_icons; | |
| 897 } else { | |
| 898 VLOG(4) << "|Skipping| setting visible count: " << num_visible_icons; | |
| 899 } | |
| 900 int target_size = IconCountToWidth(num_visible_icons, | 883 int target_size = IconCountToWidth(num_visible_icons, |
| 901 num_visible_icons < browser_action_views_.size()); | 884 num_visible_icons < browser_action_views_.size()); |
| 902 if (!disable_animations_during_testing_) { | 885 if (!disable_animations_during_testing_) { |
| 903 // Animate! We have to set the animation_target_size_ after calling Reset(), | 886 // Animate! We have to set the animation_target_size_ after calling Reset(), |
| 904 // because that could end up calling AnimationEnded which clears the value. | 887 // because that could end up calling AnimationEnded which clears the value. |
| 905 resize_animation_->Reset(); | 888 resize_animation_->Reset(); |
| 906 resize_animation_->SetTweenType(tween_type); | 889 resize_animation_->SetTweenType(tween_type); |
| 907 animation_target_size_ = target_size; | 890 animation_target_size_ = target_size; |
| 908 resize_animation_->Show(); | 891 resize_animation_->Show(); |
| 909 } else { | 892 } else { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 views::BubbleBorder::TOP_RIGHT, | 932 views::BubbleBorder::TOP_RIGHT, |
| 950 show_action); | 933 show_action); |
| 951 popup_->GetWidget()->AddObserver(this); | 934 popup_->GetWidget()->AddObserver(this); |
| 952 popup_button_ = button; | 935 popup_button_ = button; |
| 953 | 936 |
| 954 // Only set button as pushed if it was triggered by a user click. | 937 // Only set button as pushed if it was triggered by a user click. |
| 955 if (should_grant) | 938 if (should_grant) |
| 956 popup_button_->SetButtonPushed(); | 939 popup_button_->SetButtonPushed(); |
| 957 return true; | 940 return true; |
| 958 } | 941 } |
| OLD | NEW |