OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/chromeos/options/internet_page_view.h" | |
6 | |
7 #include <string> | |
8 | |
9 #include "base/string_util.h" | |
10 #include "base/utf_string_conversions.h" | |
11 #include "chrome/browser/chromeos/cros/cros_library.h" | |
12 #include "chrome/browser/chromeos/options/network_config_view.h" | |
13 #include "chrome/browser/chromeos/options/options_window_view.h" | |
14 #include "chrome/browser/chromeos/status/network_menu.h" | |
15 #include "chrome/browser/ui/views/window.h" | |
16 #include "grit/generated_resources.h" | |
17 #include "grit/theme_resources.h" | |
18 #include "ui/base/l10n/l10n_util.h" | |
19 #include "ui/base/resource/resource_bundle.h" | |
20 #include "views/controls/button/native_button.h" | |
21 #include "views/controls/combobox/combobox.h" | |
22 #include "views/controls/image_view.h" | |
23 #include "views/controls/scroll_view.h" | |
24 #include "views/layout/layout_constants.h" | |
25 #include "views/widget/widget.h" | |
26 #include "views/window/window.h" | |
27 | |
28 namespace chromeos { | |
29 | |
30 //////////////////////////////////////////////////////////////////////////////// | |
31 // NetworkSection | |
32 | |
33 class NetworkSection : public SettingsPageSection, | |
34 public views::ButtonListener { | |
35 public: | |
36 NetworkSection(InternetPageContentView* parent, Profile* profile, | |
37 int title_msg_id); | |
38 virtual ~NetworkSection() {} | |
39 | |
40 // Overriden from views::Button::ButtonListener: | |
41 virtual void ButtonPressed(views::Button* sender, const views::Event& event); | |
42 | |
43 void RefreshContents(); | |
44 | |
45 protected: | |
46 enum ButtonFlags { | |
47 OPTIONS_BUTTON = 1 << 0, | |
48 CONNECT_BUTTON = 1 << 1, | |
49 DISCONNECT_BUTTON = 1 << 2, | |
50 FORGET_BUTTON = 1 << 3, | |
51 }; | |
52 | |
53 // SettingsPageSection overrides: | |
54 virtual void InitContents(GridLayout* layout); | |
55 | |
56 // Subclasses will initialize themselves in this method. | |
57 virtual void InitSection() = 0; | |
58 | |
59 // This adds a row for a network. | |
60 // |id| is passed back in the ButtonClicked method. | |
61 // |icon|, |name|, |bold_name|, and |status| are displayed in the row. | |
62 // |button_flags| is an OR of ButtonFlags that should be displayed. | |
63 void AddNetwork(int id, const SkBitmap& icon, const std::wstring& name, | |
64 bool bold_name, const std::wstring& status, int button_flags, | |
65 int connection_type); | |
66 | |
67 // Creates a modal popup with |view|. | |
68 void CreateModalPopup(views::WindowDelegate* view); | |
69 | |
70 // This method is called when the user click on the |button| for |id|. | |
71 virtual void ButtonClicked(int button, int connection_type, int id) = 0; | |
72 | |
73 private: | |
74 // This constant determines the button tag offset for the different buttons. | |
75 // The ButtonFlag is multiplied by this offset to determine the button tag. | |
76 // For example, for disconnect buttons (DISCONNECT_BUTTON = 4), the button tag | |
77 // will be offset by 4000. | |
78 static const int kButtonIdOffset = 1000; | |
79 // This constant determines the button tag offset for the connection types. | |
80 // The ConnectionType is multiplied by this to determine the button tag. | |
81 // For example, for wifi buttons (TYPE_WIFI = 2), the button tag | |
82 // will be offset by 200. | |
83 static const int kConnectionTypeOffset = 100; | |
84 | |
85 InternetPageContentView* parent_; | |
86 | |
87 int quad_column_view_set_id_; | |
88 | |
89 GridLayout* layout_; | |
90 | |
91 DISALLOW_COPY_AND_ASSIGN(NetworkSection); | |
92 }; | |
93 | |
94 NetworkSection::NetworkSection(InternetPageContentView* parent, | |
95 Profile* profile, | |
96 int title_msg_id) | |
97 : SettingsPageSection(profile, title_msg_id), | |
98 parent_(parent), | |
99 quad_column_view_set_id_(1) { | |
100 } | |
101 | |
102 void NetworkSection::ButtonPressed(views::Button* sender, | |
103 const views::Event& event) { | |
104 int id = sender->tag(); | |
105 // Determine the button from the id (div by kButtonIdOffset). | |
106 int button = id / kButtonIdOffset; | |
107 id %= kButtonIdOffset; | |
108 // Determine the connection type from the id (div by kConnectionTypeOffset). | |
109 int connection_type = id / kConnectionTypeOffset; | |
110 id %= kConnectionTypeOffset; | |
111 | |
112 ButtonClicked(button, connection_type, id); | |
113 } | |
114 | |
115 void NetworkSection::RefreshContents() { | |
116 RemoveAllChildViews(true); | |
117 InitControlLayout(); | |
118 } | |
119 | |
120 void NetworkSection::InitContents(GridLayout* layout) { | |
121 layout_ = layout; | |
122 | |
123 ColumnSet* column_set = layout_->AddColumnSet(quad_column_view_set_id_); | |
124 // icon | |
125 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | |
126 GridLayout::USE_PREF, 0, 0); | |
127 // network name | |
128 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | |
129 GridLayout::USE_PREF, 0, 0); | |
130 // fill padding | |
131 column_set->AddPaddingColumn(10, 0); | |
132 // first button | |
133 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | |
134 GridLayout::USE_PREF, 0, 0); | |
135 // padding | |
136 column_set->AddPaddingColumn(0, 10); | |
137 // second button | |
138 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | |
139 GridLayout::USE_PREF, 0, 0); | |
140 | |
141 InitSection(); | |
142 } | |
143 | |
144 void NetworkSection::AddNetwork(int id, const SkBitmap& icon, | |
145 const std::wstring& name, bool bold_name, | |
146 const std::wstring& status, int button_flags, | |
147 int connection_type) { | |
148 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
149 | |
150 // Offset id by connection type. | |
151 id += kConnectionTypeOffset * connection_type; | |
152 | |
153 layout_->StartRow(0, quad_column_view_set_id_); | |
154 views::ImageView* icon_view = new views::ImageView(); | |
155 icon_view->SetImage(icon); | |
156 layout_->AddView(icon_view, 1, 2); | |
157 | |
158 views::Label* name_view = new views::Label(name); | |
159 if (bold_name) | |
160 name_view->SetFont(rb.GetFont(ResourceBundle::BoldFont)); | |
161 name_view->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
162 layout_->AddView(name_view); | |
163 | |
164 int num_buttons = 0; | |
165 if (button_flags & OPTIONS_BUTTON) | |
166 num_buttons++; | |
167 if (button_flags & CONNECT_BUTTON) | |
168 num_buttons++; | |
169 if (button_flags & DISCONNECT_BUTTON) | |
170 num_buttons++; | |
171 if (button_flags & FORGET_BUTTON) | |
172 num_buttons++; | |
173 | |
174 if (num_buttons > 0) { | |
175 // We only support 2 buttons. | |
176 DCHECK_LE(num_buttons, 2); | |
177 | |
178 if (num_buttons == 1) | |
179 layout_->SkipColumns(1); | |
180 | |
181 if (button_flags & FORGET_BUTTON) { | |
182 views::NativeButton* button = new views::NativeButton(this, | |
183 UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_FORGET))); | |
184 button->set_tag(id + kButtonIdOffset * FORGET_BUTTON); | |
185 layout_->AddView(button, 1, 2); | |
186 } | |
187 | |
188 if (button_flags & DISCONNECT_BUTTON) { | |
189 views::NativeButton* button = new views::NativeButton(this, UTF16ToWide( | |
190 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_DISCONNECT))); | |
191 button->set_tag(id + kButtonIdOffset * DISCONNECT_BUTTON); | |
192 layout_->AddView(button, 1, 2); | |
193 } | |
194 | |
195 if (button_flags & CONNECT_BUTTON) { | |
196 views::NativeButton* button = new views::NativeButton(this, | |
197 UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_CONNECT))); | |
198 button->set_tag(id + kButtonIdOffset * CONNECT_BUTTON); | |
199 layout_->AddView(button, 1, 2); | |
200 } | |
201 | |
202 if (button_flags & OPTIONS_BUTTON) { | |
203 views::NativeButton* button = new views::NativeButton(this, | |
204 UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_OPTIONS))); | |
205 button->set_tag(id + kButtonIdOffset * OPTIONS_BUTTON); | |
206 layout_->AddView(button, 1, 2); | |
207 } | |
208 } | |
209 | |
210 layout_->StartRow(0, quad_column_view_set_id_); | |
211 layout_->SkipColumns(1); | |
212 views::Label* status_label = new views::Label(status); | |
213 status_label->SetFont(rb.GetFont(ResourceBundle::SmallFont)); | |
214 status_label->SetColor(SK_ColorLTGRAY); | |
215 status_label->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | |
216 layout_->AddView(status_label); | |
217 layout_->AddPaddingRow(0, kRelatedControlVerticalSpacing); | |
218 } | |
219 | |
220 void NetworkSection::CreateModalPopup(views::WindowDelegate* view) { | |
221 views::Window* window = browser::CreateViewsWindow( | |
222 GetOptionsViewParent(), gfx::Rect(), view); | |
223 window->SetIsAlwaysOnTop(true); | |
224 window->Show(); | |
225 } | |
226 | |
227 //////////////////////////////////////////////////////////////////////////////// | |
228 // WiredSection | |
229 | |
230 class WiredSection : public NetworkSection { | |
231 public: | |
232 WiredSection(InternetPageContentView* parent, Profile* profile); | |
233 virtual ~WiredSection() {} | |
234 | |
235 protected: | |
236 // NetworkSection overrides: | |
237 virtual void InitSection(); | |
238 virtual void ButtonClicked(int button, int connection_type, int id); | |
239 | |
240 DISALLOW_COPY_AND_ASSIGN(WiredSection); | |
241 }; | |
242 | |
243 WiredSection::WiredSection(InternetPageContentView* parent, Profile* profile) | |
244 : NetworkSection(parent, profile, | |
245 IDS_OPTIONS_SETTINGS_SECTION_TITLE_WIRED_NETWORK) { | |
246 } | |
247 | |
248 void WiredSection::InitSection() { | |
249 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | |
250 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
251 | |
252 SkBitmap icon = *rb.GetBitmapNamed(IDR_STATUSBAR_WIRED_BLACK); | |
253 if (!cros->ethernet_connecting() && !cros->ethernet_connected()) { | |
254 icon = NetworkMenu::IconForDisplay(icon, | |
255 *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_DISCONNECTED)); | |
256 } | |
257 | |
258 std::wstring name = UTF16ToWide( | |
259 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET)); | |
260 | |
261 int s = IDS_STATUSBAR_NETWORK_DEVICE_DISABLED; | |
262 if (cros->ethernet_connecting()) | |
263 s = IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING; | |
264 else if (cros->ethernet_connected()) | |
265 s = IDS_STATUSBAR_NETWORK_DEVICE_CONNECTED; | |
266 else if (cros->ethernet_enabled()) | |
267 s = IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED; | |
268 std::wstring status = UTF16ToWide(l10n_util::GetStringUTF16(s)); | |
269 | |
270 int flags = cros->ethernet_connected() ? OPTIONS_BUTTON : 0; | |
271 bool bold = cros->ethernet_connected() ? true : false; | |
272 AddNetwork(0, icon, name, bold, status, flags, TYPE_ETHERNET); | |
273 } | |
274 | |
275 void WiredSection::ButtonClicked(int button, int connection_type, int id) { | |
276 // CreateModalPopup(new NetworkConfigView( | |
277 // CrosLibrary::Get()->GetNetworkLibrary()->ethernet_network())); | |
278 } | |
279 | |
280 //////////////////////////////////////////////////////////////////////////////// | |
281 // WirelessSection | |
282 | |
283 class WirelessSection : public NetworkSection { | |
284 public: | |
285 WirelessSection(InternetPageContentView* parent, Profile* profile); | |
286 virtual ~WirelessSection() {} | |
287 | |
288 protected: | |
289 // NetworkSection overrides: | |
290 virtual void InitSection(); | |
291 virtual void ButtonClicked(int button, int connection_type, int id); | |
292 | |
293 private: | |
294 // This calls NetworkSection::AddNetwork . | |
295 // For |connecting| or |connected| networks, the name is bold. | |
296 // The status is "Connecting" if |connecting|, "Connected" if |connected|, | |
297 // or "Disconnected". | |
298 // For connected networks, we show the disconnect and options buttons. | |
299 // For !connected and !connecting networks, we show the connect button. | |
300 void AddWirelessNetwork(int id, const SkBitmap& icon, | |
301 const std::wstring& name, bool connecting, | |
302 bool connected, int connection_type); | |
303 | |
304 WifiNetworkVector wifi_networks_; | |
305 CellularNetworkVector cellular_networks_; | |
306 | |
307 DISALLOW_COPY_AND_ASSIGN(WirelessSection); | |
308 }; | |
309 | |
310 WirelessSection::WirelessSection(InternetPageContentView* parent, | |
311 Profile* profile) | |
312 : NetworkSection(parent, profile, | |
313 IDS_OPTIONS_SETTINGS_SECTION_TITLE_WIRELESS_NETWORK) { | |
314 } | |
315 | |
316 void WirelessSection::InitSection() { | |
317 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | |
318 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
319 | |
320 // Wifi | |
321 wifi_networks_ = cros->wifi_networks(); | |
322 for (size_t i = 0; i < wifi_networks_.size(); ++i) { | |
323 std::wstring name = ASCIIToWide(wifi_networks_[i]->name()); | |
324 | |
325 SkBitmap icon = NetworkMenu::IconForNetworkStrength( | |
326 wifi_networks_[i], true); | |
327 if (wifi_networks_[i]->encrypted()) { | |
328 icon = NetworkMenu::IconForDisplay(icon, | |
329 *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE)); | |
330 } | |
331 | |
332 bool connecting = wifi_networks_[i]->connecting(); | |
333 bool connected = wifi_networks_[i]->connected(); | |
334 AddWirelessNetwork(i, icon, name, connecting, connected, TYPE_WIFI); | |
335 } | |
336 | |
337 // Cellular | |
338 cellular_networks_ = cros->cellular_networks(); | |
339 for (size_t i = 0; i < cellular_networks_.size(); ++i) { | |
340 std::wstring name = ASCIIToWide(cellular_networks_[i]->name()); | |
341 | |
342 SkBitmap icon = NetworkMenu::IconForNetworkStrength( | |
343 cellular_networks_[i], true); | |
344 SkBitmap badge = | |
345 NetworkMenu::BadgeForNetworkTechnology(cellular_networks_[i]); | |
346 icon = NetworkMenu::IconForDisplay(icon, badge); | |
347 | |
348 bool connecting = cellular_networks_[i]->connecting(); | |
349 bool connected = cellular_networks_[i]->connected(); | |
350 AddWirelessNetwork(i, icon, name, connecting, connected, TYPE_CELLULAR); | |
351 } | |
352 } | |
353 | |
354 void WirelessSection::ButtonClicked(int button, int connection_type, int id) { | |
355 if (connection_type == TYPE_CELLULAR) { | |
356 if (static_cast<int>(cellular_networks_.size()) > id) { | |
357 if (button == CONNECT_BUTTON) { | |
358 // Connect to cellular network. | |
359 CrosLibrary::Get()->GetNetworkLibrary()->ConnectToCellularNetwork( | |
360 cellular_networks_[id]); | |
361 } else if (button == DISCONNECT_BUTTON) { | |
362 CrosLibrary::Get()->GetNetworkLibrary()->DisconnectFromWirelessNetwork( | |
363 cellular_networks_[id]); | |
364 } else { | |
365 // CreateModalPopup(new NetworkConfigView(cellular_networks_[id])); | |
366 } | |
367 } | |
368 } else if (connection_type == TYPE_WIFI) { | |
369 if (static_cast<int>(wifi_networks_.size()) > id) { | |
370 if (button == CONNECT_BUTTON) { | |
371 // Connect to wifi here. Open password page if appropriate. | |
372 if (wifi_networks_[id]->encrypted()) { | |
373 // NetworkConfigView* view = | |
374 // new NetworkConfigView(wifi_networks_[id], true); | |
375 // CreateModalPopup(view); | |
376 // view->SetLoginTextfieldFocus(); | |
377 } else { | |
378 CrosLibrary::Get()->GetNetworkLibrary()->ConnectToWifiNetwork( | |
379 wifi_networks_[id], std::string(), std::string(), std::string()); | |
380 } | |
381 } else if (button == DISCONNECT_BUTTON) { | |
382 CrosLibrary::Get()->GetNetworkLibrary()->DisconnectFromWirelessNetwork( | |
383 wifi_networks_[id]); | |
384 } else { | |
385 // CreateModalPopup(new NetworkConfigView(wifi_networks_[id], false)); | |
386 } | |
387 } | |
388 } else { | |
389 NOTREACHED(); | |
390 } | |
391 } | |
392 | |
393 void WirelessSection::AddWirelessNetwork(int id, const SkBitmap& icon, | |
394 const std::wstring& name, bool connecting, bool connected, | |
395 int connection_type) { | |
396 bool bold = connecting || connected; | |
397 | |
398 int s = IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED; | |
399 if (connecting) | |
400 s = IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING; | |
401 else if (connected) | |
402 s = IDS_STATUSBAR_NETWORK_DEVICE_CONNECTED; | |
403 std::wstring status = UTF16ToWide(l10n_util::GetStringUTF16(s)); | |
404 | |
405 int flags = 0; | |
406 if (connected) { | |
407 flags |= DISCONNECT_BUTTON | OPTIONS_BUTTON; | |
408 } else if (!connecting) { | |
409 flags |= CONNECT_BUTTON; | |
410 } | |
411 | |
412 AddNetwork(id, icon, name, bold, status, flags, connection_type); | |
413 } | |
414 | |
415 //////////////////////////////////////////////////////////////////////////////// | |
416 // RememberedSection | |
417 | |
418 class RememberedSection : public NetworkSection { | |
419 public: | |
420 RememberedSection(InternetPageContentView* parent, Profile* profile); | |
421 virtual ~RememberedSection() {} | |
422 | |
423 protected: | |
424 // NetworkSection overrides: | |
425 virtual void InitSection(); | |
426 virtual void ButtonClicked(int button, int connection_type, int id); | |
427 | |
428 private: | |
429 WifiNetworkVector wifi_networks_; | |
430 | |
431 DISALLOW_COPY_AND_ASSIGN(RememberedSection); | |
432 }; | |
433 | |
434 RememberedSection::RememberedSection(InternetPageContentView* parent, | |
435 Profile* profile) | |
436 : NetworkSection(parent, profile, | |
437 IDS_OPTIONS_SETTINGS_SECTION_TITLE_REMEMBERED_NETWORK) { | |
438 } | |
439 | |
440 void RememberedSection::InitSection() { | |
441 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | |
442 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
443 | |
444 // Wifi | |
445 wifi_networks_ = cros->remembered_wifi_networks(); | |
446 for (size_t i = 0; i < wifi_networks_.size(); ++i) { | |
447 std::wstring name = ASCIIToWide(wifi_networks_[i]->name()); | |
448 | |
449 SkBitmap icon = *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_BARS0_BLACK); | |
450 if (wifi_networks_[i]->encrypted()) { | |
451 icon = NetworkMenu::IconForDisplay(icon, | |
452 *rb.GetBitmapNamed(IDR_STATUSBAR_NETWORK_SECURE)); | |
453 } | |
454 | |
455 AddNetwork(i, icon, name, false, std::wstring(), FORGET_BUTTON, TYPE_WIFI); | |
456 } | |
457 } | |
458 | |
459 void RememberedSection::ButtonClicked(int button, int connection_type, int id) { | |
460 if (connection_type == TYPE_WIFI) { | |
461 if (static_cast<int>(wifi_networks_.size()) > id) { | |
462 CrosLibrary::Get()->GetNetworkLibrary()->ForgetWifiNetwork( | |
463 wifi_networks_[id]->service_path()); | |
464 } | |
465 } else { | |
466 NOTREACHED(); | |
467 } | |
468 } | |
469 | |
470 //////////////////////////////////////////////////////////////////////////////// | |
471 // InternetPageContentView | |
472 | |
473 class InternetPageContentView : public SettingsPageView { | |
474 public: | |
475 explicit InternetPageContentView(Profile* profile); | |
476 virtual ~InternetPageContentView() {} | |
477 | |
478 virtual void RefreshContents(); | |
479 | |
480 // views::View overrides. | |
481 virtual int GetLineScrollIncrement(views::ScrollView* scroll_view, | |
482 bool is_horizontal, bool is_positive); | |
483 virtual void Layout(); | |
484 virtual void DidChangeBounds(const gfx::Rect& previous, | |
485 const gfx::Rect& current); | |
486 | |
487 protected: | |
488 // SettingsPageView implementation: | |
489 virtual void InitControlLayout(); | |
490 | |
491 private: | |
492 int line_height_; | |
493 WiredSection* wired_section_; | |
494 WirelessSection* wireless_section_; | |
495 RememberedSection* remembered_section_; | |
496 | |
497 DISALLOW_COPY_AND_ASSIGN(InternetPageContentView); | |
498 }; | |
499 | |
500 //////////////////////////////////////////////////////////////////////////////// | |
501 // InternetPageContentView, SettingsPageView implementation: | |
502 | |
503 InternetPageContentView::InternetPageContentView(Profile* profile) | |
504 : SettingsPageView(profile) { | |
505 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
506 line_height_ = rb.GetFont(ResourceBundle::BaseFont).GetHeight(); | |
507 } | |
508 | |
509 void InternetPageContentView::RefreshContents() { | |
510 wired_section_->RefreshContents(); | |
511 wireless_section_->RefreshContents(); | |
512 remembered_section_->RefreshContents(); | |
513 } | |
514 | |
515 int InternetPageContentView::GetLineScrollIncrement( | |
516 views::ScrollView* scroll_view, | |
517 bool is_horizontal, | |
518 bool is_positive) { | |
519 if (!is_horizontal) | |
520 return line_height_; | |
521 return View::GetPageScrollIncrement(scroll_view, is_horizontal, is_positive); | |
522 } | |
523 | |
524 void InternetPageContentView::Layout() { | |
525 // Set the width to the parent width and the height to the preferred height. | |
526 // We will have a vertical scrollbar if the preferred height is longer | |
527 // than the parent's height. | |
528 SetBounds(0, 0, GetParent()->width(), GetPreferredSize().height()); | |
529 View::Layout(); | |
530 } | |
531 | |
532 void InternetPageContentView::DidChangeBounds(const gfx::Rect& previous, | |
533 const gfx::Rect& current) { | |
534 // Override to do nothing. Calling Layout() interferes with our scrolling. | |
535 } | |
536 | |
537 void InternetPageContentView::InitControlLayout() { | |
538 GridLayout* layout = GridLayout::CreatePanel(this); | |
539 SetLayoutManager(layout); | |
540 | |
541 int single_column_view_set_id = 0; | |
542 ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id); | |
543 column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1, | |
544 GridLayout::USE_PREF, 0, 0); | |
545 | |
546 layout->StartRow(0, single_column_view_set_id); | |
547 wired_section_ = new WiredSection(this, profile()); | |
548 layout->AddView(wired_section_); | |
549 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | |
550 | |
551 layout->StartRow(0, single_column_view_set_id); | |
552 wireless_section_ = new WirelessSection(this, profile()); | |
553 layout->AddView(wireless_section_); | |
554 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | |
555 | |
556 layout->StartRow(0, single_column_view_set_id); | |
557 remembered_section_ = new RememberedSection(this, profile()); | |
558 layout->AddView(remembered_section_); | |
559 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | |
560 } | |
561 | |
562 //////////////////////////////////////////////////////////////////////////////// | |
563 // InternetPageView | |
564 | |
565 InternetPageView::InternetPageView(Profile* profile) | |
566 : SettingsPageView(profile), | |
567 contents_view_(new InternetPageContentView(profile)), | |
568 scroll_view_(new views::ScrollView) { | |
569 NetworkLibrary* cros = CrosLibrary::Get()->GetNetworkLibrary(); | |
570 cros->AddNetworkManagerObserver(this); | |
571 } | |
572 | |
573 InternetPageView::~InternetPageView() { | |
574 CrosLibrary::Get()->GetNetworkLibrary()->RemoveNetworkManagerObserver(this); | |
575 } | |
576 | |
577 void InternetPageView::OnNetworkManagerChanged(NetworkLibrary* obj) { | |
578 // Refresh wired, wireless, and remembered networks. | |
579 // Remember the current scroll region, and try to scroll back afterwards. | |
580 gfx::Rect rect = scroll_view_->GetVisibleRect(); | |
581 contents_view_->RefreshContents(); | |
582 Layout(); | |
583 scroll_view_->ScrollContentsRegionToBeVisible(rect); | |
584 } | |
585 | |
586 void InternetPageView::Layout() { | |
587 contents_view_->Layout(); | |
588 scroll_view_->SetBounds(GetLocalBounds(false)); | |
589 scroll_view_->Layout(); | |
590 } | |
591 | |
592 void InternetPageView::InitControlLayout() { | |
593 AddChildView(scroll_view_); | |
594 scroll_view_->SetContents(contents_view_); | |
595 } | |
596 | |
597 } // namespace chromeos | |
OLD | NEW |