Commit 60822cde authored by Katie D's avatar Katie D Committed by Commit Bot

Fades autoclick scroll position icon so content is not obscured.

Fades icon to a lower opacity in order that content behind the icon
is still partially visible. Per UX request.

Bug: 947068
Change-Id: I36d61f461af622c24cb1bf442c823730143e2a9b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1662829Reviewed-by: default avatarAnastasia Helfinstein <anastasi@google.com>
Commit-Queue: Katie Dektar <katie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#669846}
parent 99b181b5
......@@ -10,6 +10,7 @@
#include "third_party/skia/include/core/SkRect.h"
#include "ui/aura/window.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/animation/linear_animation.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/paint_vector_icon.h"
......@@ -19,9 +20,12 @@
namespace ash {
namespace {
int kScrollBackgroundSizeInDips = 32;
int kScrollIconSizeInDips = 24;
SkColor kIconBackgroundColor = SkColorSetARGB(255, 128, 134, 139);
constexpr int kScrollBackgroundSizeInDips = 32;
constexpr int kScrollIconSizeInDips = 24;
constexpr SkColor kIconBackgroundColor = SkColorSetARGB(255, 128, 134, 139);
constexpr base::TimeDelta kAnimationTime =
base::TimeDelta::FromMilliseconds(500);
constexpr float kFadedOpacity = 0.5;
} // namespace
// View of the AutoclickScrollPositionHandler. Draws the actual contents and
......@@ -52,9 +56,14 @@ class AutoclickScrollPositionView : public views::View {
kScrollBackgroundSizeInDips,
kScrollBackgroundSizeInDips));
widget_->Show();
widget_->SetOpacity(1.0);
SchedulePaint();
}
void UpdateForAnimationStep(gfx::Animation* animation) {
widget_->SetOpacity(animation->CurrentValueBetween(1.0, kFadedOpacity));
}
private:
void OnPaint(gfx::Canvas* canvas) override {
gfx::Point center(kScrollBackgroundSizeInDips / 2,
......@@ -84,9 +93,13 @@ class AutoclickScrollPositionView : public views::View {
AutoclickScrollPositionHandler::AutoclickScrollPositionHandler(
const gfx::Point& center_point_in_screen,
views::Widget* widget) {
views::Widget* widget)
: gfx::LinearAnimation(nullptr) {
view_ = std::make_unique<AutoclickScrollPositionView>(center_point_in_screen,
widget);
SetDuration(kAnimationTime);
animation_state_ = AnimationState::kWait;
Start();
}
AutoclickScrollPositionHandler::~AutoclickScrollPositionHandler() {
......@@ -97,6 +110,22 @@ void AutoclickScrollPositionHandler::SetCenter(
const gfx::Point& center_point_in_screen,
views::Widget* widget) {
view_->SetLocation(center_point_in_screen);
animation_state_ = AnimationState::kWait;
Start();
}
void AutoclickScrollPositionHandler::AnimateToState(double state) {
if (animation_state_ == AnimationState::kFade)
view_->UpdateForAnimationStep(this);
}
void AutoclickScrollPositionHandler::AnimationStopped() {
if (animation_state_ == AnimationState::kWait) {
animation_state_ = AnimationState::kFade;
Start();
} else if (animation_state_ == AnimationState::kFade) {
animation_state_ = AnimationState::kDone;
}
}
} // namespace ash
......@@ -8,6 +8,7 @@
#include <memory>
#include "base/macros.h"
#include "ui/gfx/animation/linear_animation.h"
#include "ui/gfx/geometry/point.h"
#include "ui/views/widget/widget.h"
......@@ -17,18 +18,30 @@ class AutoclickScrollPositionView;
// AutoclickScrollPositionHandler displays the position at which the next scroll
// event will occur, giving users a sense of which part of the screen will
// receive scroll events.
class AutoclickScrollPositionHandler {
// receive scroll events. It will display at full opacity for a short time, then
// partially fade out to keep from blocking content.
class AutoclickScrollPositionHandler : public gfx::LinearAnimation {
public:
AutoclickScrollPositionHandler(const gfx::Point& center_point_in_screen,
views::Widget* widget);
~AutoclickScrollPositionHandler();
~AutoclickScrollPositionHandler() override;
void SetCenter(const gfx::Point& center_point_in_screen,
views::Widget* widget);
private:
enum AnimationState {
kWait,
kFade,
kDone,
};
// Overridden from gfx::LinearAnimation.
void AnimateToState(double state) override;
void AnimationStopped() override;
std::unique_ptr<AutoclickScrollPositionView> view_;
AnimationState animation_state_ = kDone;
DISALLOW_COPY_AND_ASSIGN(AutoclickScrollPositionHandler);
};
......
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