summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/browser/chromeos/options/network_config_view.cc12
-rw-r--r--chrome/browser/chromeos/options/network_config_view.h2
-rw-r--r--chrome/browser/chromeos/options/wifi_config_view.cc34
-rw-r--r--chrome/browser/chromeos/options/wifi_config_view.h26
4 files changed, 65 insertions, 9 deletions
diff --git a/chrome/browser/chromeos/options/network_config_view.cc b/chrome/browser/chromeos/options/network_config_view.cc
index 95556ac..783ea80 100644
--- a/chrome/browser/chromeos/options/network_config_view.cc
+++ b/chrome/browser/chromeos/options/network_config_view.cc
@@ -59,6 +59,14 @@ std::wstring NetworkConfigView::GetDialogButtonLabel(
return L"";
}
+bool NetworkConfigView::IsDialogButtonEnabled(
+ MessageBoxFlags::DialogButton button) const {
+ // For login dialogs, disable ok button if nothing entered in text fields.
+ if (flags_ & FLAG_LOGIN_ONLY && button == MessageBoxFlags::DIALOGBUTTON_OK)
+ return wificonfig_view_->can_login();
+ return true;
+}
+
bool NetworkConfigView::Cancel() {
return true;
}
@@ -122,9 +130,9 @@ void NetworkConfigView::Init() {
if (flags_ & FLAG_SHOW_WIFI) {
if (flags_ & FLAG_OTHER_NETWORK)
- wificonfig_view_ = new WifiConfigView();
+ wificonfig_view_ = new WifiConfigView(this);
else
- wificonfig_view_ = new WifiConfigView(wifi_);
+ wificonfig_view_ = new WifiConfigView(this, wifi_);
tabs_->AddTab(
l10n_util::GetString(IDS_OPTIONS_SETTINGS_SECTION_TITLE_WIFI_CONFIG),
wificonfig_view_);
diff --git a/chrome/browser/chromeos/options/network_config_view.h b/chrome/browser/chromeos/options/network_config_view.h
index 92c79a2..f35b2a8 100644
--- a/chrome/browser/chromeos/options/network_config_view.h
+++ b/chrome/browser/chromeos/options/network_config_view.h
@@ -41,6 +41,8 @@ class NetworkConfigView : public views::View,
// views::DialogDelegate methods.
virtual std::wstring GetDialogButtonLabel(
MessageBoxFlags::DialogButton button) const;
+ virtual bool IsDialogButtonEnabled(
+ MessageBoxFlags::DialogButton button) const;
virtual bool Cancel();
virtual bool Accept();
diff --git a/chrome/browser/chromeos/options/wifi_config_view.cc b/chrome/browser/chromeos/options/wifi_config_view.cc
index 25241f9..2e09b8d 100644
--- a/chrome/browser/chromeos/options/wifi_config_view.cc
+++ b/chrome/browser/chromeos/options/wifi_config_view.cc
@@ -6,6 +6,7 @@
#include "app/l10n_util.h"
#include "base/string_util.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"
@@ -16,21 +17,44 @@
namespace chromeos {
-WifiConfigView::WifiConfigView(WifiNetwork wifi)
- : other_network_(false),
+WifiConfigView::WifiConfigView(NetworkConfigView* parent, WifiNetwork wifi)
+ : parent_(parent),
+ other_network_(false),
+ can_login_(false),
wifi_(wifi),
ssid_textfield_(NULL),
passphrase_textfield_(NULL) {
Init();
}
-WifiConfigView::WifiConfigView()
- : other_network_(true),
+WifiConfigView::WifiConfigView(NetworkConfigView* parent)
+ : parent_(parent),
+ other_network_(true),
+ can_login_(false),
ssid_textfield_(NULL),
passphrase_textfield_(NULL) {
Init();
}
+void WifiConfigView::ContentsChanged(views::Textfield* sender,
+ const string16& new_contents) {
+ bool can_login = true;
+ if (other_network_) {
+ // Since the user can try to connect to a non-encrypted hidden network,
+ // only enforce ssid is non-empty.
+ can_login = !ssid_textfield_->text().empty();
+ } else {
+ // Connecting to an encrypted network, so make sure passphrase is non-empty.
+ can_login = !passphrase_textfield_->text().empty();
+ }
+
+ // Update the login button enable/disable state if can_login_ changes.
+ if (can_login != can_login_) {
+ can_login_ = can_login;
+ parent_->GetDialogClientView()->UpdateDialogButtons();
+ }
+}
+
const string16& WifiConfigView::GetSSID() const {
return ssid_textfield_->text();
}
@@ -62,6 +86,7 @@ void WifiConfigView::Init() {
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SSID)));
if (other_network_) {
ssid_textfield_ = new views::Textfield(views::Textfield::STYLE_DEFAULT);
+ ssid_textfield_->SetController(this);
layout->AddView(ssid_textfield_);
} else {
views::Label* label = new views::Label(ASCIIToWide(wifi_.ssid));
@@ -77,6 +102,7 @@ void WifiConfigView::Init() {
IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSPHRASE)));
passphrase_textfield_ = new views::Textfield(
views::Textfield::STYLE_PASSWORD);
+ passphrase_textfield_->SetController(this);
layout->AddView(passphrase_textfield_);
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 0548bdc..dda8f9f 100644
--- a/chrome/browser/chromeos/options/wifi_config_view.h
+++ b/chrome/browser/chromeos/options/wifi_config_view.h
@@ -14,18 +14,32 @@
namespace chromeos {
+class NetworkConfigView;
+
// A dialog box for showing a password textfield.
-class WifiConfigView : public views::View {
+class WifiConfigView : public views::View,
+ public views::Textfield::Controller {
public:
- explicit WifiConfigView(WifiNetwork wifi);
- explicit WifiConfigView();
+ WifiConfigView(NetworkConfigView* parent, WifiNetwork wifi);
+ explicit WifiConfigView(NetworkConfigView* parent);
virtual ~WifiConfigView() {}
+ // views::Textfield::Controller methods.
+ virtual void ContentsChanged(views::Textfield* sender,
+ const string16& new_contents);
+ virtual bool HandleKeystroke(views::Textfield* sender,
+ const views::Textfield::Keystroke& keystroke) {
+ return false;
+ }
+
// Get the typed in ssid.
const string16& GetSSID() const;
// Get the typed in passphrase.
const string16& GetPassphrase() const;
+ // Returns true if the textfields are non-empty and we can login.
+ bool can_login() const { return can_login_; }
+
// Focus the first field in the UI.
void FocusFirstField();
@@ -33,8 +47,14 @@ class WifiConfigView : public views::View {
// Initializes UI.
void Init();
+ NetworkConfigView* parent_;
+
bool other_network_;
+ // Whether or not we can log in. This gets recalculated when textfield
+ // contents change.
+ bool can_login_;
+
WifiNetwork wifi_;
views::Textfield* ssid_textfield_;