Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Unified Diff: ui/views/controls/button/label_button.cc

Issue 23228004: Prepare to use gfx::RenderText in views::Label. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Revert Label implementation changes. Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/views/controls/button/label_button.h ('k') | ui/views/controls/label.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/button/label_button.cc
diff --git a/ui/views/controls/button/label_button.cc b/ui/views/controls/button/label_button.cc
index fa358c1c9d3d78e5370eb7be9573ac91cc8c9dfb..5ee97918dc9f794c1d1189ffa3e570449e6c16f7 100644
--- a/ui/views/controls/button/label_button.cc
+++ b/ui/views/controls/button/label_button.cc
@@ -101,15 +101,15 @@ void LabelButton::SetTextColor(ButtonState for_state, SkColor color) {
}
void LabelButton::SetTextShadows(const gfx::ShadowValues& shadows) {
- label_->set_shadows(shadows);
+ label_->SetShadows(shadows);
}
void LabelButton::SetTextSubpixelRenderingEnabled(bool enabled) {
- label_->set_subpixel_rendering_enabled(enabled);
+ label_->SetSubpixelRenderingEnabled(enabled);
}
bool LabelButton::GetTextMultiLine() const {
- return label_->is_multi_line();
+ return label_->multi_line();
}
void LabelButton::SetTextMultiLine(bool text_multi_line) {
@@ -144,10 +144,6 @@ void LabelButton::SetHorizontalAlignment(gfx::HorizontalAlignment alignment) {
InvalidateLayout();
}
-void LabelButton::SetDirectionalityMode(gfx::DirectionalityMode mode) {
- label_->set_directionality_mode(mode);
-}
-
void LabelButton::SetIsDefault(bool is_default) {
if (is_default == is_default_)
return;
@@ -188,7 +184,7 @@ void LabelButton::SetFocusPainter(scoped_ptr<Painter> focus_painter) {
gfx::Size LabelButton::GetPreferredSize() const {
// Use a temporary label copy for sizing to avoid calculation side-effects.
Label label(GetText(), cached_normal_font_list_);
- label.set_shadows(label_->shadows());
+ label.SetShadows(label_->shadows());
label.SetMultiLine(GetTextMultiLine());
if (style() == STYLE_BUTTON) {
@@ -200,15 +196,10 @@ gfx::Size LabelButton::GetPreferredSize() const {
label.SetFontList(cached_normal_font_list_);
}
- // Resize multi-line labels given the current limited available width.
- const gfx::Size image_size(image_->GetPreferredSize());
- const int image_width = image_size.width();
- if (GetTextMultiLine() && (width() > image_width + kSpacing))
- label.SizeToFit(width() - image_width - (image_width > 0 ? kSpacing : 0));
-
// Calculate the required size.
+ const gfx::Size image_size(image_->GetPreferredSize());
gfx::Size size(label.GetPreferredSize());
- if (image_width > 0 && size.width() > 0)
+ if (image_size.width() > 0 && size.width() > 0)
size.Enlarge(kSpacing, 0);
size.SetToMax(gfx::Size(0, image_size.height()));
const gfx::Insets insets(GetInsets());
@@ -229,6 +220,23 @@ gfx::Size LabelButton::GetPreferredSize() const {
return size;
}
+int LabelButton::GetHeightForWidth(int w) const {
+ w -= GetInsets().width();
+ const gfx::Size image_size(image_->GetPreferredSize());
+ w -= image_size.width();
+ if (image_size.width() > 0 && !GetText().empty())
+ w -= kSpacing;
+
+ int height = std::max(image_size.height(), label_->GetHeightForWidth(w));
+ if (border())
+ height = std::max(height, border()->GetMinimumSize().height());
+
+ height = std::max(height, min_size_.height());
+ if (max_size_.height() > 0)
+ height = std::min(height, max_size_.height());
+ return height;
+}
+
void LabelButton::Layout() {
gfx::HorizontalAlignment adjusted_alignment = GetHorizontalAlignment();
if (base::i18n::IsRTL() && adjusted_alignment != gfx::ALIGN_CENTER)
@@ -250,8 +258,6 @@ void LabelButton::Layout() {
std::max(child_area.width() - image_size.width() - kSpacing, 0));
if (adjusted_alignment == gfx::ALIGN_CENTER) {
// Ensure multi-line labels paired with images use their available width.
- if (GetTextMultiLine())
- label_->SizeToFit(label_size.width());
label_size.set_width(
std::min(label_size.width(), label_->GetPreferredSize().width()));
}
@@ -337,7 +343,7 @@ void LabelButton::ResetColorsFromNativeTheme() {
label_->SetBackgroundColor(SK_ColorBLACK);
label_->set_background(Background::CreateSolidBackground(SK_ColorBLACK));
label_->SetAutoColorReadabilityEnabled(true);
- label_->set_shadows(gfx::ShadowValues());
+ label_->SetShadows(gfx::ShadowValues());
} else if (style() == STYLE_BUTTON) {
// TODO(erg): This is disabled on desktop linux because of the binary asset
// confusion. These details should either be pushed into ui::NativeThemeWin
@@ -349,8 +355,8 @@ void LabelButton::ResetColorsFromNativeTheme() {
label_->SetBackgroundColor(theme->GetSystemColor(
ui::NativeTheme::kColorId_ButtonBackgroundColor));
label_->SetAutoColorReadabilityEnabled(false);
- label_->set_shadows(gfx::ShadowValues(1,
- gfx::ShadowValue(gfx::Point(0, 1), 0, kStyleButtonShadowColor)));
+ label_->SetShadows(gfx::ShadowValues(
+ 1, gfx::ShadowValue(gfx::Point(0, 1), 0, kStyleButtonShadowColor)));
#endif
label_->set_background(NULL);
} else {
« no previous file with comments | « ui/views/controls/button/label_button.h ('k') | ui/views/controls/label.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698