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/textfield.h" | 5 #include "ui/views/controls/textfield/textfield.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 // The DELETE menu action only works in case of an active selection. | 205 // The DELETE menu action only works in case of an active selection. |
206 if (has_selection) | 206 if (has_selection) |
207 return ui::TextEditCommand::DELETE_FORWARD; | 207 return ui::TextEditCommand::DELETE_FORWARD; |
208 break; | 208 break; |
209 case IDS_APP_SELECT_ALL: | 209 case IDS_APP_SELECT_ALL: |
210 return ui::TextEditCommand::SELECT_ALL; | 210 return ui::TextEditCommand::SELECT_ALL; |
211 } | 211 } |
212 return ui::TextEditCommand::INVALID_COMMAND; | 212 return ui::TextEditCommand::INVALID_COMMAND; |
213 } | 213 } |
214 | 214 |
| 215 base::TimeDelta GetPasswordRevealDuration() { |
| 216 return ViewsDelegate::GetInstance() |
| 217 ? ViewsDelegate::GetInstance() |
| 218 ->GetTextfieldPasswordRevealDuration() |
| 219 : base::TimeDelta(); |
| 220 } |
| 221 |
215 } // namespace | 222 } // namespace |
216 | 223 |
217 // static | 224 // static |
218 const char Textfield::kViewClassName[] = "Textfield"; | 225 const char Textfield::kViewClassName[] = "Textfield"; |
219 const int Textfield::kTextPadding = 3; | 226 const int Textfield::kTextPadding = 3; |
220 | 227 |
221 // static | 228 // static |
222 size_t Textfield::GetCaretBlinkMs() { | 229 size_t Textfield::GetCaretBlinkMs() { |
223 static const size_t default_value = 500; | 230 static const size_t default_value = 500; |
224 #if defined(OS_WIN) | 231 #if defined(OS_WIN) |
(...skipping 29 matching lines...) Expand all Loading... |
254 aggregated_clicks_(0), | 261 aggregated_clicks_(0), |
255 drag_start_display_offset_(0), | 262 drag_start_display_offset_(0), |
256 touch_handles_hidden_due_to_scroll_(false), | 263 touch_handles_hidden_due_to_scroll_(false), |
257 weak_ptr_factory_(this) { | 264 weak_ptr_factory_(this) { |
258 set_context_menu_controller(this); | 265 set_context_menu_controller(this); |
259 set_drag_controller(this); | 266 set_drag_controller(this); |
260 GetRenderText()->SetFontList(GetDefaultFontList()); | 267 GetRenderText()->SetFontList(GetDefaultFontList()); |
261 SetBorder(std::unique_ptr<Border>(new FocusableBorder())); | 268 SetBorder(std::unique_ptr<Border>(new FocusableBorder())); |
262 SetFocusBehavior(FocusBehavior::ALWAYS); | 269 SetFocusBehavior(FocusBehavior::ALWAYS); |
263 | 270 |
264 if (ViewsDelegate::GetInstance()) { | |
265 password_reveal_duration_ = | |
266 ViewsDelegate::GetInstance() | |
267 ->GetDefaultTextfieldObscuredRevealDuration(); | |
268 } | |
269 | |
270 // These allow BrowserView to pass edit commands from the Chrome menu to us | 271 // These allow BrowserView to pass edit commands from the Chrome menu to us |
271 // when we're focused by simply asking the FocusManager to | 272 // when we're focused by simply asking the FocusManager to |
272 // ProcessAccelerator() with the relevant accelerators. | 273 // ProcessAccelerator() with the relevant accelerators. |
273 AddAccelerator(ui::Accelerator(ui::VKEY_X, ui::EF_CONTROL_DOWN)); | 274 AddAccelerator(ui::Accelerator(ui::VKEY_X, ui::EF_CONTROL_DOWN)); |
274 AddAccelerator(ui::Accelerator(ui::VKEY_C, ui::EF_CONTROL_DOWN)); | 275 AddAccelerator(ui::Accelerator(ui::VKEY_C, ui::EF_CONTROL_DOWN)); |
275 AddAccelerator(ui::Accelerator(ui::VKEY_V, ui::EF_CONTROL_DOWN)); | 276 AddAccelerator(ui::Accelerator(ui::VKEY_V, ui::EF_CONTROL_DOWN)); |
276 } | 277 } |
277 | 278 |
278 Textfield::~Textfield() { | 279 Textfield::~Textfield() { |
279 if (GetInputMethod()) { | 280 if (GetInputMethod()) { |
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1284 // care about. | 1285 // care about. |
1285 const base::char16 ch = event.GetCharacter(); | 1286 const base::char16 ch = event.GetCharacter(); |
1286 const bool should_insert_char = ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && | 1287 const bool should_insert_char = ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && |
1287 !ui::IsSystemKeyModifier(event.flags()); | 1288 !ui::IsSystemKeyModifier(event.flags()); |
1288 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE || !should_insert_char) | 1289 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE || !should_insert_char) |
1289 return; | 1290 return; |
1290 | 1291 |
1291 DoInsertChar(ch); | 1292 DoInsertChar(ch); |
1292 | 1293 |
1293 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD && | 1294 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD && |
1294 !password_reveal_duration_.is_zero()) { | 1295 !GetPasswordRevealDuration().is_zero()) { |
1295 const size_t change_offset = model_->GetCursorPosition(); | 1296 const size_t change_offset = model_->GetCursorPosition(); |
1296 DCHECK_GT(change_offset, 0u); | 1297 DCHECK_GT(change_offset, 0u); |
1297 RevealPasswordChar(change_offset - 1); | 1298 RevealPasswordChar(change_offset - 1); |
1298 } | 1299 } |
1299 } | 1300 } |
1300 | 1301 |
1301 ui::TextInputType Textfield::GetTextInputType() const { | 1302 ui::TextInputType Textfield::GetTextInputType() const { |
1302 if (read_only() || !enabled()) | 1303 if (read_only() || !enabled()) |
1303 return ui::TEXT_INPUT_TYPE_NONE; | 1304 return ui::TEXT_INPUT_TYPE_NONE; |
1304 return text_input_type_; | 1305 return text_input_type_; |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1978 // Disallow input method editing of password fields. | 1979 // Disallow input method editing of password fields. |
1979 ui::TextInputType t = GetTextInputType(); | 1980 ui::TextInputType t = GetTextInputType(); |
1980 return (t != ui::TEXT_INPUT_TYPE_NONE && t != ui::TEXT_INPUT_TYPE_PASSWORD); | 1981 return (t != ui::TEXT_INPUT_TYPE_NONE && t != ui::TEXT_INPUT_TYPE_PASSWORD); |
1981 } | 1982 } |
1982 | 1983 |
1983 void Textfield::RevealPasswordChar(int index) { | 1984 void Textfield::RevealPasswordChar(int index) { |
1984 GetRenderText()->SetObscuredRevealIndex(index); | 1985 GetRenderText()->SetObscuredRevealIndex(index); |
1985 SchedulePaint(); | 1986 SchedulePaint(); |
1986 | 1987 |
1987 if (index != -1) { | 1988 if (index != -1) { |
1988 password_reveal_timer_.Start(FROM_HERE, password_reveal_duration_, | 1989 password_reveal_timer_.Start(FROM_HERE, GetPasswordRevealDuration(), |
1989 base::Bind(&Textfield::RevealPasswordChar, | 1990 base::Bind(&Textfield::RevealPasswordChar, |
1990 weak_ptr_factory_.GetWeakPtr(), -1)); | 1991 weak_ptr_factory_.GetWeakPtr(), -1)); |
1991 } | 1992 } |
1992 } | 1993 } |
1993 | 1994 |
1994 void Textfield::CreateTouchSelectionControllerAndNotifyIt() { | 1995 void Textfield::CreateTouchSelectionControllerAndNotifyIt() { |
1995 if (!HasFocus()) | 1996 if (!HasFocus()) |
1996 return; | 1997 return; |
1997 | 1998 |
1998 if (!touch_selection_controller_) { | 1999 if (!touch_selection_controller_) { |
(...skipping 26 matching lines...) Expand all Loading... |
2025 RequestFocus(); | 2026 RequestFocus(); |
2026 model_->MoveCursorTo(mouse); | 2027 model_->MoveCursorTo(mouse); |
2027 if (!selection_clipboard_text.empty()) { | 2028 if (!selection_clipboard_text.empty()) { |
2028 model_->InsertText(selection_clipboard_text); | 2029 model_->InsertText(selection_clipboard_text); |
2029 UpdateAfterChange(true, true); | 2030 UpdateAfterChange(true, true); |
2030 } | 2031 } |
2031 OnAfterUserAction(); | 2032 OnAfterUserAction(); |
2032 } | 2033 } |
2033 | 2034 |
2034 } // namespace views | 2035 } // namespace views |
OLD | NEW |