Reviewers: shindig.remailer_gmail.com, mhermanto,

Description:
@see https://issues.apache.org/jira/browse/SHINDIG-1155

Patch #2, provided by Michael Hermanto (try #2)

Please review this at http://codereview.appspot.com/107051

Affected files:
  features/src/main/javascript/features/dynamic-height/dynamic-height.js


Index: features/src/main/javascript/features/dynamic-height/dynamic-height.js
===================================================================
--- features/src/main/javascript/features/dynamic-height/dynamic-height.js (revision 803826) +++ features/src/main/javascript/features/dynamic-height/dynamic-height.js (working copy)
@@ -39,6 +39,7 @@

   /**
* Parse out the value (specified in px) for a CSS attribute of an element.
+   *
    * @param {Object} elem the element with the attribute to look for.
    * @param {String} attr the CSS attribute name of interest.
    * @returns {int} the value of the px attr of the elem.
@@ -51,22 +52,36 @@
   }

   /**
-   * Calculate the height of the gadget iframe by iterating through the
-   * elements in the gadget body for Webkit.
+ * For Webkit-based browsers, calculate the height of the gadget iframe by + * iterating through all elements in the gadget, starting with the body tag.
+   * It is not sufficient to only account body children elements, because
+   * CSS style position "float" may place a child element outside of the
+   * containing parent element. Not counting "float" elements may lead to
+   * undercounting.
+   *
    * @returns {int} the height of the gadget.
    */
   function getHeightForWebkit() {
     var result = 0;
-    var children = document.body.childNodes;
-    for (var i = 0; i < children.length; i++) {
-      if (typeof children[i].offsetTop !== 'undefined' &&
-          typeof children[i].scrollHeight !== 'undefined') {
- // scrollHeight already accounts for border-bottom and padding-bottom.
-        var bottom = children[i].offsetTop + children[i].scrollHeight
-            + parseIntFromElemPxAttribute(children[i], "margin-bottom");
-        result = Math.max(result, bottom);
+    var queue = [ document.body ];
+
+    while (queue.length > 0) {
+      var elem = queue.shift();
+      var children = elem.childNodes;
+
+      for (var i = 0; i < children.length; i++) {
+        var child = children[i];
+        if (typeof child.offsetTop !== 'undefined'
+            && typeof child.scrollHeight !== 'undefined') {
+ // scrollHeight already accounts for border-bottom, padding-bottom.
+          var bottom = child.offsetTop + child.scrollHeight +
+              parseIntFromElemPxAttribute(child, "margin-bottom");
+          result = Math.max(result, bottom);
+        }
+        queue.push(child);
       }
-    }
+    }
+
     // Add border, padding and margin of the containing body.
     return result
         + parseIntFromElemPxAttribute(document.body, "border-bottom")


Reply via email to