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

Side by Side Diff: ui/views/controls/textfield/native_textfield_views.cc

Issue 19666006: Supports FontList in Textfield. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixes examples and unittests. Created 7 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/textfield/native_textfield_views.h" 5 #include "ui/views/controls/textfield/native_textfield_views.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/debug/trace_event.h" 11 #include "base/debug/trace_event.h"
12 #include "base/i18n/case_conversion.h" 12 #include "base/i18n/case_conversion.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
16 #include "grit/app_locale_settings.h" 16 #include "grit/app_locale_settings.h"
msw 2013/07/26 21:19:57 Can this be removed if IDS_UI_FONT_FAMILY_CROS isn
Yuki 2013/07/29 15:27:21 Done.
17 #include "grit/ui_strings.h" 17 #include "grit/ui_strings.h"
18 #include "third_party/icu/source/common/unicode/uchar.h" 18 #include "third_party/icu/source/common/unicode/uchar.h"
19 #include "third_party/skia/include/core/SkColor.h" 19 #include "third_party/skia/include/core/SkColor.h"
20 #include "ui/base/clipboard/clipboard.h" 20 #include "ui/base/clipboard/clipboard.h"
21 #include "ui/base/dragdrop/drag_drop_types.h" 21 #include "ui/base/dragdrop/drag_drop_types.h"
22 #include "ui/base/dragdrop/drag_utils.h" 22 #include "ui/base/dragdrop/drag_utils.h"
23 #include "ui/base/events/event.h" 23 #include "ui/base/events/event.h"
24 #include "ui/base/l10n/l10n_util.h" 24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/range/range.h" 25 #include "ui/base/range/range.h"
26 #include "ui/base/ui_base_switches_util.h" 26 #include "ui/base/ui_base_switches_util.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 : textfield_(parent), 75 : textfield_(parent),
76 model_(new TextfieldViewsModel(this)), 76 model_(new TextfieldViewsModel(this)),
77 text_border_(new FocusableBorder()), 77 text_border_(new FocusableBorder()),
78 is_cursor_visible_(false), 78 is_cursor_visible_(false),
79 is_drop_cursor_visible_(false), 79 is_drop_cursor_visible_(false),
80 skip_input_method_cancel_composition_(false), 80 skip_input_method_cancel_composition_(false),
81 initiating_drag_(false), 81 initiating_drag_(false),
82 cursor_timer_(this), 82 cursor_timer_(this),
83 aggregated_clicks_(0) { 83 aggregated_clicks_(0) {
84 set_border(text_border_); 84 set_border(text_border_);
85 85 GetRenderText()->SetFontList(textfield_->font_list());
86 #if defined(OS_CHROMEOS)
87 GetRenderText()->SetFontList(gfx::FontList(l10n_util::GetStringUTF8(
msw 2013/07/26 21:19:57 I think you'll need to leave this explicit IDS_UI_
Yuki 2013/07/29 15:27:21 Done. As the same as views::Label, I've introduce
88 IDS_UI_FONT_FAMILY_CROS)));
89 #else
90 GetRenderText()->SetFont(textfield_->font());
91 #endif
92
93 UpdateColorsFromTheme(GetNativeTheme()); 86 UpdateColorsFromTheme(GetNativeTheme());
94 set_context_menu_controller(this); 87 set_context_menu_controller(this);
95 set_drag_controller(this); 88 set_drag_controller(this);
96 } 89 }
97 90
98 NativeTextfieldViews::~NativeTextfieldViews() { 91 NativeTextfieldViews::~NativeTextfieldViews() {
99 } 92 }
100 93
101 //////////////////////////////////////////////////////////////////////////////// 94 ////////////////////////////////////////////////////////////////////////////////
102 // NativeTextfieldViews, View overrides: 95 // NativeTextfieldViews, View overrides:
(...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after
568 set_background(Background::CreateSolidBackground(color)); 561 set_background(Background::CreateSolidBackground(color));
569 GetRenderText()->set_background_is_transparent(SkColorGetA(color) != 0xFF); 562 GetRenderText()->set_background_is_transparent(SkColorGetA(color) != 0xFF);
570 SchedulePaint(); 563 SchedulePaint();
571 } 564 }
572 565
573 void NativeTextfieldViews::UpdateReadOnly() { 566 void NativeTextfieldViews::UpdateReadOnly() {
574 OnTextInputTypeChanged(); 567 OnTextInputTypeChanged();
575 } 568 }
576 569
577 void NativeTextfieldViews::UpdateFont() { 570 void NativeTextfieldViews::UpdateFont() {
578 #if defined(OS_CHROMEOS) 571 GetRenderText()->SetFontList(textfield_->font_list());
579 // For ChromeOS, we support a pre-defined font list per locale. UpdateFont()
580 // only changes the font size, not the font family names.
581 GetRenderText()->SetFontSize(textfield_->font().GetFontSize());
582 #else
583 GetRenderText()->SetFont(textfield_->font());
584 #endif
585 OnCaretBoundsChanged(); 572 OnCaretBoundsChanged();
586 } 573 }
587 574
588 void NativeTextfieldViews::UpdateIsObscured() { 575 void NativeTextfieldViews::UpdateIsObscured() {
589 GetRenderText()->SetObscured(textfield_->IsObscured()); 576 GetRenderText()->SetObscured(textfield_->IsObscured());
590 OnCaretBoundsChanged(); 577 OnCaretBoundsChanged();
591 SchedulePaint(); 578 SchedulePaint();
592 OnTextInputTypeChanged(); 579 OnTextInputTypeChanged();
593 } 580 }
594 581
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
719 706
720 ui::TextInputClient* NativeTextfieldViews::GetTextInputClient() { 707 ui::TextInputClient* NativeTextfieldViews::GetTextInputClient() {
721 return textfield_->read_only() ? NULL : this; 708 return textfield_->read_only() ? NULL : this;
722 } 709 }
723 710
724 void NativeTextfieldViews::ClearEditHistory() { 711 void NativeTextfieldViews::ClearEditHistory() {
725 model_->ClearEditHistory(); 712 model_->ClearEditHistory();
726 } 713 }
727 714
728 int NativeTextfieldViews::GetFontHeight() { 715 int NativeTextfieldViews::GetFontHeight() {
729 return GetRenderText()->GetFont().GetHeight(); 716 return GetRenderText()->font_list().GetHeight();
730 } 717 }
731 718
732 int NativeTextfieldViews::GetTextfieldBaseline() const { 719 int NativeTextfieldViews::GetTextfieldBaseline() const {
733 return GetRenderText()->GetFont().GetBaseline(); 720 return GetRenderText()->font_list().GetBaseline();
734 } 721 }
735 722
736 int NativeTextfieldViews::GetWidthNeededForText() const { 723 int NativeTextfieldViews::GetWidthNeededForText() const {
737 return GetRenderText()->GetContentWidth() + GetInsets().width(); 724 return GetRenderText()->GetContentWidth() + GetInsets().width();
738 } 725 }
739 726
740 void NativeTextfieldViews::ExecuteTextCommand(int command_id) { 727 void NativeTextfieldViews::ExecuteTextCommand(int command_id) {
741 ExecuteCommand(command_id, 0); 728 ExecuteCommand(command_id, 0);
742 } 729 }
743 730
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 1146
1160 // Draw the detached drop cursor that marks where the text will be dropped. 1147 // Draw the detached drop cursor that marks where the text will be dropped.
1161 if (is_drop_cursor_visible_) 1148 if (is_drop_cursor_visible_)
1162 GetRenderText()->DrawCursor(canvas, drop_cursor_position_); 1149 GetRenderText()->DrawCursor(canvas, drop_cursor_position_);
1163 1150
1164 // Draw placeholder text if needed. 1151 // Draw placeholder text if needed.
1165 if (model_->GetText().empty() && 1152 if (model_->GetText().empty() &&
1166 !textfield_->placeholder_text().empty()) { 1153 !textfield_->placeholder_text().empty()) {
1167 canvas->DrawStringInt( 1154 canvas->DrawStringInt(
1168 textfield_->placeholder_text(), 1155 textfield_->placeholder_text(),
1169 GetRenderText()->GetFont(), 1156 GetRenderText()->GetPrimaryFont(),
1170 textfield_->placeholder_text_color(), 1157 textfield_->placeholder_text_color(),
1171 GetRenderText()->display_rect()); 1158 GetRenderText()->display_rect());
1172 } 1159 }
1173 canvas->Restore(); 1160 canvas->Restore();
1174 } 1161 }
1175 1162
1176 bool NativeTextfieldViews::HandleKeyEvent(const ui::KeyEvent& key_event) { 1163 bool NativeTextfieldViews::HandleKeyEvent(const ui::KeyEvent& key_event) {
1177 // TODO(oshima): Refactor and consolidate with ExecuteCommand. 1164 // TODO(oshima): Refactor and consolidate with ExecuteCommand.
1178 if (key_event.type() == ui::ET_KEY_PRESSED) { 1165 if (key_event.type() == ui::ET_KEY_PRESSED) {
1179 ui::KeyboardCode key_code = key_event.key_code(); 1166 ui::KeyboardCode key_code = key_event.key_code();
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 if (index != -1) { 1495 if (index != -1) {
1509 obscured_reveal_timer_.Start( 1496 obscured_reveal_timer_.Start(
1510 FROM_HERE, 1497 FROM_HERE,
1511 duration, 1498 duration,
1512 base::Bind(&NativeTextfieldViews::RevealObscuredChar, 1499 base::Bind(&NativeTextfieldViews::RevealObscuredChar,
1513 base::Unretained(this), -1, base::TimeDelta())); 1500 base::Unretained(this), -1, base::TimeDelta()));
1514 } 1501 }
1515 } 1502 }
1516 1503
1517 } // namespace views 1504 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698