1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/chromeos/status/network_dropdown_button.h"
#include "app/l10n_util.h"
#include "app/resource_bundle.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/options/network_config_view.h"
#include "chrome/browser/chromeos/status/status_area_host.h"
#include "gfx/canvas_skia.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "views/window/window.h"
namespace chromeos {
////////////////////////////////////////////////////////////////////////////////
// NetworkDropdownButton
// static
const int NetworkDropdownButton::kThrobDuration = 1000;
NetworkDropdownButton::NetworkDropdownButton(bool browser_mode,
gfx::NativeWindow parent_window)
: MenuButton(NULL,
l10n_util::GetString(IDS_STATUSBAR_NO_NETWORKS_MESSAGE),
this,
true),
browser_mode_(browser_mode),
ALLOW_THIS_IN_INITIALIZER_LIST(animation_connecting_(this)),
parent_window_(parent_window) {
animation_connecting_.SetThrobDuration(kThrobDuration);
animation_connecting_.SetTweenType(Tween::LINEAR);
NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary());
CrosLibrary::Get()->GetNetworkLibrary()->AddObserver(this);
}
NetworkDropdownButton::~NetworkDropdownButton() {
CrosLibrary::Get()->GetNetworkLibrary()->RemoveObserver(this);
}
////////////////////////////////////////////////////////////////////////////////
// NetworkMenuButton, AnimationDelegate implementation:
void NetworkDropdownButton::AnimationProgressed(const Animation* animation) {
if (animation == &animation_connecting_) {
// Figure out which image to draw. We want a value between 0-100.
// 0 represents no signal and 100 represents full signal strength.
int value = static_cast<int>(animation_connecting_.GetCurrentValue()*100.0);
if (value < 0)
value = 0;
else if (value > 100)
value = 100;
SetIcon(IconForNetworkStrength(value, true));
SchedulePaint();
} else {
MenuButton::AnimationProgressed(animation);
}
}
void NetworkDropdownButton::Refresh() {
NetworkChanged(CrosLibrary::Get()->GetNetworkLibrary());
}
////////////////////////////////////////////////////////////////////////////////
// NetworkDropdownButton, NetworkLibrary::Observer implementation:
void NetworkDropdownButton::NetworkChanged(NetworkLibrary* cros) {
// Show network that we will actually use. It could be another network than
// user selected. For example user selected WiFi network but we have Ethernet
// connection and Chrome OS device will actually use Ethernet.
// This gets called on initialization, so any changes should be reflected
// in CrosMock::SetNetworkLibraryStatusAreaExpectations().
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
if (CrosLibrary::Get()->EnsureLoaded()) {
// Always show the higher priority connection first. Ethernet then wifi.
if (cros->ethernet_connected()) {
animation_connecting_.Stop();
SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_WIRED));
SetText(l10n_util::GetString(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET));
} else if (cros->wifi_connected()) {
animation_connecting_.Stop();
SetIcon(IconForNetworkStrength(
cros->wifi_network().strength(), true));
SetText(ASCIIToWide(cros->wifi_network().name()));
} else if (cros->cellular_connected()) {
animation_connecting_.Stop();
SetIcon(IconForNetworkStrength(
cros->cellular_network().strength(), false));
SetText(ASCIIToWide(cros->cellular_network().name()));
} else if (cros->wifi_connecting() || cros->cellular_connecting()) {
if (!animation_connecting_.is_animating()) {
animation_connecting_.Reset();
animation_connecting_.StartThrobbing(-1);
SetIcon(*rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS1_BLACK));
}
if (cros->wifi_connecting())
SetText(ASCIIToWide(cros->wifi_network().name()));
else if (cros->cellular_connecting())
SetText(ASCIIToWide(cros->cellular_network().name()));
}
if (!cros->Connected() && !cros->Connecting()) {
animation_connecting_.Stop();
SetIcon(SkBitmap());
SetText(l10n_util::GetString(IDS_NETWORK_SELECTION_NONE));
}
} else {
animation_connecting_.Stop();
SetIcon(SkBitmap());
SetText(l10n_util::GetString(IDS_STATUSBAR_NO_NETWORKS_MESSAGE));
}
SchedulePaint();
}
} // namespace chromeos
|