| 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 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 596 // Setting a no-op state prevents animations from being triggered on a null | 596 // Setting a no-op state prevents animations from being triggered on a null |
| 597 // |ink_drop_ripple_| as a side effect of the tear down. | 597 // |ink_drop_ripple_| as a side effect of the tear down. |
| 598 SetHighlightState(base::MakeUnique<DestroyingHighlightState>()); | 598 SetHighlightState(base::MakeUnique<DestroyingHighlightState>()); |
| 599 | 599 |
| 600 // Explicitly destroy the InkDropRipple so that this still exists if | 600 // Explicitly destroy the InkDropRipple so that this still exists if |
| 601 // views::InkDropRippleObserver methods are called on this. | 601 // views::InkDropRippleObserver methods are called on this. |
| 602 DestroyInkDropRipple(); | 602 DestroyInkDropRipple(); |
| 603 DestroyInkDropHighlight(); | 603 DestroyInkDropHighlight(); |
| 604 } | 604 } |
| 605 | 605 |
| 606 void InkDropImpl::SetShowHighlightOnHover(bool show_highlight_on_hover) { | |
| 607 show_highlight_on_hover_ = show_highlight_on_hover; | |
| 608 highlight_state_->ShowOnHoverChanged(); | |
| 609 } | |
| 610 | |
| 611 void InkDropImpl::SetShowHighlightOnFocus(bool show_highlight_on_focus) { | |
| 612 show_highlight_on_focus_ = show_highlight_on_focus; | |
| 613 highlight_state_->ShowOnFocusChanged(); | |
| 614 } | |
| 615 | |
| 616 void InkDropImpl::SetAutoHighlightMode(AutoHighlightMode auto_highlight_mode) { | 606 void InkDropImpl::SetAutoHighlightMode(AutoHighlightMode auto_highlight_mode) { |
| 617 // Exit the current state completely first in case state tear down accesses | 607 // Exit the current state completely first in case state tear down accesses |
| 618 // the current |highlight_state_factory_| instance. | 608 // the current |highlight_state_factory_| instance. |
| 619 ExitHighlightState(); | 609 ExitHighlightState(); |
| 620 highlight_state_factory_ = | 610 highlight_state_factory_ = |
| 621 base::MakeUnique<HighlightStateFactory>(auto_highlight_mode, this); | 611 base::MakeUnique<HighlightStateFactory>(auto_highlight_mode, this); |
| 622 SetHighlightState(highlight_state_factory_->CreateStartState()); | 612 SetHighlightState(highlight_state_factory_->CreateStartState()); |
| 623 } | 613 } |
| 624 | 614 |
| 625 void InkDropImpl::HostSizeChanged(const gfx::Size& new_size) { | 615 void InkDropImpl::HostSizeChanged(const gfx::Size& new_size) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 660 void InkDropImpl::SetHovered(bool is_hovered) { | 650 void InkDropImpl::SetHovered(bool is_hovered) { |
| 661 is_hovered_ = is_hovered; | 651 is_hovered_ = is_hovered; |
| 662 highlight_state_->OnHoverChanged(); | 652 highlight_state_->OnHoverChanged(); |
| 663 } | 653 } |
| 664 | 654 |
| 665 void InkDropImpl::SetFocused(bool is_focused) { | 655 void InkDropImpl::SetFocused(bool is_focused) { |
| 666 is_focused_ = is_focused; | 656 is_focused_ = is_focused; |
| 667 highlight_state_->OnFocusChanged(); | 657 highlight_state_->OnFocusChanged(); |
| 668 } | 658 } |
| 669 | 659 |
| 660 bool InkDropImpl::IsHighlightFadingInOrVisible() const { |
| 661 return highlight_ && highlight_->IsFadingInOrVisible(); |
| 662 } |
| 663 |
| 664 void InkDropImpl::SetShowHighlightOnHover(bool show_highlight_on_hover) { |
| 665 show_highlight_on_hover_ = show_highlight_on_hover; |
| 666 highlight_state_->ShowOnHoverChanged(); |
| 667 } |
| 668 |
| 669 void InkDropImpl::SetShowHighlightOnFocus(bool show_highlight_on_focus) { |
| 670 show_highlight_on_focus_ = show_highlight_on_focus; |
| 671 highlight_state_->ShowOnFocusChanged(); |
| 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 NotifyInkDropAnimationStarted(); |
| 745 } | 746 } |
| 746 | 747 |
| 747 void InkDropImpl::AnimationEnded(InkDropState ink_drop_state, | 748 void InkDropImpl::AnimationEnded(InkDropState ink_drop_state, |
| 748 InkDropAnimationEndedReason reason) { | 749 InkDropAnimationEndedReason reason) { |
| 749 highlight_state_->AnimationEnded(ink_drop_state, reason); | 750 highlight_state_->AnimationEnded(ink_drop_state, reason); |
| 750 if (reason != InkDropAnimationEndedReason::SUCCESS) | 751 if (reason != InkDropAnimationEndedReason::SUCCESS) |
| 751 return; | 752 return; |
| 752 // |ink_drop_ripple_| might be null during destruction. | 753 // |ink_drop_ripple_| might be null during destruction. |
| 753 if (!ink_drop_ripple_) | 754 if (!ink_drop_ripple_) |
| 754 return; | 755 return; |
| 755 if (ShouldAnimateToHidden(ink_drop_state)) { | 756 if (ShouldAnimateToHidden(ink_drop_state)) { |
| 756 ink_drop_ripple_->AnimateToState(views::InkDropState::HIDDEN); | 757 ink_drop_ripple_->AnimateToState(views::InkDropState::HIDDEN); |
| 757 } else if (ink_drop_state == views::InkDropState::HIDDEN) { | 758 } else if (ink_drop_state == views::InkDropState::HIDDEN) { |
| 758 // TODO(bruthig): Investigate whether creating and destroying | 759 // TODO(bruthig): Investigate whether creating and destroying |
| 759 // InkDropRipples is expensive and consider creating an | 760 // InkDropRipples is expensive and consider creating an |
| 760 // InkDropRipplePool. See www.crbug.com/522175. | 761 // InkDropRipplePool. See www.crbug.com/522175. |
| 761 DestroyInkDropRipple(); | 762 DestroyInkDropRipple(); |
| 762 } | 763 } |
| 763 } | 764 } |
| 764 | 765 |
| 765 // ----------------------------------------------------------------------------- | 766 // ----------------------------------------------------------------------------- |
| 766 // views::InkDropHighlightObserver: | 767 // views::InkDropHighlightObserver: |
| 767 | 768 |
| 768 void InkDropImpl::AnimationStarted( | 769 void InkDropImpl::AnimationStarted( |
| 769 InkDropHighlight::AnimationType animation_type) {} | 770 InkDropHighlight::AnimationType animation_type) { |
| 771 NotifyInkDropAnimationStarted(); |
| 772 } |
| 770 | 773 |
| 771 void InkDropImpl::AnimationEnded(InkDropHighlight::AnimationType animation_type, | 774 void InkDropImpl::AnimationEnded(InkDropHighlight::AnimationType animation_type, |
| 772 InkDropAnimationEndedReason reason) { | 775 InkDropAnimationEndedReason reason) { |
| 773 if (animation_type == InkDropHighlight::FADE_OUT && | 776 if (animation_type == InkDropHighlight::FADE_OUT && |
| 774 reason == InkDropAnimationEndedReason::SUCCESS) { | 777 reason == InkDropAnimationEndedReason::SUCCESS) { |
| 775 DestroyInkDropHighlight(); | 778 DestroyInkDropHighlight(); |
| 776 } | 779 } |
| 777 } | 780 } |
| 778 | 781 |
| 779 void InkDropImpl::SetHighlight(bool should_highlight, | 782 void InkDropImpl::SetHighlight(bool should_highlight, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| OLD | NEW |