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" |
(...skipping 16 matching lines...) Expand all Loading... |
27 BOTTOM_LEFT = 2, | 27 BOTTOM_LEFT = 2, |
28 BOTTOM_RIGHT = 3, | 28 BOTTOM_RIGHT = 3, |
29 LEFT_TOP = 4, | 29 LEFT_TOP = 4, |
30 RIGHT_TOP = 5, | 30 RIGHT_TOP = 5, |
31 LEFT_BOTTOM = 6, | 31 LEFT_BOTTOM = 6, |
32 RIGHT_BOTTOM = 7, | 32 RIGHT_BOTTOM = 7, |
33 NONE = 8, // No arrow. Positioned under the supplied rect. | 33 NONE = 8, // No arrow. Positioned under the supplied rect. |
34 FLOAT = 9 // No arrow. Centered over the supplied rect. | 34 FLOAT = 9 // No arrow. Centered over the supplied rect. |
35 }; | 35 }; |
36 | 36 |
| 37 enum Shadow { |
| 38 SHADOW = 0, |
| 39 NO_SHADOW = 1 |
| 40 }; |
| 41 |
| 42 struct BorderImages { |
| 43 BorderImages() |
| 44 : left(NULL), |
| 45 top_left(NULL), |
| 46 top(NULL), |
| 47 top_right(NULL), |
| 48 right(NULL), |
| 49 bottom_right(NULL), |
| 50 bottom(NULL), |
| 51 bottom_left(NULL), |
| 52 left_arrow(NULL), |
| 53 top_arrow(NULL), |
| 54 right_arrow(NULL), |
| 55 bottom_arrow(NULL) { |
| 56 } |
| 57 |
| 58 SkBitmap* left; |
| 59 SkBitmap* top_left; |
| 60 SkBitmap* top; |
| 61 SkBitmap* top_right; |
| 62 SkBitmap* right; |
| 63 SkBitmap* bottom_right; |
| 64 SkBitmap* bottom; |
| 65 SkBitmap* bottom_left; |
| 66 SkBitmap* left_arrow; |
| 67 SkBitmap* top_arrow; |
| 68 SkBitmap* right_arrow; |
| 69 SkBitmap* bottom_arrow; |
| 70 }; |
| 71 |
37 // The position of the bubble in relation to the anchor. | 72 // The position of the bubble in relation to the anchor. |
38 enum BubbleAlignment { | 73 enum BubbleAlignment { |
39 // The tip of the arrow points to the middle of the anchor. | 74 // The tip of the arrow points to the middle of the anchor. |
40 ALIGN_ARROW_TO_MID_ANCHOR, | 75 ALIGN_ARROW_TO_MID_ANCHOR, |
41 // The edge nearest to the arrow is lined up with the edge of the anchor. | 76 // The edge nearest to the arrow is lined up with the edge of the anchor. |
42 ALIGN_EDGE_TO_ANCHOR_EDGE | 77 ALIGN_EDGE_TO_ANCHOR_EDGE |
43 }; | 78 }; |
44 | 79 |
45 explicit BubbleBorder(ArrowLocation arrow_location) | 80 BubbleBorder(ArrowLocation arrow_location, Shadow shadow); |
46 : override_arrow_offset_(0), | |
47 arrow_location_(arrow_location), | |
48 alignment_(ALIGN_ARROW_TO_MID_ANCHOR), | |
49 background_color_(SK_ColorWHITE) { | |
50 InitClass(); | |
51 } | |
52 | 81 |
53 // Returns the radius of the corner of the border. | 82 // Returns the radius of the corner of the border. |
54 static int GetCornerRadius() { | 83 static int GetCornerRadius() { |
55 // We can't safely calculate a border radius by comparing the sizes of the | 84 // 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 | 85 // 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. | 86 // directions in order to do more subtle dropshadow fading or other effects. |
58 // So we hardcode the most accurate value. | 87 // So we hardcode the most accurate value. |
59 return 4; | 88 return 4; |
60 } | 89 } |
61 | 90 |
(...skipping 49 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 | 140 // 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 | 141 // location to make that happen. Returns actuall arrow offset, in case of |
113 // overflow it differ from desired. | 142 // overflow it differ from desired. |
114 int SetArrowOffset(int offset, const gfx::Size& contents_size); | 143 int SetArrowOffset(int offset, const gfx::Size& contents_size); |
115 | 144 |
116 // Overridden from views::Border: | 145 // Overridden from views::Border: |
117 virtual void GetInsets(gfx::Insets* insets) const; | 146 virtual void GetInsets(gfx::Insets* insets) const; |
118 | 147 |
119 private: | 148 private: |
120 // Loads images if necessary. | 149 // Loads images if necessary. |
121 static void InitClass(); | 150 static BorderImages* GetBorderImages(Shadow shadow); |
122 | 151 |
123 virtual ~BubbleBorder(); | 152 virtual ~BubbleBorder(); |
124 | 153 |
125 // Overridden from views::Border: | 154 // Overridden from views::Border: |
126 virtual void Paint(const views::View& view, gfx::Canvas* canvas) const; | 155 virtual void Paint(const views::View& view, gfx::Canvas* canvas) const; |
127 | 156 |
128 void DrawEdgeWithArrow(gfx::Canvas* canvas, | 157 void DrawEdgeWithArrow(gfx::Canvas* canvas, |
129 bool is_horizontal, | 158 bool is_horizontal, |
130 SkBitmap* edge, | 159 SkBitmap* edge, |
131 SkBitmap* arrow, | 160 SkBitmap* arrow, |
132 int start_x, | 161 int start_x, |
133 int start_y, | 162 int start_y, |
134 int before_arrow, | 163 int before_arrow, |
135 int after_arrow, | 164 int after_arrow, |
136 int offset) const; | 165 int offset) const; |
137 | 166 |
138 void DrawArrowInterior(gfx::Canvas* canvas, | 167 void DrawArrowInterior(gfx::Canvas* canvas, |
139 bool is_horizontal, | 168 bool is_horizontal, |
140 int tip_x, | 169 int tip_x, |
141 int tip_y, | 170 int tip_y, |
142 int shift_x, | 171 int shift_x, |
143 int shift_y) const; | 172 int shift_y) const; |
144 | 173 |
145 // Border graphics. | 174 // Border graphics. |
146 static SkBitmap* left_; | 175 struct BorderImages* images_; |
147 static SkBitmap* top_left_; | 176 |
148 static SkBitmap* top_; | 177 // Image bundles. |
149 static SkBitmap* top_right_; | 178 static struct BorderImages* normal_images_; |
150 static SkBitmap* right_; | 179 static struct BorderImages* shadow_images_; |
151 static SkBitmap* bottom_right_; | |
152 static SkBitmap* bottom_; | |
153 static SkBitmap* bottom_left_; | |
154 static SkBitmap* left_arrow_; | |
155 static SkBitmap* top_arrow_; | |
156 static SkBitmap* right_arrow_; | |
157 static SkBitmap* bottom_arrow_; | |
158 | 180 |
159 // Minimal offset of the arrow from the closet edge of bounding rect. | 181 // Minimal offset of the arrow from the closet edge of bounding rect. |
160 static int arrow_offset_; | 182 int arrow_offset_; |
161 | 183 |
162 // If specified, overrides the pre-calculated |arrow_offset_| of the arrow. | 184 // If specified, overrides the pre-calculated |arrow_offset_| of the arrow. |
163 int override_arrow_offset_; | 185 int override_arrow_offset_; |
164 | 186 |
165 ArrowLocation arrow_location_; | 187 ArrowLocation arrow_location_; |
166 BubbleAlignment alignment_; | 188 BubbleAlignment alignment_; |
167 SkColor background_color_; | 189 SkColor background_color_; |
168 | 190 |
169 DISALLOW_COPY_AND_ASSIGN(BubbleBorder); | 191 DISALLOW_COPY_AND_ASSIGN(BubbleBorder); |
170 }; | 192 }; |
171 | 193 |
172 // A Background that clips itself to the specified BubbleBorder and uses | 194 // A Background that clips itself to the specified BubbleBorder and uses |
173 // the background color of the BubbleBorder. | 195 // the background color of the BubbleBorder. |
174 class VIEWS_EXPORT BubbleBackground : public views::Background { | 196 class VIEWS_EXPORT BubbleBackground : public views::Background { |
175 public: | 197 public: |
176 explicit BubbleBackground(BubbleBorder* border) : border_(border) {} | 198 explicit BubbleBackground(BubbleBorder* border) : border_(border) {} |
177 | 199 |
178 // Background overrides. | 200 // Background overrides. |
179 virtual void Paint(gfx::Canvas* canvas, views::View* view) const; | 201 virtual void Paint(gfx::Canvas* canvas, views::View* view) const; |
180 | 202 |
181 private: | 203 private: |
182 BubbleBorder* border_; | 204 BubbleBorder* border_; |
183 | 205 |
184 DISALLOW_COPY_AND_ASSIGN(BubbleBackground); | 206 DISALLOW_COPY_AND_ASSIGN(BubbleBackground); |
185 }; | 207 }; |
186 | 208 |
187 } // namespace views | 209 } // namespace views |
188 | 210 |
189 #endif // VIEWS_BUBBLE_BUBBLE_BORDER_H_ | 211 #endif // VIEWS_BUBBLE_BUBBLE_BORDER_H_ |
OLD | NEW |