Skip to content

Commit

Permalink
MdTextButton updates, round 2
Browse files Browse the repository at this point in the history
1. Adjust focus ring
2. Add shadow effect for hover of call-to-action buttons.

BUG=571500

Review-Url: https://codereview.chromium.org/2078053003
Cr-Commit-Position: refs/heads/master@{#401506}
  • Loading branch information
estade authored and Commit bot committed Jun 23, 2016
1 parent e8defdc commit 978a139
Show file tree
Hide file tree
Showing 13 changed files with 292 additions and 111 deletions.
2 changes: 1 addition & 1 deletion chrome/browser/ui/views/download/download_item_view_md.cc
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ void DownloadItemViewMd::OnPaint(gfx::Canvas* canvas) {
OnPaintBorder(canvas);

if (HasFocus())
views::MdTextButton::PaintMdFocusRing(canvas, this);
views::MdTextButton::PaintMdFocusRing(canvas, this, 1, SK_AlphaOPAQUE);
}

int DownloadItemViewMd::GetYForFilenameText() const {
Expand Down
7 changes: 4 additions & 3 deletions ui/views/animation/flood_fill_ink_drop_ripple.cc
Original file line number Diff line number Diff line change
Expand Up @@ -306,14 +306,15 @@ void FloodFillInkDropRipple::AnimateToOpacity(
gfx::Transform FloodFillInkDropRipple::CalculateTransform(
float target_radius) const {
const float target_scale = target_radius / circle_layer_delegate_.radius();
const gfx::Point drawn_center_point =
ToRoundedPoint(circle_layer_delegate_.GetCenterPoint());

gfx::Transform transform = gfx::Transform();
transform.Translate(center_point_.x() - root_layer_.bounds().x(),
center_point_.y() - root_layer_.bounds().y());
transform.Scale(target_scale, target_scale);
transform.Translate(-drawn_center_point.x(), -drawn_center_point.y());

const gfx::Vector2dF drawn_center_offset =
circle_layer_delegate_.GetCenteringOffset();
transform.Translate(-drawn_center_offset.x(), -drawn_center_offset.y());

return transform;
}
Expand Down
43 changes: 26 additions & 17 deletions ui/views/animation/ink_drop_highlight.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,14 @@
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_sequence.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/gfx/geometry/insets.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 highlight when it is visible.
const float kHighlightVisibleOpacity = 0.128f;

// The opacity of the highlight when it is not visible.
const float kHiddenOpacity = 0.0f;

Expand All @@ -36,27 +34,38 @@ std::string ToString(InkDropHighlight::AnimationType animation_type) {
return std::string("UNKNOWN");
}

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),
InkDropHighlight::InkDropHighlight(
const gfx::Point& center_point,
std::unique_ptr<BasePaintedLayerDelegate> layer_delegate)
: center_point_(center_point),
visible_opacity_(1.f),
last_animation_initiated_was_fade_in_(false),
layer_delegate_(
new RoundedRectangleLayerDelegate(color, size, corner_radius)),
layer_delegate_(std::move(layer_delegate)),
layer_(new ui::Layer()),
observer_(nullptr) {
layer_->SetBounds(gfx::Rect(size));
const gfx::Rect layer_bounds = layer_delegate_->GetPaintedBounds();
size_ = explode_size_ = layer_bounds.size();

layer_->SetBounds(layer_bounds);
layer_->SetFillsBoundsOpaquely(false);
layer_->set_delegate(layer_delegate_.get());
layer_->SetVisible(false);
layer_->SetOpacity(kHighlightVisibleOpacity);
layer_->SetMasksToBounds(false);
layer_->set_name("InkDropHighlight:layer");
}

InkDropHighlight::InkDropHighlight(const gfx::Size& size,
int corner_radius,
const gfx::Point& center_point,
SkColor color)
: InkDropHighlight(
center_point,
std::unique_ptr<BasePaintedLayerDelegate>(
new RoundedRectangleLayerDelegate(color, size, corner_radius))) {
visible_opacity_ = 0.128f;
layer_->SetOpacity(visible_opacity_);
}

InkDropHighlight::~InkDropHighlight() {}

bool InkDropHighlight::IsFadingInOrVisible() const {
Expand Down Expand Up @@ -102,7 +111,7 @@ void InkDropHighlight::AnimateFade(AnimationType animation_type,

ui::LayerAnimationElement* opacity_element =
ui::LayerAnimationElement::CreateOpacityElement(
animation_type == FADE_IN ? kHighlightVisibleOpacity : kHiddenOpacity,
animation_type == FADE_IN ? visible_opacity_ : kHiddenOpacity,
duration);
ui::LayerAnimationSequence* opacity_sequence =
new ui::LayerAnimationSequence(opacity_element);
Expand All @@ -127,8 +136,8 @@ gfx::Transform InkDropHighlight::CalculateTransform(
gfx::Transform transform;
transform.Translate(center_point_.x(), center_point_.y());
transform.Scale(size.width() / size_.width(), size.height() / size_.height());
transform.Translate(-layer_delegate_->GetCenterPoint().x(),
-layer_delegate_->GetCenterPoint().y());
gfx::Vector2dF layer_offset = layer_delegate_->GetCenteringOffset();
transform.Translate(-layer_offset.x(), -layer_offset.y());
return transform;
}

Expand Down
17 changes: 15 additions & 2 deletions ui/views/animation/ink_drop_highlight.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
#include "ui/gfx/transform.h"
#include "ui/views/views_export.h"

namespace gfx {
class Rect;
}

namespace ui {
class Layer;
class CallbackLayerAnimationObserver;
Expand All @@ -27,7 +31,7 @@ namespace test {
class InkDropHighlightTestApi;
} // namespace test

class RoundedRectangleLayerDelegate;
class BasePaintedLayerDelegate;
class InkDropHighlightObserver;

// Manages fade in/out animations for a painted Layer that is used to provide
Expand All @@ -37,6 +41,12 @@ class VIEWS_EXPORT InkDropHighlight {
public:
enum AnimationType { FADE_IN, FADE_OUT };

// Creates a highlight with a specified painter.
InkDropHighlight(const gfx::Point& center_point,
std::unique_ptr<BasePaintedLayerDelegate> layer_delegate);

// Creates a highlight that paints a partially transparent roundrect with
// color |color|.
InkDropHighlight(const gfx::Size& size,
int corner_radius,
const gfx::Point& center_point,
Expand Down Expand Up @@ -104,12 +114,15 @@ class VIEWS_EXPORT InkDropHighlight {
// space.
gfx::PointF center_point_;

// 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
// otherwise.
bool last_animation_initiated_was_fade_in_;

// The LayerDelegate that paints the highlight |layer_|.
std::unique_ptr<RoundedRectangleLayerDelegate> layer_delegate_;
std::unique_ptr<BasePaintedLayerDelegate> layer_delegate_;

// The visual highlight layer that is painted by |layer_delegate_|.
std::unique_ptr<ui::Layer> layer_;
Expand Down
92 changes: 78 additions & 14 deletions ui/views/animation/ink_drop_painted_layer_delegates.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,18 @@

#include "ui/views/animation/ink_drop_painted_layer_delegates.h"

#include "third_party/skia/include/core/SkDrawLooper.h"
#include "third_party/skia/include/core/SkPaint.h"
#include "third_party/skia/include/core/SkPath.h"
#include "ui/compositor/paint_recorder.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_palette.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/point_conversions.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/rect_f.h"
#include "ui/gfx/skia_util.h"

namespace views {

Expand All @@ -22,6 +29,10 @@ BasePaintedLayerDelegate::BasePaintedLayerDelegate(SkColor color)

BasePaintedLayerDelegate::~BasePaintedLayerDelegate() {}

gfx::Vector2dF BasePaintedLayerDelegate::GetCenteringOffset() const {
return gfx::RectF(GetPaintedBounds()).CenterPoint().OffsetFromOrigin();
}

void BasePaintedLayerDelegate::OnDelegatedFrameDamage(
const gfx::Rect& damage_rect_in_dip) {}

Expand All @@ -42,8 +53,9 @@ CircleLayerDelegate::CircleLayerDelegate(SkColor color, int radius)

CircleLayerDelegate::~CircleLayerDelegate() {}

gfx::PointF CircleLayerDelegate::GetCenterPoint() const {
return gfx::PointF(radius_, radius_);
gfx::Rect CircleLayerDelegate::GetPaintedBounds() const {
const int diameter = radius_ * 2;
return gfx::Rect(0, 0, diameter, diameter);
}

void CircleLayerDelegate::OnPaintLayer(const ui::PaintContext& context) {
Expand All @@ -52,10 +64,10 @@ void CircleLayerDelegate::OnPaintLayer(const ui::PaintContext& context) {
paint.setFlags(SkPaint::kAntiAlias_Flag);
paint.setStyle(SkPaint::kFill_Style);

ui::PaintRecorder recorder(context, gfx::Size(2 * radius_, 2 * radius_));
ui::PaintRecorder recorder(context, GetPaintedBounds().size());
gfx::Canvas* canvas = recorder.canvas();

canvas->DrawCircle(ToRoundedPoint(GetCenterPoint()), radius_, paint);
canvas->DrawCircle(GetPaintedBounds().CenterPoint(), radius_, paint);
}

////////////////////////////////////////////////////////////////////////////////
Expand All @@ -68,8 +80,8 @@ RectangleLayerDelegate::RectangleLayerDelegate(SkColor color, gfx::Size size)

RectangleLayerDelegate::~RectangleLayerDelegate() {}

gfx::PointF RectangleLayerDelegate::GetCenterPoint() const {
return gfx::PointF(size_.width() / 2.0f, size_.height() / 2.0f);
gfx::Rect RectangleLayerDelegate::GetPaintedBounds() const {
return gfx::Rect(size_);
}

void RectangleLayerDelegate::OnPaintLayer(const ui::PaintContext& context) {
Expand All @@ -80,25 +92,26 @@ void RectangleLayerDelegate::OnPaintLayer(const ui::PaintContext& context) {

ui::PaintRecorder recorder(context, size_);
gfx::Canvas* canvas = recorder.canvas();
canvas->DrawRect(gfx::Rect(size_), paint);
canvas->DrawRect(GetPaintedBounds(), paint);
}

////////////////////////////////////////////////////////////////////////////////
//
// RoundedRectangleLayerDelegate
//

RoundedRectangleLayerDelegate::RoundedRectangleLayerDelegate(SkColor color,
gfx::Size size,
int corner_radius)
RoundedRectangleLayerDelegate::RoundedRectangleLayerDelegate(
SkColor color,
const gfx::Size& size,
int corner_radius)
: BasePaintedLayerDelegate(color),
size_(size),
corner_radius_(corner_radius) {}

RoundedRectangleLayerDelegate::~RoundedRectangleLayerDelegate() {}

gfx::PointF RoundedRectangleLayerDelegate::GetCenterPoint() const {
return gfx::RectF(gfx::SizeF(size_)).CenterPoint();
gfx::Rect RoundedRectangleLayerDelegate::GetPaintedBounds() const {
return gfx::Rect(size_);
}

void RoundedRectangleLayerDelegate::OnPaintLayer(
Expand All @@ -109,8 +122,59 @@ void RoundedRectangleLayerDelegate::OnPaintLayer(
paint.setStyle(SkPaint::kFill_Style);

ui::PaintRecorder recorder(context, size_);
gfx::Canvas* canvas = recorder.canvas();
canvas->DrawRoundRect(gfx::Rect(size_), corner_radius_, paint);
recorder.canvas()->DrawRoundRect(GetPaintedBounds(), corner_radius_, paint);
}

////////////////////////////////////////////////////////////////////////////////
//
// BorderShadowLayerDelegate
//

BorderShadowLayerDelegate::BorderShadowLayerDelegate(
const std::vector<gfx::ShadowValue>& shadows,
const gfx::Rect& shadowed_area_bounds,
int corner_radius)
: BasePaintedLayerDelegate(gfx::kPlaceholderColor),
shadows_(shadows),
bounds_(shadowed_area_bounds),
corner_radius_(corner_radius) {}

BorderShadowLayerDelegate::~BorderShadowLayerDelegate() {}

gfx::Rect BorderShadowLayerDelegate::GetPaintedBounds() const {
gfx::Rect total_rect(bounds_);
total_rect.Inset(gfx::ShadowValue::GetMargin(shadows_));
return total_rect;
}

gfx::Vector2dF BorderShadowLayerDelegate::GetCenteringOffset() const {
return gfx::RectF(bounds_).CenterPoint().OffsetFromOrigin();
}

void BorderShadowLayerDelegate::OnPaintLayer(const ui::PaintContext& context) {
SkPaint paint;
paint.setLooper(gfx::CreateShadowDrawLooper(shadows_));
paint.setStyle(SkPaint::kStrokeAndFill_Style);
paint.setAntiAlias(true);
paint.setColor(SK_ColorTRANSPARENT);
paint.setStrokeJoin(SkPaint::kRound_Join);
gfx::RectF bounds(bounds_);
bounds -= GetPaintedBounds().OffsetFromOrigin();
gfx::RectF stroke_bounds = bounds;
stroke_bounds.Inset(-gfx::InsetsF(0.5f));

ui::PaintRecorder recorder(context, GetPaintedBounds().size());
const SkScalar corner = SkFloatToScalar(corner_radius_);
SkPath path;
path.addRoundRect(gfx::RectFToSkRect(stroke_bounds), corner, corner,
SkPath::kCCW_Direction);
recorder.canvas()->DrawPath(path, paint);

SkPaint clear_paint;
clear_paint.setAntiAlias(true);
clear_paint.setXfermodeMode(SkXfermode::kClear_Mode);
recorder.canvas()->sk_canvas()->drawRoundRect(gfx::RectFToSkRect(bounds),
corner, corner, clear_paint);
}

} // namespace views
Loading

0 comments on commit 978a139

Please sign in to comment.