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 "chrome/browser/chromeos/options/network_config_view.h" | 5 #include "chrome/browser/chromeos/options/network_config_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
| 11 #include "chrome/browser/chromeos/login/base_login_display_host.h" |
11 #include "chrome/browser/chromeos/options/vpn_config_view.h" | 12 #include "chrome/browser/chromeos/options/vpn_config_view.h" |
12 #include "chrome/browser/chromeos/options/wifi_config_view.h" | 13 #include "chrome/browser/chromeos/options/wifi_config_view.h" |
| 14 #include "chrome/browser/profiles/profile_manager.h" |
| 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/browser_list.h" |
| 17 #include "chrome/browser/ui/browser_window.h" |
13 #include "grit/chromium_strings.h" | 18 #include "grit/chromium_strings.h" |
14 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
15 #include "grit/locale_settings.h" | 20 #include "grit/locale_settings.h" |
16 #include "grit/theme_resources.h" | 21 #include "grit/theme_resources.h" |
17 #include "ui/base/accessibility/accessible_view_state.h" | 22 #include "ui/base/accessibility/accessible_view_state.h" |
18 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/gfx/image/image.h" | 25 #include "ui/gfx/image/image.h" |
21 #include "ui/gfx/rect.h" | 26 #include "ui/gfx/rect.h" |
22 #include "ui/views/controls/button/text_button.h" | 27 #include "ui/views/controls/button/text_button.h" |
23 #include "ui/views/controls/image_view.h" | 28 #include "ui/views/controls/image_view.h" |
24 #include "ui/views/layout/grid_layout.h" | 29 #include "ui/views/layout/grid_layout.h" |
25 #include "ui/views/layout/layout_constants.h" | 30 #include "ui/views/layout/layout_constants.h" |
26 #include "ui/views/widget/widget.h" | 31 #include "ui/views/widget/widget.h" |
27 | 32 |
| 33 namespace { |
| 34 |
| 35 gfx::NativeWindow GetDialogParent() { |
| 36 if (chromeos::BaseLoginDisplayHost::default_host()) { |
| 37 return chromeos::BaseLoginDisplayHost::default_host()->GetNativeWindow(); |
| 38 } else { |
| 39 Browser* browser = BrowserList::FindTabbedBrowser( |
| 40 ProfileManager::GetDefaultProfileOrOffTheRecord(), true); |
| 41 if (browser) |
| 42 return browser->window()->GetNativeHandle(); |
| 43 } |
| 44 return NULL; |
| 45 } |
| 46 |
| 47 // Avoid global static initializer. |
| 48 chromeos::NetworkConfigView** GetActiveDialogPointer() { |
| 49 static chromeos::NetworkConfigView* active_dialog = NULL; |
| 50 return &active_dialog; |
| 51 } |
| 52 |
| 53 chromeos::NetworkConfigView* GetActiveDialog() { |
| 54 return *(GetActiveDialogPointer()); |
| 55 } |
| 56 |
| 57 void SetActiveDialog(chromeos::NetworkConfigView* dialog) { |
| 58 *(GetActiveDialogPointer()) = dialog; |
| 59 } |
| 60 |
| 61 } // namespace |
| 62 |
28 namespace chromeos { | 63 namespace chromeos { |
29 | 64 |
30 // static | 65 // static |
31 const int ChildNetworkConfigView::kInputFieldMinWidth = 270; | 66 const int ChildNetworkConfigView::kInputFieldMinWidth = 270; |
32 | 67 |
33 NetworkConfigView::NetworkConfigView(Network* network) | 68 NetworkConfigView::NetworkConfigView(Network* network) |
34 : delegate_(NULL), | 69 : delegate_(NULL), |
35 advanced_button_(NULL), | 70 advanced_button_(NULL), |
36 advanced_button_container_(NULL) { | 71 advanced_button_container_(NULL) { |
| 72 DCHECK(GetActiveDialog() == NULL); |
| 73 SetActiveDialog(this); |
37 if (network->type() == TYPE_WIFI) { | 74 if (network->type() == TYPE_WIFI) { |
38 child_config_view_ = | 75 child_config_view_ = |
39 new WifiConfigView(this, static_cast<WifiNetwork*>(network)); | 76 new WifiConfigView(this, static_cast<WifiNetwork*>(network)); |
40 } else if (network->type() == TYPE_VPN) { | 77 } else if (network->type() == TYPE_VPN) { |
41 child_config_view_ = | 78 child_config_view_ = |
42 new VPNConfigView(this, static_cast<VirtualNetwork*>(network)); | 79 new VPNConfigView(this, static_cast<VirtualNetwork*>(network)); |
43 } else { | 80 } else { |
44 NOTREACHED(); | 81 NOTREACHED(); |
45 child_config_view_ = NULL; | 82 child_config_view_ = NULL; |
46 } | 83 } |
47 } | 84 } |
48 | 85 |
49 NetworkConfigView::NetworkConfigView(ConnectionType type) | 86 NetworkConfigView::NetworkConfigView(ConnectionType type) |
50 : delegate_(NULL), | 87 : delegate_(NULL), |
51 advanced_button_(NULL), | 88 advanced_button_(NULL), |
52 advanced_button_container_(NULL) { | 89 advanced_button_container_(NULL) { |
| 90 DCHECK(GetActiveDialog() == NULL); |
| 91 SetActiveDialog(this); |
53 if (type == TYPE_WIFI) { | 92 if (type == TYPE_WIFI) { |
54 child_config_view_ = new WifiConfigView(this, false /* show_8021x */); | 93 child_config_view_ = new WifiConfigView(this, false /* show_8021x */); |
55 CreateAdvancedButton(); | 94 CreateAdvancedButton(); |
56 } else if (type == TYPE_VPN) { | 95 } else if (type == TYPE_VPN) { |
57 child_config_view_ = new VPNConfigView(this); | 96 child_config_view_ = new VPNConfigView(this); |
58 } else { | 97 } else { |
59 NOTREACHED(); | 98 NOTREACHED(); |
60 child_config_view_ = NULL; | 99 child_config_view_ = NULL; |
61 } | 100 } |
62 } | 101 } |
63 | 102 |
| 103 NetworkConfigView::~NetworkConfigView() { |
| 104 DCHECK(GetActiveDialog() == this); |
| 105 SetActiveDialog(NULL); |
| 106 } |
| 107 |
| 108 // static |
| 109 bool NetworkConfigView::Show(Network* network, gfx::NativeWindow parent) { |
| 110 if (GetActiveDialog() != NULL) |
| 111 return false; |
| 112 NetworkConfigView* view = new NetworkConfigView(network); |
| 113 if (parent == NULL) |
| 114 parent = GetDialogParent(); |
| 115 views::Widget* window = views::Widget::CreateWindowWithParent(view, parent); |
| 116 window->SetAlwaysOnTop(true); |
| 117 window->Show(); |
| 118 return true; |
| 119 } |
| 120 |
| 121 // static |
| 122 bool NetworkConfigView::ShowForType(ConnectionType type, |
| 123 gfx::NativeWindow parent) { |
| 124 if (GetActiveDialog() != NULL) |
| 125 return false; |
| 126 NetworkConfigView* view = new NetworkConfigView(type); |
| 127 if (parent == NULL) |
| 128 parent = GetDialogParent(); |
| 129 views::Widget* window = views::Widget::CreateWindowWithParent(view, parent); |
| 130 window->SetAlwaysOnTop(true); |
| 131 window->Show(); |
| 132 return true; |
| 133 } |
| 134 |
64 gfx::NativeWindow NetworkConfigView::GetNativeWindow() const { | 135 gfx::NativeWindow NetworkConfigView::GetNativeWindow() const { |
65 return GetWidget()->GetNativeWindow(); | 136 return GetWidget()->GetNativeWindow(); |
66 } | 137 } |
67 | 138 |
68 string16 NetworkConfigView::GetDialogButtonLabel( | 139 string16 NetworkConfigView::GetDialogButtonLabel( |
69 ui::DialogButton button) const { | 140 ui::DialogButton button) const { |
70 if (button == ui::DIALOG_BUTTON_OK) | 141 if (button == ui::DIALOG_BUTTON_OK) |
71 return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_CONNECT); | 142 return l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_CONNECT); |
72 return string16(); | 143 return string16(); |
73 } | 144 } |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 image_view_ = new views::ImageView(); | 317 image_view_ = new views::ImageView(); |
247 // Disable |image_view_| so mouse events propagate to the parent. | 318 // Disable |image_view_| so mouse events propagate to the parent. |
248 image_view_->SetEnabled(false); | 319 image_view_->SetEnabled(false); |
249 image_view_->SetImage(gray_image_); | 320 image_view_->SetImage(gray_image_); |
250 image_view_->SetTooltipText( | 321 image_view_->SetTooltipText( |
251 l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_POLICY)); | 322 l10n_util::GetStringUTF16(IDS_OPTIONS_CONTROLLED_SETTING_POLICY)); |
252 AddChildView(image_view_); | 323 AddChildView(image_view_); |
253 } | 324 } |
254 | 325 |
255 } // namespace chromeos | 326 } // namespace chromeos |
OLD | NEW |