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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_NETWORK_CONFIG_VIEW_H_
6 #define CHROME_BROWSER_CHROMEOS_OPTIONS_NETWORK_CONFIG_VIEW_H_
10 #include "base/compiler_specific.h"
11 #include "base/string16.h"
12 #include "chrome/browser/chromeos/cros/network_library.h"
13 #include "chrome/browser/chromeos/cros/network_ui_data.h"
14 #include "ui/gfx/native_widget_types.h" // gfx::NativeWindow
15 #include "ui/views/controls/button/button.h" // views::ButtonListener
16 #include "ui/views/window/dialog_delegate.h"
24 class NativeTextButton
;
30 class ChildNetworkConfigView
;
32 // A dialog box for showing a password textfield.
33 class NetworkConfigView
: public views::DialogDelegateView
,
34 public views::ButtonListener
{
38 // Called when dialog "OK" button is pressed.
39 virtual void OnDialogAccepted() = 0;
41 // Called when dialog "Cancel" button is pressed.
42 virtual void OnDialogCancelled() = 0;
45 virtual ~Delegate() {}
48 // Shows a network connection dialog if none is currently visible.
49 // Returns false if a dialog is already visible.
50 static bool Show(Network
* network
, gfx::NativeWindow parent
);
51 static bool ShowForType(ConnectionType type
, gfx::NativeWindow parent
);
53 // Returns corresponding native window.
54 gfx::NativeWindow
GetNativeWindow() const;
56 // views::DialogDelegate methods.
57 virtual string16
GetDialogButtonLabel(ui::DialogButton button
) const OVERRIDE
;
58 virtual bool IsDialogButtonEnabled(ui::DialogButton button
) const OVERRIDE
;
59 virtual bool Cancel() OVERRIDE
;
60 virtual bool Accept() OVERRIDE
;
61 virtual views::View
* GetExtraView() OVERRIDE
;
62 virtual views::View
* GetInitiallyFocusedView() OVERRIDE
;
64 // views::WidgetDelegate methods.
65 virtual ui::ModalType
GetModalType() const OVERRIDE
;
66 virtual views::View
* GetContentsView() OVERRIDE
;
68 // views::View overrides.
69 virtual void GetAccessibleState(ui::AccessibleViewState
* state
) OVERRIDE
;
71 // views::ButtonListener overrides.
72 virtual void ButtonPressed(
73 views::Button
* sender
, const ui::Event
& event
) OVERRIDE
;
75 void set_delegate(Delegate
* delegate
) {
80 // views::View overrides:
81 virtual void Layout() OVERRIDE
;
82 virtual gfx::Size
GetPreferredSize() OVERRIDE
;
83 virtual void ViewHierarchyChanged(bool is_add
,
85 views::View
* child
) OVERRIDE
;
88 // Login dialog for known networks.
89 explicit NetworkConfigView(Network
* network
);
90 // Login dialog for new/hidden networks.
91 explicit NetworkConfigView(ConnectionType type
);
92 virtual ~NetworkConfigView();
94 // Creates an "Advanced" button in the lower-left corner of the dialog.
95 void CreateAdvancedButton();
97 // Resets the underlying view to show advanced options.
98 void ShowAdvancedView();
100 // There's always only one child view, which will get deleted when
101 // NetworkConfigView gets cleaned up.
102 ChildNetworkConfigView
* child_config_view_
;
106 // Button in lower-left corner, may be null or hidden.
107 views::NativeTextButton
* advanced_button_
;
108 views::View
* advanced_button_container_
;
110 DISALLOW_COPY_AND_ASSIGN(NetworkConfigView
);
113 // Children of NetworkConfigView must subclass this and implement the virtual
114 // methods, which are called by NetworkConfigView.
115 class ChildNetworkConfigView
: public views::View
{
117 ChildNetworkConfigView(NetworkConfigView
* parent
, Network
* network
)
118 : service_path_(network
->service_path()),
120 explicit ChildNetworkConfigView(NetworkConfigView
* parent
)
122 virtual ~ChildNetworkConfigView() {}
124 // Returns view that should be focused on dialog activation.
125 virtual views::View
* GetInitiallyFocusedView() = 0;
127 // Called to determine if "Connect" button should be enabled.
128 virtual bool CanLogin() = 0;
130 // Called when "Connect" button is clicked.
131 // Should return false if dialog should remain open.
132 virtual bool Login() = 0;
134 // Called when "Cancel" button is clicked.
135 virtual void Cancel() = 0;
137 // Called to set focus when view is recreated with the same dialog
138 // being active. For example, clicking on "Advanced" button.
139 virtual void InitFocus() = 0;
141 // Minimum with of input fields / combo boxes.
142 static const int kInputFieldMinWidth
;
145 std::string service_path_
;
146 NetworkConfigView
* parent_
;
149 DISALLOW_COPY_AND_ASSIGN(ChildNetworkConfigView
);
152 // Shows an icon with tooltip indicating whether a setting is under policy
154 class ControlledSettingIndicatorView
: public views::View
{
156 ControlledSettingIndicatorView();
157 explicit ControlledSettingIndicatorView(const NetworkPropertyUIData
& ui_data
);
158 virtual ~ControlledSettingIndicatorView();
160 // Updates the view based on |ui_data|.
161 void Update(const NetworkPropertyUIData
& ui_data
);
165 virtual gfx::Size
GetPreferredSize() OVERRIDE
;
166 virtual void Layout() OVERRIDE
;
167 virtual void OnMouseEntered(const ui::MouseEvent
& event
) OVERRIDE
;
168 virtual void OnMouseExited(const ui::MouseEvent
& event
) OVERRIDE
;
171 // Initializes the view.
175 views::ImageView
* image_view_
;
176 const gfx::ImageSkia
* gray_image_
;
177 const gfx::ImageSkia
* color_image_
;
179 DISALLOW_COPY_AND_ASSIGN(ControlledSettingIndicatorView
);
182 } // namespace chromeos
184 #endif // CHROME_BROWSER_CHROMEOS_OPTIONS_NETWORK_CONFIG_VIEW_H_