- add sources.
[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 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* CreateExtraView() OVERRIDE;
62   virtual views::View* GetInitiallyFocusedView() OVERRIDE;
63
64   // views::WidgetDelegate methods.
65   virtual string16 GetWindowTitle() const OVERRIDE;
66   virtual ui::ModalType GetModalType() const OVERRIDE;
67
68   // views::View overrides.
69   virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
70
71   // views::ButtonListener overrides.
72   virtual void ButtonPressed(
73       views::Button* sender, const ui::Event& event) OVERRIDE;
74
75   void set_delegate(Delegate* delegate) {
76     delegate_ = delegate;
77   }
78
79  protected:
80   // views::View overrides:
81   virtual void Layout() OVERRIDE;
82   virtual gfx::Size GetPreferredSize() OVERRIDE;
83   virtual void ViewHierarchyChanged(
84       const ViewHierarchyChangedDetails& details) OVERRIDE;
85
86  private:
87   NetworkConfigView();
88   virtual ~NetworkConfigView();
89
90   // Login dialog for known networks. Returns true if successfully created.
91   bool InitWithNetworkState(const NetworkState* network);
92   // Login dialog for new/hidden networks. Returns true if successfully created.
93   bool InitWithType(const std::string& type);
94
95   // Creates and shows a dialog containing this view.
96   void ShowDialog(gfx::NativeWindow parent);
97
98   // Resets the underlying view to show advanced options.
99   void ShowAdvancedView();
100
101   // There's always only one child view, which will get deleted when
102   // NetworkConfigView gets cleaned up.
103   ChildNetworkConfigView* child_config_view_;
104
105   Delegate* delegate_;
106
107   // Button in lower-left corner, may be null or hidden.
108   views::LabelButton* advanced_button_;
109
110   DISALLOW_COPY_AND_ASSIGN(NetworkConfigView);
111 };
112
113 // Children of NetworkConfigView must subclass this and implement the virtual
114 // methods, which are called by NetworkConfigView.
115 class ChildNetworkConfigView : public views::View {
116  public:
117   // If |service_path| is NULL, a dialog for configuring a new network will
118   // be created.
119   ChildNetworkConfigView(NetworkConfigView* parent,
120                          const std::string& service_path);
121   virtual ~ChildNetworkConfigView();
122
123   // Get the title to show for the dialog.
124   virtual string16 GetTitle() const = 0;
125
126   // Returns view that should be focused on dialog activation.
127   virtual views::View* GetInitiallyFocusedView() = 0;
128
129   // Called to determine if "Connect" button should be enabled.
130   virtual bool CanLogin() = 0;
131
132   // Called when "Connect" button is clicked.
133   // Should return false if dialog should remain open.
134   virtual bool Login() = 0;
135
136   // Called when "Cancel" button is clicked.
137   virtual void Cancel() = 0;
138
139   // Called to set focus when view is recreated with the same dialog
140   // being active. For example, clicking on "Advanced" button.
141   virtual void InitFocus() = 0;
142
143   // Minimum with of input fields / combo boxes.
144   static const int kInputFieldMinWidth;
145
146  protected:
147   NetworkConfigView* parent_;
148   std::string service_path_;
149
150  private:
151   DISALLOW_COPY_AND_ASSIGN(ChildNetworkConfigView);
152 };
153
154 // Shows an icon with tooltip indicating whether a setting is under policy
155 // control.
156 class ControlledSettingIndicatorView : public views::View {
157  public:
158   ControlledSettingIndicatorView();
159   explicit ControlledSettingIndicatorView(const NetworkPropertyUIData& ui_data);
160   virtual ~ControlledSettingIndicatorView();
161
162   // Updates the view based on |ui_data|.
163   void Update(const NetworkPropertyUIData& ui_data);
164
165  protected:
166   // views::View:
167   virtual gfx::Size GetPreferredSize() OVERRIDE;
168   virtual void Layout() OVERRIDE;
169   virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
170   virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
171
172  private:
173   // Initializes the view.
174   void Init();
175
176   bool managed_;
177   views::ImageView* image_view_;
178   const gfx::ImageSkia* gray_image_;
179   const gfx::ImageSkia* color_image_;
180
181   DISALLOW_COPY_AND_ASSIGN(ControlledSettingIndicatorView);
182 };
183
184 }  // namespace chromeos
185
186 #endif  // CHROME_BROWSER_CHROMEOS_OPTIONS_NETWORK_CONFIG_VIEW_H_