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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <cmath> | 10 #include <cmath> |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 result.append(lines_[0]->GetDisplayText()); | 206 result.append(lines_[0]->GetDisplayText()); |
207 for (size_t i = 1; i < lines_.size(); ++i) { | 207 for (size_t i = 1; i < lines_.size(); ++i) { |
208 result.append(1, '\n'); | 208 result.append(1, '\n'); |
209 result.append(lines_[i]->GetDisplayText()); | 209 result.append(lines_[i]->GetDisplayText()); |
210 } | 210 } |
211 return result; | 211 return result; |
212 } | 212 } |
213 | 213 |
214 gfx::Insets Label::GetInsets() const { | 214 gfx::Insets Label::GetInsets() const { |
215 gfx::Insets insets = View::GetInsets(); | 215 gfx::Insets insets = View::GetInsets(); |
| 216 // TODO(karandeepb): This won't work for Mac where labels are not focusable |
| 217 // but accessibility focusable. Fix this. |
216 if (focusable()) { | 218 if (focusable()) { |
217 insets += gfx::Insets(kFocusBorderPadding, kFocusBorderPadding, | 219 insets += gfx::Insets(kFocusBorderPadding, kFocusBorderPadding, |
218 kFocusBorderPadding, kFocusBorderPadding); | 220 kFocusBorderPadding, kFocusBorderPadding); |
219 } | 221 } |
220 return insets; | 222 return insets; |
221 } | 223 } |
222 | 224 |
223 int Label::GetBaseline() const { | 225 int Label::GetBaseline() const { |
224 return GetInsets().top() + font_list().GetBaseline(); | 226 return GetInsets().top() + font_list().GetBaseline(); |
225 } | 227 } |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 PreferredSizeChanged(); | 430 PreferredSizeChanged(); |
429 SchedulePaint(); | 431 SchedulePaint(); |
430 lines_.clear(); | 432 lines_.clear(); |
431 } | 433 } |
432 | 434 |
433 void Label::MaybeBuildRenderTextLines() { | 435 void Label::MaybeBuildRenderTextLines() { |
434 if (!lines_.empty()) | 436 if (!lines_.empty()) |
435 return; | 437 return; |
436 | 438 |
437 gfx::Rect rect = GetContentsBounds(); | 439 gfx::Rect rect = GetContentsBounds(); |
| 440 // TODO(karandeepb): This won't work for Mac where labels are not focusable |
| 441 // but accessibility focusable. Fix this. |
438 if (focusable()) | 442 if (focusable()) |
439 rect.Inset(kFocusBorderPadding, kFocusBorderPadding); | 443 rect.Inset(kFocusBorderPadding, kFocusBorderPadding); |
440 if (rect.IsEmpty()) | 444 if (rect.IsEmpty()) |
441 return; | 445 return; |
442 rect.Inset(-gfx::ShadowValue::GetMargin(shadows())); | 446 rect.Inset(-gfx::ShadowValue::GetMargin(shadows())); |
443 | 447 |
444 gfx::HorizontalAlignment alignment = horizontal_alignment(); | 448 gfx::HorizontalAlignment alignment = horizontal_alignment(); |
445 gfx::DirectionalityMode directionality = render_text_->directionality_mode(); | 449 gfx::DirectionalityMode directionality = render_text_->directionality_mode(); |
446 if (multi_line()) { | 450 if (multi_line()) { |
447 // Force the directionality and alignment of the first line on other lines. | 451 // Force the directionality and alignment of the first line on other lines. |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
586 } | 590 } |
587 | 591 |
588 bool Label::ShouldShowDefaultTooltip() const { | 592 bool Label::ShouldShowDefaultTooltip() const { |
589 const gfx::Size text_size = GetTextSize(); | 593 const gfx::Size text_size = GetTextSize(); |
590 const gfx::Size size = GetContentsBounds().size(); | 594 const gfx::Size size = GetContentsBounds().size(); |
591 return !obscured() && (text_size.width() > size.width() || | 595 return !obscured() && (text_size.width() > size.width() || |
592 (multi_line() && text_size.height() > size.height())); | 596 (multi_line() && text_size.height() > size.height())); |
593 } | 597 } |
594 | 598 |
595 } // namespace views | 599 } // namespace views |
OLD | NEW |