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
3 // found in the LICENSE file.
5 #include "chrome/browser/ui/views/infobars/infobar_background.h"
7 #include "chrome/browser/ui/infobar_container_delegate.h"
8 #include "chrome/browser/ui/views/infobars/infobar_view.h"
9 #include "components/infobars/core/infobar.h"
10 #include "third_party/skia/include/effects/SkGradientShader.h"
11 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/color_utils.h"
13 #include "ui/views/view.h"
15 InfoBarBackground::InfoBarBackground(
16 infobars::InfoBarDelegate::Type infobar_type
)
17 : separator_color_(SK_ColorBLACK
),
18 top_color_(infobars::InfoBar::GetTopColor(infobar_type
)),
19 bottom_color_(infobars::InfoBar::GetBottomColor(infobar_type
)) {
20 SetNativeControlColor(
21 color_utils::AlphaBlend(top_color_
, bottom_color_
, 128));
24 InfoBarBackground::~InfoBarBackground() {
27 void InfoBarBackground::Paint(gfx::Canvas
* canvas
, views::View
* view
) const {
28 SkPoint gradient_points
[2];
29 gradient_points
[0].iset(0, 0);
30 gradient_points
[1].iset(0, view
->height());
31 SkColor gradient_colors
[2] = { top_color_
, bottom_color_
};
32 skia::RefPtr
<SkShader
> gradient_shader
= skia::AdoptRef(
33 SkGradientShader::CreateLinear(gradient_points
, gradient_colors
, NULL
, 2,
34 SkShader::kClamp_TileMode
));
37 SkIntToScalar(InfoBarContainerDelegate::kSeparatorLineHeight
));
38 paint
.setStyle(SkPaint::kFill_Style
);
39 paint
.setStrokeCap(SkPaint::kRound_Cap
);
40 paint
.setShader(gradient_shader
.get());
42 InfoBarView
* infobar
= static_cast<InfoBarView
*>(view
);
43 SkCanvas
* canvas_skia
= canvas
->sk_canvas();
44 canvas_skia
->drawPath(infobar
->fill_path(), paint
);
46 paint
.setShader(NULL
);
47 paint
.setColor(SkColorSetA(separator_color_
,
48 SkColorGetA(gradient_colors
[0])));
49 paint
.setStyle(SkPaint::kStroke_Style
);
50 // Anti-alias the path so it doesn't look goofy when the edges are not at 45
51 // degree angles, but don't anti-alias anything else, especially not the fill,
52 // lest we get weird color bleeding problems.
53 paint
.setAntiAlias(true);
54 canvas_skia
->drawPath(infobar
->stroke_path(), paint
);
55 paint
.setAntiAlias(false);
57 // Now draw the separator at the bottom.
60 view
->height() - InfoBarContainerDelegate::kSeparatorLineHeight
,
61 view
->width(), InfoBarContainerDelegate::kSeparatorLineHeight
),