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/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 | 9 |
9 #include "base/bind.h" | 10 #include "base/bind.h" |
10 #include "base/command_line.h" | 11 #include "base/command_line.h" |
11 #include "base/debug/trace_event.h" | 12 #include "base/debug/trace_event.h" |
12 #include "base/i18n/case_conversion.h" | 13 #include "base/i18n/case_conversion.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
15 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
16 #include "grit/app_locale_settings.h" | 17 #include "grit/app_locale_settings.h" |
17 #include "grit/ui_strings.h" | 18 #include "grit/ui_strings.h" |
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
823 !textfield_->use_default_background_color() && | 824 !textfield_->use_default_background_color() && |
824 SkColorGetA(textfield_->background_color()) != 0xFF); | 825 SkColorGetA(textfield_->background_color()) != 0xFF); |
825 GetRenderText()->set_cursor_visible(is_drop_cursor_visible_ || | 826 GetRenderText()->set_cursor_visible(is_drop_cursor_visible_ || |
826 (is_cursor_visible_ && !model_->HasSelection())); | 827 (is_cursor_visible_ && !model_->HasSelection())); |
827 GetRenderText()->set_cursor_color( | 828 GetRenderText()->set_cursor_color( |
828 textfield_->use_default_cursor_color() ? | 829 textfield_->use_default_cursor_color() ? |
829 kDefaultCursorColor : | 830 kDefaultCursorColor : |
830 textfield_->cursor_color()); | 831 textfield_->cursor_color()); |
831 // Draw the text, cursor, and selection. | 832 // Draw the text, cursor, and selection. |
832 GetRenderText()->Draw(canvas); | 833 GetRenderText()->Draw(canvas); |
| 834 |
| 835 // Draw placeholder text if needed. |
| 836 if (model_->GetText().empty() && |
| 837 !textfield_->placeholder_text().empty()) { |
| 838 canvas->DrawStringInt( |
| 839 textfield_->placeholder_text(), |
| 840 GetRenderText()->GetFont(), |
| 841 textfield_->placeholder_text_color(), |
| 842 GetRenderText()->display_rect()); |
| 843 } |
833 canvas->Restore(); | 844 canvas->Restore(); |
834 } | 845 } |
835 | 846 |
836 bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) { | 847 bool NativeTextfieldViews::HandleKeyEvent(const KeyEvent& key_event) { |
837 // TODO(oshima): Refactor and consolidate with ExecuteCommand. | 848 // TODO(oshima): Refactor and consolidate with ExecuteCommand. |
838 if (key_event.type() == ui::ET_KEY_PRESSED) { | 849 if (key_event.type() == ui::ET_KEY_PRESSED) { |
839 ui::KeyboardCode key_code = key_event.key_code(); | 850 ui::KeyboardCode key_code = key_event.key_code(); |
840 // TODO(oshima): shift-tab does not work. Figure out why and fix. | 851 // TODO(oshima): shift-tab does not work. Figure out why and fix. |
841 if (key_code == ui::VKEY_TAB) | 852 if (key_code == ui::VKEY_TAB) |
842 return false; | 853 return false; |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1090 } | 1101 } |
1091 } | 1102 } |
1092 | 1103 |
1093 void NativeTextfieldViews::HandleMousePressEvent(const MouseEvent& event) { | 1104 void NativeTextfieldViews::HandleMousePressEvent(const MouseEvent& event) { |
1094 if (event.IsOnlyLeftMouseButton()) { | 1105 if (event.IsOnlyLeftMouseButton()) { |
1095 textfield_->RequestFocus(); | 1106 textfield_->RequestFocus(); |
1096 | 1107 |
1097 initiating_drag_ = false; | 1108 initiating_drag_ = false; |
1098 bool can_drag = true; | 1109 bool can_drag = true; |
1099 | 1110 |
1100 switch(aggregated_clicks_) { | 1111 switch (aggregated_clicks_) { |
1101 case 0: | 1112 case 0: |
1102 if (can_drag && GetRenderText()->IsPointInSelection(event.location())) | 1113 if (can_drag && GetRenderText()->IsPointInSelection(event.location())) |
1103 initiating_drag_ = true; | 1114 initiating_drag_ = true; |
1104 else | 1115 else |
1105 MoveCursorTo(event.location(), event.IsShiftDown()); | 1116 MoveCursorTo(event.location(), event.IsShiftDown()); |
1106 break; | 1117 break; |
1107 case 1: | 1118 case 1: |
1108 model_->SelectWord(); | 1119 model_->SelectWord(); |
1109 OnCaretBoundsChanged(); | 1120 OnCaretBoundsChanged(); |
1110 break; | 1121 break; |
(...skipping 28 matching lines...) Expand all Loading... |
1139 | 1150 |
1140 #if defined(USE_AURA) | 1151 #if defined(USE_AURA) |
1141 // static | 1152 // static |
1142 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( | 1153 NativeTextfieldWrapper* NativeTextfieldWrapper::CreateWrapper( |
1143 Textfield* field) { | 1154 Textfield* field) { |
1144 return new NativeTextfieldViews(field); | 1155 return new NativeTextfieldViews(field); |
1145 } | 1156 } |
1146 #endif | 1157 #endif |
1147 | 1158 |
1148 } // namespace views | 1159 } // namespace views |
OLD | NEW |