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

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

Issue 2435903002: Move tray code from ui/chromeos/network/ (Closed)
Patch Set: Rebase Created 4 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
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/common/system/chromeos/network/tray_network.h" 5 #include "ash/common/system/chromeos/network/tray_network.h"
6 6
7 #include "ash/common/shelf/wm_shelf_util.h" 7 #include "ash/common/shelf/wm_shelf_util.h"
8 #include "ash/common/system/chromeos/network/network_icon.h"
9 #include "ash/common/system/chromeos/network/network_icon_animation.h"
10 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h"
8 #include "ash/common/system/chromeos/network/network_state_list_detailed_view.h" 11 #include "ash/common/system/chromeos/network/network_state_list_detailed_view.h"
9 #include "ash/common/system/chromeos/network/tray_network_state_observer.h" 12 #include "ash/common/system/chromeos/network/tray_network_state_observer.h"
10 #include "ash/common/system/tray/system_tray.h" 13 #include "ash/common/system/tray/system_tray.h"
11 #include "ash/common/system/tray/system_tray_delegate.h" 14 #include "ash/common/system/tray/system_tray_delegate.h"
12 #include "ash/common/system/tray/system_tray_notifier.h" 15 #include "ash/common/system/tray/system_tray_notifier.h"
13 #include "ash/common/system/tray/tray_constants.h" 16 #include "ash/common/system/tray/tray_constants.h"
14 #include "ash/common/system/tray/tray_item_more.h" 17 #include "ash/common/system/tray/tray_item_more.h"
15 #include "ash/common/system/tray/tray_item_view.h" 18 #include "ash/common/system/tray/tray_item_view.h"
16 #include "ash/common/system/tray/tray_popup_item_style.h" 19 #include "ash/common/system/tray/tray_popup_item_style.h"
17 #include "ash/common/system/tray/tray_utils.h" 20 #include "ash/common/system/tray/tray_utils.h"
18 #include "ash/common/wm_shell.h" 21 #include "ash/common/wm_shell.h"
19 #include "base/command_line.h" 22 #include "base/command_line.h"
20 #include "base/strings/utf_string_conversions.h" 23 #include "base/strings/utf_string_conversions.h"
21 #include "chromeos/network/network_state.h" 24 #include "chromeos/network/network_state.h"
22 #include "chromeos/network/network_state_handler.h" 25 #include "chromeos/network/network_state_handler.h"
23 #include "grit/ash_resources.h" 26 #include "grit/ash_resources.h"
24 #include "grit/ash_strings.h" 27 #include "grit/ash_strings.h"
25 #include "grit/ui_chromeos_strings.h"
26 #include "third_party/cros_system_api/dbus/service_constants.h" 28 #include "third_party/cros_system_api/dbus/service_constants.h"
27 #include "ui/accessibility/ax_view_state.h" 29 #include "ui/accessibility/ax_view_state.h"
28 #include "ui/base/l10n/l10n_util.h" 30 #include "ui/base/l10n/l10n_util.h"
29 #include "ui/base/resource/resource_bundle.h" 31 #include "ui/base/resource/resource_bundle.h"
30 #include "ui/chromeos/network/network_icon.h"
31 #include "ui/chromeos/network/network_icon_animation.h"
32 #include "ui/chromeos/network/network_icon_animation_observer.h"
33 #include "ui/views/controls/image_view.h" 32 #include "ui/views/controls/image_view.h"
34 #include "ui/views/controls/link.h" 33 #include "ui/views/controls/link.h"
35 #include "ui/views/controls/link_listener.h" 34 #include "ui/views/controls/link_listener.h"
36 #include "ui/views/layout/box_layout.h" 35 #include "ui/views/layout/box_layout.h"
37 #include "ui/views/widget/widget.h" 36 #include "ui/views/widget/widget.h"
38 37
39 using chromeos::NetworkHandler; 38 using chromeos::NetworkHandler;
40 using chromeos::NetworkState; 39 using chromeos::NetworkState;
41 using chromeos::NetworkStateHandler; 40 using chromeos::NetworkStateHandler;
42 using chromeos::NetworkTypePattern; 41 using chromeos::NetworkTypePattern;
43 42
44 namespace ash { 43 namespace ash {
45 namespace tray { 44 namespace tray {
46 45
47 class NetworkTrayView : public TrayItemView, 46 class NetworkTrayView : public TrayItemView,
48 public ui::network_icon::AnimationObserver { 47 public network_icon::AnimationObserver {
49 public: 48 public:
50 explicit NetworkTrayView(TrayNetwork* network_tray) 49 explicit NetworkTrayView(TrayNetwork* network_tray)
51 : TrayItemView(network_tray) { 50 : TrayItemView(network_tray) {
52 SetLayoutManager( 51 SetLayoutManager(
53 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); 52 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0));
54 53
55 image_view_ = new views::ImageView; 54 image_view_ = new views::ImageView;
56 AddChildView(image_view_); 55 AddChildView(image_view_);
57 56
58 UpdateNetworkStateHandlerIcon(); 57 UpdateNetworkStateHandlerIcon();
59 } 58 }
60 59
61 ~NetworkTrayView() override { 60 ~NetworkTrayView() override {
62 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 61 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
63 } 62 }
64 63
65 const char* GetClassName() const override { return "NetworkTrayView"; } 64 const char* GetClassName() const override { return "NetworkTrayView"; }
66 65
67 void UpdateNetworkStateHandlerIcon() { 66 void UpdateNetworkStateHandlerIcon() {
68 NetworkStateHandler* handler = 67 NetworkStateHandler* handler =
69 NetworkHandler::Get()->network_state_handler(); 68 NetworkHandler::Get()->network_state_handler();
70 gfx::ImageSkia image; 69 gfx::ImageSkia image;
71 base::string16 name; 70 base::string16 name;
72 bool animating = false; 71 bool animating = false;
73 ui::network_icon::GetDefaultNetworkImageAndLabel( 72 network_icon::GetDefaultNetworkImageAndLabel(network_icon::ICON_TYPE_TRAY,
74 ui::network_icon::ICON_TYPE_TRAY, &image, &name, &animating); 73 &image, &name, &animating);
75 bool show_in_tray = !image.isNull(); 74 bool show_in_tray = !image.isNull();
76 UpdateIcon(show_in_tray, image); 75 UpdateIcon(show_in_tray, image);
77 if (animating) 76 if (animating)
78 ui::network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); 77 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
79 else 78 else
80 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver( 79 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
81 this);
82 // Update accessibility. 80 // Update accessibility.
83 const NetworkState* connected_network = 81 const NetworkState* connected_network =
84 handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual()); 82 handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual());
85 if (connected_network) { 83 if (connected_network) {
86 UpdateConnectionStatus(base::UTF8ToUTF16(connected_network->name()), 84 UpdateConnectionStatus(base::UTF8ToUTF16(connected_network->name()),
87 true); 85 true);
88 } else { 86 } else {
89 UpdateConnectionStatus(base::string16(), false); 87 UpdateConnectionStatus(base::string16(), false);
90 } 88 }
91 } 89 }
92 90
93 void UpdateAlignment(ShelfAlignment alignment) { 91 void UpdateAlignment(ShelfAlignment alignment) {
94 SetLayoutManager(new views::BoxLayout(IsHorizontalAlignment(alignment) 92 SetLayoutManager(new views::BoxLayout(IsHorizontalAlignment(alignment)
95 ? views::BoxLayout::kHorizontal 93 ? views::BoxLayout::kHorizontal
96 : views::BoxLayout::kVertical, 94 : views::BoxLayout::kVertical,
97 0, 0, 0)); 95 0, 0, 0));
98 Layout(); 96 Layout();
99 } 97 }
100 98
101 // views::View: 99 // views::View:
102 void GetAccessibleState(ui::AXViewState* state) override { 100 void GetAccessibleState(ui::AXViewState* state) override {
103 state->name = connection_status_string_; 101 state->name = connection_status_string_;
104 state->role = ui::AX_ROLE_BUTTON; 102 state->role = ui::AX_ROLE_BUTTON;
105 } 103 }
106 104
107 // ui::network_icon::AnimationObserver: 105 // network_icon::AnimationObserver:
108 void NetworkIconChanged() override { UpdateNetworkStateHandlerIcon(); } 106 void NetworkIconChanged() override { UpdateNetworkStateHandlerIcon(); }
109 107
110 private: 108 private:
111 // Updates connection status and notifies accessibility event when necessary. 109 // Updates connection status and notifies accessibility event when necessary.
112 void UpdateConnectionStatus(const base::string16& network_name, 110 void UpdateConnectionStatus(const base::string16& network_name,
113 bool connected) { 111 bool connected) {
114 base::string16 new_connection_status_string; 112 base::string16 new_connection_status_string;
115 if (connected) { 113 if (connected) {
116 new_connection_status_string = l10n_util::GetStringFUTF16( 114 new_connection_status_string = l10n_util::GetStringFUTF16(
117 IDS_ASH_STATUS_TRAY_NETWORK_CONNECTED, network_name); 115 IDS_ASH_STATUS_TRAY_NETWORK_CONNECTED, network_name);
(...skipping 11 matching lines...) Expand all
129 SchedulePaint(); 127 SchedulePaint();
130 } 128 }
131 129
132 views::ImageView* image_view_; 130 views::ImageView* image_view_;
133 base::string16 connection_status_string_; 131 base::string16 connection_status_string_;
134 132
135 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView); 133 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView);
136 }; 134 };
137 135
138 class NetworkDefaultView : public TrayItemMore, 136 class NetworkDefaultView : public TrayItemMore,
139 public ui::network_icon::AnimationObserver { 137 public network_icon::AnimationObserver {
140 public: 138 public:
141 NetworkDefaultView(TrayNetwork* network_tray, bool show_more) 139 NetworkDefaultView(TrayNetwork* network_tray, bool show_more)
142 : TrayItemMore(network_tray, show_more) { 140 : TrayItemMore(network_tray, show_more) {
143 Update(); 141 Update();
144 } 142 }
145 143
146 ~NetworkDefaultView() override { 144 ~NetworkDefaultView() override {
147 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 145 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
148 } 146 }
149 147
150 void Update() { 148 void Update() {
151 gfx::ImageSkia image; 149 gfx::ImageSkia image;
152 base::string16 label; 150 base::string16 label;
153 bool animating = false; 151 bool animating = false;
154 // TODO(bruthig): Update the image to use the proper color. See 152 // TODO(bruthig): Update the image to use the proper color. See
155 // https://crbug.com/632027. 153 // https://crbug.com/632027.
156 ui::network_icon::GetDefaultNetworkImageAndLabel( 154 network_icon::GetDefaultNetworkImageAndLabel(
157 ui::network_icon::ICON_TYPE_DEFAULT_VIEW, &image, &label, &animating); 155 network_icon::ICON_TYPE_DEFAULT_VIEW, &image, &label, &animating);
158 if (animating) 156 if (animating)
159 ui::network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); 157 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this);
160 else 158 else
161 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver( 159 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
162 this);
163 SetImage(image); 160 SetImage(image);
164 SetLabel(label); 161 SetLabel(label);
165 SetAccessibleName(label); 162 SetAccessibleName(label);
166 } 163 }
167 164
168 // ui::network_icon::AnimationObserver 165 // network_icon::AnimationObserver
169 void NetworkIconChanged() override { Update(); } 166 void NetworkIconChanged() override { Update(); }
170 167
171 protected: 168 protected:
172 // TrayItemMore: 169 // TrayItemMore:
173 std::unique_ptr<TrayPopupItemStyle> CreateStyle() const override { 170 std::unique_ptr<TrayPopupItemStyle> CreateStyle() const override {
174 // TODO(bruthig): Apply different ColorStyles based on network state. See 171 // TODO(bruthig): Apply different ColorStyles based on network state. See
175 // https://crbug.com/632027. 172 // https://crbug.com/632027.
176 return TrayItemMore::CreateStyle(); 173 return TrayItemMore::CreateStyle();
177 } 174 }
178 175
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 void TrayNetwork::NetworkStateChanged() { 337 void TrayNetwork::NetworkStateChanged() {
341 if (tray_) 338 if (tray_)
342 tray_->UpdateNetworkStateHandlerIcon(); 339 tray_->UpdateNetworkStateHandlerIcon();
343 if (default_) 340 if (default_)
344 default_->Update(); 341 default_->Update();
345 if (detailed_) 342 if (detailed_)
346 detailed_->Update(); 343 detailed_->Update();
347 } 344 }
348 345
349 } // namespace ash 346 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698