Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(105)

Side by Side Diff: ui/gfx/nine_image_painter.cc

Issue 806433002: Support horizontal/vertical only images in NineImagePainter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/base/nine_image_painter_factory.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/gfx/nine_image_painter.h" 5 #include "ui/gfx/nine_image_painter.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "third_party/skia/include/core/SkPaint.h" 9 #include "third_party/skia/include/core/SkPaint.h"
10 #include "third_party/skia/include/core/SkRect.h" 10 #include "third_party/skia/include/core/SkRect.h"
11 #include "third_party/skia/include/core/SkScalar.h" 11 #include "third_party/skia/include/core/SkScalar.h"
12 #include "ui/gfx/canvas.h" 12 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/geometry/rect_conversions.h" 13 #include "ui/gfx/geometry/rect_conversions.h"
14 #include "ui/gfx/geometry/safe_integer_conversions.h" 14 #include "ui/gfx/geometry/safe_integer_conversions.h"
15 #include "ui/gfx/image/image_skia_operations.h" 15 #include "ui/gfx/image/image_skia_operations.h"
16 #include "ui/gfx/insets.h" 16 #include "ui/gfx/insets.h"
17 #include "ui/gfx/rect.h" 17 #include "ui/gfx/rect.h"
18 #include "ui/gfx/scoped_canvas.h" 18 #include "ui/gfx/scoped_canvas.h"
19 #include "ui/gfx/skia_util.h" 19 #include "ui/gfx/skia_util.h"
20 20
21 namespace gfx { 21 namespace gfx {
22 22
23 namespace { 23 namespace {
24 24
25 // The following functions width and height of the image in pixels for the 25 // The following functions width and height of the image in pixels for the
26 // scale factor in the Canvas. 26 // scale factor in the Canvas.
27 int ImageWidthInPixels(const ImageSkia& i, Canvas* c) { 27 int ImageWidthInPixels(const ImageSkia& i, Canvas* c) {
28 if (i.isNull())
29 return 0;
28 return i.GetRepresentation(c->image_scale()).pixel_width(); 30 return i.GetRepresentation(c->image_scale()).pixel_width();
29 } 31 }
30 32
31 int ImageHeightInPixels(const ImageSkia& i, Canvas* c) { 33 int ImageHeightInPixels(const ImageSkia& i, Canvas* c) {
34 if (i.isNull())
35 return 0;
32 return i.GetRepresentation(c->image_scale()).pixel_height(); 36 return i.GetRepresentation(c->image_scale()).pixel_height();
33 } 37 }
34 38
35 // Stretches the given image over the specified canvas area. 39 // Stretches the given image over the specified canvas area.
36 void Fill(Canvas* c, 40 void Fill(Canvas* c,
37 const ImageSkia& i, 41 const ImageSkia& i,
38 int x, 42 int x,
39 int y, 43 int y,
40 int w, 44 int w,
41 int h, 45 int h,
42 const SkPaint& paint) { 46 const SkPaint& paint) {
47 if (i.isNull())
48 return;
43 c->DrawImageIntInPixel(i, 0, 0, ImageWidthInPixels(i, c), 49 c->DrawImageIntInPixel(i, 0, 0, ImageWidthInPixels(i, c),
44 ImageHeightInPixels(i, c), x, y, w, h, false, paint); 50 ImageHeightInPixels(i, c), x, y, w, h, false, paint);
45 } 51 }
46 52
47 } // namespace 53 } // namespace
48 54
49 NineImagePainter::NineImagePainter(const std::vector<ImageSkia>& images) { 55 NineImagePainter::NineImagePainter(const std::vector<ImageSkia>& images) {
50 DCHECK_EQ(arraysize(images_), images.size()); 56 DCHECK_EQ(arraysize(images_), images.size());
51 for (size_t i = 0; i < arraysize(images_); ++i) 57 for (size_t i = 0; i < arraysize(images_); ++i)
52 images_[i] = images[i]; 58 images_[i] = images[i];
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 int i6h = ImageHeightInPixels(images_[6], canvas); 145 int i6h = ImageHeightInPixels(images_[6], canvas);
140 int i7h = ImageHeightInPixels(images_[7], canvas); 146 int i7h = ImageHeightInPixels(images_[7], canvas);
141 int i8h = ImageHeightInPixels(images_[8], canvas); 147 int i8h = ImageHeightInPixels(images_[8], canvas);
142 148
143 int i4y = std::min(std::min(i0h, i1h), i2h); 149 int i4y = std::min(std::min(i0h, i1h), i2h);
144 int i4h = height_in_pixels - i4y - std::min(std::min(i6h, i7h), i8h); 150 int i4h = height_in_pixels - i4y - std::min(std::min(i6h, i7h), i8h);
145 151
146 SkPaint paint; 152 SkPaint paint;
147 paint.setAlpha(alpha); 153 paint.setAlpha(alpha);
148 154
149 if (!images_[4].isNull())
150 Fill(canvas, images_[4], i4x, i4y, i4w, i4h, paint);
151 canvas->DrawImageIntInPixel(images_[0], 0, 0, i0w, i0h, 155 canvas->DrawImageIntInPixel(images_[0], 0, 0, i0w, i0h,
152 0, 0, i0w, i0h, false, paint); 156 0, 0, i0w, i0h, false, paint);
157
153 Fill(canvas, images_[1], i0w, 0, width_in_pixels - i0w - i2w, i1h, paint); 158 Fill(canvas, images_[1], i0w, 0, width_in_pixels - i0w - i2w, i1h, paint);
154 canvas->DrawImageIntInPixel(images_[2], 0, 0, i2w, i2h, width_in_pixels - i2w, 159
155 0, i2w, i2h, false, paint); 160 Fill(canvas, images_[2], width_in_pixels - i2w, 0, i2w, i2h, paint);
161
156 Fill(canvas, images_[3], 0, i0h, i3w, height_in_pixels - i0h - i6h, paint); 162 Fill(canvas, images_[3], 0, i0h, i3w, height_in_pixels - i0h - i6h, paint);
163
164 Fill(canvas, images_[4], i4x, i4y, i4w, i4h, paint);
165
157 Fill(canvas, images_[5], width_in_pixels - i5w, i2h, i5w, 166 Fill(canvas, images_[5], width_in_pixels - i5w, i2h, i5w,
158 height_in_pixels - i2h - i8h, paint); 167 height_in_pixels - i2h - i8h, paint);
159 canvas->DrawImageIntInPixel(images_[6], 0, 0, i6w, i6h, 0, 168
160 height_in_pixels - i6h, i6w, i6h, false, paint); 169 Fill(canvas, images_[6], 0, height_in_pixels - i6h, i6w, i6h, paint);
170
161 Fill(canvas, images_[7], i6w, height_in_pixels - i7h, 171 Fill(canvas, images_[7], i6w, height_in_pixels - i7h,
162 width_in_pixels - i6w - i8w, i7h, paint); 172 width_in_pixels - i6w - i8w, i7h, paint);
163 canvas->DrawImageIntInPixel(images_[8], 0, 0, i8w, i8h, width_in_pixels - i8w, 173
164 height_in_pixels - i8h, i8w, i8h, false, paint); 174 Fill(canvas, images_[8], width_in_pixels - i8w, height_in_pixels - i8h, i8w,
175 i8h, paint);
165 } 176 }
166 177
167 } // namespace gfx 178 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/base/nine_image_painter_factory.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698