Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1057)

Side by Side Diff: chrome/browser/chromeos/status/network_menu_button.cc

Issue 4154002: New statusbar images for ChromeOS (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 "app/l10n_util.h" 10 #include "app/l10n_util.h"
11 #include "app/resource_bundle.h" 11 #include "app/resource_bundle.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/chromeos/cros/cros_library.h" 14 #include "chrome/browser/chromeos/cros/cros_library.h"
15 #include "chrome/browser/chromeos/options/network_config_view.h" 15 #include "chrome/browser/chromeos/options/network_config_view.h"
16 #include "chrome/browser/chromeos/status/status_area_host.h" 16 #include "chrome/browser/chromeos/status/status_area_host.h"
17 #include "gfx/canvas_skia.h" 17 #include "gfx/canvas_skia.h"
18 #include "gfx/skbitmap_operations.h"
18 #include "grit/generated_resources.h" 19 #include "grit/generated_resources.h"
19 #include "grit/theme_resources.h" 20 #include "grit/theme_resources.h"
20 #include "views/window/window.h" 21 #include "views/window/window.h"
21 22
22 namespace chromeos { 23 namespace chromeos {
23 24
24 //////////////////////////////////////////////////////////////////////////////// 25 ////////////////////////////////////////////////////////////////////////////////
25 // NetworkMenuButton 26 // NetworkMenuButton
26 27
27 // static 28 // static
28 const int NetworkMenuButton::kThrobDuration = 1000; 29 const int NetworkMenuButton::kThrobDuration = 1000;
29 30
30 NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host) 31 NetworkMenuButton::NetworkMenuButton(StatusAreaHost* host)
31 : StatusAreaButton(this), 32 : StatusAreaButton(this),
32 NetworkMenu(), 33 NetworkMenu(),
33 host_(host), 34 host_(host),
34 ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)) { 35 ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)) {
35 animation_connecting_.SetThrobDuration(kThrobDuration); 36 animation_connecting_.SetThrobDuration(kThrobDuration);
36 animation_connecting_.SetTweenType(Tween::LINEAR); 37 animation_connecting_.SetTweenType(Tween::EASE_IN_OUT);
37 NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary()); 38 NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary());
38 CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this); 39 CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this);
39 } 40 }
40 41
41 NetworkMenuButton::~NetworkMenuButton() { 42 NetworkMenuButton::~NetworkMenuButton() {
42 CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(this); 43 CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(this);
43 } 44 }
44 45
45 //////////////////////////////////////////////////////////////////////////////// 46 ////////////////////////////////////////////////////////////////////////////////
46 // NetworkMenuButton, AnimationDelegate implementation: 47 // NetworkMenuButton, AnimationDelegate implementation:
47 48
48 void NetworkMenuButton::AnimationProgressed(const Animation* animation) { 49 void NetworkMenuButton::AnimationProgressed(const Animation* animation) {
49 if (animation == &animation_connecting_) { 50 if (animation == &animation_connecting_) {
50 // Figure out which image to draw. We want a value between 0-100. 51 // Draw animation of bars icon fading in and out.
51 // 0 reperesents no signal and 100 represents full signal strength. 52 // We are fading between 0 bars and a third of the opacity of 4 bars.
52 int value = static_cast<int>(animation_connecting_.GetCurrentValue()*100.0); 53 // Use the current value of the animation to calculate the alpha value
53 if (value < 0) 54 // of how transparent the icon is.
54 value = 0; 55 SetIcon(SkBitmapOperations::CreateBlendedBitmap(
55 else if (value > 100) 56 *ResourceBundle::GetSharedInstance().GetBitmapNamed(
56 value = 100; 57 IDR_STATUSBAR_NETWORK_BARS0),
57 SetIcon(IconForNetworkStrength(value, false)); 58 *ResourceBundle::GetSharedInstance().GetBitmapNamed(
59 IDR_STATUSBAR_NETWORK_BARS4),
60 animation_connecting_.GetCurrentValue() / 3));
58 SchedulePaint(); 61 SchedulePaint();
59 } else { 62 } else {
60 MenuButton::AnimationProgressed(animation); 63 MenuButton::AnimationProgressed(animation);
61 } 64 }
62 } 65 }
63 66
64 //////////////////////////////////////////////////////////////////////////////// 67 ////////////////////////////////////////////////////////////////////////////////
65 // NetworkMenuButton, StatusAreaButton implementation: 68 // NetworkMenuButton, StatusAreaButton implementation:
66 69
67 void NetworkMenuButton::DrawPressed(gfx::Canvas* canvas) {
68 // If ethernet connected and not current connecting, then show ethernet
69 // pressed icon. Otherwise, show the bars pressed icon.
70 if (CrosLibrary::Get()->GetNetworkLibrary()->ethernet_connected() &&
71 !animation_connecting_.is_animating())
72 canvas->DrawBitmapInt(IconForDisplay(
73 *ResourceBundle::GetSharedInstance().
74 GetBitmapNamed(IDR_STATUSBAR_NETWORK_WIRED_PRESSED), SkBitmap()),
75 0, 0);
76 else
77 canvas->DrawBitmapInt(IconForDisplay(
78 *ResourceBundle::GetSharedInstance().
79 GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS_PRESSED), SkBitmap()),
80 0, 0);
81 }
82
83 void NetworkMenuButton::DrawIcon(gfx::Canvas* canvas) { 70 void NetworkMenuButton::DrawIcon(gfx::Canvas* canvas) {
84 canvas->DrawBitmapInt(IconForDisplay(icon(), badge()), 0, 0); 71 canvas->DrawBitmapInt(IconForDisplay(icon(), badge()), 0, 0);
85 } 72 }
86 73
87 //////////////////////////////////////////////////////////////////////////////// 74 ////////////////////////////////////////////////////////////////////////////////
88 // NetworkMenuButton, NetworkLibrary::Observer implementation: 75 // NetworkMenuButton, NetworkLibrary::Observer implementation:
89 76
90 void NetworkMenuButton::NetworkChanged(NetworkLibrary* cros) { 77 void NetworkMenuButton::NetworkChanged(NetworkLibrary* cros) {
91 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); 78 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
92 if (CrosLibrary::Get()->EnsureLoaded()) { 79 if (CrosLibrary::Get()->EnsureLoaded()) {
93 if (cros->wifi_connecting() || cros->cellular_connecting()) { 80 if (cros->wifi_connecting() || cros->cellular_connecting()) {
94 // Start the connecting animation if not running. 81 // Start the connecting animation if not running.
95 if (!animation_connecting_.is_animating()) { 82 if (!animation_connecting_.is_animating()) {
96 animation_connecting_.Reset(); 83 animation_connecting_.Reset();
97 animation_connecting_.StartThrobbing(std::numeric_limits<int>::max()); 84 animation_connecting_.StartThrobbing(std::numeric_limits<int>::max());
98 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS1)); 85 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0));
99 } 86 }
100 std::string network_name = cros->wifi_connecting() ? 87 std::string network_name = cros->wifi_connecting() ?
101 cros->wifi_network().name() : cros->cellular_network().name(); 88 cros->wifi_network().name() : cros->cellular_network().name();
102 SetTooltipText( 89 SetTooltipText(
103 l10n_util::GetStringF(IDS_STATUSBAR_NETWORK_CONNECTING_TOOLTIP, 90 l10n_util::GetStringF(IDS_STATUSBAR_NETWORK_CONNECTING_TOOLTIP,
104 UTF8ToWide(network_name))); 91 UTF8ToWide(network_name)));
105 } else { 92 } else {
106 // Stop connecting animation since we are not connecting. 93 // Stop connecting animation since we are not connecting.
107 animation_connecting_.Stop(); 94 animation_connecting_.Stop();
108 95
(...skipping 21 matching lines...) Expand all
130 SetTooltipText(l10n_util::GetStringF( 117 SetTooltipText(l10n_util::GetStringF(
131 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP, 118 IDS_STATUSBAR_NETWORK_CONNECTED_TOOLTIP,
132 UTF8ToWide(cellular.name()))); 119 UTF8ToWide(cellular.name())));
133 } else { 120 } else {
134 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0)); 121 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0));
135 SetTooltipText(l10n_util::GetString( 122 SetTooltipText(l10n_util::GetString(
136 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP)); 123 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP));
137 } 124 }
138 } 125 }
139 126
140 if (!cros->Connected() && !cros->Connecting()) { 127 // Figure out whether or not to show a badge.
141 SetBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED)); 128 int id = -1;
142 } else if (!cros->ethernet_connected() && !cros->wifi_connected() && 129 if (cros->Connecting()) {
143 (cros->cellular_connecting() || cros->cellular_connected())) { 130 if (cros->cellular_connecting()) {
144 int id = IDR_STATUSBAR_NETWORK_3G; 131 id = IDR_STATUSBAR_NETWORK_3G;
145 switch (cros->cellular_network().data_left()) {
146 case CellularNetwork::DATA_NONE:
147 case CellularNetwork::DATA_VERY_LOW:
148 id = IDR_STATUSBAR_NETWORK_3G_VLOWDATA;
149 break;
150 case CellularNetwork::DATA_LOW:
151 id = IDR_STATUSBAR_NETWORK_3G_LOWDATA;
152 break;
153 case CellularNetwork::DATA_NORMAL:
154 id = IDR_STATUSBAR_NETWORK_3G;
155 break;
156 } 132 }
133 } else if (cros->Connected()) {
134 if (!cros->ethernet_connected() && !cros->wifi_connected() &&
135 cros->cellular_connected()) {
136 switch (cros->cellular_network().data_left()) {
137 case CellularNetwork::DATA_NONE:
138 case CellularNetwork::DATA_VERY_LOW:
139 id = IDR_STATUSBAR_NETWORK_3G_ERROR;
140 break;
141 case CellularNetwork::DATA_LOW:
142 id = IDR_STATUSBAR_NETWORK_3G_WARN;
143 break;
144 case CellularNetwork::DATA_NORMAL:
145 id = IDR_STATUSBAR_NETWORK_3G;
146 break;
147 }
148 }
149 } else {
150 id = IDR_STATUSBAR_NETWORK_DISCONNECTED;
151 }
152 if (id != -1) {
157 SetBadge(*rb.GetBitmapNamed(id)); 153 SetBadge(*rb.GetBitmapNamed(id));
158 } else { 154 } else {
159 SetBadge(SkBitmap()); 155 SetBadge(SkBitmap());
160 } 156 }
161 } else { 157 } else {
162 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0)); 158 SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0));
163 SetBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_WARNING)); 159 SetBadge(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_WARNING));
164 SetTooltipText(l10n_util::GetString( 160 SetTooltipText(l10n_util::GetString(
165 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP)); 161 IDS_STATUSBAR_NETWORK_NO_NETWORK_TOOLTIP));
166 } 162 }
167 163
168 SchedulePaint(); 164 SchedulePaint();
169 UpdateMenu(); 165 UpdateMenu();
170 } 166 }
171 167
172 void NetworkMenuButton::CellularDataPlanChanged(NetworkLibrary* cros) { 168 void NetworkMenuButton::CellularDataPlanChanged(NetworkLibrary* cros) {
173 // Call NetworkChanged which will update the icon. 169 // Call NetworkChanged which will update the icon.
174 NetworkChanged(cros); 170 NetworkChanged(cros);
175 } 171 }
176 172
177 void NetworkMenuButton::SetBadge(const SkBitmap& badge) {
178 badge_ = badge;
179 }
180
181 //////////////////////////////////////////////////////////////////////////////// 173 ////////////////////////////////////////////////////////////////////////////////
182 // NetworkMenuButton, NetworkMenu implementation: 174 // NetworkMenuButton, NetworkMenu implementation:
183 175
184 bool NetworkMenuButton::IsBrowserMode() const { 176 bool NetworkMenuButton::IsBrowserMode() const {
185 return host_->IsBrowserMode(); 177 return host_->IsBrowserMode();
186 } 178 }
187 179
188 gfx::NativeWindow NetworkMenuButton::GetNativeWindow() const { 180 gfx::NativeWindow NetworkMenuButton::GetNativeWindow() const {
189 return host_->GetNativeWindow(); 181 return host_->GetNativeWindow();
190 } 182 }
191 183
192 void NetworkMenuButton::OpenButtonOptions() const { 184 void NetworkMenuButton::OpenButtonOptions() const {
193 host_->OpenButtonOptions(this); 185 host_->OpenButtonOptions(this);
194 } 186 }
195 187
196 bool NetworkMenuButton::ShouldOpenButtonOptions() const { 188 bool NetworkMenuButton::ShouldOpenButtonOptions() const {
197 return host_->ShouldOpenButtonOptions(this); 189 return host_->ShouldOpenButtonOptions(this);
198 } 190 }
199 191
200 } // namespace chromeos 192 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/status/network_menu_button.h ('k') | chrome/browser/chromeos/status/power_menu_button.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698