Allow interaction with page while Find is up.
In order to do this, I have changed the FindDialog from
an actual Dialog, which steals all touch events, to
a Linearlayout, which rests below the WebView.
Also dismiss Find when the user opens/closes a subwindow,
or navigates to a new page.
res/layout/browser_subwindow.xml:
Add an id to the holder for the subwindow, so it can be
used to add the FindDialog.
res/values/styles.xml:
Remove the style for FindDialog, as the animations are
now added in code (since FindDialog is now a LinearLayout,
which has no theme).
res/values/themes.xml:
Deleted, as the only theme there was FindDialog, which has
been removed.
src/com/android/browser/BrowserActivity.java:
closeFind is now the starting point for removing the
FindDialog, so that it can be called from Tab.
Close the FindDialog when a new page starts loading.
Call showFind on the current Tab.
src/com/android/browser/FindDialog.java
Change from a Dialog to a LinearLayout, so it can be
inserted into the layout.
Call closeFind directly, which now calls dismiss.
Perform the animations which were previously part
of the theme.
Remove the call to set the height of the find dialog,
which is no longer necessary.
Open and close the IME when opening and closing Find.
src/com/android/browser/Tab.java
Change pointer to mContainer to a LinearLayout, which is
used to add the FindDialog.
Add a pointer to BrowserActivity to SubWindowClient, which
is then used to close the FindDialog in onPageStarted.
Close find when adding/removing a Tab or its subwindow.
Add showFind, which attaches it to the layout for the tab,
and closeFind, which removes it from the layout.
Requires a change to frameworks/base
Change-Id: If6745fb65c5628da827781a7b98061e87b279844
diff --git a/src/com/android/browser/Tab.java b/src/com/android/browser/Tab.java
index 2dac050..12f0cf6 100644
--- a/src/com/android/browser/Tab.java
+++ b/src/com/android/browser/Tab.java
@@ -87,7 +87,7 @@
// The Geolocation permissions prompt
private GeolocationPermissionsPrompt mGeolocationPermissionsPrompt;
// Main WebView wrapper
- private View mContainer;
+ private LinearLayout mContainer;
// Main WebView
private WebView mMainView;
// Subwindow container
@@ -1205,9 +1205,18 @@
private static class SubWindowClient extends WebViewClient {
// The main WebViewClient.
private final WebViewClient mClient;
+ private final BrowserActivity mBrowserActivity;
- SubWindowClient(WebViewClient client) {
+ SubWindowClient(WebViewClient client, BrowserActivity activity) {
mClient = client;
+ mBrowserActivity = activity;
+ }
+ @Override
+ public void onPageStarted(WebView view, String url, Bitmap favicon) {
+ // Unlike the others, do not call mClient's version, which would
+ // change the progress bar. However, we do want to remove the
+ // find dialog.
+ if (view.getFindIsUp()) mBrowserActivity.closeFind();
}
@Override
public void doUpdateVisitedHistory(WebView view, String url,
@@ -1297,7 +1306,7 @@
// The tab consists of a container view, which contains the main
// WebView, as well as any other UI elements associated with the tab.
- mContainer = mInflateService.inflate(R.layout.tab, null);
+ mContainer = (LinearLayout) mInflateService.inflate(R.layout.tab, null);
mDownloadListener = new DownloadListener() {
public void onDownloadStart(String url, String userAgent,
@@ -1408,6 +1417,7 @@
*/
boolean createSubWindow() {
if (mSubView == null) {
+ if (mMainView.getFindIsUp()) mActivity.closeFind();
mSubViewContainer = mInflateService.inflate(
R.layout.browser_subwindow, null);
mSubView = (WebView) mSubViewContainer.findViewById(R.id.webview);
@@ -1416,7 +1426,8 @@
mSubView.setMapTrackballToArrowKeys(false);
// Enable the built-in zoom
mSubView.getSettings().setBuiltInZoomControls(true);
- mSubView.setWebViewClient(new SubWindowClient(mWebViewClient));
+ mSubView.setWebViewClient(new SubWindowClient(mWebViewClient,
+ mActivity));
mSubView.setWebChromeClient(new SubWindowChromeClient(
mWebChromeClient));
// Set a different DownloadListener for the mSubView, since it will
@@ -1454,6 +1465,9 @@
*/
void dismissSubWindow() {
if (mSubView != null) {
+ if (mSubView.getFindIsUp()) {
+ mActivity.closeFind();
+ }
BrowserSettings.getInstance().deleteObserver(
mSubView.getSettings());
mSubView.destroy();
@@ -1478,6 +1492,7 @@
void removeSubWindow(ViewGroup content) {
if (mSubView != null) {
content.removeView(mSubViewContainer);
+ if (mSubView.getFindIsUp()) mActivity.closeFind();
}
}
@@ -1536,6 +1551,7 @@
(FrameLayout) mContainer.findViewById(R.id.webview_wrapper);
wrapper.removeView(mMainView);
content.removeView(mContainer);
+ if (mMainView.getFindIsUp()) mActivity.closeFind();
removeSubWindow(content);
}
@@ -1931,4 +1947,36 @@
}
return true;
}
+
+ /*
+ * Open the find dialog. Called by BrowserActivity.
+ */
+ void showFind(FindDialog dialog) {
+ LinearLayout container;
+ WebView view;
+ if (mSubView != null) {
+ view = mSubView;
+ container = (LinearLayout) mSubViewContainer.findViewById(
+ R.id.inner_container);
+ } else {
+ view = mMainView;
+ container = mContainer;
+ }
+ dialog.show();
+ container.addView(dialog, new LinearLayout.LayoutParams(
+ ViewGroup.LayoutParams.MATCH_PARENT,
+ ViewGroup.LayoutParams.WRAP_CONTENT));
+ dialog.setWebView(view);
+ view.setFindIsUp(true);
+ }
+
+ /*
+ * Close the find dialog. Called by BrowserActivity.closeFind.
+ */
+ void closeFind(FindDialog dialog) {
+ // The dialog may be attached to the subwindow. Ensure that the
+ // correct parent has it removed.
+ LinearLayout parent = (LinearLayout) dialog.getParent();
+ if (parent != null) parent.removeView(dialog);
+ }
}