OSDN Git Service

don't create the fake title bar when getGlobalVisible fails
[android-x86/packages-apps-Browser.git] / src / com / android / browser / BrowserActivity.java
index fd06d90..15f986e 100644 (file)
@@ -990,6 +990,13 @@ public class BrowserActivity extends Activity
         if (mFakeTitleBar == null && mActiveTabsPage == null
                 && !mActivityInPause && decor != null
                 && decor.getWindowToken() != null) {
+            Rect visRect = new Rect();
+            if (!mBrowserFrameLayout.getGlobalVisibleRect(visRect)) {
+                if (LOGD_ENABLED) {
+                    Log.d(LOGTAG, "showFakeTitleBar visRect failed");
+                }
+                return;
+            }
             final WebView webView = getTopWindow();
             mFakeTitleBar = new TitleBar(this);
             mFakeTitleBar.setTitleAndUrl(null, webView.getUrl());
@@ -1017,9 +1024,7 @@ public class BrowserActivity extends Activity
             // XXX : Without providing an offset, the fake title bar will be
             // placed underneath the status bar.  Use the global visible rect
             // of mBrowserFrameLayout to determine the bottom of the status bar
-            Rect rectangle = new Rect();
-            mBrowserFrameLayout.getGlobalVisibleRect(rectangle);
-            params.y = rectangle.top;
+            params.y = visRect.top;
             // Add a holder for the title bar.  It also holds a shadow to show
             // below the title bar.
             if (mFakeTitleBarHolder == null) {
@@ -1071,6 +1076,9 @@ public class BrowserActivity extends Activity
      * context menu.
      */
     /* package */ void showTitleBarContextMenu() {
+        if (null == mTitleBar.getParent()) {
+            return;
+        }
         openContextMenu(mTitleBar);
     }
 
@@ -1521,6 +1529,10 @@ public class BrowserActivity extends Activity
                 break;
 
             case R.id.goto_menu_id:
+                onSearchRequested();
+                break;
+
+            case R.id.bookmarks_menu_id:
                 bookmarksOrHistoryPicker(false);
                 break;
 
@@ -2309,12 +2321,15 @@ public class BrowserActivity extends Activity
     private static final int CANCEL_CREDS_REQUEST    = 103;
     private static final int RELEASE_WAKELOCK        = 107;
 
+    private static final int UPDATE_BOOKMARK_THUMBNAIL = 108;
+
     // Private handler for handling javascript and saving passwords
     private Handler mHandler = new Handler() {
 
         public void handleMessage(Message msg) {
             switch (msg.what) {
                 case FOCUS_NODE_HREF:
+                {
                     String url = (String) msg.getData().get("url");
                     if (url == null || url.length() == 0) {
                         break;
@@ -2357,6 +2372,7 @@ public class BrowserActivity extends Activity
                             break;
                     }
                     break;
+                }
 
                 case LOAD_URL:
                     loadURL(getTopWindow(), (String) msg.obj);
@@ -2375,6 +2391,13 @@ public class BrowserActivity extends Activity
                         mWakeLock.release();
                     }
                     break;
+
+                case UPDATE_BOOKMARK_THUMBNAIL:
+                    WebView view = (WebView) msg.obj;
+                    if (view != null) {
+                        updateScreenshot(view);
+                    }
+                    break;
             }
         }
     };
@@ -2452,10 +2475,10 @@ public class BrowserActivity extends Activity
         Canvas canvas = new Canvas(bm);
         // May need to tweak these values to determine what is the
         // best scale factor
-        int contentWidth = view.getContentWidth();
-        if (contentWidth > 0) {
-            float scaleFactor = (float) getDesiredThumbnailWidth(this)
-                    / (float) contentWidth;
+        int thumbnailWidth = thumbnail.getWidth();
+        if (thumbnailWidth > 0) {
+            float scaleFactor = (float) getDesiredThumbnailWidth(this) /
+                    (float)thumbnailWidth;
             canvas.scale(scaleFactor, scaleFactor);
         }
         thumbnail.draw(canvas);
@@ -2498,6 +2521,12 @@ public class BrowserActivity extends Activity
             resetLockIcon(url);
             setUrlTitle(url, null);
 
+            // We've started to load a new page. If there was a pending message
+            // to save a screenshot then we will now take the new page and
+            // save an incorrect screenshot. Therefore, remove any pending
+            // thumbnail messages from the queue.
+            mHandler.removeMessages(UPDATE_BOOKMARK_THUMBNAIL);
+
             // If we start a touch icon load and then load a new page, we don't
             // want to cancel the current touch icon loader. But, we do want to
             // create a new one when the touch icon url is known.
@@ -2578,7 +2607,8 @@ public class BrowserActivity extends Activity
             if (!mDidStopLoad) {
                 // Only update the bookmark screenshot if the user did not
                 // cancel the load early.
-                updateScreenshot(view);
+                Message updateScreenshot = Message.obtain(mHandler, UPDATE_BOOKMARK_THUMBNAIL, view);
+                mHandler.sendMessageDelayed(updateScreenshot, 500);
             }
 
             // Update the lock icon image only once we are done loading
@@ -2896,8 +2926,6 @@ public class BrowserActivity extends Activity
             Log.e(LOGTAG, "onReceivedError " + errorCode + " " + failingUrl
                     + " " + description);
 
-                mNeedExtraScreenShot = true;
-
             // We need to reset the title after an error.
             resetTitleAndRevertLockIcon();
         }
@@ -3227,14 +3255,6 @@ public class BrowserActivity extends Activity
                         hideFakeTitleBar();
                     }
                 }
-                if (mNeedExtraScreenShot) {
-                    // if there was an error loading this page, capture a new
-                    // screenshot to ensure that we get the correct thumbnail
-                    // as onPageFinished may have been called before the error
-                    // page was displayed.
-                    updateScreenshot(view);
-                    mNeedExtraScreenShot = false;
-                }
             } else if (!mInLoad) {
                 // onPageFinished may have already been called but a subframe
                 // is still loading and updating the progress. Reset mInLoad
@@ -4406,10 +4426,6 @@ public class BrowserActivity extends Activity
     private boolean mPageStarted;
     private boolean mActivityInPause = true;
 
-    // If the frame fails to load, we should snap a second screenshot
-    // to ensure that we get the right thumbnail (i.e. of the error page).
-    private boolean mNeedExtraScreenShot = false;
-
     private boolean mMenuIsDown;
 
     private static boolean mInTrace;