| 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/resource/resource_bundle.h" | 9 #include "ui/base/resource/resource_bundle.h" |
| 10 #include "ui/gfx/animation/throb_animation.h" | 10 #include "ui/gfx/animation/throb_animation.h" |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 | 262 |
| 263 gfx::Rect child_area(GetChildAreaBounds()); | 263 gfx::Rect child_area(GetChildAreaBounds()); |
| 264 child_area.Inset(GetInsets()); | 264 child_area.Inset(GetInsets()); |
| 265 | 265 |
| 266 gfx::Size image_size(image_->GetPreferredSize()); | 266 gfx::Size image_size(image_->GetPreferredSize()); |
| 267 image_size.SetToMin(child_area.size()); | 267 image_size.SetToMin(child_area.size()); |
| 268 | 268 |
| 269 // The label takes any remaining width after sizing the image, unless both | 269 // The label takes any remaining width after sizing the image, unless both |
| 270 // views are centered. In that case, using the tighter preferred label width | 270 // views are centered. In that case, using the tighter preferred label width |
| 271 // avoids wasted space within the label that would look like awkward padding. | 271 // avoids wasted space within the label that would look like awkward padding. |
| 272 gfx::Size label_size(child_area.size()); | 272 // Labels can paint over the full button height, including the border height. |
| 273 gfx::Size label_size(child_area.width(), height()); |
| 273 if (!image_size.IsEmpty() && !label_size.IsEmpty()) { | 274 if (!image_size.IsEmpty() && !label_size.IsEmpty()) { |
| 274 label_size.set_width( | 275 label_size.set_width( |
| 275 std::max(child_area.width() - image_size.width() - kSpacing, 0)); | 276 std::max(child_area.width() - image_size.width() - kSpacing, 0)); |
| 276 if (adjusted_alignment == gfx::ALIGN_CENTER) { | 277 if (adjusted_alignment == gfx::ALIGN_CENTER) { |
| 277 // Ensure multi-line labels paired with images use their available width. | 278 // Ensure multi-line labels paired with images use their available width. |
| 278 label_size.set_width( | 279 label_size.set_width( |
| 279 std::min(label_size.width(), label_->GetPreferredSize().width())); | 280 std::min(label_size.width(), label_->GetPreferredSize().width())); |
| 280 } | 281 } |
| 281 } | 282 } |
| 282 | 283 |
| 283 gfx::Point image_origin(child_area.origin()); | 284 gfx::Point image_origin(child_area.origin()); |
| 284 image_origin.Offset(0, (child_area.height() - image_size.height()) / 2); | 285 image_origin.Offset(0, (child_area.height() - image_size.height()) / 2); |
| 285 if (adjusted_alignment == gfx::ALIGN_CENTER) { | 286 if (adjusted_alignment == gfx::ALIGN_CENTER) { |
| 286 const int total_width = image_size.width() + label_size.width() + | 287 const int total_width = image_size.width() + label_size.width() + |
| 287 ((image_size.width() > 0 && label_size.width() > 0) ? kSpacing : 0); | 288 ((image_size.width() > 0 && label_size.width() > 0) ? kSpacing : 0); |
| 288 image_origin.Offset((child_area.width() - total_width) / 2, 0); | 289 image_origin.Offset((child_area.width() - total_width) / 2, 0); |
| 289 } else if (adjusted_alignment == gfx::ALIGN_RIGHT) { | 290 } else if (adjusted_alignment == gfx::ALIGN_RIGHT) { |
| 290 image_origin.Offset(child_area.width() - image_size.width(), 0); | 291 image_origin.Offset(child_area.width() - image_size.width(), 0); |
| 291 } | 292 } |
| 292 | 293 |
| 293 gfx::Point label_origin(child_area.origin()); | 294 gfx::Point label_origin(child_area.x(), 0); |
| 294 if (!image_size.IsEmpty() && adjusted_alignment != gfx::ALIGN_RIGHT) | 295 if (!image_size.IsEmpty() && adjusted_alignment != gfx::ALIGN_RIGHT) |
| 295 label_origin.set_x(image_origin.x() + image_size.width() + kSpacing); | 296 label_origin.set_x(image_origin.x() + image_size.width() + kSpacing); |
| 296 | 297 |
| 297 image_->SetBoundsRect(gfx::Rect(image_origin, image_size)); | 298 image_->SetBoundsRect(gfx::Rect(image_origin, image_size)); |
| 298 label_->SetBoundsRect(gfx::Rect(label_origin, label_size)); | 299 label_->SetBoundsRect(gfx::Rect(label_origin, label_size)); |
| 299 } | 300 } |
| 300 | 301 |
| 301 const char* LabelButton::GetClassName() const { | 302 const char* LabelButton::GetClassName() const { |
| 302 return kViewClassName; | 303 return kViewClassName; |
| 303 } | 304 } |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 GetExtraParams(params); | 478 GetExtraParams(params); |
| 478 return ui::NativeTheme::kHovered; | 479 return ui::NativeTheme::kHovered; |
| 479 } | 480 } |
| 480 | 481 |
| 481 void LabelButton::ResetCachedPreferredSize() { | 482 void LabelButton::ResetCachedPreferredSize() { |
| 482 cached_preferred_size_valid_ = false; | 483 cached_preferred_size_valid_ = false; |
| 483 cached_preferred_size_= gfx::Size(); | 484 cached_preferred_size_= gfx::Size(); |
| 484 } | 485 } |
| 485 | 486 |
| 486 } // namespace views | 487 } // namespace views |
| OLD | NEW |