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 26 matching lines...) Expand all Loading... |
37 #include "ui/views/selection_controller.h" | 37 #include "ui/views/selection_controller.h" |
38 | 38 |
39 namespace views { | 39 namespace views { |
40 // static | 40 // static |
41 const char Label::kViewClassName[] = "Label"; | 41 const char Label::kViewClassName[] = "Label"; |
42 const int Label::kFocusBorderPadding = 1; | 42 const int Label::kFocusBorderPadding = 1; |
43 | 43 |
44 Label::Label() : Label(base::string16()) { | 44 Label::Label() : Label(base::string16()) { |
45 } | 45 } |
46 | 46 |
47 Label::Label(const base::string16& text) : Label(text, GetDefaultFontList()) { | 47 Label::Label(const base::string16& text) |
| 48 : Label(text, TextContext::CONTROL_LABEL, TextStyle::PRIMARY) {} |
| 49 |
| 50 Label::Label(const base::string16& text, TextContext context, TextStyle style) |
| 51 : context_menu_contents_(this) { |
| 52 Init(text, Typography::GetFont(context, style)); |
48 } | 53 } |
49 | 54 |
50 Label::Label(const base::string16& text, const gfx::FontList& font_list) | 55 Label::Label(const base::string16& text, const CustomFont& font) |
51 : context_menu_contents_(this) { | 56 : context_menu_contents_(this) { |
52 Init(text, font_list); | 57 Init(text, font.font_list); |
53 } | 58 } |
54 | 59 |
55 Label::~Label() { | 60 Label::~Label() { |
56 } | 61 } |
57 | 62 |
58 // static | 63 // static |
59 const gfx::FontList& Label::GetDefaultFontList() { | 64 const gfx::FontList& Label::GetDefaultFontList() { |
60 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 65 return Typography::GetFont(TextContext::CONTROL_LABEL, TextStyle::PRIMARY); |
61 return rb.GetFontListWithDelta(ui::kLabelFontSizeDelta); | |
62 } | 66 } |
63 | 67 |
64 void Label::SetFontList(const gfx::FontList& font_list) { | 68 void Label::SetFontList(const gfx::FontList& font_list) { |
65 is_first_paint_text_ = true; | 69 is_first_paint_text_ = true; |
66 render_text_->SetFontList(font_list); | 70 render_text_->SetFontList(font_list); |
67 ResetLayout(); | 71 ResetLayout(); |
68 } | 72 } |
69 | 73 |
70 void Label::SetText(const base::string16& new_text) { | 74 void Label::SetText(const base::string16& new_text) { |
71 if (new_text == text()) | 75 if (new_text == text()) |
(...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1055 .WriteText(GetSelectedText()); | 1059 .WriteText(GetSelectedText()); |
1056 } | 1060 } |
1057 | 1061 |
1058 void Label::BuildContextMenuContents() { | 1062 void Label::BuildContextMenuContents() { |
1059 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); | 1063 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); |
1060 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, | 1064 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, |
1061 IDS_APP_SELECT_ALL); | 1065 IDS_APP_SELECT_ALL); |
1062 } | 1066 } |
1063 | 1067 |
1064 } // namespace views | 1068 } // namespace views |
OLD | NEW |