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

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: . 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|.
59 void SetVectorIcon(gfx::VectorIconId id, SkColor color);
sky 2015/07/01 16:42:35 Maybe this should take the image_size to reinforce
Evan Stade 2015/07/01 21:52:59 sure
60
55 // Set the desired image size for the receiving ImageView. 61 // Set the desired image size for the receiving ImageView.
56 void SetImageSize(const gfx::Size& image_size); 62 void SetImageSize(const gfx::Size& image_size);
57 63
58 // Return the preferred size for the receiving view. Returns false if the 64 // 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 65 // preferred size is not defined, which means that the view uses the image
60 // size. 66 // size.
61 bool GetImageSize(gfx::Size* image_size) const; 67 bool GetImageSize(gfx::Size* image_size) const;
62 68
63 // Returns the actual bounds of the visible image inside the view. 69 // Returns the actual bounds of the visible image inside the view.
64 gfx::Rect GetImageBounds() const; 70 gfx::Rect GetImageBounds() const;
(...skipping 24 matching lines...) Expand all
89 void OnPaint(gfx::Canvas* canvas) override; 95 void OnPaint(gfx::Canvas* canvas) override;
90 void GetAccessibleState(ui::AXViewState* state) override; 96 void GetAccessibleState(ui::AXViewState* state) override;
91 const char* GetClassName() const override; 97 const char* GetClassName() const override;
92 bool GetTooltipText(const gfx::Point& p, 98 bool GetTooltipText(const gfx::Point& p,
93 base::string16* tooltip) const override; 99 base::string16* tooltip) const override;
94 bool CanProcessEventsWithinSubtree() const override; 100 bool CanProcessEventsWithinSubtree() const override;
95 101
96 private: 102 private:
97 void OnPaintImage(gfx::Canvas* canvas); 103 void OnPaintImage(gfx::Canvas* canvas);
98 104
105 void OnPaintVectorIcon(gfx::Canvas* canvas);
106
99 // Returns true if |img| is the same as the last image we painted. This is 107 // 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 108 // 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. 109 // for this to return false even though the images are in fact equal.
102 bool IsImageEqual(const gfx::ImageSkia& img) const; 110 bool IsImageEqual(const gfx::ImageSkia& img) const;
103 111
104 // Compute the image origin given the desired size and the receiver alignment 112 // Compute the image origin given the desired size and the receiver alignment
105 // properties. 113 // properties.
106 gfx::Point ComputeImageOrigin(const gfx::Size& image_size) const; 114 gfx::Point ComputeImageOrigin(const gfx::Size& image_size) const;
107 115
108 // Whether the image size is set. 116 // Whether the image size is set.
109 bool image_size_set_; 117 bool image_size_set_;
110 118
111 // The actual image size. 119 // The actual image size.
112 gfx::Size image_size_; 120 gfx::Size image_size_;
113 121
114 // The underlying image. 122 // The underlying image.
115 gfx::ImageSkia image_; 123 gfx::ImageSkia image_;
116 124
125 // The ID of the vector icon that should be drawn, or gfx::VECTOR_ICON_NONE.
126 // This is drawn in addition to |image_|, but in most cases you probably want
127 // one or the other and not both.
128 gfx::VectorIconId vector_id_;
129
130 // The color to use when drawing the vector icon.
131 SkColor vector_color_;
132
117 // Horizontal alignment. 133 // Horizontal alignment.
118 Alignment horiz_alignment_; 134 Alignment horiz_alignment_;
119 135
120 // Vertical alignment. 136 // Vertical alignment.
121 Alignment vert_alignment_; 137 Alignment vert_alignment_;
122 138
123 // The current tooltip text. 139 // The current tooltip text.
124 base::string16 tooltip_text_; 140 base::string16 tooltip_text_;
125 141
126 // A flag controlling hit test handling for interactivity. 142 // A flag controlling hit test handling for interactivity.
127 bool interactive_; 143 bool interactive_;
128 144
129 // Scale last painted at. 145 // Scale last painted at.
130 float last_paint_scale_; 146 float last_paint_scale_;
131 147
132 // Address of bytes we last painted. This is used only for comparison, so its 148 // Address of bytes we last painted. This is used only for comparison, so its
133 // safe to cache. 149 // safe to cache.
134 void* last_painted_bitmap_pixels_; 150 void* last_painted_bitmap_pixels_;
135 151
136 scoped_ptr<views::Painter> focus_painter_; 152 scoped_ptr<views::Painter> focus_painter_;
137 153
138 DISALLOW_COPY_AND_ASSIGN(ImageView); 154 DISALLOW_COPY_AND_ASSIGN(ImageView);
139 }; 155 };
140 156
141 } // namespace views 157 } // namespace views
142 158
143 #endif // UI_VIEWS_CONTROLS_IMAGE_VIEW_H_ 159 #endif // UI_VIEWS_CONTROLS_IMAGE_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698