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

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

Issue 1826653002: Draw infobar arrow border with width of 1px on any scale factor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: also deal with bottom separator Created 4 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
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/infobar_container_delegate.h" 7 #include "chrome/browser/ui/infobar_container_delegate.h"
8 #include "chrome/browser/ui/views/infobars/infobar_view.h" 8 #include "chrome/browser/ui/views/infobars/infobar_view.h"
9 #include "components/infobars/core/infobar.h" 9 #include "components/infobars/core/infobar.h"
10 #include "third_party/skia/include/effects/SkGradientShader.h" 10 #include "third_party/skia/include/effects/SkGradientShader.h"
11 #include "ui/base/material_design/material_design_controller.h"
11 #include "ui/gfx/canvas.h" 12 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/color_utils.h" 13 #include "ui/gfx/color_utils.h"
13 #include "ui/views/view.h" 14 #include "ui/views/view.h"
14 15
15 InfoBarBackground::InfoBarBackground( 16 InfoBarBackground::InfoBarBackground(
16 infobars::InfoBarDelegate::Type infobar_type) 17 infobars::InfoBarDelegate::Type infobar_type)
17 : separator_color_(SK_ColorBLACK), 18 : separator_color_(SK_ColorBLACK),
18 top_color_(infobars::InfoBar::GetTopColor(infobar_type)), 19 top_color_(infobars::InfoBar::GetTopColor(infobar_type)),
19 bottom_color_(infobars::InfoBar::GetBottomColor(infobar_type)) { 20 bottom_color_(infobars::InfoBar::GetBottomColor(infobar_type)) {
20 SetNativeControlColor( 21 SetNativeControlColor(
21 color_utils::AlphaBlend(top_color_, bottom_color_, 128)); 22 color_utils::AlphaBlend(top_color_, bottom_color_, 128));
22 } 23 }
23 24
24 InfoBarBackground::~InfoBarBackground() { 25 InfoBarBackground::~InfoBarBackground() {
25 } 26 }
26 27
27 void InfoBarBackground::Paint(gfx::Canvas* canvas, views::View* view) const { 28 void InfoBarBackground::Paint(gfx::Canvas* canvas, views::View* view) const {
28 SkPoint gradient_points[2]; 29 SkPoint gradient_points[2];
29 gradient_points[0].iset(0, 0); 30 gradient_points[0].iset(0, 0);
30 gradient_points[1].iset(0, view->height()); 31 gradient_points[1].iset(0, view->height());
31 SkColor gradient_colors[2] = { top_color_, bottom_color_ }; 32 SkColor gradient_colors[2] = { top_color_, bottom_color_ };
32 SkPaint paint; 33 SkPaint paint;
33 paint.setStrokeWidth(
34 SkIntToScalar(InfoBarContainerDelegate::kSeparatorLineHeight));
35 paint.setStyle(SkPaint::kFill_Style); 34 paint.setStyle(SkPaint::kFill_Style);
36 paint.setStrokeCap(SkPaint::kRound_Cap);
37 paint.setShader(SkGradientShader::MakeLinear( 35 paint.setShader(SkGradientShader::MakeLinear(
38 gradient_points, gradient_colors, NULL, 2, SkShader::kClamp_TileMode)); 36 gradient_points, gradient_colors, nullptr, 2, SkShader::kClamp_TileMode));
39 37
40 InfoBarView* infobar = static_cast<InfoBarView*>(view); 38 InfoBarView* infobar = static_cast<InfoBarView*>(view);
41 SkCanvas* canvas_skia = canvas->sk_canvas(); 39 SkCanvas* canvas_skia = canvas->sk_canvas();
42 canvas_skia->drawPath(infobar->fill_path(), paint); 40 canvas_skia->drawPath(infobar->fill_path(), paint);
43 41
44 paint.setShader(NULL); 42 paint.setShader(nullptr);
Peter Kasting 2016/03/23 00:28:17 Nit: Rather than reset this, let's just use two di
45 paint.setColor(SkColorSetA(separator_color_, 43 paint.setColor(SkColorSetA(separator_color_,
46 SkColorGetA(gradient_colors[0]))); 44 SkColorGetA(gradient_colors[0])));
45 paint.setStrokeCap(SkPaint::kRound_Cap);
Peter Kasting 2016/03/22 23:39:18 Why do we need to set the cap for a hairline?
46 paint.setStrokeWidth(
47 ui::MaterialDesignController::IsModeMaterial()
48 ? 0
49 : SkIntToScalar(InfoBarContainerDelegate::kSeparatorLineHeight));
47 paint.setStyle(SkPaint::kStroke_Style); 50 paint.setStyle(SkPaint::kStroke_Style);
48 // Anti-alias the path so it doesn't look goofy when the edges are not at 45 51 // 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, 52 // degree angles, but don't anti-alias anything else, especially not the fill,
50 // lest we get weird color bleeding problems. 53 // lest we get weird color bleeding problems.
51 paint.setAntiAlias(true); 54 paint.setAntiAlias(true);
52 canvas_skia->drawPath(infobar->stroke_path(), paint); 55 canvas_skia->drawPath(infobar->stroke_path(), paint);
53 paint.setAntiAlias(false); 56 paint.setAntiAlias(false);
54 57
55 // Now draw the separator at the bottom. 58 // Now draw the separator at the bottom.
56 canvas->FillRect( 59 paint.setColor(separator_color_);
57 gfx::Rect(0, 60 SkScalar bottom = SkIntToScalar(view->height()) - SK_ScalarHalf;
Peter Kasting 2016/03/23 00:28:17 This seems wrong at >1x. It really wants to move
Evan Stade 2016/03/23 00:35:46 You're right, it does have bugs at >2x scales. I'l
58 view->height() - InfoBarContainerDelegate::kSeparatorLineHeight, 61 canvas_skia->drawLine(0, bottom, SkIntToScalar(view->width()), bottom, paint);
59 view->width(), InfoBarContainerDelegate::kSeparatorLineHeight),
60 separator_color_);
61 } 62 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/infobars/infobar_view.cc » ('j') | chrome/browser/ui/views/infobars/infobar_view.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698