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

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

Issue 2734113006: "Bootstrap" a toolkit-views Typography spec. (Closed)
Patch Set: Rebase (conflict in layout_delegate.h due to r457774) 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"
27 #include "ui/gfx/canvas.h" 26 #include "ui/gfx/canvas.h"
28 #include "ui/gfx/color_utils.h" 27 #include "ui/gfx/color_utils.h"
29 #include "ui/gfx/geometry/insets.h" 28 #include "ui/gfx/geometry/insets.h"
30 #include "ui/gfx/text_elider.h" 29 #include "ui/gfx/text_elider.h"
31 #include "ui/native_theme/native_theme.h" 30 #include "ui/native_theme/native_theme.h"
32 #include "ui/strings/grit/ui_strings.h" 31 #include "ui/strings/grit/ui_strings.h"
33 #include "ui/views/background.h" 32 #include "ui/views/background.h"
34 #include "ui/views/controls/menu/menu_runner.h" 33 #include "ui/views/controls/menu/menu_runner.h"
35 #include "ui/views/focus/focus_manager.h" 34 #include "ui/views/focus/focus_manager.h"
36 #include "ui/views/native_cursor.h" 35 #include "ui/views/native_cursor.h"
37 #include "ui/views/selection_controller.h" 36 #include "ui/views/selection_controller.h"
38 37
39 namespace views { 38 namespace views {
40 // static 39 // static
41 const char Label::kViewClassName[] = "Label"; 40 const char Label::kViewClassName[] = "Label";
42 const int Label::kFocusBorderPadding = 1; 41 const int Label::kFocusBorderPadding = 1;
43 42
44 Label::Label() : Label(base::string16()) { 43 Label::Label() : Label(base::string16()) {
45 } 44 }
46 45
47 Label::Label(const base::string16& text) : Label(text, GetDefaultFontList()) { 46 Label::Label(const base::string16& text)
47 : Label(text, style::CONTEXT_LABEL, style::STYLE_PRIMARY) {}
48
49 Label::Label(const base::string16& text, int text_context, int text_style)
50 : context_menu_contents_(this) {
51 Init(text, style::GetFont(text_context, text_style));
48 } 52 }
49 53
50 Label::Label(const base::string16& text, const gfx::FontList& font_list) 54 Label::Label(const base::string16& text, const CustomFont& font)
51 : context_menu_contents_(this) { 55 : context_menu_contents_(this) {
52 Init(text, font_list); 56 Init(text, font.font_list);
53 } 57 }
54 58
55 Label::~Label() { 59 Label::~Label() {
56 } 60 }
57 61
58 // static 62 // static
59 const gfx::FontList& Label::GetDefaultFontList() { 63 const gfx::FontList& Label::GetDefaultFontList() {
60 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 64 return style::GetFont(style::CONTEXT_LABEL, style::STYLE_PRIMARY);
61 return rb.GetFontListWithDelta(ui::kLabelFontSizeDelta);
62 } 65 }
63 66
64 void Label::SetFontList(const gfx::FontList& font_list) { 67 void Label::SetFontList(const gfx::FontList& font_list) {
65 is_first_paint_text_ = true; 68 is_first_paint_text_ = true;
66 render_text_->SetFontList(font_list); 69 render_text_->SetFontList(font_list);
67 ResetLayout(); 70 ResetLayout();
68 } 71 }
69 72
70 void Label::SetText(const base::string16& new_text) { 73 void Label::SetText(const base::string16& new_text) {
71 if (new_text == text()) 74 if (new_text == text())
(...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 .WriteText(GetSelectedText()); 1058 .WriteText(GetSelectedText());
1056 } 1059 }
1057 1060
1058 void Label::BuildContextMenuContents() { 1061 void Label::BuildContextMenuContents() {
1059 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); 1062 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY);
1060 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, 1063 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL,
1061 IDS_APP_SELECT_ALL); 1064 IDS_APP_SELECT_ALL);
1062 } 1065 }
1063 1066
1064 } // namespace views 1067 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698