diff options
author | Steve Kobes <skobes@chromium.org> | 2015-11-02 10:06:40 -0800 |
---|---|---|
committer | Steve Kobes <skobes@chromium.org> | 2015-11-02 18:07:58 +0000 |
commit | 41cd3396af44d63fecc664d1242f73308954678d (patch) | |
tree | 969f4c593721b86fbf2724e5a1f82ac556f8548d | |
parent | 1c08373f4881eda9685aa1ad96656bb5fe0f1301 (diff) | |
download | chromium_src-41cd3396af44d63fecc664d1242f73308954678d.zip chromium_src-41cd3396af44d63fecc664d1242f73308954678d.tar.gz chromium_src-41cd3396af44d63fecc664d1242f73308954678d.tar.bz2 |
NineImagePainter should paint border pieces even if they need to be cropped.
It stopped doing this (intentionally) in http://crrev.com/351201, but this broke
the findbar textfield.
This change restores the approach from http://crrev.com/1365503007 Patch Set 1.
BUG=545891
Review URL: https://codereview.chromium.org/1413503009
Cr-Commit-Position: refs/heads/master@{#357205}
(cherry picked from commit 453d339c42f4aaa9579238adec0316873cfdffd5)
Review URL: https://codereview.chromium.org/1410013009 .
Cr-Commit-Position: refs/branch-heads/2526@{#299}
Cr-Branched-From: cb947c0153db0ec02a8abbcb3ca086d88bf6006f-refs/heads/master@{#352221}
-rw-r--r-- | ui/gfx/nine_image_painter.cc | 35 | ||||
-rw-r--r-- | ui/gfx/nine_image_painter_unittest.cc | 6 |
2 files changed, 24 insertions, 17 deletions
diff --git a/ui/gfx/nine_image_painter.cc b/ui/gfx/nine_image_painter.cc index 42d5cc0..584e522 100644 --- a/ui/gfx/nine_image_painter.cc +++ b/ui/gfx/nine_image_painter.cc @@ -139,27 +139,32 @@ void NineImagePainter::Paint(Canvas* canvas, int i7h = ImageHeightInPixels(images_[7], scale_y); int i8h = ImageHeightInPixels(images_[8], scale_y); - bool has_room_for_border = - i0w + i2w <= width_in_pixels && i3w + i5w <= width_in_pixels && - i6w + i8w <= width_in_pixels && i0h + i6h <= height_in_pixels && - i1h + i7h <= height_in_pixels && i2h + i8h <= height_in_pixels; - - int i4x = has_room_for_border ? std::min(std::min(i0w, i3w), i6w) : 0; - int i4w = width_in_pixels - - (has_room_for_border ? i4x + std::min(std::min(i2w, i5w), i8w) : 0); - - int i4y = has_room_for_border ? std::min(std::min(i0h, i1h), i2h) : 0; - int i4h = height_in_pixels - - (has_room_for_border ? i4y + std::min(std::min(i6h, i7h), i8h) : 0); + i0w = std::min(i0w, width_in_pixels); + i2w = std::min(i2w, width_in_pixels - i0w); + i3w = std::min(i3w, width_in_pixels); + i5w = std::min(i5w, width_in_pixels - i3w); + i6w = std::min(i6w, width_in_pixels); + i8w = std::min(i8w, width_in_pixels - i6w); + + i0h = std::min(i0h, height_in_pixels); + i1h = std::min(i1h, height_in_pixels); + i2h = std::min(i2h, height_in_pixels); + i6h = std::min(i6h, height_in_pixels - i0h); + i7h = std::min(i7h, height_in_pixels - i1h); + i8h = std::min(i8h, height_in_pixels - i2h); + + int i4x = std::min(std::min(i0w, i3w), i6w); + int i4y = std::min(std::min(i0h, i1h), i2h); + int i4w = + std::max(width_in_pixels - i4x - std::min(std::min(i2w, i5w), i8w), 0); + int i4h = + std::max(height_in_pixels - i4y - std::min(std::min(i6h, i7h), i8h), 0); SkPaint paint; paint.setAlpha(alpha); Fill(canvas, images_[4], i4x, i4y, i4w, i4h, paint); - if (!has_room_for_border) - return; - Fill(canvas, images_[0], 0, 0, i0w, i0h, paint); Fill(canvas, images_[1], i0w, 0, width_in_pixels - i0w - i2w, i1h, paint); diff --git a/ui/gfx/nine_image_painter_unittest.cc b/ui/gfx/nine_image_painter_unittest.cc index 6b2f10a..ecfd409 100644 --- a/ui/gfx/nine_image_painter_unittest.cc +++ b/ui/gfx/nine_image_painter_unittest.cc @@ -69,10 +69,12 @@ TEST(NineImagePainterTest, PaintScale) { TEST(NineImagePainterTest, PaintStaysInBounds) { // In this test the bounds rect is 1x1 but each image is 2x2. // The NineImagePainter should not paint outside the bounds. + // The border images should be cropped, but still painted. SkBitmap src; src.allocN32Pixels(6, 6); - src.eraseColor(SK_ColorRED); + src.eraseColor(SK_ColorGREEN); + src.erase(SK_ColorRED, SkIRect::MakeXYWH(2, 2, 2, 2)); gfx::ImageSkia image(gfx::ImageSkiaRep(src, 0.0f)); gfx::Insets insets(2, 2, 2, 2); @@ -91,7 +93,7 @@ TEST(NineImagePainterTest, PaintStaysInBounds) { result.allocN32Pixels(size.width(), size.height()); canvas.sk_canvas()->readPixels(&result, 0, 0); - EXPECT_EQ(SK_ColorRED, result.getColor(1, 1)); + EXPECT_EQ(SK_ColorGREEN, result.getColor(1, 1)); EXPECT_EQ(SK_ColorBLACK, result.getColor(0, 0)); EXPECT_EQ(SK_ColorBLACK, result.getColor(0, 1)); |