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