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

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: sky review 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|. Since the size of the view and the image will be set to
Peter Kasting 2015/07/01 22:26:58 Nit: I think you want to remove "Since" (sentence
Evan Stade 2015/07/02 00:08:06 Done.
59 // |image_size|.
60 void SetVectorIcon(gfx::VectorIconId id,
61 SkColor color,
62 const gfx::Size& image_size);
63
55 // Set the desired image size for the receiving ImageView. 64 // Set the desired image size for the receiving ImageView.
56 void SetImageSize(const gfx::Size& image_size); 65 void SetImageSize(const gfx::Size& image_size);
57 66
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. 67 // Returns the actual bounds of the visible image inside the view.
64 gfx::Rect GetImageBounds() const; 68 gfx::Rect GetImageBounds() const;
65 69
66 // Reset the image size to the current image dimensions. 70 // Reset the image size to the current image dimensions.
67 void ResetImageSize(); 71 void ResetImageSize();
68 72
69 // Set / Get the horizontal alignment. 73 // Set / Get the horizontal alignment.
70 void SetHorizontalAlignment(Alignment ha); 74 void SetHorizontalAlignment(Alignment ha);
71 Alignment GetHorizontalAlignment() const; 75 Alignment GetHorizontalAlignment() const;
72 76
(...skipping 16 matching lines...) Expand all
89 void OnPaint(gfx::Canvas* canvas) override; 93 void OnPaint(gfx::Canvas* canvas) override;
90 void GetAccessibleState(ui::AXViewState* state) override; 94 void GetAccessibleState(ui::AXViewState* state) override;
91 const char* GetClassName() const override; 95 const char* GetClassName() const override;
92 bool GetTooltipText(const gfx::Point& p, 96 bool GetTooltipText(const gfx::Point& p,
93 base::string16* tooltip) const override; 97 base::string16* tooltip) const override;
94 bool CanProcessEventsWithinSubtree() const override; 98 bool CanProcessEventsWithinSubtree() const override;
95 99
96 private: 100 private:
97 void OnPaintImage(gfx::Canvas* canvas); 101 void OnPaintImage(gfx::Canvas* canvas);
98 102
103 void OnPaintVectorIcon(gfx::Canvas* canvas);
104
99 // Returns true if |img| is the same as the last image we painted. This is 105 // 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 106 // 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. 107 // for this to return false even though the images are in fact equal.
102 bool IsImageEqual(const gfx::ImageSkia& img) const; 108 bool IsImageEqual(const gfx::ImageSkia& img) const;
103 109
104 // Compute the image origin given the desired size and the receiver alignment 110 // Compute the image origin given the desired size and the receiver alignment
105 // properties. 111 // properties.
106 gfx::Point ComputeImageOrigin(const gfx::Size& image_size) const; 112 gfx::Point ComputeImageOrigin(const gfx::Size& image_size) const;
107 113
108 // Whether the image size is set. 114 // Whether the image size is set.
109 bool image_size_set_; 115 bool image_size_set_;
110 116
111 // The actual image size. 117 // The actual image size.
112 gfx::Size image_size_; 118 gfx::Size image_size_;
113 119
114 // The underlying image. 120 // The underlying image.
115 gfx::ImageSkia image_; 121 gfx::ImageSkia image_;
116 122
123 // The ID of the vector icon that should be drawn, or gfx::VECTOR_ICON_NONE.
124 // This is drawn in addition to |image_|, but in most cases you probably want
125 // one or the other and not both.
126 gfx::VectorIconId vector_id_;
Peter Kasting 2015/07/01 22:26:58 Does it make sense to make bitmap and vector image
Evan Stade 2015/07/02 00:08:06 I'm not a huge fan of classes that hold implementa
Peter Kasting 2015/07/02 00:23:53 That latter wouldn't be a concern if the bitmap cl
Evan Stade 2015/07/02 00:58:24 Like GetImageSize, which was a public function but
Peter Kasting 2015/07/02 08:06:11 Having added and then ripped out tons of different
127
128 // The color to use when drawing the vector icon.
129 SkColor vector_color_;
130
117 // Horizontal alignment. 131 // Horizontal alignment.
118 Alignment horiz_alignment_; 132 Alignment horiz_alignment_;
119 133
120 // Vertical alignment. 134 // Vertical alignment.
121 Alignment vert_alignment_; 135 Alignment vert_alignment_;
122 136
123 // The current tooltip text. 137 // The current tooltip text.
124 base::string16 tooltip_text_; 138 base::string16 tooltip_text_;
125 139
126 // A flag controlling hit test handling for interactivity. 140 // A flag controlling hit test handling for interactivity.
127 bool interactive_; 141 bool interactive_;
128 142
129 // Scale last painted at. 143 // Scale last painted at.
130 float last_paint_scale_; 144 float last_paint_scale_;
131 145
132 // Address of bytes we last painted. This is used only for comparison, so its 146 // Address of bytes we last painted. This is used only for comparison, so its
133 // safe to cache. 147 // safe to cache.
134 void* last_painted_bitmap_pixels_; 148 void* last_painted_bitmap_pixels_;
135 149
136 scoped_ptr<views::Painter> focus_painter_; 150 scoped_ptr<views::Painter> focus_painter_;
137 151
138 DISALLOW_COPY_AND_ASSIGN(ImageView); 152 DISALLOW_COPY_AND_ASSIGN(ImageView);
139 }; 153 };
140 154
141 } // namespace views 155 } // namespace views
142 156
143 #endif // UI_VIEWS_CONTROLS_IMAGE_VIEW_H_ 157 #endif // UI_VIEWS_CONTROLS_IMAGE_VIEW_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698