Commit 5bb27fba authored by bruthig's avatar bruthig Committed by Commit bot

Fixed material design ink drop location for the MD download shelf buttons.

A recent regression caused the clip bounds for the
FloodFillInkDropAnimation to incorrectly be centered on the click point
for the DownloadItemViewMd buttons. This change fixes that and
suppresses the ripple for right clicks on the DownloadItemViewMd as
well.

BUG=603818
TEST=manual

Review-Url: https://codereview.chromium.org/1915983009
Cr-Commit-Position: refs/heads/master@{#390347}
parent 30bdfc40
......@@ -88,6 +88,7 @@
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_utils.h"
#include "ui/gfx/favicon_size.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/scoped_canvas.h"
#include "ui/gfx/text_constants.h"
......@@ -189,10 +190,10 @@ int GetHorizontalMargin() {
return kHorizontalMargin[ui::MaterialDesignController::GetMode()];
}
gfx::Size CalculateInkDropSize(const gfx::Size& button_size) {
gfx::Size ink_drop_size(button_size);
ink_drop_size.Enlarge(0, -2);
return ink_drop_size;
gfx::Rect CalculateInkDropBounds(const gfx::Size& size) {
gfx::Rect ink_drop_bounds(size);
ink_drop_bounds.Inset(0, 1);
return ink_drop_bounds;
}
// BookmarkButtonBase -----------------------------------------------
......@@ -240,16 +241,17 @@ class BookmarkButtonBase : public views::LabelButton {
std::unique_ptr<views::InkDropAnimation> CreateInkDropAnimation()
const override {
return base::WrapUnique(new views::FloodFillInkDropAnimation(
CalculateInkDropSize(size()), GetInkDropCenter(),
CalculateInkDropBounds(size()), GetInkDropCenter(),
GetInkDropBaseColor()));
}
std::unique_ptr<views::InkDropHover> CreateInkDropHover() const override {
if (!ShouldShowInkDropHover())
return nullptr;
return base::WrapUnique(
new views::InkDropHover(CalculateInkDropSize(size()), 0,
GetInkDropCenter(), GetInkDropBaseColor()));
const gfx::Rect bounds = CalculateInkDropBounds(size());
return base::WrapUnique(new views::InkDropHover(
bounds.size(), 0, bounds.CenterPoint(), GetInkDropBaseColor()));
}
SkColor GetInkDropBaseColor() const override {
......@@ -341,16 +343,17 @@ class BookmarkMenuButtonBase : public views::MenuButton {
std::unique_ptr<views::InkDropAnimation> CreateInkDropAnimation()
const override {
return base::WrapUnique(new views::FloodFillInkDropAnimation(
CalculateInkDropSize(size()), GetInkDropCenter(),
CalculateInkDropBounds(size()), GetInkDropCenter(),
GetInkDropBaseColor()));
}
std::unique_ptr<views::InkDropHover> CreateInkDropHover() const override {
if (!ShouldShowInkDropHover())
return nullptr;
return base::WrapUnique(
new views::InkDropHover(CalculateInkDropSize(size()), 0,
GetInkDropCenter(), GetInkDropBaseColor()));
const gfx::Rect bounds = CalculateInkDropBounds(size());
return base::WrapUnique(new views::InkDropHover(
bounds.size(), 0, bounds.CenterPoint(), GetInkDropBaseColor()));
}
SkColor GetInkDropBaseColor() const override {
......
......@@ -476,7 +476,7 @@ void DownloadItemViewMd::AddInkDropLayer(ui::Layer* ink_drop_layer) {
std::unique_ptr<views::InkDropAnimation>
DownloadItemViewMd::CreateInkDropAnimation() const {
return base::WrapUnique(new views::FloodFillInkDropAnimation(
size(), ink_drop_delegate_.last_ink_drop_location(),
GetLocalBounds(), ink_drop_delegate_.last_ink_drop_location(),
color_utils::DeriveDefaultIconColor(GetTextColor())));
}
......@@ -835,6 +835,10 @@ void DownloadItemViewMd::HandlePressEvent(const ui::LocatedEvent& event,
if (complete_animation_.get() && complete_animation_->is_animating())
complete_animation_->End();
// Don't show the ripple for right clicks.
if (!active_event)
return;
ink_drop_delegate_.set_last_ink_drop_location(event.location());
ink_drop_delegate_.OnAction(views::InkDropState::ACTION_PENDING);
}
......
......@@ -107,26 +107,22 @@ base::TimeDelta GetAnimationDuration(InkDropSubAnimations state) {
namespace views {
FloodFillInkDropAnimation::FloodFillInkDropAnimation(
const gfx::Size& size,
const gfx::Rect& clip_bounds,
const gfx::Point& center_point,
SkColor color)
: size_(size),
: clip_bounds_(clip_bounds),
center_point_(center_point),
root_layer_(ui::LAYER_NOT_DRAWN),
circle_layer_delegate_(color,
std::max(size_.width(), size_.height()) / 2.f),
circle_layer_delegate_(
color,
std::max(clip_bounds_.width(), clip_bounds_.height()) / 2.f),
ink_drop_state_(InkDropState::HIDDEN) {
root_layer_.set_name("FloodFillInkDropAnimation:ROOT_LAYER");
root_layer_.SetMasksToBounds(true);
root_layer_.SetBounds(gfx::Rect(size_));
root_layer_.SetBounds(clip_bounds);
const gfx::Vector2dF translate_vector =
center_point_ - root_layer_.bounds().CenterPoint();
gfx::Transform transfrom;
transfrom.Translate(translate_vector.x(), translate_vector.y());
root_layer_.SetTransform(transfrom);
const int painted_size_length = 2 * std::max(size_.width(), size_.height());
const int painted_size_length =
2 * std::max(clip_bounds_.width(), clip_bounds_.height());
painted_layer_.SetBounds(gfx::Rect(painted_size_length, painted_size_length));
painted_layer_.SetFillsBoundsOpaquely(false);
......@@ -313,10 +309,10 @@ gfx::Transform FloodFillInkDropAnimation::CalculateTransform(
ToRoundedPoint(circle_layer_delegate_.GetCenterPoint());
gfx::Transform transform = gfx::Transform();
transform.Translate(root_layer_.bounds().CenterPoint().x(),
root_layer_.bounds().CenterPoint().y());
transform.Translate(center_point_.x(), center_point_.y());
transform.Scale(target_scale, target_scale);
transform.Translate(-drawn_center_point.x(), -drawn_center_point.y());
transform.Translate(-drawn_center_point.x() - root_layer_.bounds().x(),
-drawn_center_point.y() - root_layer_.bounds().y());
return transform;
}
......@@ -325,7 +321,7 @@ gfx::Transform FloodFillInkDropAnimation::GetMaxSizeTargetTransform() const {
// TODO(estade): get rid of this 2, but make the fade out start before the
// active/action transform is done.
return CalculateTransform(
gfx::Vector2dF(size_.width(), size_.height()).Length() / 2);
gfx::Vector2dF(clip_bounds_.width(), clip_bounds_.height()).Length() / 2);
}
} // namespace views
......@@ -48,7 +48,7 @@ class FloodFillInkDropAnimationTestApi;
//
class VIEWS_EXPORT FloodFillInkDropAnimation : public InkDropAnimation {
public:
FloodFillInkDropAnimation(const gfx::Size& size,
FloodFillInkDropAnimation(const gfx::Rect& clip_bounds,
const gfx::Point& center_point,
SkColor color);
~FloodFillInkDropAnimation() override;
......@@ -101,8 +101,8 @@ class VIEWS_EXPORT FloodFillInkDropAnimation : public InkDropAnimation {
// Returns the target Transform for when the ink drop is fully shown.
gfx::Transform GetMaxSizeTargetTransform() const;
// The clip Size.
const gfx::Size size_;
// The clip bounds.
const gfx::Rect clip_bounds_;
// The point where the Center of the ink drop's circle should be drawn.
gfx::Point center_point_;
......
......@@ -69,7 +69,7 @@ InkDropAnimationTest::InkDropAnimationTest() {
}
case FLOOD_FILL_INK_DROP_ANIMATION: {
FloodFillInkDropAnimation* flood_fill_ink_drop_animation =
new FloodFillInkDropAnimation(gfx::Size(10, 10), gfx::Point(),
new FloodFillInkDropAnimation(gfx::Rect(0, 0, 10, 10), gfx::Point(),
SK_ColorBLACK);
ink_drop_animation_.reset(flood_fill_ink_drop_animation);
test_api_.reset(
......
......@@ -424,7 +424,8 @@ std::unique_ptr<views::InkDropAnimation> LabelButton::CreateInkDropAnimation()
return GetText().empty()
? CustomButton::CreateInkDropAnimation()
: base::WrapUnique(new views::FloodFillInkDropAnimation(
size(), GetInkDropCenter(), GetInkDropBaseColor()));
GetLocalBounds(), GetInkDropCenter(),
GetInkDropBaseColor()));
}
std::unique_ptr<views::InkDropHover> LabelButton::CreateInkDropHover() const {
......
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