| 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> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "third_party/skia/include/core/SkDrawLooper.h" | 10 #include "third_party/skia/include/core/SkDrawLooper.h" |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 canvas->Save(); | 356 canvas->Save(); |
| 357 canvas->ClipRect(arrow_bounds, SkRegion::kDifference_Op); | 357 canvas->ClipRect(arrow_bounds, SkRegion::kDifference_Op); |
| 358 Painter::PaintPainterAt(canvas, images_->border_painter.get(), bounds); | 358 Painter::PaintPainterAt(canvas, images_->border_painter.get(), bounds); |
| 359 canvas->Restore(); | 359 canvas->Restore(); |
| 360 | 360 |
| 361 DrawArrow(canvas, arrow_bounds); | 361 DrawArrow(canvas, arrow_bounds); |
| 362 } | 362 } |
| 363 | 363 |
| 364 gfx::Insets BubbleBorder::GetInsets() const { | 364 gfx::Insets BubbleBorder::GetInsets() const { |
| 365 if (UseMd()) { | 365 if (UseMd()) { |
| 366 gfx::Insets blur(kLargeShadowBlur); | 366 if (shadow_ == NO_ASSETS) |
| 367 gfx::Insets offset(-kLargeShadowVerticalOffset, 0, | 367 return gfx::Insets(); |
| 368 kLargeShadowVerticalOffset, 0); | 368 |
| 369 gfx::Insets border(kBorderThicknessDip); | 369 gfx::Insets blur(kLargeShadowBlur); |
| 370 return blur + offset; | 370 gfx::Insets offset(-kLargeShadowVerticalOffset, 0, |
| 371 kLargeShadowVerticalOffset, 0); |
| 372 gfx::Insets border(kBorderThicknessDip); |
| 373 return blur + offset; |
| 371 } | 374 } |
| 372 | 375 |
| 373 // The insets contain the stroke and shadow pixels outside the bubble fill. | 376 // The insets contain the stroke and shadow pixels outside the bubble fill. |
| 374 const int inset = GetBorderThickness(); | 377 const int inset = GetBorderThickness(); |
| 375 if (arrow_paint_type_ != PAINT_NORMAL || !has_arrow(arrow_)) | 378 if (arrow_paint_type_ != PAINT_NORMAL || !has_arrow(arrow_)) |
| 376 return gfx::Insets(inset); | 379 return gfx::Insets(inset); |
| 377 | 380 |
| 378 int first_inset = inset; | 381 int first_inset = inset; |
| 379 int second_inset = std::max(inset, images_->arrow_thickness); | 382 int second_inset = std::max(inset, images_->arrow_thickness); |
| 380 if (is_arrow_on_horizontal(arrow_) ? | 383 if (is_arrow_on_horizontal(arrow_) ? |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 498 canvas->DrawImageInt(*GetArrowImage(), arrow_bounds.x(), arrow_bounds.y()); | 501 canvas->DrawImageInt(*GetArrowImage(), arrow_bounds.x(), arrow_bounds.y()); |
| 499 SkPath path; | 502 SkPath path; |
| 500 GetArrowPathFromArrowBounds(arrow_bounds, &path); | 503 GetArrowPathFromArrowBounds(arrow_bounds, &path); |
| 501 SkPaint paint; | 504 SkPaint paint; |
| 502 paint.setStyle(SkPaint::kFill_Style); | 505 paint.setStyle(SkPaint::kFill_Style); |
| 503 paint.setColor(background_color_); | 506 paint.setColor(background_color_); |
| 504 | 507 |
| 505 canvas->DrawPath(path, paint); | 508 canvas->DrawPath(path, paint); |
| 506 } | 509 } |
| 507 | 510 |
| 511 SkRRect BubbleBorder::GetClientRect(const View& view) const { |
| 512 gfx::RectF bounds(view.GetLocalBounds()); |
| 513 bounds.Inset(GetInsets()); |
| 514 return SkRRect::MakeRectXY(gfx::RectFToSkRect(bounds), |
| 515 GetBorderCornerRadius(), GetBorderCornerRadius()); |
| 516 } |
| 517 |
| 508 void BubbleBorder::PaintMd(const View& view, gfx::Canvas* canvas) { | 518 void BubbleBorder::PaintMd(const View& view, gfx::Canvas* canvas) { |
| 519 if (shadow_ == NO_ASSETS) |
| 520 return PaintNoAssets(view, canvas); |
| 521 |
| 509 gfx::ScopedCanvas scoped(canvas); | 522 gfx::ScopedCanvas scoped(canvas); |
| 510 | 523 |
| 511 SkPaint paint; | 524 SkPaint paint; |
| 512 std::vector<gfx::ShadowValue> shadows; | 525 std::vector<gfx::ShadowValue> shadows; |
| 513 // gfx::ShadowValue counts blur pixels both inside and outside the shape, | 526 // gfx::ShadowValue counts blur pixels both inside and outside the shape, |
| 514 // whereas these blur values only describe the outside portion, hence they | 527 // whereas these blur values only describe the outside portion, hence they |
| 515 // must be doubled. | 528 // must be doubled. |
| 516 shadows.emplace_back(gfx::Vector2d(0, kSmallShadowVerticalOffset), | 529 shadows.emplace_back(gfx::Vector2d(0, kSmallShadowVerticalOffset), |
| 517 2 * kSmallShadowBlur, kSmallShadowColor); | 530 2 * kSmallShadowBlur, kSmallShadowColor); |
| 518 shadows.emplace_back(gfx::Vector2d(0, kLargeShadowVerticalOffset), | 531 shadows.emplace_back(gfx::Vector2d(0, kLargeShadowVerticalOffset), |
| 519 2 * kLargeShadowBlur, kLargeShadowColor); | 532 2 * kLargeShadowBlur, kLargeShadowColor); |
| 520 paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows)); | 533 paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows)); |
| 521 paint.setColor(SkColorSetA(SK_ColorBLACK, 0x26)); | 534 paint.setColor(SkColorSetA(SK_ColorBLACK, 0x26)); |
| 522 paint.setAntiAlias(true); | 535 paint.setAntiAlias(true); |
| 523 | 536 |
| 524 gfx::RectF bounds(view.GetLocalBounds()); | 537 SkRRect r_rect = GetClientRect(view); |
| 525 bounds.Inset(GetInsets()); | 538 canvas->sk_canvas()->clipRRect(r_rect, SkRegion::kDifference_Op, |
| 526 // Clip out a round rect so the fill and shadow don't draw over the contents | |
| 527 // of the bubble. | |
| 528 SkRRect clip_r_rect = | |
| 529 SkRRect::MakeRectXY(gfx::RectFToSkRect(bounds), GetBorderCornerRadius(), | |
| 530 GetBorderCornerRadius()); | |
| 531 canvas->sk_canvas()->clipRRect(clip_r_rect, SkRegion::kDifference_Op, | |
| 532 true /*doAntiAlias*/); | 539 true /*doAntiAlias*/); |
| 533 | 540 |
| 534 // The border is drawn outside the content area. | 541 // The border is drawn outside the content area. |
| 535 SkRRect r_rect = clip_r_rect; | |
| 536 const SkScalar one_pixel = | 542 const SkScalar one_pixel = |
| 537 SkFloatToScalar(kBorderStrokeThicknessPx / canvas->image_scale()); | 543 SkFloatToScalar(kBorderStrokeThicknessPx / canvas->image_scale()); |
| 538 r_rect.inset(-one_pixel, -one_pixel); | 544 r_rect.inset(-one_pixel, -one_pixel); |
| 539 canvas->sk_canvas()->drawRRect(r_rect, paint); | 545 canvas->sk_canvas()->drawRRect(r_rect, paint); |
| 540 } | 546 } |
| 541 | 547 |
| 548 void BubbleBorder::PaintNoAssets(const View& view, gfx::Canvas* canvas) { |
| 549 gfx::ScopedCanvas scoped(canvas); |
| 550 canvas->sk_canvas()->clipRRect(GetClientRect(view), SkRegion::kDifference_Op, |
| 551 true /*doAntiAlias*/); |
| 552 canvas->sk_canvas()->drawColor(SK_ColorTRANSPARENT, SkBlendMode::kSrc); |
| 553 } |
| 554 |
| 542 internal::BorderImages* BubbleBorder::GetImagesForTest() const { | 555 internal::BorderImages* BubbleBorder::GetImagesForTest() const { |
| 543 return images_; | 556 return images_; |
| 544 } | 557 } |
| 545 | 558 |
| 546 void BubbleBackground::Paint(gfx::Canvas* canvas, views::View* view) const { | 559 void BubbleBackground::Paint(gfx::Canvas* canvas, views::View* view) const { |
| 547 if (border_->shadow() == BubbleBorder::NO_SHADOW_OPAQUE_BORDER) | 560 if (border_->shadow() == BubbleBorder::NO_SHADOW_OPAQUE_BORDER) |
| 548 canvas->DrawColor(border_->background_color()); | 561 canvas->DrawColor(border_->background_color()); |
| 549 | 562 |
| 550 // Fill the contents with a round-rect region to match the border images. | 563 // Fill the contents with a round-rect region to match the border images. |
| 551 SkPaint paint; | 564 SkPaint paint; |
| 552 paint.setAntiAlias(true); | 565 paint.setAntiAlias(true); |
| 553 paint.setStyle(SkPaint::kFill_Style); | 566 paint.setStyle(SkPaint::kFill_Style); |
| 554 paint.setColor(border_->background_color()); | 567 paint.setColor(border_->background_color()); |
| 555 SkPath path; | 568 SkPath path; |
| 556 gfx::RectF bounds(view->GetLocalBounds()); | 569 gfx::RectF bounds(view->GetLocalBounds()); |
| 557 bounds.Inset(gfx::InsetsF(border_->GetInsets())); | 570 bounds.Inset(gfx::InsetsF(border_->GetInsets())); |
| 558 | 571 |
| 559 canvas->DrawRoundRect(bounds, border_->GetBorderCornerRadius(), paint); | 572 canvas->DrawRoundRect(bounds, border_->GetBorderCornerRadius(), paint); |
| 560 } | 573 } |
| 561 | 574 |
| 562 } // namespace views | 575 } // namespace views |
| OLD | NEW |