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_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ | 5 #ifndef CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ |
6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ | 6 #define CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
69 const gfx::RectF& element_bounds, | 69 const gfx::RectF& element_bounds, |
70 base::i18n::TextDirection text_direction); | 70 base::i18n::TextDirection text_direction); |
71 ~AutofillPopupControllerImpl() override; | 71 ~AutofillPopupControllerImpl() override; |
72 | 72 |
73 // AutofillPopupController implementation. | 73 // AutofillPopupController implementation. |
74 void UpdateBoundsAndRedrawPopup() override; | 74 void UpdateBoundsAndRedrawPopup() override; |
75 void SetSelectionAtPoint(const gfx::Point& point) override; | 75 void SetSelectionAtPoint(const gfx::Point& point) override; |
76 bool AcceptSelectedLine() override; | 76 bool AcceptSelectedLine() override; |
77 void SelectionCleared() override; | 77 void SelectionCleared() override; |
78 void AcceptSuggestion(size_t index) override; | 78 void AcceptSuggestion(size_t index) override; |
79 int GetIconResourceID(const base::string16& resource_name) const override; | |
80 bool IsWarning(size_t index) const override; | 79 bool IsWarning(size_t index) const override; |
81 gfx::Rect GetRowBounds(size_t index) override; | 80 |
Evan Stade
2016/01/09 00:19:02
?
Mathieu
2016/01/11 18:33:11
Done.
| |
82 const gfx::Rect& popup_bounds() const override; | 81 gfx::Rect popup_bounds() const override; |
83 gfx::NativeView container_view() override; | 82 gfx::NativeView container_view() override; |
84 const gfx::RectF& element_bounds() const override; | 83 const gfx::RectF& element_bounds() const override; |
85 bool IsRTL() const override; | 84 bool IsRTL() const override; |
86 | 85 const std::vector<autofill::Suggestion> GetSuggestions() override; |
86 #if !defined(OS_ANDROID) | |
Evan Stade
2016/01/09 00:19:02
this will need to be !BUILDFLAG(ANDROID_JAVA_UI)
Mathieu
2016/01/11 18:33:11
I would rather punt this to a subsequent CL becaus
| |
87 int GetElidedValueWidthForRow(size_t row) override; | |
88 int GetElidedLabelWidthForRow(size_t row) override; | |
89 #endif | |
87 size_t GetLineCount() const override; | 90 size_t GetLineCount() const override; |
88 const autofill::Suggestion& GetSuggestionAt(size_t row) const override; | 91 const autofill::Suggestion& GetSuggestionAt(size_t row) const override; |
89 const base::string16& GetElidedValueAt(size_t row) const override; | 92 const base::string16& GetElidedValueAt(size_t row) const override; |
90 const base::string16& GetElidedLabelAt(size_t row) const override; | 93 const base::string16& GetElidedLabelAt(size_t row) const override; |
91 bool GetRemovalConfirmationText(int list_index, | 94 bool GetRemovalConfirmationText(int list_index, |
92 base::string16* title, | 95 base::string16* title, |
93 base::string16* body) override; | 96 base::string16* body) override; |
94 bool RemoveSuggestion(int list_index) override; | 97 bool RemoveSuggestion(int list_index) override; |
95 #if !defined(OS_ANDROID) | 98 #if !defined(OS_ANDROID) |
96 const gfx::FontList& GetValueFontListForRow(size_t index) const override; | 99 const gfx::FontList& GetValueFontListForRow(size_t index) const override; |
97 const gfx::FontList& GetLabelFontList() const override; | 100 const gfx::FontList& GetLabelFontList() const override; |
98 #endif | 101 #endif |
99 int selected_line() const override; | 102 int selected_line() const override; |
100 | 103 |
101 content::WebContents* web_contents(); | 104 content::WebContents* web_contents(); |
102 | 105 |
103 // Change which line is currently selected by the user. | 106 // Change which line is currently selected by the user. |
104 void SetSelectedLine(int selected_line); | 107 void SetSelectedLine(int selected_line); |
105 | 108 |
106 // Increase the selected line by 1, properly handling wrapping. | 109 // Increase the selected line by 1, properly handling wrapping. |
107 void SelectNextLine(); | 110 void SelectNextLine(); |
108 | 111 |
109 // Decrease the selected line by 1, properly handling wrapping. | 112 // Decrease the selected line by 1, properly handling wrapping. |
110 void SelectPreviousLine(); | 113 void SelectPreviousLine(); |
111 | 114 |
112 // The user has removed a suggestion. | 115 // The user has removed a suggestion. |
113 bool RemoveSelectedLine(); | 116 bool RemoveSelectedLine(); |
114 | 117 |
115 // Convert a y-coordinate to the closest line. | |
116 int LineFromY(int y); | |
117 | |
118 // Returns the height of a row depending on its type. | |
119 int GetRowHeightFromId(int identifier) const; | |
120 | |
121 // Returns true if the given id refers to an element that can be accepted. | 118 // Returns true if the given id refers to an element that can be accepted. |
122 bool CanAccept(int id); | 119 bool CanAccept(int id); |
123 | 120 |
124 // Returns true if the popup still has non-options entries to show the user. | 121 // Returns true if the popup still has non-options entries to show the user. |
125 bool HasSuggestions(); | 122 bool HasSuggestions(); |
126 | 123 |
127 // Set the Autofill entry values. Exposed to allow tests to set these values | 124 // Set the Autofill entry values. Exposed to allow tests to set these values |
128 // without showing the popup. | 125 // without showing the popup. |
129 void SetValues(const std::vector<autofill::Suggestion>& suggestions); | 126 void SetValues(const std::vector<autofill::Suggestion>& suggestions); |
130 | 127 |
131 AutofillPopupView* view() { return view_; } | 128 AutofillPopupView* view() { return view_; } |
132 | 129 |
133 // |view_| pass throughs (virtual for testing). | 130 // |view_| pass throughs (virtual for testing). |
134 virtual void ShowView(); | 131 virtual void ShowView(); |
135 virtual void InvalidateRow(size_t row); | 132 virtual void InvalidateRow(size_t row); |
136 | 133 |
137 // Protected so tests can access. | |
138 #if !defined(OS_ANDROID) | |
139 // Calculates the desired width of the popup based on its contents. | |
140 int GetDesiredPopupWidth() const; | |
141 | |
142 // Calculates the desired height of the popup based on its contents. | |
143 int GetDesiredPopupHeight() const; | |
144 | |
145 // Calculate the width of the row, excluding all the text. This provides | |
146 // the size of the row that won't be reducible (since all the text can be | |
147 // elided if there isn't enough space). | |
148 int RowWidthWithoutText(int row) const; | |
149 #endif | |
150 | |
151 base::WeakPtr<AutofillPopupControllerImpl> GetWeakPtr(); | 134 base::WeakPtr<AutofillPopupControllerImpl> GetWeakPtr(); |
152 | 135 |
153 // Contains common popup functionality such as popup layout. Protected for | 136 // Contains common popup functionality such as popup layout. Protected for |
154 // testing. | 137 // testing. |
155 scoped_ptr<PopupControllerCommon> controller_common_; | 138 scoped_ptr<PopupControllerCommon> controller_common_; |
156 | 139 |
157 private: | 140 private: |
141 #if !defined(OS_ANDROID) | |
142 FRIEND_TEST_ALL_PREFIXES(AutofillPopupControllerUnitTest, ElideText); | |
143 | |
144 // Helper method which elides the value and label for the suggestion at |row| | |
145 // given the |available_width|. Puts the results in |elided_values_| and | |
146 // |elided_labels_|. | |
147 void ElideValueAndLabelForRow(size_t row, int available_width); | |
148 #endif | |
149 | |
158 // Clear the internal state of the controller. This is needed to ensure that | 150 // Clear the internal state of the controller. This is needed to ensure that |
159 // when the popup is reused it doesn't leak values between uses. | 151 // when the popup is reused it doesn't leak values between uses. |
160 void ClearState(); | 152 void ClearState(); |
161 | 153 |
162 #if !defined(OS_ANDROID) | |
163 // Calculates and sets the bounds of the popup, including placing it properly | |
164 // to prevent it from going off the screen. | |
165 void UpdatePopupBounds(); | |
166 #endif | |
167 | |
168 AutofillPopupView* view_; // Weak reference. | 154 AutofillPopupView* view_; // Weak reference. |
169 base::WeakPtr<AutofillPopupDelegate> delegate_; | 155 base::WeakPtr<AutofillPopupDelegate> delegate_; |
170 | 156 |
171 // The bounds of the Autofill popup. | |
172 gfx::Rect popup_bounds_; | |
173 | |
174 // The text direction of the popup. | 157 // The text direction of the popup. |
175 base::i18n::TextDirection text_direction_; | 158 base::i18n::TextDirection text_direction_; |
176 | 159 |
177 // The current Autofill query values. | 160 // The current Autofill query values. |
178 std::vector<autofill::Suggestion> suggestions_; | 161 std::vector<autofill::Suggestion> suggestions_; |
179 | 162 |
180 // Elided values and labels corresponding to the suggestions_ vector to | 163 // Elided values and labels corresponding to the suggestions_ vector to |
181 // ensure that it fits on the screen. | 164 // ensure that it fits on the screen. |
182 std::vector<base::string16> elided_values_; | 165 std::vector<base::string16> elided_values_; |
183 std::vector<base::string16> elided_labels_; | 166 std::vector<base::string16> elided_labels_; |
184 | 167 |
185 #if !defined(OS_ANDROID) | 168 #if !defined(OS_ANDROID) |
186 // The fonts for the popup text. | 169 // The fonts for the popup text. |
187 gfx::FontList value_font_list_; | 170 gfx::FontList value_font_list_; |
188 gfx::FontList label_font_list_; | 171 gfx::FontList label_font_list_; |
189 gfx::FontList warning_font_list_; | 172 gfx::FontList warning_font_list_; |
190 gfx::FontList title_font_list_; | 173 gfx::FontList title_font_list_; |
191 #endif | 174 #endif |
192 | 175 |
193 // The line that is currently selected by the user. | 176 // The line that is currently selected by the user. |
194 // |kNoSelection| indicates that no line is currently selected. | 177 // |kNoSelection| indicates that no line is currently selected. |
195 int selected_line_; | 178 int selected_line_; |
196 | 179 |
197 base::WeakPtrFactory<AutofillPopupControllerImpl> weak_ptr_factory_; | 180 base::WeakPtrFactory<AutofillPopupControllerImpl> weak_ptr_factory_; |
198 }; | 181 }; |
199 | 182 |
200 } // namespace autofill | 183 } // namespace autofill |
201 | 184 |
202 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ | 185 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ |
OLD | NEW |