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 package org.chromium.chrome.browser.autofill; | 5 package org.chromium.chrome.browser.autofill; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.content.res.Configuration; | 8 import android.content.res.Configuration; |
9 import android.graphics.Paint; | 9 import android.graphics.Paint; |
10 import android.graphics.Point; | 10 import android.graphics.Point; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 private AnchorView mAnchorView; | 51 private AnchorView mAnchorView; |
52 private Rect mAnchorRect; | 52 private Rect mAnchorRect; |
53 private Paint mNameViewPaint; | 53 private Paint mNameViewPaint; |
54 private Paint mLabelViewPaint; | 54 private Paint mLabelViewPaint; |
55 | 55 |
56 /** | 56 /** |
57 * An interface to handle the touch interaction with an AutofillPopup object
. | 57 * An interface to handle the touch interaction with an AutofillPopup object
. |
58 */ | 58 */ |
59 public interface AutofillPopupDelegate { | 59 public interface AutofillPopupDelegate { |
60 /** | 60 /** |
61 * Confirms the dismissal of the java AutofillPopup object. | 61 * Requests the controller to hide AutofillPopup. |
62 */ | 62 */ |
63 public void dismissed(); | 63 public void requestHide(); |
64 | 64 |
65 /** | 65 /** |
66 * Handles the selection of an Autofill suggestion from an AutofillPopup
. | 66 * Handles the selection of an Autofill suggestion from an AutofillPopup
. |
67 * @param listIndex The index of the selected Autofill suggestion. | 67 * @param listIndex The index of the selected Autofill suggestion. |
68 */ | 68 */ |
69 public void suggestionSelected(int listIndex); | 69 public void suggestionSelected(int listIndex); |
70 } | 70 } |
71 | 71 |
72 // ListPopupWindow needs an anchor view to determine it's size and position.
We create a view | 72 // ListPopupWindow needs an anchor view to determine it's size and position.
We create a view |
73 // with the given desired width at the text edit area as a stand-in. This i
s "Fake" in the | 73 // with the given desired width at the text edit area as a stand-in. This i
s "Fake" in the |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 if (itemId > 0 || itemId == ITEM_ID_AUTOCOMPLETE_ENTRY || | 168 if (itemId > 0 || itemId == ITEM_ID_AUTOCOMPLETE_ENTRY || |
169 itemId == ITEM_ID_PASSWORD_ENTRY || itemId == ITEM_ID_DATA_L
IST_ENTRY) { | 169 itemId == ITEM_ID_PASSWORD_ENTRY || itemId == ITEM_ID_DATA_L
IST_ENTRY) { |
170 cleanedData.add(suggestions[i]); | 170 cleanedData.add(suggestions[i]); |
171 } | 171 } |
172 } | 172 } |
173 setAdapter(new AutofillListAdapter(mNativeWindow.getContext(), cleanedDa
ta)); | 173 setAdapter(new AutofillListAdapter(mNativeWindow.getContext(), cleanedDa
ta)); |
174 // Once the mAnchorRect is resized and placed correctly, it will show th
e Autofill popup. | 174 // Once the mAnchorRect is resized and placed correctly, it will show th
e Autofill popup. |
175 mAnchorView.setSize(mAnchorRect, getDesiredWidth(suggestions)); | 175 mAnchorView.setSize(mAnchorRect, getDesiredWidth(suggestions)); |
176 } | 176 } |
177 | 177 |
| 178 |
178 /** | 179 /** |
179 * Dismisses the popup and calls to mAutofillCallback.dismissed(). | 180 * Overrides the default dismiss behavior to request the controller to dismi
ss the view. |
180 */ | 181 */ |
181 @Override | 182 @Override |
182 public void dismiss() { | 183 public void dismiss() { |
183 super.dismiss(); | 184 mAutofillCallback.requestHide(); |
184 mContainerViewDelegate.removeViewFromContainerView(mAnchorView); | |
185 mAutofillCallback.dismissed(); | |
186 } | 185 } |
187 | 186 |
188 /** | 187 /** |
| 188 * Hides the popup and removes the anchor view from the ContainerView. |
| 189 */ |
| 190 public void hide() { |
| 191 super.dismiss(); |
| 192 mContainerViewDelegate.removeViewFromContainerView(mAnchorView); |
| 193 } |
| 194 |
| 195 /** |
189 * Get desired popup window width by calculating the maximum text length fro
m Autofill data. | 196 * Get desired popup window width by calculating the maximum text length fro
m Autofill data. |
190 * @param data Autofill suggestion data. | 197 * @param data Autofill suggestion data. |
191 * @return The popup window width. | 198 * @return The popup window width. |
192 */ | 199 */ |
193 private int getDesiredWidth(AutofillSuggestion[] data) { | 200 private int getDesiredWidth(AutofillSuggestion[] data) { |
194 if (mNameViewPaint == null || mLabelViewPaint == null) { | 201 if (mNameViewPaint == null || mLabelViewPaint == null) { |
195 LayoutInflater inflater = | 202 LayoutInflater inflater = |
196 (LayoutInflater) mNativeWindow.getContext().getSystemService
( | 203 (LayoutInflater) mNativeWindow.getContext().getSystemService
( |
197 Context.LAYOUT_INFLATER_SERVICE); | 204 Context.LAYOUT_INFLATER_SERVICE); |
198 View layout = inflater.inflate(R.layout.autofill_text, null); | 205 View layout = inflater.inflate(R.layout.autofill_text, null); |
(...skipping 22 matching lines...) Expand all Loading... |
221 return maxTextWidth + (int) (TEXT_PADDING_DP * | 228 return maxTextWidth + (int) (TEXT_PADDING_DP * |
222 mNativeWindow.getContext().getResources().getDisplayMetrics().de
nsity); | 229 mNativeWindow.getContext().getResources().getDisplayMetrics().de
nsity); |
223 } | 230 } |
224 | 231 |
225 @Override | 232 @Override |
226 public void onItemClick(AdapterView<?> parent, View view, int position, long
id) { | 233 public void onItemClick(AdapterView<?> parent, View view, int position, long
id) { |
227 mAutofillCallback.suggestionSelected(position); | 234 mAutofillCallback.suggestionSelected(position); |
228 } | 235 } |
229 | 236 |
230 } | 237 } |
OLD | NEW |