OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_DIALOG_VIEWS_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_DIALOG_VIEWS_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_DIALOG_VIEWS_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_DIALOG_VIEWS_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <set> | 9 #include <set> |
10 | 10 |
11 #include "base/memory/scoped_vector.h" | 11 #include "base/memory/scoped_vector.h" |
12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
13 #include "base/scoped_observer.h" | 13 #include "base/scoped_observer.h" |
14 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" | 14 #include "chrome/browser/ui/autofill/autofill_dialog_types.h" |
15 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" | 15 #include "chrome/browser/ui/autofill/autofill_dialog_view.h" |
16 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h" | 16 #include "chrome/browser/ui/autofill/autofill_dialog_view_delegate.h" |
17 #include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h" | 17 #include "chrome/browser/ui/autofill/testable_autofill_dialog_view.h" |
| 18 #include "chrome/browser/ui/views/autofill/learn_more_icon.h" |
18 #include "ui/views/bubble/bubble_delegate.h" | 19 #include "ui/views/bubble/bubble_delegate.h" |
19 #include "ui/views/controls/button/button.h" | 20 #include "ui/views/controls/button/button.h" |
20 #include "ui/views/controls/button/menu_button.h" | 21 #include "ui/views/controls/button/menu_button.h" |
21 #include "ui/views/controls/button/menu_button_listener.h" | 22 #include "ui/views/controls/button/menu_button_listener.h" |
22 #include "ui/views/controls/combobox/combobox_listener.h" | 23 #include "ui/views/controls/combobox/combobox_listener.h" |
23 #include "ui/views/controls/link_listener.h" | 24 #include "ui/views/controls/link_listener.h" |
24 #include "ui/views/controls/progress_bar.h" | 25 #include "ui/views/controls/progress_bar.h" |
25 #include "ui/views/controls/scroll_view.h" | 26 #include "ui/views/controls/scroll_view.h" |
26 #include "ui/views/controls/styled_label_listener.h" | 27 #include "ui/views/controls/styled_label_listener.h" |
27 #include "ui/views/controls/textfield/textfield_controller.h" | 28 #include "ui/views/controls/textfield/textfield_controller.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 // Views toolkit implementation of the Autofill dialog that handles the | 62 // Views toolkit implementation of the Autofill dialog that handles the |
62 // imperative autocomplete API call. | 63 // imperative autocomplete API call. |
63 class AutofillDialogViews : public AutofillDialogView, | 64 class AutofillDialogViews : public AutofillDialogView, |
64 public TestableAutofillDialogView, | 65 public TestableAutofillDialogView, |
65 public views::DialogDelegateView, | 66 public views::DialogDelegateView, |
66 public views::WidgetObserver, | 67 public views::WidgetObserver, |
67 public views::TextfieldController, | 68 public views::TextfieldController, |
68 public views::FocusChangeListener, | 69 public views::FocusChangeListener, |
69 public views::ComboboxListener, | 70 public views::ComboboxListener, |
70 public views::StyledLabelListener, | 71 public views::StyledLabelListener, |
71 public views::MenuButtonListener { | 72 public views::MenuButtonListener, |
| 73 public LearnMoreIconDelegate { |
72 public: | 74 public: |
73 explicit AutofillDialogViews(AutofillDialogViewDelegate* delegate); | 75 explicit AutofillDialogViews(AutofillDialogViewDelegate* delegate); |
74 virtual ~AutofillDialogViews(); | 76 virtual ~AutofillDialogViews(); |
75 | 77 |
76 // AutofillDialogView implementation: | 78 // AutofillDialogView implementation: |
77 virtual void Show() OVERRIDE; | 79 virtual void Show() OVERRIDE; |
78 virtual void Hide() OVERRIDE; | 80 virtual void Hide() OVERRIDE; |
79 virtual void UpdatesStarted() OVERRIDE; | 81 virtual void UpdatesStarted() OVERRIDE; |
80 virtual void UpdatesFinished() OVERRIDE; | 82 virtual void UpdatesFinished() OVERRIDE; |
81 virtual void UpdateAccountChooser() OVERRIDE; | 83 virtual void UpdateAccountChooser() OVERRIDE; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 virtual void OnSelectedIndexChanged(views::Combobox* combobox) OVERRIDE; | 165 virtual void OnSelectedIndexChanged(views::Combobox* combobox) OVERRIDE; |
164 | 166 |
165 // views::StyledLabelListener implementation: | 167 // views::StyledLabelListener implementation: |
166 virtual void StyledLabelLinkClicked(const gfx::Range& range, int event_flags) | 168 virtual void StyledLabelLinkClicked(const gfx::Range& range, int event_flags) |
167 OVERRIDE; | 169 OVERRIDE; |
168 | 170 |
169 // views::MenuButtonListener implementation. | 171 // views::MenuButtonListener implementation. |
170 virtual void OnMenuButtonClicked(views::View* source, | 172 virtual void OnMenuButtonClicked(views::View* source, |
171 const gfx::Point& point) OVERRIDE; | 173 const gfx::Point& point) OVERRIDE; |
172 | 174 |
| 175 // LearnMoreIconDelegate implementation. |
| 176 virtual void OnLearnMoreIconMouseEntered(LearnMoreIcon* icon) OVERRIDE; |
| 177 virtual void OnLearnMoreIconMouseExited(LearnMoreIcon* icon) OVERRIDE; |
| 178 |
173 protected: | 179 protected: |
174 // Exposed for testing. | 180 // Exposed for testing. |
175 views::View* GetLoadingShieldForTesting(); | 181 views::View* GetLoadingShieldForTesting(); |
176 views::WebView* GetSignInWebViewForTesting(); | 182 views::WebView* GetSignInWebViewForTesting(); |
177 views::View* GetNotificationAreaForTesting(); | 183 views::View* GetNotificationAreaForTesting(); |
178 views::View* GetScrollableAreaForTesting(); | 184 views::View* GetScrollableAreaForTesting(); |
179 | 185 |
180 private: | 186 private: |
181 // What the entire dialog should be doing (e.g. gathering info from the user, | 187 // What the entire dialog should be doing (e.g. gathering info from the user, |
182 // asking the user to sign in, etc.). | 188 // asking the user to sign in, etc.). |
183 enum DialogMode { | 189 enum DialogMode { |
184 DETAIL_INPUT, | 190 DETAIL_INPUT, |
185 LOADING, | 191 LOADING, |
186 SIGN_IN, | 192 SIGN_IN, |
187 }; | 193 }; |
188 | 194 |
189 // A class that creates and manages a widget for error messages. | 195 // A class that creates and manages a widget for error messages. |
190 class ErrorBubble : public views::BubbleDelegateView { | 196 class InfoBubble : public views::BubbleDelegateView { |
191 public: | 197 public: |
192 ErrorBubble(views::View* anchor, | 198 InfoBubble(views::View* anchor, |
193 views::View* anchor_container, | 199 const base::string16& message, |
194 const base::string16& message); | 200 bool snap_to_grid); |
195 virtual ~ErrorBubble(); | 201 virtual ~InfoBubble(); |
196 | 202 |
197 // Updates the position of the bubble. | 203 // Updates the position of the bubble. |
198 void UpdatePosition(); | 204 void UpdatePosition(); |
199 | 205 |
200 // Hides and closes the bubble. | 206 // Hides and closes the bubble. |
201 void Hide(); | 207 void Hide(); |
202 | 208 |
203 // views::BubbleDelegateView: | 209 // views::BubbleDelegateView: |
204 virtual gfx::Size GetPreferredSize() OVERRIDE; | 210 virtual gfx::Size GetPreferredSize() OVERRIDE; |
205 virtual gfx::Rect GetBubbleBounds() OVERRIDE; | 211 virtual gfx::Rect GetBubbleBounds() OVERRIDE; |
(...skipping 14 matching lines...) Expand all Loading... |
220 | 226 |
221 views::Widget* widget_; // Weak, may be NULL. | 227 views::Widget* widget_; // Weak, may be NULL. |
222 views::View* const anchor_; // Weak. | 228 views::View* const anchor_; // Weak. |
223 | 229 |
224 // Used to determine the width of the bubble and whether to stick to the | 230 // Used to determine the width of the bubble and whether to stick to the |
225 // right edge of |anchor_|. Must contain |anchor_|. | 231 // right edge of |anchor_|. Must contain |anchor_|. |
226 views::View* const anchor_container_; // Weak. | 232 views::View* const anchor_container_; // Weak. |
227 | 233 |
228 // Whether the bubble should be shown above the anchor (default is below). | 234 // Whether the bubble should be shown above the anchor (default is below). |
229 const bool show_above_anchor_; | 235 const bool show_above_anchor_; |
| 236 const bool snap_to_grid_; |
230 | 237 |
231 DISALLOW_COPY_AND_ASSIGN(ErrorBubble); | 238 DISALLOW_COPY_AND_ASSIGN(InfoBubble); |
232 }; | 239 }; |
233 | 240 |
234 // A View which displays the currently selected account and lets the user | 241 // A View which displays the currently selected account and lets the user |
235 // switch accounts. | 242 // switch accounts. |
236 class AccountChooser : public views::View, | 243 class AccountChooser : public views::View, |
237 public views::LinkListener, | 244 public views::LinkListener, |
238 public views::MenuButtonListener, | 245 public views::MenuButtonListener, |
239 public base::SupportsWeakPtr<AccountChooser> { | 246 public base::SupportsWeakPtr<AccountChooser> { |
240 public: | 247 public: |
241 explicit AccountChooser(AutofillDialogViewDelegate* delegate); | 248 explicit AccountChooser(AutofillDialogViewDelegate* delegate); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 views::ImageView* image_view_; | 312 views::ImageView* image_view_; |
306 // Child View. When visible, below |image_view_|. | 313 // Child View. When visible, below |image_view_|. |
307 views::Label* message_view_; | 314 views::Label* message_view_; |
308 | 315 |
309 DISALLOW_COPY_AND_ASSIGN(OverlayView); | 316 DISALLOW_COPY_AND_ASSIGN(OverlayView); |
310 }; | 317 }; |
311 | 318 |
312 // An area for notifications. Some notifications point at the account chooser. | 319 // An area for notifications. Some notifications point at the account chooser. |
313 class NotificationArea : public views::View { | 320 class NotificationArea : public views::View { |
314 public: | 321 public: |
315 explicit NotificationArea(AutofillDialogViewDelegate* delegate); | 322 explicit NotificationArea( |
| 323 AutofillDialogViewDelegate* delegate, |
| 324 const base::WeakPtr<LearnMoreIconDelegate>& icon_delegate); |
316 virtual ~NotificationArea(); | 325 virtual ~NotificationArea(); |
317 | 326 |
318 // Displays the given notifications. | 327 // Displays the given notifications. |
319 void SetNotifications(const std::vector<DialogNotification>& notifications); | 328 void SetNotifications(const std::vector<DialogNotification>& notifications); |
320 | 329 |
321 // views::View implementation. | 330 // views::View implementation. |
322 virtual gfx::Size GetPreferredSize() OVERRIDE; | 331 virtual gfx::Size GetPreferredSize() OVERRIDE; |
323 virtual const char* GetClassName() const OVERRIDE; | 332 virtual const char* GetClassName() const OVERRIDE; |
324 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; | 333 virtual void PaintChildren(gfx::Canvas* canvas) OVERRIDE; |
325 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 334 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
326 | 335 |
327 void set_arrow_centering_anchor( | 336 void set_arrow_centering_anchor( |
328 const base::WeakPtr<views::View>& arrow_centering_anchor) { | 337 const base::WeakPtr<views::View>& arrow_centering_anchor) { |
329 arrow_centering_anchor_ = arrow_centering_anchor; | 338 arrow_centering_anchor_ = arrow_centering_anchor; |
330 } | 339 } |
331 | 340 |
332 private: | 341 private: |
333 // Utility function for determining whether an arrow should be drawn | 342 // Utility function for determining whether an arrow should be drawn |
334 // pointing at |arrow_centering_anchor_|. | 343 // pointing at |arrow_centering_anchor_|. |
335 bool HasArrow(); | 344 bool HasArrow(); |
336 | 345 |
337 // A reference to the delegate/controller than owns this view. | 346 // A reference to the delegate/controller than owns this view. |
338 // Used to report when checkboxes change their values. | 347 // Used to report when checkboxes change their values. |
339 AutofillDialogViewDelegate* delegate_; // weak | 348 AutofillDialogViewDelegate* delegate_; // weak |
340 | 349 |
| 350 // A weak pointer to the delegate that should be passed to any created |
| 351 // LearnMoreIcons (see: |SetNotifications()|). |
| 352 base::WeakPtr<LearnMoreIconDelegate> icon_delegate_; |
| 353 |
341 // If HasArrow() is true, the arrow should point at this. | 354 // If HasArrow() is true, the arrow should point at this. |
342 base::WeakPtr<views::View> arrow_centering_anchor_; | 355 base::WeakPtr<views::View> arrow_centering_anchor_; |
343 | 356 |
344 std::vector<DialogNotification> notifications_; | 357 std::vector<DialogNotification> notifications_; |
345 | 358 |
346 DISALLOW_COPY_AND_ASSIGN(NotificationArea); | 359 DISALLOW_COPY_AND_ASSIGN(NotificationArea); |
347 }; | 360 }; |
348 | 361 |
349 typedef std::map<const DetailInput*, DecoratedTextfield*> TextfieldMap; | 362 typedef std::map<const DetailInput*, DecoratedTextfield*> TextfieldMap; |
350 typedef std::map<const DetailInput*, views::Combobox*> ComboboxMap; | 363 typedef std::map<const DetailInput*, views::Combobox*> ComboboxMap; |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
579 // Sets the visual state for an input to be either valid or invalid. This | 592 // Sets the visual state for an input to be either valid or invalid. This |
580 // should work on Comboboxes or DecoratedTextfields. If |message| is empty, | 593 // should work on Comboboxes or DecoratedTextfields. If |message| is empty, |
581 // the input is valid. | 594 // the input is valid. |
582 template<class T> | 595 template<class T> |
583 void SetValidityForInput(T* input, const base::string16& message); | 596 void SetValidityForInput(T* input, const base::string16& message); |
584 | 597 |
585 // Shows an error bubble pointing at |view| if |view| has a message in | 598 // Shows an error bubble pointing at |view| if |view| has a message in |
586 // |validity_map_|. | 599 // |validity_map_|. |
587 void ShowErrorBubbleForViewIfNecessary(views::View* view); | 600 void ShowErrorBubbleForViewIfNecessary(views::View* view); |
588 | 601 |
589 // Hides |error_bubble_| (if it exists). | 602 // Shows an informational "learn more" bubble pointing at |icon|. |
| 603 void ShowLearnMoreBubbleIfNecessary(LearnMoreIcon* icon); |
| 604 |
| 605 // Hides |error_bubble_| or |learn_more_bubble_| (if they exist). |
590 void HideErrorBubble(); | 606 void HideErrorBubble(); |
| 607 void HideLearnMoreBubble(); |
591 | 608 |
592 // Updates validity of the inputs in |section| with new |validity_messages|. | 609 // Updates validity of the inputs in |section| with new |validity_messages|. |
593 // Fields are only updated with unsure messages if |overwrite_valid| is true. | 610 // Fields are only updated with unsure messages if |overwrite_valid| is true. |
594 void MarkInputsInvalid(DialogSection section, | 611 void MarkInputsInvalid(DialogSection section, |
595 const ValidityMessages& validity_messages, | 612 const ValidityMessages& validity_messages, |
596 bool overwrite_invalid); | 613 bool overwrite_invalid); |
597 | 614 |
598 // Checks all manual inputs in |group| for validity. Decorates the invalid | 615 // Checks all manual inputs in |group| for validity. Decorates the invalid |
599 // ones and returns true if all were valid. | 616 // ones and returns true if all were valid. |
600 bool ValidateGroup(const DetailsGroup& group, ValidationType type); | 617 bool ValidateGroup(const DetailsGroup& group, ValidationType type); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 // The view that is appended to the bottom of the dialog, below the button | 721 // The view that is appended to the bottom of the dialog, below the button |
705 // strip. Used to display legal document links. | 722 // strip. Used to display legal document links. |
706 views::View* footnote_view_; | 723 views::View* footnote_view_; |
707 | 724 |
708 // The legal document text and links. | 725 // The legal document text and links. |
709 views::StyledLabel* legal_document_view_; | 726 views::StyledLabel* legal_document_view_; |
710 | 727 |
711 // The focus manager for |window_|. | 728 // The focus manager for |window_|. |
712 views::FocusManager* focus_manager_; | 729 views::FocusManager* focus_manager_; |
713 | 730 |
714 // The object that manages the error bubble widget. | 731 // Bubbles to show validation errors or informational messages. |
715 ErrorBubble* error_bubble_; // Weak; owns itself. | 732 InfoBubble* error_bubble_; // Weak; owns itself. |
| 733 InfoBubble* learn_more_bubble_; // Weak; owns itself. |
716 | 734 |
717 // Map from input view (textfield or combobox) to error string. | 735 // Map from input view (textfield or combobox) to error string. |
718 std::map<views::View*, base::string16> validity_map_; | 736 std::map<views::View*, base::string16> validity_map_; |
719 | 737 |
720 ScopedObserver<views::Widget, AutofillDialogViews> observer_; | 738 ScopedObserver<views::Widget, AutofillDialogViews> observer_; |
721 | 739 |
722 // Delegate for the sign-in dialog's webview. | 740 // Delegate for the sign-in dialog's webview. |
723 scoped_ptr<AutofillDialogSignInDelegate> sign_in_delegate_; | 741 scoped_ptr<AutofillDialogSignInDelegate> sign_in_delegate_; |
724 | 742 |
| 743 base::WeakPtrFactory<AutofillDialogViews> weak_ptr_factory_; |
| 744 |
725 DISALLOW_COPY_AND_ASSIGN(AutofillDialogViews); | 745 DISALLOW_COPY_AND_ASSIGN(AutofillDialogViews); |
726 }; | 746 }; |
727 | 747 |
728 } // namespace autofill | 748 } // namespace autofill |
729 | 749 |
730 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_DIALOG_VIEWS_H_ | 750 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_DIALOG_VIEWS_H_ |
OLD | NEW |