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

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: move path calc 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..d5cd7b13588732d1855c9256439f02e5b86b35b5 100644
--- a/chrome/browser/ui/views/infobars/infobar_background.cc
+++ b/chrome/browser/ui/views/infobars/infobar_background.cc
@@ -8,14 +8,15 @@
#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(
infobars::InfoBarDelegate::Type infobar_type)
- : separator_color_(SK_ColorBLACK),
- top_color_(infobars::InfoBar::GetTopColor(infobar_type)),
+ : top_color_(infobars::InfoBar::GetTopColor(infobar_type)),
bottom_color_(infobars::InfoBar::GetBottomColor(infobar_type)) {
SetNativeControlColor(
color_utils::AlphaBlend(top_color_, bottom_color_, 128));
@@ -25,10 +26,21 @@ InfoBarBackground::~InfoBarBackground() {
}
void InfoBarBackground::Paint(gfx::Canvas* canvas, views::View* view) const {
+ if (ui::MaterialDesignController::IsModeMaterial()) {
+ PaintMd(canvas, view);
+ return;
+ }
+
+ InfoBarView* infobar = static_cast<InfoBarView*>(view);
Peter Kasting 2016/03/30 00:20:26 Nit: Google style guide suggests declaring these "
Evan Stade 2016/04/02 02:21:41 Done.
+ const infobars::InfoBarContainer::Delegate* delegate =
+ infobar->container_delegate();
+ SkColor separator_color =
+ delegate ? delegate->GetInfoBarSeparatorColor() : SK_ColorBLACK;
Peter Kasting 2016/03/30 00:20:26 When will the delegate be null during painting? I
Evan Stade 2016/04/02 02:21:41 I don't know why it would be null. Removed.
+
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_ };
+ SkColor gradient_colors[2] = {top_color_, bottom_color_};
SkPaint paint;
paint.setStrokeWidth(
SkIntToScalar(InfoBarContainerDelegate::kSeparatorLineHeight));
@@ -37,13 +49,11 @@ void InfoBarBackground::Paint(gfx::Canvas* canvas, views::View* view) const {
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.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,
@@ -57,5 +67,72 @@ void InfoBarBackground::Paint(gfx::Canvas* canvas, views::View* view) const {
gfx::Rect(0,
view->height() - InfoBarContainerDelegate::kSeparatorLineHeight,
view->width(), InfoBarContainerDelegate::kSeparatorLineHeight),
- separator_color_);
+ separator_color);
+}
+
+void InfoBarBackground::PaintMd(gfx::Canvas* canvas, views::View* view) const {
+ InfoBarView* infobar = static_cast<InfoBarView*>(view);
+ const infobars::InfoBarContainer::Delegate* delegate =
+ infobar->container_delegate();
+ SkPath stroke_path, fill_path;
+ SkColor separator_color = SK_ColorBLACK;
+ if (delegate) {
+ separator_color = delegate->GetInfoBarSeparatorColor();
+ int arrow_x;
+ SkScalar arrow_fill_height =
+ SkIntToScalar(std::max(infobar->arrow_height(), 0));
Peter Kasting 2016/03/30 00:20:26 Can arrow_height() actually return a negative valu
Evan Stade 2016/04/02 02:21:41 I looked into this and can't find anywhere that se
+ if (delegate->DrawInfoBarArrows(&arrow_x) && arrow_fill_height) {
+ SkScalar arrow_fill_half_width =
+ SkIntToScalar(infobar->arrow_half_width());
+ stroke_path.moveTo(SkIntToScalar(arrow_x) - arrow_fill_half_width,
+ SkIntToScalar(infobar->arrow_height()));
+ stroke_path.rLineTo(arrow_fill_half_width, -arrow_fill_height);
+ stroke_path.rLineTo(arrow_fill_half_width, arrow_fill_height);
+
+ fill_path = stroke_path;
+ fill_path.close();
+ }
+ }
+ fill_path.addRect(
+ 0.0, SkIntToScalar(infobar->arrow_height()),
Peter Kasting 2016/03/30 00:20:26 Nit: Unless it fails to compile, I'd use 0 instead
Evan Stade 2016/04/02 02:21:41 Done.
+ SkIntToScalar(infobar->width()),
+ SkIntToScalar(infobar->height() -
+ InfoBarContainerDelegate::kSeparatorLineHeight));
Peter Kasting 2016/03/30 00:20:26 Two issues: (1) In general, I don't think we want
Evan Stade 2016/04/02 02:21:41 ok, good point. Removed usage of this constant in
+
+ 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_);
+
+ 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));
+ fill_path.transform(dsf_transform);
+ fill_path.offset(SK_ScalarHalf, SK_ScalarHalf);
Peter Kasting 2016/03/30 00:20:26 Nit: This deserves an explanation
Evan Stade 2016/04/02 02:21:41 Done.
+ canvas_skia->drawPath(fill_path, fill);
+
+ SkPaint stroke;
+ stroke.setStyle(SkPaint::kStroke_Style);
+ stroke.setStrokeWidth(
+ SkIntToScalar(InfoBarContainerDelegate::kSeparatorLineHeight));
+ stroke.setColor(separator_color);
+ stroke_path.transform(dsf_transform);
+ stroke_path.offset(SK_ScalarHalf, SK_ScalarHalf);
+
+ // Top separator (with arrow shape).
Peter Kasting 2016/03/30 00:20:26 Doesn't this only draw the arrow shape, i.e. there
Evan Stade 2016/04/02 02:21:41 reworded
+ stroke.setAntiAlias(true);
+ canvas_skia->drawPath(stroke_path, stroke);
+ // Bottom separator.
+ stroke.setAntiAlias(false);
Peter Kasting 2016/03/30 00:20:26 Nit: I think this whole bottom section can just be
Evan Stade 2016/04/02 02:21:41 I don't think this is a huge win. We go from 4 lin
+ 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);
}

Powered by Google App Engine
This is Rietveld 408576698