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());
// 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) {
* context menu.
*/
/* package */ void showTitleBarContextMenu() {
+ if (null == mTitleBar.getParent()) {
+ return;
+ }
openContextMenu(mTitleBar);
}
break;
case R.id.goto_menu_id:
+ onSearchRequested();
+ break;
+
+ case R.id.bookmarks_menu_id:
bookmarksOrHistoryPicker(false);
break;
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;
break;
}
break;
+ }
case LOAD_URL:
loadURL(getTopWindow(), (String) msg.obj);
mWakeLock.release();
}
break;
+
+ case UPDATE_BOOKMARK_THUMBNAIL:
+ WebView view = (WebView) msg.obj;
+ if (view != null) {
+ updateScreenshot(view);
+ }
+ break;
}
}
};
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);
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.
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
Log.e(LOGTAG, "onReceivedError " + errorCode + " " + failingUrl
+ " " + description);
- mNeedExtraScreenShot = true;
-
// We need to reset the title after an error.
resetTitleAndRevertLockIcon();
}
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
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;