| Index: chrome/browser/chromeos/status/network_menu.cc
|
| diff --git a/chrome/browser/chromeos/status/network_menu.cc b/chrome/browser/chromeos/status/network_menu.cc
|
| index 19ac0a8d1d3ee5a63918f4962c1eda0a3f94f2a7..8aeda763c24f0c4c5131cc8249ea2a5eb2fcd31e 100644
|
| --- a/chrome/browser/chromeos/status/network_menu.cc
|
| +++ b/chrome/browser/chromeos/status/network_menu.cc
|
| @@ -23,9 +23,13 @@
|
| #include "ui/base/resource/resource_bundle.h"
|
| #include "ui/gfx/canvas_skia.h"
|
| #include "ui/gfx/skbitmap_operations.h"
|
| -#include "views/controls/menu/menu_2.h"
|
| +#include "views/controls/menu/menu_item_view.h"
|
| +#include "views/controls/menu/submenu_view.h"
|
| +#include "views/widget/widget.h"
|
| #include "views/window/window.h"
|
|
|
| +using views::MenuItemView;
|
| +
|
| namespace chromeos {
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -78,7 +82,8 @@ SkBitmap NetworkMenu::kAnimatingImagesBlack[kNumAnimatingImages];
|
|
|
| NetworkMenu::NetworkMenu()
|
| : min_width_(-1) {
|
| - network_menu_.reset(new views::Menu2(this));
|
| + network_menu_.reset(new views::MenuItemView(this));
|
| + network_menu_->set_has_icons(true);
|
| }
|
|
|
| NetworkMenu::~NetworkMenu() {
|
| @@ -148,50 +153,42 @@ bool NetworkMenu::ConnectToNetworkAt(int index,
|
| }
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| -// NetworkMenu, ui::MenuModel implementation:
|
| -
|
| -int NetworkMenu::GetItemCount() const {
|
| - return static_cast<int>(menu_items_.size());
|
| -}
|
| -
|
| -ui::MenuModel::ItemType NetworkMenu::GetTypeAt(int index) const {
|
| - return menu_items_[index].type;
|
| -}
|
| -
|
| -string16 NetworkMenu::GetLabelAt(int index) const {
|
| - return menu_items_[index].label;
|
| +// NetworkMenu, views::MenuItemView implementation:
|
| +std::wstring NetworkMenu::GetLabel(int id) const {
|
| + DCHECK_LE(0, id);
|
| + DCHECK_GT(static_cast<int>(menu_items_.size()), id);
|
| + return UTF16ToWide(menu_items_[id].label);
|
| }
|
|
|
| -const gfx::Font* NetworkMenu::GetLabelFontAt(int index) const {
|
| - return (menu_items_[index].flags & FLAG_ASSOCIATED) ?
|
| - &ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BoldFont) :
|
| - NULL;
|
| +const gfx::Font& NetworkMenu::GetLabelFont(int id) const {
|
| + return (menu_items_[id].flags & FLAG_ASSOCIATED) ?
|
| + ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BoldFont) :
|
| + ResourceBundle::GetSharedInstance().GetFont(ResourceBundle::BaseFont);
|
| }
|
|
|
| -bool NetworkMenu::IsItemCheckedAt(int index) const {
|
| - // All ui::MenuModel::TYPE_CHECK menu items are checked.
|
| - return true;
|
| +bool NetworkMenu::IsCommandEnabled(int id) const {
|
| + if (id < static_cast<int>(menu_items_.size()))
|
| + return !(menu_items_[id].flags & FLAG_DISABLED);
|
| + else
|
| + return false;
|
| }
|
|
|
| -bool NetworkMenu::GetIconAt(int index, SkBitmap* icon) {
|
| - if (!menu_items_[index].icon.empty()) {
|
| - *icon = menu_items_[index].icon;
|
| - return true;
|
| - }
|
| - return false;
|
| +bool NetworkMenu::IsItemChecked(int id) const {
|
| + DCHECK_LE(0, id);
|
| + DCHECK_GT(static_cast<int>(menu_items_.size()), id);
|
| + return menu_items_[id].type == ui::MenuModel::TYPE_CHECK;
|
| }
|
|
|
| -bool NetworkMenu::IsEnabledAt(int index) const {
|
| - return !(menu_items_[index].flags & FLAG_DISABLED);
|
| -}
|
| +void NetworkMenu::ExecuteCommand(int id) {
|
| + DCHECK_LE(0, id);
|
| + DCHECK_GT(static_cast<int>(menu_items_.size()), id);
|
|
|
| -void NetworkMenu::ActivatedAt(int index) {
|
| // When we are refreshing the menu, ignore menu item activation.
|
| if (refreshing_menu_)
|
| return;
|
|
|
| NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
|
| - int flags = menu_items_[index].flags;
|
| + int flags = menu_items_[id].flags;
|
| if (flags & FLAG_OPTIONS) {
|
| OpenButtonOptions();
|
| } else if (flags & FLAG_TOGGLE_ETHERNET) {
|
| @@ -218,30 +215,44 @@ void NetworkMenu::ActivatedAt(int index) {
|
| ShowTabbedNetworkSettings(cros->ethernet_network());
|
| }
|
| } else if (flags & FLAG_WIFI) {
|
| - ConnectToNetworkAt(index, std::string(), std::string(), -1);
|
| + ConnectToNetworkAt(id, std::string(), std::string(), -1);
|
| } else if (flags & FLAG_OTHER_WIFI_NETWORK) {
|
| - ConnectToNetworkAt(index, std::string(), std::string(), -1);
|
| + ConnectToNetworkAt(id, std::string(), std::string(), -1);
|
| } else if (flags & FLAG_CELLULAR) {
|
| - ConnectToNetworkAt(index, std::string(), std::string(), -1);
|
| + ConnectToNetworkAt(id, std::string(), std::string(), -1);
|
| } else if (flags & FLAG_OTHER_CELLULAR_NETWORK) {
|
| - ConnectToNetworkAt(index, std::string(), std::string(), -1);
|
| + ConnectToNetworkAt(id, std::string(), std::string(), -1);
|
| }
|
| }
|
|
|
| void NetworkMenu::SetFirstLevelMenuWidth(int width) {
|
| min_width_ = width;
|
| // This actually has no effect since menu is rebuilt before showing.
|
| - network_menu_->SetMinimumWidth(width);
|
| }
|
|
|
| void NetworkMenu::CancelMenu() {
|
| - network_menu_->CancelMenu();
|
| + network_menu_->Cancel();
|
| }
|
|
|
| void NetworkMenu::UpdateMenu() {
|
| refreshing_menu_ = true;
|
| +
|
| + // Rebuild list of available networks.
|
| InitMenuItems();
|
| - network_menu_->Rebuild();
|
| +
|
| + // Clear and repopulate MenuItemView.
|
| + network_menu_->CreateSubmenu()->RemoveAllChildViews(true);
|
| + for (int i = 0, n = menu_items_.size(); i < n; ++i) {
|
| + if (menu_items_[i].type == ui::MenuModel::TYPE_SEPARATOR)
|
| + network_menu_->AppendSeparator();
|
| + else
|
| + network_menu_->AppendMenuItemWithIcon(
|
| + i,
|
| + UTF16ToWide(menu_items_[i].label),
|
| + menu_items_[i].icon);
|
| + }
|
| +
|
| + network_menu_->ChildrenChanged();
|
| refreshing_menu_ = false;
|
| }
|
|
|
| @@ -424,22 +435,35 @@ SkBitmap NetworkMenu::IconForDisplay(const SkBitmap* icon,
|
| // NetworkMenu, views::ViewMenuDelegate implementation:
|
|
|
| void NetworkMenu::RunMenu(views::View* source, const gfx::Point& pt) {
|
| - refreshing_menu_ = true;
|
| + DCHECK_EQ(GetMenuButton(), source);
|
| +
|
| NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary();
|
| cros->RequestNetworkScan();
|
|
|
| - // Build initial menu items. They will be updated when UpdateMenu is
|
| - // called from NetworkChanged.
|
| - InitMenuItems();
|
| - network_menu_->Rebuild();
|
| -
|
| - // Restore menu width, if it was set up.
|
| - // NOTE: width isn't checked for correctness here since all width-related
|
| - // logic implemented inside |network_menu_|.
|
| - if (min_width_ != -1)
|
| - network_menu_->SetMinimumWidth(min_width_);
|
| - refreshing_menu_ = false;
|
| - network_menu_->RunMenuAt(pt, views::Menu2::ALIGN_TOPRIGHT);
|
| + UpdateMenu();
|
| +
|
| + // TODO(rhashimoto): Remove this workaround when WebUI provides a
|
| + // top-level widget on the ChromeOS login screen that is a window.
|
| + // The current BackgroundView class for the ChromeOS login screen
|
| + // creates a owning Widget that has a native GtkWindow but is not a
|
| + // Window. This makes it impossible to get the NativeWindow via
|
| + // the views API. This workaround casts the top-level NativeWidget
|
| + // to a NativeWindow that we can pass to MenuItemView::RunMenuAt().
|
| + gfx::NativeWindow window;
|
| + if (source->GetWindow())
|
| + window = source->GetWindow()->GetNativeWindow();
|
| + else
|
| + window = GTK_WINDOW(source->GetWidget()->GetNativeView());
|
| +
|
| + gfx::Point screen_loc;
|
| + views::View::ConvertPointToScreen(source, &screen_loc);
|
| + gfx::Rect bounds(screen_loc, source->size());
|
| + network_menu_->RunMenuAt(
|
| + window,
|
| + GetMenuButton(),
|
| + bounds,
|
| + base::i18n::IsRTL() ? MenuItemView::TOPLEFT : MenuItemView::TOPRIGHT,
|
| + true);
|
| }
|
|
|
| void NetworkMenu::InitMenuItems() {
|
|
|