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