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.
5 #ifndef CHROME_BROWSER_AUTOFILL_AUTOFILL_POPUP_VIEW_H_
6 #define CHROME_BROWSER_AUTOFILL_AUTOFILL_POPUP_VIEW_H_
10 #include "base/compiler_specific.h"
11 #include "base/string16.h"
12 #include "content/public/browser/notification_registrar.h"
13 #include "content/public/browser/notification_observer.h"
14 #include "ui/gfx/font.h"
15 #include "ui/gfx/rect.h"
21 class AutofillExternalDelegate
;
23 class AutofillPopupView
: public content::NotificationObserver
{
25 explicit AutofillPopupView(content::WebContents
* web_contents
,
26 AutofillExternalDelegate
* external_delegate_
);
27 virtual ~AutofillPopupView();
29 // Hide the popup from view. Platform-indepent work.
32 // Display the autofill popup and fill it in with the values passed in.
33 // Platform-independent work.
34 void Show(const std::vector
<string16
>& autofill_values
,
35 const std::vector
<string16
>& autofill_labels
,
36 const std::vector
<string16
>& autofill_icons
,
37 const std::vector
<int>& autofill_unique_ids
);
39 void set_element_bounds(const gfx::Rect
& bounds
) {
40 element_bounds_
= bounds
;
43 const gfx::Rect
& element_bounds() { return element_bounds_
; }
46 // Display the autofill popup and fill it in with the values passed in.
47 // Platform-dependent work.
48 virtual void ShowInternal() = 0;
50 // Hide the popup from view. Platform-dependent work.
51 virtual void HideInternal() = 0;
53 // Invalide the given row and redraw it.
54 virtual void InvalidateRow(size_t row
) = 0;
56 // Adjust the size of the popup to show the elements being held.
57 virtual void ResizePopup() = 0;
59 AutofillExternalDelegate
* external_delegate() { return external_delegate_
; }
61 const std::vector
<string16
>& autofill_values() const {
62 return autofill_values_
;
64 const std::vector
<string16
>& autofill_labels() const {
65 return autofill_labels_
;
67 const std::vector
<string16
>& autofill_icons() const {
68 return autofill_icons_
;
70 const std::vector
<int>& autofill_unique_ids() const {
71 return autofill_unique_ids_
;
74 const gfx::Font
& label_font() const { return label_font_
; }
75 const gfx::Font
& value_font() const { return value_font_
; }
77 int selected_line() const { return selected_line_
; }
79 // Change which line is currently selected by the user.
80 void SetSelectedLine(int selected_line
);
82 // Clear the currently selected line so that nothing is selected.
83 void ClearSelectedLine();
85 // Increase the selected line by 1, properly handling wrapping.
86 void SelectNextLine();
88 // Decrease the selected line by 1, properly handling wrapping.
89 void SelectPreviousLine();
91 // The user has choosen the selected line.
92 bool AcceptSelectedLine();
94 // The user has removed a suggestion.
95 bool RemoveSelectedLine();
97 // Get the resource value for the given resource, returning -1 if the
98 // resource isn't recognized.
99 int GetIconResourceID(const string16
& resource_name
);
101 // Returns true if the given id refers to an element that can be deleted.
102 bool CanDelete(int id
);
105 // Returns true if the given id refers to an element that can be accepted.
106 bool CanAccept(int id
);
108 // Returns true if the popup still has non-options entries to show the user.
109 bool HasAutofillEntries();
111 // content::NotificationObserver method override.
112 virtual void Observe(int type
,
113 const content::NotificationSource
& source
,
114 const content::NotificationDetails
& details
) OVERRIDE
;
116 // A scoped container for notification registries.
117 content::NotificationRegistrar registrar_
;
119 AutofillExternalDelegate
* external_delegate_
;
121 // The bounds of the text element that is the focus of the Autofill.
122 gfx::Rect element_bounds_
;
124 // The current Autofill query values.
125 std::vector
<string16
> autofill_values_
;
126 std::vector
<string16
> autofill_labels_
;
127 std::vector
<string16
> autofill_icons_
;
128 std::vector
<int> autofill_unique_ids_
;
130 // The fonts for the popup text.
131 gfx::Font value_font_
;
132 gfx::Font label_font_
;
134 // The line that is currently selected by the user.
135 // |kNoSelection| indicates that no line is currently selected.
139 #endif // CHROME_BROWSER_AUTOFILL_AUTOFILL_POPUP_VIEW_H_