diff options
author | skobes <skobes@chromium.org> | 2015-10-30 15:42:32 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-10-30 22:43:17 +0000 |
commit | 453d339c42f4aaa9579238adec0316873cfdffd5 (patch) | |
tree | 60b03537a540003eb1c2619dd86e871be4008a4b /ui | |
parent | b6461a2c4357e6a47f525e1926d35149fbbaf3fa (diff) | |
download | chromium_src-453d339c42f4aaa9579238adec0316873cfdffd5.zip chromium_src-453d339c42f4aaa9579238adec0316873cfdffd5.tar.gz chromium_src-453d339c42f4aaa9579238adec0316873cfdffd5.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}
Diffstat (limited to 'ui')
-rw-r--r-- | ui/gfx/nine_image_painter.cc | 59 | ||||
-rw-r--r-- | ui/gfx/nine_image_painter_unittest.cc | 6 |
2 files changed, 35 insertions, 30 deletions
diff --git a/ui/gfx/nine_image_painter.cc b/ui/gfx/nine_image_painter.cc index 49be5ee..cfed62a 100644 --- a/ui/gfx/nine_image_painter.cc +++ b/ui/gfx/nine_image_painter.cc @@ -133,39 +133,42 @@ void NineImagePainter::Paint(Canvas* canvas, int i7h = ImageRepHeightInPixels(image_reps[7]); int i8h = ImageRepHeightInPixels(image_reps[8]); - 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, image_reps[4], i4x, i4y, i4w, i4h, paint); - - if (has_room_for_border) { - Fill(canvas, image_reps[0], 0, 0, i0w, i0h, paint); - Fill(canvas, image_reps[1], i0w, 0, width_in_pixels - i0w - i2w, i1h, - paint); - Fill(canvas, image_reps[2], width_in_pixels - i2w, 0, i2w, i2h, paint); - Fill(canvas, image_reps[3], 0, i0h, i3w, height_in_pixels - i0h - i6h, - paint); - Fill(canvas, image_reps[5], width_in_pixels - i5w, i2h, i5w, - height_in_pixels - i2h - i8h, paint); - Fill(canvas, image_reps[6], 0, height_in_pixels - i6h, i6w, i6h, paint); - Fill(canvas, image_reps[7], i6w, height_in_pixels - i7h, - width_in_pixels - i6w - i8w, i7h, paint); - Fill(canvas, image_reps[8], width_in_pixels - i8w, height_in_pixels - i8h, - i8w, i8h, paint); - } + Fill(canvas, image_reps[0], 0, 0, i0w, i0h, paint); + Fill(canvas, image_reps[1], i0w, 0, width_in_pixels - i0w - i2w, i1h, paint); + Fill(canvas, image_reps[2], width_in_pixels - i2w, 0, i2w, i2h, paint); + Fill(canvas, image_reps[3], 0, i0h, i3w, height_in_pixels - i0h - i6h, paint); + Fill(canvas, image_reps[5], width_in_pixels - i5w, i2h, i5w, + height_in_pixels - i2h - i8h, paint); + Fill(canvas, image_reps[6], 0, height_in_pixels - i6h, i6w, i6h, paint); + Fill(canvas, image_reps[7], i6w, height_in_pixels - i7h, + width_in_pixels - i6w - i8w, i7h, paint); + Fill(canvas, image_reps[8], width_in_pixels - i8w, height_in_pixels - i8h, + i8w, i8h, paint); } // static diff --git a/ui/gfx/nine_image_painter_unittest.cc b/ui/gfx/nine_image_painter_unittest.cc index 9fc0688..759c7f4 100644 --- a/ui/gfx/nine_image_painter_unittest.cc +++ b/ui/gfx/nine_image_painter_unittest.cc @@ -100,10 +100,12 @@ TEST(NineImagePainterTest, PaintHighDPI) { 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); @@ -122,7 +124,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)); |