root/chrome/browser/chromeos/options/passphrase_textfield.cc

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. changed_
  2. SetShowFake
  3. OnFocus
  4. OnBlur
  5. GetPassphrase
  6. SetFakePassphrase
  7. ClearFakePassphrase

// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/options/passphrase_textfield.h"

#include "base/strings/utf_string_conversions.h"

namespace chromeos {

PassphraseTextfield::PassphraseTextfield()
    : Textfield(),
      show_fake_(false),
      changed_(true) {
  SetTextInputType(ui::TEXT_INPUT_TYPE_PASSWORD);
}

void PassphraseTextfield::SetShowFake(bool show_fake) {
  show_fake_ = show_fake;
  if (show_fake_)
    SetFakePassphrase();
  else
    ClearFakePassphrase();
}

void PassphraseTextfield::OnFocus() {
  // If showing the fake password, then clear it when focused.
  if (show_fake_ && !changed_)
    ClearFakePassphrase();
  Textfield::OnFocus();
}

void PassphraseTextfield::OnBlur() {
  // If password is not changed, then show the fake password when blurred.
  if (show_fake_ && text().empty())
    SetFakePassphrase();
  Textfield::OnBlur();
}

std::string PassphraseTextfield::GetPassphrase() {
  return changed_ ? base::UTF16ToUTF8(text()) : std::string();
}

void PassphraseTextfield::SetFakePassphrase() {
  CR_DEFINE_STATIC_LOCAL(base::string16, fake_passphrase,
      (base::ASCIIToUTF16("********")));
  SetText(fake_passphrase);
  changed_ = false;
}

void PassphraseTextfield::ClearFakePassphrase() {
  SetText(base::string16());
  changed_ = true;
}

}  // namespace chromeos

/* [<][>][^][v][top][bottom][index][help] */