Chromium Code Reviews| 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 8e732f7bad715db346865243ac35821ecf4e25e9..82270254dacd1bb51aa9b0f7271afa67f3a531a8 100644 |
| --- a/chrome/browser/ui/views/infobars/infobar_background.cc |
| +++ b/chrome/browser/ui/views/infobars/infobar_background.cc |
| @@ -71,67 +71,56 @@ 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; |
| + |
| + // The arrow part of the top separator. (The rest was drawn by the toolbar or |
| + // the infobar above this one.) |
| + SkPath stroke_path; |
| + // The fill for the arrow |
|
Peter Kasting
2016/07/25 22:21:21
Nit: This comment doesn't seem to add much. I'd p
Evan Stade
2016/07/25 23:16:48
Done.
|
| + SkPath fill_path; |
| SkColor separator_color = SK_ColorBLACK; |
| + gfx::ScopedCanvas scoped(canvas); |
| + // Undo the scale factor so we can stroke with a width of 1px (not 1dp). |
| + const float dsf = canvas->UndoDeviceScaleFactor(); |
| + // Always scale to a whole number to make sure strokes are sharp. |
|
Peter Kasting
2016/07/25 22:21:21
Nit: Can you extend this comment to explain why fl
Bret
2016/07/25 22:35:31
Which method to use to snap to pixels is somewhat
Peter Kasting
2016/07/25 22:38:27
To be clear, I'm fine with any of them (whatever w
Evan Stade
2016/07/25 23:16:48
good question, I didn't give it much thought beyon
|
| + auto scale = [dsf](int dimension) { return std::floor(dimension * dsf); }; |
| + SkScalar arrow_height = scale(infobar->arrow_height()); |
| if (delegate) { |
| separator_color = delegate->GetInfoBarSeparatorColor(); |
| int arrow_x; |
| if (delegate->DrawInfoBarArrows(&arrow_x) && infobar->arrow_height() > 0) { |
| - SkScalar arrow_fill_height = SkIntToScalar(infobar->arrow_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); |
| + SkScalar arrow_half_width = |
| + scale(infobar->arrow_half_width()); |
| + stroke_path.moveTo(scale(arrow_x) - scale(infobar->arrow_half_width()), |
|
Bret
2016/07/25 22:35:31
reuse arrow_half_width
Evan Stade
2016/07/25 23:23:25
Done.
|
| + arrow_height); |
| + stroke_path.rLineTo(arrow_half_width, -arrow_height); |
| + // Make the tip of the arrow sharp. |
| + stroke_path.rLineTo(-1, 0); |
|
Peter Kasting
2016/07/25 22:21:21
I don't understand how this line works. Doesn't t
Evan Stade
2016/07/25 23:16:48
Your ASCII art is accurate, except the way it's re
|
| + stroke_path.rLineTo(arrow_half_width, arrow_height); |
| fill_path = stroke_path; |
| fill_path.close(); |
| } |
| } |
| - fill_path.addRect(0, SkIntToScalar(infobar->arrow_height()), |
| - SkIntToScalar(infobar->width()), |
| - SkIntToScalar(infobar->height())); |
| - |
| - 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); |
| - |
| + fill_path.addRect(0, arrow_height, scale(infobar->width()), |
| + scale(infobar->height())); |
| SkPaint fill; |
| fill.setStyle(SkPaint::kFill_Style); |
| fill.setColor(top_color_); |
| - |
| - SkCanvas* canvas_skia = canvas->sk_canvas(); |
| - // The paths provided by the above calculations are in dp. Manually scale for |
| - // px. |
| - SkMatrix dsf_transform; |
| - dsf_transform.setScale(SkFloatToScalar(scale), SkFloatToScalar(scale)); |
| - fill_path.transform(dsf_transform); |
| - // In order to affect exactly the pixels we want, the fill and stroke paths |
| - // need to go through the pixel centers instead of along the pixel |
| - // edges/corners. Skia considers integral coordinates to be the edges between |
| - // pixels, so offset by 0.5 to get to the centers. |
| - fill_path.offset(SK_ScalarHalf, SK_ScalarHalf); |
| - canvas_skia->drawPath(fill_path, fill); |
| + canvas->DrawPath(fill_path, fill); |
| SkPaint stroke; |
| stroke.setStyle(SkPaint::kStroke_Style); |
| const int kSeparatorThicknessPx = 1; |
| stroke.setStrokeWidth(SkIntToScalar(kSeparatorThicknessPx)); |
|
Bret
2016/07/25 22:35:31
I think the default stroke width is 1px already (w
Evan Stade
2016/07/25 23:23:25
the default is 0 (hairline)
|
| stroke.setColor(separator_color); |
| - stroke_path.transform(dsf_transform); |
| - stroke_path.offset(SK_ScalarHalf, SK_ScalarHalf); |
| - |
| - // The arrow part of the top separator. (The rest was drawn by the toolbar or |
| - // the infobar above this one.) |
| stroke.setAntiAlias(true); |
| - canvas_skia->drawPath(stroke_path, stroke); |
| + canvas->DrawPath(stroke_path, stroke); |
| + |
| // Bottom separator. |
| stroke.setAntiAlias(false); |
| + gfx::SizeF view_size_px = gfx::ScaleSize(gfx::SizeF(view->size()), dsf); |
| SkScalar y = SkIntToScalar(view_size_px.height() - kSeparatorThicknessPx) + |
| SK_ScalarHalf; |
| SkScalar w = SkIntToScalar(view_size_px.width()); |
| - canvas_skia->drawLine(0, y, w, y, stroke); |
| + canvas->sk_canvas()->drawLine(0, y, w, y, stroke); |
| } |