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

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

Issue 11280251: chrome: Use skia::RefPtr for skia ref-counted objects. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: linuxbuild Created 8 years 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) 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 = skia::AdoptRef(
28 gradient_points, gradient_colors, NULL, 2, SkShader::kClamp_TileMode); 28 SkGradientShader::CreateLinear(gradient_points, gradient_colors, NULL, 2,
29 SkShader::kClamp_TileMode));
29 SkPaint paint; 30 SkPaint paint;
30 paint.setStrokeWidth(SkIntToScalar(InfoBar::kSeparatorLineHeight)); 31 paint.setStrokeWidth(SkIntToScalar(InfoBar::kSeparatorLineHeight));
31 paint.setStyle(SkPaint::kFill_Style); 32 paint.setStyle(SkPaint::kFill_Style);
32 paint.setStrokeCap(SkPaint::kRound_Cap); 33 paint.setStrokeCap(SkPaint::kRound_Cap);
33 paint.setShader(gradient_shader); 34 paint.setShader(gradient_shader.get());
34 gradient_shader->unref();
35 35
36 InfoBarView* infobar = static_cast<InfoBarView*>(view); 36 InfoBarView* infobar = static_cast<InfoBarView*>(view);
37 SkCanvas* canvas_skia = canvas->sk_canvas(); 37 SkCanvas* canvas_skia = canvas->sk_canvas();
38 canvas_skia->drawPath(infobar->fill_path(), paint); 38 canvas_skia->drawPath(infobar->fill_path(), paint);
39 39
40 paint.setShader(NULL); 40 paint.setShader(NULL);
41 paint.setColor(SkColorSetA(separator_color_, 41 paint.setColor(SkColorSetA(separator_color_,
42 SkColorGetA(gradient_colors[0]))); 42 SkColorGetA(gradient_colors[0])));
43 paint.setStyle(SkPaint::kStroke_Style); 43 paint.setStyle(SkPaint::kStroke_Style);
44 // Anti-alias the path so it doesn't look goofy when the edges are not at 45 44 // 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, 45 // degree angles, but don't anti-alias anything else, especially not the fill,
46 // lest we get weird color bleeding problems. 46 // lest we get weird color bleeding problems.
47 paint.setAntiAlias(true); 47 paint.setAntiAlias(true);
48 canvas_skia->drawPath(infobar->stroke_path(), paint); 48 canvas_skia->drawPath(infobar->stroke_path(), paint);
49 paint.setAntiAlias(false); 49 paint.setAntiAlias(false);
50 50
51 // Now draw the separator at the bottom. 51 // Now draw the separator at the bottom.
52 canvas->FillRect(gfx::Rect(0, view->height() - InfoBar::kSeparatorLineHeight, 52 canvas->FillRect(gfx::Rect(0, view->height() - InfoBar::kSeparatorLineHeight,
53 view->width(), InfoBar::kSeparatorLineHeight), 53 view->width(), InfoBar::kSeparatorLineHeight),
54 separator_color_); 54 separator_color_);
55 } 55 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/omnibox/location_bar_util.cc ('k') | chrome/browser/ui/views/tabs/dragged_tab_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698