summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchocobo@chromium.org <chocobo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-19 19:32:20 +0000
committerchocobo@chromium.org <chocobo@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-19 19:32:20 +0000
commit95b7d5ff5805da8d26b83abe41e93a27cfb41bcd (patch)
tree786f43567b4f11db3a70e74ad6933e3bd999534f
parentfdd126a9d582d6804d5a3ec41aae5b4b334a43c1 (diff)
downloadchromium_src-95b7d5ff5805da8d26b83abe41e93a27cfb41bcd.zip
chromium_src-95b7d5ff5805da8d26b83abe41e93a27cfb41bcd.tar.gz
chromium_src-95b7d5ff5805da8d26b83abe41e93a27cfb41bcd.tar.bz2
Add ability to show/hide password in login dialog.
BUG=none TEST=open login dialog, type in password, and click on the lock image to toggle showing password. Review URL: http://codereview.chromium.org/1113004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@42133 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/chromeos/options/wifi_config_view.cc23
-rw-r--r--chrome/browser/chromeos/options/wifi_config_view.h7
-rw-r--r--views/controls/textfield/native_textfield_gtk.cc14
-rw-r--r--views/controls/textfield/native_textfield_gtk.h1
-rw-r--r--views/controls/textfield/native_textfield_win.cc5
-rw-r--r--views/controls/textfield/native_textfield_win.h1
-rw-r--r--views/controls/textfield/native_textfield_wrapper.h5
-rw-r--r--views/controls/textfield/textfield.cc12
-rw-r--r--views/controls/textfield/textfield.h3
9 files changed, 63 insertions, 8 deletions
diff --git a/chrome/browser/chromeos/options/wifi_config_view.cc b/chrome/browser/chromeos/options/wifi_config_view.cc
index 0be42d7..66031fe 100644
--- a/chrome/browser/chromeos/options/wifi_config_view.cc
+++ b/chrome/browser/chromeos/options/wifi_config_view.cc
@@ -5,11 +5,14 @@
#include "chrome/browser/chromeos/options/wifi_config_view.h"
#include "app/l10n_util.h"
+#include "app/resource_bundle.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/chromeos/options/network_config_view.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
+#include "grit/theme_resources.h"
+#include "views/controls/button/image_button.h"
#include "views/controls/label.h"
#include "views/grid_layout.h"
#include "views/standard_layout.h"
@@ -55,6 +58,13 @@ void WifiConfigView::ContentsChanged(views::Textfield* sender,
}
}
+void WifiConfigView::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ // We only have one button to toggle password visible.
+ if (passphrase_textfield_)
+ passphrase_textfield_->SetPassword(!passphrase_textfield_->IsPassword());
+}
+
const string16& WifiConfigView::GetSSID() const {
return ssid_textfield_->text();
}
@@ -76,10 +86,15 @@ void WifiConfigView::Init() {
int column_view_set_id = 0;
views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id);
+ // Label
column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,
views::GridLayout::USE_PREF, 0, 0);
+ // Textfield
column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
views::GridLayout::USE_PREF, 0, 200);
+ // Password visible button
+ column_set->AddColumn(views::GridLayout::CENTER, views::GridLayout::FILL, 1,
+ views::GridLayout::USE_PREF, 0, 0);
layout->StartRow(0, column_view_set_id);
layout->AddView(new views::Label(l10n_util::GetString(
@@ -106,6 +121,14 @@ void WifiConfigView::Init() {
if (!wifi_.passphrase.empty())
passphrase_textfield_->SetText(UTF8ToUTF16(wifi_.passphrase));
layout->AddView(passphrase_textfield_);
+ // Password visible button.
+ views::ImageButton* button = new views::ImageButton(this);
+ button->SetImage(views::ImageButton::BS_NORMAL,
+ ResourceBundle::GetSharedInstance().GetBitmapNamed(
+ IDR_STATUSBAR_NETWORK_SECURE));
+ button->SetImageAlignment(views::ImageButton::ALIGN_CENTER,
+ views::ImageButton::ALIGN_MIDDLE);
+ layout->AddView(button);
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
}
}
diff --git a/chrome/browser/chromeos/options/wifi_config_view.h b/chrome/browser/chromeos/options/wifi_config_view.h
index dda8f9f..baec65f 100644
--- a/chrome/browser/chromeos/options/wifi_config_view.h
+++ b/chrome/browser/chromeos/options/wifi_config_view.h
@@ -9,6 +9,7 @@
#include "base/string16.h"
#include "chrome/browser/chromeos/cros/network_library.h"
+#include "views/controls/button/button.h"
#include "views/controls/textfield/textfield.h"
#include "views/view.h"
@@ -18,7 +19,8 @@ class NetworkConfigView;
// A dialog box for showing a password textfield.
class WifiConfigView : public views::View,
- public views::Textfield::Controller {
+ public views::Textfield::Controller,
+ public views::ButtonListener {
public:
WifiConfigView(NetworkConfigView* parent, WifiNetwork wifi);
explicit WifiConfigView(NetworkConfigView* parent);
@@ -32,6 +34,9 @@ class WifiConfigView : public views::View,
return false;
}
+ // views::ButtonListener
+ virtual void ButtonPressed(views::Button* sender, const views::Event& event);
+
// Get the typed in ssid.
const string16& GetSSID() const;
// Get the typed in passphrase.
diff --git a/views/controls/textfield/native_textfield_gtk.cc b/views/controls/textfield/native_textfield_gtk.cc
index 5580786..0dac9a4 100644
--- a/views/controls/textfield/native_textfield_gtk.cc
+++ b/views/controls/textfield/native_textfield_gtk.cc
@@ -129,6 +129,13 @@ void NativeTextfieldGtk::UpdateFont() {
pango_font_description_free(pfd);
}
+void NativeTextfieldGtk::UpdateIsPassword() {
+ if (!native_view())
+ return;
+ gtk_entry_set_visibility(GTK_ENTRY(native_view()),
+ !textfield_->IsPassword());
+}
+
void NativeTextfieldGtk::UpdateEnabled() {
if (!native_view())
return;
@@ -234,11 +241,8 @@ gboolean NativeTextfieldGtk::OnChanged() {
void NativeTextfieldGtk::CreateNativeControl() {
NativeControlCreated(gtk_entry_new());
- if (textfield_->IsPassword()) {
- gtk_entry_set_invisible_char(GTK_ENTRY(native_view()),
- static_cast<gunichar>(kPasswordChar));
- gtk_entry_set_visibility(GTK_ENTRY(native_view()), false);
- }
+ gtk_entry_set_invisible_char(GTK_ENTRY(native_view()),
+ static_cast<gunichar>(kPasswordChar));
}
void NativeTextfieldGtk::NativeControlCreated(GtkWidget* widget) {
diff --git a/views/controls/textfield/native_textfield_gtk.h b/views/controls/textfield/native_textfield_gtk.h
index 10cb7f2..7622521 100644
--- a/views/controls/textfield/native_textfield_gtk.h
+++ b/views/controls/textfield/native_textfield_gtk.h
@@ -31,6 +31,7 @@ class NativeTextfieldGtk : public NativeControlGtk,
virtual void UpdateBackgroundColor();
virtual void UpdateReadOnly();
virtual void UpdateFont();
+ virtual void UpdateIsPassword();
virtual void UpdateEnabled();
virtual gfx::Insets CalculateInsets();
virtual void SetHorizontalMargins(int left, int right);
diff --git a/views/controls/textfield/native_textfield_win.cc b/views/controls/textfield/native_textfield_win.cc
index a405430..9f2392f 100644
--- a/views/controls/textfield/native_textfield_win.cc
+++ b/views/controls/textfield/native_textfield_win.cc
@@ -204,6 +204,11 @@ void NativeTextfieldWin::UpdateFont() {
UpdateTextColor();
}
+void NativeTextfieldWin::UpdateIsPassword() {
+ // TODO: Need to implement for Windows.
+ NOTIMPLEMENTED();
+}
+
void NativeTextfieldWin::UpdateEnabled() {
SendMessage(m_hWnd, WM_ENABLE, textfield_->IsEnabled(), 0);
}
diff --git a/views/controls/textfield/native_textfield_win.h b/views/controls/textfield/native_textfield_win.h
index 8025597..78339e3 100644
--- a/views/controls/textfield/native_textfield_win.h
+++ b/views/controls/textfield/native_textfield_win.h
@@ -55,6 +55,7 @@ class NativeTextfieldWin
virtual void UpdateBackgroundColor();
virtual void UpdateReadOnly();
virtual void UpdateFont();
+ virtual void UpdateIsPassword();
virtual void UpdateEnabled();
virtual gfx::Insets CalculateInsets();
virtual void SetHorizontalMargins(int left, int right);
diff --git a/views/controls/textfield/native_textfield_wrapper.h b/views/controls/textfield/native_textfield_wrapper.h
index 49d7a0e..aa21d85 100644
--- a/views/controls/textfield/native_textfield_wrapper.h
+++ b/views/controls/textfield/native_textfield_wrapper.h
@@ -61,6 +61,9 @@ class NativeTextfieldWrapper {
// Updates the font used to render text in the native text field.
virtual void UpdateFont() = 0;
+ // Updates the visibility of the text in the native text field.
+ virtual void UpdateIsPassword() = 0;
+
// Updates the enabled state of the native text field.
virtual void UpdateEnabled() = 0;
@@ -85,4 +88,4 @@ class NativeTextfieldWrapper {
} // namespace views
-#endif // #ifndef VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WRAPPER_H_
+#endif // VIEWS_CONTROLS_TEXTFIELD_NATIVE_TEXTFIELD_WRAPPER_H_
diff --git a/views/controls/textfield/textfield.cc b/views/controls/textfield/textfield.cc
index 7f7251b..8f6486f 100644
--- a/views/controls/textfield/textfield.cc
+++ b/views/controls/textfield/textfield.cc
@@ -8,6 +8,8 @@
#include <gdk/gdkkeysyms.h>
#endif
+#include <string>
+
#include "base/keyboard_codes.h"
#include "base/string_util.h"
#include "gfx/insets.h"
@@ -89,6 +91,15 @@ bool Textfield::IsPassword() const {
return style_ & STYLE_PASSWORD;
}
+void Textfield::SetPassword(bool password) {
+ if (password)
+ style_ = static_cast<StyleFlags>(style_ | STYLE_PASSWORD);
+ else
+ style_ = static_cast<StyleFlags>(style_ & ~STYLE_PASSWORD);
+ if (native_wrapper_)
+ native_wrapper_->UpdateIsPassword();
+}
+
bool Textfield::IsMultiLine() const {
return !!(style_ & STYLE_MULTILINE);
}
@@ -295,6 +306,7 @@ void Textfield::ViewHierarchyChanged(bool is_add, View* parent, View* child) {
native_wrapper_->UpdateFont();
native_wrapper_->UpdateEnabled();
native_wrapper_->UpdateBorder();
+ native_wrapper_->UpdateIsPassword();
#if defined(OS_WIN)
// TODO(beng): remove this once NativeTextfieldWin subclasses
diff --git a/views/controls/textfield/textfield.h b/views/controls/textfield/textfield.h
index b20f9ec..7b9c393 100644
--- a/views/controls/textfield/textfield.h
+++ b/views/controls/textfield/textfield.h
@@ -111,8 +111,9 @@ class Textfield : public View {
bool read_only() const { return read_only_; }
void SetReadOnly(bool read_only);
- // Returns true if the Textfield is a password field.
+ // Gets/Sets whether or not this Textfield is a password field.
bool IsPassword() const;
+ void SetPassword(bool password);
// Whether the text field is multi-line or not, must be set when the text
// field is created, using StyleFlags.