Convert NetworkMenu from Menu2 to MenuItemView.

This CL depends on http://codereview.chromium.org/6931039/ to handle changes to MenuItemView menus while the menu is open.  It includes a default minimum width setting on the menu to avoid unnecessary resizing.

I have tested network names with ampersands and they display correctly with the same escaping code as before.

BUG=chromium-os:13887,chromium-os:12988
TEST=none


Review URL: http://codereview.chromium.org/7016042

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@86434 0039d316-1c4b-4281-b951-d872f2087c98
parent 723547f3
...@@ -140,4 +140,8 @@ void NetworkDropdownButton::OnNetworkManagerChanged(NetworkLibrary* cros) { ...@@ -140,4 +140,8 @@ void NetworkDropdownButton::OnNetworkManagerChanged(NetworkLibrary* cros) {
UpdateMenu(); UpdateMenu();
} }
views::MenuButton* NetworkDropdownButton::GetMenuButton() {
return this;
}
} // namespace chromeos } // namespace chromeos
// Copyright (c) 2010 The Chromium Authors. All rights reserved. // Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -37,6 +37,7 @@ class NetworkDropdownButton : public DropDownButton, ...@@ -37,6 +37,7 @@ class NetworkDropdownButton : public DropDownButton,
protected: protected:
// NetworkMenu implementation: // NetworkMenu implementation:
virtual bool IsBrowserMode() const; virtual bool IsBrowserMode() const;
virtual views::MenuButton* GetMenuButton();
virtual gfx::NativeWindow GetNativeWindow() const; virtual gfx::NativeWindow GetNativeWindow() const;
virtual void OpenButtonOptions() {} virtual void OpenButtonOptions() {}
virtual bool ShouldOpenButtonOptions() const; virtual bool ShouldOpenButtonOptions() const;
......
...@@ -15,150 +15,26 @@ ...@@ -15,150 +15,26 @@
#include "ui/gfx/native_widget_types.h" #include "ui/gfx/native_widget_types.h"
#include "views/controls/menu/view_menu_delegate.h" #include "views/controls/menu/view_menu_delegate.h"
namespace {
const int kMainCommandIndexOffset = 1000;
const int kVPNCommandIndexOffset = 2000;
const int kMoreCommandIndexOffset = 3000;
} // namespace
namespace gfx { namespace gfx {
class Canvas; class Canvas;
} }
namespace views { namespace views {
class Menu2; class MenuItemView;
class MenuButton;
} }
namespace chromeos { namespace chromeos {
class NetworkMenu; class NetworkMenuModel;
class NetworkMenuModel : public ui::MenuModel {
public:
struct NetworkInfo {
NetworkInfo();
~NetworkInfo();
// "ethernet" | "wifi" | "cellular" | "other".
std::string network_type;
// "connected" | "connecting" | "disconnected" | "error".
std::string status;
// status message or error message, empty if unknown status.
std::string message;
// IP address (if network is active, empty otherwise)
std::string ip_address;
// Remembered passphrase.
std::string passphrase;
// true if the network requires a passphrase.
bool need_passphrase;
// true if the network is currently remembered.
bool remembered;
// true if the network is auto connect (meaningful for Wifi only).
bool auto_connect;
};
explicit NetworkMenuModel(NetworkMenu* owner);
virtual ~NetworkMenuModel();
// Connect or reconnect to the network at |index|.
// If remember >= 0, set the favorite state of the network.
// Returns true if a connect occurred (e.g. menu should be closed).
bool ConnectToNetworkAt(int index,
const std::string& passphrase,
const std::string& ssid,
int remember) const;
// Called by NetworkMenu::RunMenu to initialize list of menu items.
virtual void InitMenuItems(bool is_browser_mode,
bool should_open_button_options) = 0;
// ui::MenuModel implementation.
virtual bool HasIcons() const;
virtual int GetItemCount() const;
virtual ui::MenuModel::ItemType GetTypeAt(int index) const;
virtual int GetCommandIdAt(int index) const;
virtual string16 GetLabelAt(int index) const;
virtual bool IsItemDynamicAt(int index) const;
virtual const gfx::Font* GetLabelFontAt(int index) const;
virtual bool GetAcceleratorAt(int index, ui::Accelerator* accelerator) const;
virtual bool IsItemCheckedAt(int index) const;
virtual int GetGroupIdAt(int index) const;
virtual bool GetIconAt(int index, SkBitmap* icon);
virtual ui::ButtonMenuItemModel* GetButtonMenuItemAt(int index) const;
virtual bool IsEnabledAt(int index) const;
virtual ui::MenuModel* GetSubmenuModelAt(int index) const;
virtual void HighlightChangedTo(int index);
virtual void ActivatedAt(int index);
virtual void MenuWillShow();
virtual void SetMenuModelDelegate(ui::MenuModelDelegate* delegate);
protected:
enum MenuItemFlags {
FLAG_NONE = 0,
FLAG_DISABLED = 1 << 0,
FLAG_TOGGLE_ETHERNET = 1 << 1,
FLAG_TOGGLE_WIFI = 1 << 2,
FLAG_TOGGLE_CELLULAR = 1 << 3,
FLAG_TOGGLE_OFFLINE = 1 << 4,
FLAG_ASSOCIATED = 1 << 5,
FLAG_ETHERNET = 1 << 6,
FLAG_WIFI = 1 << 7,
FLAG_CELLULAR = 1 << 8,
FLAG_OPTIONS = 1 << 9,
FLAG_ADD_WIFI = 1 << 10,
FLAG_ADD_CELLULAR = 1 << 11,
FLAG_VPN = 1 << 12,
FLAG_ADD_VPN = 1 << 13,
FLAG_DISCONNECT_VPN = 1 << 14,
FLAG_VIEW_ACCOUNT = 1 << 15,
};
struct MenuItem {
MenuItem()
: type(ui::MenuModel::TYPE_SEPARATOR),
sub_menu_model(NULL),
flags(0) {}
MenuItem(ui::MenuModel::ItemType type, string16 label, SkBitmap icon,
const std::string& service_path, int flags)
: type(type),
label(label),
icon(icon),
service_path(service_path),
sub_menu_model(NULL),
flags(flags) {}
MenuItem(ui::MenuModel::ItemType type, string16 label, SkBitmap icon,
NetworkMenuModel* sub_menu_model, int flags)
: type(type),
label(label),
icon(icon),
sub_menu_model(sub_menu_model),
flags(flags) {}
ui::MenuModel::ItemType type;
string16 label;
SkBitmap icon;
std::string service_path;
NetworkMenuModel* sub_menu_model; // Weak.
int flags;
};
typedef std::vector<MenuItem> MenuItemVector;
// Our menu items.
MenuItemVector menu_items_;
NetworkMenu* owner_; // Weak pointer to NetworkMenu that owns this MenuModel.
// Top up URL of the current carrier on empty string if there's none.
std::string top_up_url_;
// Carrier ID which top up URL is initialized for.
// Used to update top up URL only when cellular carrier has changed.
std::string carrier_id_;
private:
// Show a NetworkConfigView modal dialog instance.
void ShowNetworkConfigView(NetworkConfigView* view) const;
void ActivateCellular(const CellularNetwork* cellular) const;
void ShowOther(ConnectionType type) const;
void ShowOtherCellular() const;
DISALLOW_COPY_AND_ASSIGN(NetworkMenuModel);
};
// Menu for network menu button in the status area/welcome screen. // Menu for network menu button in the status area/welcome screen.
// This class will populating the menu with the list of networks. // This class will populating the menu with the list of networks.
...@@ -256,6 +132,7 @@ class NetworkMenu : public views::ViewMenuDelegate { ...@@ -256,6 +132,7 @@ class NetworkMenu : public views::ViewMenuDelegate {
const SkBitmap* bottom_left_badge); const SkBitmap* bottom_left_badge);
protected: protected:
virtual views::MenuButton* GetMenuButton() = 0;
virtual gfx::NativeWindow GetNativeWindow() const = 0; virtual gfx::NativeWindow GetNativeWindow() const = 0;
virtual void OpenButtonOptions() = 0; virtual void OpenButtonOptions() = 0;
virtual bool ShouldOpenButtonOptions() const = 0; virtual bool ShouldOpenButtonOptions() const = 0;
...@@ -296,11 +173,11 @@ class NetworkMenu : public views::ViewMenuDelegate { ...@@ -296,11 +173,11 @@ class NetworkMenu : public views::ViewMenuDelegate {
static SkBitmap kAnimatingImagesBlack[]; static SkBitmap kAnimatingImagesBlack[];
// The network menu. // The network menu.
scoped_ptr<views::Menu2> network_menu_; scoped_ptr<views::MenuItemView> network_menu_;
scoped_ptr<NetworkMenuModel> main_menu_model_; scoped_ptr<NetworkMenuModel> main_menu_model_;
// Holds minimum width or -1 if it wasn't set up. // Holds minimum width of the menu.
int min_width_; int min_width_;
// If true, call into the settings UI for network configuration dialogs. // If true, call into the settings UI for network configuration dialogs.
......
...@@ -193,6 +193,10 @@ bool NetworkMenuButton::IsBrowserMode() const { ...@@ -193,6 +193,10 @@ bool NetworkMenuButton::IsBrowserMode() const {
return host_->GetScreenMode() == StatusAreaHost::kBrowserMode; return host_->GetScreenMode() == StatusAreaHost::kBrowserMode;
} }
views::MenuButton* NetworkMenuButton::GetMenuButton() {
return this;
}
gfx::NativeWindow NetworkMenuButton::GetNativeWindow() const { gfx::NativeWindow NetworkMenuButton::GetNativeWindow() const {
return host_->GetNativeWindow(); return host_->GetNativeWindow();
} }
......
...@@ -82,6 +82,7 @@ class NetworkMenuButton : public StatusAreaButton, ...@@ -82,6 +82,7 @@ class NetworkMenuButton : public StatusAreaButton,
protected: protected:
// NetworkMenu implementation: // NetworkMenu implementation:
virtual views::MenuButton* GetMenuButton();
virtual gfx::NativeWindow GetNativeWindow() const; virtual gfx::NativeWindow GetNativeWindow() const;
virtual void OpenButtonOptions(); virtual void OpenButtonOptions();
virtual bool ShouldOpenButtonOptions() const; virtual bool ShouldOpenButtonOptions() const;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment