summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/password_dialog_view.cc
blob: 0d6f8a03c90740b2b9546b1ad49043a50381c0ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) 2009 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/password_dialog_view.h"

#include "app/l10n_util.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
#include "views/controls/textfield/textfield.h"
#include "views/window/window.h"

namespace chromeos {

PasswordDialogView::PasswordDialogView(PasswordDialogDelegate* delegate,
                                       const std::string& ssid)
    : delegate_(delegate),
      ssid_(ssid),
      password_textfield_(NULL) {
}

std::wstring PasswordDialogView::GetWindowTitle() const {
  return l10n_util::GetString(IDS_OPTIONS_SETTINGS_SECTION_TITLE_PASSWORD);
}

bool PasswordDialogView::Cancel() {
  return delegate_->OnPasswordDialogCancel();
}

bool PasswordDialogView::Accept() {
  // TODO(chocobo): We should not need to call SyncText ourself here.
  password_textfield_->SyncText();
  return delegate_->OnPasswordDialogAccept(ssid_, password_textfield_->text());
}

static const int kDialogPadding = 7;

void PasswordDialogView::Layout() {
  gfx::Size sz = password_textfield_->GetPreferredSize();
  password_textfield_->SetBounds(kDialogPadding, kDialogPadding,
                                 width() - 2*kDialogPadding,
                                 sz.height());
}

gfx::Size PasswordDialogView::GetPreferredSize() {
  // TODO(chocobo): Create our own localized content size once the UI is done.
  return gfx::Size(views::Window::GetLocalizedContentsSize(
      IDS_IMPORTLOCK_DIALOG_WIDTH_CHARS,
      IDS_IMPORTLOCK_DIALOG_HEIGHT_LINES));
}

void PasswordDialogView::ViewHierarchyChanged(bool is_add,
                                              views::View* parent,
                                              views::View* child) {
  if (is_add && child == this)
    Init();
}

void PasswordDialogView::Init() {
  password_textfield_ = new views::Textfield(views::Textfield::STYLE_PASSWORD);
  AddChildView(password_textfield_);
}

}  // namespace chromeos