| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ui/views/controls/button/label_button.h" | 5 #include "ui/views/controls/button/label_button.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
| 9 #include "ui/base/animation/throb_animation.h" | 9 #include "ui/base/animation/throb_animation.h" |
| 10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 void LabelButton::SetDefaultButton(bool default_button) { | 112 void LabelButton::SetDefaultButton(bool default_button) { |
| 113 if (default_button == default_button_) | 113 if (default_button == default_button_) |
| 114 return; | 114 return; |
| 115 default_button_ = default_button; | 115 default_button_ = default_button; |
| 116 ui::Accelerator accel(ui::VKEY_RETURN, ui::EF_NONE); | 116 ui::Accelerator accel(ui::VKEY_RETURN, ui::EF_NONE); |
| 117 default_button_ ? AddAccelerator(accel) : RemoveAccelerator(accel); | 117 default_button_ ? AddAccelerator(accel) : RemoveAccelerator(accel); |
| 118 } | 118 } |
| 119 | 119 |
| 120 void LabelButton::SetNativeTheme(bool native_theme) { | 120 void LabelButton::SetNativeTheme(bool native_theme) { |
| 121 native_theme_ = native_theme; | 121 native_theme_ = native_theme; |
| 122 static_cast<LabelButtonBorder*>(border())->set_native_theme(native_theme); | 122 LabelButtonBorder* border = new LabelButtonBorder(); |
| 123 border->set_native_theme(native_theme); |
| 124 set_border(border); |
| 123 // Invalidate the layout to pickup the new insets from the border. | 125 // Invalidate the layout to pickup the new insets from the border. |
| 124 InvalidateLayout(); | 126 InvalidateLayout(); |
| 125 ResetColorsFromNativeTheme(); | 127 ResetColorsFromNativeTheme(); |
| 126 } | 128 } |
| 127 | 129 |
| 128 gfx::Size LabelButton::GetPreferredSize() { | 130 gfx::Size LabelButton::GetPreferredSize() { |
| 129 // Resize multi-line labels paired with images to use their available width. | 131 // Resize multi-line labels paired with images to use their available width. |
| 130 const gfx::Size image_size(image_->GetPreferredSize()); | 132 const gfx::Size image_size(image_->GetPreferredSize()); |
| 131 if (GetTextMultiLine() && !image_size.IsEmpty() && !GetText().empty() && | 133 if (GetTextMultiLine() && !image_size.IsEmpty() && !GetText().empty() && |
| 132 GetHorizontalAlignment() == gfx::ALIGN_CENTER) { | 134 GetHorizontalAlignment() == gfx::ALIGN_CENTER) { |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 | 193 |
| 192 gfx::Size image_size(image_->GetPreferredSize()); | 194 gfx::Size image_size(image_->GetPreferredSize()); |
| 193 image_size.set_width(std::min(image_size.width(), child_area.width())); | 195 image_size.set_width(std::min(image_size.width(), child_area.width())); |
| 194 image_size.set_height(std::min(image_size.height(), child_area.height())); | 196 image_size.set_height(std::min(image_size.height(), child_area.height())); |
| 195 | 197 |
| 196 // The label takes any remaining width after sizing the image, unless both | 198 // The label takes any remaining width after sizing the image, unless both |
| 197 // views are centered. In that case, using the tighter preferred label width | 199 // views are centered. In that case, using the tighter preferred label width |
| 198 // avoids wasted space within the label that would look like awkward padding. | 200 // avoids wasted space within the label that would look like awkward padding. |
| 199 gfx::Size label_size(child_area.size()); | 201 gfx::Size label_size(child_area.size()); |
| 200 if (!image_size.IsEmpty() && !label_size.IsEmpty()) { | 202 if (!image_size.IsEmpty() && !label_size.IsEmpty()) { |
| 201 label_size.set_width(child_area.width() - image_size.width() - kSpacing); | 203 label_size.set_width( |
| 204 std::max(child_area.width() - image_size.width() - kSpacing, 0)); |
| 202 if (GetHorizontalAlignment() == gfx::ALIGN_CENTER) { | 205 if (GetHorizontalAlignment() == gfx::ALIGN_CENTER) { |
| 203 // Ensure multi-line labels paired with images use their available width. | 206 // Ensure multi-line labels paired with images use their available width. |
| 204 if (GetTextMultiLine()) | 207 if (GetTextMultiLine()) |
| 205 label_->SizeToFit(label_size.width()); | 208 label_->SizeToFit(label_size.width()); |
| 206 label_size.set_width( | 209 label_size.set_width( |
| 207 std::min(label_size.width(), label_->GetPreferredSize().width())); | 210 std::min(label_size.width(), label_->GetPreferredSize().width())); |
| 208 } | 211 } |
| 209 } | 212 } |
| 210 | 213 |
| 211 gfx::Point image_origin(child_area.origin()); | 214 gfx::Point image_origin(child_area.origin()); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 params->button.indeterminate = false; | 289 params->button.indeterminate = false; |
| 287 params->button.is_default = default_button(); | 290 params->button.is_default = default_button(); |
| 288 params->button.is_focused = HasFocus() && IsAccessibilityFocusable(); | 291 params->button.is_focused = HasFocus() && IsAccessibilityFocusable(); |
| 289 params->button.has_border = native_theme(); | 292 params->button.has_border = native_theme(); |
| 290 params->button.classic_state = 0; | 293 params->button.classic_state = 0; |
| 291 params->button.background_color = GetNativeTheme()->GetSystemColor( | 294 params->button.background_color = GetNativeTheme()->GetSystemColor( |
| 292 ui::NativeTheme::kColorId_TextButtonBackgroundColor); | 295 ui::NativeTheme::kColorId_TextButtonBackgroundColor); |
| 293 } | 296 } |
| 294 | 297 |
| 295 } // namespace views | 298 } // namespace views |
| OLD | NEW |