Commit 1f18c487 authored by msw@chromium.org's avatar msw@chromium.org

Fix new avatar button appearance regressions.

Fix the NewAvatarButton's border inset values.
Replace the halo color with shadowing.
Disable subpixel rendering for the button text.
Use the default alignment (left) instead of right.

Add LabelButton text shadow and subpixel setters.
Apply label shadows in LabelButton::GetPreferredSize.
Invalidate the Label size when shadows are set.
Apply the shadow margins in Label text sizing.

Remove unused Label halo code; update the example.

See pics from before the regression and after this CL:
http://crbug.com/155363#c111

BUG=155363
TEST=New Avatar button looks good.
R=noms@chromium.org,sky@chromium.org

Review URL: https://codereview.chromium.org/343853002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@278432 0039d316-1c4b-4281-b951-d872f2087c98
parent f63a8db7
...@@ -27,10 +27,6 @@ ...@@ -27,10 +27,6 @@
namespace { namespace {
// Text padding within the button border.
const int kLeftRightInset = 7;
const int kTopBottomInset = 2;
scoped_ptr<views::Border> CreateBorder(const int normal_image_set[], scoped_ptr<views::Border> CreateBorder(const int normal_image_set[],
const int hot_image_set[], const int hot_image_set[],
const int pushed_image_set[]) { const int pushed_image_set[]) {
...@@ -44,8 +40,11 @@ scoped_ptr<views::Border> CreateBorder(const int normal_image_set[], ...@@ -44,8 +40,11 @@ scoped_ptr<views::Border> CreateBorder(const int normal_image_set[],
border->SetPainter(false, views::Button::STATE_PRESSED, border->SetPainter(false, views::Button::STATE_PRESSED,
views::Painter::CreateImageGridPainter(pushed_image_set)); views::Painter::CreateImageGridPainter(pushed_image_set));
border->set_insets(gfx::Insets(kTopBottomInset, kLeftRightInset, const int kLeftRightInset = 10;
kTopBottomInset, kLeftRightInset)); const int kTopInset = 0;
const int kBottomInset = 4;
border->set_insets(gfx::Insets(kTopInset, kLeftRightInset,
kBottomInset, kLeftRightInset));
return border.PassAs<views::Border>(); return border.PassAs<views::Border>();
} }
...@@ -80,16 +79,11 @@ NewAvatarButton::NewAvatarButton( ...@@ -80,16 +79,11 @@ NewAvatarButton::NewAvatarButton(
SetTextColor(views::Button::STATE_NORMAL, SK_ColorWHITE); SetTextColor(views::Button::STATE_NORMAL, SK_ColorWHITE);
SetTextColor(views::Button::STATE_HOVERED, SK_ColorWHITE); SetTextColor(views::Button::STATE_HOVERED, SK_ColorWHITE);
SetTextColor(views::Button::STATE_PRESSED, SK_ColorWHITE); SetTextColor(views::Button::STATE_PRESSED, SK_ColorWHITE);
SetHaloColor(SK_ColorDKGRAY); SetTextShadows(gfx::ShadowValues(10,
SetHorizontalAlignment(gfx::ALIGN_RIGHT); gfx::ShadowValue(gfx::Point(), 1.0f, SK_ColorDKGRAY)));
SetTextSubpixelRenderingEnabled(false);
ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
bool is_win8 = false;
#if defined(OS_WIN)
is_win8 = base::win::GetVersion() >= base::win::VERSION_WIN8;
#endif
if (button_style == THEMED_BUTTON) { if (button_style == THEMED_BUTTON) {
const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL); const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_NORMAL);
const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER); const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_THEMED_BUTTON_HOVER);
...@@ -98,7 +92,8 @@ NewAvatarButton::NewAvatarButton( ...@@ -98,7 +92,8 @@ NewAvatarButton::NewAvatarButton(
SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet));
set_menu_marker( set_menu_marker(
rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_DROPARROW).ToImageSkia()); rb->GetImageNamed(IDR_AVATAR_THEMED_BUTTON_DROPARROW).ToImageSkia());
} else if (is_win8) { #if defined(OS_WIN)
} else if (base::win::GetVersion() >= base::win::VERSION_WIN8) {
const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_NORMAL); const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_NORMAL);
const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_HOVER); const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_HOVER);
const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_PRESSED); const int kPushedImageSet[] = IMAGE_GRID(IDR_AVATAR_METRO_BUTTON_PRESSED);
...@@ -106,6 +101,7 @@ NewAvatarButton::NewAvatarButton( ...@@ -106,6 +101,7 @@ NewAvatarButton::NewAvatarButton(
SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet)); SetBorder(CreateBorder(kNormalImageSet, kHotImageSet, kPushedImageSet));
set_menu_marker( set_menu_marker(
rb->GetImageNamed(IDR_AVATAR_METRO_BUTTON_DROPARROW).ToImageSkia()); rb->GetImageNamed(IDR_AVATAR_METRO_BUTTON_DROPARROW).ToImageSkia());
#endif
} else { } else {
const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL); const int kNormalImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_NORMAL);
const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER); const int kHotImageSet[] = IMAGE_GRID(IDR_AVATAR_GLASS_BUTTON_HOVER);
...@@ -118,9 +114,8 @@ NewAvatarButton::NewAvatarButton( ...@@ -118,9 +114,8 @@ NewAvatarButton::NewAvatarButton(
g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this); g_browser_process->profile_manager()->GetProfileInfoCache().AddObserver(this);
// Subscribe to authentication error changes so that the avatar button // Subscribe to authentication error changes so that the avatar button can
// can update itself. Note that guest mode profiles won't have a token // update itself. Note that guest mode profiles won't have a token service.
// service.
SigninErrorController* error = SigninErrorController* error =
profiles::GetSigninErrorController(browser_->profile()); profiles::GetSigninErrorController(browser_->profile());
if (error) { if (error) {
......
...@@ -100,8 +100,12 @@ void LabelButton::SetTextColor(ButtonState for_state, SkColor color) { ...@@ -100,8 +100,12 @@ void LabelButton::SetTextColor(ButtonState for_state, SkColor color) {
explicitly_set_colors_[for_state] = true; explicitly_set_colors_[for_state] = true;
} }
void LabelButton::SetHaloColor(SkColor color) { void LabelButton::SetTextShadows(const gfx::ShadowValues& shadows) {
label_->set_halo_color(color); label_->set_shadows(shadows);
}
void LabelButton::SetTextSubpixelRenderingEnabled(bool enabled) {
label_->set_subpixel_rendering_enabled(enabled);
} }
bool LabelButton::GetTextMultiLine() const { bool LabelButton::GetTextMultiLine() const {
...@@ -180,6 +184,7 @@ void LabelButton::SetFocusPainter(scoped_ptr<Painter> focus_painter) { ...@@ -180,6 +184,7 @@ void LabelButton::SetFocusPainter(scoped_ptr<Painter> focus_painter) {
gfx::Size LabelButton::GetPreferredSize() const { gfx::Size LabelButton::GetPreferredSize() const {
// Use a temporary label copy for sizing to avoid calculation side-effects. // Use a temporary label copy for sizing to avoid calculation side-effects.
Label label(GetText(), cached_normal_font_list_); Label label(GetText(), cached_normal_font_list_);
label.set_shadows(label_->shadows());
label.SetMultiLine(GetTextMultiLine()); label.SetMultiLine(GetTextMultiLine());
if (style() == STYLE_BUTTON) { if (style() == STYLE_BUTTON) {
...@@ -259,7 +264,7 @@ void LabelButton::Layout() { ...@@ -259,7 +264,7 @@ void LabelButton::Layout() {
} }
gfx::Point label_origin(child_area.origin()); gfx::Point label_origin(child_area.origin());
if (!image_size.IsEmpty() &&adjusted_alignment != gfx::ALIGN_RIGHT) if (!image_size.IsEmpty() && adjusted_alignment != gfx::ALIGN_RIGHT)
label_origin.set_x(image_origin.x() + image_size.width() + kSpacing); label_origin.set_x(image_origin.x() + image_size.width() + kSpacing);
image_->SetBoundsRect(gfx::Rect(image_origin, image_size)); image_->SetBoundsRect(gfx::Rect(image_origin, image_size));
......
...@@ -43,8 +43,11 @@ class VIEWS_EXPORT LabelButton : public CustomButton, ...@@ -43,8 +43,11 @@ class VIEWS_EXPORT LabelButton : public CustomButton,
// Set the text color shown for the specified button state. // Set the text color shown for the specified button state.
void SetTextColor(ButtonState for_state, SkColor color); void SetTextColor(ButtonState for_state, SkColor color);
// Sets a halo color on the label. // Set drop shadows underneath the text.
void SetHaloColor(SkColor color); void SetTextShadows(const gfx::ShadowValues& shadows);
// Sets whether subpixel rendering is used on the label.
void SetTextSubpixelRenderingEnabled(bool enabled);
// Get or set the text's multi-line property to break on '\n', etc. // Get or set the text's multi-line property to break on '\n', etc.
bool GetTextMultiLine() const; bool GetTextMultiLine() const;
......
...@@ -321,11 +321,6 @@ void Label::PaintText(gfx::Canvas* canvas, ...@@ -321,11 +321,6 @@ void Label::PaintText(gfx::Canvas* canvas,
} else { } else {
canvas->DrawStringRectWithShadows(text, font_list_, color, text_bounds, canvas->DrawStringRectWithShadows(text, font_list_, color, text_bounds,
line_height_, flags, shadows_); line_height_, flags, shadows_);
if (SkColorGetA(halo_color_) != SK_AlphaTRANSPARENT) {
canvas->DrawStringRectWithHalo(text, font_list_, color, halo_color_,
text_bounds, flags);
}
} }
if (HasFocus()) { if (HasFocus()) {
...@@ -352,6 +347,8 @@ gfx::Size Label::GetTextSize() const { ...@@ -352,6 +347,8 @@ gfx::Size Label::GetTextSize() const {
gfx::Canvas::SizeStringInt( gfx::Canvas::SizeStringInt(
layout_text(), font_list_, &w, &h, line_height_, flags); layout_text(), font_list_, &w, &h, line_height_, flags);
text_size_.SetSize(w, h); text_size_.SetSize(w, h);
const gfx::Insets shadow_margin = -gfx::ShadowValue::GetMargin(shadows_);
text_size_.Enlarge(shadow_margin.width(), shadow_margin.height());
text_size_valid_ = true; text_size_valid_ = true;
} }
...@@ -394,7 +391,6 @@ void Label::Init(const base::string16& text, const gfx::FontList& font_list) { ...@@ -394,7 +391,6 @@ void Label::Init(const base::string16& text, const gfx::FontList& font_list) {
elide_behavior_ = gfx::ELIDE_TAIL; elide_behavior_ = gfx::ELIDE_TAIL;
collapse_when_hidden_ = false; collapse_when_hidden_ = false;
directionality_mode_ = gfx::DIRECTIONALITY_FROM_UI; directionality_mode_ = gfx::DIRECTIONALITY_FROM_UI;
halo_color_ = SK_ColorTRANSPARENT;
cached_heights_.resize(kCachedSizeLimit); cached_heights_.resize(kCachedSizeLimit);
ResetCachedSize(); ResetCachedSize();
......
...@@ -60,7 +60,11 @@ class VIEWS_EXPORT Label : public View { ...@@ -60,7 +60,11 @@ class VIEWS_EXPORT Label : public View {
SkColor background_color() const { return background_color_; } SkColor background_color() const { return background_color_; }
// Set drop shadows underneath the text. // Set drop shadows underneath the text.
void set_shadows(const gfx::ShadowValues& shadows) { shadows_ = shadows; } void set_shadows(const gfx::ShadowValues& shadows) {
shadows_ = shadows;
text_size_valid_ = false;
}
const gfx::ShadowValues& shadows() const { return shadows_; }
// Sets whether subpixel rendering is used; the default is true, but this // Sets whether subpixel rendering is used; the default is true, but this
// feature also requires an opaque background color. // feature also requires an opaque background color.
...@@ -68,9 +72,6 @@ class VIEWS_EXPORT Label : public View { ...@@ -68,9 +72,6 @@ class VIEWS_EXPORT Label : public View {
subpixel_rendering_enabled_ = subpixel_rendering_enabled; subpixel_rendering_enabled_ = subpixel_rendering_enabled;
} }
// Set the color of a halo on the painted text (use transparent for none).
void set_halo_color(SkColor halo_color) { halo_color_ = halo_color; }
// Sets the horizontal alignment; the argument value is mirrored in RTL UI. // Sets the horizontal alignment; the argument value is mirrored in RTL UI.
void SetHorizontalAlignment(gfx::HorizontalAlignment alignment); void SetHorizontalAlignment(gfx::HorizontalAlignment alignment);
gfx::HorizontalAlignment GetHorizontalAlignment() const; gfx::HorizontalAlignment GetHorizontalAlignment() const;
...@@ -242,9 +243,6 @@ class VIEWS_EXPORT Label : public View { ...@@ -242,9 +243,6 @@ class VIEWS_EXPORT Label : public View {
gfx::DirectionalityMode directionality_mode_; gfx::DirectionalityMode directionality_mode_;
gfx::ShadowValues shadows_; gfx::ShadowValues shadows_;
// The halo color drawn around the text if it is not transparent.
SkColor halo_color_;
// The cached heights to avoid recalculation in GetHeightForWidth(). // The cached heights to avoid recalculation in GetHeightForWidth().
mutable std::vector<gfx::Size> cached_heights_; mutable std::vector<gfx::Size> cached_heights_;
mutable int cached_heights_cursor_; mutable int cached_heights_cursor_;
......
...@@ -62,11 +62,12 @@ void LabelExample::CreateExampleView(View* container) { ...@@ -62,11 +62,12 @@ void LabelExample::CreateExampleView(View* container) {
label->SetEnabledColor(SK_ColorBLUE); label->SetEnabledColor(SK_ColorBLUE);
container->AddChildView(label); container->AddChildView(label);
label = new Label(ASCIIToUTF16("A Courier-18 label with a halo and shadow.")); label = new Label(ASCIIToUTF16("A Courier-18 label with shadows."));
label->SetFontList(gfx::FontList("Courier, 18px")); label->SetFontList(gfx::FontList("Courier, 18px"));
label->set_shadows(gfx::ShadowValues(1, gfx::ShadowValues shadows(1, gfx::ShadowValue(gfx::Point(), 1, SK_ColorRED));
gfx::ShadowValue(gfx::Point(2, 2), 0, SK_ColorGRAY))); gfx::ShadowValue shadow(gfx::Point(2, 2), 0, SK_ColorGRAY);
label->set_halo_color(SK_ColorGREEN); shadows.push_back(shadow);
label->set_shadows(shadows);
container->AddChildView(label); container->AddChildView(label);
label = new PreferredSizeLabel(); label = new PreferredSizeLabel();
......
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