Home | History | Annotate | Download | only in autofill
      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_UI_VIEWS_AUTOFILL_AUTOFILL_DIALOG_VIEWS_H_
      6 #define CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_DIALOG_VIEWS_H_
      7 
      8 #include <map>
      9 #include <set>
     10 
     11 #include "base/memory/scoped_vector.h"
     12 #include "base/memory/weak_ptr.h"
     13 #include "base/scoped_observer.h"
     14 #include "chrome/browser/ui/autofill/autofill_dialog_types.h"
     15 #include "chrome/browser/ui/autofill/autofill_dialog_view.h"
     16 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h"
     17 #include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h"
     18 #include "ui/views/controls/button/button.h"
     19 #include "ui/views/controls/button/menu_button.h"
     20 #include "ui/views/controls/button/menu_button_listener.h"
     21 #include "ui/views/controls/combobox/combobox_listener.h"
     22 #include "ui/views/controls/link_listener.h"
     23 #include "ui/views/controls/progress_bar.h"
     24 #include "ui/views/controls/scroll_view.h"
     25 #include "ui/views/controls/styled_label_listener.h"
     26 #include "ui/views/controls/textfield/textfield_controller.h"
     27 #include "ui/views/focus/focus_manager.h"
     28 #include "ui/views/widget/widget_observer.h"
     29 #include "ui/views/window/dialog_delegate.h"
     30 
     31 namespace gfx {
     32 class Image;
     33 }
     34 
     35 namespace views {
     36 class BubbleBorder;
     37 class Checkbox;
     38 class Combobox;
     39 class FocusManager;
     40 class ImageView;
     41 class Label;
     42 class LabelButton;
     43 class Link;
     44 class MenuRunner;
     45 class StyledLabel;
     46 class WebView;
     47 class Widget;
     48 }  // namespace views
     49 
     50 namespace ui {
     51 class ComboboxModel;
     52 class KeyEvent;
     53 }
     54 
     55 namespace autofill {
     56 
     57 class AutofillDialogSignInDelegate;
     58 class DecoratedTextfield;
     59 class InfoBubble;
     60 
     61 // Views toolkit implementation of the Autofill dialog that handles the
     62 // imperative autocomplete API call.
     63 class AutofillDialogViews : public AutofillDialogView,
     64                             public TestableAutofillDialogView,
     65                             public views::DialogDelegateView,
     66                             public views::WidgetObserver,
     67                             public views::TextfieldController,
     68                             public views::FocusChangeListener,
     69                             public views::ComboboxListener,
     70                             public views::StyledLabelListener,
     71                             public views::MenuButtonListener {
     72  public:
     73   explicit AutofillDialogViews(AutofillDialogViewDelegate* delegate);
     74   virtual ~AutofillDialogViews();
     75 
     76   // AutofillDialogView implementation:
     77   virtual void Show() OVERRIDE;
     78   virtual void Hide() OVERRIDE;
     79   virtual void UpdatesStarted() OVERRIDE;
     80   virtual void UpdatesFinished() OVERRIDE;
     81   virtual void UpdateAccountChooser() OVERRIDE;
     82   virtual void UpdateButtonStrip() OVERRIDE;
     83   virtual void UpdateOverlay() OVERRIDE;
     84   virtual void UpdateDetailArea() OVERRIDE;
     85   virtual void UpdateForErrors() OVERRIDE;
     86   virtual void UpdateNotificationArea() OVERRIDE;
     87   virtual void UpdateSection(DialogSection section) OVERRIDE;
     88   virtual void UpdateErrorBubble() OVERRIDE;
     89   virtual void FillSection(DialogSection section,
     90                            const DetailInput& originating_input) OVERRIDE;
     91   virtual void GetUserInput(DialogSection section,
     92                             FieldValueMap* output) OVERRIDE;
     93   virtual base::string16 GetCvc() OVERRIDE;
     94   virtual bool HitTestInput(const DetailInput& input,
     95                             const gfx::Point& screen_point) OVERRIDE;
     96   virtual bool SaveDetailsLocally() OVERRIDE;
     97   virtual const content::NavigationController* ShowSignIn() OVERRIDE;
     98   virtual void HideSignIn() OVERRIDE;
     99   virtual void ModelChanged() OVERRIDE;
    100   virtual TestableAutofillDialogView* GetTestableView() OVERRIDE;
    101   virtual void OnSignInResize(const gfx::Size& pref_size) OVERRIDE;
    102 
    103   // TestableAutofillDialogView implementation:
    104   virtual void SubmitForTesting() OVERRIDE;
    105   virtual void CancelForTesting() OVERRIDE;
    106   virtual base::string16 GetTextContentsOfInput(
    107       const DetailInput& input) OVERRIDE;
    108   virtual void SetTextContentsOfInput(const DetailInput& input,
    109                                       const base::string16& contents) OVERRIDE;
    110   virtual void SetTextContentsOfSuggestionInput(
    111       DialogSection section,
    112       const base::string16& text) OVERRIDE;
    113   virtual void ActivateInput(const DetailInput& input) OVERRIDE;
    114   virtual gfx::Size GetSize() const OVERRIDE;
    115   virtual content::WebContents* GetSignInWebContents() OVERRIDE;
    116   virtual bool IsShowingOverlay() const OVERRIDE;
    117 
    118   // views::View implementation.
    119   virtual gfx::Size GetPreferredSize() OVERRIDE;
    120   virtual gfx::Size GetMinimumSize() OVERRIDE;
    121   virtual void Layout() OVERRIDE;
    122   virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE;
    123 
    124   // views::DialogDelegate implementation:
    125   virtual base::string16 GetWindowTitle() const OVERRIDE;
    126   virtual void WindowClosing() OVERRIDE;
    127   virtual void DeleteDelegate() OVERRIDE;
    128   virtual views::View* CreateOverlayView() OVERRIDE;
    129   virtual int GetDialogButtons() const OVERRIDE;
    130   virtual int GetDefaultDialogButton() const OVERRIDE;
    131   virtual base::string16 GetDialogButtonLabel(ui::DialogButton button) const
    132       OVERRIDE;
    133   virtual bool ShouldDefaultButtonBeBlue() const OVERRIDE;
    134   virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE;
    135   virtual views::View* GetInitiallyFocusedView() OVERRIDE;
    136   virtual views::View* CreateExtraView() OVERRIDE;
    137   virtual views::View* CreateTitlebarExtraView() OVERRIDE;
    138   virtual views::View* CreateFootnoteView() OVERRIDE;
    139   virtual bool Cancel() OVERRIDE;
    140   virtual bool Accept() OVERRIDE;
    141   virtual views::NonClientFrameView* CreateNonClientFrameView(
    142       views::Widget* widget) OVERRIDE;
    143 
    144   // views::WidgetObserver implementation:
    145   virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE;
    146   virtual void OnWidgetBoundsChanged(views::Widget* widget,
    147                                      const gfx::Rect& new_bounds) OVERRIDE;
    148 
    149   // views::TextfieldController implementation:
    150   virtual void ContentsChanged(views::Textfield* sender,
    151                                const base::string16& new_contents) OVERRIDE;
    152   virtual bool HandleKeyEvent(views::Textfield* sender,
    153                               const ui::KeyEvent& key_event) OVERRIDE;
    154   virtual bool HandleMouseEvent(views::Textfield* sender,
    155                                 const ui::MouseEvent& key_event) OVERRIDE;
    156 
    157   // views::FocusChangeListener implementation.
    158   virtual void OnWillChangeFocus(views::View* focused_before,
    159                                  views::View* focused_now) OVERRIDE;
    160   virtual void OnDidChangeFocus(views::View* focused_before,
    161                                 views::View* focused_now) OVERRIDE;
    162 
    163   // views::ComboboxListener implementation:
    164   virtual void OnSelectedIndexChanged(views::Combobox* combobox) OVERRIDE;
    165 
    166   // views::StyledLabelListener implementation:
    167   virtual void StyledLabelLinkClicked(const gfx::Range& range, int event_flags)
    168       OVERRIDE;
    169 
    170   // views::MenuButtonListener implementation.
    171   virtual void OnMenuButtonClicked(views::View* source,
    172                                    const gfx::Point& point) OVERRIDE;
    173 
    174  protected:
    175   // Exposed for testing.
    176   views::View* GetLoadingShieldForTesting();
    177   views::WebView* GetSignInWebViewForTesting();
    178   views::View* GetNotificationAreaForTesting();
    179   views::View* GetScrollableAreaForTesting();
    180 
    181  private:
    182   // What the entire dialog should be doing (e.g. gathering info from the user,
    183   // asking the user to sign in, etc.).
    184   enum DialogMode {
    185     DETAIL_INPUT,
    186     LOADING,
    187     SIGN_IN,
    188   };
    189 
    190   // A View which displays the currently selected account and lets the user
    191   // switch accounts.
    192   class AccountChooser : public views::View,
    193                          public views::LinkListener,
    194                          public views::MenuButtonListener,
    195                          public base::SupportsWeakPtr<AccountChooser> {
    196    public:
    197     explicit AccountChooser(AutofillDialogViewDelegate* delegate);
    198     virtual ~AccountChooser();
    199 
    200     // Updates the view based on the state that |delegate_| reports.
    201     void Update();
    202 
    203     // views::LinkListener implementation.
    204     virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
    205 
    206     // views::MenuButtonListener implementation.
    207     virtual void OnMenuButtonClicked(views::View* source,
    208                                      const gfx::Point& point) OVERRIDE;
    209 
    210    private:
    211     // The icon for the currently in-use account.
    212     views::ImageView* image_;
    213 
    214     // The button for showing a menu to change the currently in-use account.
    215     views::MenuButton* menu_button_;
    216 
    217     // The sign in link.
    218     views::Link* link_;
    219 
    220     // The delegate |this| queries for logic and state.
    221     AutofillDialogViewDelegate* delegate_;
    222 
    223     // Runs the suggestion menu (triggered by each section's |suggested_button|.
    224     scoped_ptr<views::MenuRunner> menu_runner_;
    225 
    226     DISALLOW_COPY_AND_ASSIGN(AccountChooser);
    227   };
    228 
    229   // A view which displays an image, optionally some messages and a button. Used
    230   // for the Wallet interstitial.
    231   class OverlayView : public views::View {
    232    public:
    233     explicit OverlayView(AutofillDialogViewDelegate* delegate);
    234     virtual ~OverlayView();
    235 
    236     // Returns a height which should be used when the contents view has width
    237     // |w|. Note that the value returned should be used as the height of the
    238     // dialog's contents.
    239     int GetHeightForContentsForWidth(int width);
    240 
    241     // Sets the state to whatever |delegate_| says it should be.
    242     void UpdateState();
    243 
    244     // views::View implementation:
    245     virtual gfx::Insets GetInsets() const OVERRIDE;
    246     virtual void Layout() OVERRIDE;
    247     virtual const char* GetClassName() const OVERRIDE;
    248     virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
    249     virtual void OnNativeThemeChanged(const ui::NativeTheme* theme) OVERRIDE;
    250 
    251    private:
    252     // Gets the border of the non-client frame view as a BubbleBorder.
    253     views::BubbleBorder* GetBubbleBorder();
    254 
    255     // Gets the bounds of this view without the frame view's bubble border.
    256     gfx::Rect ContentBoundsSansBubbleBorder();
    257 
    258     // The delegate that provides |state| when UpdateState is called.
    259     AutofillDialogViewDelegate* delegate_;
    260 
    261     // Child View. Front and center.
    262     views::ImageView* image_view_;
    263     // Child View. When visible, below |image_view_|.
    264     views::Label* message_view_;
    265 
    266     DISALLOW_COPY_AND_ASSIGN(OverlayView);
    267   };
    268 
    269   // An area for notifications. Some notifications point at the account chooser.
    270   class NotificationArea : public views::View {
    271    public:
    272     explicit NotificationArea(AutofillDialogViewDelegate* delegate);
    273     virtual ~NotificationArea();
    274 
    275     // Displays the given notifications.
    276     void SetNotifications(const std::vector<DialogNotification>& notifications);
    277 
    278     // views::View implementation.
    279     virtual gfx::Size GetPreferredSize() OVERRIDE;
    280     virtual const char* GetClassName() const OVERRIDE;
    281     virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE;
    282     virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
    283 
    284     void set_arrow_centering_anchor(
    285         const base::WeakPtr<views::View>& arrow_centering_anchor) {
    286       arrow_centering_anchor_ = arrow_centering_anchor;
    287     }
    288 
    289    private:
    290     // Utility function for determining whether an arrow should be drawn
    291     // pointing at |arrow_centering_anchor_|.
    292     bool HasArrow();
    293 
    294     // A reference to the delegate/controller than owns this view.
    295     // Used to report when checkboxes change their values.
    296     AutofillDialogViewDelegate* delegate_;  // weak
    297 
    298     // If HasArrow() is true, the arrow should point at this.
    299     base::WeakPtr<views::View> arrow_centering_anchor_;
    300 
    301     std::vector<DialogNotification> notifications_;
    302 
    303     DISALLOW_COPY_AND_ASSIGN(NotificationArea);
    304   };
    305 
    306   typedef std::map<ServerFieldType, DecoratedTextfield*> TextfieldMap;
    307   typedef std::map<ServerFieldType, views::Combobox*> ComboboxMap;
    308 
    309   // A view that packs a label on the left and some related controls
    310   // on the right.
    311   class SectionContainer : public views::View {
    312    public:
    313     SectionContainer(const base::string16& label,
    314                      views::View* controls,
    315                      views::Button* proxy_button);
    316     virtual ~SectionContainer();
    317 
    318     // Sets the visual appearance of the section to active (considered active
    319     // when showing the menu or hovered by the mouse cursor).
    320     void SetActive(bool active);
    321 
    322     // Sets whether mouse events should be forwarded to |proxy_button_|.
    323     void SetForwardMouseEvents(bool forward);
    324 
    325     // views::View implementation.
    326     virtual const char* GetClassName() const OVERRIDE;
    327     virtual void OnMouseMoved(const ui::MouseEvent& event) OVERRIDE;
    328     virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
    329     virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
    330     virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
    331     virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
    332     virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
    333     // This is needed because not all events percolate up the views hierarchy.
    334     virtual View* GetEventHandlerForRect(const gfx::Rect& rect) OVERRIDE;
    335 
    336    private:
    337     // Converts |event| to one suitable for |proxy_button_|.
    338     static ui::MouseEvent ProxyEvent(const ui::MouseEvent& event);
    339 
    340     // Returns true if the given event should be forwarded to |proxy_button_|.
    341     bool ShouldForwardEvent(const ui::LocatedEvent& event);
    342 
    343     // Mouse events on |this| are sent to this button.
    344     views::Button* proxy_button_;  // Weak reference.
    345 
    346     // When true, all mouse events will be forwarded to |proxy_button_|.
    347     bool forward_mouse_events_;
    348 
    349     DISALLOW_COPY_AND_ASSIGN(SectionContainer);
    350   };
    351 
    352   // A button to show address or billing suggestions.
    353   class SuggestedButton : public views::MenuButton {
    354    public:
    355     explicit SuggestedButton(views::MenuButtonListener* listener);
    356     virtual ~SuggestedButton();
    357 
    358     // views::MenuButton implementation.
    359     virtual gfx::Size GetPreferredSize() OVERRIDE;
    360     virtual const char* GetClassName() const OVERRIDE;
    361     virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE;
    362     virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
    363 
    364    private:
    365     // Returns the corred resource ID (i.e. IDR_*) for the current |state()|.
    366     int ResourceIDForState() const;
    367 
    368     DISALLOW_COPY_AND_ASSIGN(SuggestedButton);
    369   };
    370 
    371   // A view that runs a callback whenever its bounds change, and which can
    372   // optionally suppress layout.
    373   class DetailsContainerView : public views::View {
    374    public:
    375     explicit DetailsContainerView(const base::Closure& callback);
    376     virtual ~DetailsContainerView();
    377 
    378     void set_ignore_layouts(bool ignore_layouts) {
    379       ignore_layouts_ = ignore_layouts;
    380     }
    381 
    382     // views::View implementation.
    383     virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
    384     virtual void Layout() OVERRIDE;
    385 
    386    private:
    387     base::Closure bounds_changed_callback_;
    388 
    389     // The view ignores Layout() calls when this is true.
    390     bool ignore_layouts_;
    391 
    392     DISALLOW_COPY_AND_ASSIGN(DetailsContainerView);
    393   };
    394 
    395   // A view that contains a suggestion (such as a known address) and a link to
    396   // edit the suggestion.
    397   class SuggestionView : public views::View {
    398    public:
    399     explicit SuggestionView(AutofillDialogViews* autofill_dialog);
    400     virtual ~SuggestionView();
    401 
    402     void SetState(const SuggestionState& state);
    403 
    404     // views::View implementation.
    405     virtual gfx::Size GetPreferredSize() OVERRIDE;
    406     virtual int GetHeightForWidth(int width) OVERRIDE;
    407     virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
    408 
    409     DecoratedTextfield* decorated_textfield() { return decorated_; }
    410 
    411    private:
    412     // Returns whether there's room to display |state_.vertically_compact_text|
    413     // without resorting to an ellipsis for a pixel width of |available_width|.
    414     // Fills in |resulting_height| with the amount of space required to display
    415     // |vertically_compact_text| or |horizontally_compact_text| as the case may
    416     // be.
    417     bool CanUseVerticallyCompactText(int available_width,
    418                                      int* resulting_height);
    419 
    420     // Sets the display text of the suggestion.
    421     void SetLabelText(const base::string16& text);
    422 
    423     // Sets the icon which should be displayed ahead of the text.
    424     void SetIcon(const gfx::Image& image);
    425 
    426     // Shows an auxiliary textfield to the right of the suggestion icon and
    427     // text. This is currently only used to show a CVC field for the CC section.
    428     void SetTextfield(const base::string16& placeholder_text,
    429                       const gfx::Image& icon);
    430 
    431     // The state of |this|.
    432     SuggestionState state_;
    433 
    434     // This caches preferred heights for given widths. The key is a preferred
    435     // width, the value is a cached result of CanUseVerticallyCompactText.
    436     std::map<int, std::pair<bool, int> > calculated_heights_;
    437 
    438     // The label that holds the suggestion description text.
    439     views::Label* label_;
    440     // The second (and greater) line of text that describes the suggestion.
    441     views::Label* label_line_2_;
    442     // The icon that comes just before |label_|.
    443     views::ImageView* icon_;
    444     // The input set by ShowTextfield.
    445     DecoratedTextfield* decorated_;
    446     // An "Edit" link that flips to editable inputs rather than suggestion text.
    447     views::Link* edit_link_;
    448 
    449     DISALLOW_COPY_AND_ASSIGN(SuggestionView);
    450   };
    451 
    452   // A convenience struct for holding pointers to views within each detail
    453   // section. None of the member pointers are owned.
    454   struct DetailsGroup {
    455     explicit DetailsGroup(DialogSection section);
    456     ~DetailsGroup();
    457 
    458     // The section this group is associated with.
    459     const DialogSection section;
    460     // The view that contains the entire section (label + input).
    461     SectionContainer* container;
    462     // The view that allows manual input.
    463     views::View* manual_input;
    464     // The textfields in |manual_input|, tracked by their DetailInput.
    465     TextfieldMap textfields;
    466     // The comboboxes in |manual_input|, tracked by their DetailInput.
    467     ComboboxMap comboboxes;
    468     // The view that holds the text of the suggested data. This will be
    469     // visible IFF |manual_input| is not visible.
    470     SuggestionView* suggested_info;
    471     // The view that allows selecting other data suggestions.
    472     SuggestedButton* suggested_button;
    473   };
    474 
    475   typedef std::map<DialogSection, DetailsGroup> DetailGroupMap;
    476 
    477   // Returns the preferred size or minimum size (if |get_minimum_size| is true).
    478   gfx::Size CalculatePreferredSize(bool get_minimum_size);
    479 
    480   // Returns the minimum size of the sign in view for this dialog.
    481   gfx::Size GetMinimumSignInViewSize() const;
    482 
    483   // Returns the maximum size of the sign in view for this dialog.
    484   gfx::Size GetMaximumSignInViewSize() const;
    485 
    486   // Returns which section should currently be used for credit card info.
    487   DialogSection GetCreditCardSection() const;
    488 
    489   void InitChildViews();
    490 
    491   // Creates and returns a view that holds all detail sections.
    492   views::View* CreateDetailsContainer();
    493 
    494   // Creates and returns a view that holds the requesting host and intro text.
    495   views::View* CreateNotificationArea();
    496 
    497   // Creates and returns a view that holds the main controls of this dialog.
    498   views::View* CreateMainContainer();
    499 
    500   // Creates a detail section (Shipping, Email, etc.) with the given label,
    501   // inputs View, and suggestion model. Relevant pointers are stored in |group|.
    502   void CreateDetailsSection(DialogSection section);
    503 
    504   // Creates the view that holds controls for inputing or selecting data for
    505   // a given section.
    506   views::View* CreateInputsContainer(DialogSection section);
    507 
    508   // Creates a grid of textfield views for the given section, and stores them
    509   // in the appropriate DetailsGroup. The top level View in the hierarchy is
    510   // returned.
    511   views::View* InitInputsView(DialogSection section);
    512 
    513   // Changes the function of the whole dialog. Currently this can show a loading
    514   // shield, an embedded sign in web view, or the more typical detail input mode
    515   // (suggestions and form inputs).
    516   void ShowDialogInMode(DialogMode dialog_mode);
    517 
    518   // Updates the given section to match the state provided by |delegate_|. If
    519   // |clobber_inputs| is true, the current state of the textfields will be
    520   // ignored, otherwise their contents will be preserved.
    521   void UpdateSectionImpl(DialogSection section, bool clobber_inputs);
    522 
    523   // Updates the visual state of the given group as per the model.
    524   void UpdateDetailsGroupState(const DetailsGroup& group);
    525 
    526   // Gets a pointer to the DetailsGroup that's associated with the given section
    527   // of the dialog.
    528   DetailsGroup* GroupForSection(DialogSection section);
    529 
    530   // Gets a pointer to the DetailsGroup that's associated with a given |view|.
    531   // Returns NULL if no DetailsGroup was found.
    532   DetailsGroup* GroupForView(views::View* view);
    533 
    534   // Explicitly focuses the initially focusable view.
    535   void FocusInitialView();
    536 
    537   // Sets the visual state for an input to be either valid or invalid. This
    538   // should work on Comboboxes or DecoratedTextfields. If |message| is empty,
    539   // the input is valid.
    540   template<class T>
    541   void SetValidityForInput(T* input, const base::string16& message);
    542 
    543   // Shows an error bubble pointing at |view| if |view| has a message in
    544   // |validity_map_|.
    545   void ShowErrorBubbleForViewIfNecessary(views::View* view);
    546 
    547   // Hides |error_bubble_| (if it exists).
    548   void HideErrorBubble();
    549 
    550   // Updates validity of the inputs in |section| with new |validity_messages|.
    551   // Fields are only updated with unsure messages if |overwrite_valid| is true.
    552   void MarkInputsInvalid(DialogSection section,
    553                          const ValidityMessages& validity_messages,
    554                          bool overwrite_invalid);
    555 
    556   // Checks all manual inputs in |group| for validity. Decorates the invalid
    557   // ones and returns true if all were valid.
    558   bool ValidateGroup(const DetailsGroup& group, ValidationType type);
    559 
    560   // Checks all manual inputs in the form for validity. Decorates the invalid
    561   // ones and returns true if all were valid.
    562   bool ValidateForm();
    563 
    564   // When an input textfield is edited (its contents change) or activated
    565   // (clicked while focused), this function will inform the delegate that it's
    566   // time to show a suggestion popup and possibly reset the validity state of
    567   // the input.
    568   void TextfieldEditedOrActivated(views::Textfield* textfield, bool was_edit);
    569 
    570   // Updates the views in the button strip.
    571   void UpdateButtonStripExtraView();
    572 
    573   // Call this when the size of anything in |contents_| might've changed.
    574   void ContentsPreferredSizeChanged();
    575   void DoContentsPreferredSizeChanged();
    576 
    577   // Gets the textfield view that is shown for the given DetailInput model, or
    578   // NULL.
    579   views::Textfield* TextfieldForInput(const DetailInput& input);
    580 
    581   // Gets the combobox view that is shown for the given DetailInput model, or
    582   // NULL.
    583   views::Combobox* ComboboxForInput(const DetailInput& input);
    584 
    585   // Called when the details container changes in size or position.
    586   void DetailsContainerBoundsChanged();
    587 
    588   // Sets the icons in |section| according to the field values. For example,
    589   // sets the credit card and CVC icons according to the credit card number.
    590   void SetIconsForSection(DialogSection section);
    591 
    592   // Iterates over all the inputs in |section| and sets their enabled/disabled
    593   // state.
    594   void SetEditabilityForSection(DialogSection section);
    595 
    596   // The delegate that drives this view. Weak pointer, always non-NULL.
    597   AutofillDialogViewDelegate* const delegate_;
    598 
    599   // The preferred size of the view, cached to avoid needless recomputation.
    600   gfx::Size preferred_size_;
    601 
    602   // The current number of unmatched calls to UpdatesStarted.
    603   int updates_scope_;
    604 
    605   // True when there's been a call to ContentsPreferredSizeChanged() suppressed
    606   // due to an unmatched UpdatesStarted.
    607   bool needs_update_;
    608 
    609   // The window that displays |contents_|. Weak pointer; may be NULL when the
    610   // dialog is closing.
    611   views::Widget* window_;
    612 
    613   // A DialogSection-keyed map of the DetailGroup structs.
    614   DetailGroupMap detail_groups_;
    615 
    616   // Somewhere to show notification messages about errors, warnings, or promos.
    617   NotificationArea* notification_area_;
    618 
    619   // Runs the suggestion menu (triggered by each section's |suggested_button|.
    620   scoped_ptr<views::MenuRunner> menu_runner_;
    621 
    622   // The view that allows the user to toggle the data source.
    623   AccountChooser* account_chooser_;
    624 
    625   // A WebView to that navigates to a Google sign-in page to allow the user to
    626   // sign-in.
    627   views::WebView* sign_in_web_view_;
    628 
    629   // View that wraps |details_container_| and makes it scroll vertically.
    630   views::ScrollView* scrollable_area_;
    631 
    632   // View to host details sections.
    633   DetailsContainerView* details_container_;
    634 
    635   // A view that overlays |this| (for "loading..." messages).
    636   views::View* loading_shield_;
    637 
    638   // The height for |loading_shield_|. This prevents the height of the dialog
    639   // from changing while the loading shield is showing.
    640   int loading_shield_height_;
    641 
    642   // The view that completely overlays the dialog (used for the splash page).
    643   OverlayView* overlay_view_;
    644 
    645   // The "Extra view" is on the same row as the dialog buttons.
    646   views::View* button_strip_extra_view_;
    647 
    648   // This checkbox controls whether new details are saved to the Autofill
    649   // database. It lives in |extra_view_|.
    650   views::Checkbox* save_in_chrome_checkbox_;
    651 
    652   // Holds the above checkbox and an associated tooltip icon.
    653   views::View* save_in_chrome_checkbox_container_;
    654 
    655   // Used to display an image in the button strip extra view.
    656   views::ImageView* button_strip_image_;
    657 
    658   // View that aren't in the hierarchy but are owned by |this|. Currently
    659   // just holds the (hidden) country comboboxes.
    660   ScopedVector<views::View> other_owned_views_;
    661 
    662   // The view that is appended to the bottom of the dialog, below the button
    663   // strip. Used to display legal document links.
    664   views::View* footnote_view_;
    665 
    666   // The legal document text and links.
    667   views::StyledLabel* legal_document_view_;
    668 
    669   // The focus manager for |window_|.
    670   views::FocusManager* focus_manager_;
    671 
    672   // The object that manages the error bubble widget.
    673   InfoBubble* error_bubble_;  // Weak; owns itself.
    674 
    675   // Map from input view (textfield or combobox) to error string.
    676   std::map<views::View*, base::string16> validity_map_;
    677 
    678   ScopedObserver<views::Widget, AutofillDialogViews> observer_;
    679 
    680   // Delegate for the sign-in dialog's webview.
    681   scoped_ptr<AutofillDialogSignInDelegate> sign_in_delegate_;
    682 
    683   DISALLOW_COPY_AND_ASSIGN(AutofillDialogViews);
    684 };
    685 
    686 }  // namespace autofill
    687 
    688 #endif  // CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_DIALOG_VIEWS_H_
    689