OLD | NEW |
---|---|
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" |
11 #include "ui/views/animation/ink_drop_highlight.h" | 11 #include "ui/views/animation/ink_drop_highlight.h" |
12 #include "ui/views/animation/ink_drop_host.h" | 12 #include "ui/views/animation/ink_drop_host.h" |
13 #include "ui/views/animation/ink_drop_observer.h" | |
13 #include "ui/views/animation/square_ink_drop_ripple.h" | 14 #include "ui/views/animation/square_ink_drop_ripple.h" |
14 | 15 |
15 namespace views { | 16 namespace views { |
16 | 17 |
17 namespace { | 18 namespace { |
18 | 19 |
19 // The duration, in milliseconds for the highlight state fade in/out animations | 20 // The duration, in milliseconds for the highlight state fade in/out animations |
20 // when it is triggered by a hover changed event. | 21 // when it is triggered by a hover changed event. |
21 const int kHighlightFadeInOnHoverChangeDurationMs = 250; | 22 const int kHighlightFadeInOnHoverChangeDurationMs = 250; |
22 const int kHighlightFadeOutOnHoverChangeDurationMs = 250; | 23 const int kHighlightFadeOutOnHoverChangeDurationMs = 250; |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
660 void InkDropImpl::SetHovered(bool is_hovered) { | 661 void InkDropImpl::SetHovered(bool is_hovered) { |
661 is_hovered_ = is_hovered; | 662 is_hovered_ = is_hovered; |
662 highlight_state_->OnHoverChanged(); | 663 highlight_state_->OnHoverChanged(); |
663 } | 664 } |
664 | 665 |
665 void InkDropImpl::SetFocused(bool is_focused) { | 666 void InkDropImpl::SetFocused(bool is_focused) { |
666 is_focused_ = is_focused; | 667 is_focused_ = is_focused; |
667 highlight_state_->OnFocusChanged(); | 668 highlight_state_->OnFocusChanged(); |
668 } | 669 } |
669 | 670 |
671 bool InkDropImpl::IsHighlightFadingInOrVisible() const { | |
672 return highlight_ && highlight_->IsFadingInOrVisible(); | |
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
726 } | 731 } |
727 } | 732 } |
728 | 733 |
729 void InkDropImpl::RemoveRootLayerFromHostIfNeeded() { | 734 void InkDropImpl::RemoveRootLayerFromHostIfNeeded() { |
730 if (root_layer_added_to_host_ && !highlight_ && !ink_drop_ripple_) { | 735 if (root_layer_added_to_host_ && !highlight_ && !ink_drop_ripple_) { |
731 root_layer_added_to_host_ = false; | 736 root_layer_added_to_host_ = false; |
732 ink_drop_host_->RemoveInkDropLayer(root_layer_.get()); | 737 ink_drop_host_->RemoveInkDropLayer(root_layer_.get()); |
733 } | 738 } |
734 } | 739 } |
735 | 740 |
736 bool InkDropImpl::IsHighlightFadingInOrVisible() const { | |
737 return highlight_ && highlight_->IsFadingInOrVisible(); | |
738 } | |
739 | |
740 // ----------------------------------------------------------------------------- | 741 // ----------------------------------------------------------------------------- |
741 // views::InkDropRippleObserver: | 742 // views::InkDropRippleObserver: |
742 | 743 |
743 void InkDropImpl::AnimationStarted(InkDropState ink_drop_state) { | 744 void InkDropImpl::AnimationStarted(InkDropState ink_drop_state) { |
744 highlight_state_->AnimationStarted(ink_drop_state); | 745 highlight_state_->AnimationStarted(ink_drop_state); |
746 for (InkDropObserver& observer : *observers()) | |
bruthig
2017/04/21 15:05:10
nit: Consider adding an InkDrop::NotifyInkDropAnim
spqchan
2017/04/27 21:40:06
Done.
| |
747 observer.InkDropAnimationStarted(); | |
745 } | 748 } |
746 | 749 |
747 void InkDropImpl::AnimationEnded(InkDropState ink_drop_state, | 750 void InkDropImpl::AnimationEnded(InkDropState ink_drop_state, |
748 InkDropAnimationEndedReason reason) { | 751 InkDropAnimationEndedReason reason) { |
749 highlight_state_->AnimationEnded(ink_drop_state, reason); | 752 highlight_state_->AnimationEnded(ink_drop_state, reason); |
750 if (reason != InkDropAnimationEndedReason::SUCCESS) | 753 if (reason != InkDropAnimationEndedReason::SUCCESS) |
751 return; | 754 return; |
752 // |ink_drop_ripple_| might be null during destruction. | 755 // |ink_drop_ripple_| might be null during destruction. |
753 if (!ink_drop_ripple_) | 756 if (!ink_drop_ripple_) |
754 return; | 757 return; |
755 if (ShouldAnimateToHidden(ink_drop_state)) { | 758 if (ShouldAnimateToHidden(ink_drop_state)) { |
756 ink_drop_ripple_->AnimateToState(views::InkDropState::HIDDEN); | 759 ink_drop_ripple_->AnimateToState(views::InkDropState::HIDDEN); |
757 } else if (ink_drop_state == views::InkDropState::HIDDEN) { | 760 } else if (ink_drop_state == views::InkDropState::HIDDEN) { |
758 // TODO(bruthig): Investigate whether creating and destroying | 761 // TODO(bruthig): Investigate whether creating and destroying |
759 // InkDropRipples is expensive and consider creating an | 762 // InkDropRipples is expensive and consider creating an |
760 // InkDropRipplePool. See www.crbug.com/522175. | 763 // InkDropRipplePool. See www.crbug.com/522175. |
761 DestroyInkDropRipple(); | 764 DestroyInkDropRipple(); |
762 } | 765 } |
763 } | 766 } |
764 | 767 |
765 // ----------------------------------------------------------------------------- | 768 // ----------------------------------------------------------------------------- |
766 // views::InkDropHighlightObserver: | 769 // views::InkDropHighlightObserver: |
767 | 770 |
768 void InkDropImpl::AnimationStarted( | 771 void InkDropImpl::AnimationStarted( |
769 InkDropHighlight::AnimationType animation_type) {} | 772 InkDropHighlight::AnimationType animation_type) { |
773 for (InkDropObserver& observer : *observers()) | |
774 observer.InkDropAnimationStarted(); | |
775 } | |
770 | 776 |
771 void InkDropImpl::AnimationEnded(InkDropHighlight::AnimationType animation_type, | 777 void InkDropImpl::AnimationEnded(InkDropHighlight::AnimationType animation_type, |
772 InkDropAnimationEndedReason reason) { | 778 InkDropAnimationEndedReason reason) { |
773 if (animation_type == InkDropHighlight::FADE_OUT && | 779 if (animation_type == InkDropHighlight::FADE_OUT && |
774 reason == InkDropAnimationEndedReason::SUCCESS) { | 780 reason == InkDropAnimationEndedReason::SUCCESS) { |
775 DestroyInkDropHighlight(); | 781 DestroyInkDropHighlight(); |
776 } | 782 } |
777 } | 783 } |
778 | 784 |
779 void InkDropImpl::SetHighlight(bool should_highlight, | 785 void InkDropImpl::SetHighlight(bool should_highlight, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
814 "within a call to " | 820 "within a call to " |
815 "HighlightState::Exit()."; | 821 "HighlightState::Exit()."; |
816 if (highlight_state_) { | 822 if (highlight_state_) { |
817 base::AutoReset<bool> exit_guard(&exiting_highlight_state_, true); | 823 base::AutoReset<bool> exit_guard(&exiting_highlight_state_, true); |
818 highlight_state_->Exit(); | 824 highlight_state_->Exit(); |
819 } | 825 } |
820 highlight_state_ = nullptr; | 826 highlight_state_ = nullptr; |
821 } | 827 } |
822 | 828 |
823 } // namespace views | 829 } // namespace views |
OLD | NEW |