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 gfx::Rect popup_bounds() const override; |
82 const gfx::Rect& popup_bounds() const override; | |
83 gfx::NativeView container_view() override; | 81 gfx::NativeView container_view() override; |
84 const gfx::RectF& element_bounds() const override; | 82 const gfx::RectF& element_bounds() const override; |
85 bool IsRTL() const override; | 83 bool IsRTL() const override; |
86 | 84 const std::vector<autofill::Suggestion> GetSuggestions() override; |
| 85 #if !defined(OS_ANDROID) |
| 86 int GetElidedValueWidthForRow(size_t row) override; |
| 87 int GetElidedLabelWidthForRow(size_t row) override; |
| 88 #endif |
87 size_t GetLineCount() const override; | 89 size_t GetLineCount() const override; |
88 const autofill::Suggestion& GetSuggestionAt(size_t row) const override; | 90 const autofill::Suggestion& GetSuggestionAt(size_t row) const override; |
89 const base::string16& GetElidedValueAt(size_t row) const override; | 91 const base::string16& GetElidedValueAt(size_t row) const override; |
90 const base::string16& GetElidedLabelAt(size_t row) const override; | 92 const base::string16& GetElidedLabelAt(size_t row) const override; |
91 bool GetRemovalConfirmationText(int list_index, | 93 bool GetRemovalConfirmationText(int list_index, |
92 base::string16* title, | 94 base::string16* title, |
93 base::string16* body) override; | 95 base::string16* body) override; |
94 bool RemoveSuggestion(int list_index) override; | 96 bool RemoveSuggestion(int list_index) override; |
95 #if !defined(OS_ANDROID) | 97 #if !defined(OS_ANDROID) |
96 const gfx::FontList& GetValueFontListForRow(size_t index) const override; | 98 const gfx::FontList& GetValueFontListForRow(size_t index) const override; |
97 const gfx::FontList& GetLabelFontList() const override; | 99 const gfx::FontList& GetLabelFontList() const override; |
98 #endif | 100 #endif |
99 int selected_line() const override; | 101 int selected_line() const override; |
100 | 102 |
101 content::WebContents* web_contents(); | 103 content::WebContents* web_contents(); |
102 | 104 |
103 // Change which line is currently selected by the user. | 105 // Change which line is currently selected by the user. |
104 void SetSelectedLine(int selected_line); | 106 void SetSelectedLine(int selected_line); |
105 | 107 |
106 // Increase the selected line by 1, properly handling wrapping. | 108 // Increase the selected line by 1, properly handling wrapping. |
107 void SelectNextLine(); | 109 void SelectNextLine(); |
108 | 110 |
109 // Decrease the selected line by 1, properly handling wrapping. | 111 // Decrease the selected line by 1, properly handling wrapping. |
110 void SelectPreviousLine(); | 112 void SelectPreviousLine(); |
111 | 113 |
112 // The user has removed a suggestion. | 114 // The user has removed a suggestion. |
113 bool RemoveSelectedLine(); | 115 bool RemoveSelectedLine(); |
114 | 116 |
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. | 117 // Returns true if the given id refers to an element that can be accepted. |
122 bool CanAccept(int id); | 118 bool CanAccept(int id); |
123 | 119 |
124 // Returns true if the popup still has non-options entries to show the user. | 120 // Returns true if the popup still has non-options entries to show the user. |
125 bool HasSuggestions(); | 121 bool HasSuggestions(); |
126 | 122 |
127 // Set the Autofill entry values. Exposed to allow tests to set these values | 123 // Set the Autofill entry values. Exposed to allow tests to set these values |
128 // without showing the popup. | 124 // without showing the popup. |
129 void SetValues(const std::vector<autofill::Suggestion>& suggestions); | 125 void SetValues(const std::vector<autofill::Suggestion>& suggestions); |
130 | 126 |
131 AutofillPopupView* view() { return view_; } | 127 AutofillPopupView* view() { return view_; } |
132 | 128 |
133 // |view_| pass throughs (virtual for testing). | 129 // |view_| pass throughs (virtual for testing). |
134 virtual void ShowView(); | 130 virtual void ShowView(); |
135 virtual void InvalidateRow(size_t row); | 131 virtual void InvalidateRow(size_t row); |
136 | 132 |
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(); | 133 base::WeakPtr<AutofillPopupControllerImpl> GetWeakPtr(); |
152 | 134 |
153 // Contains common popup functionality such as popup layout. Protected for | 135 // Contains common popup functionality such as popup layout. Protected for |
154 // testing. | 136 // testing. |
155 scoped_ptr<PopupControllerCommon> controller_common_; | 137 scoped_ptr<PopupControllerCommon> controller_common_; |
156 | 138 |
157 private: | 139 private: |
| 140 #if !defined(OS_ANDROID) |
| 141 FRIEND_TEST_ALL_PREFIXES(AutofillPopupControllerUnitTest, ElideText); |
| 142 |
| 143 // Helper method which elides the value and label for the suggestion at |row| |
| 144 // given the |available_width|. Puts the results in |elided_values_| and |
| 145 // |elided_labels_|. |
| 146 void ElideValueAndLabelForRow(size_t row, int available_width); |
| 147 #endif |
| 148 |
158 // Clear the internal state of the controller. This is needed to ensure that | 149 // 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. | 150 // when the popup is reused it doesn't leak values between uses. |
160 void ClearState(); | 151 void ClearState(); |
161 | 152 |
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. | 153 AutofillPopupView* view_; // Weak reference. |
169 base::WeakPtr<AutofillPopupDelegate> delegate_; | 154 base::WeakPtr<AutofillPopupDelegate> delegate_; |
170 | 155 |
171 // The bounds of the Autofill popup. | |
172 gfx::Rect popup_bounds_; | |
173 | |
174 // The text direction of the popup. | 156 // The text direction of the popup. |
175 base::i18n::TextDirection text_direction_; | 157 base::i18n::TextDirection text_direction_; |
176 | 158 |
177 // The current Autofill query values. | 159 // The current Autofill query values. |
178 std::vector<autofill::Suggestion> suggestions_; | 160 std::vector<autofill::Suggestion> suggestions_; |
179 | 161 |
180 // Elided values and labels corresponding to the suggestions_ vector to | 162 // Elided values and labels corresponding to the suggestions_ vector to |
181 // ensure that it fits on the screen. | 163 // ensure that it fits on the screen. |
182 std::vector<base::string16> elided_values_; | 164 std::vector<base::string16> elided_values_; |
183 std::vector<base::string16> elided_labels_; | 165 std::vector<base::string16> elided_labels_; |
184 | 166 |
185 #if !defined(OS_ANDROID) | 167 #if !defined(OS_ANDROID) |
186 // The fonts for the popup text. | 168 // The fonts for the popup text. |
187 gfx::FontList value_font_list_; | 169 gfx::FontList value_font_list_; |
188 gfx::FontList label_font_list_; | 170 gfx::FontList label_font_list_; |
189 gfx::FontList warning_font_list_; | 171 gfx::FontList warning_font_list_; |
190 gfx::FontList title_font_list_; | 172 gfx::FontList title_font_list_; |
191 #endif | 173 #endif |
192 | 174 |
193 // The line that is currently selected by the user. | 175 // The line that is currently selected by the user. |
194 // |kNoSelection| indicates that no line is currently selected. | 176 // |kNoSelection| indicates that no line is currently selected. |
195 int selected_line_; | 177 int selected_line_; |
196 | 178 |
197 base::WeakPtrFactory<AutofillPopupControllerImpl> weak_ptr_factory_; | 179 base::WeakPtrFactory<AutofillPopupControllerImpl> weak_ptr_factory_; |
198 }; | 180 }; |
199 | 181 |
200 } // namespace autofill | 182 } // namespace autofill |
201 | 183 |
202 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ | 184 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ |
OLD | NEW |