summaryrefslogtreecommitdiffstats
path: root/assets
diff options
context:
space:
mode:
authorAndy Huang <ath@google.com>2013-03-14 15:15:50 -0700
committerAndy Huang <ath@google.com>2013-03-14 15:41:04 -0700
commit05c70c88e6b421bedce134799a0ea928dbf44cd5 (patch)
tree9ed53f704ab1328b0199c96fd2261f88e3229edb /assets
parent973ae76e9e6e811c8cab646a997b05416808d553 (diff)
downloadandroid_packages_apps_UnifiedEmail-05c70c88e6b421bedce134799a0ea928dbf44cd5.tar.gz
android_packages_apps_UnifiedEmail-05c70c88e6b421bedce134799a0ea928dbf44cd5.tar.bz2
android_packages_apps_UnifiedEmail-05c70c88e6b421bedce134799a0ea928dbf44cd5.zip
report transform results to the conversation fragment
Also print it out in the message body in tiny text when the transforms succeeded. Change-Id: I942f707b5f7251f7aa9043c48fc0aa794c753065
Diffstat (limited to 'assets')
-rw-r--r--assets/script.js126
1 files changed, 89 insertions, 37 deletions
diff --git a/assets/script.js b/assets/script.js
index fbff8101c..51a9d69c5 100644
--- a/assets/script.js
+++ b/assets/script.js
@@ -30,6 +30,8 @@ var gScaleInfo;
*/
TRANSFORM_MINIMUM_EFFECTIVE_RATIO = 0.7;
+var gTransformText = {};
+
/**
* Returns the page offset of an element.
*
@@ -201,12 +203,23 @@ function transformContent(el, docWidth, elWidth) {
// entry := [ undoFunction, undoFunctionThis, undoFunctionParamArray ]
var actionLog = [];
var node;
+ var done = false;
+ var msgId;
+ var transformText;
+ var existingText;
+ var textElement;
var start;
if (elWidth <= docWidth) {
return;
}
start = Date.now();
+
+ if (el.parentElement.classList.contains("mail-message")) {
+ msgId = el.parentElement.id;
+ transformText = "[origW=" + elWidth + "/" + docWidth;
+ }
+
// Try munging all divs or textareas with inline styles where the width
// is wider than docWidth, and change it to be a max-width.
touched = false;
@@ -216,58 +229,97 @@ function transformContent(el, docWidth, elWidth) {
newWidth = el.scrollWidth;
console.log("ran div-width munger on el=" + el + " oldW=" + elWidth + " newW=" + newWidth
+ " docW=" + docWidth);
+ if (msgId) {
+ transformText += " DIV:newW=" + newWidth;
+ }
if (newWidth <= docWidth) {
- console.log("munger succeeded, elapsed time=" + (Date.now() - start));
- return;
+ done = true;
}
}
- // OK, that wasn't enough. Find images with widths and override their widths.
- nodes = ENABLE_MUNGE_IMAGES ? el.querySelectorAll("img") : [];
- touched = transformImages(nodes, docWidth, actionLog);
- if (touched) {
- newWidth = el.scrollWidth;
- console.log("ran img munger on el=" + el + " oldW=" + elWidth + " newW=" + newWidth
- + " docW=" + docWidth);
- if (newWidth <= docWidth) {
- console.log("munger succeeded, elapsed time=" + (Date.now() - start));
- return;
+ if (!done) {
+ // OK, that wasn't enough. Find images with widths and override their widths.
+ nodes = ENABLE_MUNGE_IMAGES ? el.querySelectorAll("img") : [];
+ touched = transformImages(nodes, docWidth, actionLog);
+ if (touched) {
+ newWidth = el.scrollWidth;
+ console.log("ran img munger on el=" + el + " oldW=" + elWidth + " newW=" + newWidth
+ + " docW=" + docWidth);
+ if (msgId) {
+ transformText += " IMG:newW=" + newWidth;
+ }
+ if (newWidth <= docWidth) {
+ done = true;
+ }
}
}
- // OK, that wasn't enough. Find tables with widths and override their widths.
- nodes = ENABLE_MUNGE_TABLES ? el.querySelectorAll("table") : [];
- touched = addClassToElements(nodes, shouldMungeTable, "munged",
- actionLog);
- if (touched) {
- newWidth = el.scrollWidth;
- console.log("ran table munger on el=" + el + " oldW=" + elWidth + " newW=" + newWidth
- + " docW=" + docWidth);
- if (newWidth <= docWidth) {
- console.log("munger succeeded, elapsed time=" + (Date.now() - start));
- return;
+ if (!done) {
+ // OK, that wasn't enough. Find tables with widths and override their widths.
+ nodes = ENABLE_MUNGE_TABLES ? el.querySelectorAll("table") : [];
+ touched = addClassToElements(nodes, shouldMungeTable, "munged",
+ actionLog);
+ if (touched) {
+ newWidth = el.scrollWidth;
+ console.log("ran table munger on el=" + el + " oldW=" + elWidth + " newW=" + newWidth
+ + " docW=" + docWidth);
+ if (msgId) {
+ transformText += " TABLE:newW=" + newWidth;
+ }
+ if (newWidth <= docWidth) {
+ done = true;
+ }
}
}
- // OK, that wasn't enough. Try munging all <td> to override any width and nowrap set.
- nodes = ENABLE_MUNGE_TABLES ? el.querySelectorAll("td") : [];
- touched = addClassToElements(nodes, null /* mungeAll */, "munged",
- actionLog);
- if (touched) {
- newWidth = el.scrollWidth;
- console.log("ran td munger on el=" + el + " oldW=" + elWidth + " newW=" + newWidth
- + " docW=" + docWidth);
- if (newWidth <= docWidth) {
- console.log("munger succeeded, elapsed time=" + (Date.now() - start));
- return;
+ if (!done) {
+ // OK, that wasn't enough. Try munging all <td> to override any width and nowrap set.
+ nodes = ENABLE_MUNGE_TABLES ? el.querySelectorAll("td") : [];
+ touched = addClassToElements(nodes, null /* mungeAll */, "munged",
+ actionLog);
+ if (touched) {
+ newWidth = el.scrollWidth;
+ console.log("ran td munger on el=" + el + " oldW=" + elWidth + " newW=" + newWidth
+ + " docW=" + docWidth);
+ if (msgId) {
+ transformText += " TD:newW=" + newWidth;
+ }
+ if (newWidth <= docWidth) {
+ done = true;
+ }
}
}
// If the transformations shrank the width significantly enough, leave them in place.
// We figure that in those cases, the benefits outweight the risk of rendering artifacts.
- if ((elWidth - newWidth) / (elWidth - docWidth) > TRANSFORM_MINIMUM_EFFECTIVE_RATIO) {
- console.log("transform(s) deemed effective enough. elapsed time="
- + (Date.now() - start));
+ if (!done && (elWidth - newWidth) / (elWidth - docWidth) >
+ TRANSFORM_MINIMUM_EFFECTIVE_RATIO) {
+ console.log("transform(s) deemed effective enough");
+ done = true;
+ }
+
+ if (done) {
+ if (msgId) {
+ transformText += "]";
+ existingText = gTransformText[msgId];
+ if (!existingText) {
+ transformText = "Message transforms: " + transformText;
+ } else {
+ transformText = existingText + " " + transformText;
+ }
+ gTransformText[msgId] = transformText;
+ window.mail.onMessageTransform(msgId, transformText);
+ textElement = el.firstChild;
+ if (!textElement.classList || !textElement.classList.contains("transform-text")) {
+ textElement = document.createElement("div");
+ textElement.classList.add("transform-text");
+ textElement.style.fontSize = "10px";
+ textElement.style.color = "#ccc";
+ el.insertBefore(textElement, el.firstChild);
+ }
+ textElement.innerHTML = transformText + "<br>";
+ }
+ console.log("munger(s) succeeded, elapsed time=" + (Date.now() - start));
return;
}