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