| 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/label.h" | 5 #include "ui/views/controls/label.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <limits> | 9 #include <limits> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 insets += gfx::Insets(kFocusBorderPadding, kFocusBorderPadding, | 211 insets += gfx::Insets(kFocusBorderPadding, kFocusBorderPadding, |
| 212 kFocusBorderPadding, kFocusBorderPadding); | 212 kFocusBorderPadding, kFocusBorderPadding); |
| 213 } | 213 } |
| 214 return insets; | 214 return insets; |
| 215 } | 215 } |
| 216 | 216 |
| 217 int Label::GetBaseline() const { | 217 int Label::GetBaseline() const { |
| 218 return GetInsets().top() + font_list_.GetBaseline(); | 218 return GetInsets().top() + font_list_.GetBaseline(); |
| 219 } | 219 } |
| 220 | 220 |
| 221 gfx::Size Label::GetPreferredSize() { | 221 gfx::Size Label::GetPreferredSize() const { |
| 222 // Return a size of (0, 0) if the label is not visible and if the | 222 // Return a size of (0, 0) if the label is not visible and if the |
| 223 // collapse_when_hidden_ flag is set. | 223 // collapse_when_hidden_ flag is set. |
| 224 // TODO(munjal): This logic probably belongs to the View class. But for now, | 224 // TODO(munjal): This logic probably belongs to the View class. But for now, |
| 225 // put it here since putting it in View class means all inheriting classes | 225 // put it here since putting it in View class means all inheriting classes |
| 226 // need ot respect the collapse_when_hidden_ flag. | 226 // need ot respect the collapse_when_hidden_ flag. |
| 227 if (!visible() && collapse_when_hidden_) | 227 if (!visible() && collapse_when_hidden_) |
| 228 return gfx::Size(); | 228 return gfx::Size(); |
| 229 | 229 |
| 230 gfx::Size size(GetTextSize()); | 230 gfx::Size size(GetTextSize()); |
| 231 gfx::Insets insets = GetInsets(); | 231 gfx::Insets insets = GetInsets(); |
| 232 size.Enlarge(insets.width(), insets.height()); | 232 size.Enlarge(insets.width(), insets.height()); |
| 233 return size; | 233 return size; |
| 234 } | 234 } |
| 235 | 235 |
| 236 gfx::Size Label::GetMinimumSize() { | 236 gfx::Size Label::GetMinimumSize() const { |
| 237 gfx::Size text_size(GetTextSize()); | 237 gfx::Size text_size(GetTextSize()); |
| 238 if ((!visible() && collapse_when_hidden_) || text_size.IsEmpty()) | 238 if ((!visible() && collapse_when_hidden_) || text_size.IsEmpty()) |
| 239 return gfx::Size(); | 239 return gfx::Size(); |
| 240 | 240 |
| 241 gfx::Size size(gfx::GetStringWidth(base::string16(gfx::kEllipsisUTF16), | 241 gfx::Size size(gfx::GetStringWidth(base::string16(gfx::kEllipsisUTF16), |
| 242 font_list_), | 242 font_list_), |
| 243 font_list_.GetHeight()); | 243 font_list_.GetHeight()); |
| 244 size.SetToMin(text_size); // The actual text may be shorter than an ellipsis. | 244 size.SetToMin(text_size); // The actual text may be shorter than an ellipsis. |
| 245 gfx::Insets insets = GetInsets(); | 245 gfx::Insets insets = GetInsets(); |
| 246 size.Enlarge(insets.width(), insets.height()); | 246 size.Enlarge(insets.width(), insets.height()); |
| 247 return size; | 247 return size; |
| 248 } | 248 } |
| 249 | 249 |
| 250 int Label::GetHeightForWidth(int w) { | 250 int Label::GetHeightForWidth(int w) const { |
| 251 if (!is_multi_line_) | 251 if (!is_multi_line_) |
| 252 return View::GetHeightForWidth(w); | 252 return View::GetHeightForWidth(w); |
| 253 | 253 |
| 254 w = std::max(0, w - GetInsets().width()); | 254 w = std::max(0, w - GetInsets().width()); |
| 255 | 255 |
| 256 for (size_t i = 0; i < cached_heights_.size(); ++i) { | 256 for (size_t i = 0; i < cached_heights_.size(); ++i) { |
| 257 const gfx::Size& s = cached_heights_[i]; | 257 const gfx::Size& s = cached_heights_[i]; |
| 258 if (s.width() == w) | 258 if (s.width() == w) |
| 259 return s.height() + GetInsets().height(); | 259 return s.height() + GetInsets().height(); |
| 260 } | 260 } |
| (...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 cached_heights_[i] = gfx::Size(); | 557 cached_heights_[i] = gfx::Size(); |
| 558 } | 558 } |
| 559 | 559 |
| 560 bool Label::ShouldShowDefaultTooltip() const { | 560 bool Label::ShouldShowDefaultTooltip() const { |
| 561 return !is_multi_line_ && !is_obscured_ && | 561 return !is_multi_line_ && !is_obscured_ && |
| 562 gfx::GetStringWidth(layout_text(), font_list_) > | 562 gfx::GetStringWidth(layout_text(), font_list_) > |
| 563 GetAvailableRect().width(); | 563 GetAvailableRect().width(); |
| 564 } | 564 } |
| 565 | 565 |
| 566 } // namespace views | 566 } // namespace views |
| OLD | NEW |