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

Side by Side Diff: ui/views/painter.cc

Issue 10447053: Converts remainder of ui and chrome/browser/ui/views/frame to use ImageSkia (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 months 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 | Annotate | Revision Log
« no previous file with comments | « ui/views/painter.h ('k') | ui/views/view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/views/painter.h" 5 #include "ui/views/painter.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "third_party/skia/include/core/SkBitmap.h"
9 #include "third_party/skia/include/effects/SkGradientShader.h" 8 #include "third_party/skia/include/effects/SkGradientShader.h"
10 #include "ui/base/resource/resource_bundle.h" 9 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/gfx/canvas.h" 10 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/image/image.h" 11 #include "ui/gfx/image/image.h"
12 #include "ui/gfx/image/image_skia.h"
13 #include "ui/gfx/insets.h" 13 #include "ui/gfx/insets.h"
14 #include "ui/gfx/point.h" 14 #include "ui/gfx/point.h"
15 #include "ui/gfx/rect.h" 15 #include "ui/gfx/rect.h"
16 16
17 namespace views { 17 namespace views {
18 18
19 namespace { 19 namespace {
20 20
21 class GradientPainter : public Painter { 21 class GradientPainter : public Painter {
22 public: 22 public:
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 private: 54 private:
55 bool horizontal_; 55 bool horizontal_;
56 SkColor colors_[2]; 56 SkColor colors_[2];
57 57
58 DISALLOW_COPY_AND_ASSIGN(GradientPainter); 58 DISALLOW_COPY_AND_ASSIGN(GradientPainter);
59 }; 59 };
60 60
61 61
62 class ImagePainter : public Painter { 62 class ImagePainter : public Painter {
63 public: 63 public:
64 ImagePainter(const SkBitmap& image, 64 ImagePainter(const gfx::ImageSkia& image,
65 const gfx::Insets& insets, 65 const gfx::Insets& insets,
66 bool paint_center) 66 bool paint_center)
67 : image_(image), 67 : image_(image),
68 insets_(insets), 68 insets_(insets),
69 paint_center_(paint_center) { 69 paint_center_(paint_center) {
70 DCHECK(image.width() > insets.width() && 70 DCHECK(image.width() > insets.width() &&
71 image.height() > insets.height()); 71 image.height() > insets.height());
72 } 72 }
73 73
74 // Paints the images. 74 // Paints the images.
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 image_, 134 image_,
135 insets_.left(), insets_.top(), 135 insets_.left(), insets_.top(),
136 image_.width() - insets_.width(), image_.height() - insets_.height(), 136 image_.width() - insets_.width(), image_.height() - insets_.height(),
137 insets_.left(), insets_.top(), 137 insets_.left(), insets_.top(),
138 size.width() - insets_.width(), size.height() - insets_.height(), 138 size.width() - insets_.width(), size.height() - insets_.height(),
139 true); 139 true);
140 } 140 }
141 } 141 }
142 142
143 private: 143 private:
144 const SkBitmap image_; 144 const gfx::ImageSkia image_;
145 const gfx::Insets insets_; 145 const gfx::Insets insets_;
146 bool paint_center_; 146 bool paint_center_;
147 147
148 DISALLOW_COPY_AND_ASSIGN(ImagePainter); 148 DISALLOW_COPY_AND_ASSIGN(ImagePainter);
149 }; 149 };
150 150
151 } // namespace 151 } // namespace
152 152
153 // static 153 // static
154 void Painter::PaintPainterAt(gfx::Canvas* canvas, 154 void Painter::PaintPainterAt(gfx::Canvas* canvas,
(...skipping 10 matching lines...) Expand all
165 Painter* Painter::CreateHorizontalGradient(SkColor c1, SkColor c2) { 165 Painter* Painter::CreateHorizontalGradient(SkColor c1, SkColor c2) {
166 return new GradientPainter(true, c1, c2); 166 return new GradientPainter(true, c1, c2);
167 } 167 }
168 168
169 // static 169 // static
170 Painter* Painter::CreateVerticalGradient(SkColor c1, SkColor c2) { 170 Painter* Painter::CreateVerticalGradient(SkColor c1, SkColor c2) {
171 return new GradientPainter(false, c1, c2); 171 return new GradientPainter(false, c1, c2);
172 } 172 }
173 173
174 // static 174 // static
175 Painter* Painter::CreateImagePainter(const SkBitmap& image, 175 Painter* Painter::CreateImagePainter(const gfx::ImageSkia& image,
176 const gfx::Insets& insets, 176 const gfx::Insets& insets,
177 bool paint_center) { 177 bool paint_center) {
178 return new ImagePainter(image, insets, paint_center); 178 return new ImagePainter(image, insets, paint_center);
179 } 179 }
180 180
181 HorizontalPainter::HorizontalPainter(const int image_resource_names[]) { 181 HorizontalPainter::HorizontalPainter(const int image_resource_names[]) {
182 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 182 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
183 for (int i = 0; i < 3; ++i) 183 for (int i = 0; i < 3; ++i)
184 images_[i] = rb.GetImageNamed(image_resource_names[i]).ToSkBitmap(); 184 images_[i] = rb.GetImageNamed(image_resource_names[i]).ToImageSkia();
185 height_ = images_[LEFT]->height(); 185 height_ = images_[LEFT]->height();
186 DCHECK(images_[LEFT]->height() == images_[RIGHT]->height() && 186 DCHECK(images_[LEFT]->height() == images_[RIGHT]->height() &&
187 images_[LEFT]->height() == images_[CENTER]->height()); 187 images_[LEFT]->height() == images_[CENTER]->height());
188 } 188 }
189 189
190 void HorizontalPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) { 190 void HorizontalPainter::Paint(gfx::Canvas* canvas, const gfx::Size& size) {
191 if (size.width() < (images_[LEFT]->width() + images_[CENTER]->width() + 191 if (size.width() < (images_[LEFT]->width() + images_[CENTER]->width() +
192 images_[RIGHT]->width())) { 192 images_[RIGHT]->width())) {
193 // No room to paint. 193 // No room to paint.
194 return; 194 return;
195 } 195 }
196 canvas->DrawBitmapInt(*images_[LEFT], 0, 0); 196 canvas->DrawBitmapInt(*images_[LEFT], 0, 0);
197 canvas->DrawBitmapInt(*images_[RIGHT], 197 canvas->DrawBitmapInt(*images_[RIGHT],
198 size.width() - images_[RIGHT]->width(), 0); 198 size.width() - images_[RIGHT]->width(), 0);
199 canvas->TileImageInt(*images_[CENTER], images_[LEFT]->width(), 0, 199 canvas->TileImageInt(*images_[CENTER], images_[LEFT]->width(), 0,
200 size.width() - images_[LEFT]->width() - images_[RIGHT]->width(), height_); 200 size.width() - images_[LEFT]->width() - images_[RIGHT]->width(), height_);
201 } 201 }
202 202
203 } // namespace views 203 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/painter.h ('k') | ui/views/view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698