Chromium Code Reviews| 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 "chrome/browser/ui/views/infobars/infobar_background.h" | 5 #include "chrome/browser/ui/views/infobars/infobar_background.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/infobar_container_delegate.h" | 7 #include "chrome/browser/ui/infobar_container_delegate.h" |
| 8 #include "chrome/browser/ui/views/infobars/infobar_view.h" | 8 #include "chrome/browser/ui/views/infobars/infobar_view.h" |
| 9 #include "components/infobars/core/infobar.h" | 9 #include "components/infobars/core/infobar.h" |
| 10 #include "third_party/skia/include/effects/SkGradientShader.h" | 10 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 11 #include "ui/base/material_design/material_design_controller.h" | |
| 11 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/color_utils.h" | 13 #include "ui/gfx/color_utils.h" |
| 14 #include "ui/gfx/scoped_canvas.h" | |
| 13 #include "ui/views/view.h" | 15 #include "ui/views/view.h" |
| 14 | 16 |
| 15 InfoBarBackground::InfoBarBackground( | 17 InfoBarBackground::InfoBarBackground( |
| 16 infobars::InfoBarDelegate::Type infobar_type) | 18 infobars::InfoBarDelegate::Type infobar_type) |
| 17 : separator_color_(SK_ColorBLACK), | 19 : separator_color_(SK_ColorBLACK), |
| 18 top_color_(infobars::InfoBar::GetTopColor(infobar_type)), | 20 top_color_(infobars::InfoBar::GetTopColor(infobar_type)), |
| 19 bottom_color_(infobars::InfoBar::GetBottomColor(infobar_type)) { | 21 bottom_color_(infobars::InfoBar::GetBottomColor(infobar_type)) { |
| 20 SetNativeControlColor( | 22 SetNativeControlColor( |
| 21 color_utils::AlphaBlend(top_color_, bottom_color_, 128)); | 23 color_utils::AlphaBlend(top_color_, bottom_color_, 128)); |
| 22 } | 24 } |
| 23 | 25 |
| 24 InfoBarBackground::~InfoBarBackground() { | 26 InfoBarBackground::~InfoBarBackground() { |
| 25 } | 27 } |
| 26 | 28 |
| 27 void InfoBarBackground::Paint(gfx::Canvas* canvas, views::View* view) const { | 29 void InfoBarBackground::Paint(gfx::Canvas* canvas, views::View* view) const { |
| 28 SkPoint gradient_points[2]; | 30 if (ui::MaterialDesignController::IsModeMaterial()) { |
|
Peter Kasting
2016/03/25 05:07:46
For simplicity, can we just draw a 1 px border for
Evan Stade
2016/03/28 21:44:36
There are several differences:
- stroke width, as
Peter Kasting
2016/03/29 01:04:00
Right, this would be an appearance change for non-
| |
| 29 gradient_points[0].iset(0, 0); | 31 gfx::ScopedCanvas scoped(canvas); |
| 30 gradient_points[1].iset(0, view->height()); | 32 // Undo the scale factor so we can stroke with a width of 1px (not 1dp). |
| 31 SkColor gradient_colors[2] = { top_color_, bottom_color_ }; | 33 const float scale = canvas->UndoDeviceScaleFactor(); |
| 32 SkPaint paint; | 34 // View bounds are in dp. Manually scale for px. |
| 33 paint.setStrokeWidth( | 35 gfx::SizeF view_size_px = gfx::ScaleSize(gfx::SizeF(view->size()), scale); |
| 34 SkIntToScalar(InfoBarContainerDelegate::kSeparatorLineHeight)); | |
| 35 paint.setStyle(SkPaint::kFill_Style); | |
| 36 paint.setStrokeCap(SkPaint::kRound_Cap); | |
| 37 paint.setShader(SkGradientShader::MakeLinear( | |
| 38 gradient_points, gradient_colors, NULL, 2, SkShader::kClamp_TileMode)); | |
| 39 | 36 |
| 40 InfoBarView* infobar = static_cast<InfoBarView*>(view); | 37 SkPaint fill; |
| 41 SkCanvas* canvas_skia = canvas->sk_canvas(); | 38 fill.setStyle(SkPaint::kFill_Style); |
| 42 canvas_skia->drawPath(infobar->fill_path(), paint); | 39 fill.setColor(top_color_); |
| 43 | 40 |
| 44 paint.setShader(NULL); | 41 InfoBarView* infobar = static_cast<InfoBarView*>(view); |
| 45 paint.setColor(SkColorSetA(separator_color_, | 42 SkCanvas* canvas_skia = canvas->sk_canvas(); |
| 46 SkColorGetA(gradient_colors[0]))); | 43 // The paths provided by |infobar| are in dp. Manually scale for px. |
| 47 paint.setStyle(SkPaint::kStroke_Style); | 44 SkMatrix dsf_transform; |
| 48 // Anti-alias the path so it doesn't look goofy when the edges are not at 45 | 45 dsf_transform.setScale(SkFloatToScalar(scale), SkFloatToScalar(scale)); |
| 49 // degree angles, but don't anti-alias anything else, especially not the fill, | 46 SkPath fill_path = infobar->fill_path(); |
| 50 // lest we get weird color bleeding problems. | 47 fill_path.transform(dsf_transform); |
| 51 paint.setAntiAlias(true); | 48 canvas_skia->drawPath(fill_path, fill); |
| 52 canvas_skia->drawPath(infobar->stroke_path(), paint); | |
| 53 paint.setAntiAlias(false); | |
| 54 | 49 |
| 55 // Now draw the separator at the bottom. | 50 SkPaint stroke; |
| 56 canvas->FillRect( | 51 stroke.setStyle(SkPaint::kStroke_Style); |
| 57 gfx::Rect(0, | 52 stroke.setStrokeWidth( |
| 58 view->height() - InfoBarContainerDelegate::kSeparatorLineHeight, | 53 SkIntToScalar(InfoBarContainerDelegate::kSeparatorLineHeight)); |
| 59 view->width(), InfoBarContainerDelegate::kSeparatorLineHeight), | 54 stroke.setColor(separator_color_); |
| 60 separator_color_); | 55 SkPath stroke_path = infobar->stroke_path(); |
| 56 stroke_path.transform(dsf_transform); | |
| 57 | |
| 58 // Top separator (with arrow shape). | |
| 59 stroke.setAntiAlias(true); | |
| 60 canvas_skia->drawPath(stroke_path, stroke); | |
| 61 // Bottom separator. | |
| 62 stroke.setAntiAlias(false); | |
| 63 SkScalar y = SkIntToScalar(view_size_px.height() - | |
| 64 InfoBarContainerDelegate::kSeparatorLineHeight) + | |
| 65 SK_ScalarHalf; | |
| 66 SkScalar w = SkIntToScalar(view_size_px.width()); | |
| 67 canvas_skia->drawLine(0, y, w, y, stroke); | |
| 68 } else { | |
| 69 SkPoint gradient_points[2]; | |
| 70 gradient_points[0].iset(0, 0); | |
| 71 gradient_points[1].iset(0, view->height()); | |
| 72 SkColor gradient_colors[2] = {top_color_, bottom_color_}; | |
| 73 SkPaint paint; | |
| 74 paint.setStrokeWidth( | |
| 75 SkIntToScalar(InfoBarContainerDelegate::kSeparatorLineHeight)); | |
| 76 paint.setStyle(SkPaint::kFill_Style); | |
| 77 paint.setStrokeCap(SkPaint::kRound_Cap); | |
| 78 paint.setShader(SkGradientShader::MakeLinear( | |
| 79 gradient_points, gradient_colors, NULL, 2, SkShader::kClamp_TileMode)); | |
| 80 | |
| 81 InfoBarView* infobar = static_cast<InfoBarView*>(view); | |
| 82 SkCanvas* canvas_skia = canvas->sk_canvas(); | |
| 83 canvas_skia->drawPath(infobar->fill_path(), paint); | |
| 84 | |
| 85 paint.setShader(NULL); | |
| 86 paint.setColor( | |
| 87 SkColorSetA(separator_color_, SkColorGetA(gradient_colors[0]))); | |
| 88 paint.setStyle(SkPaint::kStroke_Style); | |
| 89 // Anti-alias the path so it doesn't look goofy when the edges are not at 45 | |
| 90 // degree angles, but don't anti-alias anything else, especially not the | |
| 91 // fill, lest we get weird color bleeding problems. | |
| 92 paint.setAntiAlias(true); | |
| 93 canvas_skia->drawPath(infobar->stroke_path(), paint); | |
| 94 paint.setAntiAlias(false); | |
| 95 | |
| 96 // Now draw the separator at the bottom. | |
| 97 canvas->FillRect( | |
| 98 gfx::Rect( | |
| 99 0, view->height() - InfoBarContainerDelegate::kSeparatorLineHeight, | |
| 100 view->width(), InfoBarContainerDelegate::kSeparatorLineHeight), | |
| 101 separator_color_); | |
| 102 } | |
| 61 } | 103 } |
| OLD | NEW |