blob: 7afc8f5ac6c53d0853afa584211afa22e42dd131 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// 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
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00008#include <map>
9
Ben Murdoch558790d2013-07-30 15:19:42 +010010#include "base/memory/scoped_vector.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000011#include "base/memory/weak_ptr.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010012#include "base/scoped_observer.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000013#include "chrome/browser/ui/autofill/autofill_dialog_view.h"
Ben Murdoch32409262013-08-07 11:04:47 +010014#include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010015#include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h"
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010016#include "ui/base/animation/animation_delegate.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000017#include "ui/views/controls/button/button.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000018#include "ui/views/controls/button/menu_button_listener.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000019#include "ui/views/controls/combobox/combobox_listener.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000020#include "ui/views/controls/link_listener.h"
21#include "ui/views/controls/progress_bar.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010022#include "ui/views/controls/scroll_view.h"
23#include "ui/views/controls/styled_label_listener.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000024#include "ui/views/controls/textfield/textfield_controller.h"
25#include "ui/views/focus/focus_manager.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010026#include "ui/views/widget/widget_observer.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000027#include "ui/views/window/dialog_delegate.h"
28
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000029namespace content {
30class KeyboardListener;
31}
32
33namespace gfx {
34class Image;
35}
Torne (Richard Coles)58218062012-11-14 11:43:16 +000036
37namespace views {
Ben Murdoch58e6fbe2013-07-26 10:20:38 +010038class BubbleBorder;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000039class Checkbox;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000040class Combobox;
41class FocusManager;
42class ImageButton;
43class ImageView;
44class Label;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010045class LabelButton;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000046class Link;
47class MenuRunner;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010048class StyledLabel;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000049class WebView;
50class Widget;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010051} // namespace views
Torne (Richard Coles)58218062012-11-14 11:43:16 +000052
53namespace ui {
54class ComboboxModel;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000055class KeyEvent;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010056class MultiAnimation;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000057}
58
59namespace autofill {
60
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010061class AutofillDialogSignInDelegate;
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +010062class DecoratedTextfield;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000063struct DetailInput;
64
65// Views toolkit implementation of the Autofill dialog that handles the
66// imperative autocomplete API call.
67class AutofillDialogViews : public AutofillDialogView,
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010068 public TestableAutofillDialogView,
Ben Murdocheb525c52013-07-10 11:40:50 +010069 public views::DialogDelegateView,
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010070 public views::WidgetObserver,
Torne (Richard Coles)58218062012-11-14 11:43:16 +000071 public views::ButtonListener,
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000072 public views::TextfieldController,
73 public views::FocusChangeListener,
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010074 public views::ComboboxListener,
Ben Murdocheb525c52013-07-10 11:40:50 +010075 public views::StyledLabelListener {
Torne (Richard Coles)58218062012-11-14 11:43:16 +000076 public:
Ben Murdoch32409262013-08-07 11:04:47 +010077 explicit AutofillDialogViews(AutofillDialogViewDelegate* delegate);
Torne (Richard Coles)58218062012-11-14 11:43:16 +000078 virtual ~AutofillDialogViews();
79
80 // AutofillDialogView implementation:
81 virtual void Show() OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000082 virtual void Hide() OVERRIDE;
83 virtual void UpdateAccountChooser() OVERRIDE;
Ben Murdocheb525c52013-07-10 11:40:50 +010084 virtual void UpdateAutocheckoutStepsArea() OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000085 virtual void UpdateButtonStrip() OVERRIDE;
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +010086 virtual void UpdateDetailArea() OVERRIDE;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010087 virtual void UpdateForErrors() OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000088 virtual void UpdateNotificationArea() OVERRIDE;
89 virtual void UpdateSection(DialogSection section) OVERRIDE;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010090 virtual void FillSection(DialogSection section,
91 const DetailInput& originating_input) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +000092 virtual void GetUserInput(DialogSection section,
93 DetailOutputMap* output) OVERRIDE;
Ben Murdoch558790d2013-07-30 15:19:42 +010094 virtual base::string16 GetCvc() OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000095 virtual bool SaveDetailsLocally() OVERRIDE;
96 virtual const content::NavigationController* ShowSignIn() OVERRIDE;
97 virtual void HideSignIn() OVERRIDE;
98 virtual void UpdateProgressBar(double value) OVERRIDE;
99 virtual void ModelChanged() OVERRIDE;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100100 virtual TestableAutofillDialogView* GetTestableView() OVERRIDE;
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100101 virtual void OnSignInResize(const gfx::Size& pref_size) OVERRIDE;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100102
103 // TestableAutofillDialogView implementation:
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000104 virtual void SubmitForTesting() OVERRIDE;
105 virtual void CancelForTesting() OVERRIDE;
Ben Murdoch558790d2013-07-30 15:19:42 +0100106 virtual base::string16 GetTextContentsOfInput(
107 const DetailInput& input) OVERRIDE;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100108 virtual void SetTextContentsOfInput(const DetailInput& input,
Ben Murdoch558790d2013-07-30 15:19:42 +0100109 const base::string16& contents) OVERRIDE;
Ben Murdocheb525c52013-07-10 11:40:50 +0100110 virtual void SetTextContentsOfSuggestionInput(
111 DialogSection section,
112 const base::string16& text) OVERRIDE;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100113 virtual void ActivateInput(const DetailInput& input) OVERRIDE;
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100114 virtual gfx::Size GetSize() const OVERRIDE;
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100115
Ben Murdocheb525c52013-07-10 11:40:50 +0100116 // views::View implementation.
117 virtual gfx::Size GetPreferredSize() OVERRIDE;
118 virtual void Layout() OVERRIDE;
119 virtual void OnBoundsChanged(const gfx::Rect& previous_bounds) OVERRIDE;
120
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000121 // views::DialogDelegate implementation:
Ben Murdoch558790d2013-07-30 15:19:42 +0100122 virtual base::string16 GetWindowTitle() const OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000123 virtual void WindowClosing() OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000124 virtual void DeleteDelegate() OVERRIDE;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100125 virtual views::View* CreateOverlayView() OVERRIDE;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100126 virtual int GetDialogButtons() const OVERRIDE;
Ben Murdoch558790d2013-07-30 15:19:42 +0100127 virtual base::string16 GetDialogButtonLabel(ui::DialogButton button) const
128 OVERRIDE;
Ben Murdochca12bfa2013-07-23 11:17:05 +0100129 virtual bool ShouldDefaultButtonBeBlue() const OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000130 virtual bool IsDialogButtonEnabled(ui::DialogButton button) const OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000131 virtual views::View* CreateExtraView() OVERRIDE;
132 virtual views::View* CreateTitlebarExtraView() OVERRIDE;
133 virtual views::View* CreateFootnoteView() OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000134 virtual bool Cancel() OVERRIDE;
135 virtual bool Accept() OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000136 virtual views::NonClientFrameView* CreateNonClientFrameView(
137 views::Widget* widget) OVERRIDE;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000138
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100139 // views::WidgetObserver implementation:
140 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE;
141 virtual void OnWidgetBoundsChanged(views::Widget* widget,
142 const gfx::Rect& new_bounds) OVERRIDE;
143
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000144 // views::ButtonListener implementation:
145 virtual void ButtonPressed(views::Button* sender,
146 const ui::Event& event) OVERRIDE;
147
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000148 // views::TextfieldController implementation:
149 virtual void ContentsChanged(views::Textfield* sender,
Ben Murdoch558790d2013-07-30 15:19:42 +0100150 const base::string16& new_contents) OVERRIDE;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000151 virtual bool HandleKeyEvent(views::Textfield* sender,
152 const ui::KeyEvent& key_event) OVERRIDE;
153 virtual bool HandleMouseEvent(views::Textfield* sender,
154 const ui::MouseEvent& key_event) OVERRIDE;
155
156 // views::FocusChangeListener implementation.
157 virtual void OnWillChangeFocus(views::View* focused_before,
158 views::View* focused_now) OVERRIDE;
159 virtual void OnDidChangeFocus(views::View* focused_before,
160 views::View* focused_now) OVERRIDE;
161
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000162 // views::ComboboxListener implementation:
163 virtual void OnSelectedIndexChanged(views::Combobox* combobox) OVERRIDE;
164
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100165 // views::StyledLabelListener implementation:
166 virtual void StyledLabelLinkClicked(const ui::Range& range, int event_flags)
167 OVERRIDE;
168
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000169 private:
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100170 // A class that creates and manages a widget for error messages.
171 class ErrorBubble : public views::WidgetObserver {
172 public:
Ben Murdoch558790d2013-07-30 15:19:42 +0100173 ErrorBubble(views::View* anchor, const base::string16& message);
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100174 virtual ~ErrorBubble();
175
176 bool IsShowing();
177
Torne (Richard Coles)a93a17c2013-05-15 11:34:50 +0100178 // Re-positions the bubble over |anchor_|. If |anchor_| is not visible,
179 // the bubble will hide.
180 void UpdatePosition();
181
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100182 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE;
183
184 views::View* anchor() { return anchor_; }
185
186 private:
Torne (Richard Coles)a93a17c2013-05-15 11:34:50 +0100187 // Calculates and returns the bounds of |widget_|, depending on |anchor_|
188 // and |contents_|.
189 gfx::Rect GetBoundsForWidget();
190
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100191 views::Widget* widget_; // Weak, may be NULL.
192 views::View* anchor_; // Weak.
Torne (Richard Coles)a93a17c2013-05-15 11:34:50 +0100193 // The contents view of |widget_|.
194 views::View* contents_; // Weak.
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100195 ScopedObserver<views::Widget, ErrorBubble> observer_;
196
197 DISALLOW_COPY_AND_ASSIGN(ErrorBubble);
198 };
199
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000200 // A View which displays the currently selected account and lets the user
201 // switch accounts.
202 class AccountChooser : public views::View,
203 public views::LinkListener,
204 public base::SupportsWeakPtr<AccountChooser> {
205 public:
Ben Murdoch32409262013-08-07 11:04:47 +0100206 explicit AccountChooser(AutofillDialogViewDelegate* delegate);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000207 virtual ~AccountChooser();
208
Ben Murdoch32409262013-08-07 11:04:47 +0100209 // Updates the view based on the state that |delegate_| reports.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000210 void Update();
211
212 // views::View implementation.
213 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
214 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
215
216 // views::LinkListener implementation.
217 virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
218
219 private:
220 // The icon for the currently in-use account.
221 views::ImageView* image_;
222
223 // The label for the currently in-use account.
224 views::Label* label_;
225
226 // The drop arrow.
227 views::ImageView* arrow_;
228
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100229 // The sign in link.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000230 views::Link* link_;
231
Ben Murdoch32409262013-08-07 11:04:47 +0100232 // The delegate |this| queries for logic and state.
233 AutofillDialogViewDelegate* delegate_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000234
235 // Runs the suggestion menu (triggered by each section's |suggested_button|.
236 scoped_ptr<views::MenuRunner> menu_runner_;
237
238 DISALLOW_COPY_AND_ASSIGN(AccountChooser);
239 };
240
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100241 // A view which displays an image, optionally some messages and a button. Used
242 // for the splash page as well as the Wallet interstitial.
243 class OverlayView : public views::View,
244 public ui::AnimationDelegate {
245 public:
246 // The listener is informed when |button_| is pressed.
247 explicit OverlayView(views::ButtonListener* listener);
248 virtual ~OverlayView();
249
Ben Murdoch558790d2013-07-30 15:19:42 +0100250 // Returns a height which should be used when the contents view has width
251 // |w|. Note that the value returned should be used as the height of the
252 // dialog's contents.
253 int GetHeightForContentsForWidth(int w);
254
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100255 // Sets properties that should be displayed.
256 void SetState(const DialogOverlayState& state,
257 views::ButtonListener* listener);
258
259 // Fades the view out after a delay.
260 void BeginFadeOut();
261
262 // ui::AnimationDelegate implementation:
263 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
264 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE;
265
266 // views::View implementation:
Ben Murdoch58e6fbe2013-07-26 10:20:38 +0100267 virtual gfx::Insets GetInsets() const OVERRIDE;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100268 virtual void Layout() OVERRIDE;
269 virtual const char* GetClassName() const OVERRIDE;
270 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
271 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE;
272
273 private:
Ben Murdoch58e6fbe2013-07-26 10:20:38 +0100274 // Gets the border of the non-client frame view as a BubbleBorder.
275 views::BubbleBorder* GetBubbleBorder();
276
277 // Gets the bounds of this view without the frame view's bubble border.
278 gfx::Rect ContentBoundsSansBubbleBorder();
279
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100280 // Child View. Front and center.
281 views::ImageView* image_view_;
282 // Child View. When visible, below |image_view_|.
283 views::View* message_stack_;
284 // Child View. When visible, below |message_stack_|.
285 views::LabelButton* button_;
286
287 // This MultiAnimation is used to first fade out the contents of the
288 // overlay, then fade out the background of the overlay (revealing the
289 // dialog behind the overlay). This avoids cross-fade.
290 scoped_ptr<ui::MultiAnimation> fade_out_;
291
292 DISALLOW_COPY_AND_ASSIGN(OverlayView);
293 };
294
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000295 // An area for notifications. Some notifications point at the account chooser.
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100296 class NotificationArea : public views::View,
297 public views::ButtonListener {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000298 public:
Ben Murdoch32409262013-08-07 11:04:47 +0100299 explicit NotificationArea(AutofillDialogViewDelegate* delegate);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000300 virtual ~NotificationArea();
301
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100302 // Displays the given notifications.
303 void SetNotifications(const std::vector<DialogNotification>& notifications);
304
305 // views::View implementation.
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100306 virtual gfx::Size GetPreferredSize() OVERRIDE;
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +0100307 virtual const char* GetClassName() const OVERRIDE;
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100308 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100309 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
310
311 // views::ButtonListener implementation:
312 virtual void ButtonPressed(views::Button* sender,
313 const ui::Event& event) OVERRIDE;
314
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000315 void set_arrow_centering_anchor(
316 const base::WeakPtr<views::View>& arrow_centering_anchor) {
317 arrow_centering_anchor_ = arrow_centering_anchor;
318 }
319
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000320 private:
321 // Utility function for determining whether an arrow should be drawn
322 // pointing at |arrow_centering_anchor_|.
323 bool HasArrow();
324
Ben Murdoch32409262013-08-07 11:04:47 +0100325 // A reference to the delegate/controller than owns this view.
326 // Used to report when checkboxes change their values.
327 AutofillDialogViewDelegate* delegate_; // weak
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100328
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000329 // The currently showing checkbox, or NULL if none exists.
330 views::Checkbox* checkbox_; // weak
331
332 // If HasArrow() is true, the arrow should point at this.
333 base::WeakPtr<views::View> arrow_centering_anchor_;
334
335 std::vector<DialogNotification> notifications_;
336
337 DISALLOW_COPY_AND_ASSIGN(NotificationArea);
338 };
339
340 typedef std::map<const DetailInput*, DecoratedTextfield*> TextfieldMap;
341 typedef std::map<const DetailInput*, views::Combobox*> ComboboxMap;
342
343 // A view that packs a label on the left and some related controls
344 // on the right.
345 class SectionContainer : public views::View {
346 public:
Ben Murdoch558790d2013-07-30 15:19:42 +0100347 SectionContainer(const base::string16& label,
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000348 views::View* controls,
349 views::Button* proxy_button);
350 virtual ~SectionContainer();
351
352 // Sets the visual appearance of the section to active (considered active
353 // when showing the menu or hovered by the mouse cursor).
354 void SetActive(bool active);
355
356 // Sets whether mouse events should be forwarded to |proxy_button_|.
357 void SetForwardMouseEvents(bool forward);
358
359 // views::View implementation.
360 virtual void OnMouseMoved(const ui::MouseEvent& event) OVERRIDE;
361 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
362 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
363 virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
364 virtual void OnMouseReleased(const ui::MouseEvent& event) OVERRIDE;
365
366 private:
367 // Converts |event| to one suitable for |proxy_button_|.
368 static ui::MouseEvent ProxyEvent(const ui::MouseEvent& event);
369
370 // Mouse events on |this| are sent to this button.
371 views::Button* proxy_button_; // Weak reference.
372
373 // When true, mouse events will be forwarded to |proxy_button_|.
374 bool forward_mouse_events_;
375
376 DISALLOW_COPY_AND_ASSIGN(SectionContainer);
377 };
378
379 // A view that contains a suggestion (such as a known address) and a link to
380 // edit the suggestion.
381 class SuggestionView : public views::View {
382 public:
Ben Murdoch558790d2013-07-30 15:19:42 +0100383 SuggestionView(const base::string16& edit_label,
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000384 AutofillDialogViews* autofill_dialog);
385 virtual ~SuggestionView();
386
387 // Sets the display text of the suggestion.
Ben Murdoch558790d2013-07-30 15:19:42 +0100388 void SetSuggestionText(const base::string16& text,
389 gfx::Font::FontStyle style);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000390
391 // Sets the icon which should be displayed ahead of the text.
392 void SetSuggestionIcon(const gfx::Image& image);
393
394 // Shows an auxiliary textfield to the right of the suggestion icon and
395 // text. This is currently only used to show a CVC field for the CC section.
Ben Murdoch558790d2013-07-30 15:19:42 +0100396 void ShowTextfield(const base::string16& placeholder_text,
Ben Murdocheb525c52013-07-10 11:40:50 +0100397 const gfx::Image& icon);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000398
399 DecoratedTextfield* decorated_textfield() { return decorated_; }
400
401 private:
402 // The label that holds the suggestion description text.
403 views::Label* label_;
404 // The second (and greater) line of text that describes the suggestion.
405 views::Label* label_line_2_;
406 // The icon that comes just before |label_|.
407 views::ImageView* icon_;
408 // A view to contain |label_| and |icon_|.
409 views::View* label_container_;
410 // The input set by ShowTextfield.
411 DecoratedTextfield* decorated_;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100412 // An "Edit" link that flips to editable inputs rather than suggestion text.
413 views::Link* edit_link_;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000414
415 DISALLOW_COPY_AND_ASSIGN(SuggestionView);
416 };
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000417
418 // A convenience struct for holding pointers to views within each detail
419 // section. None of the member pointers are owned.
420 struct DetailsGroup {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000421 explicit DetailsGroup(DialogSection section);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000422 ~DetailsGroup();
423
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000424 // The section this group is associated with.
425 const DialogSection section;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000426 // The view that contains the entire section (label + input).
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000427 SectionContainer* container;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000428 // The view that allows manual input.
429 views::View* manual_input;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000430 // The textfields in |manual_input|, tracked by their DetailInput.
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000431 TextfieldMap textfields;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000432 // The comboboxes in |manual_input|, tracked by their DetailInput.
433 ComboboxMap comboboxes;
434 // The view that holds the text of the suggested data. This will be
435 // visible IFF |manual_input| is not visible.
436 SuggestionView* suggested_info;
437 // The view that allows selecting other data suggestions.
438 views::ImageButton* suggested_button;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000439 };
440
Ben Murdocheb525c52013-07-10 11:40:50 +0100441 // Area for displaying that status of various steps in an Autocheckout flow.
442 class AutocheckoutStepsArea : public views::View {
443 public:
444 AutocheckoutStepsArea();
445 virtual ~AutocheckoutStepsArea() {}
446
447 // Display the given steps.
448 void SetSteps(const std::vector<DialogAutocheckoutStep>& steps);
449
450 private:
451 DISALLOW_COPY_AND_ASSIGN(AutocheckoutStepsArea);
452 };
453
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000454 class AutocheckoutProgressBar : public views::ProgressBar {
455 public:
456 AutocheckoutProgressBar();
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +0100457 virtual ~AutocheckoutProgressBar();
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000458
459 private:
Ben Murdocheb525c52013-07-10 11:40:50 +0100460 // Overriden from View
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000461 virtual gfx::Size GetPreferredSize() OVERRIDE;
462
463 DISALLOW_COPY_AND_ASSIGN(AutocheckoutProgressBar);
464 };
465
466 typedef std::map<DialogSection, DetailsGroup> DetailGroupMap;
467
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000468 void InitChildViews();
469
470 // Creates and returns a view that holds all detail sections.
471 views::View* CreateDetailsContainer();
472
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000473 // Creates and returns a view that holds the requesting host and intro text.
474 views::View* CreateNotificationArea();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000475
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000476 // Creates and returns a view that holds the main controls of this dialog.
477 views::View* CreateMainContainer();
478
479 // Creates a detail section (Shipping, Email, etc.) with the given label,
480 // inputs View, and suggestion model. Relevant pointers are stored in |group|.
481 void CreateDetailsSection(DialogSection section);
482
483 // Like CreateDetailsSection, but creates the combined billing/cc section,
484 // which is somewhat more complicated than the others.
485 void CreateBillingSection();
486
487 // Creates the view that holds controls for inputing or selecting data for
488 // a given section.
489 views::View* CreateInputsContainer(DialogSection section);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000490
491 // Creates a grid of textfield views for the given section, and stores them
492 // in the appropriate DetailsGroup. The top level View in the hierarchy is
493 // returned.
494 views::View* InitInputsView(DialogSection section);
495
Ben Murdoch32409262013-08-07 11:04:47 +0100496 // Updates the given section to match the state provided by |delegate_|. If
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100497 // |clobber_inputs| is true, the current state of the textfields will be
498 // ignored, otherwise their contents will be preserved.
499 void UpdateSectionImpl(DialogSection section, bool clobber_inputs);
500
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000501 // Updates the visual state of the given group as per the model.
502 void UpdateDetailsGroupState(const DetailsGroup& group);
503
504 // Gets a pointer to the DetailsGroup that's associated with the given section
505 // of the dialog.
506 DetailsGroup* GroupForSection(DialogSection section);
507
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100508 // Gets a pointer to the DetailsGroup that's associated with a given |view|.
509 // Returns NULL if no DetailsGroup was found.
510 DetailsGroup* GroupForView(views::View* view);
511
512 // Sets the visual state for an input to be either valid or invalid. This
513 // should work on Comboboxes or DecoratedTextfields. If |message| is empty,
514 // the input is valid.
515 template<class T>
Ben Murdoch558790d2013-07-30 15:19:42 +0100516 void SetValidityForInput(T* input, const base::string16& message);
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100517
Torne (Richard Coles)a93a17c2013-05-15 11:34:50 +0100518 // Shows an error bubble pointing at |view| if |view| has a message in
519 // |validity_map_|.
520 void ShowErrorBubbleForViewIfNecessary(views::View* view);
521
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100522 // Updates validity of the inputs in |section| with the new validity data.
523 void MarkInputsInvalid(DialogSection section,
524 const ValidityData& validity_data);
525
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000526 // Checks all manual inputs in |group| for validity. Decorates the invalid
527 // ones and returns true if all were valid.
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100528 bool ValidateGroup(const DetailsGroup& group, ValidationType type);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000529
530 // Checks all manual inputs in the form for validity. Decorates the invalid
531 // ones and returns true if all were valid.
532 bool ValidateForm();
533
534 // When an input textfield is edited (its contents change) or activated
Ben Murdoch32409262013-08-07 11:04:47 +0100535 // (clicked while focused), this function will inform the delegate that it's
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000536 // time to show a suggestion popup and possibly reset the validity state of
537 // the input.
538 void TextfieldEditedOrActivated(views::Textfield* textfield, bool was_edit);
539
Ben Murdoch2385ea32013-08-06 11:01:04 +0100540 // Updates the views in the button strip.
541 void UpdateButtonStripExtraView();
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +0100542
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000543 // Call this when the size of anything in |contents_| might've changed.
544 void ContentsPreferredSizeChanged();
545
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100546 // Gets the textfield view that is shown for the given DetailInput model, or
547 // NULL.
548 views::Textfield* TextfieldForInput(const DetailInput& input);
549
550 // Gets the combobox view that is shown for the given DetailInput model, or
551 // NULL.
552 views::Combobox* ComboboxForInput(const DetailInput& input);
553
Torne (Richard Coles)a93a17c2013-05-15 11:34:50 +0100554 // Called when the details container changes in size or position.
555 void DetailsContainerBoundsChanged();
556
Ben Murdoch32409262013-08-07 11:04:47 +0100557 // The delegate that drives this view. Weak pointer, always non-NULL.
558 AutofillDialogViewDelegate* const delegate_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000559
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000560 // The window that displays |contents_|. Weak pointer; may be NULL when the
561 // dialog is closing.
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000562 views::Widget* window_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000563
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000564 // A DialogSection-keyed map of the DetailGroup structs.
565 DetailGroupMap detail_groups_;
566
567 // Somewhere to show notification messages about errors, warnings, or promos.
568 NotificationArea* notification_area_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000569
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000570 // Runs the suggestion menu (triggered by each section's |suggested_button|.
571 scoped_ptr<views::MenuRunner> menu_runner_;
572
573 // The view that allows the user to toggle the data source.
574 AccountChooser* account_chooser_;
575
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000576 // A WebView to that navigates to a Google sign-in page to allow the user to
577 // sign-in.
578 views::WebView* sign_in_webview_;
579
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100580 // View that wraps |details_container_| and makes it scroll vertically.
Ben Murdocheb525c52013-07-10 11:40:50 +0100581 views::ScrollView* scrollable_area_;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100582
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000583 // View to host details sections.
584 views::View* details_container_;
585
Ben Murdocheb525c52013-07-10 11:40:50 +0100586 // A view that overlays |this| (for "loading..." messages).
587 views::Label* loading_shield_;
588
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100589 // The view that completely overlays the dialog (used for the splash page).
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100590 OverlayView* overlay_view_;
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100591
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000592 // The "Extra view" is on the same row as the dialog buttons.
593 views::View* button_strip_extra_view_;
594
595 // This checkbox controls whether new details are saved to the Autofill
596 // database. It lives in |extra_view_|.
597 views::Checkbox* save_in_chrome_checkbox_;
598
Ben Murdochbb1529c2013-08-08 10:24:53 +0100599 // Holds the above checkbox and an associated tooltip icon.
600 views::View* save_in_chrome_checkbox_container_;
601
Ben Murdoch2385ea32013-08-06 11:01:04 +0100602 // Used to display an image in the button strip extra view.
603 views::ImageView* button_strip_image_;
604
Ben Murdoch558790d2013-07-30 15:19:42 +0100605 // View that aren't in the hierarchy but are owned by |this|. Currently
606 // just holds the (hidden) country comboboxes.
607 ScopedVector<views::View> other_owned_views_;
608
Ben Murdocheb525c52013-07-10 11:40:50 +0100609 // View to host Autocheckout steps.
610 AutocheckoutStepsArea* autocheckout_steps_area_;
611
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000612 // View to host |autocheckout_progress_bar_| and its label.
613 views::View* autocheckout_progress_bar_view_;
614
615 // Progress bar for displaying Autocheckout progress.
616 AutocheckoutProgressBar* autocheckout_progress_bar_;
617
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100618 // The view that is appended to the bottom of the dialog, below the button
619 // strip. Used to display legal document links.
620 views::View* footnote_view_;
621
622 // The legal document text and links.
623 views::StyledLabel* legal_document_view_;
624
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000625 // The focus manager for |window_|.
626 views::FocusManager* focus_manager_;
627
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100628 // The object that manages the error bubble widget.
629 scoped_ptr<ErrorBubble> error_bubble_;
630
631 // Map from input view (textfield or combobox) to error string.
Ben Murdoch558790d2013-07-30 15:19:42 +0100632 std::map<views::View*, base::string16> validity_map_;
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100633
634 ScopedObserver<views::Widget, AutofillDialogViews> observer_;
635
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100636 // Delegate for the sign-in dialog's webview.
637 scoped_ptr<AutofillDialogSignInDelegate> sign_in_delegate_;
638
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000639 DISALLOW_COPY_AND_ASSIGN(AutofillDialogViews);
640};
641
642} // namespace autofill
643
644#endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_DIALOG_VIEWS_H_