Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: ui/views/controls/label.cc

Issue 2734113006: "Bootstrap" a toolkit-views Typography spec. (Closed)
Patch Set: Rebase Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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>
11 #include <limits> 11 #include <limits>
12 #include <utility> 12 #include <utility>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/i18n/rtl.h" 15 #include "base/i18n/rtl.h"
16 #include "base/logging.h" 16 #include "base/logging.h"
17 #include "base/memory/ptr_util.h" 17 #include "base/memory/ptr_util.h"
18 #include "base/profiler/scoped_tracker.h" 18 #include "base/profiler/scoped_tracker.h"
19 #include "base/strings/string_split.h" 19 #include "base/strings/string_split.h"
20 #include "base/strings/utf_string_conversions.h" 20 #include "base/strings/utf_string_conversions.h"
21 #include "ui/accessibility/ax_node_data.h" 21 #include "ui/accessibility/ax_node_data.h"
22 #include "ui/base/clipboard/scoped_clipboard_writer.h" 22 #include "ui/base/clipboard/scoped_clipboard_writer.h"
23 #include "ui/base/cursor/cursor.h" 23 #include "ui/base/cursor/cursor.h"
24 #include "ui/base/default_style.h" 24 #include "ui/base/default_style.h"
25 #include "ui/base/material_design/material_design_controller.h" 25 #include "ui/base/material_design/material_design_controller.h"
26 #include "ui/base/resource/resource_bundle.h" 26 #include "ui/base/resource/resource_bundle.h"
Peter Kasting 2017/03/17 02:26:00 I think this #include can be removed now. Also ch
tapted 2017/03/17 10:33:10 Done. Yeah - most of the client code files still u
27 #include "ui/gfx/canvas.h" 27 #include "ui/gfx/canvas.h"
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 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,
49 typography::CONTEXT_CONTROL_LABEL,
50 typography::STYLE_PRIMARY) {}
51
52 Label::Label(const base::string16& text, int text_context, int text_style)
53 : context_menu_contents_(this) {
54 Init(text, typography::GetFont(text_context, text_style));
sky 2017/03/16 16:23:51 Is the plan to change other controls to call to Ge
Peter Kasting 2017/03/17 02:26:00 We probably should eventually... this is connected
tapted 2017/03/17 10:33:10 Yes! Everything should be using style::GetFont().
48 } 55 }
49 56
50 Label::Label(const base::string16& text, const gfx::FontList& font_list) 57 Label::Label(const base::string16& text, const CustomFont& font)
51 : context_menu_contents_(this) { 58 : context_menu_contents_(this) {
52 Init(text, font_list); 59 Init(text, font.font_list);
53 } 60 }
54 61
55 Label::~Label() { 62 Label::~Label() {
56 } 63 }
57 64
58 // static 65 // static
59 const gfx::FontList& Label::GetDefaultFontList() { 66 const gfx::FontList& Label::GetDefaultFontList() {
60 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 67 return typography::GetFont(typography::CONTEXT_CONTROL_LABEL,
61 return rb.GetFontListWithDelta(ui::kLabelFontSizeDelta); 68 typography::STYLE_PRIMARY);
62 } 69 }
63 70
64 void Label::SetFontList(const gfx::FontList& font_list) { 71 void Label::SetFontList(const gfx::FontList& font_list) {
65 is_first_paint_text_ = true; 72 is_first_paint_text_ = true;
66 render_text_->SetFontList(font_list); 73 render_text_->SetFontList(font_list);
67 ResetLayout(); 74 ResetLayout();
68 } 75 }
69 76
70 void Label::SetText(const base::string16& new_text) { 77 void Label::SetText(const base::string16& new_text) {
71 if (new_text == text()) 78 if (new_text == text())
(...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 .WriteText(GetSelectedText()); 1062 .WriteText(GetSelectedText());
1056 } 1063 }
1057 1064
1058 void Label::BuildContextMenuContents() { 1065 void Label::BuildContextMenuContents() {
1059 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); 1066 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY);
1060 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, 1067 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL,
1061 IDS_APP_SELECT_ALL); 1068 IDS_APP_SELECT_ALL);
1062 } 1069 }
1063 1070
1064 } // namespace views 1071 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698