| 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 "skia/ext/cdl_paint.h" |
| 10 #include "third_party/skia/include/core/SkDrawLooper.h" | 11 #include "third_party/skia/include/core/SkDrawLooper.h" |
| 11 #include "third_party/skia/include/core/SkPaint.h" | 12 #include "third_party/skia/include/core/SkPaint.h" |
| 12 #include "third_party/skia/include/core/SkPath.h" | 13 #include "third_party/skia/include/core/SkPath.h" |
| 13 #include "ui/base/material_design/material_design_controller.h" | 14 #include "ui/base/material_design/material_design_controller.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
| 16 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
| 17 #include "ui/gfx/path.h" | 18 #include "ui/gfx/path.h" |
| 18 #include "ui/gfx/scoped_canvas.h" | 19 #include "ui/gfx/scoped_canvas.h" |
| 19 #include "ui/gfx/skia_util.h" | 20 #include "ui/gfx/skia_util.h" |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 497 SkDoubleToScalar(tip_y + multiplier * offset_to_next_vertex)); | 498 SkDoubleToScalar(tip_y + multiplier * offset_to_next_vertex)); |
| 498 path->close(); | 499 path->close(); |
| 499 } | 500 } |
| 500 | 501 |
| 501 void BubbleBorder::DrawArrow(gfx::Canvas* canvas, | 502 void BubbleBorder::DrawArrow(gfx::Canvas* canvas, |
| 502 const gfx::Rect& arrow_bounds) const { | 503 const gfx::Rect& arrow_bounds) const { |
| 503 DCHECK(!UseMd()); | 504 DCHECK(!UseMd()); |
| 504 canvas->DrawImageInt(*GetArrowImage(), arrow_bounds.x(), arrow_bounds.y()); | 505 canvas->DrawImageInt(*GetArrowImage(), arrow_bounds.x(), arrow_bounds.y()); |
| 505 SkPath path; | 506 SkPath path; |
| 506 GetArrowPathFromArrowBounds(arrow_bounds, &path); | 507 GetArrowPathFromArrowBounds(arrow_bounds, &path); |
| 507 SkPaint paint; | 508 CdlPaint paint; |
| 508 paint.setStyle(SkPaint::kFill_Style); | 509 paint.setStyle(CdlPaint::kFill_Style); |
| 509 paint.setColor(background_color_); | 510 paint.setColor(background_color_); |
| 510 | 511 |
| 511 canvas->DrawPath(path, paint); | 512 canvas->DrawPath(path, paint); |
| 512 } | 513 } |
| 513 | 514 |
| 514 SkRRect BubbleBorder::GetClientRect(const View& view) const { | 515 SkRRect BubbleBorder::GetClientRect(const View& view) const { |
| 515 gfx::RectF bounds(view.GetLocalBounds()); | 516 gfx::RectF bounds(view.GetLocalBounds()); |
| 516 bounds.Inset(GetInsets()); | 517 bounds.Inset(GetInsets()); |
| 517 return SkRRect::MakeRectXY(gfx::RectFToSkRect(bounds), | 518 return SkRRect::MakeRectXY(gfx::RectFToSkRect(bounds), |
| 518 GetBorderCornerRadius(), GetBorderCornerRadius()); | 519 GetBorderCornerRadius(), GetBorderCornerRadius()); |
| 519 } | 520 } |
| 520 | 521 |
| 521 void BubbleBorder::PaintMd(const View& view, gfx::Canvas* canvas) { | 522 void BubbleBorder::PaintMd(const View& view, gfx::Canvas* canvas) { |
| 522 if (shadow_ == NO_ASSETS) | 523 if (shadow_ == NO_ASSETS) |
| 523 return PaintNoAssets(view, canvas); | 524 return PaintNoAssets(view, canvas); |
| 524 | 525 |
| 525 gfx::ScopedCanvas scoped(canvas); | 526 gfx::ScopedCanvas scoped(canvas); |
| 526 | 527 |
| 527 SkPaint paint; | 528 CdlPaint paint; |
| 528 std::vector<gfx::ShadowValue> shadows; | 529 std::vector<gfx::ShadowValue> shadows; |
| 529 // gfx::ShadowValue counts blur pixels both inside and outside the shape, | 530 // gfx::ShadowValue counts blur pixels both inside and outside the shape, |
| 530 // whereas these blur values only describe the outside portion, hence they | 531 // whereas these blur values only describe the outside portion, hence they |
| 531 // must be doubled. | 532 // must be doubled. |
| 532 shadows.emplace_back(gfx::Vector2d(0, kSmallShadowVerticalOffset), | 533 shadows.emplace_back(gfx::Vector2d(0, kSmallShadowVerticalOffset), |
| 533 2 * kSmallShadowBlur, kSmallShadowColor); | 534 2 * kSmallShadowBlur, kSmallShadowColor); |
| 534 shadows.emplace_back(gfx::Vector2d(0, kLargeShadowVerticalOffset), | 535 shadows.emplace_back(gfx::Vector2d(0, kLargeShadowVerticalOffset), |
| 535 2 * kLargeShadowBlur, kLargeShadowColor); | 536 2 * kLargeShadowBlur, kLargeShadowColor); |
| 536 paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows)); | 537 paint.setLooper(gfx::CreateShadowDrawLooperCorrectBlur(shadows)); |
| 537 paint.setColor(SkColorSetA(SK_ColorBLACK, 0x26)); | 538 paint.setColor(SkColorSetA(SK_ColorBLACK, 0x26)); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 557 | 558 |
| 558 internal::BorderImages* BubbleBorder::GetImagesForTest() const { | 559 internal::BorderImages* BubbleBorder::GetImagesForTest() const { |
| 559 return images_; | 560 return images_; |
| 560 } | 561 } |
| 561 | 562 |
| 562 void BubbleBackground::Paint(gfx::Canvas* canvas, views::View* view) const { | 563 void BubbleBackground::Paint(gfx::Canvas* canvas, views::View* view) const { |
| 563 if (border_->shadow() == BubbleBorder::NO_SHADOW_OPAQUE_BORDER) | 564 if (border_->shadow() == BubbleBorder::NO_SHADOW_OPAQUE_BORDER) |
| 564 canvas->DrawColor(border_->background_color()); | 565 canvas->DrawColor(border_->background_color()); |
| 565 | 566 |
| 566 // Fill the contents with a round-rect region to match the border images. | 567 // Fill the contents with a round-rect region to match the border images. |
| 567 SkPaint paint; | 568 CdlPaint paint; |
| 568 paint.setAntiAlias(true); | 569 paint.setAntiAlias(true); |
| 569 paint.setStyle(SkPaint::kFill_Style); | 570 paint.setStyle(CdlPaint::kFill_Style); |
| 570 paint.setColor(border_->background_color()); | 571 paint.setColor(border_->background_color()); |
| 571 SkPath path; | 572 SkPath path; |
| 572 gfx::RectF bounds(view->GetLocalBounds()); | 573 gfx::RectF bounds(view->GetLocalBounds()); |
| 573 bounds.Inset(gfx::InsetsF(border_->GetInsets())); | 574 bounds.Inset(gfx::InsetsF(border_->GetInsets())); |
| 574 | 575 |
| 575 canvas->DrawRoundRect(bounds, border_->GetBorderCornerRadius(), paint); | 576 canvas->DrawRoundRect(bounds, border_->GetBorderCornerRadius(), paint); |
| 576 } | 577 } |
| 577 | 578 |
| 578 } // namespace views | 579 } // namespace views |
| OLD | NEW |