Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: chrome/browser/ui/views/infobars/infobar_background.cc

Issue 6609047: [linux_views][Win] spoof proof redesign infobar extension with tab. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: renames, don't const_cast, ditch InfoBarView::VerticalOffset. Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 = SkGradientShader::CreateLinear(
55 gradient_points, gradient_colors, NULL, 2, SkShader::kClamp_TileMode);
56 SkPaint paint;
57 paint.setStrokeWidth(1.0);
58 paint.setStyle(SkPaint::kFill_Style);
59 paint.setShader(gradient_shader);
60 paint.setAntiAlias(true);
61 gradient_shader->unref();
62
63 InfoBarView* infobar = static_cast<InfoBarView*>(view);
64 gfx::CanvasSkia* canvas_skia = canvas->AsCanvasSkia();
65 canvas_skia->drawPath(*infobar->fill_path(), paint);
66
67 paint.setShader(NULL);
68 paint.setColor(SkColorSetA(ResourceBundle::toolbar_separator_color,
69 SkColorGetA(gradient_colors[0])));
70 paint.setStyle(SkPaint::kStroke_Style);
71 canvas_skia->drawPath(*infobar->stroke_path(), paint);
72
73 // Now draw at the bottom.
46 canvas->FillRectInt(ResourceBundle::toolbar_separator_color, 0, 74 canvas->FillRectInt(ResourceBundle::toolbar_separator_color, 0,
47 view->height() - kSeparatorLineHeight, view->width(), 75 view->height() - kSeparatorLineHeight, view->width(),
48 kSeparatorLineHeight); 76 kSeparatorLineHeight);
49 } 77 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698