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

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

Issue 23531053: ui/base/animation -> ui/gfx/animation (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge 2 trunk Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/browser_actions_container.h" 5 #include "chrome/browser/ui/views/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"
11 #include "chrome/browser/extensions/extension_system.h" 11 #include "chrome/browser/extensions/extension_system.h"
12 #include "chrome/browser/extensions/tab_helper.h" 12 #include "chrome/browser/extensions/tab_helper.h"
13 #include "chrome/browser/profiles/profile.h" 13 #include "chrome/browser/profiles/profile.h"
14 #include "chrome/browser/sessions/session_tab_helper.h" 14 #include "chrome/browser/sessions/session_tab_helper.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 16 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/browser/ui/view_ids.h" 17 #include "chrome/browser/ui/view_ids.h"
18 #include "chrome/browser/ui/views/browser_action_view.h" 18 #include "chrome/browser/ui/views/browser_action_view.h"
19 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h" 19 #include "chrome/browser/ui/views/extensions/browser_action_drag_data.h"
20 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h" 20 #include "chrome/browser/ui/views/extensions/extension_keybinding_registry_views .h"
21 #include "chrome/browser/ui/views/extensions/extension_popup.h" 21 #include "chrome/browser/ui/views/extensions/extension_popup.h"
22 #include "chrome/browser/ui/views/toolbar_view.h" 22 #include "chrome/browser/ui/views/toolbar_view.h"
23 #include "chrome/common/pref_names.h" 23 #include "chrome/common/pref_names.h"
24 #include "grit/generated_resources.h" 24 #include "grit/generated_resources.h"
25 #include "grit/theme_resources.h" 25 #include "grit/theme_resources.h"
26 #include "grit/ui_resources.h" 26 #include "grit/ui_resources.h"
27 #include "ui/base/accessibility/accessible_view_state.h" 27 #include "ui/base/accessibility/accessible_view_state.h"
28 #include "ui/base/animation/slide_animation.h"
29 #include "ui/base/dragdrop/drag_utils.h" 28 #include "ui/base/dragdrop/drag_utils.h"
30 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
31 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
32 #include "ui/base/theme_provider.h" 31 #include "ui/base/theme_provider.h"
32 #include "ui/gfx/animation/slide_animation.h"
33 #include "ui/gfx/canvas.h" 33 #include "ui/gfx/canvas.h"
34 #include "ui/views/controls/resize_area.h" 34 #include "ui/views/controls/resize_area.h"
35 #include "ui/views/metrics.h" 35 #include "ui/views/metrics.h"
36 #include "ui/views/widget/widget.h" 36 #include "ui/views/widget/widget.h"
37 37
38 using extensions::Extension; 38 using extensions::Extension;
39 39
40 namespace { 40 namespace {
41 41
42 // Horizontal spacing between most items in the container, as well as after the 42 // Horizontal spacing between most items in the container, as well as after the
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 model_ = service->toolbar_model(); 79 model_ = service->toolbar_model();
80 model_->AddObserver(this); 80 model_->AddObserver(this);
81 } 81 }
82 82
83 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews( 83 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryViews(
84 browser->profile(), 84 browser->profile(),
85 owner_view->GetFocusManager(), 85 owner_view->GetFocusManager(),
86 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS, 86 extensions::ExtensionKeybindingRegistry::ALL_EXTENSIONS,
87 this)), 87 this)),
88 88
89 resize_animation_.reset(new ui::SlideAnimation(this)); 89 resize_animation_.reset(new gfx::SlideAnimation(this));
90 resize_area_ = new views::ResizeArea(this); 90 resize_area_ = new views::ResizeArea(this);
91 AddChildView(resize_area_); 91 AddChildView(resize_area_);
92 92
93 chevron_ = new views::MenuButton(NULL, string16(), this, false); 93 chevron_ = new views::MenuButton(NULL, string16(), this, false);
94 chevron_->set_border(NULL); 94 chevron_->set_border(NULL);
95 chevron_->EnableCanvasFlippingForRTLUI(true); 95 chevron_->EnableCanvasFlippingForRTLUI(true);
96 chevron_->SetAccessibleName( 96 chevron_->SetAccessibleName(
97 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON)); 97 l10n_util::GetStringUTF16(IDS_ACCNAME_EXTENSIONS_CHEVRON));
98 chevron_->SetVisible(false); 98 chevron_->SetVisible(false);
99 AddChildView(chevron_); 99 AddChildView(chevron_);
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 OnBrowserActionVisibilityChanged(); 413 OnBrowserActionVisibilityChanged();
414 return; 414 return;
415 } 415 }
416 416
417 // Up until now we've only been modifying the resize_amount, but now it is 417 // Up until now we've only been modifying the resize_amount, but now it is
418 // time to set the container size to the size we have resized to, and then 418 // time to set the container size to the size we have resized to, and then
419 // animate to the nearest icon count size if necessary (which may be 0). 419 // animate to the nearest icon count size if necessary (which may be 0).
420 int max_width = IconCountToWidth(-1, false); 420 int max_width = IconCountToWidth(-1, false);
421 container_width_ = 421 container_width_ =
422 std::min(std::max(0, container_width_ - resize_amount), max_width); 422 std::min(std::max(0, container_width_ - resize_amount), max_width);
423 SaveDesiredSizeAndAnimate(ui::Tween::EASE_OUT, 423 SaveDesiredSizeAndAnimate(gfx::Tween::EASE_OUT,
424 WidthToIconCount(container_width_)); 424 WidthToIconCount(container_width_));
425 } 425 }
426 426
427 void BrowserActionsContainer::AnimationProgressed( 427 void BrowserActionsContainer::AnimationProgressed(
428 const ui::Animation* animation) { 428 const gfx::Animation* animation) {
429 DCHECK_EQ(resize_animation_.get(), animation); 429 DCHECK_EQ(resize_animation_.get(), animation);
430 resize_amount_ = static_cast<int>(resize_animation_->GetCurrentValue() * 430 resize_amount_ = static_cast<int>(resize_animation_->GetCurrentValue() *
431 (container_width_ - animation_target_size_)); 431 (container_width_ - animation_target_size_));
432 OnBrowserActionVisibilityChanged(); 432 OnBrowserActionVisibilityChanged();
433 } 433 }
434 434
435 void BrowserActionsContainer::AnimationEnded(const ui::Animation* animation) { 435 void BrowserActionsContainer::AnimationEnded(const gfx::Animation* animation) {
436 container_width_ = animation_target_size_; 436 container_width_ = animation_target_size_;
437 animation_target_size_ = 0; 437 animation_target_size_ = 0;
438 resize_amount_ = 0; 438 resize_amount_ = 0;
439 OnBrowserActionVisibilityChanged(); 439 OnBrowserActionVisibilityChanged();
440 suppress_chevron_ = false; 440 suppress_chevron_ = false;
441 } 441 }
442 442
443 void BrowserActionsContainer::NotifyMenuDeleted( 443 void BrowserActionsContainer::NotifyMenuDeleted(
444 BrowserActionOverflowMenuController* controller) { 444 BrowserActionOverflowMenuController* controller) {
445 DCHECK_EQ(overflow_menu_, controller); 445 DCHECK_EQ(overflow_menu_, controller);
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 // If we are still initializing the container, don't bother animating. 619 // If we are still initializing the container, don't bother animating.
620 if (!model_->extensions_initialized()) 620 if (!model_->extensions_initialized())
621 return; 621 return;
622 622
623 // Enlarge the container if it was already at maximum size and we're not in 623 // Enlarge the container if it was already at maximum size and we're not in
624 // the middle of upgrading. 624 // the middle of upgrading.
625 if ((model_->GetVisibleIconCount() < 0) && 625 if ((model_->GetVisibleIconCount() < 0) &&
626 !extensions::ExtensionSystem::Get(profile_)->extension_service()-> 626 !extensions::ExtensionSystem::Get(profile_)->extension_service()->
627 IsBeingUpgraded(extension)) { 627 IsBeingUpgraded(extension)) {
628 suppress_chevron_ = true; 628 suppress_chevron_ = true;
629 SaveDesiredSizeAndAnimate(ui::Tween::LINEAR, visible_actions + 1); 629 SaveDesiredSizeAndAnimate(gfx::Tween::LINEAR, visible_actions + 1);
630 } else { 630 } else {
631 // Just redraw the (possibly modified) visible icon set. 631 // Just redraw the (possibly modified) visible icon set.
632 OnBrowserActionVisibilityChanged(); 632 OnBrowserActionVisibilityChanged();
633 } 633 }
634 } 634 }
635 635
636 void BrowserActionsContainer::BrowserActionRemoved(const Extension* extension) { 636 void BrowserActionsContainer::BrowserActionRemoved(const Extension* extension) {
637 CloseOverflowMenu(); 637 CloseOverflowMenu();
638 638
639 if (popup_ && popup_->host()->extension() == extension) 639 if (popup_ && popup_->host()->extension() == extension)
(...skipping 15 matching lines...) Expand all
655 if (browser_action_views_.size() > visible_actions) { 655 if (browser_action_views_.size() > visible_actions) {
656 // If we have more icons than we can show, then we must not be changing 656 // If we have more icons than we can show, then we must not be changing
657 // the container size (since we either removed an icon from the main 657 // the container size (since we either removed an icon from the main
658 // area and one from the overflow list will have shifted in, or we 658 // area and one from the overflow list will have shifted in, or we
659 // removed an entry directly from the overflow list). 659 // removed an entry directly from the overflow list).
660 OnBrowserActionVisibilityChanged(); 660 OnBrowserActionVisibilityChanged();
661 } else { 661 } else {
662 // Either we went from overflow to no-overflow, or we shrunk the no- 662 // Either we went from overflow to no-overflow, or we shrunk the no-
663 // overflow container by 1. Either way the size changed, so animate. 663 // overflow container by 1. Either way the size changed, so animate.
664 chevron_->SetVisible(false); 664 chevron_->SetVisible(false);
665 SaveDesiredSizeAndAnimate(ui::Tween::EASE_OUT, 665 SaveDesiredSizeAndAnimate(gfx::Tween::EASE_OUT,
666 browser_action_views_.size()); 666 browser_action_views_.size());
667 } 667 }
668 return; 668 return;
669 } 669 }
670 } 670 }
671 } 671 }
672 672
673 void BrowserActionsContainer::BrowserActionMoved(const Extension* extension, 673 void BrowserActionsContainer::BrowserActionMoved(const Extension* extension,
674 int index) { 674 int index) {
675 if (!ShouldDisplayBrowserAction(extension)) 675 if (!ShouldDisplayBrowserAction(extension))
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 return static_cast<size_t>( 770 return static_cast<size_t>(
771 std::max(0, available_space + kItemSpacing) / IconWidth(true)); 771 std::max(0, available_space + kItemSpacing) / IconWidth(true));
772 } 772 }
773 773
774 int BrowserActionsContainer::ContainerMinSize() const { 774 int BrowserActionsContainer::ContainerMinSize() const {
775 return ToolbarView::kStandardSpacing + kChevronSpacing + 775 return ToolbarView::kStandardSpacing + kChevronSpacing +
776 chevron_->GetPreferredSize().width() + ToolbarView::kStandardSpacing; 776 chevron_->GetPreferredSize().width() + ToolbarView::kStandardSpacing;
777 } 777 }
778 778
779 void BrowserActionsContainer::SaveDesiredSizeAndAnimate( 779 void BrowserActionsContainer::SaveDesiredSizeAndAnimate(
780 ui::Tween::Type tween_type, 780 gfx::Tween::Type tween_type,
781 size_t num_visible_icons) { 781 size_t num_visible_icons) {
782 // Save off the desired number of visible icons. We do this now instead of at 782 // Save off the desired number of visible icons. We do this now instead of at
783 // the end of the animation so that even if the browser is shut down while 783 // the end of the animation so that even if the browser is shut down while
784 // animating, the right value will be restored on next run. 784 // animating, the right value will be restored on next run.
785 // NOTE: Don't save the icon count in incognito because there may be fewer 785 // NOTE: Don't save the icon count in incognito because there may be fewer
786 // icons in that mode. The result is that the container in a normal window is 786 // icons in that mode. The result is that the container in a normal window is
787 // always at least as wide as in an incognito window. 787 // always at least as wide as in an incognito window.
788 if (!profile_->IsOffTheRecord()) 788 if (!profile_->IsOffTheRecord())
789 model_->SetVisibleIconCount(num_visible_icons); 789 model_->SetVisibleIconCount(num_visible_icons);
790 790
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT; 840 views::BubbleBorder::TOP_LEFT : views::BubbleBorder::TOP_RIGHT;
841 popup_ = ExtensionPopup::ShowPopup(popup_url, 841 popup_ = ExtensionPopup::ShowPopup(popup_url,
842 browser_, 842 browser_,
843 reference_view, 843 reference_view,
844 arrow, 844 arrow,
845 show_action); 845 show_action);
846 popup_->GetWidget()->AddObserver(this); 846 popup_->GetWidget()->AddObserver(this);
847 popup_button_ = button; 847 popup_button_ = button;
848 popup_button_->SetButtonPushed(); 848 popup_button_->SetButtonPushed();
849 } 849 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/browser_actions_container.h ('k') | chrome/browser/ui/views/download/download_item_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698