| 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" |
| 11 #include "base/i18n/rtl.h" | 11 #include "base/i18n/rtl.h" |
| 12 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
| 13 #include "base/strings/string16.h" | 13 #include "base/strings/string16.h" |
| 14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
| 15 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | 15 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
| 16 #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h" |
| 16 #include "chrome/browser/ui/autofill/popup_controller_common.h" | 17 #include "chrome/browser/ui/autofill/popup_controller_common.h" |
| 17 #include "ui/gfx/font_list.h" | 18 #include "ui/gfx/font_list.h" |
| 18 #include "ui/gfx/geometry/rect.h" | 19 #include "ui/gfx/geometry/rect.h" |
| 19 #include "ui/gfx/geometry/rect_f.h" | 20 #include "ui/gfx/geometry/rect_f.h" |
| 20 | 21 |
| 21 namespace autofill { | 22 namespace autofill { |
| 22 | 23 |
| 23 class AutofillPopupDelegate; | 24 class AutofillPopupDelegate; |
| 24 class AutofillPopupView; | 25 class AutofillPopupView; |
| 25 | 26 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 FRIEND_TEST_ALL_PREFIXES(AutofillPopupControllerUnitTest, | 64 FRIEND_TEST_ALL_PREFIXES(AutofillPopupControllerUnitTest, |
| 64 ProperlyResetController); | 65 ProperlyResetController); |
| 65 | 66 |
| 66 AutofillPopupControllerImpl(base::WeakPtr<AutofillPopupDelegate> delegate, | 67 AutofillPopupControllerImpl(base::WeakPtr<AutofillPopupDelegate> delegate, |
| 67 content::WebContents* web_contents, | 68 content::WebContents* web_contents, |
| 68 gfx::NativeView container_view, | 69 gfx::NativeView container_view, |
| 69 const gfx::RectF& element_bounds, | 70 const gfx::RectF& element_bounds, |
| 70 base::i18n::TextDirection text_direction); | 71 base::i18n::TextDirection text_direction); |
| 71 ~AutofillPopupControllerImpl() override; | 72 ~AutofillPopupControllerImpl() override; |
| 72 | 73 |
| 73 // AutofillPopupController implementation. | 74 // AutofillPopupViewDelegate implementation. |
| 74 void UpdateBoundsAndRedrawPopup() override; | 75 void UpdateBoundsAndRedrawPopup() override; |
| 75 void SetSelectionAtPoint(const gfx::Point& point) override; | 76 void SetSelectionAtPoint(const gfx::Point& point) override; |
| 76 bool AcceptSelectedLine() override; | 77 bool AcceptSelectedLine() override; |
| 77 void SelectionCleared() override; | 78 void SelectionCleared() override; |
| 78 void AcceptSuggestion(size_t index) override; | 79 void AcceptSuggestion(size_t index) override; |
| 79 int GetIconResourceID(const base::string16& resource_name) const override; | |
| 80 bool IsWarning(size_t index) const override; | 80 bool IsWarning(size_t index) const override; |
| 81 gfx::Rect GetRowBounds(size_t index) override; | 81 gfx::Rect popup_bounds() const override; |
| 82 const 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; |
| 85 const std::vector<autofill::Suggestion> GetSuggestions() override; |
| 86 #if !defined(OS_ANDROID) |
| 87 int GetElidedValueWidthForRow(size_t row) override; |
| 88 int GetElidedLabelWidthForRow(size_t row) override; |
| 89 #endif |
| 86 | 90 |
| 91 // AutofillPopupController implementation. |
| 87 size_t GetLineCount() const override; | 92 size_t GetLineCount() const override; |
| 88 const autofill::Suggestion& GetSuggestionAt(size_t row) const override; | 93 const autofill::Suggestion& GetSuggestionAt(size_t row) const override; |
| 89 const base::string16& GetElidedValueAt(size_t row) const override; | 94 const base::string16& GetElidedValueAt(size_t row) const override; |
| 90 const base::string16& GetElidedLabelAt(size_t row) const override; | 95 const base::string16& GetElidedLabelAt(size_t row) const override; |
| 91 bool GetRemovalConfirmationText(int list_index, | 96 bool GetRemovalConfirmationText(int list_index, |
| 92 base::string16* title, | 97 base::string16* title, |
| 93 base::string16* body) override; | 98 base::string16* body) override; |
| 94 bool RemoveSuggestion(int list_index) override; | 99 bool RemoveSuggestion(int list_index) override; |
| 95 #if !defined(OS_ANDROID) | 100 #if !defined(OS_ANDROID) |
| 96 const gfx::FontList& GetValueFontListForRow(size_t index) const override; | 101 const gfx::FontList& GetValueFontListForRow(size_t index) const override; |
| 97 const gfx::FontList& GetLabelFontList() const override; | 102 const gfx::FontList& GetLabelFontList() const override; |
| 98 #endif | 103 #endif |
| 99 int selected_line() const override; | 104 int selected_line() const override; |
| 105 const AutofillPopupLayoutModel& layout_model() const override; |
| 100 | 106 |
| 101 content::WebContents* web_contents(); | 107 content::WebContents* web_contents(); |
| 102 | 108 |
| 103 // Change which line is currently selected by the user. | 109 // Change which line is currently selected by the user. |
| 104 void SetSelectedLine(int selected_line); | 110 void SetSelectedLine(int selected_line); |
| 105 | 111 |
| 106 // Increase the selected line by 1, properly handling wrapping. | 112 // Increase the selected line by 1, properly handling wrapping. |
| 107 void SelectNextLine(); | 113 void SelectNextLine(); |
| 108 | 114 |
| 109 // Decrease the selected line by 1, properly handling wrapping. | 115 // Decrease the selected line by 1, properly handling wrapping. |
| 110 void SelectPreviousLine(); | 116 void SelectPreviousLine(); |
| 111 | 117 |
| 112 // The user has removed a suggestion. | 118 // The user has removed a suggestion. |
| 113 bool RemoveSelectedLine(); | 119 bool RemoveSelectedLine(); |
| 114 | 120 |
| 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. | 121 // Returns true if the given id refers to an element that can be accepted. |
| 122 bool CanAccept(int id); | 122 bool CanAccept(int id); |
| 123 | 123 |
| 124 // Returns true if the popup still has non-options entries to show the user. | 124 // Returns true if the popup still has non-options entries to show the user. |
| 125 bool HasSuggestions(); | 125 bool HasSuggestions(); |
| 126 | 126 |
| 127 // Set the Autofill entry values. Exposed to allow tests to set these values | 127 // Set the Autofill entry values. Exposed to allow tests to set these values |
| 128 // without showing the popup. | 128 // without showing the popup. |
| 129 void SetValues(const std::vector<autofill::Suggestion>& suggestions); | 129 void SetValues(const std::vector<autofill::Suggestion>& suggestions); |
| 130 | 130 |
| 131 AutofillPopupView* view() { return view_; } | 131 AutofillPopupView* view() { return view_; } |
| 132 | 132 |
| 133 // |view_| pass throughs (virtual for testing). | 133 // |view_| pass throughs (virtual for testing). |
| 134 virtual void ShowView(); | 134 virtual void ShowView(); |
| 135 virtual void InvalidateRow(size_t row); | 135 virtual void InvalidateRow(size_t row); |
| 136 | 136 |
| 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(); | 137 base::WeakPtr<AutofillPopupControllerImpl> GetWeakPtr(); |
| 152 | 138 |
| 153 // Contains common popup functionality such as popup layout. Protected for | 139 // Contains common popup functionality such as popup layout. Protected for |
| 154 // testing. | 140 // testing. |
| 155 scoped_ptr<PopupControllerCommon> controller_common_; | 141 scoped_ptr<PopupControllerCommon> controller_common_; |
| 156 | 142 |
| 157 private: | 143 private: |
| 144 #if !defined(OS_ANDROID) |
| 145 FRIEND_TEST_ALL_PREFIXES(AutofillPopupControllerUnitTest, ElideText); |
| 146 |
| 147 // Helper method which elides the value and label for the suggestion at |row| |
| 148 // given the |available_width|. Puts the results in |elided_values_| and |
| 149 // |elided_labels_|. |
| 150 void ElideValueAndLabelForRow(size_t row, int available_width); |
| 151 #endif |
| 152 |
| 158 // Clear the internal state of the controller. This is needed to ensure that | 153 // 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. | 154 // when the popup is reused it doesn't leak values between uses. |
| 160 void ClearState(); | 155 void ClearState(); |
| 161 | 156 |
| 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. | 157 AutofillPopupView* view_; // Weak reference. |
| 158 AutofillPopupLayoutModel layout_model_; |
| 169 base::WeakPtr<AutofillPopupDelegate> delegate_; | 159 base::WeakPtr<AutofillPopupDelegate> delegate_; |
| 170 | 160 |
| 171 // The bounds of the Autofill popup. | |
| 172 gfx::Rect popup_bounds_; | |
| 173 | |
| 174 // The text direction of the popup. | 161 // The text direction of the popup. |
| 175 base::i18n::TextDirection text_direction_; | 162 base::i18n::TextDirection text_direction_; |
| 176 | 163 |
| 177 // The current Autofill query values. | 164 // The current Autofill query values. |
| 178 std::vector<autofill::Suggestion> suggestions_; | 165 std::vector<autofill::Suggestion> suggestions_; |
| 179 | 166 |
| 180 // Elided values and labels corresponding to the suggestions_ vector to | 167 // Elided values and labels corresponding to the suggestions_ vector to |
| 181 // ensure that it fits on the screen. | 168 // ensure that it fits on the screen. |
| 182 std::vector<base::string16> elided_values_; | 169 std::vector<base::string16> elided_values_; |
| 183 std::vector<base::string16> elided_labels_; | 170 std::vector<base::string16> elided_labels_; |
| 184 | 171 |
| 185 #if !defined(OS_ANDROID) | 172 #if !defined(OS_ANDROID) |
| 186 // The fonts for the popup text. | 173 // The fonts for the popup text. |
| 187 gfx::FontList value_font_list_; | 174 gfx::FontList value_font_list_; |
| 188 gfx::FontList label_font_list_; | 175 gfx::FontList label_font_list_; |
| 189 gfx::FontList warning_font_list_; | 176 gfx::FontList warning_font_list_; |
| 190 gfx::FontList title_font_list_; | 177 gfx::FontList title_font_list_; |
| 191 #endif | 178 #endif |
| 192 | 179 |
| 193 // The line that is currently selected by the user. | 180 // The line that is currently selected by the user. |
| 194 // |kNoSelection| indicates that no line is currently selected. | 181 // |kNoSelection| indicates that no line is currently selected. |
| 195 int selected_line_; | 182 int selected_line_; |
| 196 | 183 |
| 197 base::WeakPtrFactory<AutofillPopupControllerImpl> weak_ptr_factory_; | 184 base::WeakPtrFactory<AutofillPopupControllerImpl> weak_ptr_factory_; |
| 198 }; | 185 }; |
| 199 | 186 |
| 200 } // namespace autofill | 187 } // namespace autofill |
| 201 | 188 |
| 202 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ | 189 #endif // CHROME_BROWSER_UI_AUTOFILL_AUTOFILL_POPUP_CONTROLLER_IMPL_H_ |
| OLD | NEW |