| 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 "views/controls/button/image_button.h" | 5 #include "views/controls/button/image_button.h" |
| 6 | 6 |
| 7 #include "app/gfx/canvas.h" | 7 #include "app/gfx/canvas.h" |
| 8 #include "app/throb_animation.h" | 8 #include "app/throb_animation.h" |
| 9 #include "skia/ext/image_operations.h" | 9 #include "skia/ext/image_operations.h" |
| 10 | 10 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 } | 31 } |
| 32 | 32 |
| 33 void ImageButton::SetImage(ButtonState aState, SkBitmap* anImage) { | 33 void ImageButton::SetImage(ButtonState aState, SkBitmap* anImage) { |
| 34 images_[aState] = anImage ? *anImage : SkBitmap(); | 34 images_[aState] = anImage ? *anImage : SkBitmap(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 void ImageButton::SetBackground(SkColor color, | 37 void ImageButton::SetBackground(SkColor color, |
| 38 SkBitmap* image, | 38 SkBitmap* image, |
| 39 SkBitmap* mask) { | 39 SkBitmap* mask) { |
| 40 if (!color && !image) | 40 if (!color && !image) |
| 41 background_image_ = NULL; | 41 background_image_.reset(NULL); |
| 42 | 42 |
| 43 background_image_ = new SkBitmap( | 43 background_image_.reset(new SkBitmap( |
| 44 skia::ImageOperations::CreateButtonBackground(color, *image, *mask)); | 44 skia::ImageOperations::CreateButtonBackground(color, *image, *mask))); |
| 45 } | 45 } |
| 46 | 46 |
| 47 void ImageButton::SetImageAlignment(HorizontalAlignment h_align, | 47 void ImageButton::SetImageAlignment(HorizontalAlignment h_align, |
| 48 VerticalAlignment v_align) { | 48 VerticalAlignment v_align) { |
| 49 h_alignment_ = h_align; | 49 h_alignment_ = h_align; |
| 50 v_alignment_ = v_align; | 50 v_alignment_ = v_align; |
| 51 SchedulePaint(); | 51 SchedulePaint(); |
| 52 } | 52 } |
| 53 | 53 |
| 54 //////////////////////////////////////////////////////////////////////////////// | 54 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 17 matching lines...) Expand all Loading... |
| 72 if (h_alignment_ == ALIGN_CENTER) | 72 if (h_alignment_ == ALIGN_CENTER) |
| 73 x = (width() - img.width()) / 2; | 73 x = (width() - img.width()) / 2; |
| 74 else if (h_alignment_ == ALIGN_RIGHT) | 74 else if (h_alignment_ == ALIGN_RIGHT) |
| 75 x = width() - img.width(); | 75 x = width() - img.width(); |
| 76 | 76 |
| 77 if (v_alignment_ == ALIGN_MIDDLE) | 77 if (v_alignment_ == ALIGN_MIDDLE) |
| 78 y = (height() - img.height()) / 2; | 78 y = (height() - img.height()) / 2; |
| 79 else if (v_alignment_ == ALIGN_BOTTOM) | 79 else if (v_alignment_ == ALIGN_BOTTOM) |
| 80 y = height() - img.height(); | 80 y = height() - img.height(); |
| 81 | 81 |
| 82 if (background_image_) | 82 if (background_image_.get()) |
| 83 canvas->DrawBitmapInt(*background_image_, x, y); | 83 canvas->DrawBitmapInt(*(background_image_.get()), x, y); |
| 84 canvas->DrawBitmapInt(img, x, y); | 84 canvas->DrawBitmapInt(img, x, y); |
| 85 } | 85 } |
| 86 PaintFocusBorder(canvas); | 86 PaintFocusBorder(canvas); |
| 87 } | 87 } |
| 88 | 88 |
| 89 //////////////////////////////////////////////////////////////////////////////// | 89 //////////////////////////////////////////////////////////////////////////////// |
| 90 // ImageButton, protected: | 90 // ImageButton, protected: |
| 91 | 91 |
| 92 SkBitmap ImageButton::GetImageToPaint() { | 92 SkBitmap ImageButton::GetImageToPaint() { |
| 93 SkBitmap img; | 93 SkBitmap img; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 158 |
| 159 bool ToggleImageButton::GetTooltipText(int x, int y, std::wstring* tooltip) { | 159 bool ToggleImageButton::GetTooltipText(int x, int y, std::wstring* tooltip) { |
| 160 if (!toggled_ || toggled_tooltip_text_.empty()) | 160 if (!toggled_ || toggled_tooltip_text_.empty()) |
| 161 return Button::GetTooltipText(x, y, tooltip); | 161 return Button::GetTooltipText(x, y, tooltip); |
| 162 | 162 |
| 163 *tooltip = toggled_tooltip_text_; | 163 *tooltip = toggled_tooltip_text_; |
| 164 return true; | 164 return true; |
| 165 } | 165 } |
| 166 | 166 |
| 167 } // namespace views | 167 } // namespace views |
| OLD | NEW |