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

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

Issue 2250783002: Allow InkDropRipple to co-exist with highlight (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: w/o dbg code Created 4 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
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_ripple.h" 5 #include "ui/views/animation/ink_drop_ripple.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "ui/base/ui_base_switches.h" 10 #include "ui/base/ui_base_switches.h"
(...skipping 13 matching lines...) Expand all
24 } 24 }
25 25
26 const float InkDropRipple::kHiddenOpacity = 0.f; 26 const float InkDropRipple::kHiddenOpacity = 0.f;
27 27
28 InkDropRipple::InkDropRipple() 28 InkDropRipple::InkDropRipple()
29 : target_ink_drop_state_(InkDropState::HIDDEN), observer_(nullptr) {} 29 : target_ink_drop_state_(InkDropState::HIDDEN), observer_(nullptr) {}
30 30
31 InkDropRipple::~InkDropRipple() {} 31 InkDropRipple::~InkDropRipple() {}
32 32
33 void InkDropRipple::AnimateToState(InkDropState ink_drop_state) { 33 void InkDropRipple::AnimateToState(InkDropState ink_drop_state) {
34 if (!GetRootLayer())
35 return;
36
34 // Does not return early if |target_ink_drop_state_| == |ink_drop_state| for 37 // Does not return early if |target_ink_drop_state_| == |ink_drop_state| for
35 // two reasons. 38 // two reasons.
36 // 1. The attached observers must be notified of all animations started and 39 // 1. The attached observers must be notified of all animations started and
37 // ended. 40 // ended.
38 // 2. Not all state transitions is are valid, especially no-op transitions, 41 // 2. Not all state transitions is are valid, especially no-op transitions,
39 // and these should be detected by DCHECKs in AnimateStateChange(). 42 // and these should be detected by DCHECKs in AnimateStateChange().
40 43
41 // |animation_observer| will be deleted when AnimationEndedCallback() returns 44 // |animation_observer| will be deleted when AnimationEndedCallback() returns
42 // true. 45 // true.
43 // TODO(bruthig): Implement a safer ownership model for the 46 // TODO(bruthig): Implement a safer ownership model for the
(...skipping 17 matching lines...) Expand all
61 } 64 }
62 65
63 AnimateStateChange(old_ink_drop_state, target_ink_drop_state_, 66 AnimateStateChange(old_ink_drop_state, target_ink_drop_state_,
64 animation_observer); 67 animation_observer);
65 animation_observer->SetActive(); 68 animation_observer->SetActive();
66 // |this| may be deleted! |animation_observer| might synchronously call 69 // |this| may be deleted! |animation_observer| might synchronously call
67 // AnimationEndedCallback which can delete |this|. 70 // AnimationEndedCallback which can delete |this|.
68 } 71 }
69 72
70 void InkDropRipple::SnapToActivated() { 73 void InkDropRipple::SnapToActivated() {
74 if (!GetRootLayer())
75 return;
76
71 AbortAllAnimations(); 77 AbortAllAnimations();
72 // |animation_observer| will be deleted when AnimationEndedCallback() returns 78 // |animation_observer| will be deleted when AnimationEndedCallback() returns
73 // true. 79 // true.
74 // TODO(bruthig): Implement a safer ownership model for the 80 // TODO(bruthig): Implement a safer ownership model for the
75 // |animation_observer|. 81 // |animation_observer|.
76 ui::CallbackLayerAnimationObserver* animation_observer = 82 ui::CallbackLayerAnimationObserver* animation_observer =
77 new ui::CallbackLayerAnimationObserver( 83 new ui::CallbackLayerAnimationObserver(
78 base::Bind(&InkDropRipple::AnimationStartedCallback, 84 base::Bind(&InkDropRipple::AnimationStartedCallback,
79 base::Unretained(this), InkDropState::ACTIVATED), 85 base::Unretained(this), InkDropState::ACTIVATED),
80 base::Bind(&InkDropRipple::AnimationEndedCallback, 86 base::Bind(&InkDropRipple::AnimationEndedCallback,
81 base::Unretained(this), InkDropState::ACTIVATED)); 87 base::Unretained(this), InkDropState::ACTIVATED));
82 GetRootLayer()->SetVisible(true); 88 GetRootLayer()->SetVisible(true);
83 target_ink_drop_state_ = InkDropState::ACTIVATED; 89 target_ink_drop_state_ = InkDropState::ACTIVATED;
84 animation_observer->SetActive(); 90 animation_observer->SetActive();
85 } 91 }
86 92
93 bool InkDropRipple::IsVisible() {
94 return GetRootLayer() && GetRootLayer()->visible();
95 }
96
87 void InkDropRipple::HideImmediately() { 97 void InkDropRipple::HideImmediately() {
88 AbortAllAnimations(); 98 AbortAllAnimations();
89 SetStateToHidden(); 99 SetStateToHidden();
90 target_ink_drop_state_ = InkDropState::HIDDEN; 100 target_ink_drop_state_ = InkDropState::HIDDEN;
91 } 101 }
92 102
93 test::InkDropRippleTestApi* InkDropRipple::GetTestApi() { 103 test::InkDropRippleTestApi* InkDropRipple::GetTestApi() {
94 return nullptr; 104 return nullptr;
95 } 105 }
96 106
(...skipping 10 matching lines...) Expand all
107 SetStateToHidden(); 117 SetStateToHidden();
108 observer_->AnimationEnded(ink_drop_state, 118 observer_->AnimationEnded(ink_drop_state,
109 observer.aborted_count() 119 observer.aborted_count()
110 ? InkDropAnimationEndedReason::PRE_EMPTED 120 ? InkDropAnimationEndedReason::PRE_EMPTED
111 : InkDropAnimationEndedReason::SUCCESS); 121 : InkDropAnimationEndedReason::SUCCESS);
112 // |this| may be deleted! 122 // |this| may be deleted!
113 return true; 123 return true;
114 } 124 }
115 125
116 } // namespace views 126 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698