Commit 3836df28 authored by estade's avatar estade Committed by Commit bot

Rename InkDropHover to InkDropHighlight

Most uses of "hover" become "highlight", but SetHovered still refers to
the logical state of mouse hover so that remains unaltered.

BUG=none

Review-Url: https://codereview.chromium.org/2034963002
Cr-Commit-Position: refs/heads/master@{#397843}
parent c1a84134
......@@ -97,7 +97,7 @@
#include "ui/resources/grit/ui_resources.h"
#include "ui/views/animation/button_ink_drop_delegate.h"
#include "ui/views/animation/flood_fill_ink_drop_ripple.h"
#include "ui/views/animation/ink_drop_hover.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/button_drag_utils.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/button/label_button_border.h"
......@@ -245,12 +245,13 @@ class BookmarkButtonBase : public views::LabelButton {
GetInkDropBaseColor()));
}
std::unique_ptr<views::InkDropHover> CreateInkDropHover() const override {
if (!ShouldShowInkDropHover())
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override {
if (!ShouldShowInkDropHighlight())
return nullptr;
const gfx::Rect bounds = CalculateInkDropBounds(size());
return base::WrapUnique(new views::InkDropHover(
return base::WrapUnique(new views::InkDropHighlight(
bounds.size(), 0, bounds.CenterPoint(), GetInkDropBaseColor()));
}
......@@ -342,12 +343,13 @@ class BookmarkMenuButtonBase : public views::MenuButton {
GetInkDropBaseColor()));
}
std::unique_ptr<views::InkDropHover> CreateInkDropHover() const override {
if (!ShouldShowInkDropHover())
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override {
if (!ShouldShowInkDropHighlight())
return nullptr;
const gfx::Rect bounds = CalculateInkDropBounds(size());
return base::WrapUnique(new views::InkDropHover(
return base::WrapUnique(new views::InkDropHighlight(
bounds.size(), 0, bounds.CenterPoint(), GetInkDropBaseColor()));
}
......
......@@ -60,7 +60,7 @@
#include "ui/gfx/vector_icons_public.h"
#include "ui/views/animation/flood_fill_ink_drop_ripple.h"
#include "ui/views/animation/ink_drop_delegate.h"
#include "ui/views/animation/ink_drop_hover.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/button/md_text_button.h"
......@@ -481,13 +481,13 @@ std::unique_ptr<views::InkDropRipple> DownloadItemViewMd::CreateInkDropRipple()
color_utils::DeriveDefaultIconColor(GetTextColor())));
}
std::unique_ptr<views::InkDropHover> DownloadItemViewMd::CreateInkDropHover()
const {
std::unique_ptr<views::InkDropHighlight>
DownloadItemViewMd::CreateInkDropHighlight() const {
if (IsShowingWarningDialog())
return nullptr;
gfx::Size size = GetPreferredSize();
return base::WrapUnique(new views::InkDropHover(
return base::WrapUnique(new views::InkDropHighlight(
size, kInkDropSmallCornerRadius, gfx::Rect(size).CenterPoint(),
color_utils::DeriveDefaultIconColor(GetTextColor())));
}
......
......@@ -107,7 +107,8 @@ class DownloadItemViewMd : public views::InkDropHostView,
// Overridden from view::InkDropHostView:
void AddInkDropLayer(ui::Layer* ink_drop_layer) override;
std::unique_ptr<views::InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<views::InkDropHover> CreateInkDropHover() const override;
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override;
// Overridden from ui::EventHandler:
void OnGestureEvent(ui::GestureEvent* event) override;
......
......@@ -13,7 +13,7 @@
#include "ui/gfx/paint_vector_icon.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/animation/button_ink_drop_delegate.h"
#include "ui/views/animation/ink_drop_hover.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/bubble/bubble_dialog_delegate.h"
BubbleIconView::BubbleIconView(CommandUpdater* command_updater, int command_id)
......@@ -146,10 +146,10 @@ void BubbleIconView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
image_->SetPaintToLayer(false);
}
std::unique_ptr<views::InkDropHover> BubbleIconView::CreateInkDropHover()
const {
std::unique_ptr<views::InkDropHighlight>
BubbleIconView::CreateInkDropHighlight() const {
// BubbleIconView views don't show hover effect.
return HasFocus() ? InkDropHostView::CreateInkDropHover() : nullptr;
return HasFocus() ? InkDropHostView::CreateInkDropHighlight() : nullptr;
}
SkColor BubbleIconView::GetInkDropBaseColor() const {
......
......@@ -72,7 +72,8 @@ class BubbleIconView : public views::InkDropHostView,
void OnNativeThemeChanged(const ui::NativeTheme* theme) override;
void AddInkDropLayer(ui::Layer* ink_drop_layer) override;
void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override;
std::unique_ptr<views::InkDropHover> CreateInkDropHover() const override;
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override;
SkColor GetInkDropBaseColor() const override;
bool ShouldShowInkDropForFocus() const override;
......
......@@ -17,7 +17,6 @@
#include "ui/gfx/color_palette.h"
#include "ui/gfx/color_utils.h"
#include "ui/views/animation/button_ink_drop_delegate.h"
#include "ui/views/animation/ink_drop_hover.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h"
#include "ui/views/widget/widget.h"
......
......@@ -14,7 +14,7 @@
#include "ui/gfx/image/image_util.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/animation/ink_drop_hover.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/border.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/textfield/textfield.h"
......@@ -204,8 +204,8 @@ void IconLabelBubbleView::RemoveInkDropLayer(ui::Layer* ink_drop_layer) {
image()->SetPaintToLayer(false);
}
std::unique_ptr<views::InkDropHover> IconLabelBubbleView::CreateInkDropHover()
const {
std::unique_ptr<views::InkDropHighlight>
IconLabelBubbleView::CreateInkDropHighlight() const {
// Location bar views don't show hover effect.
return nullptr;
}
......
......@@ -86,7 +86,8 @@ class IconLabelBubbleView : public views::InkDropHostView {
void OnNativeThemeChanged(const ui::NativeTheme* native_theme) override;
void AddInkDropLayer(ui::Layer* ink_drop_layer) override;
void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override;
std::unique_ptr<views::InkDropHover> CreateInkDropHover() const override;
std::unique_ptr<views::InkDropHighlight> CreateInkDropHighlight()
const override;
SkColor GetInkDropBaseColor() const override;
const gfx::FontList& font_list() const { return label_->font_list(); }
......
......@@ -117,9 +117,9 @@ SkColor ToolbarActionView::GetInkDropBaseColor() const {
ThemeProperties::COLOR_TOOLBAR_BUTTON_ICON);
}
bool ToolbarActionView::ShouldShowInkDropHover() const {
bool ToolbarActionView::ShouldShowInkDropHighlight() const {
return !delegate_->ShownInsideMenu() &&
views::MenuButton::ShouldShowInkDropHover();
views::MenuButton::ShouldShowInkDropHighlight();
}
content::WebContents* ToolbarActionView::GetCurrentWebContents() const {
......
......@@ -74,7 +74,7 @@ class ToolbarActionView : public views::MenuButton,
const override;
bool IsTriggerableEvent(const ui::Event& event) override;
SkColor GetInkDropBaseColor() const override;
bool ShouldShowInkDropHover() const override;
bool ShouldShowInkDropHighlight() const override;
// ToolbarActionViewDelegateViews:
content::WebContents* GetCurrentWebContents() const override;
......
......@@ -104,7 +104,7 @@ TEST_P(InkDropFactoryTest,
TEST_P(InkDropFactoryTest,
VerifyInkDropLayersRemovedAfterDestructionWhenHoverIsActive) {
test_ink_drop_host_.set_should_show_hover(true);
test_ink_drop_host_.set_should_show_highlight(true);
ink_drop_->SetHovered(true);
ink_drop_.reset();
EXPECT_EQ(0, test_ink_drop_host_.num_ink_drop_layers());
......
......@@ -2,33 +2,33 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/animation/ink_drop_hover.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/compositor/callback_layer_animation_observer.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_sequence.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/views/animation/ink_drop_hover_observer.h"
#include "ui/views/animation/ink_drop_highlight_observer.h"
#include "ui/views/animation/ink_drop_painted_layer_delegates.h"
namespace views {
namespace {
// The opacity of the hover when it is visible.
const float kHoverVisibleOpacity = 0.128f;
// The opacity of the highlight when it is visible.
const float kHighlightVisibleOpacity = 0.128f;
// The opacity of the hover when it is not visible.
// The opacity of the highlight when it is not visible.
const float kHiddenOpacity = 0.0f;
} // namespace
std::string ToString(InkDropHover::AnimationType animation_type) {
std::string ToString(InkDropHighlight::AnimationType animation_type) {
switch (animation_type) {
case InkDropHover::FADE_IN:
case InkDropHighlight::FADE_IN:
return std::string("FADE_IN");
case InkDropHover::FADE_OUT:
case InkDropHighlight::FADE_OUT:
return std::string("FADE_OUT");
}
NOTREACHED()
......@@ -36,10 +36,10 @@ std::string ToString(InkDropHover::AnimationType animation_type) {
return std::string("UNKNOWN");
}
InkDropHover::InkDropHover(const gfx::Size& size,
int corner_radius,
const gfx::Point& center_point,
SkColor color)
InkDropHighlight::InkDropHighlight(const gfx::Size& size,
int corner_radius,
const gfx::Point& center_point,
SkColor color)
: size_(size),
explode_size_(size),
center_point_(center_point),
......@@ -52,35 +52,35 @@ InkDropHover::InkDropHover(const gfx::Size& size,
layer_->SetFillsBoundsOpaquely(false);
layer_->set_delegate(layer_delegate_.get());
layer_->SetVisible(false);
layer_->SetOpacity(kHoverVisibleOpacity);
layer_->SetOpacity(kHighlightVisibleOpacity);
layer_->SetMasksToBounds(false);
layer_->set_name("InkDropHover:layer");
layer_->set_name("InkDropHighlight:layer");
}
InkDropHover::~InkDropHover() {}
InkDropHighlight::~InkDropHighlight() {}
bool InkDropHover::IsFadingInOrVisible() const {
bool InkDropHighlight::IsFadingInOrVisible() const {
return last_animation_initiated_was_fade_in_;
}
void InkDropHover::FadeIn(const base::TimeDelta& duration) {
void InkDropHighlight::FadeIn(const base::TimeDelta& duration) {
layer_->SetOpacity(kHiddenOpacity);
layer_->SetVisible(true);
AnimateFade(FADE_IN, duration, size_, size_);
}
void InkDropHover::FadeOut(const base::TimeDelta& duration, bool explode) {
void InkDropHighlight::FadeOut(const base::TimeDelta& duration, bool explode) {
AnimateFade(FADE_OUT, duration, size_, explode ? explode_size_ : size_);
}
test::InkDropHoverTestApi* InkDropHover::GetTestApi() {
test::InkDropHighlightTestApi* InkDropHighlight::GetTestApi() {
return nullptr;
}
void InkDropHover::AnimateFade(AnimationType animation_type,
const base::TimeDelta& duration,
const gfx::Size& initial_size,
const gfx::Size& target_size) {
void InkDropHighlight::AnimateFade(AnimationType animation_type,
const base::TimeDelta& duration,
const gfx::Size& initial_size,
const gfx::Size& target_size) {
last_animation_initiated_was_fade_in_ = animation_type == FADE_IN;
layer_->SetTransform(CalculateTransform(initial_size));
......@@ -89,9 +89,9 @@ void InkDropHover::AnimateFade(AnimationType animation_type,
// AnimationStartedCallback() returns true.
ui::CallbackLayerAnimationObserver* animation_observer =
new ui::CallbackLayerAnimationObserver(
base::Bind(&InkDropHover::AnimationStartedCallback,
base::Bind(&InkDropHighlight::AnimationStartedCallback,
base::Unretained(this), animation_type),
base::Bind(&InkDropHover::AnimationEndedCallback,
base::Bind(&InkDropHighlight::AnimationEndedCallback,
base::Unretained(this), animation_type));
ui::LayerAnimator* animator = layer_->GetAnimator();
......@@ -102,7 +102,7 @@ void InkDropHover::AnimateFade(AnimationType animation_type,
ui::LayerAnimationElement* opacity_element =
ui::LayerAnimationElement::CreateOpacityElement(
animation_type == FADE_IN ? kHoverVisibleOpacity : kHiddenOpacity,
animation_type == FADE_IN ? kHighlightVisibleOpacity : kHiddenOpacity,
duration);
ui::LayerAnimationSequence* opacity_sequence =
new ui::LayerAnimationSequence(opacity_element);
......@@ -122,7 +122,8 @@ void InkDropHover::AnimateFade(AnimationType animation_type,
animation_observer->SetActive();
}
gfx::Transform InkDropHover::CalculateTransform(const gfx::Size& size) const {
gfx::Transform InkDropHighlight::CalculateTransform(
const gfx::Size& size) const {
gfx::Transform transform;
transform.Translate(center_point_.x(), center_point_.y());
transform.Scale(size.width() / size_.width(), size.height() / size_.height());
......@@ -131,14 +132,14 @@ gfx::Transform InkDropHover::CalculateTransform(const gfx::Size& size) const {
return transform;
}
void InkDropHover::AnimationStartedCallback(
void InkDropHighlight::AnimationStartedCallback(
AnimationType animation_type,
const ui::CallbackLayerAnimationObserver& observer) {
if (observer_)
observer_->AnimationStarted(animation_type);
}
bool InkDropHover::AnimationEndedCallback(
bool InkDropHighlight::AnimationEndedCallback(
AnimationType animation_type,
const ui::CallbackLayerAnimationObserver& observer) {
// AnimationEndedCallback() may be invoked when this is being destroyed and
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_ANIMATION_INK_DROP_HOVER_H_
#define UI_VIEWS_ANIMATION_INK_DROP_HOVER_H_
#ifndef UI_VIEWS_ANIMATION_INK_DROP_HIGHLIGHT_H_
#define UI_VIEWS_ANIMATION_INK_DROP_HIGHLIGHT_H_
#include <iosfwd>
#include <memory>
......@@ -24,37 +24,41 @@ class CallbackLayerAnimationObserver;
namespace views {
namespace test {
class InkDropHoverTestApi;
class InkDropHighlightTestApi;
} // namespace test
class RoundedRectangleLayerDelegate;
class InkDropHoverObserver;
class InkDropHighlightObserver;
// Manages fade in/out animations for a painted Layer that is used to provide
// visual feedback on ui::Views for mouse hover states.
class VIEWS_EXPORT InkDropHover {
// visual feedback on ui::Views for highlight states (e.g. mouse hover, keyboard
// focus).
class VIEWS_EXPORT InkDropHighlight {
public:
enum AnimationType { FADE_IN, FADE_OUT };
InkDropHover(const gfx::Size& size,
int corner_radius,
const gfx::Point& center_point,
SkColor color);
virtual ~InkDropHover();
InkDropHighlight(const gfx::Size& size,
int corner_radius,
const gfx::Point& center_point,
SkColor color);
virtual ~InkDropHighlight();
void set_observer(InkDropHoverObserver* observer) { observer_ = observer; }
void set_observer(InkDropHighlightObserver* observer) {
observer_ = observer;
}
void set_explode_size(const gfx::Size& size) { explode_size_ = size; }
// Returns true if the hover animation is either in the process of fading
// Returns true if the highlight animation is either in the process of fading
// in or is fully visible.
bool IsFadingInOrVisible() const;
// Fades in the hover visual over the given |duration|.
// Fades in the highlight visual over the given |duration|.
void FadeIn(const base::TimeDelta& duration);
// Fades out the hover visual over the given |duration|. If |explode| is true
// then the hover will animate a size increase in addition to the fade out.
// Fades out the highlight visual over the given |duration|. If |explode| is
// true then the highlight will animate a size increase in addition to the
// fade out.
void FadeOut(const base::TimeDelta& duration, bool explode);
// The root Layer that can be added in to a Layer tree.
......@@ -63,10 +67,10 @@ class VIEWS_EXPORT InkDropHover {
// Returns a test api to access internals of this. Default implmentations
// should return nullptr and test specific subclasses can override to return
// an instance.
virtual test::InkDropHoverTestApi* GetTestApi();
virtual test::InkDropHighlightTestApi* GetTestApi();
private:
friend class test::InkDropHoverTestApi;
friend class test::InkDropHighlightTestApi;
// Animates a fade in/out as specified by |animation_type| combined with a
// transformation from the |initial_size| to the |target_size| over the given
......@@ -89,39 +93,42 @@ class VIEWS_EXPORT InkDropHover {
AnimationType animation_type,
const ui::CallbackLayerAnimationObserver& observer);
// The size of the hover shape when fully faded in.
// The size of the highlight shape when fully faded in.
gfx::Size size_;
// The target size of the hover shape when it expands during a fade out
// The target size of the highlight shape when it expands during a fade out
// animation.
gfx::Size explode_size_;
// The center point of the hover shape in the parent Layer's coordinate space.
// The center point of the highlight shape in the parent Layer's coordinate
// space.
gfx::PointF center_point_;
// True if the last animation to be initiated was a FADE_IN, and false
// otherwise.
bool last_animation_initiated_was_fade_in_;
// The LayerDelegate that paints the hover |layer_|.
// The LayerDelegate that paints the highlight |layer_|.
std::unique_ptr<RoundedRectangleLayerDelegate> layer_delegate_;
// The visual hover layer that is painted by |layer_delegate_|.
// The visual highlight layer that is painted by |layer_delegate_|.
std::unique_ptr<ui::Layer> layer_;
InkDropHoverObserver* observer_;
InkDropHighlightObserver* observer_;
DISALLOW_COPY_AND_ASSIGN(InkDropHover);
DISALLOW_COPY_AND_ASSIGN(InkDropHighlight);
};
// Returns a human readable string for |animation_type|. Useful for logging.
VIEWS_EXPORT std::string ToString(InkDropHover::AnimationType animation_type);
VIEWS_EXPORT std::string ToString(
InkDropHighlight::AnimationType animation_type);
// This is declared here for use in gtest-based unit tests but is defined in
// the views_test_support target. Depend on that to use this in your unit test.
// This should not be used in production code - call ToString() instead.
void PrintTo(InkDropHover::AnimationType animation_type, ::std::ostream* os);
void PrintTo(InkDropHighlight::AnimationType animation_type,
::std::ostream* os);
} // namespace views
#endif // UI_VIEWS_ANIMATION_INK_DROP_HOVER_H_
#endif // UI_VIEWS_ANIMATION_INK_DROP_HIGHLIGHT_H_
......@@ -2,40 +2,41 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_ANIMATION_INK_DROP_HOVER_OBSERVER_H_
#define UI_VIEWS_ANIMATION_INK_DROP_HOVER_OBSERVER_H_
#ifndef UI_VIEWS_ANIMATION_INK_DROP_HIGHLIGHT_OBSERVER_H_
#define UI_VIEWS_ANIMATION_INK_DROP_HIGHLIGHT_OBSERVER_H_
#include <string>
#include "base/macros.h"
#include "ui/views/animation/ink_drop_animation_ended_reason.h"
#include "ui/views/animation/ink_drop_hover.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/views_export.h"
namespace views {
// Observer to attach to an InkDropHover animation.
class VIEWS_EXPORT InkDropHoverObserver {
// Observer to attach to an InkDropHighlight animation.
class VIEWS_EXPORT InkDropHighlightObserver {
public:
// An animation for the given |animation_type| has started.
virtual void AnimationStarted(InkDropHover::AnimationType animation_type) = 0;
virtual void AnimationStarted(
InkDropHighlight::AnimationType animation_type) = 0;
// Notifies the observer that an animation for the given |animation_type| has
// finished and the reason for completion is given by |reason|. If |reason| is
// SUCCESS then the animation has progressed to its final frame however if
// |reason| is |PRE_EMPTED| then the animation was stopped before its final
// frame.
virtual void AnimationEnded(InkDropHover::AnimationType animation_type,
virtual void AnimationEnded(InkDropHighlight::AnimationType animation_type,
InkDropAnimationEndedReason reason) = 0;
protected:
InkDropHoverObserver() = default;
virtual ~InkDropHoverObserver() = default;
InkDropHighlightObserver() = default;
virtual ~InkDropHighlightObserver() = default;
private:
DISALLOW_COPY_AND_ASSIGN(InkDropHoverObserver);
DISALLOW_COPY_AND_ASSIGN(InkDropHighlightObserver);
};
} // namespace views
#endif // UI_VIEWS_ANIMATION_INK_DROP_HOVER_OBSERVER_H_
#endif // UI_VIEWS_ANIMATION_INK_DROP_HIGHLIGHT_OBSERVER_H_
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/animation/ink_drop_hover.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include <memory>
......@@ -12,63 +12,65 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/animation/test/ink_drop_hover_test_api.h"
#include "ui/views/animation/test/test_ink_drop_hover_observer.h"
#include "ui/views/animation/test/ink_drop_highlight_test_api.h"
#include "ui/views/animation/test/test_ink_drop_highlight_observer.h"
namespace views {
namespace test {
class InkDropHoverTest : public testing::Test {
class InkDropHighlightTest : public testing::Test {
public:
InkDropHoverTest();
~InkDropHoverTest() override;
InkDropHighlightTest();
~InkDropHighlightTest() override;
protected:
// The test target.
std::unique_ptr<InkDropHover> ink_drop_hover_;
std::unique_ptr<InkDropHighlight> ink_drop_highlight_;
// Allows privileged access to the the |ink_drop_hover_|.
InkDropHoverTestApi test_api_;
// Allows privileged access to the the |ink_drop_highlight_|.
InkDropHighlightTestApi test_api_;
// Observer of the test target.
TestInkDropHoverObserver observer_;
TestInkDropHighlightObserver observer_;
private:
DISALLOW_COPY_AND_ASSIGN(InkDropHoverTest);
DISALLOW_COPY_AND_ASSIGN(InkDropHighlightTest);
};
InkDropHoverTest::InkDropHoverTest()
: ink_drop_hover_(
new InkDropHover(gfx::Size(10, 10), 3, gfx::Point(), SK_ColorBLACK)),
test_api_(ink_drop_hover_.get()) {
ink_drop_hover_->set_observer(&observer_);
InkDropHighlightTest::InkDropHighlightTest()
: ink_drop_highlight_(new InkDropHighlight(gfx::Size(10, 10),
3,
gfx::Point(),
SK_ColorBLACK)),
test_api_(ink_drop_highlight_.get()) {
ink_drop_highlight_->set_observer(&observer_);
test_api_.SetDisableAnimationTimers(true);
}
InkDropHoverTest::~InkDropHoverTest() {}
InkDropHighlightTest::~InkDropHighlightTest() {}
TEST_F(InkDropHoverTest, InitialStateAfterConstruction) {
EXPECT_FALSE(ink_drop_hover_->IsFadingInOrVisible());
TEST_F(InkDropHighlightTest, InitialStateAfterConstruction) {
EXPECT_FALSE(ink_drop_highlight_->IsFadingInOrVisible());
}
TEST_F(InkDropHoverTest, IsHoveredStateTransitions) {
ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
EXPECT_TRUE(ink_drop_hover_->IsFadingInOrVisible());
TEST_F(InkDropHighlightTest, IsHighlightedStateTransitions) {
ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1));
EXPECT_TRUE(ink_drop_highlight_->IsFadingInOrVisible());
test_api_.CompleteAnimations();
EXPECT_TRUE(ink_drop_hover_->IsFadingInOrVisible());
EXPECT_TRUE(ink_drop_highlight_->IsFadingInOrVisible());
ink_drop_hover_->FadeOut(base::TimeDelta::FromSeconds(1),
false /* explode */);
EXPECT_FALSE(ink_drop_hover_->IsFadingInOrVisible());
ink_drop_highlight_->FadeOut(base::TimeDelta::FromSeconds(1),
false /* explode */);
EXPECT_FALSE(ink_drop_highlight_->IsFadingInOrVisible());
test_api_.CompleteAnimations();
EXPECT_FALSE(ink_drop_hover_->IsFadingInOrVisible());
EXPECT_FALSE(ink_drop_highlight_->IsFadingInOrVisible());
}
TEST_F(InkDropHoverTest, VerifyObserversAreNotified) {
ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
TEST_F(InkDropHighlightTest, VerifyObserversAreNotified) {
ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1));
EXPECT_EQ(1, observer_.last_animation_started_ordinal());
EXPECT_FALSE(observer_.AnimationHasEnded());
......@@ -79,26 +81,31 @@ TEST_F(InkDropHoverTest, VerifyObserversAreNotified) {
EXPECT_EQ(2, observer_.last_animation_ended_ordinal());
}
TEST_F(InkDropHoverTest, VerifyObserversAreNotifiedWithCorrectAnimationType) {
ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
TEST_F(InkDropHighlightTest,
VerifyObserversAreNotifiedWithCorrectAnimationType) {
ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1));
EXPECT_TRUE(observer_.AnimationHasStarted());
EXPECT_EQ(InkDropHover::FADE_IN, observer_.last_animation_started_context());
EXPECT_EQ(InkDropHighlight::FADE_IN,
observer_.last_animation_started_context());
test_api_.CompleteAnimations();
EXPECT_TRUE(observer_.AnimationHasEnded());
EXPECT_EQ(InkDropHover::FADE_IN, observer_.last_animation_started_context());
EXPECT_EQ(InkDropHighlight::FADE_IN,
observer_.last_animation_started_context());
ink_drop_hover_->FadeOut(base::TimeDelta::FromSeconds(1),
false /* explode */);
EXPECT_EQ(InkDropHover::FADE_OUT, observer_.last_animation_started_context());
ink_drop_highlight_->FadeOut(base::TimeDelta::FromSeconds(1),
false /* explode */);
EXPECT_EQ(InkDropHighlight::FADE_OUT,
observer_.last_animation_started_context());
test_api_.CompleteAnimations();
EXPECT_EQ(InkDropHover::FADE_OUT, observer_.last_animation_started_context());
EXPECT_EQ(InkDropHighlight::FADE_OUT,
observer_.last_animation_started_context());
}
TEST_F(InkDropHoverTest, VerifyObserversAreNotifiedOfSuccessfulAnimations) {
ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
TEST_F(InkDropHighlightTest, VerifyObserversAreNotifiedOfSuccessfulAnimations) {
ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1));
test_api_.CompleteAnimations();
EXPECT_EQ(2, observer_.last_animation_ended_ordinal());
......@@ -106,38 +113,40 @@ TEST_F(InkDropHoverTest, VerifyObserversAreNotifiedOfSuccessfulAnimations) {
observer_.last_animation_ended_reason());
}
TEST_F(InkDropHoverTest, VerifyObserversAreNotifiedOfPreemptedAnimations) {
ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
ink_drop_hover_->FadeOut(base::TimeDelta::FromSeconds(1),
false /* explode */);
TEST_F(InkDropHighlightTest, VerifyObserversAreNotifiedOfPreemptedAnimations) {
ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1));
ink_drop_highlight_->FadeOut(base::TimeDelta::FromSeconds(1),
false /* explode */);
EXPECT_EQ(2, observer_.last_animation_ended_ordinal());
EXPECT_EQ(InkDropHover::FADE_IN, observer_.last_animation_ended_context());
EXPECT_EQ(InkDropHighlight::FADE_IN,
observer_.last_animation_ended_context());
EXPECT_EQ(InkDropAnimationEndedReason::PRE_EMPTED,
observer_.last_animation_ended_reason());
}
// Confirms there is no crash.
TEST_F(InkDropHoverTest, NullObserverIsSafe) {
ink_drop_hover_->set_observer(nullptr);
TEST_F(InkDropHighlightTest, NullObserverIsSafe) {
ink_drop_highlight_->set_observer(nullptr);
ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1));
test_api_.CompleteAnimations();
ink_drop_hover_->FadeOut(base::TimeDelta::FromMilliseconds(0),
false /* explode */);
ink_drop_highlight_->FadeOut(base::TimeDelta::FromMilliseconds(0),
false /* explode */);
test_api_.CompleteAnimations();
EXPECT_FALSE(ink_drop_hover_->IsFadingInOrVisible());
EXPECT_FALSE(ink_drop_highlight_->IsFadingInOrVisible());
}
// Verify animations are aborted during deletion and the InkDropHoverObservers
// are notified.
TEST_F(InkDropHoverTest, AnimationsAbortedDuringDeletion) {
ink_drop_hover_->FadeIn(base::TimeDelta::FromSeconds(1));
ink_drop_hover_.reset();
// Verify animations are aborted during deletion and the
// InkDropHighlightObservers are notified.
TEST_F(InkDropHighlightTest, AnimationsAbortedDuringDeletion) {
ink_drop_highlight_->FadeIn(base::TimeDelta::FromSeconds(1));
ink_drop_highlight_.reset();
EXPECT_EQ(1, observer_.last_animation_started_ordinal());
EXPECT_EQ(2, observer_.last_animation_ended_ordinal());
EXPECT_EQ(InkDropHover::FADE_IN, observer_.last_animation_ended_context());
EXPECT_EQ(InkDropHighlight::FADE_IN,
observer_.last_animation_ended_context());
EXPECT_EQ(InkDropAnimationEndedReason::PRE_EMPTED,
observer_.last_animation_ended_reason());
}
......
......@@ -18,7 +18,7 @@ class Layer;
namespace views {
class InkDropRipple;
class InkDropHover;
class InkDropHighlight;
// Used by the InkDrop to add and remove the ink drop layers from a host's layer
// tree. Typically the ink drop layer is added to a View's layer but it can also
......@@ -41,8 +41,8 @@ class VIEWS_EXPORT InkDropHost {
// Creates and returns the effect used for press.
virtual std::unique_ptr<InkDropRipple> CreateInkDropRipple() const = 0;
// Creates and returns the effect used for hover.
virtual std::unique_ptr<InkDropHover> CreateInkDropHover() const = 0;
// Creates and returns the effect used for hover and focus.
virtual std::unique_ptr<InkDropHighlight> CreateInkDropHighlight() const = 0;
private:
DISALLOW_COPY_AND_ASSIGN(InkDropHost);
......
......@@ -7,7 +7,7 @@
#include "ui/gfx/color_palette.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/animation/ink_drop_hover.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/square_ink_drop_ripple.h"
namespace views {
......@@ -64,12 +64,13 @@ std::unique_ptr<InkDropRipple> InkDropHostView::CreateInkDropRipple() const {
return ripple;
}
std::unique_ptr<InkDropHover> InkDropHostView::CreateInkDropHover() const {
std::unique_ptr<InkDropHover> hover(
new InkDropHover(ink_drop_size_, kInkDropSmallCornerRadius,
GetInkDropCenter(), GetInkDropBaseColor()));
hover->set_explode_size(CalculateLargeInkDropSize(ink_drop_size_));
return hover;
std::unique_ptr<InkDropHighlight> InkDropHostView::CreateInkDropHighlight()
const {
std::unique_ptr<InkDropHighlight> highlight(
new InkDropHighlight(ink_drop_size_, kInkDropSmallCornerRadius,
GetInkDropCenter(), GetInkDropBaseColor()));
highlight->set_explode_size(CalculateLargeInkDropSize(ink_drop_size_));
return highlight;
}
void InkDropHostView::OnFocus() {
......
......@@ -16,7 +16,7 @@
namespace views {
class InkDropRipple;
class InkDropHover;
class InkDropHighlight;
// A view that provides InkDropHost functionality.
class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost {
......@@ -25,7 +25,7 @@ class VIEWS_EXPORT InkDropHostView : public View, public InkDropHost {
void AddInkDropLayer(ui::Layer* ink_drop_layer) override;
void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override;
std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<InkDropHover> CreateInkDropHover() const override;
std::unique_ptr<InkDropHighlight> CreateInkDropHighlight() const override;
void set_ink_drop_size(const gfx::Size& size) { ink_drop_size_ = size; }
......
......@@ -7,33 +7,33 @@
#include "base/auto_reset.h"
#include "base/timer/timer.h"
#include "ui/compositor/layer.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_host.h"
#include "ui/views/animation/ink_drop_hover.h"
#include "ui/views/animation/square_ink_drop_ripple.h"
namespace views {
namespace {
// The duration, in milliseconds, of the hover state fade in animation when it
// is triggered by user input.
const int kHoverFadeInFromUserInputDurationInMs = 250;
// The duration, in milliseconds, of the highlight state fade in animation when
// it is triggered by user input.
const int kHighlightFadeInFromUserInputDurationInMs = 250;
// The duration, in milliseconds, of the hover state fade out animation when it
// is triggered by user input.
const int kHoverFadeOutFromUserInputDurationInMs = 250;
// The duration, in milliseconds, of the highlight state fade out animation when
// it is triggered by user input.
const int kHighlightFadeOutFromUserInputDurationInMs = 250;
// The duration, in milliseconds, of the hover state fade in animation when it
// is triggered by an ink drop ripple animation ending.
const int kHoverFadeInAfterRippleDurationInMs = 250;
// The duration, in milliseconds, of the highlight state fade in animation when
// it is triggered by an ink drop ripple animation ending.
const int kHighlightFadeInAfterRippleDurationInMs = 250;
// The duration, in milliseconds, of the hover state fade out animation when it
// is triggered by an ink drop ripple animation starting.
const int kHoverFadeOutBeforeRippleDurationInMs = 120;
// The duration, in milliseconds, of the highlight state fade out animation when
// it is triggered by an ink drop ripple animation starting.
const int kHighlightFadeOutBeforeRippleDurationInMs = 120;
// The amount of time in milliseconds that |hover_| should delay after a ripple
// animation before fading in.
const int kHoverFadeInAfterRippleDelayInMs = 1000;
// The amount of time in milliseconds that |highlight_| should delay after a
// ripple animation before fading in.
const int kHighlightFadeInAfterRippleDelayInMs = 1000;
// Returns true if an ink drop with the given |ink_drop_state| should
// automatically transition to the InkDropState::HIDDEN state.
......@@ -56,7 +56,7 @@ InkDropImpl::InkDropImpl(InkDropHost* ink_drop_host)
root_layer_added_to_host_(false),
is_hovered_(false),
is_focused_(false),
hover_after_ripple_timer_(nullptr) {
highlight_after_ripple_timer_(nullptr) {
root_layer_->set_name("InkDropImpl:RootLayer");
}
......@@ -64,7 +64,7 @@ InkDropImpl::~InkDropImpl() {
// Explicitly destroy the InkDropRipple so that this still exists if
// views::InkDropRippleObserver methods are called on this.
DestroyInkDropRipple();
DestroyInkDropHover();
DestroyInkDropHighlight();
}
InkDropState InkDropImpl::GetTargetInkDropState() const {
......@@ -84,7 +84,7 @@ void InkDropImpl::AnimateToState(InkDropState ink_drop_state) {
if (ink_drop_state != views::InkDropState::HIDDEN) {
SetHighlight(false, base::TimeDelta::FromMilliseconds(
kHoverFadeOutBeforeRippleDurationInMs),
kHighlightFadeOutBeforeRippleDurationInMs),
true);
}
......@@ -104,10 +104,11 @@ void InkDropImpl::SnapToActivated() {
void InkDropImpl::SetHovered(bool is_hovered) {
is_hovered_ = is_hovered;
SetHighlight(ShouldHighlight(),
ShouldHighlight() ? base::TimeDelta::FromMilliseconds(
kHoverFadeInFromUserInputDurationInMs)
: base::TimeDelta::FromMilliseconds(
kHoverFadeOutFromUserInputDurationInMs),
ShouldHighlight()
? base::TimeDelta::FromMilliseconds(
kHighlightFadeInFromUserInputDurationInMs)
: base::TimeDelta::FromMilliseconds(
kHighlightFadeOutFromUserInputDurationInMs),
false);
}
......@@ -140,28 +141,28 @@ void InkDropImpl::DestroyInkDropRipple() {
RemoveRootLayerFromHostIfNeeded();
}
void InkDropImpl::CreateInkDropHover() {
DestroyInkDropHover();
void InkDropImpl::CreateInkDropHighlight() {
DestroyInkDropHighlight();
hover_ = ink_drop_host_->CreateInkDropHover();
if (!hover_)
highlight_ = ink_drop_host_->CreateInkDropHighlight();
if (!highlight_)
return;
hover_->set_observer(this);
root_layer_->Add(hover_->layer());
highlight_->set_observer(this);
root_layer_->Add(highlight_->layer());
AddRootLayerToHostIfNeeded();
}
void InkDropImpl::DestroyInkDropHover() {
if (!hover_)
void InkDropImpl::DestroyInkDropHighlight() {
if (!highlight_)
return;
root_layer_->Remove(hover_->layer());
hover_->set_observer(nullptr);
hover_.reset();
root_layer_->Remove(highlight_->layer());
highlight_->set_observer(nullptr);
highlight_.reset();
RemoveRootLayerFromHostIfNeeded();
}
void InkDropImpl::AddRootLayerToHostIfNeeded() {
DCHECK(hover_ || ink_drop_ripple_);
DCHECK(highlight_ || ink_drop_ripple_);
if (!root_layer_added_to_host_) {
root_layer_added_to_host_ = true;
ink_drop_host_->AddInkDropLayer(root_layer_.get());
......@@ -169,14 +170,14 @@ void InkDropImpl::AddRootLayerToHostIfNeeded() {
}
void InkDropImpl::RemoveRootLayerFromHostIfNeeded() {
if (root_layer_added_to_host_ && !hover_ && !ink_drop_ripple_) {
if (root_layer_added_to_host_ && !highlight_ && !ink_drop_ripple_) {
root_layer_added_to_host_ = false;
ink_drop_host_->RemoveInkDropLayer(root_layer_.get());
}
}
bool InkDropImpl::IsHoverFadingInOrVisible() const {
return hover_ && hover_->IsFadingInOrVisible();
bool InkDropImpl::IsHighlightFadingInOrVisible() const {
return highlight_ && highlight_->IsFadingInOrVisible();
}
// -----------------------------------------------------------------------------
......@@ -192,7 +193,7 @@ void InkDropImpl::AnimationEnded(InkDropState ink_drop_state,
ink_drop_ripple_->AnimateToState(views::InkDropState::HIDDEN);
} else if (ink_drop_state == views::InkDropState::HIDDEN) {
if (is_hovered_)
StartHoverAfterRippleTimer();
StartHighlightAfterRippleTimer();
// TODO(bruthig): Investigate whether creating and destroying
// InkDropRipples is expensive and consider creating an
// InkDropRipplePool. See www.crbug.com/522175.
......@@ -201,33 +202,33 @@ void InkDropImpl::AnimationEnded(InkDropState ink_drop_state,
}
// -----------------------------------------------------------------------------
// views::InkDropHoverObserver:
// views::InkDropHighlightObserver:
void InkDropImpl::AnimationStarted(InkDropHover::AnimationType animation_type) {
}
void InkDropImpl::AnimationStarted(
InkDropHighlight::AnimationType animation_type) {}
void InkDropImpl::AnimationEnded(InkDropHover::AnimationType animation_type,
void InkDropImpl::AnimationEnded(InkDropHighlight::AnimationType animation_type,
InkDropAnimationEndedReason reason) {
if (animation_type == InkDropHover::FADE_OUT &&
if (animation_type == InkDropHighlight::FADE_OUT &&
reason == InkDropAnimationEndedReason::SUCCESS) {
DestroyInkDropHover();
DestroyInkDropHighlight();
}
}
void InkDropImpl::SetHighlight(bool should_highlight,
base::TimeDelta animation_duration,
bool explode) {
StopHoverAfterRippleTimer();
StopHighlightAfterRippleTimer();
if (IsHoverFadingInOrVisible() == should_highlight)
if (IsHighlightFadingInOrVisible() == should_highlight)
return;
if (should_highlight) {
CreateInkDropHover();
if (hover_ && !IsVisible())
hover_->FadeIn(animation_duration);
CreateInkDropHighlight();
if (highlight_ && !IsVisible())
highlight_->FadeIn(animation_duration);
} else {
hover_->FadeOut(animation_duration, explode);
highlight_->FadeOut(animation_duration, explode);
}
}
......@@ -235,29 +236,29 @@ bool InkDropImpl::ShouldHighlight() const {
return is_focused_ || is_hovered_;
}
void InkDropImpl::StartHoverAfterRippleTimer() {
StopHoverAfterRippleTimer();
void InkDropImpl::StartHighlightAfterRippleTimer() {
StopHighlightAfterRippleTimer();
if (!hover_after_ripple_timer_)
hover_after_ripple_timer_.reset(new base::OneShotTimer);
if (!highlight_after_ripple_timer_)
highlight_after_ripple_timer_.reset(new base::OneShotTimer);
hover_after_ripple_timer_->Start(
highlight_after_ripple_timer_->Start(
FROM_HERE,
base::TimeDelta::FromMilliseconds(kHoverFadeInAfterRippleDelayInMs),
base::Bind(&InkDropImpl::HoverAfterRippleTimerFired,
base::TimeDelta::FromMilliseconds(kHighlightFadeInAfterRippleDelayInMs),
base::Bind(&InkDropImpl::HighlightAfterRippleTimerFired,
base::Unretained(this)));
}
void InkDropImpl::StopHoverAfterRippleTimer() {
if (hover_after_ripple_timer_)
hover_after_ripple_timer_.reset();
void InkDropImpl::StopHighlightAfterRippleTimer() {
if (highlight_after_ripple_timer_)
highlight_after_ripple_timer_.reset();
}
void InkDropImpl::HoverAfterRippleTimerFired() {
void InkDropImpl::HighlightAfterRippleTimerFired() {
SetHighlight(true, base::TimeDelta::FromMilliseconds(
kHoverFadeInAfterRippleDurationInMs),
kHighlightFadeInAfterRippleDurationInMs),
true);
hover_after_ripple_timer_.reset();
highlight_after_ripple_timer_.reset();
}
} // namespace views
......@@ -11,7 +11,7 @@
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/animation/ink_drop.h"
#include "ui/views/animation/ink_drop_hover_observer.h"
#include "ui/views/animation/ink_drop_highlight_observer.h"
#include "ui/views/animation/ink_drop_ripple_observer.h"
#include "ui/views/views_export.h"
......@@ -26,13 +26,13 @@ class InkDropImplTestApi;
class InkDropRipple;
class InkDropHost;
class InkDropHover;
class InkDropHighlight;
class InkDropFactoryTest;
// A functional implementation of an InkDrop.
class VIEWS_EXPORT InkDropImpl : public InkDrop,
public InkDropRippleObserver,
public InkDropHoverObserver {
public InkDropHighlightObserver {
public:
// Constructs an ink drop that will attach the ink drop to the given
// |ink_drop_host|.
......@@ -61,38 +61,40 @@ class VIEWS_EXPORT InkDropImpl : public InkDrop,
// Destroys the current |ink_drop_ripple_|.
void DestroyInkDropRipple();
// Creates a new InkDropHover and sets it to |hover_|. If |hover_| wasn't null
// then it will be destroyed using DestroyInkDropHover().
void CreateInkDropHover();
// Creates a new InkDropHighlight and assigns it to |highlight_|. If
// |highlight_| wasn't null then it will be destroyed using
// DestroyInkDropHighlight().
void CreateInkDropHighlight();
// Destroys the current |hover_|.
void DestroyInkDropHover();
// Destroys the current |highlight_|.
void DestroyInkDropHighlight();
// Adds the |root_layer_| to the |ink_drop_host_| if it hasn't already been
// added.
void AddRootLayerToHostIfNeeded();
// Removes the |root_layer_| from the |ink_drop_host_| if no ink drop ripple
// or hover is active.
// or highlight is active.
void RemoveRootLayerFromHostIfNeeded();
// Returns true if the hover animation is in the process of fading in or
// Returns true if the highlight animation is in the process of fading in or
// is visible.
bool IsHoverFadingInOrVisible() const;
bool IsHighlightFadingInOrVisible() const;
// views::InkDropRippleObserver:
void AnimationStarted(InkDropState ink_drop_state) override;
void AnimationEnded(InkDropState ink_drop_state,
InkDropAnimationEndedReason reason) override;
// views::InkDropHoverObserver:
void AnimationStarted(InkDropHover::AnimationType animation_type) override;
void AnimationEnded(InkDropHover::AnimationType animation_type,
// views::InkDropHighlightObserver:
void AnimationStarted(
InkDropHighlight::AnimationType animation_type) override;
void AnimationEnded(InkDropHighlight::AnimationType animation_type,
InkDropAnimationEndedReason reason) override;
// Enables or disables the hover state based on |should_highlight| and if an
// animation is triggered it will be scheduled to have the given
// |animation_duration|. If |explode| is true the hover will expand as it
// Enables or disables the highlight state based on |should_highlight| and if
// an animation is triggered it will be scheduled to have the given
// |animation_duration|. If |explode| is true the highlight will expand as it
// fades out. |explode| is ignored when |should_higlight| is true.
void SetHighlight(bool should_highlight,
base::TimeDelta animation_duration,
......@@ -101,30 +103,32 @@ class VIEWS_EXPORT InkDropImpl : public InkDrop,
// Returns true if this ink drop is hovered or focused.
bool ShouldHighlight() const;
// Starts the |hover_after_ripple_timer_| timer. This will stop the current
// |hover_after_ripple_timer_| instance if it exists.
void StartHoverAfterRippleTimer();
// Starts the |highlight_after_ripple_timer_| timer. This will stop the
// current
// |highlight_after_ripple_timer_| instance if it exists.
void StartHighlightAfterRippleTimer();
// Stops and destroys the current |hover_after_ripple_timer_| instance.
void StopHoverAfterRippleTimer();
// Stops and destroys the current |highlight_after_ripple_timer_| instance.
void StopHighlightAfterRippleTimer();
// Callback for when the |hover_after_ripple_timer_| fires.
void HoverAfterRippleTimerFired();
// Callback for when the |highlight_after_ripple_timer_| fires.
void HighlightAfterRippleTimerFired();
// The host of the ink drop. Used to poll for information such as whether the
// hover should be shown or not.
// highlight should be shown or not.
InkDropHost* ink_drop_host_;
// The root Layer that parents the InkDropRipple layers and the InkDropHover
// layers. The |root_layer_| is the one that is added and removed from the
// InkDropHost.
// The root Layer that parents the InkDropRipple layers and the
// InkDropHighlight layers. The |root_layer_| is the one that is added and
// removed from the InkDropHost.
std::unique_ptr<ui::Layer> root_layer_;
// True when the |root_layer_| has been added to the |ink_drop_host_|.
bool root_layer_added_to_host_;
// The current InkDropHover. Lazily created using CreateInkDropHover();
std::unique_ptr<InkDropHover> hover_;
// The current InkDropHighlight. Lazily created using
// CreateInkDropHighlight();
std::unique_ptr<InkDropHighlight> highlight_;
// Tracks the logical hovered state of |this| as manipulated by the public
// SetHovered() function.
......@@ -137,9 +141,9 @@ class VIEWS_EXPORT InkDropImpl : public InkDrop,
// The current InkDropRipple. Created on demand using CreateInkDropRipple().
std::unique_ptr<InkDropRipple> ink_drop_ripple_;
// The timer used to delay the hover fade in after an ink drop ripple
// The timer used to delay the highlight fade in after an ink drop ripple
// animation.
std::unique_ptr<base::Timer> hover_after_ripple_timer_;
std::unique_ptr<base::Timer> highlight_after_ripple_timer_;
DISALLOW_COPY_AND_ASSIGN(InkDropImpl);
};
......
......@@ -26,7 +26,7 @@ class InkDropImplTest : public testing::Test {
// The test target.
InkDropImpl ink_drop_;
// Allows privileged access to the the |ink_drop_hover_|.
// Allows privileged access to the the |ink_drop_highlight_|.
test::InkDropImplTestApi test_api_;
// Used to control the tasks scheduled by the InkDropImpl's Timer.
......@@ -50,54 +50,54 @@ InkDropImplTest::InkDropImplTest()
InkDropImplTest::~InkDropImplTest() {}
TEST_F(InkDropImplTest, SetHoveredIsFadingInOrVisible) {
ink_drop_host_.set_should_show_hover(true);
TEST_F(InkDropImplTest, SetHoveredHighlightIsFadingInOrVisible) {
ink_drop_host_.set_should_show_highlight(true);
ink_drop_.SetHovered(true);
EXPECT_TRUE(test_api_.IsHoverFadingInOrVisible());
EXPECT_TRUE(test_api_.IsHighlightFadingInOrVisible());
test_api_.CompleteAnimations();
ink_drop_.SetHovered(false);
EXPECT_FALSE(test_api_.IsHoverFadingInOrVisible());
EXPECT_FALSE(test_api_.IsHighlightFadingInOrVisible());
}
TEST_F(InkDropImplTest, FocusAndHoverAtSameTime) {
ink_drop_host_.set_should_show_hover(true);
EXPECT_FALSE(test_api_.IsHoverFadingInOrVisible());
ink_drop_host_.set_should_show_highlight(true);
EXPECT_FALSE(test_api_.IsHighlightFadingInOrVisible());
ink_drop_.SetFocused(true);
EXPECT_TRUE(test_api_.IsHoverFadingInOrVisible());
EXPECT_TRUE(test_api_.IsHighlightFadingInOrVisible());
test_api_.CompleteAnimations();
ink_drop_.SetHovered(false);
EXPECT_TRUE(test_api_.IsHoverFadingInOrVisible());
EXPECT_TRUE(test_api_.IsHighlightFadingInOrVisible());
test_api_.CompleteAnimations();
ink_drop_.SetHovered(true);
EXPECT_TRUE(test_api_.IsHoverFadingInOrVisible());
EXPECT_TRUE(test_api_.IsHighlightFadingInOrVisible());
test_api_.CompleteAnimations();
ink_drop_.SetFocused(false);
EXPECT_TRUE(test_api_.IsHoverFadingInOrVisible());
EXPECT_TRUE(test_api_.IsHighlightFadingInOrVisible());
test_api_.CompleteAnimations();
ink_drop_.SetHovered(false);
EXPECT_FALSE(test_api_.IsHoverFadingInOrVisible());
EXPECT_FALSE(test_api_.IsHighlightFadingInOrVisible());
}
TEST_F(InkDropImplTest, HoverDoesntFadeInAfterAnimationIfHoverNotSet) {
ink_drop_host_.set_should_show_hover(true);
TEST_F(InkDropImplTest, HighlightDoesntFadeInAfterAnimationIfHighlightNotSet) {
ink_drop_host_.set_should_show_highlight(true);
ink_drop_.SetHovered(false);
ink_drop_.AnimateToState(InkDropState::ACTION_TRIGGERED);
test_api_.CompleteAnimations();
EXPECT_FALSE(task_runner_->HasPendingTask());
EXPECT_FALSE(test_api_.IsHoverFadingInOrVisible());
EXPECT_FALSE(test_api_.IsHighlightFadingInOrVisible());
}
TEST_F(InkDropImplTest, HoverFadesInAfterAnimationWhenHostIsHovered) {
ink_drop_host_.set_should_show_hover(true);
TEST_F(InkDropImplTest, HighlightFadesInAfterAnimationWhenHostIsHovered) {
ink_drop_host_.set_should_show_highlight(true);
ink_drop_.SetHovered(true);
ink_drop_.AnimateToState(InkDropState::ACTION_TRIGGERED);
test_api_.CompleteAnimations();
......@@ -106,11 +106,12 @@ TEST_F(InkDropImplTest, HoverFadesInAfterAnimationWhenHostIsHovered) {
task_runner_->RunPendingTasks();
EXPECT_TRUE(test_api_.IsHoverFadingInOrVisible());
EXPECT_TRUE(test_api_.IsHighlightFadingInOrVisible());
}
TEST_F(InkDropImplTest, HoverDoesntFadeInAfterAnimationWhenHostIsNotHovered) {
ink_drop_host_.set_should_show_hover(false);
TEST_F(InkDropImplTest,
HighlightDoesntFadeInAfterAnimationWhenHostIsNotHovered) {
ink_drop_host_.set_should_show_highlight(false);
ink_drop_.SetHovered(true);
ink_drop_.AnimateToState(InkDropState::ACTION_TRIGGERED);
test_api_.CompleteAnimations();
......@@ -119,44 +120,44 @@ TEST_F(InkDropImplTest, HoverDoesntFadeInAfterAnimationWhenHostIsNotHovered) {
task_runner_->RunPendingTasks();
EXPECT_FALSE(test_api_.IsHoverFadingInOrVisible());
EXPECT_FALSE(test_api_.IsHighlightFadingInOrVisible());
}
TEST_F(InkDropImplTest, HoveredStateNotVisibleOrFadingInAfterAnimateToState) {
ink_drop_host_.set_should_show_hover(true);
ink_drop_host_.set_should_show_highlight(true);
ink_drop_.SetHovered(true);
test_api_.CompleteAnimations();
EXPECT_TRUE(test_api_.IsHoverFadingInOrVisible());
EXPECT_TRUE(test_api_.IsHighlightFadingInOrVisible());
ink_drop_.AnimateToState(InkDropState::ACTION_TRIGGERED);
EXPECT_FALSE(test_api_.IsHoverFadingInOrVisible());
EXPECT_FALSE(test_api_.IsHighlightFadingInOrVisible());
}
// Verifies that there is not a crash when setting hovered state and the host
// returns null for the hover.
TEST_F(InkDropImplTest, SetHoveredFalseWorksWhenNoInkDropHoverExists) {
ink_drop_host_.set_should_show_hover(false);
// returns null for the highlight.
TEST_F(InkDropImplTest, SetHoveredFalseWorksWhenNoInkDropHighlightExists) {
ink_drop_host_.set_should_show_highlight(false);
ink_drop_.SetHovered(true);
EXPECT_FALSE(test_api_.hover());
EXPECT_FALSE(test_api_.highlight());
ink_drop_.SetHovered(false);
EXPECT_FALSE(test_api_.hover());
EXPECT_FALSE(test_api_.highlight());
}
TEST_F(InkDropImplTest, HoverFadesOutOnSnapToActivated) {
ink_drop_host_.set_should_show_hover(true);
TEST_F(InkDropImplTest, HighlightFadesOutOnSnapToActivated) {
ink_drop_host_.set_should_show_highlight(true);
ink_drop_.SetHovered(true);
test_api_.CompleteAnimations();
EXPECT_TRUE(test_api_.IsHoverFadingInOrVisible());
EXPECT_TRUE(test_api_.IsHighlightFadingInOrVisible());
ink_drop_.SnapToActivated();
EXPECT_FALSE(test_api_.IsHoverFadingInOrVisible());
EXPECT_FALSE(test_api_.IsHighlightFadingInOrVisible());
}
TEST_F(InkDropImplTest, LayersRemovedFromHostAfterHover) {
ink_drop_host_.set_should_show_hover(true);
TEST_F(InkDropImplTest, LayersRemovedFromHostAfterHighlight) {
ink_drop_host_.set_should_show_highlight(true);
EXPECT_EQ(0, ink_drop_host_.num_ink_drop_layers());
......@@ -173,7 +174,7 @@ TEST_F(InkDropImplTest, LayersRemovedFromHostAfterHover) {
}
TEST_F(InkDropImplTest, LayersRemovedFromHostAfterInkDrop) {
ink_drop_host_.set_should_show_hover(true);
ink_drop_host_.set_should_show_highlight(true);
EXPECT_EQ(0, ink_drop_host_.num_ink_drop_layers());
......@@ -187,8 +188,8 @@ TEST_F(InkDropImplTest, LayersRemovedFromHostAfterInkDrop) {
EXPECT_EQ(0, ink_drop_host_.num_ink_drop_layers());
}
TEST_F(InkDropImplTest, LayersAddedToHostWhenHoverOrInkDropVisible) {
ink_drop_host_.set_should_show_hover(true);
TEST_F(InkDropImplTest, LayersAddedToHostWhenHighlightOrInkDropVisible) {
ink_drop_host_.set_should_show_highlight(true);
EXPECT_EQ(0, ink_drop_host_.num_ink_drop_layers());
......@@ -207,13 +208,13 @@ TEST_F(InkDropImplTest, LayersAddedToHostWhenHoverOrInkDropVisible) {
EXPECT_TRUE(task_runner_->HasPendingTask());
task_runner_->RunPendingTasks();
// Hover should be fading back in.
// Highlight should be fading back in.
EXPECT_TRUE(test_api_.HasActiveAnimations());
EXPECT_EQ(1, ink_drop_host_.num_ink_drop_layers());
}
TEST_F(InkDropImplTest, LayersNotAddedToHostWhenHoverTimeFires) {
ink_drop_host_.set_should_show_hover(true);
TEST_F(InkDropImplTest, LayersNotAddedToHostWhenHighlightTimeFires) {
ink_drop_host_.set_should_show_highlight(true);
EXPECT_EQ(0, ink_drop_host_.num_ink_drop_layers());
......@@ -227,7 +228,7 @@ TEST_F(InkDropImplTest, LayersNotAddedToHostWhenHoverTimeFires) {
test_api_.CompleteAnimations();
EXPECT_EQ(0, ink_drop_host_.num_ink_drop_layers());
ink_drop_host_.set_should_show_hover(false);
ink_drop_host_.set_should_show_highlight(false);
EXPECT_TRUE(task_runner_->HasPendingTask());
task_runner_->RunPendingTasks();
......@@ -236,7 +237,7 @@ TEST_F(InkDropImplTest, LayersNotAddedToHostWhenHoverTimeFires) {
}
TEST_F(InkDropImplTest, LayersArentRemovedWhenPreemptingFadeOut) {
ink_drop_host_.set_should_show_hover(true);
ink_drop_host_.set_should_show_highlight(true);
EXPECT_EQ(0, ink_drop_host_.num_ink_drop_layers());
......
......@@ -2,26 +2,27 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/animation/test/ink_drop_hover_test_api.h"
#include "ui/views/animation/test/ink_drop_highlight_test_api.h"
#include "base/time/time.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animator.h"
#include "ui/compositor/test/layer_animator_test_controller.h"
#include "ui/views/animation/ink_drop_hover.h"
#include "ui/views/animation/ink_drop_highlight.h"
namespace views {
namespace test {
InkDropHoverTestApi::InkDropHoverTestApi(InkDropHover* ink_drop_hover)
InkDropHighlightTestApi::InkDropHighlightTestApi(
InkDropHighlight* ink_drop_highlight)
: ui::test::MultiLayerAnimatorTestController(this),
ink_drop_hover_(ink_drop_hover) {}
ink_drop_highlight_(ink_drop_highlight) {}
InkDropHoverTestApi::~InkDropHoverTestApi() {}
InkDropHighlightTestApi::~InkDropHighlightTestApi() {}
std::vector<ui::LayerAnimator*> InkDropHoverTestApi::GetLayerAnimators() {
std::vector<ui::LayerAnimator*> InkDropHighlightTestApi::GetLayerAnimators() {
std::vector<ui::LayerAnimator*> animators;
animators.push_back(ink_drop_hover()->layer_->GetAnimator());
animators.push_back(ink_drop_highlight()->layer_->GetAnimator());
return animators;
}
......
......@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_ANIMATION_TEST_INK_DROP_HOVER_TEST_API_H_
#define UI_VIEWS_ANIMATION_TEST_INK_DROP_HOVER_TEST_API_H_
#ifndef UI_VIEWS_ANIMATION_TEST_INK_DROP_HIGHLIGHT_TEST_API_H_
#define UI_VIEWS_ANIMATION_TEST_INK_DROP_HIGHLIGHT_TEST_API_H_
#include <vector>
......@@ -16,38 +16,39 @@ class LayerAnimator;
} // namespace ui
namespace views {
class InkDropHover;
class InkDropHighlight;
namespace test {
// Test API to provide internal access to an InkDropHover instance. This can
// Test API to provide internal access to an InkDropHighlight instance. This can
// also be used to control the animations via the
// ui::test::MultiLayerAnimatorTestController API.
class InkDropHoverTestApi
class InkDropHighlightTestApi
: public ui::test::MultiLayerAnimatorTestController,
public ui::test::MultiLayerAnimatorTestControllerDelegate {
public:
explicit InkDropHoverTestApi(InkDropHover* ink_drop_hover);
~InkDropHoverTestApi() override;
explicit InkDropHighlightTestApi(InkDropHighlight* ink_drop_highlight);
~InkDropHighlightTestApi() override;
// MultiLayerAnimatorTestControllerDelegate:
std::vector<ui::LayerAnimator*> GetLayerAnimators() override;
protected:
InkDropHover* ink_drop_hover() {
return static_cast<const InkDropHoverTestApi*>(this)->ink_drop_hover();
InkDropHighlight* ink_drop_highlight() {
return static_cast<const InkDropHighlightTestApi*>(this)
->ink_drop_highlight();
}
InkDropHover* ink_drop_hover() const { return ink_drop_hover_; }
InkDropHighlight* ink_drop_highlight() const { return ink_drop_highlight_; }
private:
// The InkDropHover to provide internal access to.
InkDropHover* ink_drop_hover_;
// The InkDropHighlight to provide internal access to.
InkDropHighlight* ink_drop_highlight_;
DISALLOW_COPY_AND_ASSIGN(InkDropHoverTestApi);
DISALLOW_COPY_AND_ASSIGN(InkDropHighlightTestApi);
};
} // namespace test
} // namespace views
#endif // UI_VIEWS_ANIMATION_TEST_INK_DROP_HOVER_TEST_API_H_
#endif // UI_VIEWS_ANIMATION_TEST_INK_DROP_HIGHLIGHT_TEST_API_H_
......@@ -4,10 +4,10 @@
#include "ui/views/animation/test/ink_drop_impl_test_api.h"
#include "ui/views/animation/ink_drop_hover.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/ink_drop_ripple.h"
#include "ui/views/animation/test/ink_drop_hover_test_api.h"
#include "ui/views/animation/test/ink_drop_highlight_test_api.h"
#include "ui/views/animation/test/ink_drop_ripple_test_api.h"
namespace views {
......@@ -18,24 +18,24 @@ InkDropImplTestApi::InkDropImplTestApi(InkDropImpl* ink_drop)
InkDropImplTestApi::~InkDropImplTestApi() {}
const InkDropHover* InkDropImplTestApi::hover() const {
return ink_drop_->hover_.get();
const InkDropHighlight* InkDropImplTestApi::highlight() const {
return ink_drop_->highlight_.get();
}
bool InkDropImplTestApi::IsHoverFadingInOrVisible() const {
return ink_drop_->IsHoverFadingInOrVisible();
bool InkDropImplTestApi::IsHighlightFadingInOrVisible() const {
return ink_drop_->IsHighlightFadingInOrVisible();
}
std::vector<ui::LayerAnimator*> InkDropImplTestApi::GetLayerAnimators() {
std::vector<ui::LayerAnimator*> animators;
if (ink_drop_->hover_) {
InkDropHoverTestApi* ink_drop_hover_test_api =
ink_drop_->hover_->GetTestApi();
std::vector<ui::LayerAnimator*> ink_drop_hover_animators =
ink_drop_hover_test_api->GetLayerAnimators();
animators.insert(animators.end(), ink_drop_hover_animators.begin(),
ink_drop_hover_animators.end());
if (ink_drop_->highlight_) {
InkDropHighlightTestApi* ink_drop_highlight_test_api =
ink_drop_->highlight_->GetTestApi();
std::vector<ui::LayerAnimator*> ink_drop_highlight_animators =
ink_drop_highlight_test_api->GetLayerAnimators();
animators.insert(animators.end(), ink_drop_highlight_animators.begin(),
ink_drop_highlight_animators.end());
}
if (ink_drop_->ink_drop_ripple_) {
......
......@@ -17,12 +17,12 @@ class LayerAnimator;
namespace views {
class InkDropImpl;
class InkDropHover;
class InkDropHighlight;
namespace test {
// Test API to provide internal access to an InkDropImpl instance. This can also
// be used to control the InkDropRipple and InkDropHover animations via the
// be used to control the InkDropRipple and InkDropHighlight animations via the
// ui::test::MultiLayerAnimatorTestController API.
class InkDropImplTestApi
: public ui::test::MultiLayerAnimatorTestController,
......@@ -32,8 +32,8 @@ class InkDropImplTestApi
~InkDropImplTestApi() override;
// Wrappers to InkDropImpl internals:
const InkDropHover* hover() const;
bool IsHoverFadingInOrVisible() const;
const InkDropHighlight* highlight() const;
bool IsHighlightFadingInOrVisible() const;
protected:
// MultiLayerAnimatorTestControllerDelegate:
......
......@@ -5,7 +5,7 @@
#include <ostream>
#include "ui/views/animation/ink_drop_animation_ended_reason.h"
#include "ui/views/animation/ink_drop_hover.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_state.h"
namespace views {
......@@ -14,7 +14,8 @@ void PrintTo(InkDropState ink_drop_state, ::std::ostream* os) {
*os << ToString(ink_drop_state);
}
void PrintTo(InkDropHover::AnimationType animation_type, ::std::ostream* os) {
void PrintTo(InkDropHighlight::AnimationType animation_type,
::std::ostream* os) {
*os << ToString(animation_type);
}
......
......@@ -2,22 +2,22 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/views/animation/test/test_ink_drop_hover_observer.h"
#include "ui/views/animation/test/test_ink_drop_highlight_observer.h"
#include "ui/views/animation/ink_drop_hover.h"
#include "ui/views/animation/ink_drop_highlight.h"
namespace views {
namespace test {
TestInkDropHoverObserver::TestInkDropHoverObserver() {}
TestInkDropHighlightObserver::TestInkDropHighlightObserver() {}
void TestInkDropHoverObserver::AnimationStarted(
InkDropHover::AnimationType animation_type) {
void TestInkDropHighlightObserver::AnimationStarted(
InkDropHighlight::AnimationType animation_type) {
ObserverHelper::OnAnimationStarted(animation_type);
}
void TestInkDropHoverObserver::AnimationEnded(
InkDropHover::AnimationType animation_type,
void TestInkDropHighlightObserver::AnimationEnded(
InkDropHighlight::AnimationType animation_type,
InkDropAnimationEndedReason reason) {
ObserverHelper::OnAnimationEnded(animation_type, reason);
}
......
......@@ -2,49 +2,51 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_HOVER_OBSERVER_H_
#define UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_HOVER_OBSERVER_H_
#ifndef UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_HIGHLIGHT_OBSERVER_H_
#define UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_HIGHLIGHT_OBSERVER_H_
#include "base/macros.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/views/animation/ink_drop_hover.h"
#include "ui/views/animation/ink_drop_hover_observer.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/ink_drop_highlight_observer.h"
#include "ui/views/animation/ink_drop_state.h"
#include "ui/views/animation/test/test_ink_drop_animation_observer_helper.h"
namespace views {
namespace test {
// Simple InkDropHoverObserver test double that tracks if InkDropHoverObserver
// methods are invoked and the parameters used for the last invocation.
class TestInkDropHoverObserver
: public InkDropHoverObserver,
public TestInkDropAnimationObserverHelper<InkDropHover::AnimationType> {
// Simple InkDropHighlightObserver test double that tracks if
// InkDropHighlightObserver methods are invoked and the parameters used for the
// last invocation.
class TestInkDropHighlightObserver : public InkDropHighlightObserver,
public TestInkDropAnimationObserverHelper<
InkDropHighlight::AnimationType> {
public:
TestInkDropHoverObserver();
~TestInkDropHoverObserver() override = default;
TestInkDropHighlightObserver();
~TestInkDropHighlightObserver() override = default;
void set_ink_drop_hover(InkDropHover* ink_drop_hover) {
ink_drop_hover_ = ink_drop_hover;
void set_ink_drop_highlight(InkDropHighlight* ink_drop_highlight) {
ink_drop_highlight_ = ink_drop_highlight;
}
// InkDropHoverObserver:
void AnimationStarted(InkDropHover::AnimationType animation_type) override;
void AnimationEnded(InkDropHover::AnimationType animation_type,
// InkDropHighlightObserver:
void AnimationStarted(
InkDropHighlight::AnimationType animation_type) override;
void AnimationEnded(InkDropHighlight::AnimationType animation_type,
InkDropAnimationEndedReason reason) override;
private:
// The type this inherits from. Reduces verbosity in .cc file.
using ObserverHelper =
TestInkDropAnimationObserverHelper<InkDropHover::AnimationType>;
TestInkDropAnimationObserverHelper<InkDropHighlight::AnimationType>;
// An InkDropHover to spy info from when notifications are handled.
InkDropHover* ink_drop_hover_ = nullptr;
// An InkDropHighlight to spy info from when notifications are handled.
InkDropHighlight* ink_drop_highlight_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(TestInkDropHoverObserver);
DISALLOW_COPY_AND_ASSIGN(TestInkDropHighlightObserver);
};
} // namespace test
} // namespace views
#endif // UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_HOVER_OBSERVER_H_
#endif // UI_VIEWS_ANIMATION_TEST_TEST_INK_DROP_HIGHLIGHT_OBSERVER_H_
......@@ -6,9 +6,9 @@
#include "base/memory/ptr_util.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/animation/ink_drop_hover.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/animation/square_ink_drop_ripple.h"
#include "ui/views/animation/test/ink_drop_hover_test_api.h"
#include "ui/views/animation/test/ink_drop_highlight_test_api.h"
#include "ui/views/animation/test/square_ink_drop_ripple_test_api.h"
namespace views {
......@@ -46,35 +46,35 @@ class TestInkDropRipple : public SquareInkDropRipple {
DISALLOW_COPY_AND_ASSIGN(TestInkDropRipple);
};
// Test specific subclass of InkDropHover that returns a test api from
// Test specific subclass of InkDropHighlight that returns a test api from
// GetTestApi().
class TestInkDropHover : public InkDropHover {
class TestInkDropHighlight : public InkDropHighlight {
public:
TestInkDropHover(const gfx::Size& size,
int corner_radius,
const gfx::Point& center_point,
SkColor color)
: InkDropHover(size, corner_radius, center_point, color) {}
TestInkDropHighlight(const gfx::Size& size,
int corner_radius,
const gfx::Point& center_point,
SkColor color)
: InkDropHighlight(size, corner_radius, center_point, color) {}
~TestInkDropHover() override {}
~TestInkDropHighlight() override {}
test::InkDropHoverTestApi* GetTestApi() override {
test::InkDropHighlightTestApi* GetTestApi() override {
if (!test_api_)
test_api_.reset(new test::InkDropHoverTestApi(this));
test_api_.reset(new test::InkDropHighlightTestApi(this));
return test_api_.get();
}
private:
std::unique_ptr<test::InkDropHoverTestApi> test_api_;
std::unique_ptr<test::InkDropHighlightTestApi> test_api_;
DISALLOW_COPY_AND_ASSIGN(TestInkDropHover);
DISALLOW_COPY_AND_ASSIGN(TestInkDropHighlight);
};
} // namespace
TestInkDropHost::TestInkDropHost()
: num_ink_drop_layers_(0),
should_show_hover_(false),
should_show_highlight_(false),
disable_timers_for_test_(false) {}
TestInkDropHost::~TestInkDropHost() {}
......@@ -96,15 +96,16 @@ std::unique_ptr<InkDropRipple> TestInkDropHost::CreateInkDropRipple() const {
return ripple;
}
std::unique_ptr<InkDropHover> TestInkDropHost::CreateInkDropHover() const {
std::unique_ptr<InkDropHover> hover;
if (should_show_hover_) {
hover.reset(new TestInkDropHover(gfx::Size(10, 10), 4, gfx::Point(),
SK_ColorBLACK));
std::unique_ptr<InkDropHighlight> TestInkDropHost::CreateInkDropHighlight()
const {
std::unique_ptr<InkDropHighlight> highlight;
if (should_show_highlight_) {
highlight.reset(new TestInkDropHighlight(gfx::Size(10, 10), 4, gfx::Point(),
SK_ColorBLACK));
if (disable_timers_for_test_)
hover->GetTestApi()->SetDisableAnimationTimers(true);
highlight->GetTestApi()->SetDisableAnimationTimers(true);
}
return hover;
return highlight;
}
} // namespace views
......@@ -19,8 +19,8 @@ class TestInkDropHost : public InkDropHost {
int num_ink_drop_layers() const { return num_ink_drop_layers_; }
void set_should_show_hover(bool should_show_hover) {
should_show_hover_ = should_show_hover;
void set_should_show_highlight(bool should_show_highlight) {
should_show_highlight_ = should_show_highlight;
}
void set_disable_timers_for_test(bool disable_timers_for_test) {
......@@ -31,14 +31,14 @@ class TestInkDropHost : public InkDropHost {
void AddInkDropLayer(ui::Layer* ink_drop_layer) override;
void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override;
std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<InkDropHover> CreateInkDropHover() const override;
std::unique_ptr<InkDropHighlight> CreateInkDropHighlight() const override;
private:
int num_ink_drop_layers_;
bool should_show_hover_;
bool should_show_highlight_;
// When true, the InkDropRipple/InkDropHover instances will have their
// When true, the InkDropRipple/InkDropHighlight instances will have their
// timers disabled after creation.
bool disable_timers_for_test_;
......
......@@ -13,7 +13,7 @@
#include "ui/gfx/color_palette.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/animation/ink_drop_delegate.h"
#include "ui/views/animation/ink_drop_hover.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/controls/button/blue_button.h"
#include "ui/views/controls/button/checkbox.h"
#include "ui/views/controls/button/image_button.h"
......@@ -136,7 +136,7 @@ void CustomButton::OnEnabledChanged() {
SetState(STATE_DISABLED);
if (ink_drop_delegate())
ink_drop_delegate()->SetHovered(ShouldShowInkDropHover());
ink_drop_delegate()->SetHovered(ShouldShowInkDropHighlight());
}
const char* CustomButton::GetClassName() const {
......@@ -354,8 +354,9 @@ void CustomButton::VisibilityChanged(View* starting_from, bool visible) {
SetState(visible && ShouldEnterHoveredState() ? STATE_HOVERED : STATE_NORMAL);
}
std::unique_ptr<InkDropHover> CustomButton::CreateInkDropHover() const {
return ShouldShowInkDropHover() ? Button::CreateInkDropHover() : nullptr;
std::unique_ptr<InkDropHighlight> CustomButton::CreateInkDropHighlight() const {
return ShouldShowInkDropHighlight() ? Button::CreateInkDropHighlight()
: nullptr;
}
SkColor CustomButton::GetInkDropBaseColor() const {
......@@ -430,7 +431,7 @@ bool CustomButton::ShouldEnterPushedState(const ui::Event& event) {
return IsTriggerableEvent(event);
}
bool CustomButton::ShouldShowInkDropHover() const {
bool CustomButton::ShouldShowInkDropHighlight() const {
return enabled() && !InDrag() &&
(IsMouseHovered() || (ShouldShowInkDropForFocus() && HasFocus()));
}
......
......@@ -110,7 +110,7 @@ class VIEWS_EXPORT CustomButton : public Button, public gfx::AnimationDelegate {
void OnDragDone() override;
void GetAccessibleState(ui::AXViewState* state) override;
void VisibilityChanged(View* starting_from, bool is_visible) override;
std::unique_ptr<InkDropHover> CreateInkDropHover() const override;
std::unique_ptr<InkDropHighlight> CreateInkDropHighlight() const override;
SkColor GetInkDropBaseColor() const override;
// Overridden from gfx::AnimationDelegate:
......@@ -141,8 +141,8 @@ class VIEWS_EXPORT CustomButton : public Button, public gfx::AnimationDelegate {
// we simply return IsTriggerableEvent(event).
virtual bool ShouldEnterPushedState(const ui::Event& event);
// Returns true if hover effect should be visible.
virtual bool ShouldShowInkDropHover() const;
// Returns true if highlight effect should be visible.
virtual bool ShouldShowInkDropHighlight() const;
void set_has_ink_drop_action_on_click(bool has_ink_drop_action_on_click) {
has_ink_drop_action_on_click_ = has_ink_drop_action_on_click;
......
......@@ -20,7 +20,7 @@
#include "ui/gfx/geometry/vector2d.h"
#include "ui/native_theme/native_theme.h"
#include "ui/views/animation/flood_fill_ink_drop_ripple.h"
#include "ui/views/animation/ink_drop_hover.h"
#include "ui/views/animation/ink_drop_highlight.h"
#include "ui/views/background.h"
#include "ui/views/controls/button/label_button_border.h"
#include "ui/views/painter.h"
......@@ -445,11 +445,12 @@ std::unique_ptr<views::InkDropRipple> LabelButton::CreateInkDropRipple() const {
GetInkDropBaseColor()));
}
std::unique_ptr<views::InkDropHover> LabelButton::CreateInkDropHover() const {
if (!ShouldShowInkDropHover())
std::unique_ptr<views::InkDropHighlight> LabelButton::CreateInkDropHighlight()
const {
if (!ShouldShowInkDropHighlight())
return nullptr;
return GetText().empty() ? CustomButton::CreateInkDropHover()
: base::WrapUnique(new views::InkDropHover(
return GetText().empty() ? CustomButton::CreateInkDropHighlight()
: base::WrapUnique(new views::InkDropHighlight(
size(), kInkDropSmallCornerRadius,
GetInkDropCenter(), GetInkDropBaseColor()));
}
......
......@@ -20,7 +20,7 @@
namespace views {
class InkDropRipple;
class InkDropHover;
class InkDropHighlight;
class LabelButtonBorder;
class Painter;
......@@ -105,7 +105,7 @@ class VIEWS_EXPORT LabelButton : public CustomButton,
void AddInkDropLayer(ui::Layer* ink_drop_layer) override;
void RemoveInkDropLayer(ui::Layer* ink_drop_layer) override;
std::unique_ptr<InkDropRipple> CreateInkDropRipple() const override;
std::unique_ptr<InkDropHover> CreateInkDropHover() const override;
std::unique_ptr<InkDropHighlight> CreateInkDropHighlight() const override;
gfx::Point GetInkDropCenter() const override;
protected:
......
......@@ -27,12 +27,12 @@
'animation/ink_drop_animation_ended_reason.h',
'animation/ink_drop_ripple_observer.h',
'animation/ink_drop_delegate.h',
'animation/ink_drop_highlight.cc',
'animation/ink_drop_highlight.h',
'animation/ink_drop_highlight_observer.h',
'animation/ink_drop_host.h',
'animation/ink_drop_host_view.cc',
'animation/ink_drop_host_view.h',
'animation/ink_drop_hover.cc',
'animation/ink_drop_hover.h',
'animation/ink_drop_hover_observer.h',
'animation/ink_drop_painted_layer_delegates.cc',
'animation/ink_drop_painted_layer_delegates.h',
'animation/ink_drop_state.cc',
......@@ -495,24 +495,24 @@
'views_test_support_sources': [
'animation/test/flood_fill_ink_drop_ripple_test_api.cc',
'animation/test/flood_fill_ink_drop_ripple_test_api.h',
'animation/test/ink_drop_ripple_test_api.cc',
'animation/test/ink_drop_ripple_test_api.h',
'animation/test/ink_drop_highlight_test_api.cc',
'animation/test/ink_drop_highlight_test_api.h',
'animation/test/ink_drop_impl_test_api.cc',
'animation/test/ink_drop_impl_test_api.h',
'animation/test/ink_drop_hover_test_api.cc',
'animation/test/ink_drop_hover_test_api.h',
'animation/test/ink_drop_ripple_test_api.cc',
'animation/test/ink_drop_ripple_test_api.h',
'animation/test/ink_drop_utils.cc',
'animation/test/square_ink_drop_ripple_test_api.cc',
'animation/test/square_ink_drop_ripple_test_api.h',
'animation/test/test_ink_drop_ripple_observer.cc',
'animation/test/test_ink_drop_ripple_observer.h',
'animation/test/test_ink_drop_animation_observer_helper.h',
'animation/test/test_ink_drop_host.cc',
'animation/test/test_ink_drop_host.h',
'animation/test/test_ink_drop_hover_observer.cc',
'animation/test/test_ink_drop_hover_observer.h',
'animation/test/test_ink_drop_delegate.cc',
'animation/test/test_ink_drop_delegate.h',
'animation/test/test_ink_drop_highlight_observer.cc',
'animation/test/test_ink_drop_highlight_observer.h',
'animation/test/test_ink_drop_host.cc',
'animation/test/test_ink_drop_host.h',
'animation/test/test_ink_drop_ripple_observer.cc',
'animation/test/test_ink_drop_ripple_observer.h',
'controls/textfield/textfield_test_api.cc',
'controls/textfield/textfield_test_api.h',
'test/capture_tracking_view.cc',
......@@ -575,9 +575,9 @@
'animation/bounds_animator_unittest.cc',
'animation/flood_fill_ink_drop_ripple_unittest.cc',
'animation/ink_drop_factory_unittest.cc',
'animation/ink_drop_highlight_unittest.cc',
'animation/ink_drop_impl_unittest.cc',
'animation/ink_drop_ripple_unittest.cc',
'animation/ink_drop_hover_unittest.cc',
'animation/square_ink_drop_ripple_unittest.cc',
'bubble/bubble_border_unittest.cc',
'bubble/bubble_dialog_delegate_unittest.cc',
......
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