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

Side by Side Diff: ui/views/bubble/bubble_border.h

Issue 12310022: More flexibility in BubbleBorder arrow rendering. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Address msw style nits. Created 7 years, 10 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_BUBBLE_BUBBLE_BORDER_H_ 5 #ifndef UI_VIEWS_BUBBLE_BUBBLE_BORDER_H_
6 #define UI_VIEWS_BUBBLE_BUBBLE_BORDER_H_ 6 #define UI_VIEWS_BUBBLE_BUBBLE_BORDER_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/compiler_specific.h" 9 #include "base/compiler_specific.h"
10 #include "ui/views/background.h" 10 #include "ui/views/background.h"
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 }; 58 };
59 59
60 // The position of the bubble in relation to the anchor. 60 // The position of the bubble in relation to the anchor.
61 enum BubbleAlignment { 61 enum BubbleAlignment {
62 // The tip of the arrow points to the middle of the anchor. 62 // The tip of the arrow points to the middle of the anchor.
63 ALIGN_ARROW_TO_MID_ANCHOR, 63 ALIGN_ARROW_TO_MID_ANCHOR,
64 // The edge nearest to the arrow is lined up with the edge of the anchor. 64 // The edge nearest to the arrow is lined up with the edge of the anchor.
65 ALIGN_EDGE_TO_ANCHOR_EDGE 65 ALIGN_EDGE_TO_ANCHOR_EDGE
66 }; 66 };
67 67
68 // The way the arrow should be painted.
69 enum ArrowPaintType {
70 // Fully render the arrow.
71 PAINT_NORMAL,
72 // Leave space for the arrow, but do not paint it.
73 PAINT_TRANSPARENT,
74 // Neither paint nor leave space for the arrow.
75 PAINT_NONE,
76 };
77
68 BubbleBorder(ArrowLocation arrow, Shadow shadow, SkColor color); 78 BubbleBorder(ArrowLocation arrow, Shadow shadow, SkColor color);
69 79
70 // Returns the radius of the corner of the border. 80 // Returns the radius of the corner of the border.
71 // TODO(xiyuan): Get rid of this since it's part of BorderImages now? 81 // TODO(xiyuan): Get rid of this since it's part of BorderImages now?
72 static int GetCornerRadius() { 82 static int GetCornerRadius() {
73 // We can't safely calculate a border radius by comparing the sizes of the 83 // We can't safely calculate a border radius by comparing the sizes of the
74 // side and corner images, because either may have been extended in various 84 // side and corner images, because either may have been extended in various
75 // directions in order to do more subtle dropshadow fading or other effects. 85 // directions in order to do more subtle dropshadow fading or other effects.
76 // So we hardcode the most accurate value. 86 // So we hardcode the most accurate value.
77 return 4; 87 return 4;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 SkColor background_color() const { return background_color_; } 133 SkColor background_color() const { return background_color_; }
124 134
125 void set_client_bounds(const gfx::Rect& bounds) { client_bounds_ = bounds; } 135 void set_client_bounds(const gfx::Rect& bounds) { client_bounds_ = bounds; }
126 const gfx::Rect& client_bounds() const { return client_bounds_; } 136 const gfx::Rect& client_bounds() const { return client_bounds_; }
127 137
128 // Sets a fixed offset for the arrow from the beginning of corresponding edge. 138 // Sets a fixed offset for the arrow from the beginning of corresponding edge.
129 // The arrow will still point to the same location but the bubble will shift 139 // The arrow will still point to the same location but the bubble will shift
130 // location to make that happen. 140 // location to make that happen.
131 void set_arrow_offset(int offset) { override_arrow_offset_ = offset; } 141 void set_arrow_offset(int offset) { override_arrow_offset_ = offset; }
132 142
133 // Sets whether the arrow is actually painted. If false, an arrow may still be 143 // Sets the way the arrow is actually painted. Default is PAINT_NORMAL.
134 // used for the geometry computations, but it is not shown. Default is true. 144 void set_paint_arrow(ArrowPaintType value) { arrow_paint_type_ = value; }
135 void set_paint_arrow(bool value) { paint_arrow_ = value; }
136 145
137 // For borders with an arrow, gives the desired bounds (in screen coordinates) 146 // For borders with an arrow, gives the desired bounds (in screen coordinates)
138 // given the rect to point to and the size of the contained contents. This 147 // given the rect to point to and the size of the contained contents. This
139 // depends on the arrow location, so if you change that, you should call this 148 // depends on the arrow location, so if you change that, you should call this
140 // again to find out the new coordinates. 149 // again to find out the new coordinates.
141 virtual gfx::Rect GetBounds(const gfx::Rect& position_relative_to, 150 virtual gfx::Rect GetBounds(const gfx::Rect& position_relative_to,
142 const gfx::Size& contents_size) const; 151 const gfx::Size& contents_size) const;
143 152
144 // Returns the corner radius of the current image set. 153 // Returns the corner radius of the current image set.
145 int GetBorderCornerRadius() const; 154 int GetBorderCornerRadius() const;
(...skipping 14 matching lines...) Expand all
160 // GetInsets(arrow_location()), but may be called by specialized BubbleBorder 169 // GetInsets(arrow_location()), but may be called by specialized BubbleBorder
161 // implementations. 170 // implementations.
162 virtual gfx::Insets GetInsetsForArrowLocation(ArrowLocation arrow_loc) const; 171 virtual gfx::Insets GetInsetsForArrowLocation(ArrowLocation arrow_loc) const;
163 172
164 private: 173 private:
165 struct BorderImages; 174 struct BorderImages;
166 175
167 // Loads images if necessary. 176 // Loads images if necessary.
168 static BorderImages* GetBorderImages(Shadow shadow); 177 static BorderImages* GetBorderImages(Shadow shadow);
169 178
179 int GetArrowSize() const;
180
170 // Overridden from Border: 181 // Overridden from Border:
171 virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE; 182 virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE;
172 183
173 void DrawEdgeWithArrow(gfx::Canvas* canvas, 184 void DrawEdgeWithArrow(gfx::Canvas* canvas,
174 bool is_horizontal, 185 bool is_horizontal,
175 const gfx::ImageSkia& edge, 186 const gfx::ImageSkia& edge,
176 const gfx::ImageSkia& arrow, 187 const gfx::ImageSkia& arrow,
177 int start_x, 188 int start_x,
178 int start_y, 189 int start_y,
179 int before_arrow, 190 int before_arrow,
180 int after_arrow, 191 int after_arrow,
181 int offset) const; 192 int offset) const;
182 193
183 void DrawArrowInterior(gfx::Canvas* canvas, float tip_x, float tip_y) const; 194 void DrawArrowInterior(gfx::Canvas* canvas, float tip_x, float tip_y) const;
184 195
185 // Border graphics. 196 // Border graphics.
186 struct BorderImages* images_; 197 struct BorderImages* images_;
187 198
188 // Image bundles. 199 // Image bundles.
189 static struct BorderImages* border_images_[SHADOW_COUNT]; 200 static struct BorderImages* border_images_[SHADOW_COUNT];
190 201
191 // Minimal offset of the arrow from the closet edge of bounding rect. 202 // Minimal offset of the arrow from the closet edge of bounding rect.
192 int arrow_offset_; 203 int arrow_offset_;
193 204
194 // If specified, overrides the pre-calculated |arrow_offset_| of the arrow. 205 // If specified, overrides the pre-calculated |arrow_offset_| of the arrow.
195 int override_arrow_offset_; 206 int override_arrow_offset_;
196 207
197 ArrowLocation arrow_location_; 208 ArrowLocation arrow_location_;
198 // See description above setter. 209 ArrowPaintType arrow_paint_type_;
199 bool paint_arrow_;
200 BubbleAlignment alignment_; 210 BubbleAlignment alignment_;
201 SkColor background_color_; 211 SkColor background_color_;
202 212
203 // The client/content bounds; must be clipped from the background on Windows. 213 // The client/content bounds; must be clipped from the background on Windows.
204 // TODO(msw): Clean this up when Windows native controls are no longer needed. 214 // TODO(msw): Clean this up when Windows native controls are no longer needed.
205 gfx::Rect client_bounds_; 215 gfx::Rect client_bounds_;
206 216
207 DISALLOW_COPY_AND_ASSIGN(BubbleBorder); 217 DISALLOW_COPY_AND_ASSIGN(BubbleBorder);
208 }; 218 };
209 219
210 // A Background that clips itself to the specified BubbleBorder and uses 220 // A Background that clips itself to the specified BubbleBorder and uses
211 // the background color of the BubbleBorder. 221 // the background color of the BubbleBorder.
212 class VIEWS_EXPORT BubbleBackground : public Background { 222 class VIEWS_EXPORT BubbleBackground : public Background {
213 public: 223 public:
214 explicit BubbleBackground(BubbleBorder* border) : border_(border) {} 224 explicit BubbleBackground(BubbleBorder* border) : border_(border) {}
215 225
216 // Overridden from Background: 226 // Overridden from Background:
217 virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE; 227 virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE;
218 228
219 private: 229 private:
220 BubbleBorder* border_; 230 BubbleBorder* border_;
221 231
222 DISALLOW_COPY_AND_ASSIGN(BubbleBackground); 232 DISALLOW_COPY_AND_ASSIGN(BubbleBackground);
223 }; 233 };
224 234
225 } // namespace views 235 } // namespace views
226 236
227 #endif // UI_VIEWS_BUBBLE_BUBBLE_BORDER_H_ 237 #endif // UI_VIEWS_BUBBLE_BUBBLE_BORDER_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/message_center/notification_bubble_wrapper_win.cc ('k') | ui/views/bubble/bubble_border.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698