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

Side by Side Diff: ui/views/controls/image_view.cc

Issue 1214693005: Introduce some util code for drawing vector assets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 5 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
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/controls/image_view.h" 5 #include "ui/views/controls/image_view.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "third_party/skia/include/core/SkPaint.h" 9 #include "third_party/skia/include/core/SkPaint.h"
10 #include "ui/accessibility/ax_view_state.h" 10 #include "ui/accessibility/ax_view_state.h"
(...skipping 13 matching lines...) Expand all
24 return bitmap.getPixels(); 24 return bitmap.getPixels();
25 } 25 }
26 26
27 } // namespace 27 } // namespace
28 28
29 // static 29 // static
30 const char ImageView::kViewClassName[] = "ImageView"; 30 const char ImageView::kViewClassName[] = "ImageView";
31 31
32 ImageView::ImageView() 32 ImageView::ImageView()
33 : image_size_set_(false), 33 : image_size_set_(false),
34 vector_id_(gfx::VECTOR_ICON_NONE),
34 horiz_alignment_(CENTER), 35 horiz_alignment_(CENTER),
35 vert_alignment_(CENTER), 36 vert_alignment_(CENTER),
36 interactive_(true), 37 interactive_(true),
37 last_paint_scale_(0.f), 38 last_paint_scale_(0.f),
38 last_painted_bitmap_pixels_(NULL), 39 last_painted_bitmap_pixels_(NULL),
39 focus_painter_(Painter::CreateDashedFocusPainter()) { 40 focus_painter_(Painter::CreateDashedFocusPainter()) {
40 } 41 }
41 42
42 ImageView::~ImageView() { 43 ImageView::~ImageView() {
43 } 44 }
(...skipping 16 matching lines...) Expand all
60 } else { 61 } else {
61 gfx::ImageSkia t; 62 gfx::ImageSkia t;
62 SetImage(t); 63 SetImage(t);
63 } 64 }
64 } 65 }
65 66
66 const gfx::ImageSkia& ImageView::GetImage() { 67 const gfx::ImageSkia& ImageView::GetImage() {
67 return image_; 68 return image_;
68 } 69 }
69 70
71 void ImageView::SetVectorIcon(gfx::VectorIconId id, SkColor color) {
72 vector_id_ = id;
73 vector_color_ = color;
74 }
75
70 void ImageView::SetImageSize(const gfx::Size& image_size) { 76 void ImageView::SetImageSize(const gfx::Size& image_size) {
71 image_size_set_ = true; 77 image_size_set_ = true;
72 image_size_ = image_size; 78 image_size_ = image_size;
73 PreferredSizeChanged(); 79 PreferredSizeChanged();
74 } 80 }
75 81
76 bool ImageView::GetImageSize(gfx::Size* image_size) const { 82 bool ImageView::GetImageSize(gfx::Size* image_size) const {
77 DCHECK(image_size); 83 DCHECK(image_size);
78 if (image_size_set_) 84 if (image_size_set_)
79 *image_size = image_size_; 85 *image_size = image_size_;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 160
155 void ImageView::OnBlur() { 161 void ImageView::OnBlur() {
156 View::OnBlur(); 162 View::OnBlur();
157 if (focus_painter_.get()) 163 if (focus_painter_.get())
158 SchedulePaint(); 164 SchedulePaint();
159 } 165 }
160 166
161 void ImageView::OnPaint(gfx::Canvas* canvas) { 167 void ImageView::OnPaint(gfx::Canvas* canvas) {
162 View::OnPaint(canvas); 168 View::OnPaint(canvas);
163 OnPaintImage(canvas); 169 OnPaintImage(canvas);
170 OnPaintVectorIcon(canvas);
164 Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); 171 Painter::PaintFocusPainter(this, canvas, focus_painter_.get());
165 } 172 }
166 173
167 void ImageView::GetAccessibleState(ui::AXViewState* state) { 174 void ImageView::GetAccessibleState(ui::AXViewState* state) {
168 state->role = ui::AX_ROLE_IMAGE; 175 state->role = ui::AX_ROLE_IMAGE;
169 state->name = tooltip_text_; 176 state->name = tooltip_text_;
170 } 177 }
171 178
172 const char* ImageView::GetClassName() const { 179 const char* ImageView::GetClassName() const {
173 return kViewClassName; 180 return kViewClassName;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 paint.setFilterQuality(kLow_SkFilterQuality); 240 paint.setFilterQuality(kLow_SkFilterQuality);
234 canvas->DrawImageInt(image_, 0, 0, image_.width(), image_.height(), 241 canvas->DrawImageInt(image_, 0, 0, image_.width(), image_.height(),
235 image_bounds.x(), image_bounds.y(), image_bounds.width(), 242 image_bounds.x(), image_bounds.y(), image_bounds.width(),
236 image_bounds.height(), true, paint); 243 image_bounds.height(), true, paint);
237 } else { 244 } else {
238 canvas->DrawImageInt(image_, image_bounds.x(), image_bounds.y()); 245 canvas->DrawImageInt(image_, image_bounds.x(), image_bounds.y());
239 } 246 }
240 last_painted_bitmap_pixels_ = GetBitmapPixels(image_, last_paint_scale_); 247 last_painted_bitmap_pixels_ = GetBitmapPixels(image_, last_paint_scale_);
241 } 248 }
242 249
250 void ImageView::OnPaintVectorIcon(gfx::Canvas* canvas) {
251 if (vector_id_ == gfx::VECTOR_ICON_NONE)
252 return;
253
254 gfx::Vector2d origin = ComputeImageOrigin(image_size_) - gfx::Point();
255 canvas->Translate(origin);
256 gfx::PaintVectorIcon(canvas, vector_id_, image_size_.width(), vector_color_);
sky 2015/07/01 16:19:52 Seems like you should DCHECK on image_size_.
Evan Stade 2015/07/01 21:52:59 Done.
257 }
258
243 } // namespace views 259 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698