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

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

Issue 2347773003: Remove pre-MD infobar code (on Views). (Closed)
Patch Set: pkasting review/button image clear out Created 4 years, 3 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"
11 #include "ui/base/material_design/material_design_controller.h" 10 #include "ui/base/material_design/material_design_controller.h"
12 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/color_utils.h"
14 #include "ui/gfx/scoped_canvas.h" 12 #include "ui/gfx/scoped_canvas.h"
15 #include "ui/views/view.h" 13 #include "ui/views/view.h"
16 14
17 InfoBarBackground::InfoBarBackground( 15 InfoBarBackground::InfoBarBackground(
18 infobars::InfoBarDelegate::Type infobar_type) 16 infobars::InfoBarDelegate::Type infobar_type) {
19 : top_color_(infobars::InfoBar::GetTopColor(infobar_type)), 17 SetNativeControlColor(infobars::InfoBar::GetTopColor(infobar_type));
20 bottom_color_(infobars::InfoBar::GetBottomColor(infobar_type)) {
21 SetNativeControlColor(
22 color_utils::AlphaBlend(top_color_, bottom_color_, 128));
23 } 18 }
24 19
25 InfoBarBackground::~InfoBarBackground() { 20 InfoBarBackground::~InfoBarBackground() {
26 } 21 }
27 22
28 void InfoBarBackground::Paint(gfx::Canvas* canvas, views::View* view) const { 23 void InfoBarBackground::Paint(gfx::Canvas* canvas, views::View* view) const {
29 if (ui::MaterialDesignController::IsModeMaterial()) {
30 PaintMd(canvas, view);
31 return;
32 }
33
34 SkPoint gradient_points[2];
35 gradient_points[0].iset(0, 0);
36 gradient_points[1].iset(0, view->height());
37 SkColor gradient_colors[2] = {top_color_, bottom_color_};
38 SkPaint paint;
39 paint.setStrokeWidth(
40 SkIntToScalar(InfoBarContainerDelegate::kSeparatorLineHeight));
41 paint.setStyle(SkPaint::kFill_Style);
42 paint.setStrokeCap(SkPaint::kRound_Cap);
43 paint.setShader(SkGradientShader::MakeLinear(
44 gradient_points, gradient_colors, nullptr, 2, SkShader::kClamp_TileMode));
45
46 SkCanvas* canvas_skia = canvas->sk_canvas();
47 InfoBarView* infobar = static_cast<InfoBarView*>(view);
48 canvas_skia->drawPath(infobar->fill_path(), paint);
49
50 paint.setShader(nullptr);
51 SkColor separator_color =
52 infobar->container_delegate()->GetInfoBarSeparatorColor();
53 paint.setColor(SkColorSetA(separator_color, SkColorGetA(gradient_colors[0])));
54 paint.setStyle(SkPaint::kStroke_Style);
55 // Anti-alias the path so it doesn't look goofy when the edges are not at 45
56 // degree angles, but don't anti-alias anything else, especially not the fill,
57 // lest we get weird color bleeding problems.
58 paint.setAntiAlias(true);
59 canvas_skia->drawPath(infobar->stroke_path(), paint);
60 paint.setAntiAlias(false);
61
62 // Now draw the separator at the bottom.
63 canvas->FillRect(
64 gfx::Rect(0,
65 view->height() - InfoBarContainerDelegate::kSeparatorLineHeight,
66 view->width(), InfoBarContainerDelegate::kSeparatorLineHeight),
67 separator_color);
68 }
69
70 void InfoBarBackground::PaintMd(gfx::Canvas* canvas, views::View* view) const {
71 InfoBarView* infobar = static_cast<InfoBarView*>(view); 24 InfoBarView* infobar = static_cast<InfoBarView*>(view);
72 const infobars::InfoBarContainer::Delegate* delegate = 25 const infobars::InfoBarContainer::Delegate* delegate =
73 infobar->container_delegate(); 26 infobar->container_delegate();
74 SkPath stroke_path, fill_path; 27 SkPath stroke_path, fill_path;
75 SkColor separator_color = SK_ColorBLACK; 28 SkColor separator_color = SK_ColorBLACK;
76 gfx::ScopedCanvas scoped(canvas); 29 gfx::ScopedCanvas scoped(canvas);
77 // Undo the scale factor so we can stroke with a width of 1px (not 1dp). 30 // Undo the scale factor so we can stroke with a width of 1px (not 1dp).
78 const float dsf = canvas->UndoDeviceScaleFactor(); 31 const float dsf = canvas->UndoDeviceScaleFactor();
79 // Always scale to a whole number to make sure strokes are sharp. 32 // Always scale to a whole number to make sure strokes are sharp.
80 // For some fractional DSFs, view size rounding issues may cause there to be a 33 // For some fractional DSFs, view size rounding issues may cause there to be a
(...skipping 24 matching lines...) Expand all
105 // Add SK_ScalarHalf to both axes to place the path on pixel centers. 58 // Add SK_ScalarHalf to both axes to place the path on pixel centers.
106 stroke_path.offset(SK_ScalarHalf, SK_ScalarHalf); 59 stroke_path.offset(SK_ScalarHalf, SK_ScalarHalf);
107 60
108 fill_path = stroke_path; 61 fill_path = stroke_path;
109 fill_path.close(); 62 fill_path.close();
110 } 63 }
111 } 64 }
112 fill_path.addRect(0, arrow_height, infobar_width, scale(infobar->height())); 65 fill_path.addRect(0, arrow_height, infobar_width, scale(infobar->height()));
113 SkPaint fill; 66 SkPaint fill;
114 fill.setStyle(SkPaint::kFill_Style); 67 fill.setStyle(SkPaint::kFill_Style);
115 fill.setColor(top_color_); 68 fill.setColor(get_color());
116 canvas->DrawPath(fill_path, fill); 69 canvas->DrawPath(fill_path, fill);
117 70
118 SkPaint stroke; 71 SkPaint stroke;
119 stroke.setStyle(SkPaint::kStroke_Style); 72 stroke.setStyle(SkPaint::kStroke_Style);
120 const int kSeparatorThicknessPx = 1; 73 const int kSeparatorThicknessPx = 1;
121 stroke.setStrokeWidth(SkIntToScalar(kSeparatorThicknessPx)); 74 stroke.setStrokeWidth(SkIntToScalar(kSeparatorThicknessPx));
122 stroke.setColor(separator_color); 75 stroke.setColor(separator_color);
123 stroke.setAntiAlias(true); 76 stroke.setAntiAlias(true);
124 canvas->DrawPath(stroke_path, stroke); 77 canvas->DrawPath(stroke_path, stroke);
125 78
126 // Bottom separator. 79 // Bottom separator.
127 stroke.setAntiAlias(false); 80 stroke.setAntiAlias(false);
128 gfx::SizeF view_size_px = gfx::ScaleSize(gfx::SizeF(view->size()), dsf); 81 gfx::SizeF view_size_px = gfx::ScaleSize(gfx::SizeF(view->size()), dsf);
129 SkScalar y = SkIntToScalar(view_size_px.height() - kSeparatorThicknessPx) + 82 SkScalar y = SkIntToScalar(view_size_px.height() - kSeparatorThicknessPx) +
130 SK_ScalarHalf; 83 SK_ScalarHalf;
131 SkScalar w = SkFloatToScalar(view_size_px.width()); 84 SkScalar w = SkFloatToScalar(view_size_px.width());
132 canvas->sk_canvas()->drawLine(0, y, w, y, stroke); 85 canvas->sk_canvas()->drawLine(0, y, w, y, stroke);
133 } 86 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/infobars/infobar_background.h ('k') | chrome/browser/ui/views/infobars/infobar_container_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698