| 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 30 matching lines...) Expand all Loading... |
| 41 const int Label::kFocusBorderPadding = 1; | 41 const int Label::kFocusBorderPadding = 1; |
| 42 | 42 |
| 43 Label::Label() : Label(base::string16()) { | 43 Label::Label() : Label(base::string16()) { |
| 44 } | 44 } |
| 45 | 45 |
| 46 Label::Label(const base::string16& text) | 46 Label::Label(const base::string16& text) |
| 47 : Label(text, style::CONTEXT_LABEL, style::STYLE_PRIMARY) {} | 47 : Label(text, style::CONTEXT_LABEL, style::STYLE_PRIMARY) {} |
| 48 | 48 |
| 49 Label::Label(const base::string16& text, int text_context, int text_style) | 49 Label::Label(const base::string16& text, int text_context, int text_style) |
| 50 : context_menu_contents_(this) { | 50 : context_menu_contents_(this) { |
| 51 Init(text, style::GetFont(text_context, text_style)); | 51 Init(text); |
| 52 render_text_->SetFontList(style::GetFont(text_context, text_style)); |
| 53 SetLineHeight(style::GetLineHeight(text_context, text_style)); |
| 52 } | 54 } |
| 53 | 55 |
| 54 Label::Label(const base::string16& text, const CustomFont& font) | 56 Label::Label(const base::string16& text, const CustomFont& font) |
| 55 : context_menu_contents_(this) { | 57 : context_menu_contents_(this) { |
| 56 Init(text, font.font_list); | 58 Init(text); |
| 59 render_text_->SetFontList(font.font_list); |
| 57 } | 60 } |
| 58 | 61 |
| 59 Label::~Label() { | 62 Label::~Label() { |
| 60 } | 63 } |
| 61 | 64 |
| 62 // static | 65 // static |
| 63 const gfx::FontList& Label::GetDefaultFontList() { | 66 const gfx::FontList& Label::GetDefaultFontList() { |
| 64 return style::GetFont(style::CONTEXT_LABEL, style::STYLE_PRIMARY); | 67 return style::GetFont(style::CONTEXT_LABEL, style::STYLE_PRIMARY); |
| 65 } | 68 } |
| 66 | 69 |
| (...skipping 720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 MaybeBuildRenderTextLines(); | 790 MaybeBuildRenderTextLines(); |
| 788 | 791 |
| 789 // This may happen when the content bounds of the view are empty. | 792 // This may happen when the content bounds of the view are empty. |
| 790 if (lines_.empty()) | 793 if (lines_.empty()) |
| 791 return nullptr; | 794 return nullptr; |
| 792 | 795 |
| 793 DCHECK_EQ(1u, lines_.size()); | 796 DCHECK_EQ(1u, lines_.size()); |
| 794 return lines_[0].get(); | 797 return lines_[0].get(); |
| 795 } | 798 } |
| 796 | 799 |
| 797 void Label::Init(const base::string16& text, const gfx::FontList& font_list) { | 800 void Label::Init(const base::string16& text) { |
| 798 render_text_.reset(gfx::RenderText::CreateInstance()); | 801 render_text_.reset(gfx::RenderText::CreateInstance()); |
| 799 render_text_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 802 render_text_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 800 render_text_->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_TEXT); | 803 render_text_->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_TEXT); |
| 801 // NOTE: |render_text_| should not be elided at all. This is used to keep some | 804 // NOTE: |render_text_| should not be elided at all. This is used to keep some |
| 802 // properties and to compute the size of the string. | 805 // properties and to compute the size of the string. |
| 803 render_text_->SetElideBehavior(gfx::NO_ELIDE); | 806 render_text_->SetElideBehavior(gfx::NO_ELIDE); |
| 804 render_text_->SetFontList(font_list); | |
| 805 render_text_->SetCursorEnabled(false); | 807 render_text_->SetCursorEnabled(false); |
| 806 render_text_->SetWordWrapBehavior(gfx::TRUNCATE_LONG_WORDS); | 808 render_text_->SetWordWrapBehavior(gfx::TRUNCATE_LONG_WORDS); |
| 807 | 809 |
| 808 elide_behavior_ = gfx::ELIDE_TAIL; | 810 elide_behavior_ = gfx::ELIDE_TAIL; |
| 809 stored_selection_range_ = gfx::Range::InvalidRange(); | 811 stored_selection_range_ = gfx::Range::InvalidRange(); |
| 810 enabled_color_set_ = disabled_color_set_ = background_color_set_ = false; | 812 enabled_color_set_ = disabled_color_set_ = background_color_set_ = false; |
| 811 selection_text_color_set_ = selection_background_color_set_ = false; | 813 selection_text_color_set_ = selection_background_color_set_ = false; |
| 812 subpixel_rendering_enabled_ = true; | 814 subpixel_rendering_enabled_ = true; |
| 813 auto_color_readability_ = true; | 815 auto_color_readability_ = true; |
| 814 multi_line_ = false; | 816 multi_line_ = false; |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1058 .WriteText(GetSelectedText()); | 1060 .WriteText(GetSelectedText()); |
| 1059 } | 1061 } |
| 1060 | 1062 |
| 1061 void Label::BuildContextMenuContents() { | 1063 void Label::BuildContextMenuContents() { |
| 1062 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); | 1064 context_menu_contents_.AddItemWithStringId(IDS_APP_COPY, IDS_APP_COPY); |
| 1063 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, | 1065 context_menu_contents_.AddItemWithStringId(IDS_APP_SELECT_ALL, |
| 1064 IDS_APP_SELECT_ALL); | 1066 IDS_APP_SELECT_ALL); |
| 1065 } | 1067 } |
| 1066 | 1068 |
| 1067 } // namespace views | 1069 } // namespace views |
| OLD | NEW |