network_config_view.h revision ca12bfac764ba476d6cd062bf1dde12cc64c3f40
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 "chrome/browser/chromeos/cros/network_library.h" 13#include "ui/gfx/native_widget_types.h" // gfx::NativeWindow 14#include "ui/views/controls/button/button.h" // views::ButtonListener 15#include "ui/views/window/dialog_delegate.h" 16 17namespace gfx { 18class ImageSkia; 19} 20 21namespace views { 22class ImageView; 23class LabelButton; 24} 25 26namespace chromeos { 27 28class ChildNetworkConfigView; 29class NetworkPropertyUIData; 30 31// A dialog box for showing a password textfield. 32class 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(Network* network, gfx::NativeWindow parent); 49 static void ShowForType(ConnectionType type, gfx::NativeWindow parent); 50 51 // Returns corresponding native window. 52 gfx::NativeWindow GetNativeWindow() const; 53 54 // views::DialogDelegate methods. 55 virtual string16 GetDialogButtonLabel(ui::DialogButton button) const OVERRIDE; 56 virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE; 57 virtual bool Cancel() OVERRIDE; 58 virtual bool Accept() OVERRIDE; 59 virtual views::View* CreateExtraView() OVERRIDE; 60 virtual views::View* GetInitiallyFocusedView() OVERRIDE; 61 62 // views::WidgetDelegate methods. 63 virtual string16 GetWindowTitle() const OVERRIDE; 64 virtual ui::ModalType GetModalType() const OVERRIDE; 65 66 // views::View overrides. 67 virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; 68 69 // views::ButtonListener overrides. 70 virtual void ButtonPressed( 71 views::Button* sender, const ui::Event& event) OVERRIDE; 72 73 void set_delegate(Delegate* delegate) { 74 delegate_ = delegate; 75 } 76 77 static const base::DictionaryValue* FindPolicyForActiveUser( 78 const Network* network, 79 onc::ONCSource* onc_source); 80 81 protected: 82 // views::View overrides: 83 virtual void Layout() OVERRIDE; 84 virtual gfx::Size GetPreferredSize() OVERRIDE; 85 virtual void ViewHierarchyChanged( 86 const ViewHierarchyChangedDetails& details) OVERRIDE; 87 88 private: 89 // Login dialog for known networks. 90 explicit NetworkConfigView(Network* network); 91 // Login dialog for new/hidden networks. 92 explicit NetworkConfigView(ConnectionType type); 93 virtual ~NetworkConfigView(); 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. 115class ChildNetworkConfigView : public views::View { 116 public: 117 ChildNetworkConfigView(NetworkConfigView* parent, Network* network) 118 : service_path_(network->service_path()), 119 parent_(parent) {} 120 explicit ChildNetworkConfigView(NetworkConfigView* parent) 121 : parent_(parent) {} 122 virtual ~ChildNetworkConfigView() {} 123 124 // Get the title to show for the dialog. 125 virtual 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 // Minimum with of input fields / combo boxes. 145 static const int kInputFieldMinWidth; 146 147 protected: 148 std::string service_path_; 149 NetworkConfigView* parent_; 150 151 private: 152 DISALLOW_COPY_AND_ASSIGN(ChildNetworkConfigView); 153}; 154 155// Shows an icon with tooltip indicating whether a setting is under policy 156// control. 157class ControlledSettingIndicatorView : public views::View { 158 public: 159 ControlledSettingIndicatorView(); 160 explicit ControlledSettingIndicatorView(const NetworkPropertyUIData& ui_data); 161 virtual ~ControlledSettingIndicatorView(); 162 163 // Updates the view based on |ui_data|. 164 void Update(const NetworkPropertyUIData& ui_data); 165 166 protected: 167 // views::View: 168 virtual gfx::Size GetPreferredSize() OVERRIDE; 169 virtual void Layout() OVERRIDE; 170 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; 171 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; 172 173 private: 174 // Initializes the view. 175 void Init(); 176 177 bool managed_; 178 views::ImageView* image_view_; 179 const gfx::ImageSkia* gray_image_; 180 const gfx::ImageSkia* color_image_; 181 182 DISALLOW_COPY_AND_ASSIGN(ControlledSettingIndicatorView); 183}; 184 185} // namespace chromeos 186 187#endif // CHROME_BROWSER_CHROMEOS_OPTIONS_NETWORK_CONFIG_VIEW_H_ 188