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

Side by Side Diff: ui/views/animation/ink_drop_impl.cc

Issue 2720183002: [Views] Update ink drop for omnibox icons (Closed)
Patch Set: Update the behavior Created 3 years, 9 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ui/views/animation/ink_drop_impl.h" 5 #include "ui/views/animation/ink_drop_impl.h"
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/timer/timer.h" 9 #include "base/timer/timer.h"
10 #include "ui/compositor/layer.h" 10 #include "ui/compositor/layer.h"
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
660 void InkDropImpl::SetHovered(bool is_hovered) { 660 void InkDropImpl::SetHovered(bool is_hovered) {
661 is_hovered_ = is_hovered; 661 is_hovered_ = is_hovered;
662 highlight_state_->OnHoverChanged(); 662 highlight_state_->OnHoverChanged();
663 } 663 }
664 664
665 void InkDropImpl::SetFocused(bool is_focused) { 665 void InkDropImpl::SetFocused(bool is_focused) {
666 is_focused_ = is_focused; 666 is_focused_ = is_focused;
667 highlight_state_->OnFocusChanged(); 667 highlight_state_->OnFocusChanged();
668 } 668 }
669 669
670 bool InkDropImpl::ShouldHighlight() const {
671 return ShouldHighlightBasedOnFocus() ||
672 (show_highlight_on_hover_ && is_hovered_);
673 }
674
670 void InkDropImpl::DestroyHiddenTargetedAnimations() { 675 void InkDropImpl::DestroyHiddenTargetedAnimations() {
671 if (ink_drop_ripple_ && 676 if (ink_drop_ripple_ &&
672 (ink_drop_ripple_->target_ink_drop_state() == InkDropState::HIDDEN || 677 (ink_drop_ripple_->target_ink_drop_state() == InkDropState::HIDDEN ||
673 ShouldAnimateToHidden(ink_drop_ripple_->target_ink_drop_state()))) { 678 ShouldAnimateToHidden(ink_drop_ripple_->target_ink_drop_state()))) {
674 DestroyInkDropRipple(); 679 DestroyInkDropRipple();
675 } 680 }
676 } 681 }
677 682
678 void InkDropImpl::CreateInkDropRipple() { 683 void InkDropImpl::CreateInkDropRipple() {
679 DCHECK(!destroying_); 684 DCHECK(!destroying_);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 740
736 bool InkDropImpl::IsHighlightFadingInOrVisible() const { 741 bool InkDropImpl::IsHighlightFadingInOrVisible() const {
737 return highlight_ && highlight_->IsFadingInOrVisible(); 742 return highlight_ && highlight_->IsFadingInOrVisible();
738 } 743 }
739 744
740 // ----------------------------------------------------------------------------- 745 // -----------------------------------------------------------------------------
741 // views::InkDropRippleObserver: 746 // views::InkDropRippleObserver:
742 747
743 void InkDropImpl::AnimationStarted(InkDropState ink_drop_state) { 748 void InkDropImpl::AnimationStarted(InkDropState ink_drop_state) {
744 highlight_state_->AnimationStarted(ink_drop_state); 749 highlight_state_->AnimationStarted(ink_drop_state);
750 ink_drop_host_->InkDropAnimationStarted();
745 } 751 }
746 752
747 void InkDropImpl::AnimationEnded(InkDropState ink_drop_state, 753 void InkDropImpl::AnimationEnded(InkDropState ink_drop_state,
748 InkDropAnimationEndedReason reason) { 754 InkDropAnimationEndedReason reason) {
749 highlight_state_->AnimationEnded(ink_drop_state, reason); 755 highlight_state_->AnimationEnded(ink_drop_state, reason);
750 if (reason != InkDropAnimationEndedReason::SUCCESS) 756 if (reason != InkDropAnimationEndedReason::SUCCESS)
751 return; 757 return;
752 // |ink_drop_ripple_| might be null during destruction. 758 // |ink_drop_ripple_| might be null during destruction.
753 if (!ink_drop_ripple_) 759 if (!ink_drop_ripple_)
754 return; 760 return;
755 if (ShouldAnimateToHidden(ink_drop_state)) { 761 if (ShouldAnimateToHidden(ink_drop_state)) {
756 ink_drop_ripple_->AnimateToState(views::InkDropState::HIDDEN); 762 ink_drop_ripple_->AnimateToState(views::InkDropState::HIDDEN);
757 } else if (ink_drop_state == views::InkDropState::HIDDEN) { 763 } else if (ink_drop_state == views::InkDropState::HIDDEN) {
758 // TODO(bruthig): Investigate whether creating and destroying 764 // TODO(bruthig): Investigate whether creating and destroying
759 // InkDropRipples is expensive and consider creating an 765 // InkDropRipples is expensive and consider creating an
760 // InkDropRipplePool. See www.crbug.com/522175. 766 // InkDropRipplePool. See www.crbug.com/522175.
761 DestroyInkDropRipple(); 767 DestroyInkDropRipple();
762 } 768 }
763 } 769 }
764 770
765 // ----------------------------------------------------------------------------- 771 // -----------------------------------------------------------------------------
766 // views::InkDropHighlightObserver: 772 // views::InkDropHighlightObserver:
767 773
768 void InkDropImpl::AnimationStarted( 774 void InkDropImpl::AnimationStarted(
769 InkDropHighlight::AnimationType animation_type) {} 775 InkDropHighlight::AnimationType animation_type) {
776 ink_drop_host_->InkDropAnimationStarted();
777 }
770 778
771 void InkDropImpl::AnimationEnded(InkDropHighlight::AnimationType animation_type, 779 void InkDropImpl::AnimationEnded(InkDropHighlight::AnimationType animation_type,
772 InkDropAnimationEndedReason reason) { 780 InkDropAnimationEndedReason reason) {
773 if (animation_type == InkDropHighlight::FADE_OUT && 781 if (animation_type == InkDropHighlight::FADE_OUT &&
774 reason == InkDropAnimationEndedReason::SUCCESS) { 782 reason == InkDropAnimationEndedReason::SUCCESS) {
775 DestroyInkDropHighlight(); 783 DestroyInkDropHighlight();
776 } 784 }
777 } 785 }
778 786
779 void InkDropImpl::SetHighlight(bool should_highlight, 787 void InkDropImpl::SetHighlight(bool should_highlight,
780 base::TimeDelta animation_duration, 788 base::TimeDelta animation_duration,
781 bool explode) { 789 bool explode) {
782 if (IsHighlightFadingInOrVisible() == should_highlight) 790 if (IsHighlightFadingInOrVisible() == should_highlight)
783 return; 791 return;
784 792
785 if (should_highlight) { 793 if (should_highlight) {
786 CreateInkDropHighlight(); 794 CreateInkDropHighlight();
787 // TODO(bruthig): Remove check for null since all CreateInkDropHighlight() 795 // TODO(bruthig): Remove check for null since all CreateInkDropHighlight()
788 // methods should return a valid instance. 796 // methods should return a valid instance.
789 if (highlight_) 797 if (highlight_)
790 highlight_->FadeIn(animation_duration); 798 highlight_->FadeIn(animation_duration);
791 } else { 799 } else {
792 highlight_->FadeOut(animation_duration, explode); 800 highlight_->FadeOut(animation_duration, explode);
793 } 801 }
794 } 802 }
795 803
796 bool InkDropImpl::ShouldHighlight() const {
797 return ShouldHighlightBasedOnFocus() ||
798 (show_highlight_on_hover_ && is_hovered_);
799 }
800
801 bool InkDropImpl::ShouldHighlightBasedOnFocus() const { 804 bool InkDropImpl::ShouldHighlightBasedOnFocus() const {
802 return show_highlight_on_focus_ && is_focused_; 805 return show_highlight_on_focus_ && is_focused_;
803 } 806 }
804 807
805 void InkDropImpl::SetHighlightState( 808 void InkDropImpl::SetHighlightState(
806 std::unique_ptr<HighlightState> highlight_state) { 809 std::unique_ptr<HighlightState> highlight_state) {
807 ExitHighlightState(); 810 ExitHighlightState();
808 highlight_state_ = std::move(highlight_state); 811 highlight_state_ = std::move(highlight_state);
809 highlight_state_->Enter(); 812 highlight_state_->Enter();
810 } 813 }
811 814
812 void InkDropImpl::ExitHighlightState() { 815 void InkDropImpl::ExitHighlightState() {
813 DCHECK(!exiting_highlight_state_) << "HighlightStates should not be changed " 816 DCHECK(!exiting_highlight_state_) << "HighlightStates should not be changed "
814 "within a call to " 817 "within a call to "
815 "HighlightState::Exit()."; 818 "HighlightState::Exit().";
816 if (highlight_state_) { 819 if (highlight_state_) {
817 base::AutoReset<bool> exit_guard(&exiting_highlight_state_, true); 820 base::AutoReset<bool> exit_guard(&exiting_highlight_state_, true);
818 highlight_state_->Exit(); 821 highlight_state_->Exit();
819 } 822 }
820 highlight_state_ = nullptr; 823 highlight_state_ = nullptr;
821 } 824 }
822 825
823 } // namespace views 826 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698