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 #include "views/bubble/bubble_border.h" | 5 #include "views/bubble/bubble_border.h" |
6 | 6 |
7 #include <algorithm> // for std::max | 7 #include <algorithm> // for std::max |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
11 #include "grit/ui_resources_standard.h" | 11 #include "grit/ui_resources_standard.h" |
12 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
13 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
14 #include "ui/gfx/canvas_skia.h" | 14 #include "ui/gfx/canvas_skia.h" |
15 #include "ui/gfx/path.h" | 15 #include "ui/gfx/path.h" |
16 | 16 |
17 namespace views { | 17 namespace views { |
18 | 18 |
19 // static | 19 // static |
20 SkBitmap* BubbleBorder::left_ = NULL; | 20 struct BubbleBorder::BorderImages* BubbleBorder::normal_images_ = NULL; |
21 SkBitmap* BubbleBorder::top_left_ = NULL; | 21 struct BubbleBorder::BorderImages* BubbleBorder::shadow_images_ = NULL; |
22 SkBitmap* BubbleBorder::top_ = NULL; | |
23 SkBitmap* BubbleBorder::top_right_ = NULL; | |
24 SkBitmap* BubbleBorder::right_ = NULL; | |
25 SkBitmap* BubbleBorder::bottom_right_ = NULL; | |
26 SkBitmap* BubbleBorder::bottom_ = NULL; | |
27 SkBitmap* BubbleBorder::bottom_left_ = NULL; | |
28 SkBitmap* BubbleBorder::top_arrow_ = NULL; | |
29 SkBitmap* BubbleBorder::bottom_arrow_ = NULL; | |
30 SkBitmap* BubbleBorder::left_arrow_ = NULL; | |
31 SkBitmap* BubbleBorder::right_arrow_ = NULL; | |
32 | 22 |
33 // static | |
34 int BubbleBorder::arrow_offset_; | |
35 | 23 |
36 // The height inside the arrow image, in pixels. | 24 // The height inside the arrow image, in pixels. |
37 static const int kArrowInteriorHeight = 7; | 25 static const int kArrowInteriorHeight = 7; |
38 | 26 |
27 BubbleBorder::BubbleBorder(ArrowLocation arrow_location, Shadow shadow) | |
28 : override_arrow_offset_(0), | |
sky
2011/11/15 16:36:34
spacing is off.
koz (OOO until 15th September)
2011/11/15 22:45:39
Done.
| |
29 arrow_location_(arrow_location), | |
30 alignment_(ALIGN_ARROW_TO_MID_ANCHOR), | |
31 background_color_(SK_ColorWHITE) { | |
32 images_ = GetBorderImages(shadow); | |
33 | |
34 // Calculate horizontal and vertical insets for arrow by ensuring that | |
35 // the widest arrow and corner images will have enough room to avoid overlap | |
36 int offset_x = | |
37 (std::max(images_->top_arrow->width(), | |
38 images_->bottom_arrow->width()) / 2) + | |
39 std::max(std::max(images_->top_left->width(), | |
40 images_->top_right->width()), | |
41 std::max(images_->bottom_left->width(), | |
42 images_->bottom_right->width())); | |
43 int offset_y = | |
44 (std::max(images_->left_arrow->height(), | |
45 images_->right_arrow->height()) / 2) + | |
46 std::max(std::max(images_->top_left->height(), | |
47 images_->top_right->height()), | |
48 std::max(images_->bottom_left->height(), | |
49 images_->bottom_right->height())); | |
50 arrow_offset_ = std::max(offset_x, offset_y); | |
51 } | |
52 | |
39 gfx::Rect BubbleBorder::GetBounds(const gfx::Rect& position_relative_to, | 53 gfx::Rect BubbleBorder::GetBounds(const gfx::Rect& position_relative_to, |
40 const gfx::Size& contents_size) const { | 54 const gfx::Size& contents_size) const { |
41 // Desired size is size of contents enlarged by the size of the border images. | 55 // Desired size is size of contents enlarged by the size of the border images. |
42 gfx::Size border_size(contents_size); | 56 gfx::Size border_size(contents_size); |
43 gfx::Insets insets; | 57 gfx::Insets insets; |
44 GetInsets(&insets); | 58 GetInsets(&insets); |
45 border_size.Enlarge(insets.left() + insets.right(), | 59 border_size.Enlarge(insets.left() + insets.right(), |
46 insets.top() + insets.bottom()); | 60 insets.top() + insets.bottom()); |
47 | 61 |
48 // Screen position depends on the arrow location. | 62 // Screen position depends on the arrow location. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 | 132 |
119 case FLOAT: | 133 case FLOAT: |
120 y += h / 2 - border_size.height() / 2; | 134 y += h / 2 - border_size.height() / 2; |
121 break; | 135 break; |
122 } | 136 } |
123 | 137 |
124 return gfx::Rect(x, y, border_size.width(), border_size.height()); | 138 return gfx::Rect(x, y, border_size.width(), border_size.height()); |
125 } | 139 } |
126 | 140 |
127 void BubbleBorder::GetInsets(gfx::Insets* insets) const { | 141 void BubbleBorder::GetInsets(gfx::Insets* insets) const { |
128 int top = top_->height(); | 142 int top = images_->top->height(); |
129 int bottom = bottom_->height(); | 143 int bottom = images_->bottom->height(); |
130 int left = left_->width(); | 144 int left = images_->left->width(); |
131 int right = right_->width(); | 145 int right = images_->right->width(); |
132 switch (arrow_location_) { | 146 switch (arrow_location_) { |
133 case TOP_LEFT: | 147 case TOP_LEFT: |
134 case TOP_RIGHT: | 148 case TOP_RIGHT: |
135 top = std::max(top, top_arrow_->height()); | 149 top = std::max(top, images_->top_arrow->height()); |
136 break; | 150 break; |
137 | 151 |
138 case BOTTOM_LEFT: | 152 case BOTTOM_LEFT: |
139 case BOTTOM_RIGHT: | 153 case BOTTOM_RIGHT: |
140 bottom = std::max(bottom, bottom_arrow_->height()); | 154 bottom = std::max(bottom, images_->bottom_arrow->height()); |
141 break; | 155 break; |
142 | 156 |
143 case LEFT_TOP: | 157 case LEFT_TOP: |
144 case LEFT_BOTTOM: | 158 case LEFT_BOTTOM: |
145 left = std::max(left, left_arrow_->width()); | 159 left = std::max(left, images_->left_arrow->width()); |
146 break; | 160 break; |
147 | 161 |
148 case RIGHT_TOP: | 162 case RIGHT_TOP: |
149 case RIGHT_BOTTOM: | 163 case RIGHT_BOTTOM: |
150 right = std::max(right, right_arrow_->width()); | 164 right = std::max(right, images_->right_arrow->width()); |
151 break; | 165 break; |
152 | 166 |
153 case NONE: | 167 case NONE: |
154 case FLOAT: | 168 case FLOAT: |
155 // Nothing to do. | 169 // Nothing to do. |
156 break; | 170 break; |
157 } | 171 } |
158 insets->Set(top, left, bottom, right); | 172 insets->Set(top, left, bottom, right); |
159 } | 173 } |
160 | 174 |
161 int BubbleBorder::SetArrowOffset(int offset, const gfx::Size& contents_size) { | 175 int BubbleBorder::SetArrowOffset(int offset, const gfx::Size& contents_size) { |
162 gfx::Size border_size(contents_size); | 176 gfx::Size border_size(contents_size); |
163 gfx::Insets insets; | 177 gfx::Insets insets; |
164 GetInsets(&insets); | 178 GetInsets(&insets); |
165 border_size.Enlarge(insets.left() + insets.right(), | 179 border_size.Enlarge(insets.left() + insets.right(), |
166 insets.top() + insets.bottom()); | 180 insets.top() + insets.bottom()); |
167 offset = std::max(arrow_offset_, | 181 offset = std::max(arrow_offset_, |
168 std::min(offset, (is_arrow_on_horizontal(arrow_location_) ? | 182 std::min(offset, (is_arrow_on_horizontal(arrow_location_) ? |
169 border_size.width() : border_size.height()) - arrow_offset_)); | 183 border_size.width() : border_size.height()) - arrow_offset_)); |
170 override_arrow_offset_ = offset; | 184 override_arrow_offset_ = offset; |
171 return override_arrow_offset_; | 185 return override_arrow_offset_; |
172 } | 186 } |
173 | 187 |
174 // static | 188 // static |
175 void BubbleBorder::InitClass() { | 189 BubbleBorder::BorderImages* BubbleBorder::GetBorderImages(Shadow shadow) { |
176 static bool initialized = false; | 190 if (shadow == SHADOW && shadow_images_ == NULL) { |
177 if (!initialized) { | |
178 // Load images. | |
179 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 191 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
180 left_ = rb.GetBitmapNamed(IDR_BUBBLE_L); | 192 shadow_images_ = new BorderImages(); |
181 top_left_ = rb.GetBitmapNamed(IDR_BUBBLE_TL); | 193 shadow_images_->left = rb.GetBitmapNamed(IDR_BUBBLE_SHADOW_L); |
182 top_ = rb.GetBitmapNamed(IDR_BUBBLE_T); | 194 shadow_images_->top_left = rb.GetBitmapNamed(IDR_BUBBLE_SHADOW_TL); |
183 top_right_ = rb.GetBitmapNamed(IDR_BUBBLE_TR); | 195 shadow_images_->top = rb.GetBitmapNamed(IDR_BUBBLE_SHADOW_T); |
184 right_ = rb.GetBitmapNamed(IDR_BUBBLE_R); | 196 shadow_images_->top_right = rb.GetBitmapNamed(IDR_BUBBLE_SHADOW_TR); |
185 bottom_right_ = rb.GetBitmapNamed(IDR_BUBBLE_BR); | 197 shadow_images_->right = rb.GetBitmapNamed(IDR_BUBBLE_SHADOW_R); |
186 bottom_ = rb.GetBitmapNamed(IDR_BUBBLE_B); | 198 shadow_images_->bottom_right = rb.GetBitmapNamed(IDR_BUBBLE_SHADOW_BR); |
187 bottom_left_ = rb.GetBitmapNamed(IDR_BUBBLE_BL); | 199 shadow_images_->bottom = rb.GetBitmapNamed(IDR_BUBBLE_SHADOW_B); |
188 left_arrow_ = rb.GetBitmapNamed(IDR_BUBBLE_L_ARROW); | 200 shadow_images_->bottom_left = rb.GetBitmapNamed(IDR_BUBBLE_SHADOW_BL); |
189 top_arrow_ = rb.GetBitmapNamed(IDR_BUBBLE_T_ARROW); | 201 shadow_images_->left_arrow = new SkBitmap(); |
190 right_arrow_ = rb.GetBitmapNamed(IDR_BUBBLE_R_ARROW); | 202 shadow_images_->top_arrow = new SkBitmap(); |
191 bottom_arrow_ = rb.GetBitmapNamed(IDR_BUBBLE_B_ARROW); | 203 shadow_images_->right_arrow = new SkBitmap(); |
192 | 204 shadow_images_->bottom_arrow = new SkBitmap(); |
193 // Calculate horizontal and vertical insets for arrow by ensuring that | 205 } else if (shadow == NO_SHADOW && normal_images_ == NULL) { |
194 // the widest arrow and corner images will have enough room to avoid overlap | 206 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
195 int offset_x = | 207 normal_images_ = new BorderImages(); |
196 (std::max(top_arrow_->width(), bottom_arrow_->width()) / 2) + | 208 normal_images_->left = rb.GetBitmapNamed(IDR_BUBBLE_L); |
197 std::max(std::max(top_left_->width(), top_right_->width()), | 209 normal_images_->top_left = rb.GetBitmapNamed(IDR_BUBBLE_TL); |
198 std::max(bottom_left_->width(), bottom_right_->width())); | 210 normal_images_->top = rb.GetBitmapNamed(IDR_BUBBLE_T); |
199 int offset_y = | 211 normal_images_->top_right = rb.GetBitmapNamed(IDR_BUBBLE_TR); |
200 (std::max(left_arrow_->height(), right_arrow_->height()) / 2) + | 212 normal_images_->right = rb.GetBitmapNamed(IDR_BUBBLE_R); |
201 std::max(std::max(top_left_->height(), top_right_->height()), | 213 normal_images_->bottom_right = rb.GetBitmapNamed(IDR_BUBBLE_BR); |
202 std::max(bottom_left_->height(), bottom_right_->height())); | 214 normal_images_->bottom = rb.GetBitmapNamed(IDR_BUBBLE_B); |
203 arrow_offset_ = std::max(offset_x, offset_y); | 215 normal_images_->bottom_left = rb.GetBitmapNamed(IDR_BUBBLE_BL); |
204 | 216 normal_images_->left_arrow = rb.GetBitmapNamed(IDR_BUBBLE_L_ARROW); |
205 initialized = true; | 217 normal_images_->top_arrow = rb.GetBitmapNamed(IDR_BUBBLE_T_ARROW); |
218 normal_images_->right_arrow = rb.GetBitmapNamed(IDR_BUBBLE_R_ARROW); | |
219 normal_images_->bottom_arrow = rb.GetBitmapNamed(IDR_BUBBLE_B_ARROW); | |
206 } | 220 } |
221 return shadow == SHADOW ? shadow_images_ : normal_images_; | |
207 } | 222 } |
208 | 223 |
209 BubbleBorder::~BubbleBorder() {} | 224 BubbleBorder::~BubbleBorder() {} |
210 | 225 |
211 void BubbleBorder::Paint(const views::View& view, gfx::Canvas* canvas) const { | 226 void BubbleBorder::Paint(const views::View& view, gfx::Canvas* canvas) const { |
212 // Convenience shorthand variables. | 227 // Convenience shorthand variables. |
213 const int tl_width = top_left_->width(); | 228 const int tl_width = images_->top_left->width(); |
214 const int tl_height = top_left_->height(); | 229 const int tl_height = images_->top_left->height(); |
215 const int t_height = top_->height(); | 230 const int t_height = images_->top->height(); |
216 const int tr_width = top_right_->width(); | 231 const int tr_width = images_->top_right->width(); |
217 const int tr_height = top_right_->height(); | 232 const int tr_height = images_->top_right->height(); |
218 const int l_width = left_->width(); | 233 const int l_width = images_->left->width(); |
219 const int r_width = right_->width(); | 234 const int r_width = images_->right->width(); |
220 const int br_width = bottom_right_->width(); | 235 const int br_width = images_->bottom_right->width(); |
221 const int br_height = bottom_right_->height(); | 236 const int br_height = images_->bottom_right->height(); |
222 const int b_height = bottom_->height(); | 237 const int b_height = images_->bottom->height(); |
223 const int bl_width = bottom_left_->width(); | 238 const int bl_width = images_->bottom_left->width(); |
224 const int bl_height = bottom_left_->height(); | 239 const int bl_height = images_->bottom_left->height(); |
225 | 240 |
226 gfx::Insets insets; | 241 gfx::Insets insets; |
227 GetInsets(&insets); | 242 GetInsets(&insets); |
228 const int top = insets.top() - t_height; | 243 const int top = insets.top() - t_height; |
229 const int bottom = view.height() - insets.bottom() + b_height; | 244 const int bottom = view.height() - insets.bottom() + b_height; |
230 const int left = insets.left() - l_width; | 245 const int left = insets.left() - l_width; |
231 const int right = view.width() - insets.right() + r_width; | 246 const int right = view.width() - insets.right() + r_width; |
232 const int height = bottom - top; | 247 const int height = bottom - top; |
233 const int width = right - left; | 248 const int width = right - left; |
234 | 249 |
235 // |arrow_offset| is offset of arrow from the begining of the edge. | 250 // |arrow_offset| is offset of arrow from the begining of the edge. |
236 int arrow_offset = arrow_offset_; | 251 int arrow_offset = arrow_offset_; |
237 if (override_arrow_offset_) | 252 if (override_arrow_offset_) |
238 arrow_offset = override_arrow_offset_; | 253 arrow_offset = override_arrow_offset_; |
239 else if (is_arrow_on_horizontal(arrow_location_) && | 254 else if (is_arrow_on_horizontal(arrow_location_) && |
240 !is_arrow_on_left(arrow_location_)) { | 255 !is_arrow_on_left(arrow_location_)) { |
241 arrow_offset = view.width() - arrow_offset - 1; | 256 arrow_offset = view.width() - arrow_offset - 1; |
242 } else if (!is_arrow_on_horizontal(arrow_location_) && | 257 } else if (!is_arrow_on_horizontal(arrow_location_) && |
243 !is_arrow_on_top(arrow_location_)) { | 258 !is_arrow_on_top(arrow_location_)) { |
244 arrow_offset = view.height() - arrow_offset - 1; | 259 arrow_offset = view.height() - arrow_offset - 1; |
245 } | 260 } |
246 | 261 |
247 // Left edge. | 262 // Left edge. |
248 if (arrow_location_ == LEFT_TOP || arrow_location_ == LEFT_BOTTOM) { | 263 if (arrow_location_ == LEFT_TOP || arrow_location_ == LEFT_BOTTOM) { |
249 int start_y = top + tl_height; | 264 int start_y = top + tl_height; |
250 int before_arrow = arrow_offset - start_y - left_arrow_->height() / 2; | 265 int before_arrow = |
251 int after_arrow = | 266 arrow_offset - start_y - images_->left_arrow->height() / 2; |
252 height - tl_height - bl_height - left_arrow_->height() - before_arrow; | 267 int after_arrow = height - tl_height - bl_height - |
268 images_->left_arrow->height() - before_arrow; | |
269 int tip_y = start_y + before_arrow + images_->left_arrow->height() / 2; | |
253 DrawArrowInterior(canvas, | 270 DrawArrowInterior(canvas, |
254 false, | 271 false, |
255 left_arrow_->width() - kArrowInteriorHeight, | 272 images_->left_arrow->width() - kArrowInteriorHeight, |
256 start_y + before_arrow + left_arrow_->height() / 2, | 273 tip_y, |
257 kArrowInteriorHeight, | 274 kArrowInteriorHeight, |
258 left_arrow_->height() / 2 - 1); | 275 images_->left_arrow->height() / 2 - 1); |
259 DrawEdgeWithArrow(canvas, | 276 DrawEdgeWithArrow(canvas, |
260 false, | 277 false, |
261 left_, | 278 images_->left, |
262 left_arrow_, | 279 images_->left_arrow, |
263 left, | 280 left, |
264 start_y, | 281 start_y, |
265 before_arrow, | 282 before_arrow, |
266 after_arrow, | 283 after_arrow, |
267 left_->width() - left_arrow_->width()); | 284 images_->left->width() - images_->left_arrow->width()); |
268 } else { | 285 } else { |
269 canvas->TileImageInt(*left_, left, top + tl_height, l_width, | 286 canvas->TileImageInt(*images_->left, left, top + tl_height, l_width, |
270 height - tl_height - bl_height); | 287 height - tl_height - bl_height); |
271 } | 288 } |
272 | 289 |
273 // Top left corner. | 290 // Top left corner. |
274 canvas->DrawBitmapInt(*top_left_, left, top); | 291 canvas->DrawBitmapInt(*images_->top_left, left, top); |
275 | 292 |
276 // Top edge. | 293 // Top edge. |
277 if (arrow_location_ == TOP_LEFT || arrow_location_ == TOP_RIGHT) { | 294 if (arrow_location_ == TOP_LEFT || arrow_location_ == TOP_RIGHT) { |
278 int start_x = left + tl_width; | 295 int start_x = left + tl_width; |
279 int before_arrow = arrow_offset - start_x - top_arrow_->width() / 2; | 296 int before_arrow = arrow_offset - start_x - images_->top_arrow->width() / 2; |
280 int after_arrow = | 297 int after_arrow = width - tl_width - tr_width - |
281 width - tl_width - tr_width - top_arrow_->width() - before_arrow; | 298 images_->top_arrow->width() - before_arrow; |
282 DrawArrowInterior(canvas, | 299 DrawArrowInterior(canvas, |
283 true, | 300 true, |
284 start_x + before_arrow + top_arrow_->width() / 2, | 301 start_x + before_arrow + images_->top_arrow->width() / 2, |
285 top_arrow_->height() - kArrowInteriorHeight, | 302 images_->top_arrow->height() - kArrowInteriorHeight, |
286 1 - top_arrow_->width() / 2, | 303 1 - images_->top_arrow->width() / 2, |
287 kArrowInteriorHeight); | 304 kArrowInteriorHeight); |
288 DrawEdgeWithArrow(canvas, | 305 DrawEdgeWithArrow(canvas, |
289 true, | 306 true, |
290 top_, | 307 images_->top, |
291 top_arrow_, | 308 images_->top_arrow, |
292 start_x, | 309 start_x, |
293 top, | 310 top, |
294 before_arrow, | 311 before_arrow, |
295 after_arrow, | 312 after_arrow, |
296 top_->height() - top_arrow_->height()); | 313 images_->top->height() - images_->top_arrow->height()); |
297 } else { | 314 } else { |
298 canvas->TileImageInt(*top_, left + tl_width, top, | 315 canvas->TileImageInt(*images_->top, left + tl_width, top, |
299 width - tl_width - tr_width, t_height); | 316 width - tl_width - tr_width, t_height); |
300 } | 317 } |
301 | 318 |
302 // Top right corner. | 319 // Top right corner. |
303 canvas->DrawBitmapInt(*top_right_, right - tr_width, top); | 320 canvas->DrawBitmapInt(*images_->top_right, right - tr_width, top); |
304 | 321 |
305 // Right edge. | 322 // Right edge. |
306 if (arrow_location_ == RIGHT_TOP || arrow_location_ == RIGHT_BOTTOM) { | 323 if (arrow_location_ == RIGHT_TOP || arrow_location_ == RIGHT_BOTTOM) { |
307 int start_y = top + tr_height; | 324 int start_y = top + tr_height; |
308 int before_arrow = arrow_offset - start_y - right_arrow_->height() / 2; | 325 int before_arrow = |
326 arrow_offset - start_y - images_->right_arrow->height() / 2; | |
309 int after_arrow = height - tl_height - bl_height - | 327 int after_arrow = height - tl_height - bl_height - |
310 right_arrow_->height() - before_arrow; | 328 images_->right_arrow->height() - before_arrow; |
329 int tip_y = start_y + before_arrow + images_->right_arrow->height() / 2; | |
311 DrawArrowInterior(canvas, | 330 DrawArrowInterior(canvas, |
312 false, | 331 false, |
313 right - r_width + kArrowInteriorHeight, | 332 right - r_width + kArrowInteriorHeight, |
314 start_y + before_arrow + right_arrow_->height() / 2, | 333 tip_y, |
315 -kArrowInteriorHeight, | 334 -kArrowInteriorHeight, |
316 right_arrow_->height() / 2 - 1); | 335 images_->right_arrow->height() / 2 - 1); |
317 DrawEdgeWithArrow(canvas, | 336 DrawEdgeWithArrow(canvas, |
318 false, | 337 false, |
319 right_, | 338 images_->right, |
320 right_arrow_, | 339 images_->right_arrow, |
321 right - r_width, | 340 right - r_width, |
322 start_y, | 341 start_y, |
323 before_arrow, | 342 before_arrow, |
324 after_arrow, | 343 after_arrow, |
325 0); | 344 0); |
326 } else { | 345 } else { |
327 canvas->TileImageInt(*right_, right - r_width, top + tr_height, r_width, | 346 canvas->TileImageInt(*images_->right, right - r_width, top + tr_height, |
328 height - tr_height - br_height); | 347 r_width, height - tr_height - br_height); |
329 } | 348 } |
330 | 349 |
331 // Bottom right corner. | 350 // Bottom right corner. |
332 canvas->DrawBitmapInt(*bottom_right_, right - br_width, bottom - br_height); | 351 canvas->DrawBitmapInt(*images_->bottom_right, |
352 right - br_width, | |
353 bottom - br_height); | |
333 | 354 |
334 // Bottom edge. | 355 // Bottom edge. |
335 if (arrow_location_ == BOTTOM_LEFT || arrow_location_ == BOTTOM_RIGHT) { | 356 if (arrow_location_ == BOTTOM_LEFT || arrow_location_ == BOTTOM_RIGHT) { |
336 int start_x = left + bl_width; | 357 int start_x = left + bl_width; |
337 int before_arrow = arrow_offset - start_x - bottom_arrow_->width() / 2; | 358 int before_arrow = |
338 int after_arrow = | 359 arrow_offset - start_x - images_->bottom_arrow->width() / 2; |
339 width - bl_width - br_width - bottom_arrow_->width() - before_arrow; | 360 int after_arrow = width - bl_width - br_width - |
361 images_->bottom_arrow->width() - before_arrow; | |
362 int tip_x = start_x + before_arrow + images_->bottom_arrow->width() / 2; | |
340 DrawArrowInterior(canvas, | 363 DrawArrowInterior(canvas, |
341 true, | 364 true, |
342 start_x + before_arrow + bottom_arrow_->width() / 2, | 365 tip_x, |
343 bottom - b_height + kArrowInteriorHeight, | 366 bottom - b_height + kArrowInteriorHeight, |
344 1 - bottom_arrow_->width() / 2, | 367 1 - images_->bottom_arrow->width() / 2, |
345 -kArrowInteriorHeight); | 368 -kArrowInteriorHeight); |
346 DrawEdgeWithArrow(canvas, | 369 DrawEdgeWithArrow(canvas, |
347 true, | 370 true, |
348 bottom_, | 371 images_->bottom, |
349 bottom_arrow_, | 372 images_->bottom_arrow, |
350 start_x, | 373 start_x, |
351 bottom - b_height, | 374 bottom - b_height, |
352 before_arrow, | 375 before_arrow, |
353 after_arrow, | 376 after_arrow, |
354 0); | 377 0); |
355 } else { | 378 } else { |
356 canvas->TileImageInt(*bottom_, left + bl_width, bottom - b_height, | 379 canvas->TileImageInt(*images_->bottom, left + bl_width, bottom - b_height, |
357 width - bl_width - br_width, b_height); | 380 width - bl_width - br_width, b_height); |
358 } | 381 } |
359 | 382 |
360 // Bottom left corner. | 383 // Bottom left corner. |
361 canvas->DrawBitmapInt(*bottom_left_, left, bottom - bl_height); | 384 canvas->DrawBitmapInt(*images_->bottom_left, left, bottom - bl_height); |
362 } | 385 } |
363 | 386 |
364 void BubbleBorder::DrawEdgeWithArrow(gfx::Canvas* canvas, | 387 void BubbleBorder::DrawEdgeWithArrow(gfx::Canvas* canvas, |
365 bool is_horizontal, | 388 bool is_horizontal, |
366 SkBitmap* edge, | 389 SkBitmap* edge, |
367 SkBitmap* arrow, | 390 SkBitmap* arrow, |
368 int start_x, | 391 int start_x, |
369 int start_y, | 392 int start_y, |
370 int before_arrow, | 393 int before_arrow, |
371 int after_arrow, | 394 int after_arrow, |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
449 gfx::Rect bounds(view->GetContentsBounds()); | 472 gfx::Rect bounds(view->GetContentsBounds()); |
450 SkRect rect; | 473 SkRect rect; |
451 rect.set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y()), | 474 rect.set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y()), |
452 SkIntToScalar(bounds.right()), SkIntToScalar(bounds.bottom())); | 475 SkIntToScalar(bounds.right()), SkIntToScalar(bounds.bottom())); |
453 SkScalar radius = SkIntToScalar(BubbleBorder::GetCornerRadius()); | 476 SkScalar radius = SkIntToScalar(BubbleBorder::GetCornerRadius()); |
454 path.addRoundRect(rect, radius, radius); | 477 path.addRoundRect(rect, radius, radius); |
455 canvas->GetSkCanvas()->drawPath(path, paint); | 478 canvas->GetSkCanvas()->drawPath(path, paint); |
456 } | 479 } |
457 | 480 |
458 } // namespace views | 481 } // namespace views |
OLD | NEW |