summaryrefslogtreecommitdiff
path: root/core/java/android/webkit/FindActionModeCallback.java
diff options
context:
space:
mode:
authorVictoria Lease <violets@google.com>2012-02-13 15:47:48 -0800
committerVictoria Lease <violets@google.com>2012-02-21 11:08:27 -0800
commit47d0ee9766fb972f49d5116d2d7d3a23b5321211 (patch)
treefe983877c356de2f4ebf3e314166c7360fa54c5e /core/java/android/webkit/FindActionModeCallback.java
parentc10e48901c6531167dd001280ad9207023a01431 (diff)
async find-on-page implementation via WebKit
Change-Id: I63c6f8fc97bf452ea4456c77a89c5d2540c3d1ea
Diffstat (limited to 'core/java/android/webkit/FindActionModeCallback.java')
-rw-r--r--core/java/android/webkit/FindActionModeCallback.java39
1 files changed, 26 insertions, 13 deletions
diff --git a/core/java/android/webkit/FindActionModeCallback.java b/core/java/android/webkit/FindActionModeCallback.java
index fffa90b5518a..10b0885359db 100644
--- a/core/java/android/webkit/FindActionModeCallback.java
+++ b/core/java/android/webkit/FindActionModeCallback.java
@@ -43,7 +43,9 @@ class FindActionModeCallback implements ActionMode.Callback, TextWatcher,
private Resources mResources;
private boolean mMatchesFound;
private int mNumberOfMatches;
+ private int mActiveMatchIndex;
private ActionMode mActionMode;
+ private String mLastFind;
FindActionModeCallback(Context context) {
mCustomView = LayoutInflater.from(context).inflate(
@@ -132,16 +134,13 @@ class FindActionModeCallback implements ActionMode.Callback, TextWatcher,
mWebView.clearMatches();
mMatches.setVisibility(View.GONE);
mMatchesFound = false;
+ mLastFind = null;
} else {
mMatchesFound = true;
- mMatches.setVisibility(View.VISIBLE);
- mNumberOfMatches = mWebView.findAll(find.toString());
- if (0 == mNumberOfMatches) {
- mMatches.setText(mResources.getString(
- com.android.internal.R.string.no_matches));
- } else {
- updateMatchesString();
- }
+ mMatches.setVisibility(View.INVISIBLE);
+ mNumberOfMatches = 0;
+ mLastFind = find.toString();
+ mWebView.findAllAsync(mLastFind);
}
}
@@ -151,17 +150,31 @@ class FindActionModeCallback implements ActionMode.Callback, TextWatcher,
mInput.showSoftInput(mEditText, 0);
}
+ public void updateMatchCount(int matchIndex, int matchCount,
+ String findText) {
+ if (mLastFind != null && mLastFind.equals(findText)) {
+ mNumberOfMatches = matchCount;
+ mActiveMatchIndex = matchIndex;
+ updateMatchesString();
+ } else {
+ mMatches.setVisibility(View.INVISIBLE);
+ mNumberOfMatches = 0;
+ }
+ }
+
/*
* Update the string which tells the user how many matches were found, and
* which match is currently highlighted.
- * Not to be called when mNumberOfMatches is 0.
*/
private void updateMatchesString() {
- String template = mResources.getQuantityString(
+ if (mNumberOfMatches == 0) {
+ mMatches.setText(com.android.internal.R.string.no_matches);
+ } else {
+ mMatches.setText(mResources.getQuantityString(
com.android.internal.R.plurals.matches_found, mNumberOfMatches,
- mWebView.findIndex() + 1, mNumberOfMatches);
-
- mMatches.setText(template);
+ mActiveMatchIndex + 1, mNumberOfMatches));
+ }
+ mMatches.setVisibility(View.VISIBLE);
}
// OnLongClickListener implementation