summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
authorchocobo@google.com <chocobo@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-25 22:39:23 +0000
committerchocobo@google.com <chocobo@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-25 22:39:23 +0000
commite9b2727fd53475a42d0fc1acd310d63641a544f6 (patch)
treee2ef5704760b69aa194761de7eecc61225c05abd /chrome
parentfaa604ed475fe52732041197d1218150fccd801c (diff)
downloadchromium_src-e9b2727fd53475a42d0fc1acd310d63641a544f6.zip
chromium_src-e9b2727fd53475a42d0fc1acd310d63641a544f6.tar.gz
chromium_src-e9b2727fd53475a42d0fc1acd310d63641a544f6.tar.bz2
Add wifi menu button to status bar of Chrome OS. Currently showing mock data as we have not hooked it up to ChromeOS shared library wifi code yet.
TEST=none BUG=23090 Review URL: http://codereview.chromium.org/231014 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27269 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r--chrome/app/generated_resources.grd3
-rw-r--r--chrome/app/theme/statusbar_disconnected.pngbin0 -> 266 bytes
-rw-r--r--chrome/app/theme/statusbar_wifi_1.pngbin0 -> 313 bytes
-rw-r--r--chrome/app/theme/statusbar_wifi_2.pngbin0 -> 381 bytes
-rw-r--r--chrome/app/theme/statusbar_wifi_3.pngbin0 -> 465 bytes
-rw-r--r--chrome/app/theme/statusbar_wifi_4.pngbin0 -> 473 bytes
-rwxr-xr-xchrome/app/theme/statusbar_wifi_5.pngbin0 -> 515 bytes
-rwxr-xr-xchrome/app/theme/statusbar_wifi_6.pngbin0 -> 535 bytes
-rwxr-xr-xchrome/app/theme/statusbar_wifi_7.pngbin0 -> 532 bytes
-rwxr-xr-xchrome/app/theme/statusbar_wifi_8.pngbin0 -> 524 bytes
-rwxr-xr-xchrome/app/theme/statusbar_wired.pngbin0 -> 328 bytes
-rw-r--r--chrome/app/theme/theme_resources.grd10
-rw-r--r--chrome/browser/chromeos/network_menu_button.cc172
-rw-r--r--chrome/browser/chromeos/network_menu_button.h116
-rw-r--r--chrome/browser/chromeos/password_dialog_view.cc59
-rw-r--r--chrome/browser/chromeos/password_dialog_view.h66
-rw-r--r--chrome/browser/chromeos/settings_contents_view.cc115
-rw-r--r--chrome/browser/chromeos/status_area_view.cc11
-rw-r--r--chrome/browser/chromeos/status_area_view.h4
-rw-r--r--chrome/chrome.gyp4
20 files changed, 453 insertions, 107 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 8ff7699..e5345a5 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -5290,6 +5290,9 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_OPTIONS_SETTINGS_SPEED_FACTOR_DESCRIPTION" desc="In the settings tab, the text next to the slider for the touchpad speed factor.">
Speed Sensitivity:
</message>
+ <message name="IDS_STATUSBAR_NO_NETWORKS_MESSAGE" desc="No networks are available">
+ Speed Sensitivity:
+ </message>
</if>
</messages>
diff --git a/chrome/app/theme/statusbar_disconnected.png b/chrome/app/theme/statusbar_disconnected.png
new file mode 100644
index 0000000..bc88d77
--- /dev/null
+++ b/chrome/app/theme/statusbar_disconnected.png
Binary files differ
diff --git a/chrome/app/theme/statusbar_wifi_1.png b/chrome/app/theme/statusbar_wifi_1.png
new file mode 100644
index 0000000..b1b4d5b
--- /dev/null
+++ b/chrome/app/theme/statusbar_wifi_1.png
Binary files differ
diff --git a/chrome/app/theme/statusbar_wifi_2.png b/chrome/app/theme/statusbar_wifi_2.png
new file mode 100644
index 0000000..a35ed72
--- /dev/null
+++ b/chrome/app/theme/statusbar_wifi_2.png
Binary files differ
diff --git a/chrome/app/theme/statusbar_wifi_3.png b/chrome/app/theme/statusbar_wifi_3.png
new file mode 100644
index 0000000..ba4681a
--- /dev/null
+++ b/chrome/app/theme/statusbar_wifi_3.png
Binary files differ
diff --git a/chrome/app/theme/statusbar_wifi_4.png b/chrome/app/theme/statusbar_wifi_4.png
new file mode 100644
index 0000000..97ce705
--- /dev/null
+++ b/chrome/app/theme/statusbar_wifi_4.png
Binary files differ
diff --git a/chrome/app/theme/statusbar_wifi_5.png b/chrome/app/theme/statusbar_wifi_5.png
new file mode 100755
index 0000000..34848ec
--- /dev/null
+++ b/chrome/app/theme/statusbar_wifi_5.png
Binary files differ
diff --git a/chrome/app/theme/statusbar_wifi_6.png b/chrome/app/theme/statusbar_wifi_6.png
new file mode 100755
index 0000000..7a24d92
--- /dev/null
+++ b/chrome/app/theme/statusbar_wifi_6.png
Binary files differ
diff --git a/chrome/app/theme/statusbar_wifi_7.png b/chrome/app/theme/statusbar_wifi_7.png
new file mode 100755
index 0000000..d5aeb2f
--- /dev/null
+++ b/chrome/app/theme/statusbar_wifi_7.png
Binary files differ
diff --git a/chrome/app/theme/statusbar_wifi_8.png b/chrome/app/theme/statusbar_wifi_8.png
new file mode 100755
index 0000000..465c51d
--- /dev/null
+++ b/chrome/app/theme/statusbar_wifi_8.png
Binary files differ
diff --git a/chrome/app/theme/statusbar_wired.png b/chrome/app/theme/statusbar_wired.png
new file mode 100755
index 0000000..ac8415d
--- /dev/null
+++ b/chrome/app/theme/statusbar_wired.png
Binary files differ
diff --git a/chrome/app/theme/theme_resources.grd b/chrome/app/theme/theme_resources.grd
index 9a9dc35..65f8cbc 100644
--- a/chrome/app/theme/theme_resources.grd
+++ b/chrome/app/theme/theme_resources.grd
@@ -376,6 +376,16 @@
<include name="IDR_STATUSBAR_BATTERY_DISCHARGING_6" file="statusbar_battery6d.png" type="BINDATA" />
<include name="IDR_STATUSBAR_BATTERY_DISCHARGING_7" file="statusbar_battery7d.png" type="BINDATA" />
<include name="IDR_STATUSBAR_BATTERY_DISCHARGING_8" file="statusbar_battery8d.png" type="BINDATA" />
+ <include name="IDR_STATUSBAR_DISCONNECTED" file="statusbar_disconnected.png" type="BINDATA" />
+ <include name="IDR_STATUSBAR_WIFI_1" file="statusbar_wifi_1.png" type="BINDATA" />
+ <include name="IDR_STATUSBAR_WIFI_2" file="statusbar_wifi_2.png" type="BINDATA" />
+ <include name="IDR_STATUSBAR_WIFI_3" file="statusbar_wifi_3.png" type="BINDATA" />
+ <include name="IDR_STATUSBAR_WIFI_4" file="statusbar_wifi_4.png" type="BINDATA" />
+ <include name="IDR_STATUSBAR_WIFI_5" file="statusbar_wifi_5.png" type="BINDATA" />
+ <include name="IDR_STATUSBAR_WIFI_6" file="statusbar_wifi_6.png" type="BINDATA" />
+ <include name="IDR_STATUSBAR_WIFI_7" file="statusbar_wifi_7.png" type="BINDATA" />
+ <include name="IDR_STATUSBAR_WIFI_8" file="statusbar_wifi_8.png" type="BINDATA" />
+ <include name="IDR_STATUSBAR_WIRED" file="statusbar_wired.png" type="BINDATA" />
<include name="IDR_MAIN_MENU_BUTTON" file="google_chrome/button_menu.png" type="BINDATA" />
<include name="IDR_MAIN_MENU_BUTTON_DROP_DOWN" file="google_chrome/button_menu_drop_down.png" type="BINDATA" />
</if>
diff --git a/chrome/browser/chromeos/network_menu_button.cc b/chrome/browser/chromeos/network_menu_button.cc
new file mode 100644
index 0000000..ddffa3c
--- /dev/null
+++ b/chrome/browser/chromeos/network_menu_button.cc
@@ -0,0 +1,172 @@
+// 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/network_menu_button.h"
+
+#include "app/l10n_util.h"
+#include "app/resource_bundle.h"
+#include "base/string_util.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/browser_window.h"
+#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
+#include "views/widget/widget.h"
+#include "views/window/window.h"
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkMenuButton
+
+// static
+const int NetworkMenuButton::kNumWifiImages = 8;
+SkBitmap* NetworkMenuButton::wifi_images_[kNumWifiImages];
+SkBitmap* NetworkMenuButton::wired_image_ = NULL;
+SkBitmap* NetworkMenuButton::disconnected_image_ = NULL;
+
+NetworkMenuButton::NetworkMenuButton(Browser* browser)
+ : MenuButton(NULL, std::wstring(), this, false),
+ refreshing_menu_(false),
+ network_menu_(this),
+ browser_(browser) {
+ static bool initialized = false;
+ if (!initialized) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ int image_index = IDR_STATUSBAR_WIFI_1;
+ for (int i = 0; i < kNumWifiImages; i++)
+ wifi_images_[i] = rb.GetBitmapNamed(image_index + i);
+ wired_image_ = rb.GetBitmapNamed(IDR_STATUSBAR_WIRED);
+ disconnected_image_ = rb.GetBitmapNamed(IDR_STATUSBAR_DISCONNECTED);
+ initialized = true;
+ }
+ SetIcon(*disconnected_image_);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkMenuButton, views::Menu2Model implementation:
+
+int NetworkMenuButton::GetItemCount() const {
+ // The menu contains the available wifi networks. If there are none, then it
+ // only has one item with a message that no networks are available.
+ return wifi_networks_.empty() ? 1 : static_cast<int>(wifi_networks_.size());
+}
+
+views::Menu2Model::ItemType NetworkMenuButton::GetTypeAt(int index) const {
+ return views::Menu2Model::TYPE_CHECK;
+}
+
+int NetworkMenuButton::GetCommandIdAt(int index) const {
+ return index;
+}
+
+string16 NetworkMenuButton::GetLabelAt(int index) const {
+ return wifi_networks_.empty() ?
+ l10n_util::GetStringUTF16(IDS_STATUSBAR_NO_NETWORKS_MESSAGE) :
+ wifi_networks_[index].ssid;
+}
+
+bool NetworkMenuButton::IsItemCheckedAt(int index) const {
+ return GetLabelAt(index) == current_ssid_;
+}
+
+bool NetworkMenuButton::IsEnabledAt(int index) const {
+ return !wifi_networks_.empty();
+}
+
+void NetworkMenuButton::ActivatedAt(int index) {
+ // When we are refreshing the menu, ignore menu item activation.
+ if (refreshing_menu_)
+ return;
+
+ connecting_ssid_ = wifi_networks_[index].ssid;
+ if (wifi_networks_[index].encryption.empty()) {
+ ConnectToWifiNetwork(connecting_ssid_, string16());
+ } else {
+ // If network requires password, we open a password dialog window.
+ gfx::NativeWindow parent = browser_->window()->GetNativeHandle();
+ PasswordDialogView* dialog = new PasswordDialogView(this);
+ views::Window* window = views::Window::CreateChromeWindow(
+ parent, gfx::Rect(), dialog);
+ // Draw the password dialog right below this button and right aligned.
+ gfx::Size size = dialog->GetPreferredSize();
+ gfx::Rect rect = bounds();
+ gfx::Point point = gfx::Point(rect.width() - size.width(), rect.height());
+ ConvertPointToScreen(this, &point);
+ window->SetBounds(gfx::Rect(point, size), parent);
+ window->Show();
+ }
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkMenuButton, PasswordDialogDelegate implementation:
+
+bool NetworkMenuButton::OnPasswordDialogCancel() {
+ connecting_ssid_.clear();
+ return true;
+}
+
+bool NetworkMenuButton::OnPasswordDialogAccept(const string16& password) {
+ return ConnectToWifiNetwork(connecting_ssid_, password);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// NetworkMenuButton, views::ViewMenuDelegate implementation:
+
+void NetworkMenuButton::RunMenu(views::View* source, const gfx::Point& pt,
+ gfx::NativeView hwnd) {
+ RefreshWifiNetworks();
+ refreshing_menu_ = true;
+ network_menu_.Rebuild();
+ network_menu_.UpdateStates();
+ refreshing_menu_ = false;
+ network_menu_.RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
+}
+
+void NetworkMenuButton::AddWifiNetwork(const string16& ssid,
+ const string16& encryption,
+ int strength) {
+ wifi_networks_.push_back(WifiNetwork(ssid, encryption, strength));
+}
+
+void NetworkMenuButton::RefreshWifiNetworks() {
+ // TODO(chocobo): Refresh wifi model here.
+ wifi_networks_.clear();
+ AddWifiNetwork(ASCIIToUTF16("Wifi 12"), string16(), 12);
+ AddWifiNetwork(ASCIIToUTF16("Wifi 28"), string16(), 28);
+ AddWifiNetwork(ASCIIToUTF16("Wifi 70"), string16(), 70);
+ AddWifiNetwork(ASCIIToUTF16("Wifi 99"), ASCIIToUTF16("WPA-PSK"), 99);
+
+ // TODO(chocobo): Handle the case where current_ssid_ or connecting_ssid_ are
+ // no longer found in the list of wifi networks.
+
+ // Refresh the menu button image.
+ if (current_ssid_.empty()) {
+ SetIcon(*disconnected_image_);
+ } else {
+ int size = static_cast<int>(wifi_networks_.size());
+ for (int i = 0; i < size; i++) {
+ if (wifi_networks_[i].ssid == current_ssid_) {
+ SetIcon(GetWifiImage(wifi_networks_[i]));
+ }
+ }
+ }
+ SchedulePaint();
+}
+
+bool NetworkMenuButton::ConnectToWifiNetwork(const string16& ssid,
+ const string16& password) {
+ // TODO(chocobo): Connect to wifi here.
+ current_ssid_ = ssid;
+ connecting_ssid_.clear();
+ RefreshWifiNetworks();
+ return true;
+}
+
+SkBitmap NetworkMenuButton::GetWifiImage(WifiNetwork wifi_network) const {
+ // Returns the wifi image of 1-8 bars depending on signal strength.
+ // Since signal strenght is from 0 to 100, we need to convert that to 0 to 7.
+ int index = floor(wifi_network.strength / (100.0 / kNumWifiImages));
+ // This can happen if the signal strength is 100.
+ if (index == kNumWifiImages)
+ index--;
+ return *wifi_images_[index];
+}
diff --git a/chrome/browser/chromeos/network_menu_button.h b/chrome/browser/chromeos/network_menu_button.h
new file mode 100644
index 0000000..2de58b1
--- /dev/null
+++ b/chrome/browser/chromeos/network_menu_button.h
@@ -0,0 +1,116 @@
+// Copyright (c) 2006-2008 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.
+
+#ifndef CHROME_BROWSER_CHROMEOS_NETWORK_MENU_BUTTON_H_
+#define CHROME_BROWSER_CHROMEOS_NETWORK_MENU_BUTTON_H_
+
+#include <vector>
+
+#include "chrome/browser/chromeos/password_dialog_view.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "views/controls/button/menu_button.h"
+#include "views/controls/menu/menu_2.h"
+#include "views/controls/menu/view_menu_delegate.h"
+
+class Browser;
+
+// The network menu button in the status area.
+// This class will handle getting the wifi networks and populating the menu.
+// It will also handle the status icon changing and connecting to another
+// wifi network.
+class NetworkMenuButton : public views::MenuButton,
+ public views::ViewMenuDelegate,
+ public views::Menu2Model,
+ public PasswordDialogDelegate {
+ public:
+ struct WifiNetwork {
+ WifiNetwork() { }
+ WifiNetwork(const string16& ssid, const string16& encryption, int strength)
+ : ssid(ssid),
+ encryption(encryption),
+ strength(strength) { }
+
+ string16 ssid;
+ string16 encryption;
+ int strength;
+ };
+
+ explicit NetworkMenuButton(Browser* browser);
+ virtual ~NetworkMenuButton() {}
+
+ // views::Menu2Model implementation.
+ virtual bool HasIcons() const { return false; }
+ virtual int GetItemCount() const;
+ virtual views::Menu2Model::ItemType GetTypeAt(int index) const;
+ virtual int GetCommandIdAt(int index) const;
+ virtual string16 GetLabelAt(int index) const;
+ virtual bool IsLabelDynamicAt(int index) const { return true; }
+ virtual bool GetAcceleratorAt(int index,
+ views::Accelerator* accelerator) const { return false; }
+ virtual bool IsItemCheckedAt(int index) const;
+ virtual int GetGroupIdAt(int index) const { return 0; }
+ virtual bool GetIconAt(int index, SkBitmap* icon) const { return false; }
+ virtual bool IsEnabledAt(int index) const;
+ virtual Menu2Model* GetSubmenuModelAt(int index) const { return NULL; }
+ virtual void HighlightChangedTo(int index) {}
+ virtual void ActivatedAt(int index);
+ virtual void MenuWillShow() {}
+
+ // PasswordDialogDelegate implementation.
+ virtual bool OnPasswordDialogCancel();
+ virtual bool OnPasswordDialogAccept(const string16& password);
+
+ private:
+ // views::ViewMenuDelegate implementation.
+ virtual void RunMenu(views::View* source, const gfx::Point& pt,
+ gfx::NativeView hwnd);
+
+ // Helper method to add a wifi network to the model.
+ void AddWifiNetwork(const string16& ssid, const string16& encryption,
+ int strength);
+
+ // Refreshes the wifi networks model using real data.
+ void RefreshWifiNetworks();
+
+ // Connect to the specified wireless network with password.
+ // Returns whether or not connection was successful.
+ bool ConnectToWifiNetwork(const string16& ssid, const string16& password);
+
+ // Gets the wifi image for specified wifi network.
+ SkBitmap GetWifiImage(WifiNetwork wifi_network) const;
+
+ // Set to true if we are currently refreshing the menu.
+ bool refreshing_menu_;
+
+ // The number of wifi strength images.
+ static const int kNumWifiImages;
+
+ // Wifi strength images.
+ static SkBitmap* wifi_images_[];
+
+ // Wired image.
+ static SkBitmap* wired_image_;
+
+ // Disconnected image.
+ static SkBitmap* disconnected_image_;
+
+ // The currently connected wifi network ssid.
+ string16 current_ssid_;
+
+ // The wifi netowrk ssid we are attempting to connect to.
+ string16 connecting_ssid_;
+
+ // A list of wifi networks.
+ std::vector<WifiNetwork> wifi_networks_;
+
+ // The network menu.
+ views::Menu2 network_menu_;
+
+ // The browser window that owns us.
+ Browser* browser_;
+
+ DISALLOW_COPY_AND_ASSIGN(NetworkMenuButton);
+};
+
+#endif // CHROME_BROWSER_CHROMEOS_NETWORK_MENU_BUTTON_H_
diff --git a/chrome/browser/chromeos/password_dialog_view.cc b/chrome/browser/chromeos/password_dialog_view.cc
new file mode 100644
index 0000000..fe80e47
--- /dev/null
+++ b/chrome/browser/chromeos/password_dialog_view.cc
@@ -0,0 +1,59 @@
+// 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"
+
+PasswordDialogView::PasswordDialogView(PasswordDialogDelegate* delegate)
+ : delegate_(delegate),
+ 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(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_);
+}
diff --git a/chrome/browser/chromeos/password_dialog_view.h b/chrome/browser/chromeos/password_dialog_view.h
new file mode 100644
index 0000000..04f7429
--- /dev/null
+++ b/chrome/browser/chromeos/password_dialog_view.h
@@ -0,0 +1,66 @@
+// Copyright (c) 2006-2008 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.
+
+#ifndef CHROME_BROWSER_CHROMEOS_PASSWORD_DIALOG_VIEW_H_
+#define CHROME_BROWSER_CHROMEOS_PASSWORD_DIALOG_VIEW_H_
+
+#include "base/string16.h"
+#include "views/window/dialog_delegate.h"
+
+namespace views {
+class Textfield;
+class View;
+class Window;
+}
+
+// Delegate implemented by caller of PasswordDialogView to handle the user
+// interacting with the dialog box.
+class PasswordDialogDelegate {
+ public:
+ // Called when user clicks on cancel button.
+ // Return whether or not to allow password dialog to close.
+ virtual bool OnPasswordDialogCancel() = 0;
+
+ // Called when user clicks on ok with a password.
+ // Return whether or not to allow password dialog to close.
+ virtual bool OnPasswordDialogAccept(const string16& password) = 0;
+};
+
+// A dialog box for showing a password textfield.
+class PasswordDialogView : public views::View,
+ public views::DialogDelegate {
+ public:
+ explicit PasswordDialogView(PasswordDialogDelegate* delegate);
+ virtual ~PasswordDialogView() {}
+
+ // views::DialogDelegate methods.
+ virtual bool Cancel();
+ virtual bool Accept();
+ virtual std::wstring GetWindowTitle() const;
+
+ // views::WindowDelegate method.
+ virtual bool IsModal() const { return true; }
+ virtual views::View* GetContentsView() { return this; }
+
+ // views::View overrides.
+ virtual void Layout();
+ virtual gfx::Size GetPreferredSize();
+
+ protected:
+ virtual void ViewHierarchyChanged(bool is_add, views::View* parent,
+ views::View* child);
+
+ private:
+ void Init();
+
+ // Used for call back to delegate that password has been entered.
+ PasswordDialogDelegate* delegate_;
+
+ // Combobox and its corresponding model.
+ views::Textfield* password_textfield_;
+
+ DISALLOW_COPY_AND_ASSIGN(PasswordDialogView);
+};
+
+#endif // CHROME_BROWSER_CHROMEOS_PASSWORD_DIALOG_VIEW_H_
diff --git a/chrome/browser/chromeos/settings_contents_view.cc b/chrome/browser/chromeos/settings_contents_view.cc
index 4c38b34..541ba0f 100644
--- a/chrome/browser/chromeos/settings_contents_view.cc
+++ b/chrome/browser/chromeos/settings_contents_view.cc
@@ -12,19 +12,17 @@
#include "app/resource_bundle.h"
#include "base/basictypes.h"
#include "base/string_util.h"
+#include "chrome/browser/chromeos/password_dialog_view.h"
#include "chrome/common/pref_member.h"
#include "chrome/common/pref_names.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
-#include "grit/locale_settings.h"
#include "views/background.h"
#include "views/controls/button/checkbox.h"
#include "views/controls/combobox/combobox.h"
#include "views/controls/slider/slider.h"
-#include "views/controls/textfield/textfield.h"
#include "views/grid_layout.h"
#include "views/standard_layout.h"
-#include "views/window/dialog_delegate.h"
#include "views/window/window.h"
using views::GridLayout;
@@ -126,7 +124,8 @@ void WifiSSIDComboModel::AddWifiNetwork(const string16& ssid,
// Network section for wifi settings
class NetworkSection : public OptionsPageView,
- public views::Combobox::Listener {
+ public views::Combobox::Listener,
+ public PasswordDialogDelegate {
public:
explicit NetworkSection(Profile* profile);
virtual ~NetworkSection() {}
@@ -136,8 +135,10 @@ class NetworkSection : public OptionsPageView,
int prev_index,
int new_index);
- bool OnPasswordWindowCancel();
- bool OnPasswordWindowAccept(const string16& password);
+ // PasswordDialogDelegate implementation.
+ virtual bool OnPasswordDialogCancel();
+ virtual bool OnPasswordDialogAccept(const string16& password);
+
bool ConnectToWifi(const string16& ssid, const string16& password);
protected:
@@ -162,101 +163,6 @@ class NetworkSection : public OptionsPageView,
};
////////////////////////////////////////////////////////////////////////////////
-// PasswordWindowView
-
-static const int kDialogPadding = 7;
-
-// A view for showing a password textfield
-class PasswordWindowView : public views::View,
- public views::DialogDelegate {
- public:
- PasswordWindowView(NetworkSection* network_delegate, Profile* profile);
- views::Window* container() const { return container_; }
- void set_container(views::Window* container) {
- container_ = container;
- }
-
- // views::DialogDelegate methods.
- virtual bool Cancel();
- virtual bool Accept();
- virtual std::wstring GetWindowTitle() const;
-
- // views::WindowDelegate method.
- virtual bool IsModal() const { return true; }
- virtual views::View* GetContentsView() { return this; }
-
- // views::View overrides.
- virtual void Layout();
- virtual gfx::Size GetPreferredSize();
-
- protected:
- virtual void ViewHierarchyChanged(bool is_add, views::View* parent,
- views::View* child);
-
- private:
- void Init();
-
- // The Options dialog window.
- views::Window* container_;
-
- // Used for Call back to NetworkSection that password has been entered.
- NetworkSection* network_delegate_;
-
- // Combobox and its corresponding model.
- views::Textfield* password_textfield_;
-
- DISALLOW_COPY_AND_ASSIGN(PasswordWindowView);
-};
-
-PasswordWindowView::PasswordWindowView(
- NetworkSection* network_delegate,
- Profile* profile)
- : network_delegate_(network_delegate),
- password_textfield_(NULL) {
- Init();
-}
-
-std::wstring PasswordWindowView::GetWindowTitle() const {
- return l10n_util::GetString(IDS_OPTIONS_SETTINGS_SECTION_TITLE_PASSWORD);
-}
-
-bool PasswordWindowView::Cancel() {
- return network_delegate_->OnPasswordWindowCancel();
-}
-
-bool PasswordWindowView::Accept() {
- // TODO(chocobo): we should not need to call SyncText ourself here.
- password_textfield_->SyncText();
- return network_delegate_->OnPasswordWindowAccept(password_textfield_->text());
-}
-
-void PasswordWindowView::Layout() {
- gfx::Size sz = password_textfield_->GetPreferredSize();
- password_textfield_->SetBounds(kDialogPadding, kDialogPadding,
- width() - 2*kDialogPadding,
- sz.height());
-}
-
-gfx::Size PasswordWindowView::GetPreferredSize() {
- // TODO(chocobo): Create our own localized content size once the UI is done.
- return gfx::Size(views::Window::GetLocalizedContentsSize(
- IDS_ABOUT_DIALOG_WIDTH_CHARS,
- IDS_ABOUT_DIALOG_MINIMUM_HEIGHT_LINES));
-}
-
-void PasswordWindowView::ViewHierarchyChanged(bool is_add,
- views::View* parent,
- views::View* child) {
- if (is_add && child == this)
- Init();
-}
-
-void PasswordWindowView::Init() {
- password_textfield_ = new views::Textfield(views::Textfield::STYLE_PASSWORD);
- AddChildView(password_textfield_);
-}
-
-////////////////////////////////////////////////////////////////////////////////
// NetworkSection
NetworkSection::NetworkSection(Profile* profile)
@@ -279,7 +185,8 @@ void NetworkSection::ItemChanged(views::Combobox* sender,
views::Window* window = views::Window::CreateChromeWindow(
NULL,
gfx::Rect(),
- new PasswordWindowView(this, profile()));
+ new PasswordDialogView(this));
+ window->SetIsAlwaysOnTop(true);
window->Show();
} else {
ConnectToWifi(ssid, string16());
@@ -287,13 +194,13 @@ void NetworkSection::ItemChanged(views::Combobox* sender,
}
}
-bool NetworkSection::OnPasswordWindowCancel() {
+bool NetworkSection::OnPasswordDialogCancel() {
// Change combobox to previous setting
wifi_ssid_combobox_->SetSelectedItem(last_selected_wifi_ssid_index_);
return true;
}
-bool NetworkSection::OnPasswordWindowAccept(const string16& password) {
+bool NetworkSection::OnPasswordDialogAccept(const string16& password) {
// Try connecting to wifi
return ConnectToWifi(wifi_ssid_model_.GetSSIDAt(
wifi_ssid_combobox_->selected_item()), password);
diff --git a/chrome/browser/chromeos/status_area_view.cc b/chrome/browser/chromeos/status_area_view.cc
index 7cbc28b..06f9ab7 100644
--- a/chrome/browser/chromeos/status_area_view.cc
+++ b/chrome/browser/chromeos/status_area_view.cc
@@ -4,9 +4,10 @@
#include "chrome/browser/chromeos/status_area_view.h"
-#include <algorithm>
#include <dlfcn.h>
+#include <algorithm>
+
#include "app/gfx/canvas.h"
#include "app/gfx/font.h"
#include "app/l10n_util.h"
@@ -19,9 +20,10 @@
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_window.h"
-#include "chrome/common/chrome_paths.h"
+#include "chrome/browser/chromeos/network_menu_button.h"
#include "chrome/browser/gtk/browser_window_gtk.h"
#include "chrome/browser/profile.h"
+#include "chrome/common/chrome_paths.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
@@ -204,6 +206,7 @@ bool StatusAreaView::power_library_error_ = false;
StatusAreaView::StatusAreaView(Browser* browser)
: browser_(browser),
+ network_view_(NULL),
battery_view_(NULL),
menu_view_(NULL),
power_status_connection_(NULL) {
@@ -221,6 +224,10 @@ void StatusAreaView::Init() {
// Clock.
AddChildView(new ClockView);
+ // Network.
+ network_view_ = new NetworkMenuButton(browser_);
+ AddChildView(network_view_);
+
// Battery.
battery_view_ = new views::ImageView;
battery_view_->SetImage(theme->GetBitmapNamed(IDR_STATUSBAR_BATTERY_UNKNOWN));
diff --git a/chrome/browser/chromeos/status_area_view.h b/chrome/browser/chromeos/status_area_view.h
index b75159b..89e52d2 100644
--- a/chrome/browser/chromeos/status_area_view.h
+++ b/chrome/browser/chromeos/status_area_view.h
@@ -12,6 +12,7 @@
#include "views/view.h"
class Browser;
+class NetworkMenuButton;
namespace views {
class MenuButton;
@@ -30,7 +31,7 @@ class StatusAreaView : public views::View,
OPEN_TABS_ON_RIGHT
};
- StatusAreaView(Browser* browser);
+ explicit StatusAreaView(Browser* browser);
virtual ~StatusAreaView();
void Init();
@@ -68,6 +69,7 @@ class StatusAreaView : public views::View,
// The browser window that owns us.
Browser* browser_;
+ NetworkMenuButton* network_view_;
views::ImageView* battery_view_;
views::MenuButton* menu_view_;
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index ed18daa..1282b40 100644
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -869,6 +869,10 @@
'browser/chromeos/external_cookie_handler.h',
'browser/chromeos/gview_request_interceptor.cc',
'browser/chromeos/gview_request_interceptor.h',
+ 'browser/chromeos/network_menu_button.cc',
+ 'browser/chromeos/network_menu_button.h',
+ 'browser/chromeos/password_dialog_view.cc',
+ 'browser/chromeos/password_dialog_view.h',
'browser/chromeos/settings_contents_view.cc',
'browser/chromeos/settings_contents_view.h',
'browser/chromeos/settings_page_view.cc',