| 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 #ifndef UI_VIEWS_CONTROLS_IMAGE_VIEW_H_ | 5 #ifndef UI_VIEWS_CONTROLS_IMAGE_VIEW_H_ |
| 6 #define UI_VIEWS_CONTROLS_IMAGE_VIEW_H_ | 6 #define UI_VIEWS_CONTROLS_IMAGE_VIEW_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "third_party/skia/include/core/SkBitmap.h" | |
| 10 #include "ui/gfx/image/image_skia.h" | 9 #include "ui/gfx/image/image_skia.h" |
| 11 #include "ui/views/view.h" | 10 #include "ui/views/view.h" |
| 12 | 11 |
| 13 namespace gfx { | 12 namespace gfx { |
| 14 class Canvas; | 13 class Canvas; |
| 15 } | 14 } |
| 16 | 15 |
| 17 namespace views { | 16 namespace views { |
| 18 | 17 |
| 19 ///////////////////////////////////////////////////////////////////////////// | 18 ///////////////////////////////////////////////////////////////////////////// |
| 20 // | 19 // |
| 21 // ImageView class. | 20 // ImageView class. |
| 22 // | 21 // |
| 23 // An ImageView can display an image from an SkBitmap. If a size is provided, | 22 // An ImageView can display an image from an ImageSkia. If a size is provided, |
| 24 // the ImageView will resize the provided image to fit if it is too big or will | 23 // the ImageView will resize the provided image to fit if it is too big or will |
| 25 // center the image if smaller. Otherwise, the preferred size matches the | 24 // center the image if smaller. Otherwise, the preferred size matches the |
| 26 // provided image size. | 25 // provided image size. |
| 27 // | 26 // |
| 28 ///////////////////////////////////////////////////////////////////////////// | 27 ///////////////////////////////////////////////////////////////////////////// |
| 29 class VIEWS_EXPORT ImageView : public View { | 28 class VIEWS_EXPORT ImageView : public View { |
| 30 public: | 29 public: |
| 31 enum Alignment { | 30 enum Alignment { |
| 32 LEADING = 0, | 31 LEADING = 0, |
| 33 CENTER, | 32 CENTER, |
| 34 TRAILING | 33 TRAILING |
| 35 }; | 34 }; |
| 36 | 35 |
| 37 ImageView(); | 36 ImageView(); |
| 38 virtual ~ImageView(); | 37 virtual ~ImageView(); |
| 39 | 38 |
| 40 // Set the bitmap that should be displayed. | 39 // Set the image that should be displayed. |
| 41 void SetImage(const SkBitmap& bm); | 40 void SetImage(const gfx::ImageSkia& img); |
| 42 | 41 |
| 43 // Set the image that should be displayed from a pointer. Reset the image | 42 // Set the image that should be displayed from a pointer. Reset the image |
| 44 // if the pointer is NULL. The pointer contents is copied in the receiver's | 43 // if the pointer is NULL. The pointer contents is copied in the receiver's |
| 45 // bitmap. | 44 // image. |
| 46 void SetImage(const gfx::ImageSkia* image_skia); | 45 void SetImage(const gfx::ImageSkia* image_skia); |
| 47 | 46 |
| 48 // Returns the bitmap currently displayed or NULL of none is currently set. | 47 // Returns the image currently displayed or NULL of none is currently set. |
| 49 // The returned bitmap is still owned by the ImageView. | 48 // The returned image is still owned by the ImageView. |
| 50 const SkBitmap& GetImage(); | 49 const gfx::ImageSkia& GetImage(); |
| 51 | 50 |
| 52 // Set the desired image size for the receiving ImageView. | 51 // Set the desired image size for the receiving ImageView. |
| 53 void SetImageSize(const gfx::Size& image_size); | 52 void SetImageSize(const gfx::Size& image_size); |
| 54 | 53 |
| 55 // Return the preferred size for the receiving view. Returns false if the | 54 // Return the preferred size for the receiving view. Returns false if the |
| 56 // preferred size is not defined, which means that the view uses the image | 55 // preferred size is not defined, which means that the view uses the image |
| 57 // size. | 56 // size. |
| 58 bool GetImageSize(gfx::Size* image_size); | 57 bool GetImageSize(gfx::Size* image_size); |
| 59 | 58 |
| 60 // Returns the actual bounds of the visible image inside the view. | 59 // Returns the actual bounds of the visible image inside the view. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 86 // Compute the image origin given the desired size and the receiver alignment | 85 // Compute the image origin given the desired size and the receiver alignment |
| 87 // properties. | 86 // properties. |
| 88 gfx::Point ComputeImageOrigin(const gfx::Size& image_size) const; | 87 gfx::Point ComputeImageOrigin(const gfx::Size& image_size) const; |
| 89 | 88 |
| 90 // Whether the image size is set. | 89 // Whether the image size is set. |
| 91 bool image_size_set_; | 90 bool image_size_set_; |
| 92 | 91 |
| 93 // The actual image size. | 92 // The actual image size. |
| 94 gfx::Size image_size_; | 93 gfx::Size image_size_; |
| 95 | 94 |
| 96 // The underlying bitmap. | 95 // The underlying image. |
| 97 SkBitmap image_; | 96 gfx::ImageSkia image_; |
| 98 | 97 |
| 99 // Horizontal alignment. | 98 // Horizontal alignment. |
| 100 Alignment horiz_alignment_; | 99 Alignment horiz_alignment_; |
| 101 | 100 |
| 102 // Vertical alignment. | 101 // Vertical alignment. |
| 103 Alignment vert_alignment_; | 102 Alignment vert_alignment_; |
| 104 | 103 |
| 105 // The current tooltip text. | 104 // The current tooltip text. |
| 106 string16 tooltip_text_; | 105 string16 tooltip_text_; |
| 107 | 106 |
| 108 DISALLOW_COPY_AND_ASSIGN(ImageView); | 107 DISALLOW_COPY_AND_ASSIGN(ImageView); |
| 109 }; | 108 }; |
| 110 | 109 |
| 111 } // namespace views | 110 } // namespace views |
| 112 | 111 |
| 113 #endif // UI_VIEWS_CONTROLS_IMAGE_VIEW_H_ | 112 #endif // UI_VIEWS_CONTROLS_IMAGE_VIEW_H_ |
| OLD | NEW |