Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / chrome / browser / chromeos / options / passphrase_textfield.cc
blob8267edf5046678cbe4c96755cd855b3eb2b0112a
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"
9 namespace chromeos {
11 PassphraseTextfield::PassphraseTextfield()
12 : Textfield(),
13 show_fake_(false),
14 changed_(true) {
15 SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
18 void PassphraseTextfield::SetShowFake(bool show_fake) {
19 show_fake_ = show_fake;
20 if (show_fake_)
21 SetFakePassphrase();
22 else
23 ClearFakePassphrase();
26 void PassphraseTextfield::OnFocus() {
27 // If showing the fake password, then clear it when focused.
28 if (show_fake_ && !changed_)
29 ClearFakePassphrase();
30 Textfield::OnFocus();
33 void PassphraseTextfield::OnBlur() {
34 // If password is not changed, then show the fake password when blurred.
35 if (show_fake_ && text().empty())
36 SetFakePassphrase();
37 Textfield::OnBlur();
40 std::string PassphraseTextfield::GetPassphrase() {
41 return changed_ ? base::UTF16ToUTF8(text()) : std::string();
44 void PassphraseTextfield::SetFakePassphrase() {
45 CR_DEFINE_STATIC_LOCAL(base::string16, fake_passphrase,
46 (base::ASCIIToUTF16("********")));
47 SetText(fake_passphrase);
48 changed_ = false;
51 void PassphraseTextfield::ClearFakePassphrase() {
52 SetText(base::string16());
53 changed_ = true;
56 } // namespace chromeos