Commit 640bff17 authored by msw@chromium.org's avatar msw@chromium.org

Views: Use the new button style instead of native-styled buttons.

Force STYLE_BUTTON instead of STYLE_NATIVE_TEXTBUTTON.
( easier to revert than replacing all uses, if necessary )
Make STYLE_BUTTON focusable like STYLE_NATIVE_TEXTBUTTON.
Give default STYLE_BUTTON buttons bold text.

Make STYLE_BUTTON buttons big enough for bolded text.
( so they'll fit bold text when made default without resizing )

See before/after pics at http://crbug.com/155363#c62

TODO(followup): Tweak individual buttons' layout as needed.
TODO(followup): Officialy deprecate/remove STYLE_NATIVE_TEXTBUTTON.

BUG=155363
TEST=The new button style appears everywhere as intended.
R=ben@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194673 0039d316-1c4b-4281-b951-d872f2087c98
parent a35f783b
...@@ -120,18 +120,30 @@ void LabelButton::SetIsDefault(bool is_default) { ...@@ -120,18 +120,30 @@ void LabelButton::SetIsDefault(bool is_default) {
is_default_ = is_default; is_default_ = is_default;
ui::Accelerator accel(ui::VKEY_RETURN, ui::EF_NONE); ui::Accelerator accel(ui::VKEY_RETURN, ui::EF_NONE);
is_default_ ? AddAccelerator(accel) : RemoveAccelerator(accel); is_default_ ? AddAccelerator(accel) : RemoveAccelerator(accel);
// STYLE_BUTTON uses bold text to indicate default buttons.
if (style_ == STYLE_BUTTON) {
int style = label_->font().GetStyle();
style = is_default ? style | gfx::Font::BOLD : style & !gfx::Font::BOLD;
label_->SetFont(label_->font().DeriveFont(0, style));
}
} }
void LabelButton::SetStyle(ButtonStyle style) { void LabelButton::SetStyle(ButtonStyle style) {
// Use the new button style instead of the native button style.
// TODO(msw): Officialy deprecate and remove STYLE_NATIVE_TEXTBUTTON.
if (style == STYLE_NATIVE_TEXTBUTTON)
style = STYLE_BUTTON;
style_ = style; style_ = style;
set_border(new LabelButtonBorder(style)); set_border(new LabelButtonBorder(style));
// Inset the button focus rect from the actual border; roughly match Windows. // Inset the button focus rect from the actual border; roughly match Windows.
if (style == STYLE_TEXTBUTTON || style == STYLE_NATIVE_TEXTBUTTON) if (style == STYLE_TEXTBUTTON || style == STYLE_NATIVE_TEXTBUTTON)
set_focus_border(FocusBorder::CreateDashedFocusBorder(3, 3, 3, 3)); set_focus_border(FocusBorder::CreateDashedFocusBorder(3, 3, 3, 3));
if (style == STYLE_BUTTON || style == STYLE_NATIVE_TEXTBUTTON) if (style == STYLE_BUTTON || style == STYLE_NATIVE_TEXTBUTTON) {
label_->SetHorizontalAlignment(gfx::ALIGN_CENTER); label_->SetHorizontalAlignment(gfx::ALIGN_CENTER);
if (style == STYLE_NATIVE_TEXTBUTTON)
set_focusable(true); set_focusable(true);
}
if (style == STYLE_BUTTON) { if (style == STYLE_BUTTON) {
set_min_size(gfx::Size(70, 31)); set_min_size(gfx::Size(70, 31));
const SkColor color = GetNativeTheme()->GetSystemColor( const SkColor color = GetNativeTheme()->GetSystemColor(
...@@ -145,6 +157,11 @@ void LabelButton::SetStyle(ButtonStyle style) { ...@@ -145,6 +157,11 @@ void LabelButton::SetStyle(ButtonStyle style) {
} }
gfx::Size LabelButton::GetPreferredSize() { gfx::Size LabelButton::GetPreferredSize() {
// Accommodate bold text in case this STYLE_BUTTON button is made default.
const gfx::Font font = label_->font();
if (style_ == STYLE_BUTTON)
label_->SetFont(font.DeriveFont(0, font.GetStyle() | gfx::Font::BOLD));
// Resize multi-line labels paired with images to use their available width. // Resize multi-line labels paired with images to use their available width.
const gfx::Size image_size(image_->GetPreferredSize()); const gfx::Size image_size(image_->GetPreferredSize());
if (GetTextMultiLine() && !image_size.IsEmpty() && !GetText().empty() && if (GetTextMultiLine() && !image_size.IsEmpty() && !GetText().empty() &&
...@@ -159,6 +176,10 @@ gfx::Size LabelButton::GetPreferredSize() { ...@@ -159,6 +176,10 @@ gfx::Size LabelButton::GetPreferredSize() {
size.set_height(std::max(size.height(), image_size.height())); size.set_height(std::max(size.height(), image_size.height()));
size.Enlarge(image_size.width() + GetInsets().width(), GetInsets().height()); size.Enlarge(image_size.width() + GetInsets().width(), GetInsets().height());
// Restore the label's original font without the temporary bold style.
if (style_ == STYLE_BUTTON)
label_->SetFont(font);
// Increase the minimum size monotonically with the preferred size. // Increase the minimum size monotonically with the preferred size.
size.SetSize(std::max(min_size_.width(), size.width()), size.SetSize(std::max(min_size_.width(), size.width()),
std::max(min_size_.height(), size.height())); std::max(min_size_.height(), size.height()));
......
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