OLD | NEW |
---|---|
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 Loading... | |
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. | |
msw
2013/02/21 07:29:29
nit: describe values meanings like your awesome cl
dewittj
2013/02/21 19:13:57
Done.
| |
69 enum ArrowPaintType { | |
70 PAINT_NORMAL, | |
71 PAINT_TRANSPARENT, | |
72 PAINT_NONE, | |
73 }; | |
74 | |
68 BubbleBorder(ArrowLocation arrow, Shadow shadow, SkColor color); | 75 BubbleBorder(ArrowLocation arrow, Shadow shadow, SkColor color); |
69 | 76 |
70 // Returns the radius of the corner of the border. | 77 // Returns the radius of the corner of the border. |
71 // TODO(xiyuan): Get rid of this since it's part of BorderImages now? | 78 // TODO(xiyuan): Get rid of this since it's part of BorderImages now? |
72 static int GetCornerRadius() { | 79 static int GetCornerRadius() { |
73 // We can't safely calculate a border radius by comparing the sizes of the | 80 // 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 | 81 // 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. | 82 // directions in order to do more subtle dropshadow fading or other effects. |
76 // So we hardcode the most accurate value. | 83 // So we hardcode the most accurate value. |
77 return 4; | 84 return 4; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 SkColor background_color() const { return background_color_; } | 130 SkColor background_color() const { return background_color_; } |
124 | 131 |
125 void set_client_bounds(const gfx::Rect& bounds) { client_bounds_ = bounds; } | 132 void set_client_bounds(const gfx::Rect& bounds) { client_bounds_ = bounds; } |
126 const gfx::Rect& client_bounds() const { return client_bounds_; } | 133 const gfx::Rect& client_bounds() const { return client_bounds_; } |
127 | 134 |
128 // Sets a fixed offset for the arrow from the beginning of corresponding edge. | 135 // 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 | 136 // The arrow will still point to the same location but the bubble will shift |
130 // location to make that happen. | 137 // location to make that happen. |
131 void set_arrow_offset(int offset) { override_arrow_offset_ = offset; } | 138 void set_arrow_offset(int offset) { override_arrow_offset_ = offset; } |
132 | 139 |
133 // Sets whether the arrow is actually painted. If false, an arrow may still be | 140 // 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. | 141 void set_paint_arrow(ArrowPaintType value) { arrow_paint_type_ = value; } |
135 void set_paint_arrow(bool value) { paint_arrow_ = value; } | |
136 | 142 |
137 // For borders with an arrow, gives the desired bounds (in screen coordinates) | 143 // 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 | 144 // 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 | 145 // depends on the arrow location, so if you change that, you should call this |
140 // again to find out the new coordinates. | 146 // again to find out the new coordinates. |
141 virtual gfx::Rect GetBounds(const gfx::Rect& position_relative_to, | 147 virtual gfx::Rect GetBounds(const gfx::Rect& position_relative_to, |
142 const gfx::Size& contents_size) const; | 148 const gfx::Size& contents_size) const; |
143 | 149 |
144 // Returns the corner radius of the current image set. | 150 // Returns the corner radius of the current image set. |
145 int GetBorderCornerRadius() const; | 151 int GetBorderCornerRadius() const; |
(...skipping 14 matching lines...) Expand all Loading... | |
160 // GetInsets(arrow_location()), but may be called by specialized BubbleBorder | 166 // GetInsets(arrow_location()), but may be called by specialized BubbleBorder |
161 // implementations. | 167 // implementations. |
162 virtual gfx::Insets GetInsetsForArrowLocation(ArrowLocation arrow_loc) const; | 168 virtual gfx::Insets GetInsetsForArrowLocation(ArrowLocation arrow_loc) const; |
163 | 169 |
164 private: | 170 private: |
165 struct BorderImages; | 171 struct BorderImages; |
166 | 172 |
167 // Loads images if necessary. | 173 // Loads images if necessary. |
168 static BorderImages* GetBorderImages(Shadow shadow); | 174 static BorderImages* GetBorderImages(Shadow shadow); |
169 | 175 |
176 int GetArrowSize() const; | |
177 | |
170 // Overridden from Border: | 178 // Overridden from Border: |
171 virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE; | 179 virtual void Paint(const View& view, gfx::Canvas* canvas) OVERRIDE; |
172 | 180 |
173 void DrawEdgeWithArrow(gfx::Canvas* canvas, | 181 void DrawEdgeWithArrow(gfx::Canvas* canvas, |
174 bool is_horizontal, | 182 bool is_horizontal, |
175 const gfx::ImageSkia& edge, | 183 const gfx::ImageSkia& edge, |
176 const gfx::ImageSkia& arrow, | 184 const gfx::ImageSkia& arrow, |
177 int start_x, | 185 int start_x, |
178 int start_y, | 186 int start_y, |
179 int before_arrow, | 187 int before_arrow, |
180 int after_arrow, | 188 int after_arrow, |
181 int offset) const; | 189 int offset) const; |
182 | 190 |
183 void DrawArrowInterior(gfx::Canvas* canvas, float tip_x, float tip_y) const; | 191 void DrawArrowInterior(gfx::Canvas* canvas, float tip_x, float tip_y) const; |
184 | 192 |
185 // Border graphics. | 193 // Border graphics. |
186 struct BorderImages* images_; | 194 struct BorderImages* images_; |
187 | 195 |
188 // Image bundles. | 196 // Image bundles. |
189 static struct BorderImages* border_images_[SHADOW_COUNT]; | 197 static struct BorderImages* border_images_[SHADOW_COUNT]; |
190 | 198 |
191 // Minimal offset of the arrow from the closet edge of bounding rect. | 199 // Minimal offset of the arrow from the closet edge of bounding rect. |
192 int arrow_offset_; | 200 int arrow_offset_; |
193 | 201 |
194 // If specified, overrides the pre-calculated |arrow_offset_| of the arrow. | 202 // If specified, overrides the pre-calculated |arrow_offset_| of the arrow. |
195 int override_arrow_offset_; | 203 int override_arrow_offset_; |
196 | 204 |
197 ArrowLocation arrow_location_; | 205 ArrowLocation arrow_location_; |
198 // See description above setter. | 206 ArrowPaintType arrow_paint_type_; |
199 bool paint_arrow_; | |
200 BubbleAlignment alignment_; | 207 BubbleAlignment alignment_; |
201 SkColor background_color_; | 208 SkColor background_color_; |
202 | 209 |
203 // The client/content bounds; must be clipped from the background on Windows. | 210 // 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. | 211 // TODO(msw): Clean this up when Windows native controls are no longer needed. |
205 gfx::Rect client_bounds_; | 212 gfx::Rect client_bounds_; |
206 | 213 |
207 DISALLOW_COPY_AND_ASSIGN(BubbleBorder); | 214 DISALLOW_COPY_AND_ASSIGN(BubbleBorder); |
208 }; | 215 }; |
209 | 216 |
210 // A Background that clips itself to the specified BubbleBorder and uses | 217 // A Background that clips itself to the specified BubbleBorder and uses |
211 // the background color of the BubbleBorder. | 218 // the background color of the BubbleBorder. |
212 class VIEWS_EXPORT BubbleBackground : public Background { | 219 class VIEWS_EXPORT BubbleBackground : public Background { |
213 public: | 220 public: |
214 explicit BubbleBackground(BubbleBorder* border) : border_(border) {} | 221 explicit BubbleBackground(BubbleBorder* border) : border_(border) {} |
215 | 222 |
216 // Overridden from Background: | 223 // Overridden from Background: |
217 virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE; | 224 virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE; |
218 | 225 |
219 private: | 226 private: |
220 BubbleBorder* border_; | 227 BubbleBorder* border_; |
221 | 228 |
222 DISALLOW_COPY_AND_ASSIGN(BubbleBackground); | 229 DISALLOW_COPY_AND_ASSIGN(BubbleBackground); |
223 }; | 230 }; |
224 | 231 |
225 } // namespace views | 232 } // namespace views |
226 | 233 |
227 #endif // UI_VIEWS_BUBBLE_BUBBLE_BORDER_H_ | 234 #endif // UI_VIEWS_BUBBLE_BUBBLE_BORDER_H_ |
OLD | NEW |