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

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

Issue 10905311: Consolidate bubble border code. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix nit in #2 and arrow interior color Created 8 years, 3 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 | Annotate | Revision Log
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 21 matching lines...) Expand all
32 LEFT_TOP = 4, 32 LEFT_TOP = 4,
33 RIGHT_TOP = 5, 33 RIGHT_TOP = 5,
34 LEFT_BOTTOM = 6, 34 LEFT_BOTTOM = 6,
35 RIGHT_BOTTOM = 7, 35 RIGHT_BOTTOM = 7,
36 NONE = 8, // No arrow. Positioned under the supplied rect. 36 NONE = 8, // No arrow. Positioned under the supplied rect.
37 FLOAT = 9 // No arrow. Centered over the supplied rect. 37 FLOAT = 9 // No arrow. Centered over the supplied rect.
38 }; 38 };
39 39
40 enum Shadow { 40 enum Shadow {
41 SHADOW = 0, 41 SHADOW = 0,
42 NO_SHADOW = 1 42 NO_SHADOW,
43 #if defined(USE_AURA)
44 BIG_SHADOW,
45 SMALL_SHADOW,
46 #endif
47 SHADOW_COUNT
msw 2012/09/18 19:33:42 nit: add a comma (same for ArrowLocation if you do
xiyuan 2012/09/19 18:20:09 Done.
43 }; 48 };
44 49
45 // The position of the bubble in relation to the anchor. 50 // The position of the bubble in relation to the anchor.
46 enum BubbleAlignment { 51 enum BubbleAlignment {
47 // The tip of the arrow points to the middle of the anchor. 52 // The tip of the arrow points to the middle of the anchor.
48 ALIGN_ARROW_TO_MID_ANCHOR, 53 ALIGN_ARROW_TO_MID_ANCHOR,
49 // The edge nearest to the arrow is lined up with the edge of the anchor. 54 // The edge nearest to the arrow is lined up with the edge of the anchor.
50 ALIGN_EDGE_TO_ANCHOR_EDGE 55 ALIGN_EDGE_TO_ANCHOR_EDGE
51 }; 56 };
52 57
53 BubbleBorder(ArrowLocation arrow_location, Shadow shadow); 58 BubbleBorder(ArrowLocation arrow_location, Shadow shadow);
54 59
55 // Returns the radius of the corner of the border. 60 // Returns the radius of the corner of the border.
61 // TODO(xiyuan): Get rid of this since it's part of BorderImages now?
msw 2012/09/18 19:33:42 Yeah, GetCornerRadius and GetBorderCornerRadius ar
xiyuan 2012/09/19 18:20:09 I'll do it later in a clean up CL. Right now, this
msw 2012/09/19 20:12:31 sgtm
56 static int GetCornerRadius() { 62 static int GetCornerRadius() {
57 // We can't safely calculate a border radius by comparing the sizes of the 63 // We can't safely calculate a border radius by comparing the sizes of the
58 // side and corner images, because either may have been extended in various 64 // side and corner images, because either may have been extended in various
59 // directions in order to do more subtle dropshadow fading or other effects. 65 // directions in order to do more subtle dropshadow fading or other effects.
60 // So we hardcode the most accurate value. 66 // So we hardcode the most accurate value.
61 return 4; 67 return 4;
62 } 68 }
63 69
64 // Sets the location for the arrow. 70 // Sets the location for the arrow.
65 void set_arrow_location(ArrowLocation loc) { arrow_location_ = loc; } 71 void set_arrow_location(ArrowLocation loc) { arrow_location_ = loc; }
(...skipping 28 matching lines...) Expand all
94 } 100 }
95 101
96 // Sets the background color for the arrow body. This is irrelevant if you do 102 // Sets the background color for the arrow body. This is irrelevant if you do
97 // not also set the arrow location to something other than NONE. 103 // not also set the arrow location to something other than NONE.
98 void set_background_color(SkColor color) { background_color_ = color; } 104 void set_background_color(SkColor color) { background_color_ = color; }
99 SkColor background_color() const { return background_color_; } 105 SkColor background_color() const { return background_color_; }
100 106
101 void set_client_bounds(const gfx::Rect& bounds) { client_bounds_ = bounds; } 107 void set_client_bounds(const gfx::Rect& bounds) { client_bounds_ = bounds; }
102 const gfx::Rect& client_bounds() const { return client_bounds_; } 108 const gfx::Rect& client_bounds() const { return client_bounds_; }
103 109
110 void set_relative_arrow_offset(int relative_arrow_offset) {
msw 2012/09/18 19:33:42 nit: fits on one line if you s/relative_arrow_offs
xiyuan 2012/09/19 18:20:09 Done.
111 relative_arrow_offset_ = relative_arrow_offset;
112 }
113 int relative_arrow_offset() const { return relative_arrow_offset_; }
114
115 void set_center_arrow(bool center_arrow) { center_arrow_ = center_arrow; }
116 bool center_arrow() const { return center_arrow_; }
117
104 // For borders with an arrow, gives the desired bounds (in screen coordinates) 118 // For borders with an arrow, gives the desired bounds (in screen coordinates)
105 // given the rect to point to and the size of the contained contents. This 119 // given the rect to point to and the size of the contained contents. This
106 // depends on the arrow location, so if you change that, you should call this 120 // depends on the arrow location, so if you change that, you should call this
107 // again to find out the new coordinates. 121 // again to find out the new coordinates.
108 virtual gfx::Rect GetBounds(const gfx::Rect& position_relative_to, 122 virtual gfx::Rect GetBounds(const gfx::Rect& position_relative_to,
109 const gfx::Size& contents_size) const; 123 const gfx::Size& contents_size) const;
110 124
125 // Returns the corner radius of current image set.
msw 2012/09/18 19:33:42 nit: "*the* current"
xiyuan 2012/09/19 18:20:09 Done.
126 int GetBorderCornerRadius() const;
127
111 // Sets a fixed offset for the arrow from the beginning of corresponding edge. 128 // Sets a fixed offset for the arrow from the beginning of corresponding edge.
112 // The arrow will still point to the same location but the bubble will shift 129 // The arrow will still point to the same location but the bubble will shift
113 // location to make that happen. Returns actuall arrow offset, in case of 130 // location to make that happen. Returns actual arrow offset, in case of
114 // overflow it differ from desired. 131 // overflow it differs from desired.
115 int SetArrowOffset(int offset, const gfx::Size& contents_size); 132 int SetArrowOffset(int offset, const gfx::Size& contents_size);
116 133
117 // Overridden from Border: 134 // Overridden from Border:
118 virtual void GetInsets(gfx::Insets* insets) const OVERRIDE; 135 virtual void GetInsets(gfx::Insets* insets) const OVERRIDE;
119 136
120 // How many pixels the bubble border is from the edge of the images. 137 // How many pixels the bubble border is from the edge of the images.
121 virtual int GetBorderThickness() const; 138 virtual int GetBorderThickness() const;
122 139
123 protected: 140 protected:
124 virtual ~BubbleBorder(); 141 virtual ~BubbleBorder();
(...skipping 19 matching lines...) Expand all
144 gfx::ImageSkia* edge, 161 gfx::ImageSkia* edge,
145 gfx::ImageSkia* arrow, 162 gfx::ImageSkia* arrow,
146 int start_x, 163 int start_x,
147 int start_y, 164 int start_y,
148 int before_arrow, 165 int before_arrow,
149 int after_arrow, 166 int after_arrow,
150 int offset) const; 167 int offset) const;
151 168
152 void DrawArrowInterior(gfx::Canvas* canvas, float tip_x, float tip_y) const; 169 void DrawArrowInterior(gfx::Canvas* canvas, float tip_x, float tip_y) const;
153 170
171 // Ensures that |arrow_offset| is in valid range so that border images are
172 // drawn correctly.
173 int SanitizeArrowOffset(int arrow_offset, const gfx::Size& border_size) const;
174
175 // Calculates the arrow offset to use.
176 int CalculateArrowOffset(const gfx::Size& border_size) const;
177
154 // Border graphics. 178 // Border graphics.
155 struct BorderImages* images_; 179 struct BorderImages* images_;
156 180
157 // Image bundles. 181 // Image bundles.
158 static struct BorderImages* normal_images_; 182 static struct BorderImages* border_images_[SHADOW_COUNT];
159 static struct BorderImages* shadow_images_;
160 183
161 // Minimal offset of the arrow from the closet edge of bounding rect. 184 // Minimal offset of the arrow from the closet edge of bounding rect.
162 int arrow_offset_; 185 int arrow_offset_;
163 186
164 // If specified, overrides the pre-calculated |arrow_offset_| of the arrow. 187 // If specified, overrides the pre-calculated |arrow_offset_| of the arrow.
165 int override_arrow_offset_; 188 int override_arrow_offset_;
166 189
190 // Relative offset to move current arrow. It is used for move bubble relative
msw 2012/09/18 19:33:42 nit: grammar "to move the" twice.
xiyuan 2012/09/19 18:20:09 Done.
191 // to its default position when it is off screen.
192 int relative_arrow_offset_;
msw 2012/09/18 19:33:42 Instead of adding a new offset (in addition to |ar
xiyuan 2012/09/19 18:20:09 Initially my concern is that if we set |override_a
msw 2012/09/19 20:12:31 Great! Thanks for being thorough!
193
167 ArrowLocation arrow_location_; 194 ArrowLocation arrow_location_;
168 BubbleAlignment alignment_; 195 BubbleAlignment alignment_;
169 SkColor background_color_; 196 SkColor background_color_;
170 197
171 // The client/content bounds; must be clipped from the background on Windows. 198 // The client/content bounds; must be clipped from the background on Windows.
172 // TODO(msw): Clean this up when Windows native controls are no longer needed. 199 // TODO(msw): Clean this up when Windows native controls are no longer needed.
173 gfx::Rect client_bounds_; 200 gfx::Rect client_bounds_;
174 201
202 // If true (default is false) and |override_arrow_offset_| is not specified,
203 // use arrow edge's center point as default arrow offset.
204 bool center_arrow_;
msw 2012/09/18 19:33:42 This state should be merged into the ArrowLocation
xiyuan 2012/09/19 18:20:09 Done.
205
175 DISALLOW_COPY_AND_ASSIGN(BubbleBorder); 206 DISALLOW_COPY_AND_ASSIGN(BubbleBorder);
176 }; 207 };
177 208
178 // A Background that clips itself to the specified BubbleBorder and uses 209 // A Background that clips itself to the specified BubbleBorder and uses
179 // the background color of the BubbleBorder. 210 // the background color of the BubbleBorder.
180 class VIEWS_EXPORT BubbleBackground : public Background { 211 class VIEWS_EXPORT BubbleBackground : public Background {
181 public: 212 public:
182 explicit BubbleBackground(BubbleBorder* border) : border_(border) {} 213 explicit BubbleBackground(BubbleBorder* border) : border_(border) {}
183 214
184 // Overridden from Background: 215 // Overridden from Background:
185 virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE; 216 virtual void Paint(gfx::Canvas* canvas, View* view) const OVERRIDE;
186 217
187 private: 218 private:
188 BubbleBorder* border_; 219 BubbleBorder* border_;
189 220
190 DISALLOW_COPY_AND_ASSIGN(BubbleBackground); 221 DISALLOW_COPY_AND_ASSIGN(BubbleBackground);
191 }; 222 };
192 223
193 } // namespace views 224 } // namespace views
194 225
195 #endif // UI_VIEWS_BUBBLE_BUBBLE_BORDER_H_ 226 #endif // UI_VIEWS_BUBBLE_BUBBLE_BORDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698