Loading core/java/android/webkit/FindActionModeCallback.java +24 −12 Original line number Diff line number Diff line Loading @@ -33,12 +33,15 @@ import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.TextView; class FindActionModeCallback implements ActionMode.Callback, TextWatcher, View.OnClickListener { /** * @hide */ public class FindActionModeCallback implements ActionMode.Callback, TextWatcher, View.OnClickListener, WebView.FindListener { private View mCustomView; private EditText mEditText; private TextView mMatches; private WebViewClassic mWebView; private WebView mWebView; private InputMethodManager mInput; private Resources mResources; private boolean mMatchesFound; Loading @@ -46,7 +49,7 @@ class FindActionModeCallback implements ActionMode.Callback, TextWatcher, private int mActiveMatchIndex; private ActionMode mActionMode; FindActionModeCallback(Context context) { public FindActionModeCallback(Context context) { mCustomView = LayoutInflater.from(context).inflate( com.android.internal.R.layout.webview_find, null); mEditText = (EditText) mCustomView.findViewById( Loading @@ -61,7 +64,7 @@ class FindActionModeCallback implements ActionMode.Callback, TextWatcher, mResources = context.getResources(); } void finish() { public void finish() { mActionMode.finish(); } Loading @@ -69,7 +72,7 @@ class FindActionModeCallback implements ActionMode.Callback, TextWatcher, * Place text in the text field so it can be searched for. Need to press * the find next or find previous button to find all of the matches. */ void setText(String text) { public void setText(String text) { mEditText.setText(text); Spannable span = (Spannable) mEditText.getText(); int length = span.length(); Loading @@ -84,15 +87,23 @@ class FindActionModeCallback implements ActionMode.Callback, TextWatcher, } /* * Set the WebView to search. Must be non null, and set before calling * startActionMode. * Set the WebView to search. Must be non null. */ void setWebView(WebViewClassic webView) { public void setWebView(WebView webView) { if (null == webView) { throw new AssertionError("WebView supplied to " + "FindActionModeCallback cannot be null"); } mWebView = webView; mWebView.setFindDialogFindListener(this); } @Override public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches, boolean isDoneCounting) { if (isDoneCounting) { updateMatchCount(activeMatchOrdinal, numberOfMatches, numberOfMatches == 0); } } /* Loading Loading @@ -121,7 +132,7 @@ class FindActionModeCallback implements ActionMode.Callback, TextWatcher, /* * Highlight all the instances of the string from mEditText in mWebView. */ void findAll() { public void findAll() { if (mWebView == null) { throw new AssertionError( "No WebView for FindActionModeCallback::findAll"); Loading Loading @@ -208,7 +219,8 @@ class FindActionModeCallback implements ActionMode.Callback, TextWatcher, public void onDestroyActionMode(ActionMode mode) { mActionMode = null; mWebView.notifyFindDialogDismissed(); mInput.hideSoftInputFromWindow(mWebView.getWebView().getWindowToken(), 0); mWebView.setFindDialogFindListener(null); mInput.hideSoftInputFromWindow(mWebView.getWindowToken(), 0); } @Override Loading @@ -222,7 +234,7 @@ class FindActionModeCallback implements ActionMode.Callback, TextWatcher, throw new AssertionError( "No WebView for FindActionModeCallback::onActionItemClicked"); } mInput.hideSoftInputFromWindow(mWebView.getWebView().getWindowToken(), 0); mInput.hideSoftInputFromWindow(mWebView.getWindowToken(), 0); switch(item.getItemId()) { case com.android.internal.R.id.find_prev: findNext(false); Loading core/java/android/webkit/WebView.java +51 −1 Original line number Diff line number Diff line Loading @@ -1329,7 +1329,8 @@ public class WebView extends AbsoluteLayout */ public void setFindListener(FindListener listener) { checkThread(); mProvider.setFindListener(listener); setupFindListenerIfNeeded(); mFindListener.mUserFindListener = listener; } /** Loading Loading @@ -1849,12 +1850,61 @@ public class WebView extends AbsoluteLayout } //------------------------------------------------------------------------- // Package-private internal stuff //------------------------------------------------------------------------- // Only used by android.webkit.FindActionModeCallback. void setFindDialogFindListener(FindListener listener) { checkThread(); setupFindListenerIfNeeded(); mFindListener.mFindDialogFindListener = listener; } // Only used by android.webkit.FindActionModeCallback. void notifyFindDialogDismissed() { checkThread(); mProvider.notifyFindDialogDismissed(); } //------------------------------------------------------------------------- // Private internal stuff //------------------------------------------------------------------------- private WebViewProvider mProvider; /** * In addition to the FindListener that the user may set via the WebView.setFindListener * API, FindActionModeCallback will register it's own FindListener. We keep them separate * via this class so that that the two FindListeners can potentially exist at once. */ private class FindListenerDistributor implements FindListener { private FindListener mFindDialogFindListener; private FindListener mUserFindListener; @Override public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches, boolean isDoneCounting) { if (mFindDialogFindListener != null) { mFindDialogFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches, isDoneCounting); } if (mUserFindListener != null) { mUserFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches, isDoneCounting); } } } private FindListenerDistributor mFindListener; private void setupFindListenerIfNeeded() { if (mFindListener == null) { mFindListener = new FindListenerDistributor(); mProvider.setFindListener(mFindListener); } } private void ensureProviderCreated() { checkThread(); if (mProvider == null) { Loading core/java/android/webkit/WebViewClassic.java +3 −2 Original line number Diff line number Diff line Loading @@ -3668,7 +3668,7 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc mCachedOverlappingActionModeHeight = -1; mFindCallback = callback; setFindIsUp(true); mFindCallback.setWebView(this); mFindCallback.setWebView(getWebView()); if (showIme) { mFindCallback.showSoftInput(); } else if (text != null) { Loading Loading @@ -3770,7 +3770,8 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc /** * Called when the find ActionMode ends. */ void notifyFindDialogDismissed() { @Override public void notifyFindDialogDismissed() { mFindCallback = null; mCachedOverlappingActionModeHeight = -1; if (mWebViewCore == null) { Loading core/java/android/webkit/WebViewProvider.java +7 −1 Original line number Diff line number Diff line Loading @@ -240,7 +240,7 @@ public interface WebViewProvider { public View findHierarchyView(String className, int hashCode); //------------------------------------------------------------------------- // Provider glue methods // Provider internal methods //------------------------------------------------------------------------- /** Loading @@ -255,6 +255,12 @@ public interface WebViewProvider { */ /* package */ ScrollDelegate getScrollDelegate(); /** * Only used by FindActionModeCallback to inform providers that the find dialog has * been dismissed. */ public void notifyFindDialogDismissed(); //------------------------------------------------------------------------- // View / ViewGroup delegation methods //------------------------------------------------------------------------- Loading Loading
core/java/android/webkit/FindActionModeCallback.java +24 −12 Original line number Diff line number Diff line Loading @@ -33,12 +33,15 @@ import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.TextView; class FindActionModeCallback implements ActionMode.Callback, TextWatcher, View.OnClickListener { /** * @hide */ public class FindActionModeCallback implements ActionMode.Callback, TextWatcher, View.OnClickListener, WebView.FindListener { private View mCustomView; private EditText mEditText; private TextView mMatches; private WebViewClassic mWebView; private WebView mWebView; private InputMethodManager mInput; private Resources mResources; private boolean mMatchesFound; Loading @@ -46,7 +49,7 @@ class FindActionModeCallback implements ActionMode.Callback, TextWatcher, private int mActiveMatchIndex; private ActionMode mActionMode; FindActionModeCallback(Context context) { public FindActionModeCallback(Context context) { mCustomView = LayoutInflater.from(context).inflate( com.android.internal.R.layout.webview_find, null); mEditText = (EditText) mCustomView.findViewById( Loading @@ -61,7 +64,7 @@ class FindActionModeCallback implements ActionMode.Callback, TextWatcher, mResources = context.getResources(); } void finish() { public void finish() { mActionMode.finish(); } Loading @@ -69,7 +72,7 @@ class FindActionModeCallback implements ActionMode.Callback, TextWatcher, * Place text in the text field so it can be searched for. Need to press * the find next or find previous button to find all of the matches. */ void setText(String text) { public void setText(String text) { mEditText.setText(text); Spannable span = (Spannable) mEditText.getText(); int length = span.length(); Loading @@ -84,15 +87,23 @@ class FindActionModeCallback implements ActionMode.Callback, TextWatcher, } /* * Set the WebView to search. Must be non null, and set before calling * startActionMode. * Set the WebView to search. Must be non null. */ void setWebView(WebViewClassic webView) { public void setWebView(WebView webView) { if (null == webView) { throw new AssertionError("WebView supplied to " + "FindActionModeCallback cannot be null"); } mWebView = webView; mWebView.setFindDialogFindListener(this); } @Override public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches, boolean isDoneCounting) { if (isDoneCounting) { updateMatchCount(activeMatchOrdinal, numberOfMatches, numberOfMatches == 0); } } /* Loading Loading @@ -121,7 +132,7 @@ class FindActionModeCallback implements ActionMode.Callback, TextWatcher, /* * Highlight all the instances of the string from mEditText in mWebView. */ void findAll() { public void findAll() { if (mWebView == null) { throw new AssertionError( "No WebView for FindActionModeCallback::findAll"); Loading Loading @@ -208,7 +219,8 @@ class FindActionModeCallback implements ActionMode.Callback, TextWatcher, public void onDestroyActionMode(ActionMode mode) { mActionMode = null; mWebView.notifyFindDialogDismissed(); mInput.hideSoftInputFromWindow(mWebView.getWebView().getWindowToken(), 0); mWebView.setFindDialogFindListener(null); mInput.hideSoftInputFromWindow(mWebView.getWindowToken(), 0); } @Override Loading @@ -222,7 +234,7 @@ class FindActionModeCallback implements ActionMode.Callback, TextWatcher, throw new AssertionError( "No WebView for FindActionModeCallback::onActionItemClicked"); } mInput.hideSoftInputFromWindow(mWebView.getWebView().getWindowToken(), 0); mInput.hideSoftInputFromWindow(mWebView.getWindowToken(), 0); switch(item.getItemId()) { case com.android.internal.R.id.find_prev: findNext(false); Loading
core/java/android/webkit/WebView.java +51 −1 Original line number Diff line number Diff line Loading @@ -1329,7 +1329,8 @@ public class WebView extends AbsoluteLayout */ public void setFindListener(FindListener listener) { checkThread(); mProvider.setFindListener(listener); setupFindListenerIfNeeded(); mFindListener.mUserFindListener = listener; } /** Loading Loading @@ -1849,12 +1850,61 @@ public class WebView extends AbsoluteLayout } //------------------------------------------------------------------------- // Package-private internal stuff //------------------------------------------------------------------------- // Only used by android.webkit.FindActionModeCallback. void setFindDialogFindListener(FindListener listener) { checkThread(); setupFindListenerIfNeeded(); mFindListener.mFindDialogFindListener = listener; } // Only used by android.webkit.FindActionModeCallback. void notifyFindDialogDismissed() { checkThread(); mProvider.notifyFindDialogDismissed(); } //------------------------------------------------------------------------- // Private internal stuff //------------------------------------------------------------------------- private WebViewProvider mProvider; /** * In addition to the FindListener that the user may set via the WebView.setFindListener * API, FindActionModeCallback will register it's own FindListener. We keep them separate * via this class so that that the two FindListeners can potentially exist at once. */ private class FindListenerDistributor implements FindListener { private FindListener mFindDialogFindListener; private FindListener mUserFindListener; @Override public void onFindResultReceived(int activeMatchOrdinal, int numberOfMatches, boolean isDoneCounting) { if (mFindDialogFindListener != null) { mFindDialogFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches, isDoneCounting); } if (mUserFindListener != null) { mUserFindListener.onFindResultReceived(activeMatchOrdinal, numberOfMatches, isDoneCounting); } } } private FindListenerDistributor mFindListener; private void setupFindListenerIfNeeded() { if (mFindListener == null) { mFindListener = new FindListenerDistributor(); mProvider.setFindListener(mFindListener); } } private void ensureProviderCreated() { checkThread(); if (mProvider == null) { Loading
core/java/android/webkit/WebViewClassic.java +3 −2 Original line number Diff line number Diff line Loading @@ -3668,7 +3668,7 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc mCachedOverlappingActionModeHeight = -1; mFindCallback = callback; setFindIsUp(true); mFindCallback.setWebView(this); mFindCallback.setWebView(getWebView()); if (showIme) { mFindCallback.showSoftInput(); } else if (text != null) { Loading Loading @@ -3770,7 +3770,8 @@ public final class WebViewClassic implements WebViewProvider, WebViewProvider.Sc /** * Called when the find ActionMode ends. */ void notifyFindDialogDismissed() { @Override public void notifyFindDialogDismissed() { mFindCallback = null; mCachedOverlappingActionModeHeight = -1; if (mWebViewCore == null) { Loading
core/java/android/webkit/WebViewProvider.java +7 −1 Original line number Diff line number Diff line Loading @@ -240,7 +240,7 @@ public interface WebViewProvider { public View findHierarchyView(String className, int hashCode); //------------------------------------------------------------------------- // Provider glue methods // Provider internal methods //------------------------------------------------------------------------- /** Loading @@ -255,6 +255,12 @@ public interface WebViewProvider { */ /* package */ ScrollDelegate getScrollDelegate(); /** * Only used by FindActionModeCallback to inform providers that the find dialog has * been dismissed. */ public void notifyFindDialogDismissed(); //------------------------------------------------------------------------- // View / ViewGroup delegation methods //------------------------------------------------------------------------- Loading