Commit e3d882f0 authored by Hwanseung Lee's avatar Hwanseung Lee Committed by Commit Bot

Convert enum to enum class for InkDropHighlight::AnimationType

Use enum class instead of enum for InkDropHighlight::AnimationType.
enum class is more type safety.

Bug: 940736
Change-Id: I4fb353a460efd4387f7caa16aed4ee968c426728
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2062017
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742525}
parent d1a31446
......@@ -35,9 +35,9 @@ constexpr float kDefaultOpacity = 0.128f;
std::string ToString(InkDropHighlight::AnimationType animation_type) {
switch (animation_type) {
case InkDropHighlight::FADE_IN:
case InkDropHighlight::AnimationType::kFadeIn:
return std::string("FADE_IN");
case InkDropHighlight::FADE_OUT:
case InkDropHighlight::AnimationType::kFadeOut:
return std::string("FADE_OUT");
}
NOTREACHED()
......@@ -112,11 +112,12 @@ bool InkDropHighlight::IsFadingInOrVisible() const {
void InkDropHighlight::FadeIn(const base::TimeDelta& duration) {
layer_->SetOpacity(kHiddenOpacity);
layer_->SetVisible(true);
AnimateFade(FADE_IN, duration, size_, size_);
AnimateFade(AnimationType::kFadeIn, duration, size_, size_);
}
void InkDropHighlight::FadeOut(const base::TimeDelta& duration, bool explode) {
AnimateFade(FADE_OUT, duration, size_, explode ? explode_size_ : size_);
AnimateFade(AnimationType::kFadeOut, duration, size_,
explode ? explode_size_ : size_);
}
test::InkDropHighlightTestApi* InkDropHighlight::GetTestApi() {
......@@ -130,7 +131,8 @@ void InkDropHighlight::AnimateFade(AnimationType animation_type,
const base::TimeDelta effective_duration =
gfx::Animation::ShouldRenderRichAnimation() ? duration
: base::TimeDelta();
last_animation_initiated_was_fade_in_ = animation_type == FADE_IN;
last_animation_initiated_was_fade_in_ =
animation_type == AnimationType::kFadeIn;
layer_->SetTransform(CalculateTransform(initial_size));
......@@ -151,7 +153,8 @@ void InkDropHighlight::AnimateFade(AnimationType animation_type,
std::unique_ptr<ui::LayerAnimationElement> opacity_element =
ui::LayerAnimationElement::CreateOpacityElement(
animation_type == FADE_IN ? visible_opacity_ : kHiddenOpacity,
animation_type == AnimationType::kFadeIn ? visible_opacity_
: kHiddenOpacity,
effective_duration);
ui::LayerAnimationSequence* opacity_sequence =
new ui::LayerAnimationSequence(std::move(opacity_element));
......@@ -207,7 +210,7 @@ bool InkDropHighlight::AnimationEndedCallback(
const ui::CallbackLayerAnimationObserver& observer) {
// AnimationEndedCallback() may be invoked when this is being destroyed and
// |layer_| may be null.
if (animation_type == FADE_OUT && layer_)
if (animation_type == AnimationType::kFadeOut && layer_)
layer_->SetVisible(false);
if (observer_) {
......
......@@ -36,7 +36,7 @@ class InkDropHighlightObserver;
// focus).
class VIEWS_EXPORT InkDropHighlight {
public:
enum AnimationType { FADE_IN, FADE_OUT };
enum class AnimationType { kFadeIn, kFadeOut };
// Creates a highlight with a specified painter.
InkDropHighlight(const gfx::PointF& center_point,
......@@ -132,7 +132,7 @@ class VIEWS_EXPORT InkDropHighlight {
// The opacity for the fully visible state of the highlight.
float visible_opacity_;
// True if the last animation to be initiated was a FADE_IN, and false
// True if the last animation to be initiated was a kFadeIn, and false
// otherwise.
bool last_animation_initiated_was_fade_in_;
......
......@@ -124,21 +124,21 @@ TEST_F(InkDropHighlightTest,
ink_drop_highlight()->FadeIn(base::TimeDelta::FromSeconds(1));
EXPECT_TRUE(observer()->AnimationHasStarted());
EXPECT_EQ(InkDropHighlight::FADE_IN,
EXPECT_EQ(InkDropHighlight::AnimationType::kFadeIn,
observer()->last_animation_started_context());
test_api()->CompleteAnimations();
EXPECT_TRUE(observer()->AnimationHasEnded());
EXPECT_EQ(InkDropHighlight::FADE_IN,
EXPECT_EQ(InkDropHighlight::AnimationType::kFadeIn,
observer()->last_animation_started_context());
ink_drop_highlight()->FadeOut(base::TimeDelta::FromSeconds(1),
false /* explode */);
EXPECT_EQ(InkDropHighlight::FADE_OUT,
EXPECT_EQ(InkDropHighlight::AnimationType::kFadeOut,
observer()->last_animation_started_context());
test_api()->CompleteAnimations();
EXPECT_EQ(InkDropHighlight::FADE_OUT,
EXPECT_EQ(InkDropHighlight::AnimationType::kFadeOut,
observer()->last_animation_started_context());
}
......@@ -162,7 +162,7 @@ TEST_F(InkDropHighlightTest, VerifyObserversAreNotifiedOfPreemptedAnimations) {
false /* explode */);
EXPECT_EQ(2, observer()->last_animation_ended_ordinal());
EXPECT_EQ(InkDropHighlight::FADE_IN,
EXPECT_EQ(InkDropHighlight::AnimationType::kFadeIn,
observer()->last_animation_ended_context());
EXPECT_EQ(InkDropAnimationEndedReason::PRE_EMPTED,
observer()->last_animation_ended_reason());
......@@ -193,7 +193,7 @@ TEST_F(InkDropHighlightTest, AnimationsAbortedDuringDeletion) {
DestroyHighlight();
EXPECT_EQ(1, observer()->last_animation_started_ordinal());
EXPECT_EQ(2, observer()->last_animation_ended_ordinal());
EXPECT_EQ(InkDropHighlight::FADE_IN,
EXPECT_EQ(InkDropHighlight::AnimationType::kFadeIn,
observer()->last_animation_ended_context());
EXPECT_EQ(InkDropAnimationEndedReason::PRE_EMPTED,
observer()->last_animation_ended_reason());
......
......@@ -823,7 +823,7 @@ void InkDropImpl::AnimationStarted(
void InkDropImpl::AnimationEnded(InkDropHighlight::AnimationType animation_type,
InkDropAnimationEndedReason reason) {
if (animation_type == InkDropHighlight::FADE_OUT &&
if (animation_type == InkDropHighlight::AnimationType::kFadeOut &&
reason == InkDropAnimationEndedReason::SUCCESS) {
DestroyInkDropHighlight();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment