| 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 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 351 Painter::PaintPainterAt(canvas, images_->border_painter.get(), bounds); | 351 Painter::PaintPainterAt(canvas, images_->border_painter.get(), bounds); |
| 352 return; | 352 return; |
| 353 } | 353 } |
| 354 if (!images_->border_painter) { | 354 if (!images_->border_painter) { |
| 355 DrawArrow(canvas, arrow_bounds); | 355 DrawArrow(canvas, arrow_bounds); |
| 356 return; | 356 return; |
| 357 } | 357 } |
| 358 | 358 |
| 359 // Clip the arrow bounds out to avoid painting the overlapping edge area. | 359 // Clip the arrow bounds out to avoid painting the overlapping edge area. |
| 360 canvas->Save(); | 360 canvas->Save(); |
| 361 canvas->ClipRect(arrow_bounds, kDifference_SkClipOp); | 361 canvas->ClipRect(arrow_bounds, SkClipOp::kDifference); |
| 362 Painter::PaintPainterAt(canvas, images_->border_painter.get(), bounds); | 362 Painter::PaintPainterAt(canvas, images_->border_painter.get(), bounds); |
| 363 canvas->Restore(); | 363 canvas->Restore(); |
| 364 | 364 |
| 365 DrawArrow(canvas, arrow_bounds); | 365 DrawArrow(canvas, arrow_bounds); |
| 366 } | 366 } |
| 367 | 367 |
| 368 gfx::Insets BubbleBorder::GetInsets() const { | 368 gfx::Insets BubbleBorder::GetInsets() const { |
| 369 if (UseMd()) { | 369 if (UseMd()) { |
| 370 if (shadow_ == NO_ASSETS) | 370 if (shadow_ == NO_ASSETS) |
| 371 return gfx::Insets(); | 371 return gfx::Insets(); |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 // must be doubled. | 531 // must be doubled. |
| 532 shadows.emplace_back(gfx::Vector2d(0, kSmallShadowVerticalOffset), | 532 shadows.emplace_back(gfx::Vector2d(0, kSmallShadowVerticalOffset), |
| 533 2 * kSmallShadowBlur, kSmallShadowColor); | 533 2 * kSmallShadowBlur, kSmallShadowColor); |
| 534 shadows.emplace_back(gfx::Vector2d(0, kLargeShadowVerticalOffset), | 534 shadows.emplace_back(gfx::Vector2d(0, kLargeShadowVerticalOffset), |
| 535 2 * kLargeShadowBlur, kLargeShadowColor); | 535 2 * kLargeShadowBlur, kLargeShadowColor); |
| 536 paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows)); | 536 paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows)); |
| 537 paint.setColor(SkColorSetA(SK_ColorBLACK, 0x26)); | 537 paint.setColor(SkColorSetA(SK_ColorBLACK, 0x26)); |
| 538 paint.setAntiAlias(true); | 538 paint.setAntiAlias(true); |
| 539 | 539 |
| 540 SkRRect r_rect = GetClientRect(view); | 540 SkRRect r_rect = GetClientRect(view); |
| 541 canvas->sk_canvas()->clipRRect(r_rect, kDifference_SkClipOp, | 541 canvas->sk_canvas()->clipRRect(r_rect, SkClipOp::kDifference, |
| 542 true /*doAntiAlias*/); | 542 true /*doAntiAlias*/); |
| 543 | 543 |
| 544 // The border is drawn outside the content area. | 544 // The border is drawn outside the content area. |
| 545 const SkScalar one_pixel = | 545 const SkScalar one_pixel = |
| 546 SkFloatToScalar(kBorderStrokeThicknessPx / canvas->image_scale()); | 546 SkFloatToScalar(kBorderStrokeThicknessPx / canvas->image_scale()); |
| 547 r_rect.inset(-one_pixel, -one_pixel); | 547 r_rect.inset(-one_pixel, -one_pixel); |
| 548 canvas->sk_canvas()->drawRRect(r_rect, paint); | 548 canvas->sk_canvas()->drawRRect(r_rect, paint); |
| 549 } | 549 } |
| 550 | 550 |
| 551 void BubbleBorder::PaintNoAssets(const View& view, gfx::Canvas* canvas) { | 551 void BubbleBorder::PaintNoAssets(const View& view, gfx::Canvas* canvas) { |
| 552 gfx::ScopedCanvas scoped(canvas); | 552 gfx::ScopedCanvas scoped(canvas); |
| 553 canvas->sk_canvas()->clipRRect(GetClientRect(view), kDifference_SkClipOp, | 553 canvas->sk_canvas()->clipRRect(GetClientRect(view), SkClipOp::kDifference, |
| 554 true /*doAntiAlias*/); | 554 true /*doAntiAlias*/); |
| 555 canvas->sk_canvas()->drawColor(SK_ColorTRANSPARENT, SkBlendMode::kSrc); | 555 canvas->sk_canvas()->drawColor(SK_ColorTRANSPARENT, SkBlendMode::kSrc); |
| 556 } | 556 } |
| 557 | 557 |
| 558 internal::BorderImages* BubbleBorder::GetImagesForTest() const { | 558 internal::BorderImages* BubbleBorder::GetImagesForTest() const { |
| 559 return images_; | 559 return images_; |
| 560 } | 560 } |
| 561 | 561 |
| 562 void BubbleBackground::Paint(gfx::Canvas* canvas, views::View* view) const { | 562 void BubbleBackground::Paint(gfx::Canvas* canvas, views::View* view) const { |
| 563 if (border_->shadow() == BubbleBorder::NO_SHADOW_OPAQUE_BORDER) | 563 if (border_->shadow() == BubbleBorder::NO_SHADOW_OPAQUE_BORDER) |
| 564 canvas->DrawColor(border_->background_color()); | 564 canvas->DrawColor(border_->background_color()); |
| 565 | 565 |
| 566 // Fill the contents with a round-rect region to match the border images. | 566 // Fill the contents with a round-rect region to match the border images. |
| 567 SkPaint paint; | 567 SkPaint paint; |
| 568 paint.setAntiAlias(true); | 568 paint.setAntiAlias(true); |
| 569 paint.setStyle(SkPaint::kFill_Style); | 569 paint.setStyle(SkPaint::kFill_Style); |
| 570 paint.setColor(border_->background_color()); | 570 paint.setColor(border_->background_color()); |
| 571 SkPath path; | 571 SkPath path; |
| 572 gfx::RectF bounds(view->GetLocalBounds()); | 572 gfx::RectF bounds(view->GetLocalBounds()); |
| 573 bounds.Inset(gfx::InsetsF(border_->GetInsets())); | 573 bounds.Inset(gfx::InsetsF(border_->GetInsets())); |
| 574 | 574 |
| 575 canvas->DrawRoundRect(bounds, border_->GetBorderCornerRadius(), paint); | 575 canvas->DrawRoundRect(bounds, border_->GetBorderCornerRadius(), paint); |
| 576 } | 576 } |
| 577 | 577 |
| 578 } // namespace views | 578 } // namespace views |
| OLD | NEW |