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