| 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" | |
| 10 #include "base/stl_util-inl.h" | 9 #include "base/stl_util-inl.h" |
| 11 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 12 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 13 #include "chrome/browser/browser_window.h" | 12 #include "chrome/browser/browser_window.h" |
| 14 #include "chrome/browser/extensions/extension_browser_event_router.h" | 13 #include "chrome/browser/extensions/extension_browser_event_router.h" |
| 15 #include "chrome/browser/extensions/extension_host.h" | 14 #include "chrome/browser/extensions/extension_host.h" |
| 16 #include "chrome/browser/extensions/extension_tabs_module.h" | 15 #include "chrome/browser/extensions/extension_tabs_module.h" |
| 17 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
| 18 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
| 19 #include "chrome/browser/renderer_host/render_view_host.h" | 18 #include "chrome/browser/renderer_host/render_view_host.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 31 #include "chrome/common/notification_source.h" | 30 #include "chrome/common/notification_source.h" |
| 32 #include "chrome/common/notification_type.h" | 31 #include "chrome/common/notification_type.h" |
| 33 #include "chrome/common/pref_names.h" | 32 #include "chrome/common/pref_names.h" |
| 34 #include "gfx/canvas.h" | 33 #include "gfx/canvas.h" |
| 35 #include "gfx/canvas_skia.h" | 34 #include "gfx/canvas_skia.h" |
| 36 #include "grit/app_resources.h" | 35 #include "grit/app_resources.h" |
| 37 #include "grit/generated_resources.h" | 36 #include "grit/generated_resources.h" |
| 38 #include "third_party/skia/include/core/SkBitmap.h" | 37 #include "third_party/skia/include/core/SkBitmap.h" |
| 39 #include "third_party/skia/include/core/SkTypeface.h" | 38 #include "third_party/skia/include/core/SkTypeface.h" |
| 40 #include "third_party/skia/include/effects/SkGradientShader.h" | 39 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 40 #include "ui/base/animation/slide_animation.h" |
| 41 #include "views/controls/button/menu_button.h" | 41 #include "views/controls/button/menu_button.h" |
| 42 #include "views/controls/button/text_button.h" | 42 #include "views/controls/button/text_button.h" |
| 43 #include "views/controls/menu/menu_2.h" | 43 #include "views/controls/menu/menu_2.h" |
| 44 #include "views/drag_utils.h" | 44 #include "views/drag_utils.h" |
| 45 #include "views/window/window.h" | 45 #include "views/window/window.h" |
| 46 | 46 |
| 47 #include "grit/theme_resources.h" | 47 #include "grit/theme_resources.h" |
| 48 | 48 |
| 49 // Horizontal spacing between most items in the container, as well as after the | 49 // Horizontal spacing between most items in the container, as well as after the |
| 50 // last item or chevron (if visible). | 50 // last item or chevron (if visible). |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 359 drop_indicator_position_(-1), | 359 drop_indicator_position_(-1), |
| 360 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), | 360 ALLOW_THIS_IN_INITIALIZER_LIST(task_factory_(this)), |
| 361 ALLOW_THIS_IN_INITIALIZER_LIST(show_menu_task_factory_(this)) { | 361 ALLOW_THIS_IN_INITIALIZER_LIST(show_menu_task_factory_(this)) { |
| 362 SetID(VIEW_ID_BROWSER_ACTION_TOOLBAR); | 362 SetID(VIEW_ID_BROWSER_ACTION_TOOLBAR); |
| 363 | 363 |
| 364 if (profile_->GetExtensionService()) { | 364 if (profile_->GetExtensionService()) { |
| 365 model_ = profile_->GetExtensionService()->toolbar_model(); | 365 model_ = profile_->GetExtensionService()->toolbar_model(); |
| 366 model_->AddObserver(this); | 366 model_->AddObserver(this); |
| 367 } | 367 } |
| 368 | 368 |
| 369 resize_animation_.reset(new SlideAnimation(this)); | 369 resize_animation_.reset(new ui::SlideAnimation(this)); |
| 370 resize_area_ = new views::ResizeArea(this); | 370 resize_area_ = new views::ResizeArea(this); |
| 371 resize_area_->SetAccessibleName( | 371 resize_area_->SetAccessibleName( |
| 372 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_SEPARATOR))); | 372 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_SEPARATOR))); |
| 373 AddChildView(resize_area_); | 373 AddChildView(resize_area_); |
| 374 | 374 |
| 375 chevron_ = new views::MenuButton(NULL, std::wstring(), this, false); | 375 chevron_ = new views::MenuButton(NULL, std::wstring(), this, false); |
| 376 chevron_->set_border(NULL); | 376 chevron_->set_border(NULL); |
| 377 chevron_->EnableCanvasFlippingForRTLUI(true); | 377 chevron_->EnableCanvasFlippingForRTLUI(true); |
| 378 chevron_->SetAccessibleName( | 378 chevron_->SetAccessibleName( |
| 379 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON))); | 379 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON))); |
| (...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 OnBrowserActionVisibilityChanged(); | 792 OnBrowserActionVisibilityChanged(); |
| 793 return; | 793 return; |
| 794 } | 794 } |
| 795 | 795 |
| 796 // Up until now we've only been modifying the resize_amount, but now it is | 796 // Up until now we've only been modifying the resize_amount, but now it is |
| 797 // time to set the container size to the size we have resized to, and then | 797 // time to set the container size to the size we have resized to, and then |
| 798 // animate to the nearest icon count size if necessary (which may be 0). | 798 // animate to the nearest icon count size if necessary (which may be 0). |
| 799 int max_width = IconCountToWidth(-1, false); | 799 int max_width = IconCountToWidth(-1, false); |
| 800 container_width_ = | 800 container_width_ = |
| 801 std::min(std::max(0, container_width_ - resize_amount), max_width); | 801 std::min(std::max(0, container_width_ - resize_amount), max_width); |
| 802 SaveDesiredSizeAndAnimate(Tween::EASE_OUT, | 802 SaveDesiredSizeAndAnimate(ui::Tween::EASE_OUT, |
| 803 WidthToIconCount(container_width_)); | 803 WidthToIconCount(container_width_)); |
| 804 } | 804 } |
| 805 | 805 |
| 806 void BrowserActionsContainer::AnimationProgressed(const Animation* animation) { | 806 void BrowserActionsContainer::AnimationProgressed( |
| 807 const ui::Animation* animation) { |
| 807 DCHECK_EQ(resize_animation_.get(), animation); | 808 DCHECK_EQ(resize_animation_.get(), animation); |
| 808 resize_amount_ = static_cast<int>(resize_animation_->GetCurrentValue() * | 809 resize_amount_ = static_cast<int>(resize_animation_->GetCurrentValue() * |
| 809 (container_width_ - animation_target_size_)); | 810 (container_width_ - animation_target_size_)); |
| 810 OnBrowserActionVisibilityChanged(); | 811 OnBrowserActionVisibilityChanged(); |
| 811 } | 812 } |
| 812 | 813 |
| 813 void BrowserActionsContainer::AnimationEnded(const Animation* animation) { | 814 void BrowserActionsContainer::AnimationEnded(const ui::Animation* animation) { |
| 814 container_width_ = animation_target_size_; | 815 container_width_ = animation_target_size_; |
| 815 animation_target_size_ = 0; | 816 animation_target_size_ = 0; |
| 816 resize_amount_ = 0; | 817 resize_amount_ = 0; |
| 817 OnBrowserActionVisibilityChanged(); | 818 OnBrowserActionVisibilityChanged(); |
| 818 suppress_chevron_ = false; | 819 suppress_chevron_ = false; |
| 819 } | 820 } |
| 820 | 821 |
| 821 void BrowserActionsContainer::NotifyMenuDeleted( | 822 void BrowserActionsContainer::NotifyMenuDeleted( |
| 822 BrowserActionOverflowMenuController* controller) { | 823 BrowserActionOverflowMenuController* controller) { |
| 823 DCHECK(controller == overflow_menu_); | 824 DCHECK(controller == overflow_menu_); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 | 914 |
| 914 // If we are still initializing the container, don't bother animating. | 915 // If we are still initializing the container, don't bother animating. |
| 915 if (!model_->extensions_initialized()) | 916 if (!model_->extensions_initialized()) |
| 916 return; | 917 return; |
| 917 | 918 |
| 918 // Enlarge the container if it was already at maximum size and we're not in | 919 // Enlarge the container if it was already at maximum size and we're not in |
| 919 // the middle of upgrading. | 920 // the middle of upgrading. |
| 920 if ((model_->GetVisibleIconCount() < 0) && | 921 if ((model_->GetVisibleIconCount() < 0) && |
| 921 !profile_->GetExtensionService()->IsBeingUpgraded(extension)) { | 922 !profile_->GetExtensionService()->IsBeingUpgraded(extension)) { |
| 922 suppress_chevron_ = true; | 923 suppress_chevron_ = true; |
| 923 SaveDesiredSizeAndAnimate(Tween::LINEAR, visible_actions + 1); | 924 SaveDesiredSizeAndAnimate(ui::Tween::LINEAR, visible_actions + 1); |
| 924 } else { | 925 } else { |
| 925 // Just redraw the (possibly modified) visible icon set. | 926 // Just redraw the (possibly modified) visible icon set. |
| 926 OnBrowserActionVisibilityChanged(); | 927 OnBrowserActionVisibilityChanged(); |
| 927 } | 928 } |
| 928 } | 929 } |
| 929 | 930 |
| 930 void BrowserActionsContainer::BrowserActionRemoved(const Extension* extension) { | 931 void BrowserActionsContainer::BrowserActionRemoved(const Extension* extension) { |
| 931 CloseOverflowMenu(); | 932 CloseOverflowMenu(); |
| 932 | 933 |
| 933 if (popup_ && popup_->host()->extension() == extension) | 934 if (popup_ && popup_->host()->extension() == extension) |
| (...skipping 15 matching lines...) Expand all Loading... |
| 949 if (browser_action_views_.size() > visible_actions) { | 950 if (browser_action_views_.size() > visible_actions) { |
| 950 // If we have more icons than we can show, then we must not be changing | 951 // If we have more icons than we can show, then we must not be changing |
| 951 // the container size (since we either removed an icon from the main | 952 // the container size (since we either removed an icon from the main |
| 952 // area and one from the overflow list will have shifted in, or we | 953 // area and one from the overflow list will have shifted in, or we |
| 953 // removed an entry directly from the overflow list). | 954 // removed an entry directly from the overflow list). |
| 954 OnBrowserActionVisibilityChanged(); | 955 OnBrowserActionVisibilityChanged(); |
| 955 } else { | 956 } else { |
| 956 // Either we went from overflow to no-overflow, or we shrunk the no- | 957 // Either we went from overflow to no-overflow, or we shrunk the no- |
| 957 // overflow container by 1. Either way the size changed, so animate. | 958 // overflow container by 1. Either way the size changed, so animate. |
| 958 chevron_->SetVisible(false); | 959 chevron_->SetVisible(false); |
| 959 SaveDesiredSizeAndAnimate(Tween::EASE_OUT, | 960 SaveDesiredSizeAndAnimate(ui::Tween::EASE_OUT, |
| 960 browser_action_views_.size()); | 961 browser_action_views_.size()); |
| 961 } | 962 } |
| 962 return; | 963 return; |
| 963 } | 964 } |
| 964 } | 965 } |
| 965 } | 966 } |
| 966 | 967 |
| 967 void BrowserActionsContainer::BrowserActionMoved(const Extension* extension, | 968 void BrowserActionsContainer::BrowserActionMoved(const Extension* extension, |
| 968 int index) { | 969 int index) { |
| 969 if (!ShouldDisplayBrowserAction(extension)) | 970 if (!ShouldDisplayBrowserAction(extension)) |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1061 return static_cast<size_t>( | 1062 return static_cast<size_t>( |
| 1062 std::max(0, available_space + kItemSpacing) / IconWidth(true)); | 1063 std::max(0, available_space + kItemSpacing) / IconWidth(true)); |
| 1063 } | 1064 } |
| 1064 | 1065 |
| 1065 int BrowserActionsContainer::ContainerMinSize() const { | 1066 int BrowserActionsContainer::ContainerMinSize() const { |
| 1066 return ToolbarView::kStandardSpacing + kChevronSpacing + | 1067 return ToolbarView::kStandardSpacing + kChevronSpacing + |
| 1067 chevron_->GetPreferredSize().width() + ToolbarView::kStandardSpacing; | 1068 chevron_->GetPreferredSize().width() + ToolbarView::kStandardSpacing; |
| 1068 } | 1069 } |
| 1069 | 1070 |
| 1070 void BrowserActionsContainer::SaveDesiredSizeAndAnimate( | 1071 void BrowserActionsContainer::SaveDesiredSizeAndAnimate( |
| 1071 Tween::Type tween_type, | 1072 ui::Tween::Type tween_type, |
| 1072 size_t num_visible_icons) { | 1073 size_t num_visible_icons) { |
| 1073 // Save off the desired number of visible icons. We do this now instead of at | 1074 // Save off the desired number of visible icons. We do this now instead of at |
| 1074 // the end of the animation so that even if the browser is shut down while | 1075 // the end of the animation so that even if the browser is shut down while |
| 1075 // animating, the right value will be restored on next run. | 1076 // animating, the right value will be restored on next run. |
| 1076 // NOTE: Don't save the icon count in incognito because there may be fewer | 1077 // NOTE: Don't save the icon count in incognito because there may be fewer |
| 1077 // icons in that mode. The result is that the container in a normal window is | 1078 // icons in that mode. The result is that the container in a normal window is |
| 1078 // always at least as wide as in an incognito window. | 1079 // always at least as wide as in an incognito window. |
| 1079 if (!profile_->IsOffTheRecord()) | 1080 if (!profile_->IsOffTheRecord()) |
| 1080 model_->SetVisibleIconCount(num_visible_icons); | 1081 model_->SetVisibleIconCount(num_visible_icons); |
| 1081 | 1082 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1093 AnimationEnded(resize_animation_.get()); | 1094 AnimationEnded(resize_animation_.get()); |
| 1094 } | 1095 } |
| 1095 } | 1096 } |
| 1096 | 1097 |
| 1097 bool BrowserActionsContainer::ShouldDisplayBrowserAction( | 1098 bool BrowserActionsContainer::ShouldDisplayBrowserAction( |
| 1098 const Extension* extension) { | 1099 const Extension* extension) { |
| 1099 // Only display incognito-enabled extensions while in incognito mode. | 1100 // Only display incognito-enabled extensions while in incognito mode. |
| 1100 return (!profile_->IsOffTheRecord() || | 1101 return (!profile_->IsOffTheRecord() || |
| 1101 profile_->GetExtensionService()->IsIncognitoEnabled(extension)); | 1102 profile_->GetExtensionService()->IsIncognitoEnabled(extension)); |
| 1102 } | 1103 } |
| OLD | NEW |