| 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; |
| 11 import android.graphics.Rect; | 11 import android.graphics.Rect; |
| 12 import android.graphics.drawable.Drawable; | 12 import android.graphics.drawable.Drawable; |
| 13 import android.util.Log; | 13 import android.util.Log; |
| 14 import android.view.LayoutInflater; | 14 import android.view.LayoutInflater; |
| 15 import android.view.View; | 15 import android.view.View; |
| 16 import android.view.WindowManager; | 16 import android.view.WindowManager; |
| 17 import android.widget.AdapterView; | 17 import android.widget.AdapterView; |
| 18 import android.widget.FrameLayout; | 18 import android.widget.FrameLayout; |
| 19 import android.widget.ListAdapter; | 19 import android.widget.ListAdapter; |
| 20 import android.widget.ListPopupWindow; | 20 import android.widget.ListPopupWindow; |
| 21 import android.widget.TextView; | 21 import android.widget.TextView; |
| 22 | 22 |
| 23 import java.util.ArrayList; | 23 import java.util.ArrayList; |
| 24 | 24 |
| 25 import org.chromium.chrome.R; | 25 import org.chromium.chrome.R; |
| 26 import org.chromium.content.browser.ContainerViewDelegate; | 26 import org.chromium.content.browser.ContainerViewDelegate; |
| 27 import org.chromium.ui.gfx.DeviceDisplayInfo; |
| 27 import org.chromium.ui.gfx.NativeWindow; | 28 import org.chromium.ui.gfx.NativeWindow; |
| 28 | 29 |
| 29 /** | 30 /** |
| 30 * The Autofill suggestion popup that lists relevant suggestions. | 31 * The Autofill suggestion popup that lists relevant suggestions. |
| 31 */ | 32 */ |
| 32 public class AutofillPopup extends ListPopupWindow implements AdapterView.OnItem
ClickListener { | 33 public class AutofillPopup extends ListPopupWindow implements AdapterView.OnItem
ClickListener { |
| 33 | 34 |
| 34 /** | 35 /** |
| 35 * Constants defining types of Autofill suggestion entries. | 36 * Constants defining types of Autofill suggestion entries. |
| 36 * Has to be kept in sync with enum in WebAutofillClient.h | 37 * Has to be kept in sync with enum in WebAutofillClient.h |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 144 |
| 144 /** | 145 /** |
| 145 * Sets the location and the size of the anchor view that the AutofillPopup
will use to attach | 146 * Sets the location and the size of the anchor view that the AutofillPopup
will use to attach |
| 146 * itself. | 147 * itself. |
| 147 * @param x X coordinate of the top left corner of the anchor view. | 148 * @param x X coordinate of the top left corner of the anchor view. |
| 148 * @param y Y coordinate of the top left corner of the anchor view. | 149 * @param y Y coordinate of the top left corner of the anchor view. |
| 149 * @param width The width of the anchor view. | 150 * @param width The width of the anchor view. |
| 150 * @param height The height of the anchor view. | 151 * @param height The height of the anchor view. |
| 151 */ | 152 */ |
| 152 public void setAnchorRect(float x, float y, float width, float height) { | 153 public void setAnchorRect(float x, float y, float width, float height) { |
| 153 mAnchorRect = new Rect((int) x, (int) y, (int) (x + width), (int) (y + h
eight)); | 154 float scale = (float) DeviceDisplayInfo.create(mNativeWindow.getContext(
)).getDIPScale(); |
| 155 mAnchorRect = new Rect(Math.round(x * scale), Math.round(y * scale), |
| 156 Math.round((x + width) * scale), Math.round((y + height) * scale
)); |
| 154 } | 157 } |
| 155 | 158 |
| 156 /** | 159 /** |
| 157 * Sets the Autofill suggestions to display in the popup and shows the popup
. | 160 * Sets the Autofill suggestions to display in the popup and shows the popup
. |
| 158 * @param suggestions Autofill suggestion data. | 161 * @param suggestions Autofill suggestion data. |
| 159 */ | 162 */ |
| 160 public void show(AutofillSuggestion[] suggestions) { | 163 public void show(AutofillSuggestion[] suggestions) { |
| 161 // Remove the AutofillSuggestions with IDs that are not supported by And
roid | 164 // Remove the AutofillSuggestions with IDs that are not supported by And
roid |
| 162 ArrayList<AutofillSuggestion> cleanedData = new ArrayList<AutofillSugges
tion>(); | 165 ArrayList<AutofillSuggestion> cleanedData = new ArrayList<AutofillSugges
tion>(); |
| 163 for (int i = 0; i < suggestions.length; i++) { | 166 for (int i = 0; i < suggestions.length; i++) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 return maxTextWidth + (int) (TEXT_PADDING_DP * | 221 return maxTextWidth + (int) (TEXT_PADDING_DP * |
| 219 mNativeWindow.getContext().getResources().getDisplayMetrics().de
nsity); | 222 mNativeWindow.getContext().getResources().getDisplayMetrics().de
nsity); |
| 220 } | 223 } |
| 221 | 224 |
| 222 @Override | 225 @Override |
| 223 public void onItemClick(AdapterView<?> parent, View view, int position, long
id) { | 226 public void onItemClick(AdapterView<?> parent, View view, int position, long
id) { |
| 224 mAutofillCallback.suggestionSelected(position); | 227 mAutofillCallback.suggestionSelected(position); |
| 225 } | 228 } |
| 226 | 229 |
| 227 } | 230 } |
| OLD | NEW |