Home | History | Annotate | Download | only in options
      1 // Copyright (c) 2011 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 #pragma once
      8 
      9 #include "chrome/browser/chromeos/cros/network_library.h"
     10 #include "views/window/dialog_delegate.h"
     11 
     12 namespace views {
     13 class View;
     14 class Window;
     15 }
     16 
     17 namespace chromeos {
     18 
     19 class ChildNetworkConfigView;
     20 
     21 // A dialog box for showing a password textfield.
     22 class NetworkConfigView : public views::View,
     23                           public views::DialogDelegate {
     24  public:
     25   class Delegate {
     26    public:
     27     // Called when dialog "OK" button is pressed.
     28     virtual void OnDialogAccepted() = 0;
     29 
     30     // Called when dialog "Cancel" button is pressed.
     31     virtual void OnDialogCancelled() = 0;
     32 
     33    protected:
     34      virtual ~Delegate() {}
     35   };
     36 
     37   // Login dialog for known networks.
     38   explicit NetworkConfigView(Network* network);
     39   // Login dialog for new/hidden networks.
     40   explicit NetworkConfigView(ConnectionType type);
     41   virtual ~NetworkConfigView() {}
     42 
     43   // Returns corresponding native window.
     44   gfx::NativeWindow GetNativeWindow() const;
     45 
     46   // views::DialogDelegate methods.
     47   virtual std::wstring GetDialogButtonLabel(
     48       MessageBoxFlags::DialogButton button) const;
     49   virtual bool IsDialogButtonEnabled(
     50       MessageBoxFlags::DialogButton button) const;
     51   virtual bool Cancel();
     52   virtual bool Accept();
     53 
     54   // views::WindowDelegate method.
     55   virtual bool IsModal() const { return true; }
     56   virtual views::View* GetContentsView() { return this; }
     57 
     58   // views::View overrides.
     59   virtual std::wstring GetWindowTitle() const OVERRIDE;
     60   virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
     61 
     62   // Getter/setter for browser mode.
     63   void set_browser_mode(bool value) {
     64     browser_mode_ = value;
     65   }
     66   bool is_browser_mode() const {
     67     return browser_mode_;
     68   }
     69 
     70   void set_delegate(Delegate* delegate) {
     71     delegate_ = delegate;
     72   }
     73 
     74  protected:
     75   // views::View overrides:
     76   virtual void Layout();
     77   virtual gfx::Size GetPreferredSize();
     78   virtual void ViewHierarchyChanged(bool is_add,
     79                                     views::View* parent,
     80                                     views::View* child);
     81 
     82  private:
     83   // True when opening in browser, otherwise in OOBE/login mode.
     84   bool browser_mode_;
     85 
     86   // There's always only one child view, which will get deleted when
     87   // NetworkConfigView gets cleaned up.
     88   ChildNetworkConfigView* child_config_view_;
     89 
     90   Delegate* delegate_;
     91 
     92   DISALLOW_COPY_AND_ASSIGN(NetworkConfigView);
     93 };
     94 
     95 // Children of NetworkConfigView must subclass this and implement the virtual
     96 // methods, which are called by NetworkConfigView.
     97 class ChildNetworkConfigView : public views::View {
     98  public:
     99   // Called to get title for parent NetworkConfigView dialog box.
    100   virtual string16 GetTitle() = 0;
    101 
    102   // Called to determine if "Connect" button should be enabled.
    103   virtual bool CanLogin() = 0;
    104 
    105   // Called when "Connect" button is clicked.
    106   // Should return false if dialog should remain open.
    107   virtual bool Login() = 0;
    108 
    109   // Called when "Cancel" button is clicked.
    110   virtual void Cancel() = 0;
    111 
    112   // Called to set initial focus in a reasonable widget.  Must be done
    113   // post-construction after the view has a parent window.
    114   virtual void InitFocus() = 0;
    115 
    116   // Width of passphrase fields.
    117   static const int kPassphraseWidth;
    118 
    119  protected:
    120   explicit ChildNetworkConfigView(NetworkConfigView* parent, Network* network)
    121       : service_path_(network->service_path()),
    122         parent_(parent) {}
    123   explicit ChildNetworkConfigView(NetworkConfigView* parent)
    124       : parent_(parent) {}
    125   virtual ~ChildNetworkConfigView() {}
    126 
    127   std::string service_path_;
    128   NetworkConfigView* parent_;
    129 
    130  private:
    131   DISALLOW_COPY_AND_ASSIGN(ChildNetworkConfigView);
    132 };
    133 
    134 }  // namespace chromeos
    135 
    136 #endif  // CHROME_BROWSER_CHROMEOS_OPTIONS_NETWORK_CONFIG_VIEW_H_
    137