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