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

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

Issue 1228923002: Revert vector icon CLs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@merge_aide_oobe_completion
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
« no previous file with comments | « ui/views/controls/image_view.h ('k') | ui/views/controls/throbber.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/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"
11 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/geometry/insets.h" 12 #include "ui/gfx/geometry/insets.h"
13 #include "ui/gfx/paint_vector_icon.h"
14 #include "ui/views/painter.h" 13 #include "ui/views/painter.h"
15 14
16 namespace views { 15 namespace views {
17 16
18 namespace { 17 namespace {
19 18
20 // Returns the pixels for the bitmap in |image| at scale |image_scale|. 19 // Returns the pixels for the bitmap in |image| at scale |image_scale|.
21 void* GetBitmapPixels(const gfx::ImageSkia& img, float image_scale) { 20 void* GetBitmapPixels(const gfx::ImageSkia& img, float image_scale) {
22 DCHECK_NE(0.0f, image_scale); 21 DCHECK_NE(0.0f, image_scale);
23 const SkBitmap& bitmap = img.GetRepresentation(image_scale).sk_bitmap(); 22 const SkBitmap& bitmap = img.GetRepresentation(image_scale).sk_bitmap();
24 SkAutoLockPixels pixel_lock(bitmap); 23 SkAutoLockPixels pixel_lock(bitmap);
25 return bitmap.getPixels(); 24 return bitmap.getPixels();
26 } 25 }
27 26
28 } // namespace 27 } // namespace
29 28
30 // static 29 // static
31 const char ImageView::kViewClassName[] = "ImageView"; 30 const char ImageView::kViewClassName[] = "ImageView";
32 31
33 ImageView::ImageView() 32 ImageView::ImageView()
34 : image_size_set_(false), 33 : image_size_set_(false),
35 vector_id_(gfx::VectorIconId::VECTOR_ICON_NONE),
36 vector_color_(SK_ColorGREEN),
37 horiz_alignment_(CENTER), 34 horiz_alignment_(CENTER),
38 vert_alignment_(CENTER), 35 vert_alignment_(CENTER),
39 interactive_(true), 36 interactive_(true),
40 last_paint_scale_(0.f), 37 last_paint_scale_(0.f),
41 last_painted_bitmap_pixels_(NULL), 38 last_painted_bitmap_pixels_(NULL),
42 focus_painter_(Painter::CreateDashedFocusPainter()) { 39 focus_painter_(Painter::CreateDashedFocusPainter()) {
43 } 40 }
44 41
45 ImageView::~ImageView() { 42 ImageView::~ImageView() {
46 } 43 }
(...skipping 16 matching lines...) Expand all
63 } else { 60 } else {
64 gfx::ImageSkia t; 61 gfx::ImageSkia t;
65 SetImage(t); 62 SetImage(t);
66 } 63 }
67 } 64 }
68 65
69 const gfx::ImageSkia& ImageView::GetImage() { 66 const gfx::ImageSkia& ImageView::GetImage() {
70 return image_; 67 return image_;
71 } 68 }
72 69
73 void ImageView::SetVectorIcon(gfx::VectorIconId id,
74 SkColor color,
75 const gfx::Size& image_size) {
76 SetImageSize(image_size);
77 vector_id_ = id;
78 vector_color_ = color;
79 }
80
81 void ImageView::SetImageSize(const gfx::Size& image_size) { 70 void ImageView::SetImageSize(const gfx::Size& image_size) {
82 image_size_set_ = true; 71 image_size_set_ = true;
83 image_size_ = image_size; 72 image_size_ = image_size;
84 PreferredSizeChanged(); 73 PreferredSizeChanged();
85 } 74 }
86 75
76 bool ImageView::GetImageSize(gfx::Size* image_size) const {
77 DCHECK(image_size);
78 if (image_size_set_)
79 *image_size = image_size_;
80 return image_size_set_;
81 }
82
87 gfx::Rect ImageView::GetImageBounds() const { 83 gfx::Rect ImageView::GetImageBounds() const {
88 gfx::Size image_size(image_size_set_ ? 84 gfx::Size image_size(image_size_set_ ?
89 image_size_ : gfx::Size(image_.width(), image_.height())); 85 image_size_ : gfx::Size(image_.width(), image_.height()));
90 return gfx::Rect(ComputeImageOrigin(image_size), image_size); 86 return gfx::Rect(ComputeImageOrigin(image_size), image_size);
91 } 87 }
92 88
93 void ImageView::ResetImageSize() { 89 void ImageView::ResetImageSize() {
94 image_size_set_ = false; 90 image_size_set_ = false;
95 } 91 }
96 92
97 void ImageView::SetFocusPainter(scoped_ptr<Painter> focus_painter) { 93 void ImageView::SetFocusPainter(scoped_ptr<Painter> focus_painter) {
98 focus_painter_ = focus_painter.Pass(); 94 focus_painter_ = focus_painter.Pass();
99 } 95 }
100 96
101 gfx::Size ImageView::GetPreferredSize() const { 97 gfx::Size ImageView::GetPreferredSize() const {
102 gfx::Insets insets = GetInsets(); 98 gfx::Insets insets = GetInsets();
103 if (image_size_set_) { 99 if (image_size_set_) {
104 gfx::Size image_size = image_size_; 100 gfx::Size image_size;
101 GetImageSize(&image_size);
105 image_size.Enlarge(insets.width(), insets.height()); 102 image_size.Enlarge(insets.width(), insets.height());
106 return image_size; 103 return image_size;
107 } 104 }
108 return gfx::Size(image_.width() + insets.width(), 105 return gfx::Size(image_.width() + insets.width(),
109 image_.height() + insets.height()); 106 image_.height() + insets.height());
110 } 107 }
111 108
112 bool ImageView::IsImageEqual(const gfx::ImageSkia& img) const { 109 bool ImageView::IsImageEqual(const gfx::ImageSkia& img) const {
113 // Even though we copy ImageSkia in SetImage() the backing store 110 // Even though we copy ImageSkia in SetImage() the backing store
114 // (ImageSkiaStorage) is not copied and may have changed since the last call 111 // (ImageSkiaStorage) is not copied and may have changed since the last call
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 154
158 void ImageView::OnBlur() { 155 void ImageView::OnBlur() {
159 View::OnBlur(); 156 View::OnBlur();
160 if (focus_painter_.get()) 157 if (focus_painter_.get())
161 SchedulePaint(); 158 SchedulePaint();
162 } 159 }
163 160
164 void ImageView::OnPaint(gfx::Canvas* canvas) { 161 void ImageView::OnPaint(gfx::Canvas* canvas) {
165 View::OnPaint(canvas); 162 View::OnPaint(canvas);
166 OnPaintImage(canvas); 163 OnPaintImage(canvas);
167 OnPaintVectorIcon(canvas);
168 Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); 164 Painter::PaintFocusPainter(this, canvas, focus_painter_.get());
169 } 165 }
170 166
171 void ImageView::GetAccessibleState(ui::AXViewState* state) { 167 void ImageView::GetAccessibleState(ui::AXViewState* state) {
172 state->role = ui::AX_ROLE_IMAGE; 168 state->role = ui::AX_ROLE_IMAGE;
173 state->name = tooltip_text_; 169 state->name = tooltip_text_;
174 } 170 }
175 171
176 const char* ImageView::GetClassName() const { 172 const char* ImageView::GetClassName() const {
177 return kViewClassName; 173 return kViewClassName;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 paint.setFilterQuality(kLow_SkFilterQuality); 233 paint.setFilterQuality(kLow_SkFilterQuality);
238 canvas->DrawImageInt(image_, 0, 0, image_.width(), image_.height(), 234 canvas->DrawImageInt(image_, 0, 0, image_.width(), image_.height(),
239 image_bounds.x(), image_bounds.y(), image_bounds.width(), 235 image_bounds.x(), image_bounds.y(), image_bounds.width(),
240 image_bounds.height(), true, paint); 236 image_bounds.height(), true, paint);
241 } else { 237 } else {
242 canvas->DrawImageInt(image_, image_bounds.x(), image_bounds.y()); 238 canvas->DrawImageInt(image_, image_bounds.x(), image_bounds.y());
243 } 239 }
244 last_painted_bitmap_pixels_ = GetBitmapPixels(image_, last_paint_scale_); 240 last_painted_bitmap_pixels_ = GetBitmapPixels(image_, last_paint_scale_);
245 } 241 }
246 242
247 void ImageView::OnPaintVectorIcon(gfx::Canvas* canvas) {
248 if (vector_id_ == gfx::VectorIconId::VECTOR_ICON_NONE)
249 return;
250
251 DCHECK(image_size_set_);
252 canvas->Translate(ComputeImageOrigin(image_size_).OffsetFromOrigin());
253 gfx::PaintVectorIcon(canvas, vector_id_, image_size_.width(), vector_color_);
254 }
255
256 } // namespace views 243 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/image_view.h ('k') | ui/views/controls/throbber.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698