Commit e040344b authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Chrome OS: improvements to frame avatar icon.

1. Better (more vertically centered) position for hosted app windows.
2. Correct sizing (29x29 instead of crunching to 24x24) for browser and
   hosted app windows. Packaged apps were already using 29x29.
3. Get rid of outline. GetAvatarImageFor{User,Context} already adds a
   white border.

Bug: 901127
Change-Id: I5b0fcb1bcd3266c988e1a62c84b4f8455b53df35
Reviewed-on: https://chromium-review.googlesource.com/c/1313746
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#605006}
parent 125179af
......@@ -82,9 +82,6 @@ constexpr SkColor kIncognitoWindowTitleTextColor = SK_ColorWHITE;
// The indicator for teleported windows has 8 DIPs before and below it.
constexpr int kProfileIndicatorPadding = 8;
// The indicator for teleported windows is 24 DIP on a side.
constexpr int kProfileIndicatorSize = 24;
bool IsV1AppBackButtonEnabled() {
return base::CommandLine::ForCurrentProcess()->HasSwitch(
ash::switches::kAshEnableV1AppBackButton);
......@@ -737,7 +734,7 @@ bool BrowserNonClientFrameViewAsh::ShouldShowCaptionButtons() const {
int BrowserNonClientFrameViewAsh::GetTabStripLeftInset() const {
int left_inset = frame_values().normal_insets.left();
if (profile_indicator_icon_)
left_inset += kProfileIndicatorPadding + kProfileIndicatorSize;
left_inset += kProfileIndicatorPadding + profile_indicator_icon_->width();
return left_inset;
}
......@@ -874,19 +871,22 @@ bool BrowserNonClientFrameViewAsh::ShouldShowProfileIndicatorIcon() const {
void BrowserNonClientFrameViewAsh::UpdateProfileIcons() {
View* root_view = frame()->GetRootView();
if (ShouldShowProfileIndicatorIcon()) {
bool needs_layout = !profile_indicator_icon_;
if (!profile_indicator_icon_) {
profile_indicator_icon_ = new ProfileIndicatorIcon();
AddChildView(profile_indicator_icon_);
if (root_view) {
}
gfx::Image image(
GetAvatarImageForContext(browser_view()->browser()->profile()));
profile_indicator_icon_->SetSize(image.Size());
profile_indicator_icon_->SetIcon(image);
if (needs_layout && root_view) {
// Adding a child does not invalidate the layout.
InvalidateLayout();
root_view->Layout();
}
}
profile_indicator_icon_->SetIcon(gfx::Image(
GetAvatarImageForContext(browser_view()->browser()->profile())));
profile_indicator_icon_->set_stroke_color(GetToolbarTopSeparatorColor());
} else if (profile_indicator_icon_) {
delete profile_indicator_icon_;
profile_indicator_icon_ = nullptr;
......@@ -897,12 +897,15 @@ void BrowserNonClientFrameViewAsh::UpdateProfileIcons() {
void BrowserNonClientFrameViewAsh::LayoutProfileIndicator() {
DCHECK(profile_indicator_icon_);
const int bottom = GetTopInset(false) + browser_view()->GetTabStripHeight() -
kProfileIndicatorPadding;
profile_indicator_icon_->SetBounds(
kProfileIndicatorPadding, bottom - kProfileIndicatorSize,
kProfileIndicatorSize, kProfileIndicatorSize);
const int frame_height =
GetTopInset(false) + browser_view()->GetTabStripHeight();
profile_indicator_icon_->SetPosition(
gfx::Point(kProfileIndicatorPadding,
(frame_height - profile_indicator_icon_->height()) / 2));
profile_indicator_icon_->SetVisible(true);
// The layout size is set along with the image.
DCHECK_LE(profile_indicator_icon_->height(), frame_height);
}
ws::Id BrowserNonClientFrameViewAsh::GetServerWindowId() const {
......
......@@ -45,22 +45,6 @@ void ProfileIndicatorIcon::OnPaint(gfx::Canvas* canvas) {
canvas->DrawImageInt(modified_icon_, 0, 0, modified_icon_.width(),
modified_icon_.height(), dst_x, dst_y, dst_width,
dst_height, false);
if (stroke_color_ == SK_ColorTRANSPARENT)
return;
// Draw a 1px circular stroke (regardless of DSF) around the avatar icon.
const gfx::PointF center((dst_x + dst_width) / 2.0f,
(dst_y + dst_height) / 2.0f);
cc::PaintFlags paint_flags;
paint_flags.setAntiAlias(true);
paint_flags.setStyle(cc::PaintFlags::kStroke_Style);
paint_flags.setColor(stroke_color_);
paint_flags.setStrokeWidth(1.0f / canvas->image_scale());
// Reduce the radius by 0.5f such that the circle overlaps with the edge of
// the image.
const float radius = (dst_width + dst_height) / 4.0f;
canvas->DrawCircle(center, radius - 0.5f, paint_flags);
}
void ProfileIndicatorIcon::SetIcon(const gfx::Image& icon) {
......
......@@ -33,15 +33,10 @@ class ProfileIndicatorIcon : public views::View {
// to Chrome avatar icons, will be resized and modified for the title bar.
void SetIcon(const gfx::Image& icon);
// Sets the color to use for drawing a circular stroke around the icon image.
// Use SK_ColorTRANSPARENT not to draw any stroke.
void set_stroke_color(SkColor color) { stroke_color_ = color; }
private:
gfx::Image base_icon_;
gfx::ImageSkia modified_icon_;
int old_height_ = 0;
SkColor stroke_color_ = SK_ColorTRANSPARENT;
DISALLOW_COPY_AND_ASSIGN(ProfileIndicatorIcon);
};
......
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