| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ui/base/resource/resource_bundle.h" | 8 #include "ui/base/resource/resource_bundle.h" |
| 8 #include "ui/gfx/canvas.h" | 9 #include "ui/gfx/canvas.h" |
| 10 #include "ui/gfx/canvas_skia_paint.h" |
| 11 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 9 #include "views/view.h" | 12 #include "views/view.h" |
| 10 | 13 |
| 11 // static | 14 // static |
| 12 const int InfoBarBackground::kSeparatorLineHeight = 1; | 15 const int InfoBarBackground::kSeparatorLineHeight = 1; |
| 13 | 16 |
| 14 InfoBarBackground::InfoBarBackground(InfoBarDelegate::Type infobar_type) { | 17 InfoBarBackground::InfoBarBackground(InfoBarDelegate::Type infobar_type) |
| 15 gradient_background_.reset( | 18 : top_color_(GetTopColor(infobar_type)), |
| 16 views::Background::CreateVerticalGradientBackground( | 19 bottom_color_(GetBottomColor(infobar_type)) { |
| 17 GetTopColor(infobar_type), | |
| 18 GetBottomColor(infobar_type))); | |
| 19 } | 20 } |
| 20 | 21 |
| 21 InfoBarBackground::~InfoBarBackground() { | 22 InfoBarBackground::~InfoBarBackground() { |
| 22 } | 23 } |
| 23 | 24 |
| 24 SkColor InfoBarBackground::GetTopColor(InfoBarDelegate::Type infobar_type) { | 25 SkColor InfoBarBackground::GetTopColor(InfoBarDelegate::Type infobar_type) { |
| 25 static const SkColor kWarningBackgroundColorTop = | 26 static const SkColor kWarningBackgroundColorTop = |
| 26 SkColorSetRGB(255, 242, 183); | 27 SkColorSetRGB(255, 242, 183); |
| 27 static const SkColor kPageActionBackgroundColorTop = | 28 static const SkColor kPageActionBackgroundColorTop = |
| 28 SkColorSetRGB(218, 231, 249); | 29 SkColorSetRGB(218, 231, 249); |
| 29 | 30 |
| 30 return (infobar_type == InfoBarDelegate::WARNING_TYPE) ? | 31 return (infobar_type == InfoBarDelegate::WARNING_TYPE) ? |
| 31 kWarningBackgroundColorTop : kPageActionBackgroundColorTop; | 32 kWarningBackgroundColorTop : kPageActionBackgroundColorTop; |
| 32 } | 33 } |
| 33 | 34 |
| 34 SkColor InfoBarBackground::GetBottomColor(InfoBarDelegate::Type infobar_type) { | 35 SkColor InfoBarBackground::GetBottomColor(InfoBarDelegate::Type infobar_type) { |
| 35 static const SkColor kWarningBackgroundColorBottom = | 36 static const SkColor kWarningBackgroundColorBottom = |
| 36 SkColorSetRGB(250, 230, 145); | 37 SkColorSetRGB(250, 230, 145); |
| 37 static const SkColor kPageActionBackgroundColorBottom = | 38 static const SkColor kPageActionBackgroundColorBottom = |
| 38 SkColorSetRGB(179, 202, 231); | 39 SkColorSetRGB(179, 202, 231); |
| 39 | 40 |
| 40 return (infobar_type == InfoBarDelegate::WARNING_TYPE) ? | 41 return (infobar_type == InfoBarDelegate::WARNING_TYPE) ? |
| 41 kWarningBackgroundColorBottom : kPageActionBackgroundColorBottom; | 42 kWarningBackgroundColorBottom : kPageActionBackgroundColorBottom; |
| 42 } | 43 } |
| 43 | 44 |
| 44 void InfoBarBackground::Paint(gfx::Canvas* canvas, views::View* view) const { | 45 void InfoBarBackground::Paint(gfx::Canvas* canvas, views::View* view) const { |
| 45 gradient_background_->Paint(canvas, view); | 46 SkPoint gradient_points[2] = { |
| 47 {SkIntToScalar(0), SkIntToScalar(0)}, |
| 48 {SkIntToScalar(0), SkIntToScalar(view->height())} |
| 49 }; |
| 50 SkColor gradient_colors[2] = { |
| 51 top_color_, |
| 52 bottom_color_ |
| 53 }; |
| 54 SkShader* gradient_shader = |
| 55 SkGradientShader::CreateLinear(gradient_points, gradient_colors, |
| 56 NULL, 2, SkShader::kClamp_TileMode); |
| 57 SkPaint paint; |
| 58 paint.setStrokeWidth(SkIntToScalar(InfoBarView::kTabStrokeWidth)); |
| 59 paint.setStyle(SkPaint::kFill_Style); |
| 60 paint.setShader(gradient_shader); |
| 61 paint.setAntiAlias(true); |
| 62 gradient_shader->unref(); |
| 63 |
| 64 InfoBarView* infobar = static_cast<InfoBarView*>(view); |
| 65 gfx::CanvasSkia* canvas_skia = canvas->AsCanvasSkia(); |
| 66 canvas_skia->drawPath(*infobar->fill_path(), paint); |
| 67 |
| 68 paint.setShader(NULL); |
| 69 paint.setColor(SkColorSetA(ResourceBundle::toolbar_separator_color, |
| 70 SkColorGetA(gradient_colors[0]))); |
| 71 paint.setStyle(SkPaint::kStroke_Style); |
| 72 canvas_skia->drawPath(*infobar->stroke_path(), paint); |
| 73 |
| 74 // Now draw at the bottom. |
| 46 canvas->FillRectInt(ResourceBundle::toolbar_separator_color, 0, | 75 canvas->FillRectInt(ResourceBundle::toolbar_separator_color, 0, |
| 47 view->height() - kSeparatorLineHeight, view->width(), | 76 view->height() - kSeparatorLineHeight, view->width(), |
| 48 kSeparatorLineHeight); | 77 kSeparatorLineHeight); |
| 49 } | 78 } |
| OLD | NEW |