Chromium Code Reviews| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 254 aggregated_clicks_(0), | 254 aggregated_clicks_(0), |
| 255 drag_start_display_offset_(0), | 255 drag_start_display_offset_(0), |
| 256 touch_handles_hidden_due_to_scroll_(false), | 256 touch_handles_hidden_due_to_scroll_(false), |
| 257 weak_ptr_factory_(this) { | 257 weak_ptr_factory_(this) { |
| 258 set_context_menu_controller(this); | 258 set_context_menu_controller(this); |
| 259 set_drag_controller(this); | 259 set_drag_controller(this); |
| 260 GetRenderText()->SetFontList(GetDefaultFontList()); | 260 GetRenderText()->SetFontList(GetDefaultFontList()); |
| 261 SetBorder(std::unique_ptr<Border>(new FocusableBorder())); | 261 SetBorder(std::unique_ptr<Border>(new FocusableBorder())); |
| 262 SetFocusBehavior(FocusBehavior::ALWAYS); | 262 SetFocusBehavior(FocusBehavior::ALWAYS); |
| 263 | 263 |
| 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 | 264 // These allow BrowserView to pass edit commands from the Chrome menu to us |
| 271 // when we're focused by simply asking the FocusManager to | 265 // when we're focused by simply asking the FocusManager to |
| 272 // ProcessAccelerator() with the relevant accelerators. | 266 // ProcessAccelerator() with the relevant accelerators. |
| 273 AddAccelerator(ui::Accelerator(ui::VKEY_X, ui::EF_CONTROL_DOWN)); | 267 AddAccelerator(ui::Accelerator(ui::VKEY_X, ui::EF_CONTROL_DOWN)); |
| 274 AddAccelerator(ui::Accelerator(ui::VKEY_C, ui::EF_CONTROL_DOWN)); | 268 AddAccelerator(ui::Accelerator(ui::VKEY_C, ui::EF_CONTROL_DOWN)); |
| 275 AddAccelerator(ui::Accelerator(ui::VKEY_V, ui::EF_CONTROL_DOWN)); | 269 AddAccelerator(ui::Accelerator(ui::VKEY_V, ui::EF_CONTROL_DOWN)); |
| 276 } | 270 } |
| 277 | 271 |
| 278 Textfield::~Textfield() { | 272 Textfield::~Textfield() { |
| 279 if (GetInputMethod()) { | 273 if (GetInputMethod()) { |
| (...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1284 // care about. | 1278 // care about. |
| 1285 const base::char16 ch = event.GetCharacter(); | 1279 const base::char16 ch = event.GetCharacter(); |
| 1286 const bool should_insert_char = ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && | 1280 const bool should_insert_char = ((ch >= 0x20 && ch < 0x7F) || ch > 0x9F) && |
| 1287 !ui::IsSystemKeyModifier(event.flags()); | 1281 !ui::IsSystemKeyModifier(event.flags()); |
| 1288 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE || !should_insert_char) | 1282 if (GetTextInputType() == ui::TEXT_INPUT_TYPE_NONE || !should_insert_char) |
| 1289 return; | 1283 return; |
| 1290 | 1284 |
| 1291 DoInsertChar(ch); | 1285 DoInsertChar(ch); |
| 1292 | 1286 |
| 1293 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD && | 1287 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD && |
| 1294 !password_reveal_duration_.is_zero()) { | 1288 !GetPasswordRevealDuration().is_zero()) { |
| 1295 const size_t change_offset = model_->GetCursorPosition(); | 1289 const size_t change_offset = model_->GetCursorPosition(); |
| 1296 DCHECK_GT(change_offset, 0u); | 1290 DCHECK_GT(change_offset, 0u); |
| 1297 RevealPasswordChar(change_offset - 1); | 1291 RevealPasswordChar(change_offset - 1); |
| 1298 } | 1292 } |
| 1299 } | 1293 } |
| 1300 | 1294 |
| 1301 ui::TextInputType Textfield::GetTextInputType() const { | 1295 ui::TextInputType Textfield::GetTextInputType() const { |
| 1302 if (read_only() || !enabled()) | 1296 if (read_only() || !enabled()) |
| 1303 return ui::TEXT_INPUT_TYPE_NONE; | 1297 return ui::TEXT_INPUT_TYPE_NONE; |
| 1304 return text_input_type_; | 1298 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. | 1972 // Disallow input method editing of password fields. |
| 1979 ui::TextInputType t = GetTextInputType(); | 1973 ui::TextInputType t = GetTextInputType(); |
| 1980 return (t != ui::TEXT_INPUT_TYPE_NONE && t != ui::TEXT_INPUT_TYPE_PASSWORD); | 1974 return (t != ui::TEXT_INPUT_TYPE_NONE && t != ui::TEXT_INPUT_TYPE_PASSWORD); |
| 1981 } | 1975 } |
| 1982 | 1976 |
| 1983 void Textfield::RevealPasswordChar(int index) { | 1977 void Textfield::RevealPasswordChar(int index) { |
| 1984 GetRenderText()->SetObscuredRevealIndex(index); | 1978 GetRenderText()->SetObscuredRevealIndex(index); |
| 1985 SchedulePaint(); | 1979 SchedulePaint(); |
| 1986 | 1980 |
| 1987 if (index != -1) { | 1981 if (index != -1) { |
| 1988 password_reveal_timer_.Start(FROM_HERE, password_reveal_duration_, | 1982 password_reveal_timer_.Start(FROM_HERE, GetPasswordRevealDuration(), |
| 1989 base::Bind(&Textfield::RevealPasswordChar, | 1983 base::Bind(&Textfield::RevealPasswordChar, |
| 1990 weak_ptr_factory_.GetWeakPtr(), -1)); | 1984 weak_ptr_factory_.GetWeakPtr(), -1)); |
| 1991 } | 1985 } |
| 1992 } | 1986 } |
| 1993 | 1987 |
| 1994 void Textfield::CreateTouchSelectionControllerAndNotifyIt() { | 1988 void Textfield::CreateTouchSelectionControllerAndNotifyIt() { |
| 1995 if (!HasFocus()) | 1989 if (!HasFocus()) |
| 1996 return; | 1990 return; |
| 1997 | 1991 |
| 1998 if (!touch_selection_controller_) { | 1992 if (!touch_selection_controller_) { |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 2024 if (!HasFocus()) | 2018 if (!HasFocus()) |
| 2025 RequestFocus(); | 2019 RequestFocus(); |
| 2026 model_->MoveCursorTo(mouse); | 2020 model_->MoveCursorTo(mouse); |
| 2027 if (!selection_clipboard_text.empty()) { | 2021 if (!selection_clipboard_text.empty()) { |
| 2028 model_->InsertText(selection_clipboard_text); | 2022 model_->InsertText(selection_clipboard_text); |
| 2029 UpdateAfterChange(true, true); | 2023 UpdateAfterChange(true, true); |
| 2030 } | 2024 } |
| 2031 OnAfterUserAction(); | 2025 OnAfterUserAction(); |
| 2032 } | 2026 } |
| 2033 | 2027 |
| 2028 base::TimeDelta Textfield::GetPasswordRevealDuration() { | |
|
sky
2016/08/26 19:02:52
Make this an anonymous function and move to namesp
xiyuan
2016/08/26 19:45:40
Done.
| |
| 2029 return ViewsDelegate::GetInstance() | |
| 2030 ? ViewsDelegate::GetInstance() | |
| 2031 ->GetTextfieldPasswordRevealDuration() | |
| 2032 : base::TimeDelta(); | |
| 2033 } | |
| 2034 | |
| 2034 } // namespace views | 2035 } // namespace views |
| OLD | NEW |