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

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

Issue 10437006: Converts ui/views/controls, ui/views/examples, ui/base/models to ImageSkia (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 8 years, 7 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
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/utf_string_conversions.h" 8 #include "base/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/base/accessibility/accessible_view_state.h" 10 #include "ui/base/accessibility/accessible_view_state.h"
11 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/insets.h" 12 #include "ui/gfx/insets.h"
13 13
14 namespace views { 14 namespace views {
15 15
16 ImageView::ImageView() 16 ImageView::ImageView()
17 : image_size_set_(false), 17 : image_size_set_(false),
18 horiz_alignment_(CENTER), 18 horiz_alignment_(CENTER),
19 vert_alignment_(CENTER) { 19 vert_alignment_(CENTER) {
20 } 20 }
21 21
22 ImageView::~ImageView() { 22 ImageView::~ImageView() {
23 } 23 }
24 24
25 void ImageView::SetImage(const SkBitmap& bm) { 25 void ImageView::SetImage(const gfx::ImageSkia& img) {
26 gfx::Size pref_size(GetPreferredSize()); 26 gfx::Size pref_size(GetPreferredSize());
27 image_ = bm; 27 image_ = img;
28 if (pref_size != GetPreferredSize()) 28 if (pref_size != GetPreferredSize())
29 PreferredSizeChanged(); 29 PreferredSizeChanged();
30 SchedulePaint(); 30 SchedulePaint();
31 } 31 }
32 32
33 void ImageView::SetImage(const gfx::ImageSkia* image_skia) { 33 void ImageView::SetImage(const gfx::ImageSkia* image_skia) {
34 if (image_skia) { 34 if (image_skia) {
35 SetImage(*image_skia); 35 SetImage(*image_skia);
36 } else { 36 } else {
37 SkBitmap t; 37 gfx::ImageSkia t;
38 SetImage(t); 38 SetImage(t);
39 } 39 }
40 } 40 }
41 41
42 const SkBitmap& ImageView::GetImage() { 42 const gfx::ImageSkia& ImageView::GetImage() {
43 return image_; 43 return image_;
44 } 44 }
45 45
46 void ImageView::SetImageSize(const gfx::Size& image_size) { 46 void ImageView::SetImageSize(const gfx::Size& image_size) {
47 image_size_set_ = true; 47 image_size_set_ = true;
48 image_size_ = image_size; 48 image_size_ = image_size;
49 PreferredSizeChanged(); 49 PreferredSizeChanged();
50 } 50 }
51 51
52 bool ImageView::GetImageSize(gfx::Size* image_size) { 52 bool ImageView::GetImageSize(gfx::Size* image_size) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 112
113 if (image_.empty()) 113 if (image_.empty())
114 return; 114 return;
115 115
116 gfx::Rect image_bounds(GetImageBounds()); 116 gfx::Rect image_bounds(GetImageBounds());
117 if (image_bounds.IsEmpty()) 117 if (image_bounds.IsEmpty())
118 return; 118 return;
119 119
120 if (image_bounds.size() != gfx::Size(image_.width(), image_.height())) { 120 if (image_bounds.size() != gfx::Size(image_.width(), image_.height())) {
121 // Resize case 121 // Resize case
122 image_.buildMipMap(false);
123 SkPaint paint; 122 SkPaint paint;
124 paint.setFilterBitmap(true); 123 paint.setFilterBitmap(true);
125 canvas->DrawBitmapInt(image_, 0, 0, image_.width(), image_.height(), 124 canvas->DrawBitmapInt(image_, 0, 0, image_.width(), image_.height(),
126 image_bounds.x(), image_bounds.y(), image_bounds.width(), 125 image_bounds.x(), image_bounds.y(), image_bounds.width(),
127 image_bounds.height(), true, paint); 126 image_bounds.height(), true, paint);
128 } else { 127 } else {
129 canvas->DrawBitmapInt(image_, image_bounds.x(), image_bounds.y()); 128 canvas->DrawBitmapInt(image_, image_bounds.x(), image_bounds.y());
130 } 129 }
131 } 130 }
132 131
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 166
168 bool ImageView::GetTooltipText(const gfx::Point& p, string16* tooltip) const { 167 bool ImageView::GetTooltipText(const gfx::Point& p, string16* tooltip) const {
169 if (tooltip_text_.empty()) 168 if (tooltip_text_.empty())
170 return false; 169 return false;
171 170
172 *tooltip = GetTooltipText(); 171 *tooltip = GetTooltipText();
173 return true; 172 return true;
174 } 173 }
175 174
176 } // namespace views 175 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698