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.
5 #ifndef VIEWS_CONTROLS_IMAGE_VIEW_H_
6 #define VIEWS_CONTROLS_IMAGE_VIEW_H_
9 #include "third_party/skia/include/core/SkBitmap.h"
10 #include "views/view.h"
18 /////////////////////////////////////////////////////////////////////////////
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.
27 /////////////////////////////////////////////////////////////////////////////
28 class VIEWS_EXPORT ImageView
: public View
{
39 // Set the bitmap that should be displayed.
40 void SetImage(const SkBitmap
& bm
);
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
45 void SetImage(const SkBitmap
* bm
);
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();
51 // Set the desired image size for the receiving ImageView.
52 void SetImageSize(const gfx::Size
& image_size
);
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
57 bool GetImageSize(gfx::Size
* image_size
);
59 // Returns the actual bounds of the visible image inside the view.
60 gfx::Rect
GetImageBounds() const;
62 // Reset the image size to the current image dimensions.
63 void ResetImageSize();
65 // Set / Get the horizontal alignment.
66 void SetHorizontalAlignment(Alignment ha
);
67 Alignment
GetHorizontalAlignment();
69 // Set / Get the vertical alignment.
70 void SetVerticalAlignment(Alignment va
);
71 Alignment
GetVerticalAlignment();
73 // Set / Get the tooltip text.
74 void SetTooltipText(const string16
& tooltip
);
75 string16
GetTooltipText();
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
, string16
* tooltip
) OVERRIDE
;
84 // Compute the image origin given the desired size and the receiver alignment
86 gfx::Point
ComputeImageOrigin(const gfx::Size
& image_size
) const;
88 // Whether the image size is set.
91 // The actual image size.
92 gfx::Size image_size_
;
94 // The underlying bitmap.
97 // Horizontal alignment.
98 Alignment horiz_alignment_
;
100 // Vertical alignment.
101 Alignment vert_alignment_
;
103 // The current tooltip text.
104 string16 tooltip_text_
;
106 DISALLOW_COPY_AND_ASSIGN(ImageView
);
111 #endif // VIEWS_CONTROLS_IMAGE_VIEW_H_