| OLD | NEW |
| 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 #include "ui/views/bubble/bubble_border.h" | 5 #include "ui/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" |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 DrawEdgeWithArrow(canvas, | 312 DrawEdgeWithArrow(canvas, |
| 313 false, | 313 false, |
| 314 images_->left, | 314 images_->left, |
| 315 images_->left_arrow, | 315 images_->left_arrow, |
| 316 left, | 316 left, |
| 317 start_y, | 317 start_y, |
| 318 before_arrow, | 318 before_arrow, |
| 319 after_arrow, | 319 after_arrow, |
| 320 images_->left->width() - images_->left_arrow->width()); | 320 images_->left->width() - images_->left_arrow->width()); |
| 321 } else { | 321 } else { |
| 322 canvas->TileImageInt(*images_->left, left, top + tl_height, l_width, | 322 canvas->TileImage(*images_->left, gfx::Rect(left, top + tl_height, |
| 323 height - tl_height - bl_height); | 323 l_width, height - tl_height - bl_height)); |
| 324 } | 324 } |
| 325 | 325 |
| 326 // Top left corner. | 326 // Top left corner. |
| 327 canvas->DrawBitmapInt(*images_->top_left, left, top); | 327 canvas->DrawBitmapInt(*images_->top_left, left, top); |
| 328 | 328 |
| 329 // Top edge. | 329 // Top edge. |
| 330 if (arrow_location_ == TOP_LEFT || arrow_location_ == TOP_RIGHT) { | 330 if (arrow_location_ == TOP_LEFT || arrow_location_ == TOP_RIGHT) { |
| 331 int start_x = left + tl_width; | 331 int start_x = left + tl_width; |
| 332 int before_arrow = arrow_offset - start_x - images_->top_arrow->width() / 2; | 332 int before_arrow = arrow_offset - start_x - images_->top_arrow->width() / 2; |
| 333 int after_arrow = width - tl_width - tr_width - | 333 int after_arrow = width - tl_width - tr_width - |
| 334 images_->top_arrow->width() - before_arrow; | 334 images_->top_arrow->width() - before_arrow; |
| 335 DrawArrowInterior(canvas, | 335 DrawArrowInterior(canvas, |
| 336 true, | 336 true, |
| 337 start_x + before_arrow + images_->top_arrow->width() / 2, | 337 start_x + before_arrow + images_->top_arrow->width() / 2, |
| 338 images_->top_arrow->height() - kArrowInteriorHeight, | 338 images_->top_arrow->height() - kArrowInteriorHeight, |
| 339 1 - images_->top_arrow->width() / 2, | 339 1 - images_->top_arrow->width() / 2, |
| 340 kArrowInteriorHeight); | 340 kArrowInteriorHeight); |
| 341 DrawEdgeWithArrow(canvas, | 341 DrawEdgeWithArrow(canvas, |
| 342 true, | 342 true, |
| 343 images_->top, | 343 images_->top, |
| 344 images_->top_arrow, | 344 images_->top_arrow, |
| 345 start_x, | 345 start_x, |
| 346 top, | 346 top, |
| 347 before_arrow, | 347 before_arrow, |
| 348 after_arrow, | 348 after_arrow, |
| 349 images_->top->height() - images_->top_arrow->height()); | 349 images_->top->height() - images_->top_arrow->height()); |
| 350 } else { | 350 } else { |
| 351 canvas->TileImageInt(*images_->top, left + tl_width, top, | 351 canvas->TileImage(*images_->top, gfx::Rect(left + tl_width, top, |
| 352 width - tl_width - tr_width, t_height); | 352 width - tl_width - tr_width, t_height)); |
| 353 } | 353 } |
| 354 | 354 |
| 355 // Top right corner. | 355 // Top right corner. |
| 356 canvas->DrawBitmapInt(*images_->top_right, right - tr_width, top); | 356 canvas->DrawBitmapInt(*images_->top_right, right - tr_width, top); |
| 357 | 357 |
| 358 // Right edge. | 358 // Right edge. |
| 359 if (arrow_location_ == RIGHT_TOP || arrow_location_ == RIGHT_BOTTOM) { | 359 if (arrow_location_ == RIGHT_TOP || arrow_location_ == RIGHT_BOTTOM) { |
| 360 int start_y = top + tr_height; | 360 int start_y = top + tr_height; |
| 361 int before_arrow = | 361 int before_arrow = |
| 362 arrow_offset - start_y - images_->right_arrow->height() / 2; | 362 arrow_offset - start_y - images_->right_arrow->height() / 2; |
| 363 int after_arrow = height - tl_height - bl_height - | 363 int after_arrow = height - tl_height - bl_height - |
| 364 images_->right_arrow->height() - before_arrow; | 364 images_->right_arrow->height() - before_arrow; |
| 365 int tip_y = start_y + before_arrow + images_->right_arrow->height() / 2; | 365 int tip_y = start_y + before_arrow + images_->right_arrow->height() / 2; |
| 366 DrawArrowInterior(canvas, | 366 DrawArrowInterior(canvas, |
| 367 false, | 367 false, |
| 368 right - r_width + kArrowInteriorHeight, | 368 right - r_width + kArrowInteriorHeight, |
| 369 tip_y, | 369 tip_y, |
| 370 -kArrowInteriorHeight, | 370 -kArrowInteriorHeight, |
| 371 images_->right_arrow->height() / 2 - 1); | 371 images_->right_arrow->height() / 2 - 1); |
| 372 DrawEdgeWithArrow(canvas, | 372 DrawEdgeWithArrow(canvas, |
| 373 false, | 373 false, |
| 374 images_->right, | 374 images_->right, |
| 375 images_->right_arrow, | 375 images_->right_arrow, |
| 376 right - r_width, | 376 right - r_width, |
| 377 start_y, | 377 start_y, |
| 378 before_arrow, | 378 before_arrow, |
| 379 after_arrow, | 379 after_arrow, |
| 380 0); | 380 0); |
| 381 } else { | 381 } else { |
| 382 canvas->TileImageInt(*images_->right, right - r_width, top + tr_height, | 382 canvas->TileImage(*images_->right, gfx::Rect(right - r_width, |
| 383 r_width, height - tr_height - br_height); | 383 top + tr_height, r_width, height - tr_height - br_height)); |
| 384 } | 384 } |
| 385 | 385 |
| 386 // Bottom right corner. | 386 // Bottom right corner. |
| 387 canvas->DrawBitmapInt(*images_->bottom_right, | 387 canvas->DrawBitmapInt(*images_->bottom_right, |
| 388 right - br_width, | 388 right - br_width, |
| 389 bottom - br_height); | 389 bottom - br_height); |
| 390 | 390 |
| 391 // Bottom edge. | 391 // Bottom edge. |
| 392 if (arrow_location_ == BOTTOM_LEFT || arrow_location_ == BOTTOM_RIGHT) { | 392 if (arrow_location_ == BOTTOM_LEFT || arrow_location_ == BOTTOM_RIGHT) { |
| 393 int start_x = left + bl_width; | 393 int start_x = left + bl_width; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 405 DrawEdgeWithArrow(canvas, | 405 DrawEdgeWithArrow(canvas, |
| 406 true, | 406 true, |
| 407 images_->bottom, | 407 images_->bottom, |
| 408 images_->bottom_arrow, | 408 images_->bottom_arrow, |
| 409 start_x, | 409 start_x, |
| 410 bottom - b_height, | 410 bottom - b_height, |
| 411 before_arrow, | 411 before_arrow, |
| 412 after_arrow, | 412 after_arrow, |
| 413 0); | 413 0); |
| 414 } else { | 414 } else { |
| 415 canvas->TileImageInt(*images_->bottom, left + bl_width, bottom - b_height, | 415 canvas->TileImage(*images_->bottom, gfx::Rect(left + bl_width, |
| 416 width - bl_width - br_width, b_height); | 416 bottom - b_height, width - bl_width - br_width, b_height)); |
| 417 } | 417 } |
| 418 | 418 |
| 419 // Bottom left corner. | 419 // Bottom left corner. |
| 420 canvas->DrawBitmapInt(*images_->bottom_left, left, bottom - bl_height); | 420 canvas->DrawBitmapInt(*images_->bottom_left, left, bottom - bl_height); |
| 421 } | 421 } |
| 422 | 422 |
| 423 void BubbleBorder::DrawEdgeWithArrow(gfx::Canvas* canvas, | 423 void BubbleBorder::DrawEdgeWithArrow(gfx::Canvas* canvas, |
| 424 bool is_horizontal, | 424 bool is_horizontal, |
| 425 SkBitmap* edge, | 425 SkBitmap* edge, |
| 426 SkBitmap* arrow, | 426 SkBitmap* arrow, |
| 427 int start_x, | 427 int start_x, |
| 428 int start_y, | 428 int start_y, |
| 429 int before_arrow, | 429 int before_arrow, |
| 430 int after_arrow, | 430 int after_arrow, |
| 431 int offset) const { | 431 int offset) const { |
| 432 /* Here's what the parameters mean: | 432 /* Here's what the parameters mean: |
| 433 * start_x | 433 * start_x |
| 434 * . | 434 * . |
| 435 * . ┌───┐ ┬ offset | 435 * . ┌───┐ ┬ offset |
| 436 * start_y..........┌────┬────────┤ ▲ ├────────┬────┐ | 436 * start_y..........┌────┬────────┤ ▲ ├────────┬────┐ |
| 437 * │ / │--------│∙ ∙│--------│ \ │ | 437 * │ / │--------│∙ ∙│--------│ \ │ |
| 438 * │ / ├────────┴───┴────────┤ \ │ | 438 * │ / ├────────┴───┴────────┤ \ │ |
| 439 * ├───┬┘ └┬───┤ | 439 * ├───┬┘ └┬───┤ |
| 440 * └───┬────┘ └───┬────┘ | 440 * └───┬────┘ └───┬────┘ |
| 441 * before_arrow ─┘ └─ after_arrow | 441 * before_arrow ─┘ └─ after_arrow |
| 442 */ | 442 */ |
| 443 if (before_arrow) { | 443 if (before_arrow) { |
| 444 canvas->TileImageInt(*edge, start_x, start_y, | 444 canvas->TileImage(*edge, gfx::Rect(start_x, start_y, |
| 445 is_horizontal ? before_arrow : edge->width(), | 445 is_horizontal ? before_arrow : edge->width(), |
| 446 is_horizontal ? edge->height() : before_arrow); | 446 is_horizontal ? edge->height() : before_arrow)); |
| 447 } | 447 } |
| 448 | 448 |
| 449 canvas->DrawBitmapInt(*arrow, | 449 canvas->DrawBitmapInt(*arrow, |
| 450 start_x + (is_horizontal ? before_arrow : offset), | 450 start_x + (is_horizontal ? before_arrow : offset), |
| 451 start_y + (is_horizontal ? offset : before_arrow)); | 451 start_y + (is_horizontal ? offset : before_arrow)); |
| 452 | 452 |
| 453 if (after_arrow) { | 453 if (after_arrow) { |
| 454 start_x += (is_horizontal ? before_arrow + arrow->width() : 0); | 454 start_x += (is_horizontal ? before_arrow + arrow->width() : 0); |
| 455 start_y += (is_horizontal ? 0 : before_arrow + arrow->height()); | 455 start_y += (is_horizontal ? 0 : before_arrow + arrow->height()); |
| 456 canvas->TileImageInt(*edge, start_x, start_y, | 456 canvas->TileImage(*edge, gfx::Rect(start_x, start_y, |
| 457 is_horizontal ? after_arrow : edge->width(), | 457 is_horizontal ? after_arrow : edge->width(), |
| 458 is_horizontal ? edge->height() : after_arrow); | 458 is_horizontal ? edge->height() : after_arrow)); |
| 459 } | 459 } |
| 460 } | 460 } |
| 461 | 461 |
| 462 void BubbleBorder::DrawArrowInterior(gfx::Canvas* canvas, | 462 void BubbleBorder::DrawArrowInterior(gfx::Canvas* canvas, |
| 463 bool is_horizontal, | 463 bool is_horizontal, |
| 464 int tip_x, | 464 int tip_x, |
| 465 int tip_y, | 465 int tip_y, |
| 466 int shift_x, | 466 int shift_x, |
| 467 int shift_y) const { | 467 int shift_y) const { |
| 468 /* This function fills the interior of the arrow with background color. | 468 /* This function fills the interior of the arrow with background color. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 519 SkRect rect; | 519 SkRect rect; |
| 520 rect.set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y()), | 520 rect.set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y()), |
| 521 SkIntToScalar(bounds.right()), SkIntToScalar(bounds.bottom())); | 521 SkIntToScalar(bounds.right()), SkIntToScalar(bounds.bottom())); |
| 522 rect.inset(-border_->border_thickness(), -border_->border_thickness()); | 522 rect.inset(-border_->border_thickness(), -border_->border_thickness()); |
| 523 SkScalar radius = SkIntToScalar(BubbleBorder::GetCornerRadius()); | 523 SkScalar radius = SkIntToScalar(BubbleBorder::GetCornerRadius()); |
| 524 path.addRoundRect(rect, radius, radius); | 524 path.addRoundRect(rect, radius, radius); |
| 525 canvas->GetSkCanvas()->drawPath(path, paint); | 525 canvas->GetSkCanvas()->drawPath(path, paint); |
| 526 } | 526 } |
| 527 | 527 |
| 528 } // namespace views | 528 } // namespace views |
| OLD | NEW |