diff options
-rw-r--r-- | assets/script.js | 35 | ||||
-rw-r--r-- | src/com/android/mail/ui/ConversationViewFragment.java | 16 |
2 files changed, 45 insertions, 6 deletions
diff --git a/assets/script.js b/assets/script.js index 39ee3c800..f458204ea 100644 --- a/assets/script.js +++ b/assets/script.js @@ -17,6 +17,10 @@ var BLOCKED_SRC_ATTR = "blocked-src"; +// the set of Elements currently scheduled for processing in handleAllImageLoads +// this is an Array, but we treat it like a Set and only insert unique items +var gImageLoadElements = []; + /** * Returns the page offset of an element. * @@ -165,14 +169,41 @@ function attachImageLoadListener(imageElement) { imageElement.src = originalSrc; } +/** + * Handle an onload event for an <img> tag. + * The image could be within an elided-text block, or at the top level of a message. + * When a new image loads, its new bounds may affect message or elided-text geometry, + * so we need to inspect and adjust the enclosing element's zoom level where necessary. + * + * Because this method can be called really often, and zoom-level adjustment is slow, + * we collect the elements to be processed and do them all later in a single deferred pass. + */ function imageOnLoad(e) { // normalize the quoted text parent if we're in a quoted text block, or else // normalize the parent message content element var parent = up(e.target, "elided-text") || up(e.target, "mail-message-content"); - if (parent) { - normalizeElementWidths([parent]); + if (!parent) { + // sanity check. shouldn't really happen. + return; } + + // if there was no previous work, schedule a new deferred job + if (gImageLoadElements.length == 0) { + window.setTimeout(handleAllImageOnLoads, 0); + } + + // enqueue the work if it wasn't already enqueued + if (gImageLoadElements.indexOf(parent) == -1) { + gImageLoadElements.push(parent); + } +} + +// handle all deferred work from image onload events +function handleAllImageOnLoads() { + normalizeElementWidths(gImageLoadElements); measurePositions(); + // clear the queue so the next onload event starts a new job + gImageLoadElements = []; } function blockImage(imageElement) { diff --git a/src/com/android/mail/ui/ConversationViewFragment.java b/src/com/android/mail/ui/ConversationViewFragment.java index 804fb9975..596d93b42 100644 --- a/src/com/android/mail/ui/ConversationViewFragment.java +++ b/src/com/android/mail/ui/ConversationViewFragment.java @@ -165,6 +165,8 @@ public final class ConversationViewFragment extends AbstractConversationViewFrag */ private boolean mWebViewLoadedData; + private long mWebViewLoadStartMs; + private final DataSetObserver mLoadedObserver = new DataSetObserver() { @Override public void onChanged() { @@ -528,6 +530,7 @@ public final class ConversationViewFragment extends AbstractConversationViewFrag mWebView.loadDataWithBaseURL(mBaseUri, convHtml, "text/html", "utf-8", null); mWebViewLoadedData = true; + mWebViewLoadStartMs = SystemClock.uptimeMillis(); } /** @@ -878,8 +881,9 @@ public final class ConversationViewFragment extends AbstractConversationViewFrag return; } - LogUtils.i(LOG_TAG, "IN CVF.onPageFinished, url=%s fragment=%s act=%s", url, - ConversationViewFragment.this, getActivity()); + LogUtils.i(LOG_TAG, "IN CVF.onPageFinished, url=%s fragment=%s t=%sms", url, + ConversationViewFragment.this, + (SystemClock.uptimeMillis() - mWebViewLoadStartMs)); super.onPageFinished(view, url); @@ -1004,8 +1008,12 @@ public final class ConversationViewFragment extends AbstractConversationViewFrag getHandler().post(new Runnable() { @Override public void run() { - LogUtils.d(LOG_TAG, "ANIMATION STARTED, ready to draw. t=%s", - SystemClock.uptimeMillis()); + if (mWebViewLoadStartMs != 0) { + LogUtils.i(LOG_TAG, "IN CVF.onContentReady, f=%s vis=%s t=%sms", + ConversationViewFragment.this, + isUserVisible(), + (SystemClock.uptimeMillis() - mWebViewLoadStartMs)); + } showConversation(conv); } }); |