OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "athena/system/network_selector.h" | 5 #include "athena/system/network_selector.h" |
6 | 6 |
| 7 #include "athena/screen/public/screen_manager.h" |
7 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
8 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
9 #include "chromeos/network/network_configuration_handler.h" | 10 #include "chromeos/network/network_configuration_handler.h" |
10 #include "chromeos/network/network_connection_handler.h" | 11 #include "chromeos/network/network_connection_handler.h" |
11 #include "chromeos/network/network_handler.h" | 12 #include "chromeos/network/network_handler.h" |
12 #include "chromeos/network/network_profile_handler.h" | 13 #include "chromeos/network/network_profile_handler.h" |
13 #include "chromeos/network/network_state.h" | 14 #include "chromeos/network/network_state.h" |
14 #include "chromeos/network/network_state_handler.h" | 15 #include "chromeos/network/network_state_handler.h" |
15 #include "chromeos/network/network_state_handler_observer.h" | 16 #include "chromeos/network/network_state_handler_observer.h" |
16 #include "chromeos/network/network_type_pattern.h" | 17 #include "chromeos/network/network_type_pattern.h" |
(...skipping 14 matching lines...) Expand all Loading... |
31 #include "ui/views/controls/button/blue_button.h" | 32 #include "ui/views/controls/button/blue_button.h" |
32 #include "ui/views/controls/button/button.h" | 33 #include "ui/views/controls/button/button.h" |
33 #include "ui/views/controls/image_view.h" | 34 #include "ui/views/controls/image_view.h" |
34 #include "ui/views/controls/label.h" | 35 #include "ui/views/controls/label.h" |
35 #include "ui/views/controls/scroll_view.h" | 36 #include "ui/views/controls/scroll_view.h" |
36 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" | 37 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h" |
37 #include "ui/views/controls/textfield/textfield.h" | 38 #include "ui/views/controls/textfield/textfield.h" |
38 #include "ui/views/layout/box_layout.h" | 39 #include "ui/views/layout/box_layout.h" |
39 #include "ui/views/layout/fill_layout.h" | 40 #include "ui/views/layout/fill_layout.h" |
40 #include "ui/views/widget/widget.h" | 41 #include "ui/views/widget/widget.h" |
| 42 #include "ui/views/window/dialog_delegate.h" |
41 | 43 |
42 using chromeos::NetworkConfigurationHandler; | 44 using chromeos::NetworkConfigurationHandler; |
43 using chromeos::NetworkConnectionHandler; | 45 using chromeos::NetworkConnectionHandler; |
44 using chromeos::NetworkHandler; | 46 using chromeos::NetworkHandler; |
45 using chromeos::NetworkProfileHandler; | 47 using chromeos::NetworkProfileHandler; |
46 using chromeos::NetworkState; | 48 using chromeos::NetworkState; |
47 | 49 |
48 namespace { | 50 namespace { |
49 | 51 |
50 const int kBackgroundColor = SkColorSetARGB(0x7f, 0, 0, 0); | 52 const int kBackgroundColor = SkColorSetARGB(0x7f, 0, 0, 0); |
51 | 53 |
52 // The View for the user to enter the password for connceting to a network. This | 54 // The View for the user to enter the password for connceting to a network. This |
53 // view also shows an error message if the network connection fails. | 55 // view also shows an error message if the network connection fails. |
54 class PasswordView : public views::View, public views::ButtonListener { | 56 class PasswordView : public views::View, public views::ButtonListener { |
55 public: | 57 public: |
56 PasswordView(const ui::NetworkInfo& network, | 58 PasswordView(const ui::NetworkInfo& network, |
57 const base::Callback<void(bool)>& callback, | 59 const base::Callback<void(bool)>& callback) |
58 views::View* parent_container) | |
59 : network_(network), | 60 : network_(network), |
60 callback_(callback), | 61 callback_(callback), |
61 parent_container_(parent_container), | |
62 connect_(NULL), | 62 connect_(NULL), |
63 cancel_(NULL), | 63 cancel_(NULL), |
64 textfield_(NULL), | 64 textfield_(NULL), |
65 error_msg_(NULL), | 65 error_msg_(NULL), |
66 weak_ptr_(this) { | 66 weak_ptr_(this) { |
67 const int kHorizontal = 5; | 67 const int kHorizontal = 5; |
68 const int kVertical = 0; | 68 const int kVertical = 0; |
69 const int kPadding = 0; | 69 const int kPadding = 0; |
70 | 70 |
71 views::BoxLayout* layout = new views::BoxLayout( | 71 views::BoxLayout* layout = new views::BoxLayout( |
(...skipping 23 matching lines...) Expand all Loading... |
95 cancel_ = new views::LabelButton(this, base::ASCIIToUTF16("Cancel")); | 95 cancel_ = new views::LabelButton(this, base::ASCIIToUTF16("Cancel")); |
96 cancel_->SetHorizontalAlignment(gfx::ALIGN_CENTER); | 96 cancel_->SetHorizontalAlignment(gfx::ALIGN_CENTER); |
97 container->AddChildView(cancel_); | 97 container->AddChildView(cancel_); |
98 | 98 |
99 AddChildView(container); | 99 AddChildView(container); |
100 } | 100 } |
101 | 101 |
102 virtual ~PasswordView() {} | 102 virtual ~PasswordView() {} |
103 | 103 |
104 private: | 104 private: |
105 void Close(bool successful) { callback_.Run(successful); } | 105 void CloseDialog(bool successful) { callback_.Run(successful); } |
106 | 106 |
107 void OnKnownError(const std::string& error_name, | 107 void OnKnownError(const std::string& error_name, |
108 scoped_ptr<base::DictionaryValue> error_data) { | 108 scoped_ptr<base::DictionaryValue> error_data) { |
109 std::string message; | 109 std::string message; |
110 if (!error_data->GetString(chromeos::network_handler::kDbusErrorMessage, | 110 if (!error_data->GetString(chromeos::network_handler::kDbusErrorMessage, |
111 &message)) | 111 &message)) |
112 message = error_name; | 112 message = error_name; |
113 if (message.empty()) | 113 if (message.empty()) |
114 message = std::string("Unknown error."); | 114 message = std::string("Unknown error."); |
115 if (!error_msg_) { | 115 if (!error_msg_) { |
116 error_msg_ = new views::Label(); | 116 error_msg_ = new views::Label(); |
117 error_msg_->SetFontList( | 117 error_msg_->SetFontList( |
118 error_msg_->font_list().Derive(0, gfx::Font::BOLD)); | 118 error_msg_->font_list().Derive(0, gfx::Font::BOLD)); |
119 error_msg_->SetEnabledColor(SK_ColorRED); | 119 error_msg_->SetEnabledColor(SK_ColorRED); |
120 } | 120 } |
121 error_msg_->SetText(base::UTF8ToUTF16(message)); | 121 error_msg_->SetText(base::UTF8ToUTF16(message)); |
122 if (!error_msg_->parent()) { | 122 if (!error_msg_->parent()) { |
123 AddChildView(error_msg_); | 123 AddChildView(error_msg_); |
124 InvalidateLayout(); | 124 InvalidateLayout(); |
125 parent_container_->Layout(); | 125 GetWidget()->GetRootView()->Layout(); |
126 ScrollRectToVisible(error_msg_->bounds()); | 126 ScrollRectToVisible(error_msg_->bounds()); |
127 } | 127 } |
128 connect_->SetEnabled(true); | 128 connect_->SetEnabled(true); |
129 } | 129 } |
130 | 130 |
131 void OnSetProfileSucceed(const base::string16& password) { | 131 void OnSetProfileSucceed(const base::string16& password) { |
132 base::DictionaryValue properties; | 132 base::DictionaryValue properties; |
133 properties.SetStringWithoutPathExpansion(shill::kPassphraseProperty, | 133 properties.SetStringWithoutPathExpansion(shill::kPassphraseProperty, |
134 textfield_->text()); | 134 textfield_->text()); |
135 NetworkHandler::Get()->network_configuration_handler()->SetProperties( | 135 NetworkHandler::Get()->network_configuration_handler()->SetProperties( |
136 network_.service_path, | 136 network_.service_path, |
137 properties, | 137 properties, |
138 base::Bind(&PasswordView::OnSetPropertiesSucceed, | 138 base::Bind(&PasswordView::OnSetPropertiesSucceed, |
139 weak_ptr_.GetWeakPtr()), | 139 weak_ptr_.GetWeakPtr()), |
140 base::Bind(&PasswordView::OnKnownError, weak_ptr_.GetWeakPtr())); | 140 base::Bind(&PasswordView::OnKnownError, weak_ptr_.GetWeakPtr())); |
141 } | 141 } |
142 | 142 |
143 void OnSetPropertiesSucceed() { | 143 void OnSetPropertiesSucceed() { |
144 const bool check_error_state = false; | 144 const bool check_error_state = false; |
145 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork( | 145 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork( |
146 network_.service_path, | 146 network_.service_path, |
147 base::Bind(&PasswordView::OnConnectionSucceed, weak_ptr_.GetWeakPtr()), | 147 base::Bind(&PasswordView::OnConnectionSucceed, weak_ptr_.GetWeakPtr()), |
148 base::Bind(&PasswordView::OnKnownError, weak_ptr_.GetWeakPtr()), | 148 base::Bind(&PasswordView::OnKnownError, weak_ptr_.GetWeakPtr()), |
149 check_error_state); | 149 check_error_state); |
150 } | 150 } |
151 | 151 |
152 void OnConnectionSucceed() { Close(true); } | 152 void OnConnectionSucceed() { CloseDialog(true); } |
153 | 153 |
154 // views::View: | 154 // views::View: |
155 virtual void ViewHierarchyChanged( | 155 virtual void ViewHierarchyChanged( |
156 const views::View::ViewHierarchyChangedDetails& details) override { | 156 const views::View::ViewHierarchyChangedDetails& details) override { |
157 if (details.is_add && details.child == this) | 157 if (details.is_add && details.child == this) |
158 textfield_->RequestFocus(); | 158 textfield_->RequestFocus(); |
159 } | 159 } |
160 | 160 |
161 // views::ButtonListener: | 161 // views::ButtonListener: |
162 virtual void ButtonPressed(views::Button* sender, | 162 virtual void ButtonPressed(views::Button* sender, |
163 const ui::Event& event) override { | 163 const ui::Event& event) override { |
164 if (sender == connect_) { | 164 if (sender == connect_) { |
165 if (error_msg_) { | 165 if (error_msg_) { |
166 RemoveChildView(error_msg_); | 166 RemoveChildView(error_msg_); |
167 delete error_msg_; | 167 delete error_msg_; |
168 error_msg_ = NULL; | 168 error_msg_ = NULL; |
169 } | 169 } |
170 connect_->SetEnabled(false); | 170 connect_->SetEnabled(false); |
171 NetworkHandler::Get()->network_configuration_handler()->SetNetworkProfile( | 171 NetworkHandler::Get()->network_configuration_handler()->SetNetworkProfile( |
172 network_.service_path, | 172 network_.service_path, |
173 NetworkProfileHandler::GetSharedProfilePath(), | 173 NetworkProfileHandler::GetSharedProfilePath(), |
174 base::Bind(&PasswordView::OnSetProfileSucceed, | 174 base::Bind(&PasswordView::OnSetProfileSucceed, |
175 weak_ptr_.GetWeakPtr(), | 175 weak_ptr_.GetWeakPtr(), |
176 textfield_->text()), | 176 textfield_->text()), |
177 base::Bind(&PasswordView::OnKnownError, weak_ptr_.GetWeakPtr())); | 177 base::Bind(&PasswordView::OnKnownError, weak_ptr_.GetWeakPtr())); |
178 } else if (sender == cancel_) { | 178 } else if (sender == cancel_) { |
179 Close(false); | 179 CloseDialog(false); |
180 } else { | 180 } else { |
181 NOTREACHED(); | 181 NOTREACHED(); |
182 } | 182 } |
183 } | 183 } |
184 | 184 |
185 ui::NetworkInfo network_; | 185 ui::NetworkInfo network_; |
186 base::Callback<void(bool)> callback_; | 186 base::Callback<void(bool)> callback_; |
187 views::View* parent_container_; | |
188 | 187 |
189 views::BlueButton* connect_; | 188 views::BlueButton* connect_; |
190 views::LabelButton* cancel_; | 189 views::LabelButton* cancel_; |
191 views::Textfield* textfield_; | 190 views::Textfield* textfield_; |
192 views::Label* error_msg_; | 191 views::Label* error_msg_; |
193 base::WeakPtrFactory<PasswordView> weak_ptr_; | 192 base::WeakPtrFactory<PasswordView> weak_ptr_; |
194 | 193 |
195 DISALLOW_COPY_AND_ASSIGN(PasswordView); | 194 DISALLOW_COPY_AND_ASSIGN(PasswordView); |
196 }; | 195 }; |
197 | 196 |
198 // A View that represents a single row in the network list. This row also | 197 // A View that represents a single row in the network list. This row also |
199 // contains the View for taking password for password-protected networks. | 198 // contains the View for taking password for password-protected networks. |
200 class NetworkRow : public views::View { | 199 class NetworkRow : public views::View { |
201 public: | 200 public: |
202 NetworkRow(const ui::NetworkInfo& network, views::View* container) | 201 NetworkRow(const ui::NetworkInfo& network) |
203 : network_(network), container_(container), weak_ptr_(this) { | 202 : network_(network), weak_ptr_(this) { |
204 SetBorder(views::Border::CreateEmptyBorder(10, 5, 10, 5)); | 203 SetBorder(views::Border::CreateEmptyBorder(10, 5, 10, 5)); |
205 SetLayoutManager( | 204 SetLayoutManager( |
206 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 10)); | 205 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 10)); |
207 Update(network); | 206 Update(network); |
208 } | 207 } |
209 | 208 |
210 virtual ~NetworkRow() {} | 209 virtual ~NetworkRow() {} |
211 | 210 |
212 void Update(const ui::NetworkInfo& network) { | 211 void Update(const ui::NetworkInfo& network) { |
213 network_ = network; | 212 network_ = network; |
214 views::ImageView* icon = new views::ImageView(); | 213 views::ImageView* icon = new views::ImageView(); |
215 icon->SetImage(network.image); | 214 icon->SetImage(network.image); |
216 icon->SetBounds(0, 0, network.image.width(), network.image.height()); | 215 icon->SetBounds(0, 0, network.image.width(), network.image.height()); |
217 | 216 |
218 views::Label* label = new views::Label(network.label); | 217 views::Label* label = new views::Label(network.label); |
219 if (network.highlight) | 218 if (network.highlight) |
220 label->SetFontList(label->font_list().Derive(0, gfx::Font::BOLD)); | 219 label->SetFontList(label->font_list().Derive(0, gfx::Font::BOLD)); |
221 AddChildView(icon); | 220 AddChildView(icon); |
222 AddChildView(label); | 221 AddChildView(label); |
223 if (password_view_) | 222 if (password_view_) |
224 AddChildView(password_view_.get()); | 223 AddChildView(password_view_.get()); |
225 } | 224 } |
226 | 225 |
227 bool has_password_view() const { return password_view_; } | 226 bool has_password_view() const { return password_view_; } |
228 | 227 |
229 private: | 228 private: |
230 void OnPasswordComplete(bool successful) { | 229 void OnPasswordComplete(bool successful) { |
231 password_view_.reset(); | 230 password_view_.reset(); |
232 InvalidateLayout(); | 231 InvalidateLayout(); |
233 container_->Layout(); | 232 GetWidget()->GetRootView()->Layout(); |
234 ScrollRectToVisible(GetContentsBounds()); | 233 ScrollRectToVisible(GetContentsBounds()); |
235 } | 234 } |
236 | 235 |
237 void ShowPasswordView(const std::string& service_path) { | 236 void ShowPasswordView(const std::string& service_path) { |
238 const NetworkState* network = | 237 const NetworkState* network = |
239 NetworkHandler::Get()->network_state_handler()->GetNetworkState( | 238 NetworkHandler::Get()->network_state_handler()->GetNetworkState( |
240 service_path); | 239 service_path); |
241 if (!network) | 240 if (!network) |
242 return; | 241 return; |
243 | 242 |
244 // If this is not a wifi network that needs a password, then ignore. | 243 // If this is not a wifi network that needs a password, then ignore. |
245 if (network->type() != shill::kTypeWifi || | 244 if (network->type() != shill::kTypeWifi || |
246 network->security() == shill::kSecurityNone) { | 245 network->security() == shill::kSecurityNone) { |
247 return; | 246 return; |
248 } | 247 } |
249 | 248 |
250 password_view_.reset(new PasswordView( | 249 password_view_.reset(new PasswordView( |
251 network_, | 250 network_, |
252 base::Bind(&NetworkRow::OnPasswordComplete, weak_ptr_.GetWeakPtr()), | 251 base::Bind(&NetworkRow::OnPasswordComplete, weak_ptr_.GetWeakPtr()))); |
253 container_)); | |
254 password_view_->set_owned_by_client(); | 252 password_view_->set_owned_by_client(); |
255 AddChildView(password_view_.get()); | 253 AddChildView(password_view_.get()); |
256 PreferredSizeChanged(); | 254 PreferredSizeChanged(); |
257 container_->Layout(); | 255 GetWidget()->GetRootView()->Layout(); |
258 ScrollRectToVisible(password_view_->bounds()); | 256 ScrollRectToVisible(password_view_->bounds()); |
259 } | 257 } |
260 | 258 |
261 void OnNetworkConnectionError(const std::string& service_path, | 259 void OnNetworkConnectionError(const std::string& service_path, |
262 const std::string& error_name, | 260 const std::string& error_name, |
263 scoped_ptr<base::DictionaryValue> error_data) { | 261 scoped_ptr<base::DictionaryValue> error_data) { |
264 if (error_name == NetworkConnectionHandler::kErrorConnectCanceled) | 262 if (error_name == NetworkConnectionHandler::kErrorConnectCanceled) |
265 return; | 263 return; |
266 if (error_name == shill::kErrorBadPassphrase || | 264 if (error_name == shill::kErrorBadPassphrase || |
267 error_name == NetworkConnectionHandler::kErrorPassphraseRequired || | 265 error_name == NetworkConnectionHandler::kErrorPassphraseRequired || |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 } | 301 } |
304 | 302 |
305 virtual void OnGestureEvent(ui::GestureEvent* gesture) override { | 303 virtual void OnGestureEvent(ui::GestureEvent* gesture) override { |
306 if (gesture->type() != ui::ET_GESTURE_TAP) | 304 if (gesture->type() != ui::ET_GESTURE_TAP) |
307 return; | 305 return; |
308 ActivateNetwork(); | 306 ActivateNetwork(); |
309 gesture->SetHandled(); | 307 gesture->SetHandled(); |
310 } | 308 } |
311 | 309 |
312 ui::NetworkInfo network_; | 310 ui::NetworkInfo network_; |
313 views::View* container_; | |
314 scoped_ptr<views::View> password_view_; | 311 scoped_ptr<views::View> password_view_; |
315 base::WeakPtrFactory<NetworkRow> weak_ptr_; | 312 base::WeakPtrFactory<NetworkRow> weak_ptr_; |
316 | 313 |
317 DISALLOW_COPY_AND_ASSIGN(NetworkRow); | 314 DISALLOW_COPY_AND_ASSIGN(NetworkRow); |
318 }; | 315 }; |
319 | 316 |
320 class NetworkSelector : public ui::NetworkListDelegate, | 317 class NetworkSelector : public ui::NetworkListDelegate, |
321 public chromeos::NetworkStateHandlerObserver, | 318 public chromeos::NetworkStateHandlerObserver, |
322 public ui::EventHandler { | 319 public views::DialogDelegate { |
323 public: | 320 public: |
324 explicit NetworkSelector(aura::Window* container) | 321 NetworkSelector() |
325 : background_view_(NULL), | 322 : scroll_content_(NULL), scroller_(NULL), network_list_(this) { |
326 scroll_content_(NULL), | |
327 scroller_(NULL), | |
328 network_list_(this) { | |
329 CreateWidget(container); | |
330 CreateNetworkList(); | 323 CreateNetworkList(); |
| 324 CreateWidget(); |
331 | 325 |
332 NetworkHandler::Get()->network_state_handler()->RequestScan(); | 326 NetworkHandler::Get()->network_state_handler()->RequestScan(); |
333 NetworkHandler::Get()->network_state_handler()->AddObserver(this, | 327 NetworkHandler::Get()->network_state_handler()->AddObserver(this, |
334 FROM_HERE); | 328 FROM_HERE); |
335 } | 329 } |
336 | 330 |
337 virtual ~NetworkSelector() { | 331 virtual ~NetworkSelector() { |
338 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, | 332 NetworkHandler::Get()->network_state_handler()->RemoveObserver(this, |
339 FROM_HERE); | 333 FROM_HERE); |
340 } | 334 } |
341 | 335 |
342 private: | 336 private: |
343 void CreateWidget(aura::Window* container) { | 337 void CreateWidget() { |
344 views::Widget::InitParams params; | 338 // Same as CreateDialogWidgetWithBounds() with an empty |bounds|. |
345 params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS; | 339 views::Widget* widget = views::DialogDelegate::CreateDialogWidget( |
346 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 340 this, athena::ScreenManager::Get()->GetContext(), NULL); |
347 params.activatable = views::Widget::InitParams::ACTIVATABLE_DEFAULT; | 341 widget->Show(); |
348 params.accept_events = true; | 342 widget->CenterWindow(gfx::Size(400, 400)); |
349 params.bounds = gfx::Rect(container->bounds().size()); | |
350 params.parent = container; | |
351 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | |
352 widget_.reset(new views::Widget()); | |
353 widget_->Init(params); | |
354 widget_->Show(); | |
355 | |
356 background_view_ = new views::View; | |
357 background_view_->set_background( | |
358 views::Background::CreateSolidBackground(kBackgroundColor)); | |
359 background_view_->SetBorder( | |
360 views::Border::CreateEmptyBorder(100, 300, 300, 300)); | |
361 background_view_->SetLayoutManager(new views::FillLayout()); | |
362 background_view_->set_target_handler(this); | |
363 | |
364 widget_->SetContentsView(background_view_); | |
365 } | 343 } |
366 | 344 |
367 void CreateNetworkList() { | 345 void CreateNetworkList() { |
368 const int kListHeight = 500; | 346 const int kListHeight = 400; |
369 scroller_ = new views::ScrollView(); | 347 scroller_ = new views::ScrollView(); |
370 scroller_->set_background( | 348 scroller_->set_background( |
371 views::Background::CreateSolidBackground(SK_ColorWHITE)); | 349 views::Background::CreateSolidBackground(SK_ColorWHITE)); |
372 scroller_->SetBounds(0, 0, 400, kListHeight); | |
373 | 350 |
374 scroll_content_ = new views::View; | 351 scroll_content_ = new views::View; |
375 scroll_content_->SetLayoutManager( | 352 scroll_content_->SetLayoutManager( |
376 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 353 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
377 scroller_->SetContents(scroll_content_); | 354 scroller_->SetContents(scroll_content_); |
378 | 355 |
379 scroller_->ClipHeightTo(kListHeight, kListHeight); | 356 scroller_->ClipHeightTo(kListHeight, kListHeight); |
380 scroller_->SetVerticalScrollBar(new views::OverlayScrollBar(false)); | 357 scroller_->SetVerticalScrollBar(new views::OverlayScrollBar(false)); |
381 background_view_->AddChildView(scroller_); | |
382 | |
383 background_view_->Layout(); | |
384 | 358 |
385 network_list_.set_content_view(scroll_content_); | 359 network_list_.set_content_view(scroll_content_); |
386 } | 360 } |
387 | 361 |
388 void UpdateNetworkList() { network_list_.UpdateNetworkList(); } | 362 void UpdateNetworkList() { network_list_.UpdateNetworkList(); } |
389 | 363 |
390 void Close() { delete this; } | |
391 | |
392 // ui::NetworkListDelegate: | 364 // ui::NetworkListDelegate: |
393 virtual views::View* CreateViewForNetwork( | 365 virtual views::View* CreateViewForNetwork( |
394 const ui::NetworkInfo& info) override { | 366 const ui::NetworkInfo& info) override { |
395 return new NetworkRow(info, background_view_); | 367 return new NetworkRow(info); |
396 } | 368 } |
397 | 369 |
398 virtual bool IsViewHovered(views::View* view) override { | 370 virtual bool IsViewHovered(views::View* view) override { |
399 return static_cast<NetworkRow*>(view)->has_password_view(); | 371 return static_cast<NetworkRow*>(view)->has_password_view(); |
400 } | 372 } |
401 | 373 |
402 virtual chromeos::NetworkTypePattern GetNetworkTypePattern() const override { | 374 virtual chromeos::NetworkTypePattern GetNetworkTypePattern() const override { |
403 return chromeos::NetworkTypePattern::NonVirtual(); | 375 return chromeos::NetworkTypePattern::NonVirtual(); |
404 } | 376 } |
405 | 377 |
(...skipping 16 matching lines...) Expand all Loading... |
422 | 394 |
423 virtual void DefaultNetworkChanged( | 395 virtual void DefaultNetworkChanged( |
424 const chromeos::NetworkState* network) override {} | 396 const chromeos::NetworkState* network) override {} |
425 | 397 |
426 virtual void NetworkConnectionStateChanged( | 398 virtual void NetworkConnectionStateChanged( |
427 const chromeos::NetworkState* network) override {} | 399 const chromeos::NetworkState* network) override {} |
428 | 400 |
429 virtual void NetworkPropertiesUpdated( | 401 virtual void NetworkPropertiesUpdated( |
430 const chromeos::NetworkState* network) override {} | 402 const chromeos::NetworkState* network) override {} |
431 | 403 |
432 // ui::EventHandler: | 404 // views::DialogDelegate: |
433 virtual void OnMouseEvent(ui::MouseEvent* mouse) override { | 405 virtual ui::ModalType GetModalType() const override { |
434 CHECK_EQ(background_view_, mouse->target()); | 406 return ui::MODAL_TYPE_SYSTEM; |
435 if (mouse->type() == ui::ET_MOUSE_PRESSED && !mouse->handled()) { | |
436 Close(); | |
437 mouse->SetHandled(); | |
438 } | |
439 } | 407 } |
| 408 virtual void DeleteDelegate() override { delete this; } |
| 409 virtual views::Widget* GetWidget() override { return scroller_->GetWidget(); } |
| 410 virtual const views::Widget* GetWidget() const override { |
| 411 return scroller_->GetWidget(); |
| 412 } |
| 413 virtual views::View* GetContentsView() override { return scroller_; } |
| 414 virtual int GetDialogButtons() const override { return ui::DIALOG_BUTTON_OK; } |
| 415 virtual bool Close() override { return true; } |
440 | 416 |
441 virtual void OnGestureEvent(ui::GestureEvent* gesture) override { | |
442 CHECK_EQ(background_view_, gesture->target()); | |
443 if (gesture->type() == ui::ET_GESTURE_TAP && !gesture->handled()) { | |
444 Close(); | |
445 gesture->SetHandled(); | |
446 } | |
447 } | |
448 | |
449 scoped_ptr<views::Widget> widget_; | |
450 views::View* background_view_; | |
451 views::View* scroll_content_; | 417 views::View* scroll_content_; |
452 views::ScrollView* scroller_; | 418 views::ScrollView* scroller_; |
453 | 419 |
454 views::View* connect_; | 420 views::View* connect_; |
455 | 421 |
456 ui::NetworkListView network_list_; | 422 ui::NetworkListView network_list_; |
457 | 423 |
458 DISALLOW_COPY_AND_ASSIGN(NetworkSelector); | 424 DISALLOW_COPY_AND_ASSIGN(NetworkSelector); |
459 }; | 425 }; |
460 | 426 |
461 } // namespace | 427 } // namespace |
462 | 428 |
463 namespace athena { | 429 namespace athena { |
464 | 430 |
465 void CreateNetworkSelector(aura::Window* container) { | 431 void CreateNetworkSelector() { |
466 new NetworkSelector(container); | 432 new NetworkSelector(); |
467 } | 433 } |
468 | 434 |
469 } // namespace athena | 435 } // namespace athena |
OLD | NEW |