| 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.BitmapFactory; | 9 import android.graphics.BitmapFactory; |
| 10 import android.graphics.Color; | 10 import android.graphics.Color; |
| 11 import android.graphics.drawable.BitmapDrawable; | 11 import android.graphics.drawable.BitmapDrawable; |
| 12 import android.graphics.drawable.ColorDrawable; | 12 import android.graphics.drawable.ColorDrawable; |
| 13 import android.graphics.drawable.Drawable; | 13 import android.graphics.drawable.Drawable; |
| 14 import android.text.TextUtils; | 14 import android.text.TextUtils; |
| 15 import android.view.Gravity; | 15 import android.view.Gravity; |
| 16 import android.view.View; | 16 import android.view.View; |
| 17 import android.view.ViewGroup; | 17 import android.view.ViewGroup; |
| 18 import android.widget.AdapterView; | 18 import android.widget.AdapterView; |
| 19 import android.widget.BaseAdapter; | 19 import android.widget.BaseAdapter; |
| 20 import android.widget.HeaderViewListAdapter; | 20 import android.widget.HeaderViewListAdapter; |
| 21 import android.widget.ListPopupWindow; | 21 import android.widget.ListPopupWindow; |
| 22 import android.widget.PopupWindow; | 22 import android.widget.PopupWindow; |
| 23 import android.widget.TextView; | 23 import android.widget.TextView; |
| 24 | 24 |
| 25 import org.chromium.base.ThreadUtils; | 25 import org.chromium.base.ThreadUtils; |
| 26 import org.chromium.chrome.R; | 26 import org.chromium.chrome.R; |
| 27 import org.chromium.chrome.browser.favicon.FaviconHelper; | 27 import org.chromium.chrome.browser.favicon.FaviconHelper; |
| 28 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback; | 28 import org.chromium.chrome.browser.favicon.FaviconHelper.FaviconImageCallback; |
| 29 import org.chromium.chrome.browser.navigation.NavigationHandler; | |
| 30 import org.chromium.chrome.browser.profiles.Profile; | 29 import org.chromium.chrome.browser.profiles.Profile; |
| 30 import org.chromium.content_public.browser.NavigationController; |
| 31 import org.chromium.content_public.browser.NavigationEntry; | 31 import org.chromium.content_public.browser.NavigationEntry; |
| 32 import org.chromium.content_public.browser.NavigationHistory; | 32 import org.chromium.content_public.browser.NavigationHistory; |
| 33 import org.chromium.ui.base.LocalizationUtils; | 33 import org.chromium.ui.base.LocalizationUtils; |
| 34 | 34 |
| 35 import java.util.HashSet; | 35 import java.util.HashSet; |
| 36 import java.util.Set; | 36 import java.util.Set; |
| 37 | 37 |
| 38 /** | 38 /** |
| 39 * A popup that handles displaying the navigation history for a given tab. | 39 * A popup that handles displaying the navigation history for a given tab. |
| 40 */ | 40 */ |
| 41 public class NavigationPopup extends ListPopupWindow implements AdapterView.OnIt
emClickListener { | 41 public class NavigationPopup extends ListPopupWindow implements AdapterView.OnIt
emClickListener { |
| 42 | 42 |
| 43 private static final int MAXIMUM_HISTORY_ITEMS = 8; | 43 private static final int MAXIMUM_HISTORY_ITEMS = 8; |
| 44 | 44 |
| 45 private final Profile mProfile; | 45 private final Profile mProfile; |
| 46 private final Context mContext; | 46 private final Context mContext; |
| 47 private final NavigationHandler mNavigationHandler; | 47 private final NavigationController mNavigationController; |
| 48 private final NavigationHistory mHistory; | 48 private final NavigationHistory mHistory; |
| 49 private final NavigationAdapter mAdapter; | 49 private final NavigationAdapter mAdapter; |
| 50 private final ListItemFactory mListItemFactory; | 50 private final ListItemFactory mListItemFactory; |
| 51 | 51 |
| 52 private final int mFaviconSize; | 52 private final int mFaviconSize; |
| 53 | 53 |
| 54 private Bitmap mDefaultFavicon; | 54 private Bitmap mDefaultFavicon; |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * Loads the favicons asynchronously. | 57 * Loads the favicons asynchronously. |
| 58 */ | 58 */ |
| 59 private FaviconHelper mFaviconHelper; | 59 private FaviconHelper mFaviconHelper; |
| 60 | 60 |
| 61 private boolean mInitialized; | 61 private boolean mInitialized; |
| 62 | 62 |
| 63 /** | 63 /** |
| 64 * Constructs a new popup with the given history information. | 64 * Constructs a new popup with the given history information. |
| 65 * | 65 * |
| 66 * @param profile The profile used for fetching favicons. | 66 * @param profile The profile used for fetching favicons. |
| 67 * @param context The context used for building the popup. | 67 * @param context The context used for building the popup. |
| 68 * @param navigationController The controller which takes care of page navig
ations. | 68 * @param navigationController The controller which takes care of page navig
ations. |
| 69 * @param isForward Whether to request forward navigation entries. | 69 * @param isForward Whether to request forward navigation entries. |
| 70 */ | 70 */ |
| 71 public NavigationPopup(Profile profile, Context context, | 71 public NavigationPopup(Profile profile, Context context, |
| 72 NavigationHandler navigationController, boolean isForward) { | 72 NavigationController navigationController, boolean isForward) { |
| 73 super(context, null, android.R.attr.popupMenuStyle); | 73 super(context, null, android.R.attr.popupMenuStyle); |
| 74 mProfile = profile; | 74 mProfile = profile; |
| 75 mContext = context; | 75 mContext = context; |
| 76 mNavigationHandler = navigationController; | 76 mNavigationController = navigationController; |
| 77 mHistory = mNavigationHandler.getDirectedNavigationHistory( | 77 mHistory = mNavigationController.getDirectedNavigationHistory( |
| 78 isForward, MAXIMUM_HISTORY_ITEMS); | 78 isForward, MAXIMUM_HISTORY_ITEMS); |
| 79 mAdapter = new NavigationAdapter(); | 79 mAdapter = new NavigationAdapter(); |
| 80 | 80 |
| 81 mFaviconSize = mContext.getResources().getDimensionPixelSize(R.dimen.def
ault_favicon_size); | 81 mFaviconSize = mContext.getResources().getDimensionPixelSize(R.dimen.def
ault_favicon_size); |
| 82 | 82 |
| 83 setModal(true); | 83 setModal(true); |
| 84 setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); | 84 setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); |
| 85 setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); | 85 setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); |
| 86 setOnItemClickListener(this); | 86 setOnItemClickListener(this); |
| 87 | 87 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 159 for (int i = 0; i < mHistory.getEntryCount(); i++) { | 159 for (int i = 0; i < mHistory.getEntryCount(); i++) { |
| 160 NavigationEntry entry = mHistory.getEntryAtIndex(i); | 160 NavigationEntry entry = mHistory.getEntryAtIndex(i); |
| 161 if (TextUtils.equals(pageUrl, entry.getUrl())) entry.updateFavicon((
Bitmap) favicon); | 161 if (TextUtils.equals(pageUrl, entry.getUrl())) entry.updateFavicon((
Bitmap) favicon); |
| 162 } | 162 } |
| 163 mAdapter.notifyDataSetChanged(); | 163 mAdapter.notifyDataSetChanged(); |
| 164 } | 164 } |
| 165 | 165 |
| 166 @Override | 166 @Override |
| 167 public void onItemClick(AdapterView<?> parent, View view, int position, long
id) { | 167 public void onItemClick(AdapterView<?> parent, View view, int position, long
id) { |
| 168 NavigationEntry entry = (NavigationEntry) parent.getItemAtPosition(posit
ion); | 168 NavigationEntry entry = (NavigationEntry) parent.getItemAtPosition(posit
ion); |
| 169 mNavigationHandler.goToNavigationIndex(entry.getIndex()); | 169 mNavigationController.goToNavigationIndex(entry.getIndex()); |
| 170 dismiss(); | 170 dismiss(); |
| 171 } | 171 } |
| 172 | 172 |
| 173 private void updateBitmapForTextView(TextView view, Bitmap bitmap) { | 173 private void updateBitmapForTextView(TextView view, Bitmap bitmap) { |
| 174 Drawable faviconDrawable = null; | 174 Drawable faviconDrawable = null; |
| 175 if (bitmap != null) { | 175 if (bitmap != null) { |
| 176 faviconDrawable = new BitmapDrawable(mContext.getResources(), bitmap
); | 176 faviconDrawable = new BitmapDrawable(mContext.getResources(), bitmap
); |
| 177 ((BitmapDrawable) faviconDrawable).setGravity(Gravity.FILL); | 177 ((BitmapDrawable) faviconDrawable).setGravity(Gravity.FILL); |
| 178 } else { | 178 } else { |
| 179 faviconDrawable = new ColorDrawable(Color.TRANSPARENT); | 179 faviconDrawable = new ColorDrawable(Color.TRANSPARENT); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 String entryText = entry.getTitle(); | 260 String entryText = entry.getTitle(); |
| 261 if (TextUtils.isEmpty(entryText)) entryText = entry.getVirtualUrl(); | 261 if (TextUtils.isEmpty(entryText)) entryText = entry.getVirtualUrl(); |
| 262 if (TextUtils.isEmpty(entryText)) entryText = entry.getUrl(); | 262 if (TextUtils.isEmpty(entryText)) entryText = entry.getUrl(); |
| 263 view.setText(entryText); | 263 view.setText(entryText); |
| 264 updateBitmapForTextView(view, entry.getFavicon()); | 264 updateBitmapForTextView(view, entry.getFavicon()); |
| 265 | 265 |
| 266 return view; | 266 return view; |
| 267 } | 267 } |
| 268 } | 268 } |
| 269 } | 269 } |
| OLD | NEW |