| 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..5e62559bd3b8aa757c3b9f5c5fa5cc70157511ed 100644
|
| --- a/chrome/browser/ui/views/infobars/infobar_background.cc
|
| +++ b/chrome/browser/ui/views/infobars/infobar_background.cc
|
| @@ -73,65 +73,61 @@ void InfoBarBackground::PaintMd(gfx::Canvas* canvas, views::View* view) const {
|
| infobar->container_delegate();
|
| SkPath stroke_path, 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.
|
| + // For some fractional DSFs, view size rounding issues may cause there to be a
|
| + // gap above the infobar (below the horizontal stroke painted by the previous
|
| + // infobar or the toolbar). We use floor here to "pull" the fill region up a
|
| + // pixel and bridge the gap. Sometimes this will be 1px too high, so we also
|
| + // re-draw the horizontal portions of the top separator in case this floor
|
| + // operation has covered it up. For whole-number DSFs, the floor should have
|
| + // no effect.
|
| + auto scale = [dsf](int dimension) { return std::floor(dimension * dsf); };
|
| + SkScalar arrow_height = scale(infobar->arrow_height());
|
| + SkScalar infobar_width = scale(infobar->width());
|
| 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);
|
| + // Compensate for the fact that a relative movement of n creates a line of
|
| + // length n + 1 once the path is placed on pixel centers and stroked.
|
| + SkScalar r_arrow_half_width = scale(infobar->arrow_half_width()) - 1;
|
| + SkScalar r_arrow_height = arrow_height - 1;
|
| + SkScalar arrow_tip_x = scale(arrow_x);
|
| + stroke_path.moveTo(0, r_arrow_height);
|
| + stroke_path.lineTo(arrow_tip_x - r_arrow_half_width, r_arrow_height);
|
| + stroke_path.lineTo(arrow_tip_x, 0);
|
| + stroke_path.lineTo(arrow_tip_x + r_arrow_half_width, r_arrow_height);
|
| + stroke_path.lineTo(infobar_width - 1, r_arrow_height);
|
| +
|
| + // Add SK_ScalarHalf to both axes to place the path on pixel centers.
|
| + stroke_path.offset(SK_ScalarHalf, SK_ScalarHalf);
|
|
|
| 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, 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));
|
| 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);
|
| + SkScalar w = SkFloatToScalar(view_size_px.width());
|
| + canvas->sk_canvas()->drawLine(0, y, w, y, stroke);
|
| }
|
|
|