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