| OLD | NEW | 
|---|
| 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" | 13 #include "ui/gfx/paint_vector_icon.h" | 
|  | 14 #include "ui/gfx/vector_icons_public.h" | 
| 14 #include "ui/views/painter.h" | 15 #include "ui/views/painter.h" | 
| 15 | 16 | 
| 16 namespace views { | 17 namespace views { | 
| 17 | 18 | 
| 18 namespace { | 19 namespace { | 
| 19 | 20 | 
| 20 // Returns the pixels for the bitmap in |image| at scale |image_scale|. | 21 // Returns the pixels for the bitmap in |image| at scale |image_scale|. | 
| 21 void* GetBitmapPixels(const gfx::ImageSkia& img, float image_scale) { | 22 void* GetBitmapPixels(const gfx::ImageSkia& img, float image_scale) { | 
| 22   DCHECK_NE(0.0f, image_scale); | 23   DCHECK_NE(0.0f, image_scale); | 
| 23   const SkBitmap& bitmap = img.GetRepresentation(image_scale).sk_bitmap(); | 24   const SkBitmap& bitmap = img.GetRepresentation(image_scale).sk_bitmap(); | 
| 24   SkAutoLockPixels pixel_lock(bitmap); | 25   SkAutoLockPixels pixel_lock(bitmap); | 
| 25   return bitmap.getPixels(); | 26   return bitmap.getPixels(); | 
| 26 } | 27 } | 
| 27 | 28 | 
| 28 }  // namespace | 29 }  // namespace | 
| 29 | 30 | 
| 30 // static | 31 // static | 
| 31 const char ImageView::kViewClassName[] = "ImageView"; | 32 const char ImageView::kViewClassName[] = "ImageView"; | 
| 32 | 33 | 
| 33 ImageView::ImageView() | 34 ImageView::ImageView() | 
| 34     : image_size_set_(false), | 35     : image_size_set_(false), | 
| 35       vector_id_(gfx::VectorIconId::VECTOR_ICON_NONE), | 36       vector_id_(static_cast<int>(gfx::VectorIconId::VECTOR_ICON_NONE)), | 
| 36       vector_color_(SK_ColorGREEN), | 37       vector_color_(SK_ColorGREEN), | 
| 37       horiz_alignment_(CENTER), | 38       horiz_alignment_(CENTER), | 
| 38       vert_alignment_(CENTER), | 39       vert_alignment_(CENTER), | 
| 39       interactive_(true), | 40       interactive_(true), | 
| 40       last_paint_scale_(0.f), | 41       last_paint_scale_(0.f), | 
| 41       last_painted_bitmap_pixels_(NULL), | 42       last_painted_bitmap_pixels_(NULL), | 
| 42       focus_painter_(Painter::CreateDashedFocusPainter()) { | 43       focus_painter_(Painter::CreateDashedFocusPainter()) { | 
| 43 } | 44 } | 
| 44 | 45 | 
| 45 ImageView::~ImageView() { | 46 ImageView::~ImageView() { | 
| (...skipping 21 matching lines...) Expand all  Loading... | 
| 67 } | 68 } | 
| 68 | 69 | 
| 69 const gfx::ImageSkia& ImageView::GetImage() { | 70 const gfx::ImageSkia& ImageView::GetImage() { | 
| 70   return image_; | 71   return image_; | 
| 71 } | 72 } | 
| 72 | 73 | 
| 73 void ImageView::SetVectorIcon(gfx::VectorIconId id, | 74 void ImageView::SetVectorIcon(gfx::VectorIconId id, | 
| 74                               SkColor color, | 75                               SkColor color, | 
| 75                               const gfx::Size& image_size) { | 76                               const gfx::Size& image_size) { | 
| 76   SetImageSize(image_size); | 77   SetImageSize(image_size); | 
| 77   vector_id_ = id; | 78   vector_id_ = static_cast<int>(id); | 
| 78   vector_color_ = color; | 79   vector_color_ = color; | 
| 79 } | 80 } | 
| 80 | 81 | 
| 81 void ImageView::SetImageSize(const gfx::Size& image_size) { | 82 void ImageView::SetImageSize(const gfx::Size& image_size) { | 
| 82   image_size_set_ = true; | 83   image_size_set_ = true; | 
| 83   image_size_ = image_size; | 84   image_size_ = image_size; | 
| 84   PreferredSizeChanged(); | 85   PreferredSizeChanged(); | 
| 85 } | 86 } | 
| 86 | 87 | 
| 87 gfx::Rect ImageView::GetImageBounds() const { | 88 gfx::Rect ImageView::GetImageBounds() const { | 
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 238     canvas->DrawImageInt(image_, 0, 0, image_.width(), image_.height(), | 239     canvas->DrawImageInt(image_, 0, 0, image_.width(), image_.height(), | 
| 239         image_bounds.x(), image_bounds.y(), image_bounds.width(), | 240         image_bounds.x(), image_bounds.y(), image_bounds.width(), | 
| 240         image_bounds.height(), true, paint); | 241         image_bounds.height(), true, paint); | 
| 241   } else { | 242   } else { | 
| 242     canvas->DrawImageInt(image_, image_bounds.x(), image_bounds.y()); | 243     canvas->DrawImageInt(image_, image_bounds.x(), image_bounds.y()); | 
| 243   } | 244   } | 
| 244   last_painted_bitmap_pixels_ = GetBitmapPixels(image_, last_paint_scale_); | 245   last_painted_bitmap_pixels_ = GetBitmapPixels(image_, last_paint_scale_); | 
| 245 } | 246 } | 
| 246 | 247 | 
| 247 void ImageView::OnPaintVectorIcon(gfx::Canvas* canvas) { | 248 void ImageView::OnPaintVectorIcon(gfx::Canvas* canvas) { | 
| 248   if (vector_id_ == gfx::VectorIconId::VECTOR_ICON_NONE) | 249   if (vector_id_ == static_cast<int>(gfx::VectorIconId::VECTOR_ICON_NONE)) | 
| 249     return; | 250     return; | 
| 250 | 251 | 
| 251   DCHECK(image_size_set_); | 252   DCHECK(image_size_set_); | 
| 252   canvas->Translate(ComputeImageOrigin(image_size_).OffsetFromOrigin()); | 253   canvas->Translate(ComputeImageOrigin(image_size_).OffsetFromOrigin()); | 
| 253   gfx::PaintVectorIcon(canvas, vector_id_, image_size_.width(), vector_color_); | 254   gfx::PaintVectorIcon(canvas, static_cast<gfx::VectorIconId>(vector_id_), | 
|  | 255                        image_size_.width(), vector_color_); | 
| 254 } | 256 } | 
| 255 | 257 | 
| 256 }  // namespace views | 258 }  // namespace views | 
| OLD | NEW | 
|---|