Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 #include "ui/gfx/shadow_value.h" | 22 #include "ui/gfx/shadow_value.h" |
| 23 #include "ui/gfx/text_elider.h" | 23 #include "ui/gfx/text_elider.h" |
| 24 #include "ui/gfx/text_utils.h" | 24 #include "ui/gfx/text_utils.h" |
| 25 #include "ui/native_theme/native_theme.h" | 25 #include "ui/native_theme/native_theme.h" |
| 26 #include "ui/views/background.h" | 26 #include "ui/views/background.h" |
| 27 | 27 |
| 28 namespace { | 28 namespace { |
| 29 | 29 |
| 30 const int kCachedSizeLimit = 10; | 30 const int kCachedSizeLimit = 10; |
| 31 | 31 |
| 32 gfx::FontList GetDefaultFontList() { | |
| 33 return ui::ResourceBundle::GetSharedInstance().GetFontList( | |
| 34 ui::ResourceBundle::BaseFont); | |
| 35 } | |
| 36 | |
| 37 } // namespace | 32 } // namespace |
| 38 | 33 |
| 39 namespace views { | 34 namespace views { |
| 40 | 35 |
| 41 // static | 36 // static |
| 42 const char Label::kViewClassName[] = "Label"; | 37 const char Label::kViewClassName[] = "Label"; |
| 43 const int Label::kFocusBorderPadding = 1; | 38 const int Label::kFocusBorderPadding = 1; |
| 44 | 39 |
| 45 Label::Label() { | 40 Label::Label() { |
| 46 Init(base::string16(), GetDefaultFontList()); | 41 Init(base::string16(), gfx::FontList()); |
|
sadrul
2014/01/06 18:41:04
Is this gfx::FontList() equivalent to the default
Yuki
2014/01/07 02:28:36
Yes, it's now equivalent.
sadrul
2014/01/07 02:35:32
Considering crbug.com/330975, if we get the FontLi
Yuki
2014/01/07 02:41:32
That's a good point. Let me address the issue fir
Yuki
2014/01/07 13:00:53
Just FYI, I've sent out a CL: http://crrev.com/124
| |
| 47 } | 42 } |
| 48 | 43 |
| 49 Label::Label(const base::string16& text) { | 44 Label::Label(const base::string16& text) { |
| 50 Init(text, GetDefaultFontList()); | 45 Init(text, gfx::FontList()); |
| 51 } | 46 } |
| 52 | 47 |
| 53 Label::Label(const base::string16& text, const gfx::FontList& font_list) { | 48 Label::Label(const base::string16& text, const gfx::FontList& font_list) { |
| 54 Init(text, font_list); | 49 Init(text, font_list); |
| 55 } | 50 } |
| 56 | 51 |
| 57 Label::Label(const base::string16& text, const gfx::Font& font) { | |
| 58 Init(text, gfx::FontList(font)); | |
| 59 } | |
| 60 | |
| 61 Label::~Label() { | 52 Label::~Label() { |
| 62 } | 53 } |
| 63 | 54 |
| 64 void Label::SetFontList(const gfx::FontList& font_list) { | 55 void Label::SetFontList(const gfx::FontList& font_list) { |
| 65 font_list_ = font_list; | 56 font_list_ = font_list; |
| 66 ResetCachedSize(); | 57 ResetCachedSize(); |
| 67 PreferredSizeChanged(); | 58 PreferredSizeChanged(); |
| 68 SchedulePaint(); | 59 SchedulePaint(); |
| 69 } | 60 } |
| 70 | 61 |
| 71 const gfx::Font& Label::font() const { | |
| 72 return font_list_.GetPrimaryFont(); | |
| 73 } | |
| 74 | |
| 75 void Label::SetFont(const gfx::Font& font) { | |
| 76 SetFontList(gfx::FontList(font)); | |
| 77 } | |
| 78 | |
| 79 void Label::SetText(const base::string16& text) { | 62 void Label::SetText(const base::string16& text) { |
| 80 if (text == text_) | 63 if (text == text_) |
| 81 return; | 64 return; |
| 82 text_ = text; | 65 text_ = text; |
| 83 ResetCachedSize(); | 66 ResetCachedSize(); |
| 84 PreferredSizeChanged(); | 67 PreferredSizeChanged(); |
| 85 SchedulePaint(); | 68 SchedulePaint(); |
| 86 } | 69 } |
| 87 | 70 |
| 88 void Label::SetAutoColorReadabilityEnabled(bool enabled) { | 71 void Label::SetAutoColorReadabilityEnabled(bool enabled) { |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 537 for (int i = 0; i < kCachedSizeLimit; ++i) | 520 for (int i = 0; i < kCachedSizeLimit; ++i) |
| 538 cached_heights_[i] = gfx::Size(); | 521 cached_heights_[i] = gfx::Size(); |
| 539 } | 522 } |
| 540 | 523 |
| 541 bool Label::ShouldShowDefaultTooltip() const { | 524 bool Label::ShouldShowDefaultTooltip() const { |
| 542 return !is_multi_line_ && | 525 return !is_multi_line_ && |
| 543 gfx::GetStringWidth(text_, font_list_) > GetAvailableRect().width(); | 526 gfx::GetStringWidth(text_, font_list_) > GetAvailableRect().width(); |
| 544 } | 527 } |
| 545 | 528 |
| 546 } // namespace views | 529 } // namespace views |
| OLD | NEW |