OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 VIEWS_BUBBLE_BUBBLE_BORDER_H_ | 5 #ifndef VIEWS_BUBBLE_BUBBLE_BORDER_H_ |
6 #define VIEWS_BUBBLE_BUBBLE_BORDER_H_ | 6 #define VIEWS_BUBBLE_BUBBLE_BORDER_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "views/background.h" | 9 #include "views/background.h" |
10 #include "views/border.h" | 10 #include "views/border.h" |
11 | 11 |
12 class SkBitmap; | 12 class SkBitmap; |
13 | 13 |
14 namespace views { | 14 namespace views { |
15 | 15 |
16 struct BorderImages { | |
sky
2011/11/15 05:06:37
Forward declare this as a struct in BubbleBorder.
koz (OOO until 15th September)
2011/11/15 06:35:43
I'm not sure I've understood you here - I've added
sky
2011/11/15 16:36:33
Close. Since you don't actually need the implement
koz (OOO until 15th September)
2011/11/15 22:45:39
Thanks for the clarification. Done.
| |
17 SkBitmap* left; | |
18 SkBitmap* top_left; | |
19 SkBitmap* top; | |
20 SkBitmap* top_right; | |
21 SkBitmap* right; | |
22 SkBitmap* bottom_right; | |
23 SkBitmap* bottom; | |
24 SkBitmap* bottom_left; | |
25 SkBitmap* left_arrow; | |
26 SkBitmap* top_arrow; | |
27 SkBitmap* right_arrow; | |
28 SkBitmap* bottom_arrow; | |
29 }; | |
30 | |
sky
2011/11/15 05:06:37
nit: remove one of these lines.
koz (OOO until 15th September)
2011/11/15 06:35:43
Done.
| |
31 | |
16 // Renders a border, with optional arrow, and a custom dropshadow. | 32 // Renders a border, with optional arrow, and a custom dropshadow. |
17 // This can be used to produce floating "bubble" objects with rounded corners. | 33 // This can be used to produce floating "bubble" objects with rounded corners. |
18 class VIEWS_EXPORT BubbleBorder : public views::Border { | 34 class VIEWS_EXPORT BubbleBorder : public views::Border { |
19 public: | 35 public: |
20 // Possible locations for the (optional) arrow. | 36 // Possible locations for the (optional) arrow. |
21 // 0 bit specifies left or right. | 37 // 0 bit specifies left or right. |
22 // 1 bit specifies top or bottom. | 38 // 1 bit specifies top or bottom. |
23 // 2 bit specifies horizontal or vertical. | 39 // 2 bit specifies horizontal or vertical. |
24 enum ArrowLocation { | 40 enum ArrowLocation { |
25 TOP_LEFT = 0, | 41 TOP_LEFT = 0, |
26 TOP_RIGHT = 1, | 42 TOP_RIGHT = 1, |
27 BOTTOM_LEFT = 2, | 43 BOTTOM_LEFT = 2, |
28 BOTTOM_RIGHT = 3, | 44 BOTTOM_RIGHT = 3, |
29 LEFT_TOP = 4, | 45 LEFT_TOP = 4, |
30 RIGHT_TOP = 5, | 46 RIGHT_TOP = 5, |
31 LEFT_BOTTOM = 6, | 47 LEFT_BOTTOM = 6, |
32 RIGHT_BOTTOM = 7, | 48 RIGHT_BOTTOM = 7, |
33 NONE = 8, // No arrow. Positioned under the supplied rect. | 49 NONE = 8, // No arrow. Positioned under the supplied rect. |
34 FLOAT = 9 // No arrow. Centered over the supplied rect. | 50 FLOAT = 9 // No arrow. Centered over the supplied rect. |
35 }; | 51 }; |
36 | 52 |
53 enum Shadow { | |
54 SHADOW = 0, | |
55 NO_SHADOW = 1 | |
56 }; | |
57 | |
37 // The position of the bubble in relation to the anchor. | 58 // The position of the bubble in relation to the anchor. |
38 enum BubbleAlignment { | 59 enum BubbleAlignment { |
39 // The tip of the arrow points to the middle of the anchor. | 60 // The tip of the arrow points to the middle of the anchor. |
40 ALIGN_ARROW_TO_MID_ANCHOR, | 61 ALIGN_ARROW_TO_MID_ANCHOR, |
41 // The edge nearest to the arrow is lined up with the edge of the anchor. | 62 // The edge nearest to the arrow is lined up with the edge of the anchor. |
42 ALIGN_EDGE_TO_ANCHOR_EDGE | 63 ALIGN_EDGE_TO_ANCHOR_EDGE |
43 }; | 64 }; |
44 | 65 |
45 explicit BubbleBorder(ArrowLocation arrow_location) | 66 BubbleBorder(ArrowLocation arrow_location, Shadow shadow) |
46 : override_arrow_offset_(0), | 67 : override_arrow_offset_(0), |
47 arrow_location_(arrow_location), | 68 arrow_location_(arrow_location), |
48 alignment_(ALIGN_ARROW_TO_MID_ANCHOR), | 69 alignment_(ALIGN_ARROW_TO_MID_ANCHOR), |
49 background_color_(SK_ColorWHITE) { | 70 background_color_(SK_ColorWHITE) { |
50 InitClass(); | 71 InitClass(shadow); |
51 } | 72 } |
52 | 73 |
53 // Returns the radius of the corner of the border. | 74 // Returns the radius of the corner of the border. |
54 static int GetCornerRadius() { | 75 static int GetCornerRadius() { |
55 // We can't safely calculate a border radius by comparing the sizes of the | 76 // We can't safely calculate a border radius by comparing the sizes of the |
56 // side and corner images, because either may have been extended in various | 77 // side and corner images, because either may have been extended in various |
57 // directions in order to do more subtle dropshadow fading or other effects. | 78 // directions in order to do more subtle dropshadow fading or other effects. |
58 // So we hardcode the most accurate value. | 79 // So we hardcode the most accurate value. |
59 return 4; | 80 return 4; |
60 } | 81 } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
111 // The arrow will still point to the same location but the bubble will shift | 132 // The arrow will still point to the same location but the bubble will shift |
112 // location to make that happen. Returns actuall arrow offset, in case of | 133 // location to make that happen. Returns actuall arrow offset, in case of |
113 // overflow it differ from desired. | 134 // overflow it differ from desired. |
114 int SetArrowOffset(int offset, const gfx::Size& contents_size); | 135 int SetArrowOffset(int offset, const gfx::Size& contents_size); |
115 | 136 |
116 // Overridden from views::Border: | 137 // Overridden from views::Border: |
117 virtual void GetInsets(gfx::Insets* insets) const; | 138 virtual void GetInsets(gfx::Insets* insets) const; |
118 | 139 |
119 private: | 140 private: |
120 // Loads images if necessary. | 141 // Loads images if necessary. |
121 static void InitClass(); | 142 void InitClass(Shadow shadow); |
122 | 143 |
123 virtual ~BubbleBorder(); | 144 virtual ~BubbleBorder(); |
124 | 145 |
125 // Overridden from views::Border: | 146 // Overridden from views::Border: |
126 virtual void Paint(const views::View& view, gfx::Canvas* canvas) const; | 147 virtual void Paint(const views::View& view, gfx::Canvas* canvas) const; |
127 | 148 |
128 void DrawEdgeWithArrow(gfx::Canvas* canvas, | 149 void DrawEdgeWithArrow(gfx::Canvas* canvas, |
129 bool is_horizontal, | 150 bool is_horizontal, |
130 SkBitmap* edge, | 151 SkBitmap* edge, |
131 SkBitmap* arrow, | 152 SkBitmap* arrow, |
132 int start_x, | 153 int start_x, |
133 int start_y, | 154 int start_y, |
134 int before_arrow, | 155 int before_arrow, |
135 int after_arrow, | 156 int after_arrow, |
136 int offset) const; | 157 int offset) const; |
137 | 158 |
138 void DrawArrowInterior(gfx::Canvas* canvas, | 159 void DrawArrowInterior(gfx::Canvas* canvas, |
139 bool is_horizontal, | 160 bool is_horizontal, |
140 int tip_x, | 161 int tip_x, |
141 int tip_y, | 162 int tip_y, |
142 int shift_x, | 163 int shift_x, |
143 int shift_y) const; | 164 int shift_y) const; |
144 | 165 |
145 // Border graphics. | 166 // Border graphics. |
146 static SkBitmap* left_; | 167 SkBitmap* left_; |
sky
2011/11/15 05:06:37
It's weird to have this and the struct. How about
koz (OOO until 15th September)
2011/11/15 06:35:43
Done.
| |
147 static SkBitmap* top_left_; | 168 SkBitmap* top_left_; |
148 static SkBitmap* top_; | 169 SkBitmap* top_; |
149 static SkBitmap* top_right_; | 170 SkBitmap* top_right_; |
150 static SkBitmap* right_; | 171 SkBitmap* right_; |
151 static SkBitmap* bottom_right_; | 172 SkBitmap* bottom_right_; |
152 static SkBitmap* bottom_; | 173 SkBitmap* bottom_; |
153 static SkBitmap* bottom_left_; | 174 SkBitmap* bottom_left_; |
154 static SkBitmap* left_arrow_; | 175 SkBitmap* left_arrow_; |
155 static SkBitmap* top_arrow_; | 176 SkBitmap* top_arrow_; |
156 static SkBitmap* right_arrow_; | 177 SkBitmap* right_arrow_; |
157 static SkBitmap* bottom_arrow_; | 178 SkBitmap* bottom_arrow_; |
179 | |
180 // Image bundles. | |
181 static struct BorderImages* normal_images_; | |
182 static struct BorderImages* shadow_images_; | |
158 | 183 |
159 // 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. |
160 static int arrow_offset_; | 185 int arrow_offset_; |
161 | 186 |
162 // If specified, overrides the pre-calculated |arrow_offset_| of the arrow. | 187 // If specified, overrides the pre-calculated |arrow_offset_| of the arrow. |
163 int override_arrow_offset_; | 188 int override_arrow_offset_; |
164 | 189 |
165 ArrowLocation arrow_location_; | 190 ArrowLocation arrow_location_; |
166 BubbleAlignment alignment_; | 191 BubbleAlignment alignment_; |
167 SkColor background_color_; | 192 SkColor background_color_; |
168 | 193 |
169 DISALLOW_COPY_AND_ASSIGN(BubbleBorder); | 194 DISALLOW_COPY_AND_ASSIGN(BubbleBorder); |
170 }; | 195 }; |
171 | 196 |
172 // A Background that clips itself to the specified BubbleBorder and uses | 197 // A Background that clips itself to the specified BubbleBorder and uses |
173 // the background color of the BubbleBorder. | 198 // the background color of the BubbleBorder. |
174 class VIEWS_EXPORT BubbleBackground : public views::Background { | 199 class VIEWS_EXPORT BubbleBackground : public views::Background { |
175 public: | 200 public: |
176 explicit BubbleBackground(BubbleBorder* border) : border_(border) {} | 201 explicit BubbleBackground(BubbleBorder* border) : border_(border) {} |
177 | 202 |
178 // Background overrides. | 203 // Background overrides. |
179 virtual void Paint(gfx::Canvas* canvas, views::View* view) const; | 204 virtual void Paint(gfx::Canvas* canvas, views::View* view) const; |
180 | 205 |
181 private: | 206 private: |
182 BubbleBorder* border_; | 207 BubbleBorder* border_; |
183 | 208 |
184 DISALLOW_COPY_AND_ASSIGN(BubbleBackground); | 209 DISALLOW_COPY_AND_ASSIGN(BubbleBackground); |
185 }; | 210 }; |
186 | 211 |
187 } // namespace views | 212 } // namespace views |
188 | 213 |
189 #endif // VIEWS_BUBBLE_BUBBLE_BORDER_H_ | 214 #endif // VIEWS_BUBBLE_BUBBLE_BORDER_H_ |
OLD | NEW |