| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/status/network_menu_button.h" | 5 #include "chrome/browser/chromeos/status/network_menu_button.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 | 9 |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
| 12 #include "chrome/browser/chromeos/cros/cros_library.h" | 12 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 13 #include "chrome/browser/chromeos/options/network_config_view.h" | 13 #include "chrome/browser/chromeos/options/network_config_view.h" |
| 14 #include "chrome/browser/chromeos/status/status_area_host.h" | 14 #include "chrome/browser/chromeos/status/status_area_host.h" |
| 15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
| 16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/gfx/canvas_skia.h" | 19 #include "ui/gfx/canvas_skia.h" |
| 20 #include "views/window/window.h" | 20 #include "views/window/window.h" |
| 21 | 21 |
| 22 namespace chromeos { | 22 namespace chromeos { |
| 23 | 23 |
| 24 //////////////////////////////////////////////////////////////////////////////// | 24 // NetworkMenuButton ---------------------------------------------------------- |
| 25 // NetworkMenuButton | |
| 26 | 25 |
| 27 // static | 26 // static |
| 28 const int NetworkMenuButton::kThrobDuration = 1000; | 27 const int NetworkMenuButton::kThrobDuration = 1000; |
| 29 | 28 |
| 30 NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host) | 29 NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host) |
| 31 : StatusAreaButton(this), | 30 : StatusAreaButton(this), |
| 32 NetworkMenu(), | 31 NetworkMenu(), |
| 33 host_(host), | 32 host_(host), |
| 34 icon_(NULL), | 33 icon_(NULL), |
| 35 badge_(NULL), | 34 badge_(NULL), |
| 36 ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)) { | 35 ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)) { |
| 37 animation_connecting_.SetThrobDuration(kThrobDuration); | 36 animation_connecting_.SetThrobDuration(kThrobDuration); |
| 38 animation_connecting_.SetTweenType(ui::Tween::EASE_IN_OUT); | 37 animation_connecting_.SetTweenType(ui::Tween::EASE_IN_OUT); |
| 39 OnNetworkManagerChanged(CrosLibrary::Get()->GetNetworkLibrary()); | 38 OnNetworkManagerChanged(CrosLibrary::Get()->GetNetworkLibrary()); |
| 40 CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this); | 39 CrosLibrary::Get()->GetNetworkLibrary()->AddNetworkManagerObserver(this); |
| 41 CrosLibrary::Get()->GetNetworkLibrary()->AddCellularDataPlanObserver(this); | 40 CrosLibrary::Get()->GetNetworkLibrary()->AddCellularDataPlanObserver(this); |
| 42 } | 41 } |
| 43 | 42 |
| 44 NetworkMenuButton::~NetworkMenuButton() { | 43 NetworkMenuButton::~NetworkMenuButton() { |
| 45 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); | 44 NetworkLibrary* netlib = CrosLibrary::Get()->GetNetworkLibrary(); |
| 46 netlib->RemoveNetworkManagerObserver(this); | 45 netlib->RemoveNetworkManagerObserver(this); |
| 47 netlib->RemoveObserverForAllNetworks(this); | 46 netlib->RemoveObserverForAllNetworks(this); |
| 48 netlib->RemoveCellularDataPlanObserver(this); | 47 netlib->RemoveCellularDataPlanObserver(this); |
| 49 } | 48 } |
| 50 | 49 |
| 51 //////////////////////////////////////////////////////////////////////////////// | 50 // NetworkMenuButton, ui::AnimationDelegate implementation: ------------------- |
| 52 // NetworkMenuButton, ui::AnimationDelegate implementation: | |
| 53 | 51 |
| 54 void NetworkMenuButton::AnimationProgressed(const ui::Animation* animation) { | 52 void NetworkMenuButton::AnimationProgressed(const ui::Animation* animation) { |
| 55 if (animation == &animation_connecting_) { | 53 if (animation == &animation_connecting_) { |
| 56 SetIconOnly(IconForNetworkConnecting( | 54 SetIconOnly(IconForNetworkConnecting( |
| 57 animation_connecting_.GetCurrentValue(), false)); | 55 animation_connecting_.GetCurrentValue(), false)); |
| 58 // No need to set the badge here, because it should already be set. | 56 // No need to set the badge here, because it should already be set. |
| 59 SchedulePaint(); | 57 SchedulePaint(); |
| 60 } else { | 58 } else { |
| 61 MenuButton::AnimationProgressed(animation); | 59 MenuButton::AnimationProgressed(animation); |
| 62 } | 60 } |
| 63 } | 61 } |
| 64 | 62 |
| 65 //////////////////////////////////////////////////////////////////////////////// | 63 // NetworkMenuButton, NetworkLibrary::NetworkManagerObserver implementation: -- |
| 66 // NetworkMenuButton, NetworkLibrary::NetworkManagerObserver implementation: | |
| 67 | 64 |
| 68 void NetworkMenuButton::OnNetworkManagerChanged(NetworkLibrary* cros) { | 65 void NetworkMenuButton::OnNetworkManagerChanged(NetworkLibrary* cros) { |
| 69 OnNetworkChanged(cros, cros->active_network()); | 66 OnNetworkChanged(cros, cros->active_network()); |
| 70 } | 67 } |
| 71 | 68 |
| 72 //////////////////////////////////////////////////////////////////////////////// | 69 // NetworkMenuButton, NetworkLibrary::NetworkObserver implementation: --------- |
| 73 // NetworkMenuButton, NetworkLibrary::NetworkObserver implementation: | 70 |
| 74 void NetworkMenuButton::OnNetworkChanged(NetworkLibrary* cros, | 71 void NetworkMenuButton::OnNetworkChanged(NetworkLibrary* cros, |
| 75 const Network* network) { | 72 const Network* network) { |
| 76 // This gets called on initialization, so any changes should be reflected | 73 // This gets called on initialization, so any changes should be reflected |
| 77 // in CrosMock::SetNetworkLibraryStatusAreaExpectations(). | 74 // in CrosMock::SetNetworkLibraryStatusAreaExpectations(). |
| 78 SetNetworkIcon(cros, network); | 75 SetNetworkIcon(cros, network); |
| 79 RefreshNetworkObserver(cros); | 76 RefreshNetworkObserver(cros); |
| 80 SchedulePaint(); | 77 SchedulePaint(); |
| 81 UpdateMenu(); | 78 UpdateMenu(); |
| 82 } | 79 } |
| 83 | 80 |
| 84 void NetworkMenuButton::OnCellularDataPlanChanged(NetworkLibrary* cros) { | 81 void NetworkMenuButton::OnCellularDataPlanChanged(NetworkLibrary* cros) { |
| 85 // Call OnNetworkManagerChanged which will update the icon. | 82 // Call OnNetworkManagerChanged which will update the icon. |
| 86 OnNetworkManagerChanged(cros); | 83 OnNetworkManagerChanged(cros); |
| 87 } | 84 } |
| 88 | 85 |
| 89 //////////////////////////////////////////////////////////////////////////////// | 86 // NetworkMenuButton, NetworkMenu implementation: ----------------------------- |
| 90 // NetworkMenuButton, NetworkMenu implementation: | |
| 91 | 87 |
| 92 bool NetworkMenuButton::IsBrowserMode() const { | 88 bool NetworkMenuButton::IsBrowserMode() const { |
| 93 return host_->GetScreenMode() == StatusAreaHost::kBrowserMode; | 89 return host_->GetScreenMode() == StatusAreaHost::kBrowserMode; |
| 94 } | 90 } |
| 95 | 91 |
| 92 views::MenuButton* NetworkMenuButton::GetMenuButton() OVERRIDE { |
| 93 return this; |
| 94 } |
| 95 |
| 96 gfx::NativeWindow NetworkMenuButton::GetNativeWindow() const { | 96 gfx::NativeWindow NetworkMenuButton::GetNativeWindow() const { |
| 97 return host_->GetNativeWindow(); | 97 return host_->GetNativeWindow(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 void NetworkMenuButton::OpenButtonOptions() { | 100 void NetworkMenuButton::OpenButtonOptions() { |
| 101 host_->OpenButtonOptions(this); | 101 host_->OpenButtonOptions(this); |
| 102 } | 102 } |
| 103 | 103 |
| 104 bool NetworkMenuButton::ShouldOpenButtonOptions() const { | 104 bool NetworkMenuButton::ShouldOpenButtonOptions() const { |
| 105 return host_->ShouldOpenButtonOptions(this); | 105 return host_->ShouldOpenButtonOptions(this); |
| 106 } | 106 } |
| 107 | 107 |
| 108 //////////////////////////////////////////////////////////////////////////////// | 108 // NetworkMenuButton, views::View implementation: ----------------------------- |
| 109 // NetworkMenuButton, views::View implementation: | |
| 110 | 109 |
| 111 void NetworkMenuButton::OnLocaleChanged() { | 110 void NetworkMenuButton::OnLocaleChanged() { |
| 112 NetworkLibrary* lib = CrosLibrary::Get()->GetNetworkLibrary(); | 111 NetworkLibrary* lib = CrosLibrary::Get()->GetNetworkLibrary(); |
| 113 SetNetworkIcon(lib, lib->active_network()); | 112 SetNetworkIcon(lib, lib->active_network()); |
| 114 } | 113 } |
| 115 | 114 |
| 116 //////////////////////////////////////////////////////////////////////////////// | 115 // NetworkMenuButton, private methods ----------------------------------------- |
| 117 // NetworkMenuButton, private methods | |
| 118 | 116 |
| 119 void NetworkMenuButton::SetIconAndBadge(const SkBitmap* icon, | 117 void NetworkMenuButton::SetIconAndBadge(const SkBitmap* icon, |
| 120 const SkBitmap* badge) { | 118 const SkBitmap* badge) { |
| 121 icon_ = icon; | 119 icon_ = icon; |
| 122 badge_ = badge; | 120 badge_ = badge; |
| 123 SetIcon(IconForDisplay(icon_, badge_)); | 121 SetIcon(IconForDisplay(icon_, badge_)); |
| 124 } | 122 } |
| 125 | 123 |
| 126 void NetworkMenuButton::SetIconOnly(const SkBitmap* icon) { | 124 void NetworkMenuButton::SetIconOnly(const SkBitmap* icon) { |
| 127 icon_ = icon; | 125 icon_ = icon; |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 cros->RemoveNetworkObserver(active_network_, this); | 210 cros->RemoveNetworkObserver(active_network_, this); |
| 213 } | 211 } |
| 214 if (!new_network.empty()) { | 212 if (!new_network.empty()) { |
| 215 cros->AddNetworkObserver(new_network, this); | 213 cros->AddNetworkObserver(new_network, this); |
| 216 } | 214 } |
| 217 active_network_ = new_network; | 215 active_network_ = new_network; |
| 218 } | 216 } |
| 219 } | 217 } |
| 220 | 218 |
| 221 } // namespace chromeos | 219 } // namespace chromeos |
| OLD | NEW |