OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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; | 5 package org.chromium.chrome.browser; |
6 | 6 |
7 import android.content.Context; | 7 import android.content.Context; |
8 import android.graphics.Bitmap; | 8 import android.graphics.Bitmap; |
9 import android.graphics.Color; | 9 import android.graphics.Color; |
10 import android.graphics.drawable.BitmapDrawable; | 10 import android.graphics.drawable.BitmapDrawable; |
11 import android.graphics.drawable.ColorDrawable; | 11 import android.graphics.drawable.ColorDrawable; |
12 import android.graphics.drawable.Drawable; | 12 import android.graphics.drawable.Drawable; |
13 import android.text.TextUtils; | 13 import android.text.TextUtils; |
14 import android.view.Gravity; | 14 import android.view.Gravity; |
15 import android.view.View; | 15 import android.view.View; |
16 import android.view.ViewGroup; | 16 import android.view.ViewGroup; |
17 import android.widget.AdapterView; | 17 import android.widget.AdapterView; |
18 import android.widget.BaseAdapter; | 18 import android.widget.BaseAdapter; |
19 import android.widget.HeaderViewListAdapter; | 19 import android.widget.HeaderViewListAdapter; |
20 import android.widget.ListPopupWindow; | 20 import android.widget.ListPopupWindow; |
21 import android.widget.PopupWindow; | 21 import android.widget.PopupWindow; |
22 import android.widget.TextView; | 22 import android.widget.TextView; |
23 | 23 |
24 import org.chromium.base.CalledByNative; | 24 import org.chromium.base.CalledByNative; |
25 import org.chromium.base.ThreadUtils; | 25 import org.chromium.base.ThreadUtils; |
26 import org.chromium.content.browser.NavigationClient; | 26 import org.chromium.content_public.browser.NavigationController; |
27 import org.chromium.content_public.browser.NavigationEntry; | 27 import org.chromium.content_public.browser.NavigationEntry; |
28 import org.chromium.content_public.browser.NavigationHistory; | 28 import org.chromium.content_public.browser.NavigationHistory; |
29 import org.chromium.ui.base.LocalizationUtils; | 29 import org.chromium.ui.base.LocalizationUtils; |
30 | 30 |
31 import java.util.HashSet; | 31 import java.util.HashSet; |
32 import java.util.Set; | 32 import java.util.Set; |
33 | 33 |
34 /** | 34 /** |
35 * A popup that handles displaying the navigation history for a given tab. | 35 * A popup that handles displaying the navigation history for a given tab. |
36 */ | 36 */ |
37 public class NavigationPopup extends ListPopupWindow implements AdapterView.OnIt emClickListener { | 37 public class NavigationPopup extends ListPopupWindow implements AdapterView.OnIt emClickListener { |
38 | 38 |
39 private static final int FAVICON_SIZE_DP = 16; | 39 private static final int FAVICON_SIZE_DP = 16; |
40 | 40 |
41 private static final int MAXIMUM_HISTORY_ITEMS = 8; | 41 private static final int MAXIMUM_HISTORY_ITEMS = 8; |
42 | 42 |
43 private final Context mContext; | 43 private final Context mContext; |
44 private final NavigationClient mNavigationClient; | 44 private final NavigationController mNavigationController; |
45 private final NavigationHistory mHistory; | 45 private final NavigationHistory mHistory; |
46 private final NavigationAdapter mAdapter; | 46 private final NavigationAdapter mAdapter; |
47 private final ListItemFactory mListItemFactory; | 47 private final ListItemFactory mListItemFactory; |
48 | 48 |
49 private final int mFaviconSize; | 49 private final int mFaviconSize; |
50 | 50 |
51 private long mNativeNavigationPopup; | 51 private long mNativeNavigationPopup; |
52 | 52 |
53 /** | 53 /** |
54 * Constructs a new popup with the given history information. | 54 * Constructs a new popup with the given history information. |
55 * | 55 * |
56 * @param context The context used for building the popup. | 56 * @param context The context used for building the popup. |
57 * @param navigationClient The owner of the history being displayed. | 57 * @param navigationController The owner of the history being displayed. |
Ted C
2014/10/22 17:41:33
I would update this comment
AKVT
2014/10/23 13:34:27
Done.
| |
58 * @param isForward Whether to request forward navigation entries. | 58 * @param isForward Whether to request forward navigation entries. |
59 */ | 59 */ |
60 public NavigationPopup( | 60 public NavigationPopup( |
61 Context context, NavigationClient navigationClient, boolean isForwar d) { | 61 Context context, NavigationController navigationController, boolean isForward) { |
62 super(context, null, android.R.attr.popupMenuStyle); | 62 super(context, null, android.R.attr.popupMenuStyle); |
63 mContext = context; | 63 mContext = context; |
64 mNavigationClient = navigationClient; | 64 mNavigationController = navigationController; |
65 mHistory = mNavigationClient.getDirectedNavigationHistory( | 65 mHistory = mNavigationController.getDirectedNavigationHistory( |
66 isForward, MAXIMUM_HISTORY_ITEMS); | 66 isForward, MAXIMUM_HISTORY_ITEMS); |
67 mAdapter = new NavigationAdapter(); | 67 mAdapter = new NavigationAdapter(); |
68 | 68 |
69 float density = mContext.getResources().getDisplayMetrics().density; | 69 float density = mContext.getResources().getDisplayMetrics().density; |
70 mFaviconSize = (int) (density * FAVICON_SIZE_DP); | 70 mFaviconSize = (int) (density * FAVICON_SIZE_DP); |
71 | 71 |
72 setModal(true); | 72 setModal(true); |
73 setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); | 73 setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); |
74 setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); | 74 setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); |
75 setOnItemClickListener(this); | 75 setOnItemClickListener(this); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
123 for (int i = 0; i < mHistory.getEntryCount(); i++) { | 123 for (int i = 0; i < mHistory.getEntryCount(); i++) { |
124 NavigationEntry entry = mHistory.getEntryAtIndex(i); | 124 NavigationEntry entry = mHistory.getEntryAtIndex(i); |
125 if (TextUtils.equals(url, entry.getUrl())) entry.updateFavicon((Bitm ap) favicon); | 125 if (TextUtils.equals(url, entry.getUrl())) entry.updateFavicon((Bitm ap) favicon); |
126 } | 126 } |
127 mAdapter.notifyDataSetChanged(); | 127 mAdapter.notifyDataSetChanged(); |
128 } | 128 } |
129 | 129 |
130 @Override | 130 @Override |
131 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { | 131 public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
132 NavigationEntry entry = (NavigationEntry) parent.getItemAtPosition(posit ion); | 132 NavigationEntry entry = (NavigationEntry) parent.getItemAtPosition(posit ion); |
133 mNavigationClient.goToNavigationIndex(entry.getIndex()); | 133 mNavigationController.goToNavigationIndex(entry.getIndex()); |
134 dismiss(); | 134 dismiss(); |
135 } | 135 } |
136 | 136 |
137 private void updateBitmapForTextView(TextView view, Bitmap bitmap) { | 137 private void updateBitmapForTextView(TextView view, Bitmap bitmap) { |
138 Drawable faviconDrawable = null; | 138 Drawable faviconDrawable = null; |
139 if (bitmap != null) { | 139 if (bitmap != null) { |
140 faviconDrawable = new BitmapDrawable(mContext.getResources(), bitmap ); | 140 faviconDrawable = new BitmapDrawable(mContext.getResources(), bitmap ); |
141 ((BitmapDrawable) faviconDrawable).setGravity(Gravity.FILL); | 141 ((BitmapDrawable) faviconDrawable).setGravity(Gravity.FILL); |
142 } else { | 142 } else { |
143 faviconDrawable = new ColorDrawable(Color.TRANSPARENT); | 143 faviconDrawable = new ColorDrawable(Color.TRANSPARENT); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
230 return view; | 230 return view; |
231 } | 231 } |
232 } | 232 } |
233 | 233 |
234 private static native String nativeGetHistoryUrl(); | 234 private static native String nativeGetHistoryUrl(); |
235 | 235 |
236 private native long nativeInit(); | 236 private native long nativeInit(); |
237 private native void nativeDestroy(long nativeNavigationPopup); | 237 private native void nativeDestroy(long nativeNavigationPopup); |
238 private native void nativeFetchFaviconForUrl(long nativeNavigationPopup, Str ing url); | 238 private native void nativeFetchFaviconForUrl(long nativeNavigationPopup, Str ing url); |
239 } | 239 } |
OLD | NEW |