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

Unified 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: fix comment typo 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/infobars/infobar_background.cc
diff --git a/chrome/browser/ui/views/infobars/infobar_background.cc b/chrome/browser/ui/views/infobars/infobar_background.cc
index 7e9fe105f810af8ee28893f3064b0fc34bf69ece..5cee72194fc62fe598738b32d0240c0907bcd4d9 100644
--- a/chrome/browser/ui/views/infobars/infobar_background.cc
+++ b/chrome/browser/ui/views/infobars/infobar_background.cc
@@ -8,8 +8,10 @@
#include "chrome/browser/ui/views/infobars/infobar_view.h"
#include "components/infobars/core/infobar.h"
#include "third_party/skia/include/effects/SkGradientShader.h"
+#include "ui/base/material_design/material_design_controller.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/color_utils.h"
+#include "ui/gfx/scoped_canvas.h"
#include "ui/views/view.h"
InfoBarBackground::InfoBarBackground(
@@ -25,37 +27,77 @@ InfoBarBackground::~InfoBarBackground() {
}
void InfoBarBackground::Paint(gfx::Canvas* canvas, views::View* view) const {
- SkPoint gradient_points[2];
- gradient_points[0].iset(0, 0);
- gradient_points[1].iset(0, view->height());
- SkColor gradient_colors[2] = { top_color_, bottom_color_ };
- SkPaint paint;
- paint.setStrokeWidth(
- SkIntToScalar(InfoBarContainerDelegate::kSeparatorLineHeight));
- paint.setStyle(SkPaint::kFill_Style);
- paint.setStrokeCap(SkPaint::kRound_Cap);
- paint.setShader(SkGradientShader::MakeLinear(
- gradient_points, gradient_colors, NULL, 2, SkShader::kClamp_TileMode));
-
- InfoBarView* infobar = static_cast<InfoBarView*>(view);
- SkCanvas* canvas_skia = canvas->sk_canvas();
- canvas_skia->drawPath(infobar->fill_path(), paint);
-
- paint.setShader(NULL);
- paint.setColor(SkColorSetA(separator_color_,
- SkColorGetA(gradient_colors[0])));
- paint.setStyle(SkPaint::kStroke_Style);
- // Anti-alias the path so it doesn't look goofy when the edges are not at 45
- // degree angles, but don't anti-alias anything else, especially not the fill,
- // lest we get weird color bleeding problems.
- paint.setAntiAlias(true);
- canvas_skia->drawPath(infobar->stroke_path(), paint);
- paint.setAntiAlias(false);
-
- // Now draw the separator at the bottom.
- canvas->FillRect(
- gfx::Rect(0,
- view->height() - InfoBarContainerDelegate::kSeparatorLineHeight,
- view->width(), InfoBarContainerDelegate::kSeparatorLineHeight),
- separator_color_);
+ if (ui::MaterialDesignController::IsModeMaterial()) {
Peter Kasting 2016/03/25 05:07:46 For simplicity, can we just draw a 1 px border for
Evan Stade 2016/03/28 21:44:36 There are several differences: - stroke width, as
Peter Kasting 2016/03/29 01:04:00 Right, this would be an appearance change for non-
+ gfx::ScopedCanvas scoped(canvas);
+ // Undo the scale factor so we can stroke with a width of 1px (not 1dp).
+ const float scale = canvas->UndoDeviceScaleFactor();
+ // View bounds are in dp. Manually scale for px.
+ gfx::SizeF view_size_px = gfx::ScaleSize(gfx::SizeF(view->size()), scale);
+
+ SkPaint fill;
+ fill.setStyle(SkPaint::kFill_Style);
+ fill.setColor(top_color_);
+
+ InfoBarView* infobar = static_cast<InfoBarView*>(view);
+ SkCanvas* canvas_skia = canvas->sk_canvas();
+ // The paths provided by |infobar| are in dp. Manually scale for px.
+ SkMatrix dsf_transform;
+ dsf_transform.setScale(SkFloatToScalar(scale), SkFloatToScalar(scale));
+ SkPath fill_path = infobar->fill_path();
+ fill_path.transform(dsf_transform);
+ canvas_skia->drawPath(fill_path, fill);
+
+ SkPaint stroke;
+ stroke.setStyle(SkPaint::kStroke_Style);
+ stroke.setStrokeWidth(
+ SkIntToScalar(InfoBarContainerDelegate::kSeparatorLineHeight));
+ stroke.setColor(separator_color_);
+ SkPath stroke_path = infobar->stroke_path();
+ stroke_path.transform(dsf_transform);
+
+ // Top separator (with arrow shape).
+ stroke.setAntiAlias(true);
+ canvas_skia->drawPath(stroke_path, stroke);
+ // Bottom separator.
+ stroke.setAntiAlias(false);
+ SkScalar y = SkIntToScalar(view_size_px.height() -
+ InfoBarContainerDelegate::kSeparatorLineHeight) +
+ SK_ScalarHalf;
+ SkScalar w = SkIntToScalar(view_size_px.width());
+ canvas_skia->drawLine(0, y, w, y, stroke);
+ } else {
+ SkPoint gradient_points[2];
+ gradient_points[0].iset(0, 0);
+ gradient_points[1].iset(0, view->height());
+ SkColor gradient_colors[2] = {top_color_, bottom_color_};
+ SkPaint paint;
+ paint.setStrokeWidth(
+ SkIntToScalar(InfoBarContainerDelegate::kSeparatorLineHeight));
+ paint.setStyle(SkPaint::kFill_Style);
+ paint.setStrokeCap(SkPaint::kRound_Cap);
+ paint.setShader(SkGradientShader::MakeLinear(
+ gradient_points, gradient_colors, NULL, 2, SkShader::kClamp_TileMode));
+
+ InfoBarView* infobar = static_cast<InfoBarView*>(view);
+ SkCanvas* canvas_skia = canvas->sk_canvas();
+ canvas_skia->drawPath(infobar->fill_path(), paint);
+
+ paint.setShader(NULL);
+ paint.setColor(
+ SkColorSetA(separator_color_, SkColorGetA(gradient_colors[0])));
+ paint.setStyle(SkPaint::kStroke_Style);
+ // Anti-alias the path so it doesn't look goofy when the edges are not at 45
+ // degree angles, but don't anti-alias anything else, especially not the
+ // fill, lest we get weird color bleeding problems.
+ paint.setAntiAlias(true);
+ canvas_skia->drawPath(infobar->stroke_path(), paint);
+ paint.setAntiAlias(false);
+
+ // Now draw the separator at the bottom.
+ canvas->FillRect(
+ gfx::Rect(
+ 0, view->height() - InfoBarContainerDelegate::kSeparatorLineHeight,
+ view->width(), InfoBarContainerDelegate::kSeparatorLineHeight),
+ separator_color_);
+ }
}
« 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