Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / chromeos / options / network_config_view.h
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.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_OPTIONS_NETWORK_CONFIG_VIEW_H_
6 #define CHROME_BROWSER_CHROMEOS_OPTIONS_NETWORK_CONFIG_VIEW_H_
7
8 #include <string>
9
10 #include "base/compiler_specific.h"
11 #include "base/strings/string16.h"
12 #include "ui/gfx/native_widget_types.h"  // gfx::NativeWindow
13 #include "ui/views/controls/button/button.h"  // views::ButtonListener
14 #include "ui/views/window/dialog_delegate.h"
15
16 namespace gfx {
17 class ImageSkia;
18 }
19
20 namespace views {
21 class ImageView;
22 class LabelButton;
23 }
24
25 namespace chromeos {
26
27 class ChildNetworkConfigView;
28 class NetworkPropertyUIData;
29 class NetworkState;
30
31 // A dialog box for showing a password textfield.
32 class NetworkConfigView : public views::DialogDelegateView,
33                           public views::ButtonListener {
34  public:
35   class Delegate {
36    public:
37     // Called when dialog "OK" button is pressed.
38     virtual void OnDialogAccepted() = 0;
39
40     // Called when dialog "Cancel" button is pressed.
41     virtual void OnDialogCancelled() = 0;
42
43    protected:
44      virtual ~Delegate() {}
45   };
46
47   // Shows a network connection dialog if none is currently visible.
48   static void Show(const std::string& service_path, gfx::NativeWindow parent);
49   // Shows a dialog to configure a new network. |type| must be a valid Shill
50   // 'Type' property value.
51   static void ShowForType(const std::string& type, gfx::NativeWindow parent);
52
53   // Returns corresponding native window.
54   gfx::NativeWindow GetNativeWindow() const;
55
56   // views::DialogDelegate methods.
57   virtual base::string16 GetDialogButtonLabel(
58       ui::DialogButton button) const OVERRIDE;
59   virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE;
60   virtual bool Cancel() OVERRIDE;
61   virtual bool Accept() OVERRIDE;
62   virtual views::View* CreateExtraView() OVERRIDE;
63   virtual views::View* GetInitiallyFocusedView() OVERRIDE;
64
65   // views::WidgetDelegate methods.
66   virtual base::string16 GetWindowTitle() const OVERRIDE;
67   virtual ui::ModalType GetModalType() const OVERRIDE;
68
69   // views::View overrides.
70   virtual void GetAccessibleState(ui::AXViewState* state) OVERRIDE;
71
72   // views::ButtonListener overrides.
73   virtual void ButtonPressed(
74       views::Button* sender, const ui::Event& event) OVERRIDE;
75
76   void set_delegate(Delegate* delegate) {
77     delegate_ = delegate;
78   }
79
80  protected:
81   // views::View overrides:
82   virtual void Layout() OVERRIDE;
83   virtual gfx::Size GetPreferredSize() OVERRIDE;
84   virtual void ViewHierarchyChanged(
85       const ViewHierarchyChangedDetails& details) OVERRIDE;
86
87  private:
88   NetworkConfigView();
89   virtual ~NetworkConfigView();
90
91   // Login dialog for known networks. Returns true if successfully created.
92   bool InitWithNetworkState(const NetworkState* network);
93   // Login dialog for new/hidden networks. Returns true if successfully created.
94   bool InitWithType(const std::string& type);
95
96   // Creates and shows a dialog containing this view.
97   void ShowDialog(gfx::NativeWindow parent);
98
99   // Resets the underlying view to show advanced options.
100   void ShowAdvancedView();
101
102   // There's always only one child view, which will get deleted when
103   // NetworkConfigView gets cleaned up.
104   ChildNetworkConfigView* child_config_view_;
105
106   Delegate* delegate_;
107
108   // Button in lower-left corner, may be null or hidden.
109   views::LabelButton* advanced_button_;
110
111   DISALLOW_COPY_AND_ASSIGN(NetworkConfigView);
112 };
113
114 // Children of NetworkConfigView must subclass this and implement the virtual
115 // methods, which are called by NetworkConfigView.
116 class ChildNetworkConfigView : public views::View {
117  public:
118   // If |service_path| is NULL, a dialog for configuring a new network will
119   // be created.
120   ChildNetworkConfigView(NetworkConfigView* parent,
121                          const std::string& service_path);
122   virtual ~ChildNetworkConfigView();
123
124   // Get the title to show for the dialog.
125   virtual base::string16 GetTitle() const = 0;
126
127   // Returns view that should be focused on dialog activation.
128   virtual views::View* GetInitiallyFocusedView() = 0;
129
130   // Called to determine if "Connect" button should be enabled.
131   virtual bool CanLogin() = 0;
132
133   // Called when "Connect" button is clicked.
134   // Should return false if dialog should remain open.
135   virtual bool Login() = 0;
136
137   // Called when "Cancel" button is clicked.
138   virtual void Cancel() = 0;
139
140   // Called to set focus when view is recreated with the same dialog
141   // being active. For example, clicking on "Advanced" button.
142   virtual void InitFocus() = 0;
143
144   // Returns 'true' if the dialog is for configuration only (default is false).
145   virtual bool IsConfigureDialog();
146
147   // Minimum with of input fields / combo boxes.
148   static const int kInputFieldMinWidth;
149
150  protected:
151   // Gets the default network share state for the current login state.
152   static void GetShareStateForLoginState(bool* default_value, bool* modifiable);
153
154   NetworkConfigView* parent_;
155   std::string service_path_;
156
157  private:
158   DISALLOW_COPY_AND_ASSIGN(ChildNetworkConfigView);
159 };
160
161 // Shows an icon with tooltip indicating whether a setting is under policy
162 // control.
163 class ControlledSettingIndicatorView : public views::View {
164  public:
165   ControlledSettingIndicatorView();
166   explicit ControlledSettingIndicatorView(const NetworkPropertyUIData& ui_data);
167   virtual ~ControlledSettingIndicatorView();
168
169   // Updates the view based on |ui_data|.
170   void Update(const NetworkPropertyUIData& ui_data);
171
172  protected:
173   // views::View:
174   virtual gfx::Size GetPreferredSize() OVERRIDE;
175   virtual void Layout() OVERRIDE;
176
177  private:
178   // Initializes the view.
179   void Init();
180
181   bool managed_;
182   views::ImageView* image_view_;
183   const gfx::ImageSkia* image_;
184
185   DISALLOW_COPY_AND_ASSIGN(ControlledSettingIndicatorView);
186 };
187
188 }  // namespace chromeos
189
190 #endif  // CHROME_BROWSER_CHROMEOS_OPTIONS_NETWORK_CONFIG_VIEW_H_