network_config_view.h revision 5821806d5e7f356e8fa4b058a389a808ea183019
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/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" 17 18namespace gfx { 19class ImageSkia; 20} 21 22namespace views { 23class ImageView; 24class NativeTextButton; 25class View; 26} 27 28namespace chromeos { 29 30class ChildNetworkConfigView; 31 32// A dialog box for showing a password textfield. 33class NetworkConfigView : public views::DialogDelegateView, 34 public views::ButtonListener { 35 public: 36 class Delegate { 37 public: 38 // Called when dialog "OK" button is pressed. 39 virtual void OnDialogAccepted() = 0; 40 41 // Called when dialog "Cancel" button is pressed. 42 virtual void OnDialogCancelled() = 0; 43 44 protected: 45 virtual ~Delegate() {} 46 }; 47 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); 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* GetExtraView() OVERRIDE; 62 virtual views::View* GetInitiallyFocusedView() OVERRIDE; 63 64 // views::WidgetDelegate methods. 65 virtual ui::ModalType GetModalType() const OVERRIDE; 66 virtual views::View* GetContentsView() 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(bool is_add, 84 views::View* parent, 85 views::View* child) OVERRIDE; 86 87 private: 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(); 93 94 // Creates an "Advanced" button in the lower-left corner of the dialog. 95 void CreateAdvancedButton(); 96 97 // Resets the underlying view to show advanced options. 98 void ShowAdvancedView(); 99 100 // There's always only one child view, which will get deleted when 101 // NetworkConfigView gets cleaned up. 102 ChildNetworkConfigView* child_config_view_; 103 104 Delegate* delegate_; 105 106 // Button in lower-left corner, may be null or hidden. 107 views::NativeTextButton* advanced_button_; 108 views::View* advanced_button_container_; 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 // Returns view that should be focused on dialog activation. 125 virtual views::View* GetInitiallyFocusedView() = 0; 126 127 // Called to determine if "Connect" button should be enabled. 128 virtual bool CanLogin() = 0; 129 130 // Called when "Connect" button is clicked. 131 // Should return false if dialog should remain open. 132 virtual bool Login() = 0; 133 134 // Called when "Cancel" button is clicked. 135 virtual void Cancel() = 0; 136 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; 140 141 // Minimum with of input fields / combo boxes. 142 static const int kInputFieldMinWidth; 143 144 protected: 145 std::string service_path_; 146 NetworkConfigView* parent_; 147 148 private: 149 DISALLOW_COPY_AND_ASSIGN(ChildNetworkConfigView); 150}; 151 152// Shows an icon with tooltip indicating whether a setting is under policy 153// control. 154class ControlledSettingIndicatorView : public views::View { 155 public: 156 ControlledSettingIndicatorView(); 157 explicit ControlledSettingIndicatorView(const NetworkPropertyUIData& ui_data); 158 virtual ~ControlledSettingIndicatorView(); 159 160 // Updates the view based on |ui_data|. 161 void Update(const NetworkPropertyUIData& ui_data); 162 163 protected: 164 // views::View: 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; 169 170 private: 171 // Initializes the view. 172 void Init(); 173 174 bool managed_; 175 views::ImageView* image_view_; 176 const gfx::ImageSkia* gray_image_; 177 const gfx::ImageSkia* color_image_; 178 179 DISALLOW_COPY_AND_ASSIGN(ControlledSettingIndicatorView); 180}; 181 182} // namespace chromeos 183 184#endif // CHROME_BROWSER_CHROMEOS_OPTIONS_NETWORK_CONFIG_VIEW_H_ 185