| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/logging.h" | 5 #include "base/logging.h" |
| 6 #include "chrome/common/gfx/chrome_canvas.h" | 6 #include "chrome/common/gfx/chrome_canvas.h" |
| 7 #include "chrome/views/image_view.h" | 7 #include "chrome/views/image_view.h" |
| 8 | 8 |
| 9 namespace ChromeViews { | 9 namespace ChromeViews { |
| 10 | 10 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 } else { | 28 } else { |
| 29 SkBitmap t; | 29 SkBitmap t; |
| 30 SetImage(t); | 30 SetImage(t); |
| 31 } | 31 } |
| 32 } | 32 } |
| 33 | 33 |
| 34 const SkBitmap& ImageView::GetImage() { | 34 const SkBitmap& ImageView::GetImage() { |
| 35 return image_; | 35 return image_; |
| 36 } | 36 } |
| 37 | 37 |
| 38 void ImageView::SetImageSize(const CSize& image_size) { | 38 void ImageView::SetImageSize(const gfx::Size& image_size) { |
| 39 image_size_set_ = true; | 39 image_size_set_ = true; |
| 40 image_size_ = image_size; | 40 image_size_ = image_size; |
| 41 } | 41 } |
| 42 | 42 |
| 43 bool ImageView::GetImageSize(CSize* image_size) { | 43 bool ImageView::GetImageSize(gfx::Size* image_size) { |
| 44 DCHECK(image_size); | 44 DCHECK(image_size); |
| 45 if (image_size_set_) | 45 if (image_size_set_) |
| 46 *image_size = image_size_; | 46 *image_size = image_size_; |
| 47 return image_size_set_; | 47 return image_size_set_; |
| 48 } | 48 } |
| 49 | 49 |
| 50 void ImageView::ResetImageSize() { | 50 void ImageView::ResetImageSize() { |
| 51 image_size_set_ = false; | 51 image_size_set_ = false; |
| 52 } | 52 } |
| 53 | 53 |
| 54 void ImageView::GetPreferredSize(CSize* out) { | 54 gfx::Size ImageView::GetPreferredSize() { |
| 55 DCHECK(out); | |
| 56 if (image_size_set_) { | 55 if (image_size_set_) { |
| 57 GetImageSize(out); | 56 gfx::Size image_size; |
| 58 } else { | 57 GetImageSize(&image_size); |
| 59 out->cx = image_.width(); | 58 return image_size; |
| 60 out->cy = image_.height(); | |
| 61 } | 59 } |
| 60 return gfx::Size(image_.width(), image_.height()); |
| 62 } | 61 } |
| 63 | 62 |
| 64 void ImageView::ComputeImageOrigin(int image_width, int image_height, | 63 void ImageView::ComputeImageOrigin(int image_width, int image_height, |
| 65 int *x, int *y) { | 64 int *x, int *y) { |
| 66 // In order to properly handle alignment of images in RTL locales, we need | 65 // In order to properly handle alignment of images in RTL locales, we need |
| 67 // to flip the meaning of trailing and leading. For example, if the | 66 // to flip the meaning of trailing and leading. For example, if the |
| 68 // horizontal alignment is set to trailing, then we'll use left alignment for | 67 // horizontal alignment is set to trailing, then we'll use left alignment for |
| 69 // the image instead of right alignment if the UI layout is RTL. | 68 // the image instead of right alignment if the UI layout is RTL. |
| 70 Alignment actual_horiz_alignment = horiz_alignment_; | 69 Alignment actual_horiz_alignment = horiz_alignment_; |
| 71 if (UILayoutIsRightToLeft()) { | 70 if (UILayoutIsRightToLeft()) { |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 void ImageView::Paint(ChromeCanvas* canvas) { | 106 void ImageView::Paint(ChromeCanvas* canvas) { |
| 108 View::Paint(canvas); | 107 View::Paint(canvas); |
| 109 int image_width = image_.width(); | 108 int image_width = image_.width(); |
| 110 int image_height = image_.height(); | 109 int image_height = image_.height(); |
| 111 | 110 |
| 112 if (image_width == 0 || image_height == 0) | 111 if (image_width == 0 || image_height == 0) |
| 113 return; | 112 return; |
| 114 | 113 |
| 115 int x, y; | 114 int x, y; |
| 116 if (image_size_set_ && | 115 if (image_size_set_ && |
| 117 (image_size_.cx != image_width || image_size_.cy != image_height)) { | 116 (image_size_.width() != image_width || |
| 117 image_size_.width() != image_height)) { |
| 118 // Resize case | 118 // Resize case |
| 119 image_.buildMipMap(false); | 119 image_.buildMipMap(false); |
| 120 ComputeImageOrigin(image_size_.cx, image_size_.cy, &x, &y); | 120 ComputeImageOrigin(image_size_.width(), image_size_.height(), &x, &y); |
| 121 canvas->DrawBitmapInt(image_, 0, 0, image_width, image_height, | 121 canvas->DrawBitmapInt(image_, 0, 0, image_width, image_height, |
| 122 x, y, image_size_.cx, image_size_.cy, | 122 x, y, image_size_.width(), image_size_.height(), |
| 123 true); | 123 true); |
| 124 } else { | 124 } else { |
| 125 ComputeImageOrigin(image_width, image_height, &x, &y); | 125 ComputeImageOrigin(image_width, image_height, &x, &y); |
| 126 canvas->DrawBitmapInt(image_, x, y); | 126 canvas->DrawBitmapInt(image_, x, y); |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 void ImageView::SetHorizontalAlignment(Alignment ha) { | 130 void ImageView::SetHorizontalAlignment(Alignment ha) { |
| 131 if (ha != horiz_alignment_) { | 131 if (ha != horiz_alignment_) { |
| 132 horiz_alignment_ = ha; | 132 horiz_alignment_ = ha; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 161 if (tooltip_text_.empty()) { | 161 if (tooltip_text_.empty()) { |
| 162 return false; | 162 return false; |
| 163 } else { | 163 } else { |
| 164 * tooltip = GetTooltipText(); | 164 * tooltip = GetTooltipText(); |
| 165 return true; | 165 return true; |
| 166 } | 166 } |
| 167 } | 167 } |
| 168 | 168 |
| 169 } | 169 } |
| 170 | 170 |
| OLD | NEW |