| OLD | NEW | 
|     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" |  | 
|    17 #include "grit/ui_strings.h" |    16 #include "grit/ui_strings.h" | 
|    18 #include "third_party/icu/source/common/unicode/uchar.h" |    17 #include "third_party/icu/source/common/unicode/uchar.h" | 
|    19 #include "third_party/skia/include/core/SkColor.h" |    18 #include "third_party/skia/include/core/SkColor.h" | 
|    20 #include "ui/base/clipboard/clipboard.h" |    19 #include "ui/base/clipboard/clipboard.h" | 
|    21 #include "ui/base/dragdrop/drag_drop_types.h" |    20 #include "ui/base/dragdrop/drag_drop_types.h" | 
|    22 #include "ui/base/dragdrop/drag_utils.h" |    21 #include "ui/base/dragdrop/drag_utils.h" | 
|    23 #include "ui/base/events/event.h" |    22 #include "ui/base/events/event.h" | 
|    24 #include "ui/base/l10n/l10n_util.h" |    23 #include "ui/base/l10n/l10n_util.h" | 
|    25 #include "ui/base/range/range.h" |    24 #include "ui/base/range/range.h" | 
|    26 #include "ui/base/ui_base_switches_util.h" |    25 #include "ui/base/ui_base_switches_util.h" | 
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|    75     : textfield_(parent), |    74     : textfield_(parent), | 
|    76       model_(new TextfieldViewsModel(this)), |    75       model_(new TextfieldViewsModel(this)), | 
|    77       text_border_(new FocusableBorder()), |    76       text_border_(new FocusableBorder()), | 
|    78       is_cursor_visible_(false), |    77       is_cursor_visible_(false), | 
|    79       is_drop_cursor_visible_(false), |    78       is_drop_cursor_visible_(false), | 
|    80       skip_input_method_cancel_composition_(false), |    79       skip_input_method_cancel_composition_(false), | 
|    81       initiating_drag_(false), |    80       initiating_drag_(false), | 
|    82       cursor_timer_(this), |    81       cursor_timer_(this), | 
|    83       aggregated_clicks_(0) { |    82       aggregated_clicks_(0) { | 
|    84   set_border(text_border_); |    83   set_border(text_border_); | 
|    85  |    84   GetRenderText()->SetFontList(textfield_->font_list()); | 
|    86 #if defined(OS_CHROMEOS) |  | 
|    87   GetRenderText()->SetFontList(gfx::FontList(l10n_util::GetStringUTF8( |  | 
|    88       IDS_UI_FONT_FAMILY_CROS))); |  | 
|    89 #else |  | 
|    90   GetRenderText()->SetFont(textfield_->font()); |  | 
|    91 #endif |  | 
|    92  |  | 
|    93   UpdateColorsFromTheme(GetNativeTheme()); |    85   UpdateColorsFromTheme(GetNativeTheme()); | 
|    94   set_context_menu_controller(this); |    86   set_context_menu_controller(this); | 
|    95   set_drag_controller(this); |    87   set_drag_controller(this); | 
|    96 } |    88 } | 
|    97  |    89  | 
|    98 NativeTextfieldViews::~NativeTextfieldViews() { |    90 NativeTextfieldViews::~NativeTextfieldViews() { | 
|    99 } |    91 } | 
|   100  |    92  | 
|   101 //////////////////////////////////////////////////////////////////////////////// |    93 //////////////////////////////////////////////////////////////////////////////// | 
|   102 // NativeTextfieldViews, View overrides: |    94 // NativeTextfieldViews, View overrides: | 
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   568   set_background(Background::CreateSolidBackground(color)); |   560   set_background(Background::CreateSolidBackground(color)); | 
|   569   GetRenderText()->set_background_is_transparent(SkColorGetA(color) != 0xFF); |   561   GetRenderText()->set_background_is_transparent(SkColorGetA(color) != 0xFF); | 
|   570   SchedulePaint(); |   562   SchedulePaint(); | 
|   571 } |   563 } | 
|   572  |   564  | 
|   573 void NativeTextfieldViews::UpdateReadOnly() { |   565 void NativeTextfieldViews::UpdateReadOnly() { | 
|   574   OnTextInputTypeChanged(); |   566   OnTextInputTypeChanged(); | 
|   575 } |   567 } | 
|   576  |   568  | 
|   577 void NativeTextfieldViews::UpdateFont() { |   569 void NativeTextfieldViews::UpdateFont() { | 
|   578 #if defined(OS_CHROMEOS) |   570   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(); |   571   OnCaretBoundsChanged(); | 
|   586 } |   572 } | 
|   587  |   573  | 
|   588 void NativeTextfieldViews::UpdateIsObscured() { |   574 void NativeTextfieldViews::UpdateIsObscured() { | 
|   589   GetRenderText()->SetObscured(textfield_->IsObscured()); |   575   GetRenderText()->SetObscured(textfield_->IsObscured()); | 
|   590   OnCaretBoundsChanged(); |   576   OnCaretBoundsChanged(); | 
|   591   SchedulePaint(); |   577   SchedulePaint(); | 
|   592   OnTextInputTypeChanged(); |   578   OnTextInputTypeChanged(); | 
|   593 } |   579 } | 
|   594  |   580  | 
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   719  |   705  | 
|   720 ui::TextInputClient* NativeTextfieldViews::GetTextInputClient() { |   706 ui::TextInputClient* NativeTextfieldViews::GetTextInputClient() { | 
|   721   return textfield_->read_only() ? NULL : this; |   707   return textfield_->read_only() ? NULL : this; | 
|   722 } |   708 } | 
|   723  |   709  | 
|   724 void NativeTextfieldViews::ClearEditHistory() { |   710 void NativeTextfieldViews::ClearEditHistory() { | 
|   725   model_->ClearEditHistory(); |   711   model_->ClearEditHistory(); | 
|   726 } |   712 } | 
|   727  |   713  | 
|   728 int NativeTextfieldViews::GetFontHeight() { |   714 int NativeTextfieldViews::GetFontHeight() { | 
|   729   return GetRenderText()->GetFont().GetHeight(); |   715   return GetRenderText()->font_list().GetHeight(); | 
|   730 } |   716 } | 
|   731  |   717  | 
|   732 int NativeTextfieldViews::GetTextfieldBaseline() const { |   718 int NativeTextfieldViews::GetTextfieldBaseline() const { | 
|   733   return GetRenderText()->GetFont().GetBaseline(); |   719   return GetRenderText()->font_list().GetBaseline(); | 
|   734 } |   720 } | 
|   735  |   721  | 
|   736 int NativeTextfieldViews::GetWidthNeededForText() const { |   722 int NativeTextfieldViews::GetWidthNeededForText() const { | 
|   737   return GetRenderText()->GetContentWidth() + GetInsets().width(); |   723   return GetRenderText()->GetContentWidth() + GetInsets().width(); | 
|   738 } |   724 } | 
|   739  |   725  | 
|   740 void NativeTextfieldViews::ExecuteTextCommand(int command_id) { |   726 void NativeTextfieldViews::ExecuteTextCommand(int command_id) { | 
|   741   ExecuteCommand(command_id, 0); |   727   ExecuteCommand(command_id, 0); | 
|   742 } |   728 } | 
|   743  |   729  | 
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1159  |  1145  | 
|  1160   // Draw the detached drop cursor that marks where the text will be dropped. |  1146   // Draw the detached drop cursor that marks where the text will be dropped. | 
|  1161   if (is_drop_cursor_visible_) |  1147   if (is_drop_cursor_visible_) | 
|  1162     GetRenderText()->DrawCursor(canvas, drop_cursor_position_); |  1148     GetRenderText()->DrawCursor(canvas, drop_cursor_position_); | 
|  1163  |  1149  | 
|  1164   // Draw placeholder text if needed. |  1150   // Draw placeholder text if needed. | 
|  1165   if (model_->GetText().empty() && |  1151   if (model_->GetText().empty() && | 
|  1166       !textfield_->placeholder_text().empty()) { |  1152       !textfield_->placeholder_text().empty()) { | 
|  1167     canvas->DrawStringInt( |  1153     canvas->DrawStringInt( | 
|  1168         textfield_->placeholder_text(), |  1154         textfield_->placeholder_text(), | 
|  1169         GetRenderText()->GetFont(), |  1155         GetRenderText()->GetPrimaryFont(), | 
|  1170         textfield_->placeholder_text_color(), |  1156         textfield_->placeholder_text_color(), | 
|  1171         GetRenderText()->display_rect()); |  1157         GetRenderText()->display_rect()); | 
|  1172   } |  1158   } | 
|  1173   canvas->Restore(); |  1159   canvas->Restore(); | 
|  1174 } |  1160 } | 
|  1175  |  1161  | 
|  1176 bool NativeTextfieldViews::HandleKeyEvent(const ui::KeyEvent& key_event) { |  1162 bool NativeTextfieldViews::HandleKeyEvent(const ui::KeyEvent& key_event) { | 
|  1177   // TODO(oshima): Refactor and consolidate with ExecuteCommand. |  1163   // TODO(oshima): Refactor and consolidate with ExecuteCommand. | 
|  1178   if (key_event.type() == ui::ET_KEY_PRESSED) { |  1164   if (key_event.type() == ui::ET_KEY_PRESSED) { | 
|  1179     ui::KeyboardCode key_code = key_event.key_code(); |  1165     ui::KeyboardCode key_code = key_event.key_code(); | 
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|  1508   if (index != -1) { |  1494   if (index != -1) { | 
|  1509     obscured_reveal_timer_.Start( |  1495     obscured_reveal_timer_.Start( | 
|  1510         FROM_HERE, |  1496         FROM_HERE, | 
|  1511         duration, |  1497         duration, | 
|  1512         base::Bind(&NativeTextfieldViews::RevealObscuredChar, |  1498         base::Bind(&NativeTextfieldViews::RevealObscuredChar, | 
|  1513                    base::Unretained(this), -1, base::TimeDelta())); |  1499                    base::Unretained(this), -1, base::TimeDelta())); | 
|  1514   } |  1500   } | 
|  1515 } |  1501 } | 
|  1516  |  1502  | 
|  1517 }  // namespace views |  1503 }  // namespace views | 
| OLD | NEW |