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