Commit 29d3efeb authored by Richard Knoll's avatar Richard Knoll Committed by Commit Bot

Animate Click to Call icon text opacity.

After showing the "Sent to device" success message to the user, we want
to gradually fade out the message while collapsing the icon.

Bug: 986743
Change-Id: Ifb32d5c7b4e70b73fe68ba1f38e8bc04c18ed47e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1713534
Commit-Queue: Richard Knoll <knollr@chromium.org>
Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#679966}
parent e557c49c
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "chrome/browser/ui/views/sharing/click_to_call/click_to_call_dialog_view.h" #include "chrome/browser/ui/views/sharing/click_to_call/click_to_call_dialog_view.h"
#include "components/vector_icons/vector_icons.h" #include "components/vector_icons/vector_icons.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/material_design/material_design_controller.h"
#include "ui/gfx/animation/throb_animation.h" #include "ui/gfx/animation/throb_animation.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
...@@ -26,6 +27,10 @@ constexpr float kLoaderHeight = 4.0f; ...@@ -26,6 +27,10 @@ constexpr float kLoaderHeight = 4.0f;
// Width of the loader bar in percent of its range. // Width of the loader bar in percent of its range.
constexpr float kLoaderWidth = 0.2f; constexpr float kLoaderWidth = 0.2f;
// TODO(knollr): move these into IconLabelBubbleView.
constexpr int kIconTextSpacing = 8;
constexpr int kIconTextSpacingTouch = 10;
ClickToCallSharingDialogController* GetControllerFromWebContents( ClickToCallSharingDialogController* GetControllerFromWebContents(
content::WebContents* web_contents) { content::WebContents* web_contents) {
if (!web_contents) if (!web_contents)
...@@ -141,14 +146,33 @@ void ClickToCallIconView::PaintButtonContents(gfx::Canvas* canvas) { ...@@ -141,14 +146,33 @@ void ClickToCallIconView::PaintButtonContents(gfx::Canvas* canvas) {
canvas->DrawRoundRect(bounds, bounds.height() / 2, flags); canvas->DrawRoundRect(bounds, bounds.height() / 2, flags);
} }
double ClickToCallIconView::WidthMultiplier() const {
double multiplier = PageActionIconView::WidthMultiplier();
double min_width = image()->GetPreferredSize().width() + GetInsets().width();
double spacing = ui::MaterialDesignController::touch_ui()
? kIconTextSpacingTouch
: kIconTextSpacing;
double label_width = label()->GetPreferredSize().width();
double max_width = min_width + spacing + label_width;
// We offset the width multiplier to start expanding the label straight away
// instead of completely hide the icon and expanding it from zero width.
double offset = min_width / max_width;
return multiplier * (1 - offset) + offset;
}
void ClickToCallIconView::AnimationProgressed(const gfx::Animation* animation) { void ClickToCallIconView::AnimationProgressed(const gfx::Animation* animation) {
if (animation != loading_animation_.get()) if (animation != loading_animation_.get()) {
UpdateOpacity();
return PageActionIconView::AnimationProgressed(animation); return PageActionIconView::AnimationProgressed(animation);
}
SchedulePaint(); SchedulePaint();
} }
void ClickToCallIconView::AnimationEnded(const gfx::Animation* animation) { void ClickToCallIconView::AnimationEnded(const gfx::Animation* animation) {
PageActionIconView::AnimationEnded(animation); PageActionIconView::AnimationEnded(animation);
UpdateOpacity();
Update(); Update();
} }
...@@ -157,6 +181,22 @@ void ClickToCallIconView::OnThemeChanged() { ...@@ -157,6 +181,22 @@ void ClickToCallIconView::OnThemeChanged() {
UpdateLoaderColor(); UpdateLoaderColor();
} }
void ClickToCallIconView::UpdateOpacity() {
if (!IsShrinking()) {
DestroyLayer();
SetTextSubpixelRenderingEnabled(true);
return;
}
if (!layer()) {
SetPaintToLayer();
SetTextSubpixelRenderingEnabled(false);
layer()->SetFillsBoundsOpaquely(false);
}
layer()->SetOpacity(PageActionIconView::WidthMultiplier());
}
void ClickToCallIconView::UpdateInkDrop(bool activate) { void ClickToCallIconView::UpdateInkDrop(bool activate) {
auto target_state = auto target_state =
activate ? views::InkDropState::ACTIVATED : views::InkDropState::HIDDEN; activate ? views::InkDropState::ACTIVATED : views::InkDropState::HIDDEN;
......
...@@ -51,6 +51,7 @@ class ClickToCallIconView : public PageActionIconView { ...@@ -51,6 +51,7 @@ class ClickToCallIconView : public PageActionIconView {
const gfx::VectorIcon& GetVectorIcon() const override; const gfx::VectorIcon& GetVectorIcon() const override;
const gfx::VectorIcon& GetVectorIconBadge() const override; const gfx::VectorIcon& GetVectorIconBadge() const override;
bool IsTriggerableEvent(const ui::Event& event) override; bool IsTriggerableEvent(const ui::Event& event) override;
double WidthMultiplier() const override;
// gfx::AnimationDelegate: // gfx::AnimationDelegate:
void AnimationProgressed(const gfx::Animation* animation) override; void AnimationProgressed(const gfx::Animation* animation) override;
...@@ -59,6 +60,7 @@ class ClickToCallIconView : public PageActionIconView { ...@@ -59,6 +60,7 @@ class ClickToCallIconView : public PageActionIconView {
private: private:
void UpdateInkDrop(bool activate); void UpdateInkDrop(bool activate);
void UpdateLoaderColor(); void UpdateLoaderColor();
void UpdateOpacity();
SkColor loader_color_; SkColor loader_color_;
std::unique_ptr<gfx::ThrobAnimation> loading_animation_; std::unique_ptr<gfx::ThrobAnimation> loading_animation_;
......
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