| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef VIEWS_CONTROLS_IMAGE_VIEW_H_ | |
| 6 #define VIEWS_CONTROLS_IMAGE_VIEW_H_ | |
| 7 #pragma once | |
| 8 | |
| 9 #include "third_party/skia/include/core/SkBitmap.h" | |
| 10 #include "views/view.h" | |
| 11 | |
| 12 namespace gfx { | |
| 13 class Canvas; | |
| 14 } | |
| 15 | |
| 16 namespace views { | |
| 17 | |
| 18 ///////////////////////////////////////////////////////////////////////////// | |
| 19 // | |
| 20 // ImageView class. | |
| 21 // | |
| 22 // An ImageView can display an image from an SkBitmap. If a size is provided, | |
| 23 // the ImageView will resize the provided image to fit if it is too big or will | |
| 24 // center the image if smaller. Otherwise, the preferred size matches the | |
| 25 // provided image size. | |
| 26 // | |
| 27 ///////////////////////////////////////////////////////////////////////////// | |
| 28 class VIEWS_EXPORT ImageView : public View { | |
| 29 public: | |
| 30 enum Alignment { | |
| 31 LEADING = 0, | |
| 32 CENTER, | |
| 33 TRAILING | |
| 34 }; | |
| 35 | |
| 36 ImageView(); | |
| 37 virtual ~ImageView(); | |
| 38 | |
| 39 // Set the bitmap that should be displayed. | |
| 40 void SetImage(const SkBitmap& bm); | |
| 41 | |
| 42 // Set the bitmap that should be displayed from a pointer. Reset the image | |
| 43 // if the pointer is NULL. The pointer contents is copied in the receiver's | |
| 44 // bitmap. | |
| 45 void SetImage(const SkBitmap* bm); | |
| 46 | |
| 47 // Returns the bitmap currently displayed or NULL of none is currently set. | |
| 48 // The returned bitmap is still owned by the ImageView. | |
| 49 const SkBitmap& GetImage(); | |
| 50 | |
| 51 // Set the desired image size for the receiving ImageView. | |
| 52 void SetImageSize(const gfx::Size& image_size); | |
| 53 | |
| 54 // Return the preferred size for the receiving view. Returns false if the | |
| 55 // preferred size is not defined, which means that the view uses the image | |
| 56 // size. | |
| 57 bool GetImageSize(gfx::Size* image_size); | |
| 58 | |
| 59 // Returns the actual bounds of the visible image inside the view. | |
| 60 gfx::Rect GetImageBounds() const; | |
| 61 | |
| 62 // Reset the image size to the current image dimensions. | |
| 63 void ResetImageSize(); | |
| 64 | |
| 65 // Set / Get the horizontal alignment. | |
| 66 void SetHorizontalAlignment(Alignment ha); | |
| 67 Alignment GetHorizontalAlignment() const; | |
| 68 | |
| 69 // Set / Get the vertical alignment. | |
| 70 void SetVerticalAlignment(Alignment va); | |
| 71 Alignment GetVerticalAlignment() const; | |
| 72 | |
| 73 // Set / Get the tooltip text. | |
| 74 void SetTooltipText(const string16& tooltip); | |
| 75 string16 GetTooltipText() const; | |
| 76 | |
| 77 // Overriden from View | |
| 78 virtual gfx::Size GetPreferredSize() OVERRIDE; | |
| 79 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | |
| 80 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; | |
| 81 virtual bool GetTooltipText(const gfx::Point& p, | |
| 82 string16* tooltip) const OVERRIDE; | |
| 83 | |
| 84 private: | |
| 85 // Compute the image origin given the desired size and the receiver alignment | |
| 86 // properties. | |
| 87 gfx::Point ComputeImageOrigin(const gfx::Size& image_size) const; | |
| 88 | |
| 89 // Whether the image size is set. | |
| 90 bool image_size_set_; | |
| 91 | |
| 92 // The actual image size. | |
| 93 gfx::Size image_size_; | |
| 94 | |
| 95 // The underlying bitmap. | |
| 96 SkBitmap image_; | |
| 97 | |
| 98 // Horizontal alignment. | |
| 99 Alignment horiz_alignment_; | |
| 100 | |
| 101 // Vertical alignment. | |
| 102 Alignment vert_alignment_; | |
| 103 | |
| 104 // The current tooltip text. | |
| 105 string16 tooltip_text_; | |
| 106 | |
| 107 DISALLOW_COPY_AND_ASSIGN(ImageView); | |
| 108 }; | |
| 109 | |
| 110 } // namespace views | |
| 111 | |
| 112 #endif // VIEWS_CONTROLS_IMAGE_VIEW_H_ | |
| OLD | NEW |