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

Side by Side Diff: trunk/src/ash/system/chromeos/network/tray_network.cc

Issue 383373002: Revert 282837 because it broke non-chromeos builds. (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 6 years, 5 months 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "ash/system/chromeos/network/tray_network.h" 5 #include "ash/system/chromeos/network/tray_network.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/metrics/user_metrics_recorder.h" 8 #include "ash/metrics/user_metrics_recorder.h"
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/system/chromeos/network/network_icon_animation.h"
10 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" 11 #include "ash/system/chromeos/network/network_state_list_detailed_view.h"
11 #include "ash/system/chromeos/network/tray_network_state_observer.h" 12 #include "ash/system/chromeos/network/tray_network_state_observer.h"
12 #include "ash/system/tray/system_tray.h" 13 #include "ash/system/tray/system_tray.h"
13 #include "ash/system/tray/system_tray_delegate.h" 14 #include "ash/system/tray/system_tray_delegate.h"
14 #include "ash/system/tray/system_tray_notifier.h" 15 #include "ash/system/tray/system_tray_notifier.h"
15 #include "ash/system/tray/tray_constants.h" 16 #include "ash/system/tray/tray_constants.h"
16 #include "ash/system/tray/tray_item_more.h" 17 #include "ash/system/tray/tray_item_more.h"
17 #include "ash/system/tray/tray_item_view.h" 18 #include "ash/system/tray/tray_item_view.h"
18 #include "ash/system/tray/tray_utils.h" 19 #include "ash/system/tray/tray_utils.h"
19 #include "base/command_line.h" 20 #include "base/command_line.h"
20 #include "base/strings/utf_string_conversions.h" 21 #include "base/strings/utf_string_conversions.h"
21 #include "chromeos/network/network_state.h" 22 #include "chromeos/network/network_state.h"
22 #include "chromeos/network/network_state_handler.h" 23 #include "chromeos/network/network_state_handler.h"
23 #include "grit/ash_resources.h" 24 #include "grit/ash_resources.h"
24 #include "grit/ash_strings.h" 25 #include "grit/ash_strings.h"
25 #include "grit/ui_chromeos_strings.h"
26 #include "third_party/cros_system_api/dbus/service_constants.h" 26 #include "third_party/cros_system_api/dbus/service_constants.h"
27 #include "ui/accessibility/ax_view_state.h" 27 #include "ui/accessibility/ax_view_state.h"
28 #include "ui/base/l10n/l10n_util.h" 28 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/base/resource/resource_bundle.h" 29 #include "ui/base/resource/resource_bundle.h"
30 #include "ui/chromeos/network/network_icon_animation.h"
31 #include "ui/views/controls/image_view.h" 30 #include "ui/views/controls/image_view.h"
32 #include "ui/views/controls/link.h" 31 #include "ui/views/controls/link.h"
33 #include "ui/views/controls/link_listener.h" 32 #include "ui/views/controls/link_listener.h"
34 #include "ui/views/layout/box_layout.h" 33 #include "ui/views/layout/box_layout.h"
35 #include "ui/views/widget/widget.h" 34 #include "ui/views/widget/widget.h"
36 35
37 using chromeos::NetworkHandler; 36 using chromeos::NetworkHandler;
38 using chromeos::NetworkState; 37 using chromeos::NetworkState;
39 using chromeos::NetworkStateHandler; 38 using chromeos::NetworkStateHandler;
40 using chromeos::NetworkTypePattern; 39 using chromeos::NetworkTypePattern;
41 40
42 namespace ash { 41 namespace ash {
43 namespace tray { 42 namespace tray {
44 43
45 class NetworkTrayView : public TrayItemView, 44 class NetworkTrayView : public TrayItemView,
46 public ui::network_icon::AnimationObserver { 45 public network_icon::AnimationObserver {
47 public: 46 public:
48 explicit NetworkTrayView(TrayNetwork* network_tray) 47 explicit NetworkTrayView(TrayNetwork* network_tray)
49 : TrayItemView(network_tray), 48 : TrayItemView(network_tray),
50 network_tray_(network_tray) { 49 network_tray_(network_tray) {
51 SetLayoutManager( 50 SetLayoutManager(
52 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); 51 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
53 52
54 image_view_ = new views::ImageView; 53 image_view_ = new views::ImageView;
55 AddChildView(image_view_); 54 AddChildView(image_view_);
56 55
57 UpdateNetworkStateHandlerIcon(); 56 UpdateNetworkStateHandlerIcon();
58 } 57 }
59 58
60 virtual ~NetworkTrayView() { 59 virtual ~NetworkTrayView() {
61 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 60 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
62 } 61 }
63 62
64 virtual const char* GetClassName() const OVERRIDE { 63 virtual const char* GetClassName() const OVERRIDE {
65 return "NetworkTrayView"; 64 return "NetworkTrayView";
66 } 65 }
67 66
68 void UpdateNetworkStateHandlerIcon() { 67 void UpdateNetworkStateHandlerIcon() {
69 NetworkStateHandler* handler = 68 NetworkStateHandler* handler =
70 NetworkHandler::Get()->network_state_handler(); 69 NetworkHandler::Get()->network_state_handler();
71 gfx::ImageSkia image; 70 gfx::ImageSkia image;
72 base::string16 name; 71 base::string16 name;
73 bool animating = false; 72 bool animating = false;
74 ui::network_icon::GetDefaultNetworkImageAndLabel( 73 network_icon::GetDefaultNetworkImageAndLabel(
75 ui::network_icon::ICON_TYPE_TRAY, &image, &name, &animating); 74 network_icon::ICON_TYPE_TRAY, &image, &name, &animating);
76 bool show_in_tray = !image.isNull(); 75 bool show_in_tray = !image.isNull();
77 UpdateIcon(show_in_tray, image); 76 UpdateIcon(show_in_tray, image);
78 if (animating) 77 if (animating)
79 ui::network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); 78 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
80 else 79 else
81 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver( 80 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
82 this);
83 // Update accessibility. 81 // Update accessibility.
84 const NetworkState* connected_network = 82 const NetworkState* connected_network =
85 handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual()); 83 handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual());
86 if (connected_network) { 84 if (connected_network) {
87 UpdateConnectionStatus( 85 UpdateConnectionStatus(
88 base::UTF8ToUTF16(connected_network->name()), true); 86 base::UTF8ToUTF16(connected_network->name()), true);
89 } else { 87 } else {
90 UpdateConnectionStatus(base::string16(), false); 88 UpdateConnectionStatus(base::string16(), false);
91 } 89 }
92 } 90 }
93 91
94 void UpdateAlignment(ShelfAlignment alignment) { 92 void UpdateAlignment(ShelfAlignment alignment) {
95 SetLayoutManager(new views::BoxLayout( 93 SetLayoutManager(new views::BoxLayout(
96 alignment == SHELF_ALIGNMENT_BOTTOM ? 94 alignment == SHELF_ALIGNMENT_BOTTOM ?
97 views::BoxLayout::kHorizontal : views::BoxLayout::kVertical, 95 views::BoxLayout::kHorizontal : views::BoxLayout::kVertical,
98 0, 0, 0)); 96 0, 0, 0));
99 Layout(); 97 Layout();
100 } 98 }
101 99
102 // views::View override. 100 // views::View override.
103 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE { 101 virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE {
104 state->name = connection_status_string_; 102 state->name = connection_status_string_;
105 state->role = ui::AX_ROLE_BUTTON; 103 state->role = ui::AX_ROLE_BUTTON;
106 } 104 }
107 105
108 // ui::network_icon::AnimationObserver 106 // network_icon::AnimationObserver
109 virtual void NetworkIconChanged() OVERRIDE { 107 virtual void NetworkIconChanged() OVERRIDE {
110 UpdateNetworkStateHandlerIcon(); 108 UpdateNetworkStateHandlerIcon();
111 } 109 }
112 110
113 private: 111 private:
114 // Updates connection status and notifies accessibility event when necessary. 112 // Updates connection status and notifies accessibility event when necessary.
115 void UpdateConnectionStatus(const base::string16& network_name, 113 void UpdateConnectionStatus(const base::string16& network_name,
116 bool connected) { 114 bool connected) {
117 base::string16 new_connection_status_string; 115 base::string16 new_connection_status_string;
118 if (connected) { 116 if (connected) {
(...skipping 14 matching lines...) Expand all
133 } 131 }
134 132
135 TrayNetwork* network_tray_; 133 TrayNetwork* network_tray_;
136 views::ImageView* image_view_; 134 views::ImageView* image_view_;
137 base::string16 connection_status_string_; 135 base::string16 connection_status_string_;
138 136
139 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView); 137 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView);
140 }; 138 };
141 139
142 class NetworkDefaultView : public TrayItemMore, 140 class NetworkDefaultView : public TrayItemMore,
143 public ui::network_icon::AnimationObserver { 141 public network_icon::AnimationObserver {
144 public: 142 public:
145 NetworkDefaultView(TrayNetwork* network_tray, bool show_more) 143 NetworkDefaultView(TrayNetwork* network_tray, bool show_more)
146 : TrayItemMore(network_tray, show_more), 144 : TrayItemMore(network_tray, show_more),
147 network_tray_(network_tray) { 145 network_tray_(network_tray) {
148 Update(); 146 Update();
149 } 147 }
150 148
151 virtual ~NetworkDefaultView() { 149 virtual ~NetworkDefaultView() {
152 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 150 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
153 } 151 }
154 152
155 void Update() { 153 void Update() {
156 gfx::ImageSkia image; 154 gfx::ImageSkia image;
157 base::string16 label; 155 base::string16 label;
158 bool animating = false; 156 bool animating = false;
159 ui::network_icon::GetDefaultNetworkImageAndLabel( 157 network_icon::GetDefaultNetworkImageAndLabel(
160 ui::network_icon::ICON_TYPE_DEFAULT_VIEW, &image, &label, &animating); 158 network_icon::ICON_TYPE_DEFAULT_VIEW, &image, &label, &animating);
161 if (animating) 159 if (animating)
162 ui::network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); 160 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
163 else 161 else
164 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver( 162 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
165 this);
166 SetImage(&image); 163 SetImage(&image);
167 SetLabel(label); 164 SetLabel(label);
168 SetAccessibleName(label); 165 SetAccessibleName(label);
169 } 166 }
170 167
171 // ui::network_icon::AnimationObserver 168 // network_icon::AnimationObserver
172 virtual void NetworkIconChanged() OVERRIDE { 169 virtual void NetworkIconChanged() OVERRIDE {
173 Update(); 170 Update();
174 } 171 }
175 172
176 private: 173 private:
177 TrayNetwork* network_tray_; 174 TrayNetwork* network_tray_;
178 175
179 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView); 176 DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView);
180 }; 177 };
181 178
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 detailed_->ManagerChanged(); 365 detailed_->ManagerChanged();
369 } 366 }
370 } 367 }
371 368
372 void TrayNetwork::NetworkServiceChanged(const chromeos::NetworkState* network) { 369 void TrayNetwork::NetworkServiceChanged(const chromeos::NetworkState* network) {
373 if (detailed_) 370 if (detailed_)
374 detailed_->NetworkServiceChanged(network); 371 detailed_->NetworkServiceChanged(network);
375 } 372 }
376 373
377 } // namespace ash 374 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698