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" |
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::IsHighlightFadingInOrVisible() const { |
| 671 return highlight_ && highlight_->IsFadingInOrVisible(); |
| 672 } |
| 673 |
670 void InkDropImpl::DestroyHiddenTargetedAnimations() { | 674 void InkDropImpl::DestroyHiddenTargetedAnimations() { |
671 if (ink_drop_ripple_ && | 675 if (ink_drop_ripple_ && |
672 (ink_drop_ripple_->target_ink_drop_state() == InkDropState::HIDDEN || | 676 (ink_drop_ripple_->target_ink_drop_state() == InkDropState::HIDDEN || |
673 ShouldAnimateToHidden(ink_drop_ripple_->target_ink_drop_state()))) { | 677 ShouldAnimateToHidden(ink_drop_ripple_->target_ink_drop_state()))) { |
674 DestroyInkDropRipple(); | 678 DestroyInkDropRipple(); |
675 } | 679 } |
676 } | 680 } |
677 | 681 |
678 void InkDropImpl::CreateInkDropRipple() { | 682 void InkDropImpl::CreateInkDropRipple() { |
679 DCHECK(!destroying_); | 683 DCHECK(!destroying_); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
726 } | 730 } |
727 } | 731 } |
728 | 732 |
729 void InkDropImpl::RemoveRootLayerFromHostIfNeeded() { | 733 void InkDropImpl::RemoveRootLayerFromHostIfNeeded() { |
730 if (root_layer_added_to_host_ && !highlight_ && !ink_drop_ripple_) { | 734 if (root_layer_added_to_host_ && !highlight_ && !ink_drop_ripple_) { |
731 root_layer_added_to_host_ = false; | 735 root_layer_added_to_host_ = false; |
732 ink_drop_host_->RemoveInkDropLayer(root_layer_.get()); | 736 ink_drop_host_->RemoveInkDropLayer(root_layer_.get()); |
733 } | 737 } |
734 } | 738 } |
735 | 739 |
736 bool InkDropImpl::IsHighlightFadingInOrVisible() const { | |
737 return highlight_ && highlight_->IsFadingInOrVisible(); | |
738 } | |
739 | |
740 // ----------------------------------------------------------------------------- | 740 // ----------------------------------------------------------------------------- |
741 // views::InkDropRippleObserver: | 741 // views::InkDropRippleObserver: |
742 | 742 |
743 void InkDropImpl::AnimationStarted(InkDropState ink_drop_state) { | 743 void InkDropImpl::AnimationStarted(InkDropState ink_drop_state) { |
744 highlight_state_->AnimationStarted(ink_drop_state); | 744 highlight_state_->AnimationStarted(ink_drop_state); |
| 745 if (observer_) |
| 746 observer_->InkDropAnimationStarted(); |
745 } | 747 } |
746 | 748 |
747 void InkDropImpl::AnimationEnded(InkDropState ink_drop_state, | 749 void InkDropImpl::AnimationEnded(InkDropState ink_drop_state, |
748 InkDropAnimationEndedReason reason) { | 750 InkDropAnimationEndedReason reason) { |
749 highlight_state_->AnimationEnded(ink_drop_state, reason); | 751 highlight_state_->AnimationEnded(ink_drop_state, reason); |
750 if (reason != InkDropAnimationEndedReason::SUCCESS) | 752 if (reason != InkDropAnimationEndedReason::SUCCESS) |
751 return; | 753 return; |
752 // |ink_drop_ripple_| might be null during destruction. | 754 // |ink_drop_ripple_| might be null during destruction. |
753 if (!ink_drop_ripple_) | 755 if (!ink_drop_ripple_) |
754 return; | 756 return; |
755 if (ShouldAnimateToHidden(ink_drop_state)) { | 757 if (ShouldAnimateToHidden(ink_drop_state)) { |
756 ink_drop_ripple_->AnimateToState(views::InkDropState::HIDDEN); | 758 ink_drop_ripple_->AnimateToState(views::InkDropState::HIDDEN); |
757 } else if (ink_drop_state == views::InkDropState::HIDDEN) { | 759 } else if (ink_drop_state == views::InkDropState::HIDDEN) { |
758 // TODO(bruthig): Investigate whether creating and destroying | 760 // TODO(bruthig): Investigate whether creating and destroying |
759 // InkDropRipples is expensive and consider creating an | 761 // InkDropRipples is expensive and consider creating an |
760 // InkDropRipplePool. See www.crbug.com/522175. | 762 // InkDropRipplePool. See www.crbug.com/522175. |
761 DestroyInkDropRipple(); | 763 DestroyInkDropRipple(); |
762 } | 764 } |
763 } | 765 } |
764 | 766 |
765 // ----------------------------------------------------------------------------- | 767 // ----------------------------------------------------------------------------- |
766 // views::InkDropHighlightObserver: | 768 // views::InkDropHighlightObserver: |
767 | 769 |
768 void InkDropImpl::AnimationStarted( | 770 void InkDropImpl::AnimationStarted( |
769 InkDropHighlight::AnimationType animation_type) {} | 771 InkDropHighlight::AnimationType animation_type) { |
| 772 if (observer_) |
| 773 observer_->InkDropAnimationStarted(); |
| 774 } |
770 | 775 |
771 void InkDropImpl::AnimationEnded(InkDropHighlight::AnimationType animation_type, | 776 void InkDropImpl::AnimationEnded(InkDropHighlight::AnimationType animation_type, |
772 InkDropAnimationEndedReason reason) { | 777 InkDropAnimationEndedReason reason) { |
773 if (animation_type == InkDropHighlight::FADE_OUT && | 778 if (animation_type == InkDropHighlight::FADE_OUT && |
774 reason == InkDropAnimationEndedReason::SUCCESS) { | 779 reason == InkDropAnimationEndedReason::SUCCESS) { |
775 DestroyInkDropHighlight(); | 780 DestroyInkDropHighlight(); |
776 } | 781 } |
777 } | 782 } |
778 | 783 |
779 void InkDropImpl::SetHighlight(bool should_highlight, | 784 void InkDropImpl::SetHighlight(bool should_highlight, |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
814 "within a call to " | 819 "within a call to " |
815 "HighlightState::Exit()."; | 820 "HighlightState::Exit()."; |
816 if (highlight_state_) { | 821 if (highlight_state_) { |
817 base::AutoReset<bool> exit_guard(&exiting_highlight_state_, true); | 822 base::AutoReset<bool> exit_guard(&exiting_highlight_state_, true); |
818 highlight_state_->Exit(); | 823 highlight_state_->Exit(); |
819 } | 824 } |
820 highlight_state_ = nullptr; | 825 highlight_state_ = nullptr; |
821 } | 826 } |
822 | 827 |
823 } // namespace views | 828 } // namespace views |
OLD | NEW |