| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/status/network_dropdown_button.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/utf_string_conversions.h" | |
| 9 #include "chrome/browser/chromeos/cros/cros_library.h" | |
| 10 #include "chrome/browser/chromeos/login/proxy_settings_dialog.h" | |
| 11 #include "chrome/browser/chromeos/options/network_config_view.h" | |
| 12 #include "chrome/common/chrome_switches.h" | |
| 13 #include "grit/generated_resources.h" | |
| 14 #include "ui/base/l10n/l10n_util.h" | |
| 15 | |
| 16 namespace chromeos { | |
| 17 | |
| 18 //////////////////////////////////////////////////////////////////////////////// | |
| 19 // NetworkDropdownButton | |
| 20 | |
| 21 NetworkDropdownButton::NetworkDropdownButton(bool is_browser_mode, | |
| 22 gfx::NativeWindow parent_window, | |
| 23 bool should_show_options) | |
| 24 : DropDownButton( | |
| 25 NULL, | |
| 26 l10n_util::GetStringUTF16(IDS_STATUSBAR_NO_NETWORKS_MESSAGE), | |
| 27 this, | |
| 28 true), | |
| 29 parent_window_(parent_window), | |
| 30 should_show_options_(should_show_options) { | |
| 31 network_menu_.reset(new NetworkMenu(this, is_browser_mode)); | |
| 32 network_icon_.reset( | |
| 33 new NetworkMenuIcon(this, NetworkMenuIcon::DROPDOWN_MODE)); | |
| 34 CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this); | |
| 35 // The initial state will be updated on Refresh. | |
| 36 // See network_selection_view.cc. | |
| 37 } | |
| 38 | |
| 39 NetworkDropdownButton::~NetworkDropdownButton() { | |
| 40 CrosLibrary::Get()->GetNetworkLibrary()->RemoveNetworkManagerObserver(this); | |
| 41 } | |
| 42 | |
| 43 void NetworkDropdownButton::Refresh() { | |
| 44 OnNetworkManagerChanged(CrosLibrary::Get()->GetNetworkLibrary()); | |
| 45 } | |
| 46 | |
| 47 void NetworkDropdownButton::SetFirstLevelMenuWidth(int width) { | |
| 48 network_menu_->set_min_width(width); | |
| 49 } | |
| 50 | |
| 51 void NetworkDropdownButton::CancelMenu() { | |
| 52 network_menu_->CancelMenu(); | |
| 53 } | |
| 54 | |
| 55 //////////////////////////////////////////////////////////////////////////////// | |
| 56 // NetworkDropdownButton, NetworkMenu::Delegate implementation: | |
| 57 | |
| 58 views::MenuButton* NetworkDropdownButton::GetMenuButton() { | |
| 59 return this; | |
| 60 } | |
| 61 | |
| 62 gfx::NativeWindow NetworkDropdownButton::GetNativeWindow() const { | |
| 63 return parent_window_; | |
| 64 } | |
| 65 | |
| 66 void NetworkDropdownButton::OpenButtonOptions() { | |
| 67 if (proxy_settings_dialog_.get() == NULL) { | |
| 68 proxy_settings_dialog_.reset(new ProxySettingsDialog(this, | |
| 69 GetNativeWindow())); | |
| 70 } | |
| 71 proxy_settings_dialog_->Show(); | |
| 72 } | |
| 73 | |
| 74 bool NetworkDropdownButton::ShouldOpenButtonOptions() const { | |
| 75 return should_show_options_; | |
| 76 } | |
| 77 | |
| 78 //////////////////////////////////////////////////////////////////////////////// | |
| 79 // NetworkDropdownButton, views::ViewMenuDelegate implementation: | |
| 80 | |
| 81 void NetworkDropdownButton::RunMenu(views::View* source, const gfx::Point& pt) { | |
| 82 network_menu_->RunMenu(source); | |
| 83 } | |
| 84 | |
| 85 //////////////////////////////////////////////////////////////////////////////// | |
| 86 // NetworkDropdownButton, overridden from views::View. | |
| 87 | |
| 88 void NetworkDropdownButton::OnLocaleChanged() { | |
| 89 // Proxy settings dialog contains localized strings. | |
| 90 proxy_settings_dialog_.reset(); | |
| 91 } | |
| 92 | |
| 93 //////////////////////////////////////////////////////////////////////////////// | |
| 94 // NetworkDropdownButton, LoginHtmlDialog::Delegate implementation: | |
| 95 | |
| 96 void NetworkDropdownButton::OnDialogClosed() { | |
| 97 } | |
| 98 | |
| 99 //////////////////////////////////////////////////////////////////////////////// | |
| 100 // NetworkDropdownButton, NetworkLibrary::NetworkManagerObserver implementation: | |
| 101 | |
| 102 void NetworkDropdownButton::OnNetworkManagerChanged(NetworkLibrary* cros) { | |
| 103 // This gets called on initialization, so any changes should be reflected | |
| 104 // in CrosMock::SetNetworkLibraryStatusAreaExpectations(). | |
| 105 SetNetworkIconAndText(); | |
| 106 SchedulePaint(); | |
| 107 network_menu_->UpdateMenu(); | |
| 108 } | |
| 109 | |
| 110 //////////////////////////////////////////////////////////////////////////////// | |
| 111 // NetworkDropdownButton, NetworkMenuIcon::Delegate implementation: | |
| 112 void NetworkDropdownButton::NetworkMenuIconChanged() { | |
| 113 const SkBitmap bitmap = network_icon_->GetIconAndText(NULL); | |
| 114 SetIcon(bitmap); | |
| 115 SchedulePaint(); | |
| 116 } | |
| 117 | |
| 118 //////////////////////////////////////////////////////////////////////////////// | |
| 119 // NetworkDropdownButton, private methods: | |
| 120 | |
| 121 void NetworkDropdownButton::SetNetworkIconAndText() { | |
| 122 string16 text; | |
| 123 const SkBitmap bitmap = network_icon_->GetIconAndText(&text); | |
| 124 SetIcon(bitmap); | |
| 125 SetText(text); | |
| 126 } | |
| 127 | |
| 128 } // namespace chromeos | |
| OLD | NEW |