| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 | 70 |
| 71 gfx::Rect ImageView::GetImageBounds() const { | 71 gfx::Rect ImageView::GetImageBounds() const { |
| 72 gfx::Size image_size = GetImageSize(); | 72 gfx::Size image_size = GetImageSize(); |
| 73 return gfx::Rect(ComputeImageOrigin(image_size), image_size); | 73 return gfx::Rect(ComputeImageOrigin(image_size), image_size); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void ImageView::ResetImageSize() { | 76 void ImageView::ResetImageSize() { |
| 77 image_size_set_ = false; | 77 image_size_set_ = false; |
| 78 } | 78 } |
| 79 | 79 |
| 80 gfx::Size ImageView::GetPreferredSize() const { | |
| 81 gfx::Size size = GetImageSize(); | |
| 82 size.Enlarge(GetInsets().width(), GetInsets().height()); | |
| 83 return size; | |
| 84 } | |
| 85 | |
| 86 bool ImageView::IsImageEqual(const gfx::ImageSkia& img) const { | 80 bool ImageView::IsImageEqual(const gfx::ImageSkia& img) const { |
| 87 // Even though we copy ImageSkia in SetImage() the backing store | 81 // Even though we copy ImageSkia in SetImage() the backing store |
| 88 // (ImageSkiaStorage) is not copied and may have changed since the last call | 82 // (ImageSkiaStorage) is not copied and may have changed since the last call |
| 89 // to SetImage(). The expectation is that SetImage() with different pixels is | 83 // to SetImage(). The expectation is that SetImage() with different pixels is |
| 90 // treated as though the image changed. For this reason we compare not only | 84 // treated as though the image changed. For this reason we compare not only |
| 91 // the backing store but also the pixels of the last image we painted. | 85 // the backing store but also the pixels of the last image we painted. |
| 92 return image_.BackedBySameObjectAs(img) && | 86 return image_.BackedBySameObjectAs(img) && |
| 93 last_paint_scale_ != 0.0f && | 87 last_paint_scale_ != 0.0f && |
| 94 last_painted_bitmap_pixels_ == GetBitmapPixels(img, last_paint_scale_); | 88 last_painted_bitmap_pixels_ == GetBitmapPixels(img, last_paint_scale_); |
| 95 } | 89 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 | 167 |
| 174 bool ImageView::GetTooltipText(const gfx::Point& p, | 168 bool ImageView::GetTooltipText(const gfx::Point& p, |
| 175 base::string16* tooltip) const { | 169 base::string16* tooltip) const { |
| 176 if (tooltip_text_.empty()) | 170 if (tooltip_text_.empty()) |
| 177 return false; | 171 return false; |
| 178 | 172 |
| 179 *tooltip = GetTooltipText(); | 173 *tooltip = GetTooltipText(); |
| 180 return true; | 174 return true; |
| 181 } | 175 } |
| 182 | 176 |
| 177 gfx::Size ImageView::CalculatePreferredSize() const { |
| 178 gfx::Size size = GetImageSize(); |
| 179 size.Enlarge(GetInsets().width(), GetInsets().height()); |
| 180 return size; |
| 181 } |
| 182 |
| 183 void ImageView::OnPaintImage(gfx::Canvas* canvas) { | 183 void ImageView::OnPaintImage(gfx::Canvas* canvas) { |
| 184 last_paint_scale_ = canvas->image_scale(); | 184 last_paint_scale_ = canvas->image_scale(); |
| 185 last_painted_bitmap_pixels_ = NULL; | 185 last_painted_bitmap_pixels_ = NULL; |
| 186 | 186 |
| 187 if (image_.isNull()) | 187 if (image_.isNull()) |
| 188 return; | 188 return; |
| 189 | 189 |
| 190 gfx::Rect image_bounds(GetImageBounds()); | 190 gfx::Rect image_bounds(GetImageBounds()); |
| 191 if (image_bounds.IsEmpty()) | 191 if (image_bounds.IsEmpty()) |
| 192 return; | 192 return; |
| 193 | 193 |
| 194 if (image_bounds.size() != gfx::Size(image_.width(), image_.height())) { | 194 if (image_bounds.size() != gfx::Size(image_.width(), image_.height())) { |
| 195 // Resize case | 195 // Resize case |
| 196 cc::PaintFlags flags; | 196 cc::PaintFlags flags; |
| 197 flags.setFilterQuality(kLow_SkFilterQuality); | 197 flags.setFilterQuality(kLow_SkFilterQuality); |
| 198 canvas->DrawImageInt(image_, 0, 0, image_.width(), image_.height(), | 198 canvas->DrawImageInt(image_, 0, 0, image_.width(), image_.height(), |
| 199 image_bounds.x(), image_bounds.y(), | 199 image_bounds.x(), image_bounds.y(), |
| 200 image_bounds.width(), image_bounds.height(), true, | 200 image_bounds.width(), image_bounds.height(), true, |
| 201 flags); | 201 flags); |
| 202 } else { | 202 } else { |
| 203 canvas->DrawImageInt(image_, image_bounds.x(), image_bounds.y()); | 203 canvas->DrawImageInt(image_, image_bounds.x(), image_bounds.y()); |
| 204 } | 204 } |
| 205 last_painted_bitmap_pixels_ = GetBitmapPixels(image_, last_paint_scale_); | 205 last_painted_bitmap_pixels_ = GetBitmapPixels(image_, last_paint_scale_); |
| 206 } | 206 } |
| 207 | 207 |
| 208 } // namespace views | 208 } // namespace views |
| OLD | NEW |