| 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" | 
| (...skipping 13 matching lines...) Expand all  Loading... | 
| 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::VectorIconId::VECTOR_ICON_NONE), | 
|  | 35       vector_color_(SK_ColorGREEN), | 
| 34       horiz_alignment_(CENTER), | 36       horiz_alignment_(CENTER), | 
| 35       vert_alignment_(CENTER), | 37       vert_alignment_(CENTER), | 
| 36       interactive_(true), | 38       interactive_(true), | 
| 37       last_paint_scale_(0.f), | 39       last_paint_scale_(0.f), | 
| 38       last_painted_bitmap_pixels_(NULL), | 40       last_painted_bitmap_pixels_(NULL), | 
| 39       focus_painter_(Painter::CreateDashedFocusPainter()) { | 41       focus_painter_(Painter::CreateDashedFocusPainter()) { | 
| 40 } | 42 } | 
| 41 | 43 | 
| 42 ImageView::~ImageView() { | 44 ImageView::~ImageView() { | 
| 43 } | 45 } | 
| (...skipping 16 matching lines...) Expand all  Loading... | 
| 60   } else { | 62   } else { | 
| 61     gfx::ImageSkia t; | 63     gfx::ImageSkia t; | 
| 62     SetImage(t); | 64     SetImage(t); | 
| 63   } | 65   } | 
| 64 } | 66 } | 
| 65 | 67 | 
| 66 const gfx::ImageSkia& ImageView::GetImage() { | 68 const gfx::ImageSkia& ImageView::GetImage() { | 
| 67   return image_; | 69   return image_; | 
| 68 } | 70 } | 
| 69 | 71 | 
|  | 72 void ImageView::SetVectorIcon(gfx::VectorIconId id, | 
|  | 73                               SkColor color, | 
|  | 74                               const gfx::Size& image_size) { | 
|  | 75   SetImageSize(image_size); | 
|  | 76   vector_id_ = id; | 
|  | 77   vector_color_ = color; | 
|  | 78 } | 
|  | 79 | 
| 70 void ImageView::SetImageSize(const gfx::Size& image_size) { | 80 void ImageView::SetImageSize(const gfx::Size& image_size) { | 
| 71   image_size_set_ = true; | 81   image_size_set_ = true; | 
| 72   image_size_ = image_size; | 82   image_size_ = image_size; | 
| 73   PreferredSizeChanged(); | 83   PreferredSizeChanged(); | 
| 74 } | 84 } | 
| 75 | 85 | 
| 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 |  | 
| 83 gfx::Rect ImageView::GetImageBounds() const { | 86 gfx::Rect ImageView::GetImageBounds() const { | 
| 84   gfx::Size image_size(image_size_set_ ? | 87   gfx::Size image_size(image_size_set_ ? | 
| 85     image_size_ : gfx::Size(image_.width(), image_.height())); | 88     image_size_ : gfx::Size(image_.width(), image_.height())); | 
| 86   return gfx::Rect(ComputeImageOrigin(image_size), image_size); | 89   return gfx::Rect(ComputeImageOrigin(image_size), image_size); | 
| 87 } | 90 } | 
| 88 | 91 | 
| 89 void ImageView::ResetImageSize() { | 92 void ImageView::ResetImageSize() { | 
| 90   image_size_set_ = false; | 93   image_size_set_ = false; | 
| 91 } | 94 } | 
| 92 | 95 | 
| 93 void ImageView::SetFocusPainter(scoped_ptr<Painter> focus_painter) { | 96 void ImageView::SetFocusPainter(scoped_ptr<Painter> focus_painter) { | 
| 94   focus_painter_ = focus_painter.Pass(); | 97   focus_painter_ = focus_painter.Pass(); | 
| 95 } | 98 } | 
| 96 | 99 | 
| 97 gfx::Size ImageView::GetPreferredSize() const { | 100 gfx::Size ImageView::GetPreferredSize() const { | 
| 98   gfx::Insets insets = GetInsets(); | 101   gfx::Insets insets = GetInsets(); | 
| 99   if (image_size_set_) { | 102   if (image_size_set_) { | 
| 100     gfx::Size image_size; | 103     gfx::Size image_size = image_size_; | 
| 101     GetImageSize(&image_size); |  | 
| 102     image_size.Enlarge(insets.width(), insets.height()); | 104     image_size.Enlarge(insets.width(), insets.height()); | 
| 103     return image_size; | 105     return image_size; | 
| 104   } | 106   } | 
| 105   return gfx::Size(image_.width() + insets.width(), | 107   return gfx::Size(image_.width() + insets.width(), | 
| 106                    image_.height() + insets.height()); | 108                    image_.height() + insets.height()); | 
| 107 } | 109 } | 
| 108 | 110 | 
| 109 bool ImageView::IsImageEqual(const gfx::ImageSkia& img) const { | 111 bool ImageView::IsImageEqual(const gfx::ImageSkia& img) const { | 
| 110   // Even though we copy ImageSkia in SetImage() the backing store | 112   // Even though we copy ImageSkia in SetImage() the backing store | 
| 111   // (ImageSkiaStorage) is not copied and may have changed since the last call | 113   // (ImageSkiaStorage) is not copied and may have changed since the last call | 
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 154 | 156 | 
| 155 void ImageView::OnBlur() { | 157 void ImageView::OnBlur() { | 
| 156   View::OnBlur(); | 158   View::OnBlur(); | 
| 157   if (focus_painter_.get()) | 159   if (focus_painter_.get()) | 
| 158     SchedulePaint(); | 160     SchedulePaint(); | 
| 159 } | 161 } | 
| 160 | 162 | 
| 161 void ImageView::OnPaint(gfx::Canvas* canvas) { | 163 void ImageView::OnPaint(gfx::Canvas* canvas) { | 
| 162   View::OnPaint(canvas); | 164   View::OnPaint(canvas); | 
| 163   OnPaintImage(canvas); | 165   OnPaintImage(canvas); | 
|  | 166   OnPaintVectorIcon(canvas); | 
| 164   Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); | 167   Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); | 
| 165 } | 168 } | 
| 166 | 169 | 
| 167 void ImageView::GetAccessibleState(ui::AXViewState* state) { | 170 void ImageView::GetAccessibleState(ui::AXViewState* state) { | 
| 168   state->role = ui::AX_ROLE_IMAGE; | 171   state->role = ui::AX_ROLE_IMAGE; | 
| 169   state->name = tooltip_text_; | 172   state->name = tooltip_text_; | 
| 170 } | 173 } | 
| 171 | 174 | 
| 172 const char* ImageView::GetClassName() const { | 175 const char* ImageView::GetClassName() const { | 
| 173   return kViewClassName; | 176   return kViewClassName; | 
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 233     paint.setFilterQuality(kLow_SkFilterQuality); | 236     paint.setFilterQuality(kLow_SkFilterQuality); | 
| 234     canvas->DrawImageInt(image_, 0, 0, image_.width(), image_.height(), | 237     canvas->DrawImageInt(image_, 0, 0, image_.width(), image_.height(), | 
| 235         image_bounds.x(), image_bounds.y(), image_bounds.width(), | 238         image_bounds.x(), image_bounds.y(), image_bounds.width(), | 
| 236         image_bounds.height(), true, paint); | 239         image_bounds.height(), true, paint); | 
| 237   } else { | 240   } else { | 
| 238     canvas->DrawImageInt(image_, image_bounds.x(), image_bounds.y()); | 241     canvas->DrawImageInt(image_, image_bounds.x(), image_bounds.y()); | 
| 239   } | 242   } | 
| 240   last_painted_bitmap_pixels_ = GetBitmapPixels(image_, last_paint_scale_); | 243   last_painted_bitmap_pixels_ = GetBitmapPixels(image_, last_paint_scale_); | 
| 241 } | 244 } | 
| 242 | 245 | 
|  | 246 void ImageView::OnPaintVectorIcon(gfx::Canvas* canvas) { | 
|  | 247   if (vector_id_ == gfx::VectorIconId::VECTOR_ICON_NONE) | 
|  | 248     return; | 
|  | 249 | 
|  | 250   DCHECK(image_size_set_); | 
|  | 251   canvas->Translate(ComputeImageOrigin(image_size_).OffsetFromOrigin()); | 
|  | 252   gfx::PaintVectorIcon(canvas, vector_id_, image_size_.width(), vector_color_); | 
|  | 253 } | 
|  | 254 | 
| 243 }  // namespace views | 255 }  // namespace views | 
| OLD | NEW | 
|---|