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

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

Issue 11756005: Implement rough new dialog style. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 7 years, 11 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/examples/widget_example.cc » ('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 59a35a6f1691af6654032ab2b18b1e8f5f248d30..c3033c82f662a5a9b431e408c5f935f8816f1977 100644
--- a/ui/views/controls/button/label_button.cc
+++ b/ui/views/controls/button/label_button.cc
@@ -125,6 +125,34 @@ void LabelButton::SetNativeTheme(bool native_theme) {
ResetColorsFromNativeTheme();
}
+gfx::Size LabelButton::GetPreferredSize() {
+ // Resize multi-line labels paired with images to use their available width.
+ const gfx::Size image_size(image_->GetPreferredSize());
+ if (GetTextMultiLine() && !image_size.IsEmpty() && !GetText().empty() &&
+ GetHorizontalAlignment() == gfx::ALIGN_CENTER) {
+ label_->SizeToFit(GetLocalBounds().width() - image_size.width() - kSpacing);
+ }
+
+ // Calculate the required size.
+ gfx::Size size(label_->GetPreferredSize());
+ if (image_size.width() > 0 && size.width() > 0)
+ size.Enlarge(kSpacing, 0);
+ size.set_height(std::max(size.height(), image_size.height()));
+ size.Enlarge(image_size.width() + GetInsets().width(), GetInsets().height());
+
+ // Increase the minimum size monotonically with the preferred size.
+ size.SetSize(std::max(min_size_.width(), size.width()),
+ std::max(min_size_.height(), size.height()));
+ min_size_ = size;
+
+ // Return the largest known size clamped to the maximum size (if valid).
+ if (max_size_.width() > 0)
+ size.set_width(std::min(max_size_.width(), size.width()));
+ if (max_size_.height() > 0)
+ size.set_height(std::min(max_size_.height(), size.height()));
+ return size;
+}
+
void LabelButton::ResetColorsFromNativeTheme() {
const ui::NativeTheme* theme = GetNativeTheme();
SkColor colors[STATE_COUNT] = {
@@ -157,34 +185,6 @@ void LabelButton::StateChanged() {
Layout();
}
-gfx::Size LabelButton::GetPreferredSize() {
- // Resize multi-line labels paired with images to use their available width.
- const gfx::Size image_size(image_->GetPreferredSize());
- if (GetTextMultiLine() && !image_size.IsEmpty() && !GetText().empty() &&
- GetHorizontalAlignment() == gfx::ALIGN_CENTER) {
- label_->SizeToFit(GetLocalBounds().width() - image_size.width() - kSpacing);
- }
-
- // Calculate the required size.
- gfx::Size size(label_->GetPreferredSize());
- if (image_size.width() > 0 && size.width() > 0)
- size.Enlarge(kSpacing, 0);
- size.set_height(std::max(size.height(), image_size.height()));
- size.Enlarge(image_size.width() + GetInsets().width(), GetInsets().height());
-
- // Increase the minimum size monotonically with the preferred size.
- size.SetSize(std::max(min_size_.width(), size.width()),
- std::max(min_size_.height(), size.height()));
- min_size_ = size;
-
- // Return the largest known size clamped to the maximum size (if valid).
- if (max_size_.width() > 0)
- size.set_width(std::min(max_size_.width(), size.width()));
- if (max_size_.height() > 0)
- size.set_height(std::min(max_size_.height(), size.height()));
- return size;
-}
-
void LabelButton::Layout() {
gfx::Rect child_area(GetLocalBounds());
child_area.Inset(GetInsets());
« no previous file with comments | « ui/views/controls/button/label_button.h ('k') | ui/views/examples/widget_example.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698