| 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" |
| 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/skia_util.h" |
| 16 | 16 |
| 17 namespace views { | 17 namespace views { |
| 18 | 18 |
| 19 struct BubbleBorder::BorderImages { | 19 struct BubbleBorder::BorderImages { |
| 20 BorderImages() | 20 BorderImages() |
| 21 : left(NULL), | 21 : left(NULL), |
| 22 top_left(NULL), | 22 top_left(NULL), |
| 23 top(NULL), | 23 top(NULL), |
| 24 top_right(NULL), | 24 top_right(NULL), |
| 25 right(NULL), | 25 right(NULL), |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 * ┌──────── |tip_x| | 473 * ┌──────── |tip_x| |
| 474 * ┌─────┐ | 474 * ┌─────┐ |
| 475 * │ ▲ │ ──── |tip y| | 475 * │ ▲ │ ──── |tip y| |
| 476 * │∙∙∙∙∙│ ┐ | 476 * │∙∙∙∙∙│ ┐ |
| 477 * └─────┘ └─── |shift_x| (offset from tip to vertexes of isosceles triangle) | 477 * └─────┘ └─── |shift_x| (offset from tip to vertexes of isosceles triangle) |
| 478 * └────────── |shift_y| | 478 * └────────── |shift_y| |
| 479 */ | 479 */ |
| 480 SkPaint paint; | 480 SkPaint paint; |
| 481 paint.setStyle(SkPaint::kFill_Style); | 481 paint.setStyle(SkPaint::kFill_Style); |
| 482 paint.setColor(background_color_); | 482 paint.setColor(background_color_); |
| 483 gfx::Path path; | 483 SkPath path; |
| 484 path.incReserve(4); | 484 path.incReserve(4); |
| 485 path.moveTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); | 485 path.moveTo(SkIntToScalar(tip_x), SkIntToScalar(tip_y)); |
| 486 path.lineTo(SkIntToScalar(tip_x + shift_x), | 486 path.lineTo(SkIntToScalar(tip_x + shift_x), |
| 487 SkIntToScalar(tip_y + shift_y)); | 487 SkIntToScalar(tip_y + shift_y)); |
| 488 if (is_horizontal) | 488 if (is_horizontal) |
| 489 path.lineTo(SkIntToScalar(tip_x - shift_x), SkIntToScalar(tip_y + shift_y)); | 489 path.lineTo(SkIntToScalar(tip_x - shift_x), SkIntToScalar(tip_y + shift_y)); |
| 490 else | 490 else |
| 491 path.lineTo(SkIntToScalar(tip_x + shift_x), SkIntToScalar(tip_y - shift_y)); | 491 path.lineTo(SkIntToScalar(tip_x + shift_x), SkIntToScalar(tip_y - shift_y)); |
| 492 path.close(); | 492 path.close(); |
| 493 canvas->GetSkCanvas()->drawPath(path, paint); | 493 canvas->GetSkCanvas()->drawPath(path, paint); |
| 494 } | 494 } |
| 495 | 495 |
| 496 ///////////////////////// | 496 ///////////////////////// |
| 497 | 497 |
| 498 void BubbleBackground::Paint(gfx::Canvas* canvas, views::View* view) const { | 498 void BubbleBackground::Paint(gfx::Canvas* canvas, views::View* view) const { |
| 499 // Clip out the client bounds to prevent overlapping transparent widgets. | 499 // Clip out the client bounds to prevent overlapping transparent widgets. |
| 500 if (!border_->client_bounds().IsEmpty()) { | 500 if (!border_->client_bounds().IsEmpty()) { |
| 501 SkRect client_rect; | 501 SkRect client_rect(gfx::RectToSkRect(border_->client_bounds())); |
| 502 client_rect.set(SkIntToScalar(border_->client_bounds().x()), | |
| 503 SkIntToScalar(border_->client_bounds().y()), | |
| 504 SkIntToScalar(border_->client_bounds().right()), | |
| 505 SkIntToScalar(border_->client_bounds().bottom())); | |
| 506 canvas->GetSkCanvas()->clipRect(client_rect, SkRegion::kDifference_Op); | 502 canvas->GetSkCanvas()->clipRect(client_rect, SkRegion::kDifference_Op); |
| 507 } | 503 } |
| 508 | 504 |
| 509 // The border of this view creates an anti-aliased round-rect region for the | 505 // The border of this view creates an anti-aliased round-rect region for the |
| 510 // contents, which we need to fill with the background color. | 506 // contents, which we need to fill with the background color. |
| 511 // NOTE: This doesn't handle an arrow location of "NONE", which has square top | 507 // NOTE: This doesn't handle an arrow location of "NONE", which has square top |
| 512 // corners. | 508 // corners. |
| 513 SkPaint paint; | 509 SkPaint paint; |
| 514 paint.setAntiAlias(true); | 510 paint.setAntiAlias(true); |
| 515 paint.setStyle(SkPaint::kFill_Style); | 511 paint.setStyle(SkPaint::kFill_Style); |
| 516 paint.setColor(border_->background_color()); | 512 paint.setColor(border_->background_color()); |
| 517 gfx::Path path; | 513 SkPath path; |
| 518 gfx::Rect bounds(view->GetContentsBounds()); | 514 gfx::Rect bounds(view->GetContentsBounds()); |
| 519 SkRect rect; | 515 bounds.Inset(-border_->border_thickness(), -border_->border_thickness()); |
| 520 rect.set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y()), | |
| 521 SkIntToScalar(bounds.right()), SkIntToScalar(bounds.bottom())); | |
| 522 rect.inset(-border_->border_thickness(), -border_->border_thickness()); | |
| 523 SkScalar radius = SkIntToScalar(BubbleBorder::GetCornerRadius()); | 516 SkScalar radius = SkIntToScalar(BubbleBorder::GetCornerRadius()); |
| 524 path.addRoundRect(rect, radius, radius); | 517 path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius); |
| 525 canvas->GetSkCanvas()->drawPath(path, paint); | 518 canvas->GetSkCanvas()->drawPath(path, paint); |
| 526 } | 519 } |
| 527 | 520 |
| 528 } // namespace views | 521 } // namespace views |
| OLD | NEW |