Commit 4d78709a authored by Dana Fried's avatar Dana Fried Committed by Commit Bot

Adjust avatar profile size to avoid DIP rounding issues.

This is a local fix to the larger problem of scaled bitmaps rendered in
ImageViews at non-integral DIP scaling factors (125%, 133%, 175%, etc.)

It solves the specific bug, but does not solve the larger problem of the
ways we scale bitmaps and Views canvases being sometimes different.

More info is available on the issue cited.

I am looking for feedback - if this is an acceptable fix for right now
or if we should drive towards a more comprehensive approach.

Probably both.

Bug: 1094566
Change-Id: I024e216542cee057cd4198a5a65344ffa0cd999d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2306751Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
Commit-Queue: Dana Fried <dfried@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791060}
parent e6ffd1a6
......@@ -102,6 +102,26 @@ void AvatarToolbarButton::UpdateIcon() {
SetInsets();
}
void AvatarToolbarButton::Layout() {
ToolbarButton::Layout();
// TODO(crbug.com/1094566): this is a hack to avoid mismatch between avatar
// bitmap scaling and DIP->canvas pixel scaling in fractional DIP scaling
// modes (125%, 133%, etc.) that can cause the right-hand or bottom pixel row
// of the avatar image to be sliced off at certain specific browser sizes and
// configurations.
//
// In order to solve this, we increase the width and height of the image by 1
// after layout, so the rest of the layout is before. Since the profile image
// uses transparency, visually this does not cause any change in cases where
// the bug doesn't manifest.
image()->SetHorizontalAlignment(views::ImageView::Alignment::kLeading);
image()->SetVerticalAlignment(views::ImageView::Alignment::kLeading);
gfx::Size image_size = image()->GetImage().size();
image_size.Enlarge(1, 1);
image()->SetSize(image_size);
}
void AvatarToolbarButton::UpdateText() {
base::Optional<SkColor> color;
base::string16 text;
......
......@@ -59,6 +59,7 @@ class AvatarToolbarButton : public ToolbarButton,
void OnBlur() override;
void OnThemeChanged() override;
void UpdateIcon() override;
void Layout() override;
// ToolbarIconContainerView::Observer:
void OnHighlightChanged() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment