OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/views/browser_actions_container.h" | 5 #include "chrome/browser/views/browser_actions_container.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "app/slide_animation.h" | 9 #include "app/slide_animation.h" |
10 #include "base/stl_util-inl.h" | 10 #include "base/stl_util-inl.h" |
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
945 // Some icons were hidden, don't increase the size of the container. | 945 // Some icons were hidden, don't increase the size of the container. |
946 OnBrowserActionVisibilityChanged(); | 946 OnBrowserActionVisibilityChanged(); |
947 } else { | 947 } else { |
948 // Container was at max, increase the size of it by one icon. | 948 // Container was at max, increase the size of it by one icon. |
949 int target_size = IconCountToWidth(visible_actions + 1); | 949 int target_size = IconCountToWidth(visible_actions + 1); |
950 | 950 |
951 // We don't want the chevron to appear while we animate. See documentation | 951 // We don't want the chevron to appear while we animate. See documentation |
952 // in the header for why we do this. | 952 // in the header for why we do this. |
953 suppress_chevron_ = !chevron_->IsVisible(); | 953 suppress_chevron_ = !chevron_->IsVisible(); |
954 | 954 |
955 Animate(SlideAnimation::NONE, target_size); | 955 Animate(Tween::LINEAR, target_size); |
956 } | 956 } |
957 } | 957 } |
958 | 958 |
959 void BrowserActionsContainer::BrowserActionRemoved(Extension* extension) { | 959 void BrowserActionsContainer::BrowserActionRemoved(Extension* extension) { |
960 CloseOverflowMenu(); | 960 CloseOverflowMenu(); |
961 | 961 |
962 if (popup_ && popup_->host()->extension() == extension) | 962 if (popup_ && popup_->host()->extension() == extension) |
963 HidePopup(); | 963 HidePopup(); |
964 | 964 |
965 // Before we change anything, determine the number of visible browser | 965 // Before we change anything, determine the number of visible browser |
(...skipping 17 matching lines...) Expand all Loading... |
983 // header. | 983 // header. |
984 | 984 |
985 // Calculate the target size we'll animate to (end state). This might be | 985 // Calculate the target size we'll animate to (end state). This might be |
986 // the same size (if the icon we are removing is in the overflow bucket | 986 // the same size (if the icon we are removing is in the overflow bucket |
987 // and there are other icons there). We don't decrement visible_actions | 987 // and there are other icons there). We don't decrement visible_actions |
988 // because we want the container to stay the same size (clamping will take | 988 // because we want the container to stay the same size (clamping will take |
989 // care of shrinking the container if there aren't enough icons to show). | 989 // care of shrinking the container if there aren't enough icons to show). |
990 int target_size = | 990 int target_size = |
991 ClampToNearestIconCount(IconCountToWidth(visible_actions), true); | 991 ClampToNearestIconCount(IconCountToWidth(visible_actions), true); |
992 | 992 |
993 Animate(SlideAnimation::EASE_OUT, target_size); | 993 Animate(Tween::EASE_OUT, target_size); |
994 return; | 994 return; |
995 } | 995 } |
996 } | 996 } |
997 } | 997 } |
998 | 998 |
999 void BrowserActionsContainer::BrowserActionMoved(Extension* extension, | 999 void BrowserActionsContainer::BrowserActionMoved(Extension* extension, |
1000 int index) { | 1000 int index) { |
1001 if (!ShouldDisplayBrowserAction(extension)) | 1001 if (!ShouldDisplayBrowserAction(extension)) |
1002 return; | 1002 return; |
1003 | 1003 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1041 | 1041 |
1042 int icon_width = kButtonSize + kBrowserActionButtonPadding; | 1042 int icon_width = kButtonSize + kBrowserActionButtonPadding; |
1043 | 1043 |
1044 return WidthOfNonIconArea() + (icons * icon_width); | 1044 return WidthOfNonIconArea() + (icons * icon_width); |
1045 } | 1045 } |
1046 | 1046 |
1047 int BrowserActionsContainer::ContainerMinSize() const { | 1047 int BrowserActionsContainer::ContainerMinSize() const { |
1048 return resize_gripper_->width() + chevron_->width() + kChevronRightMargin; | 1048 return resize_gripper_->width() + chevron_->width() + kChevronRightMargin; |
1049 } | 1049 } |
1050 | 1050 |
1051 void BrowserActionsContainer::Animate( | 1051 void BrowserActionsContainer::Animate(Tween::Type tween_type, int target_size) { |
1052 SlideAnimation::TweenType tween_type, int target_size) { | |
1053 if (!disable_animations_during_testing_) { | 1052 if (!disable_animations_during_testing_) { |
1054 // Animate! We have to set the animation_target_size_ after calling Reset(), | 1053 // Animate! We have to set the animation_target_size_ after calling Reset(), |
1055 // because that could end up calling AnimationEnded which clears the value. | 1054 // because that could end up calling AnimationEnded which clears the value. |
1056 resize_animation_->Reset(); | 1055 resize_animation_->Reset(); |
1057 resize_animation_->SetTweenType(tween_type); | 1056 resize_animation_->SetTweenType(tween_type); |
1058 animation_target_size_ = target_size; | 1057 animation_target_size_ = target_size; |
1059 resize_animation_->Show(); | 1058 resize_animation_->Show(); |
1060 } else { | 1059 } else { |
1061 animation_target_size_ = target_size; | 1060 animation_target_size_ = target_size; |
1062 AnimationEnded(resize_animation_.get()); | 1061 AnimationEnded(resize_animation_.get()); |
(...skipping 23 matching lines...) Expand all Loading... |
1086 int new_width = std::max(0, container_size_.width() - resize_amount); | 1085 int new_width = std::max(0, container_size_.width() - resize_amount); |
1087 int max_width = ClampToNearestIconCount(-1, false); | 1086 int max_width = ClampToNearestIconCount(-1, false); |
1088 new_width = std::min(new_width, max_width); | 1087 new_width = std::min(new_width, max_width); |
1089 | 1088 |
1090 // Up until now we've only been modifying the resize_amount, but now it is | 1089 // Up until now we've only been modifying the resize_amount, but now it is |
1091 // time to set the container size to the size we have resized to, but then | 1090 // time to set the container size to the size we have resized to, but then |
1092 // animate to the nearest icon count size (or down to min size if no icon). | 1091 // animate to the nearest icon count size (or down to min size if no icon). |
1093 container_size_.set_width(new_width); | 1092 container_size_.set_width(new_width); |
1094 animation_target_size_ = ClampToNearestIconCount(new_width, true); | 1093 animation_target_size_ = ClampToNearestIconCount(new_width, true); |
1095 resize_animation_->Reset(); | 1094 resize_animation_->Reset(); |
1096 resize_animation_->SetTweenType(SlideAnimation::EASE_OUT); | 1095 resize_animation_->SetTweenType(Tween::EASE_OUT); |
1097 resize_animation_->Show(); | 1096 resize_animation_->Show(); |
1098 } | 1097 } |
1099 } | 1098 } |
1100 | 1099 |
1101 void BrowserActionsContainer::AnimationProgressed(const Animation* animation) { | 1100 void BrowserActionsContainer::AnimationProgressed(const Animation* animation) { |
1102 DCHECK(animation == resize_animation_.get()); | 1101 DCHECK(animation == resize_animation_.get()); |
1103 | 1102 |
1104 double e = resize_animation_->GetCurrentValue(); | 1103 double e = resize_animation_->GetCurrentValue(); |
1105 int difference = container_size_.width() - animation_target_size_; | 1104 int difference = container_size_.width() - animation_target_size_; |
1106 | 1105 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1141 popup_ = NULL; | 1140 popup_ = NULL; |
1142 popup_button_->SetButtonNotPushed(); | 1141 popup_button_->SetButtonNotPushed(); |
1143 popup_button_ = NULL; | 1142 popup_button_ = NULL; |
1144 } | 1143 } |
1145 | 1144 |
1146 bool BrowserActionsContainer::ShouldDisplayBrowserAction(Extension* extension) { | 1145 bool BrowserActionsContainer::ShouldDisplayBrowserAction(Extension* extension) { |
1147 // Only display incognito-enabled extensions while in incognito mode. | 1146 // Only display incognito-enabled extensions while in incognito mode. |
1148 return (!profile_->IsOffTheRecord() || | 1147 return (!profile_->IsOffTheRecord() || |
1149 profile_->GetExtensionsService()->IsIncognitoEnabled(extension)); | 1148 profile_->GetExtensionsService()->IsIncognitoEnabled(extension)); |
1150 } | 1149 } |
OLD | NEW |