OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/views/bubble_border.h" | 5 #include "chrome/browser/views/bubble_border.h" |
6 | 6 |
7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "gfx/canvas.h" | 9 #include "gfx/canvas.h" |
10 #include "gfx/path.h" | 10 #include "gfx/path.h" |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 case LEFT_TOP: | 66 case LEFT_TOP: |
67 case LEFT_BOTTOM: | 67 case LEFT_BOTTOM: |
68 x += w - kArrowOverlap; | 68 x += w - kArrowOverlap; |
69 break; | 69 break; |
70 | 70 |
71 case RIGHT_TOP: | 71 case RIGHT_TOP: |
72 case RIGHT_BOTTOM: | 72 case RIGHT_BOTTOM: |
73 x += kArrowOverlap - border_size.width(); | 73 x += kArrowOverlap - border_size.width(); |
74 break; | 74 break; |
75 | 75 |
| 76 case NONE: |
76 case FLOAT: | 77 case FLOAT: |
77 case NONE: | |
78 x += w / 2 - border_size.width() / 2; | 78 x += w / 2 - border_size.width() / 2; |
79 break; | 79 break; |
80 } | 80 } |
81 | 81 |
82 // Calculate bubble y coordinate. | 82 // Calculate bubble y coordinate. |
83 switch (arrow_location_) { | 83 switch (arrow_location_) { |
84 case TOP_LEFT: | 84 case TOP_LEFT: |
85 case TOP_RIGHT: | 85 case TOP_RIGHT: |
86 y += h - kArrowOverlap; | 86 y += h - kArrowOverlap; |
87 break; | 87 break; |
88 | 88 |
89 case BOTTOM_LEFT: | 89 case BOTTOM_LEFT: |
90 case BOTTOM_RIGHT: | 90 case BOTTOM_RIGHT: |
91 y += kArrowOverlap - border_size.height(); | 91 y += kArrowOverlap - border_size.height(); |
92 break; | 92 break; |
93 | 93 |
94 case LEFT_TOP: | 94 case LEFT_TOP: |
95 case RIGHT_TOP: | 95 case RIGHT_TOP: |
96 y += h / 2 - arrow_offset; | 96 y += h / 2 - arrow_offset; |
97 break; | 97 break; |
98 | 98 |
99 case LEFT_BOTTOM: | 99 case LEFT_BOTTOM: |
100 case RIGHT_BOTTOM: | 100 case RIGHT_BOTTOM: |
101 y += h / 2 + arrow_offset - border_size.height(); | 101 y += h / 2 + arrow_offset - border_size.height(); |
102 break; | 102 break; |
103 | 103 |
| 104 case NONE: |
| 105 y += h; |
| 106 break; |
| 107 |
104 case FLOAT: | 108 case FLOAT: |
105 y += h / 2 - border_size.height() / 2; | 109 y += h / 2 - border_size.height() / 2; |
106 break; | 110 break; |
107 | |
108 case NONE: | |
109 y += h; | |
110 break; | |
111 } | 111 } |
112 | 112 |
113 return gfx::Rect(x, y, border_size.width(), border_size.height()); | 113 return gfx::Rect(x, y, border_size.width(), border_size.height()); |
114 } | 114 } |
115 | 115 |
116 void BubbleBorder::GetInsets(gfx::Insets* insets) const { | 116 void BubbleBorder::GetInsets(gfx::Insets* insets) const { |
117 int top = top_->height(); | 117 int top = top_->height(); |
118 int bottom = bottom_->height(); | 118 int bottom = bottom_->height(); |
119 int left = left_->width(); | 119 int left = left_->width(); |
120 int right = right_->width(); | 120 int right = right_->width(); |
(...skipping 12 matching lines...) Expand all Loading... |
133 case LEFT_BOTTOM: | 133 case LEFT_BOTTOM: |
134 left = std::max(left, left_arrow_->width()); | 134 left = std::max(left, left_arrow_->width()); |
135 break; | 135 break; |
136 | 136 |
137 case RIGHT_TOP: | 137 case RIGHT_TOP: |
138 case RIGHT_BOTTOM: | 138 case RIGHT_BOTTOM: |
139 right = std::max(right, right_arrow_->width()); | 139 right = std::max(right, right_arrow_->width()); |
140 break; | 140 break; |
141 | 141 |
142 case NONE: | 142 case NONE: |
143 top = 0; | |
144 break; | |
145 | |
146 case FLOAT: | 143 case FLOAT: |
147 // Nothing to do. | 144 // Nothing to do. |
148 break; | 145 break; |
149 } | 146 } |
150 insets->Set(top, left, bottom, right); | 147 insets->Set(top, left, bottom, right); |
151 } | 148 } |
152 | 149 |
153 int BubbleBorder::SetArrowOffset(int offset, const gfx::Size& contents_size) { | 150 int BubbleBorder::SetArrowOffset(int offset, const gfx::Size& contents_size) { |
154 gfx::Size border_size(contents_size); | 151 gfx::Size border_size(contents_size); |
155 gfx::Insets insets; | 152 gfx::Insets insets; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 std::max(std::max(top_left_->height(), top_right_->height()), | 190 std::max(std::max(top_left_->height(), top_right_->height()), |
194 std::max(bottom_left_->height(), bottom_right_->height())); | 191 std::max(bottom_left_->height(), bottom_right_->height())); |
195 arrow_offset_ = std::max(offset_x, offset_y); | 192 arrow_offset_ = std::max(offset_x, offset_y); |
196 | 193 |
197 initialized = true; | 194 initialized = true; |
198 } | 195 } |
199 } | 196 } |
200 | 197 |
201 void BubbleBorder::Paint(const views::View& view, gfx::Canvas* canvas) const { | 198 void BubbleBorder::Paint(const views::View& view, gfx::Canvas* canvas) const { |
202 // Convenience shorthand variables. | 199 // Convenience shorthand variables. |
203 // If |arrow_location_| == NONE, the entire top edge is omitted and height of | |
204 // corresponding bitmaps is set to 0. | |
205 const int tl_width = top_left_->width(); | 200 const int tl_width = top_left_->width(); |
206 const int tl_height = (arrow_location_ == NONE ? 0 : top_left_->height()); | 201 const int tl_height = top_left_->height(); |
207 const int t_height = (arrow_location_ == NONE ? 0 : top_->height()); | 202 const int t_height = top_->height(); |
208 const int tr_width = top_right_->width(); | 203 const int tr_width = top_right_->width(); |
209 const int tr_height = (arrow_location_ == NONE ? 0 : top_right_->height()); | 204 const int tr_height = top_right_->height(); |
210 const int l_width = left_->width(); | 205 const int l_width = left_->width(); |
211 const int r_width = right_->width(); | 206 const int r_width = right_->width(); |
212 const int br_width = bottom_right_->width(); | 207 const int br_width = bottom_right_->width(); |
213 const int br_height = bottom_right_->height(); | 208 const int br_height = bottom_right_->height(); |
214 const int b_height = bottom_->height(); | 209 const int b_height = bottom_->height(); |
215 const int bl_width = bottom_left_->width(); | 210 const int bl_width = bottom_left_->width(); |
216 const int bl_height = bottom_left_->height(); | 211 const int bl_height = bottom_left_->height(); |
217 | 212 |
218 gfx::Insets insets; | 213 gfx::Insets insets; |
219 GetInsets(&insets); | 214 GetInsets(&insets); |
(...skipping 13 matching lines...) Expand all Loading... |
233 arrow_offset = view.width() - arrow_offset - 1; | 228 arrow_offset = view.width() - arrow_offset - 1; |
234 } else if (!is_arrow_on_horizontal(arrow_location_) && | 229 } else if (!is_arrow_on_horizontal(arrow_location_) && |
235 !is_arrow_on_top(arrow_location_)) { | 230 !is_arrow_on_top(arrow_location_)) { |
236 arrow_offset = view.height() - arrow_offset - 1; | 231 arrow_offset = view.height() - arrow_offset - 1; |
237 } | 232 } |
238 | 233 |
239 // Left edge. | 234 // Left edge. |
240 if (arrow_location_ == LEFT_TOP || arrow_location_ == LEFT_BOTTOM) { | 235 if (arrow_location_ == LEFT_TOP || arrow_location_ == LEFT_BOTTOM) { |
241 int start_y = top + tl_height; | 236 int start_y = top + tl_height; |
242 int before_arrow = arrow_offset - start_y - left_arrow_->height() / 2; | 237 int before_arrow = arrow_offset - start_y - left_arrow_->height() / 2; |
243 int after_arrow = height - tl_height - bl_height - | 238 int after_arrow = |
244 left_arrow_->height() - before_arrow; | 239 height - tl_height - bl_height - left_arrow_->height() - before_arrow; |
245 DrawArrowInterior(canvas, | 240 DrawArrowInterior(canvas, |
246 false, | 241 false, |
247 left_arrow_->width() - kArrowInteriorHeight, | 242 left_arrow_->width() - kArrowInteriorHeight, |
248 start_y + before_arrow + left_arrow_->height() / 2, | 243 start_y + before_arrow + left_arrow_->height() / 2, |
249 kArrowInteriorHeight, | 244 kArrowInteriorHeight, |
250 left_arrow_->height() / 2 - 1); | 245 left_arrow_->height() / 2 - 1); |
251 DrawEdgeWithArrow(canvas, | 246 DrawEdgeWithArrow(canvas, |
252 false, | 247 false, |
253 left_, | 248 left_, |
254 left_arrow_, | 249 left_arrow_, |
255 left, | 250 left, |
256 start_y, | 251 start_y, |
257 before_arrow, | 252 before_arrow, |
258 after_arrow, | 253 after_arrow, |
259 left_->width() - left_arrow_->width()); | 254 left_->width() - left_arrow_->width()); |
260 } else { | 255 } else { |
261 canvas->TileImageInt(*left_, left, top + tl_height, l_width, | 256 canvas->TileImageInt(*left_, left, top + tl_height, l_width, |
262 height - tl_height - bl_height); | 257 height - tl_height - bl_height); |
263 } | 258 } |
264 | 259 |
265 if (arrow_location_ != NONE) { | 260 // Top left corner. |
266 // Top left corner. | 261 canvas->DrawBitmapInt(*top_left_, left, top); |
267 canvas->DrawBitmapInt(*top_left_, left, top); | |
268 | 262 |
269 // Top edge. | 263 // Top edge. |
270 if (arrow_location_ == TOP_LEFT || arrow_location_ == TOP_RIGHT) { | 264 if (arrow_location_ == TOP_LEFT || arrow_location_ == TOP_RIGHT) { |
271 int start_x = left + tl_width; | 265 int start_x = left + tl_width; |
272 int before_arrow = arrow_offset - start_x - top_arrow_->width() / 2; | 266 int before_arrow = arrow_offset - start_x - top_arrow_->width() / 2; |
273 int after_arrow = width - tl_width - tr_width - | 267 int after_arrow = |
274 top_arrow_->width() - before_arrow; | 268 width - tl_width - tr_width - top_arrow_->width() - before_arrow; |
275 DrawArrowInterior(canvas, | 269 DrawArrowInterior(canvas, |
276 true, | 270 true, |
277 start_x + before_arrow + top_arrow_->width() / 2, | 271 start_x + before_arrow + top_arrow_->width() / 2, |
278 top_arrow_->height() - kArrowInteriorHeight, | 272 top_arrow_->height() - kArrowInteriorHeight, |
279 1 - top_arrow_->width() / 2, | 273 1 - top_arrow_->width() / 2, |
280 kArrowInteriorHeight); | 274 kArrowInteriorHeight); |
281 DrawEdgeWithArrow(canvas, | 275 DrawEdgeWithArrow(canvas, |
282 true, | 276 true, |
283 top_, | 277 top_, |
284 top_arrow_, | 278 top_arrow_, |
285 start_x, | 279 start_x, |
286 top, | 280 top, |
287 before_arrow, | 281 before_arrow, |
288 after_arrow, | 282 after_arrow, |
289 top_->height() - top_arrow_->height()); | 283 top_->height() - top_arrow_->height()); |
290 } else { | 284 } else { |
291 canvas->TileImageInt(*top_, left + tl_width, top, | 285 canvas->TileImageInt(*top_, left + tl_width, top, |
292 width - tl_width - tr_width, t_height); | 286 width - tl_width - tr_width, t_height); |
293 } | 287 } |
294 | 288 |
295 // Top right corner. | 289 // Top right corner. |
296 canvas->DrawBitmapInt(*top_right_, right - tr_width, top); | 290 canvas->DrawBitmapInt(*top_right_, right - tr_width, top); |
297 } | |
298 | 291 |
299 // Right edge. | 292 // Right edge. |
300 if (arrow_location_ == RIGHT_TOP || arrow_location_ == RIGHT_BOTTOM) { | 293 if (arrow_location_ == RIGHT_TOP || arrow_location_ == RIGHT_BOTTOM) { |
301 int start_y = top + tr_height; | 294 int start_y = top + tr_height; |
302 int before_arrow = arrow_offset - start_y - right_arrow_->height() / 2; | 295 int before_arrow = arrow_offset - start_y - right_arrow_->height() / 2; |
303 int after_arrow = height - tl_height - bl_height - | 296 int after_arrow = height - tl_height - bl_height - |
304 right_arrow_->height() - before_arrow; | 297 right_arrow_->height() - before_arrow; |
305 DrawArrowInterior(canvas, | 298 DrawArrowInterior(canvas, |
306 false, | 299 false, |
307 right - r_width + kArrowInteriorHeight, | 300 right - r_width + kArrowInteriorHeight, |
(...skipping 14 matching lines...) Expand all Loading... |
322 height - tr_height - br_height); | 315 height - tr_height - br_height); |
323 } | 316 } |
324 | 317 |
325 // Bottom right corner. | 318 // Bottom right corner. |
326 canvas->DrawBitmapInt(*bottom_right_, right - br_width, bottom - br_height); | 319 canvas->DrawBitmapInt(*bottom_right_, right - br_width, bottom - br_height); |
327 | 320 |
328 // Bottom edge. | 321 // Bottom edge. |
329 if (arrow_location_ == BOTTOM_LEFT || arrow_location_ == BOTTOM_RIGHT) { | 322 if (arrow_location_ == BOTTOM_LEFT || arrow_location_ == BOTTOM_RIGHT) { |
330 int start_x = left + bl_width; | 323 int start_x = left + bl_width; |
331 int before_arrow = arrow_offset - start_x - bottom_arrow_->width() / 2; | 324 int before_arrow = arrow_offset - start_x - bottom_arrow_->width() / 2; |
332 int after_arrow = width - bl_width - br_width - | 325 int after_arrow = |
333 bottom_arrow_->width() - before_arrow; | 326 width - bl_width - br_width - bottom_arrow_->width() - before_arrow; |
334 DrawArrowInterior(canvas, | 327 DrawArrowInterior(canvas, |
335 true, | 328 true, |
336 start_x + before_arrow + bottom_arrow_->width() / 2, | 329 start_x + before_arrow + bottom_arrow_->width() / 2, |
337 bottom - b_height + kArrowInteriorHeight, | 330 bottom - b_height + kArrowInteriorHeight, |
338 1 - bottom_arrow_->width() / 2, | 331 1 - bottom_arrow_->width() / 2, |
339 -kArrowInteriorHeight); | 332 -kArrowInteriorHeight); |
340 DrawEdgeWithArrow(canvas, | 333 DrawEdgeWithArrow(canvas, |
341 true, | 334 true, |
342 bottom_, | 335 bottom_, |
343 bottom_arrow_, | 336 bottom_arrow_, |
(...skipping 17 matching lines...) Expand all Loading... |
361 SkBitmap* arrow, | 354 SkBitmap* arrow, |
362 int start_x, | 355 int start_x, |
363 int start_y, | 356 int start_y, |
364 int before_arrow, | 357 int before_arrow, |
365 int after_arrow, | 358 int after_arrow, |
366 int offset) const { | 359 int offset) const { |
367 /* Here's what the parameters mean: | 360 /* Here's what the parameters mean: |
368 * start_x | 361 * start_x |
369 * . | 362 * . |
370 * . ┌───┐ ┬ offset | 363 * . ┌───┐ ┬ offset |
371 * start_y..........┌────┬────────┤ ▲ ├────────┬────┐ ┴ | 364 * start_y..........┌────┬────────┤ ▲ ├────────┬────┐ |
372 * │ / │--------│∙ ∙│--------│ \ │ | 365 * │ / │--------│∙ ∙│--------│ \ │ |
373 * │ / ├────────┴───┴────────┤ \ │ | 366 * │ / ├────────┴───┴────────┤ \ │ |
374 * ├───┬┘ └┬───┤ | 367 * ├───┬┘ └┬───┤ |
375 * └───┬────┘ └───┬────┘ | 368 * └───┬────┘ └───┬────┘ |
376 * before_arrow ─┘ └─ after_arrow | 369 * before_arrow ─┘ └─ after_arrow |
377 */ | 370 */ |
378 if (before_arrow) { | 371 if (before_arrow) { |
379 canvas->TileImageInt(*edge, start_x, start_y, | 372 canvas->TileImageInt(*edge, start_x, start_y, |
380 is_horizontal ? before_arrow : edge->width(), | 373 is_horizontal ? before_arrow : edge->width(), |
381 is_horizontal ? edge->height() : before_arrow); | 374 is_horizontal ? edge->height() : before_arrow); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 paint.setColor(border_->background_color()); | 434 paint.setColor(border_->background_color()); |
442 gfx::Path path; | 435 gfx::Path path; |
443 gfx::Rect bounds(view->GetLocalBounds(false)); | 436 gfx::Rect bounds(view->GetLocalBounds(false)); |
444 SkRect rect; | 437 SkRect rect; |
445 rect.set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y()), | 438 rect.set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y()), |
446 SkIntToScalar(bounds.right()), SkIntToScalar(bounds.bottom())); | 439 SkIntToScalar(bounds.right()), SkIntToScalar(bounds.bottom())); |
447 SkScalar radius = SkIntToScalar(BubbleBorder::GetCornerRadius()); | 440 SkScalar radius = SkIntToScalar(BubbleBorder::GetCornerRadius()); |
448 path.addRoundRect(rect, radius, radius); | 441 path.addRoundRect(rect, radius, radius); |
449 canvas->drawPath(path, paint); | 442 canvas->drawPath(path, paint); |
450 } | 443 } |
OLD | NEW |