Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(76)

Side by Side Diff: ui/views/controls/image_view.h

Issue 1214693005: Introduce some util code for drawing vector assets. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix compile and rebase Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 7
8 #include "third_party/skia/include/core/SkColor.h"
8 #include "ui/gfx/image/image_skia.h" 9 #include "ui/gfx/image/image_skia.h"
10 #include "ui/gfx/vector_icons.h"
9 #include "ui/views/view.h" 11 #include "ui/views/view.h"
10 12
11 namespace gfx { 13 namespace gfx {
12 class Canvas; 14 class Canvas;
13 } 15 }
14 16
15 namespace views { 17 namespace views {
16 18
17 class Painter; 19 class Painter;
18 20
(...skipping 26 matching lines...) Expand all
45 47
46 // Set the image that should be displayed from a pointer. Reset the image 48 // Set the image that should be displayed from a pointer. Reset the image
47 // if the pointer is NULL. The pointer contents is copied in the receiver's 49 // if the pointer is NULL. The pointer contents is copied in the receiver's
48 // image. 50 // image.
49 void SetImage(const gfx::ImageSkia* image_skia); 51 void SetImage(const gfx::ImageSkia* image_skia);
50 52
51 // Returns the image currently displayed or NULL of none is currently set. 53 // Returns the image currently displayed or NULL of none is currently set.
52 // The returned image is still owned by the ImageView. 54 // The returned image is still owned by the ImageView.
53 const gfx::ImageSkia& GetImage(); 55 const gfx::ImageSkia& GetImage();
54 56
57 // Tells the view to draw a monochrome vector image identified by |id| using
58 // |color|. The size of the view and the image will be set to |image_size|.
59 void SetVectorIcon(gfx::VectorIconId id,
60 SkColor color,
61 const gfx::Size& image_size);
62
55 // Set the desired image size for the receiving ImageView. 63 // Set the desired image size for the receiving ImageView.
56 void SetImageSize(const gfx::Size& image_size); 64 void SetImageSize(const gfx::Size& image_size);
57 65
58 // Return the preferred size for the receiving view. Returns false if the
59 // preferred size is not defined, which means that the view uses the image
60 // size.
61 bool GetImageSize(gfx::Size* image_size) const;
62
63 // Returns the actual bounds of the visible image inside the view. 66 // Returns the actual bounds of the visible image inside the view.
64 gfx::Rect GetImageBounds() const; 67 gfx::Rect GetImageBounds() const;
65 68
66 // Reset the image size to the current image dimensions. 69 // Reset the image size to the current image dimensions.
67 void ResetImageSize(); 70 void ResetImageSize();
68 71
69 // Set / Get the horizontal alignment. 72 // Set / Get the horizontal alignment.
70 void SetHorizontalAlignment(Alignment ha); 73 void SetHorizontalAlignment(Alignment ha);
71 Alignment GetHorizontalAlignment() const; 74 Alignment GetHorizontalAlignment() const;
72 75
(...skipping 16 matching lines...) Expand all
89 void OnPaint(gfx::Canvas* canvas) override; 92 void OnPaint(gfx::Canvas* canvas) override;
90 void GetAccessibleState(ui::AXViewState* state) override; 93 void GetAccessibleState(ui::AXViewState* state) override;
91 const char* GetClassName() const override; 94 const char* GetClassName() const override;
92 bool GetTooltipText(const gfx::Point& p, 95 bool GetTooltipText(const gfx::Point& p,
93 base::string16* tooltip) const override; 96 base::string16* tooltip) const override;
94 bool CanProcessEventsWithinSubtree() const override; 97 bool CanProcessEventsWithinSubtree() const override;
95 98
96 private: 99 private:
97 void OnPaintImage(gfx::Canvas* canvas); 100 void OnPaintImage(gfx::Canvas* canvas);
98 101
102 void OnPaintVectorIcon(gfx::Canvas* canvas);
103
99 // Returns true if |img| is the same as the last image we painted. This is 104 // Returns true if |img| is the same as the last image we painted. This is
100 // intended to be a quick check, not exhaustive. In other words it's possible 105 // intended to be a quick check, not exhaustive. In other words it's possible
101 // for this to return false even though the images are in fact equal. 106 // for this to return false even though the images are in fact equal.
102 bool IsImageEqual(const gfx::ImageSkia& img) const; 107 bool IsImageEqual(const gfx::ImageSkia& img) const;
103 108
104 // Compute the image origin given the desired size and the receiver alignment 109 // Compute the image origin given the desired size and the receiver alignment
105 // properties. 110 // properties.
106 gfx::Point ComputeImageOrigin(const gfx::Size& image_size) const; 111 gfx::Point ComputeImageOrigin(const gfx::Size& image_size) const;
107 112
108 // Whether the image size is set. 113 // Whether the image size is set.
109 bool image_size_set_; 114 bool image_size_set_;
110 115
111 // The actual image size. 116 // The actual image size.
112 gfx::Size image_size_; 117 gfx::Size image_size_;
113 118
114 // The underlying image. 119 // The underlying image.
115 gfx::ImageSkia image_; 120 gfx::ImageSkia image_;
116 121
122 // The ID of the vector icon that should be drawn, or gfx::VECTOR_ICON_NONE.
123 // This is drawn in addition to |image_|, but in most cases you probably want
124 // one or the other and not both.
125 gfx::VectorIconId vector_id_;
126
127 // The color to use when drawing the vector icon.
128 SkColor vector_color_;
129
117 // Horizontal alignment. 130 // Horizontal alignment.
118 Alignment horiz_alignment_; 131 Alignment horiz_alignment_;
119 132
120 // Vertical alignment. 133 // Vertical alignment.
121 Alignment vert_alignment_; 134 Alignment vert_alignment_;
122 135
123 // The current tooltip text. 136 // The current tooltip text.
124 base::string16 tooltip_text_; 137 base::string16 tooltip_text_;
125 138
126 // A flag controlling hit test handling for interactivity. 139 // A flag controlling hit test handling for interactivity.
127 bool interactive_; 140 bool interactive_;
128 141
129 // Scale last painted at. 142 // Scale last painted at.
130 float last_paint_scale_; 143 float last_paint_scale_;
131 144
132 // Address of bytes we last painted. This is used only for comparison, so its 145 // Address of bytes we last painted. This is used only for comparison, so its
133 // safe to cache. 146 // safe to cache.
134 void* last_painted_bitmap_pixels_; 147 void* last_painted_bitmap_pixels_;
135 148
136 scoped_ptr<views::Painter> focus_painter_; 149 scoped_ptr<views::Painter> focus_painter_;
137 150
138 DISALLOW_COPY_AND_ASSIGN(ImageView); 151 DISALLOW_COPY_AND_ASSIGN(ImageView);
139 }; 152 };
140 153
141 } // namespace views 154 } // namespace views
142 155
143 #endif // UI_VIEWS_CONTROLS_IMAGE_VIEW_H_ 156 #endif // UI_VIEWS_CONTROLS_IMAGE_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698