Commit 1e740e13 authored by Peter Kasting's avatar Peter Kasting Committed by Commit Bot

Remove image button background alignment.

This was only set once, and the caller set it to the default behavior.

Bug: 957264
Change-Id: I13b47fe69e44fe8394bf22fe6433655023d1b4c7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1640604
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Commit-Queue: Ahmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Cr-Commit-Position: refs/heads/master@{#665707}
parent 91ec7eca
......@@ -37,8 +37,6 @@ CloseDeskButton::CloseDeskButton(views::ButtonListener* listener)
gfx::CreateVectorIcon(kDesksCloseDeskButtonIcon, SK_ColorWHITE));
SetImageHorizontalAlignment(views::ImageButton::ALIGN_CENTER);
SetImageVerticalAlignment(views::ImageButton::ALIGN_MIDDLE);
SetBackgroundImageAlignment(views::ImageButton::ALIGN_CENTER,
views::ImageButton::ALIGN_MIDDLE);
SetBackground(
CreateBackgroundFromPainter(views::Painter::CreateSolidRoundRectPainter(
kBackgroundColor, kCornerRadius)));
......
......@@ -94,13 +94,6 @@ void ImageButton::SetImageVerticalAlignment(VerticalAlignment v_alignment) {
OnPropertyChanged(&v_alignment_, kPropertyEffectsPaint);
}
void ImageButton::SetBackgroundImageAlignment(HorizontalAlignment h_align,
VerticalAlignment v_align) {
h_background_alignment_ = h_align;
v_background_alignment_ = v_align;
SchedulePaint();
}
gfx::Size ImageButton::GetMinimumImageSize() const {
return minimum_image_size_;
}
......@@ -160,20 +153,14 @@ void ImageButton::PaintButtonContents(gfx::Canvas* canvas) {
}
if (!background_image_.isNull()) {
// If the background image alignment was not set, use the image
// alignment.
HorizontalAlignment h_alignment =
h_background_alignment_.value_or(GetImageHorizontalAlignment());
VerticalAlignment v_alignment =
v_background_alignment_.value_or(GetImageVerticalAlignment());
gfx::Point background_position = ComputeImagePaintPosition(
background_image_, h_alignment, v_alignment);
// The background image alignment is the same as for the image.
gfx::Point background_position =
ComputeImagePaintPosition(background_image_);
canvas->DrawImageInt(background_image_, background_position.x(),
background_position.y());
}
gfx::Point position = ComputeImagePaintPosition(
img, GetImageHorizontalAlignment(), GetImageVerticalAlignment());
gfx::Point position = ComputeImagePaintPosition(img);
canvas->DrawImageInt(img, position.x(), position.y());
}
}
......@@ -199,12 +186,9 @@ gfx::ImageSkia ImageButton::GetImageToPaint() {
// ImageButton, private:
const gfx::Point ImageButton::ComputeImagePaintPosition(
const gfx::ImageSkia& image,
HorizontalAlignment h_alignment,
VerticalAlignment v_alignment) {
int x = 0, y = 0;
gfx::Rect rect = GetContentsBounds();
const gfx::ImageSkia& image) const {
HorizontalAlignment h_alignment = GetImageHorizontalAlignment();
VerticalAlignment v_alignment = GetImageVerticalAlignment();
if (draw_image_mirrored_) {
if (h_alignment == ALIGN_RIGHT)
h_alignment = ALIGN_LEFT;
......@@ -212,20 +196,21 @@ const gfx::Point ImageButton::ComputeImagePaintPosition(
h_alignment = ALIGN_RIGHT;
}
const gfx::Rect rect = GetContentsBounds();
int x = 0;
if (h_alignment == ALIGN_CENTER)
x = (rect.width() - image.width()) / 2;
else if (h_alignment == ALIGN_RIGHT)
x = rect.width() - image.width();
int y = 0;
if (v_alignment == ALIGN_MIDDLE)
y = (rect.height() - image.height()) / 2;
else if (v_alignment == ALIGN_BOTTOM)
y = rect.height() - image.height();
x += rect.x();
y += rect.y();
return gfx::Point(x, y);
return rect.origin() + gfx::Vector2d(x, y);
}
////////////////////////////////////////////////////////////////////////////////
......
......@@ -53,7 +53,8 @@ class VIEWS_EXPORT ImageButton : public Button {
// consolidated.
virtual void SetImage(ButtonState state, const gfx::ImageSkia& image);
// Set the background details.
// Set the background details. The background image uses the same alignment
// as the image.
void SetBackgroundImage(SkColor color,
const gfx::ImageSkia* image,
const gfx::ImageSkia* mask);
......@@ -64,10 +65,6 @@ class VIEWS_EXPORT ImageButton : public Button {
void SetImageHorizontalAlignment(HorizontalAlignment h_alignment);
void SetImageVerticalAlignment(VerticalAlignment v_alignment);
// Sets how the background is laid out within the button's bounds.
void SetBackgroundImageAlignment(HorizontalAlignment h_align,
VerticalAlignment v_align);
// The minimum size of the contents (not including the border). The contents
// will be at least this size, but may be larger if the image itself is
// larger.
......@@ -110,20 +107,13 @@ class VIEWS_EXPORT ImageButton : public Button {
FRIEND_TEST_ALL_PREFIXES(ImageButtonFactoryTest, CreateVectorImageButton);
// Returns the correct position of the image for painting.
const gfx::Point ComputeImagePaintPosition(const gfx::ImageSkia& image,
HorizontalAlignment h_alignment,
VerticalAlignment v_alignment);
const gfx::Point ComputeImagePaintPosition(const gfx::ImageSkia& image) const;
// Image alignment.
HorizontalAlignment h_alignment_ = ALIGN_LEFT;
VerticalAlignment v_alignment_ = ALIGN_TOP;
gfx::Size minimum_image_size_;
// Background alignment. If these are not set, the background image uses the
// image alignment.
base::Optional<HorizontalAlignment> h_background_alignment_;
base::Optional<VerticalAlignment> v_background_alignment_;
// Whether we draw our resources horizontally flipped. This can happen in the
// linux titlebar, where image resources were designed to be flipped so a
// small curved corner in the close button designed to fit into the frame
......
......@@ -39,13 +39,6 @@ class Parent : public views::View {
namespace views {
namespace {
const ImageButton::HorizontalAlignment kDefaultHorizontalAlignment =
ImageButton::ALIGN_LEFT;
const ImageButton::VerticalAlignment kDefaultVerticalAlignment =
ImageButton::ALIGN_TOP;
} // namespace
using ImageButtonTest = ViewsTestBase;
TEST_F(ImageButtonTest, Basics) {
......@@ -128,30 +121,20 @@ TEST_F(ImageButtonTest, ImagePositionWithBorder) {
button.SetImage(Button::STATE_NORMAL, &image);
// The image should be painted at the top-left corner.
EXPECT_EQ(gfx::Point(),
button.ComputeImagePaintPosition(image, kDefaultHorizontalAlignment,
kDefaultVerticalAlignment));
EXPECT_EQ(gfx::Point(), button.ComputeImagePaintPosition(image));
button.SetBorder(views::CreateEmptyBorder(10, 5, 0, 0));
EXPECT_EQ(gfx::Point(5, 10),
button.ComputeImagePaintPosition(image, kDefaultHorizontalAlignment,
kDefaultVerticalAlignment));
EXPECT_EQ(gfx::Point(5, 10), button.ComputeImagePaintPosition(image));
button.SetBorder(NullBorder());
button.SetBounds(0, 0, 50, 50);
EXPECT_EQ(gfx::Point(),
button.ComputeImagePaintPosition(image, kDefaultHorizontalAlignment,
kDefaultVerticalAlignment));
EXPECT_EQ(gfx::Point(), button.ComputeImagePaintPosition(image));
button.SetImageHorizontalAlignment(ImageButton::ALIGN_CENTER);
button.SetImageVerticalAlignment(ImageButton::ALIGN_MIDDLE);
EXPECT_EQ(gfx::Point(15, 10),
button.ComputeImagePaintPosition(image, ImageButton::ALIGN_CENTER,
ImageButton::ALIGN_MIDDLE));
EXPECT_EQ(gfx::Point(15, 10), button.ComputeImagePaintPosition(image));
button.SetBorder(views::CreateEmptyBorder(10, 10, 0, 0));
EXPECT_EQ(gfx::Point(20, 15),
button.ComputeImagePaintPosition(image, ImageButton::ALIGN_CENTER,
ImageButton::ALIGN_MIDDLE));
EXPECT_EQ(gfx::Point(20, 15), button.ComputeImagePaintPosition(image));
// The entire button's size should take the border into account.
EXPECT_EQ(gfx::Size(30, 40), button.GetPreferredSize());
......@@ -171,9 +154,7 @@ TEST_F(ImageButtonTest, LeftAlignedMirrored) {
// Because the coordinates are flipped, we should expect this to draw as if
// it were ALIGN_RIGHT.
EXPECT_EQ(gfx::Point(30, 0),
button.ComputeImagePaintPosition(image, ImageButton::ALIGN_LEFT,
ImageButton::ALIGN_BOTTOM));
EXPECT_EQ(gfx::Point(30, 0), button.ComputeImagePaintPosition(image));
}
TEST_F(ImageButtonTest, RightAlignedMirrored) {
......@@ -187,9 +168,7 @@ TEST_F(ImageButtonTest, RightAlignedMirrored) {
// Because the coordinates are flipped, we should expect this to draw as if
// it were ALIGN_LEFT.
EXPECT_EQ(gfx::Point(0, 0),
button.ComputeImagePaintPosition(image, ImageButton::ALIGN_RIGHT,
ImageButton::ALIGN_BOTTOM));
EXPECT_EQ(gfx::Point(0, 0), button.ComputeImagePaintPosition(image));
}
TEST_F(ImageButtonTest, PreferredSizeInvalidation) {
......
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