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
3 // found in the LICENSE file.
5 #include "chrome/browser/chromeos/options/passphrase_textfield.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "ui/views/ime/input_method.h"
12 PassphraseTextfield::PassphraseTextfield()
16 SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD
);
19 void PassphraseTextfield::SetShowFake(bool show_fake
) {
20 show_fake_
= show_fake
;
24 ClearFakePassphrase();
27 void PassphraseTextfield::OnFocus() {
28 // If showing the fake password, then clear it when focused.
29 if (show_fake_
&& !changed_
)
30 ClearFakePassphrase();
32 GetInputMethod()->OnFocus();
35 void PassphraseTextfield::OnBlur() {
36 // If password is not changed, then show the fake password when blurred.
37 if (show_fake_
&& text().empty())
40 GetInputMethod()->OnFocus();
43 std::string
PassphraseTextfield::GetPassphrase() {
44 return changed_
? base::UTF16ToUTF8(text()) : std::string();
47 void PassphraseTextfield::SetFakePassphrase() {
48 CR_DEFINE_STATIC_LOCAL(base::string16
, fake_passphrase
,
49 (base::ASCIIToUTF16("********")));
50 SetText(fake_passphrase
);
54 void PassphraseTextfield::ClearFakePassphrase() {
55 SetText(base::string16());
59 } // namespace chromeos