Title: [93728] trunk
Revision
93728
Author
[email protected]
Date
2011-08-24 13:20:57 -0700 (Wed, 24 Aug 2011)

Log Message

[CSSRegions] Fix Element::getBoundingClientRect and Element::getClientRects for content flow
https://bugs.webkit.org/show_bug.cgi?id=66641

Original author of the patch is Mihnea Ovidenie <[email protected]>.

Source/WebCore:

Redirected the mapLocalToContainer method to the appropriate RenderRegion.

Note: RenderObject::absoluteQuads method needs some refactor to support multiple regions,
will do that in a separate bug.

Patch by Alexandru Chiculita <[email protected]> on 2011-08-24
Reviewed by David Hyatt.

Tests: fast/regions/flowed-content-bounding-client-rect-horizontal-bt.html
       fast/regions/flowed-content-bounding-client-rect-vertical-rl.html
       fast/regions/flowed-content-bounding-client-rect-vertical.html
       fast/regions/flowed-content-bounding-client-rect.html
       fast/regions/flowed-content-transform-bounding-client-rect.html

* rendering/RenderBox.cpp:
(WebCore::RenderBox::mapLocalToContainer):
* rendering/RenderFlowThread.cpp:
(WebCore::RenderFlowThread::renderRegionForLine):
(WebCore::RenderFlowThread::mapFromFlowToRegion):
* rendering/RenderFlowThread.h:

LayoutTests:

Patch by Alexandru Chiculita <[email protected]> on 2011-08-24
Reviewed by David Hyatt.

* fast/regions/flowed-content-bounding-client-rect-expected.txt: Added.
* fast/regions/flowed-content-bounding-client-rect-horizontal-bt-expected.txt: Added.
* fast/regions/flowed-content-bounding-client-rect-horizontal-bt.html: Added.
* fast/regions/flowed-content-bounding-client-rect-vertical-expected.txt: Added.
* fast/regions/flowed-content-bounding-client-rect-vertical-rl-expected.txt: Added.
* fast/regions/flowed-content-bounding-client-rect-vertical-rl.html: Added.
* fast/regions/flowed-content-bounding-client-rect-vertical.html: Added.
* fast/regions/flowed-content-bounding-client-rect.html: Added.
* fast/regions/flowed-content-transform-bounding-client-rect-expected.txt: Added.
* fast/regions/flowed-content-transform-bounding-client-rect.html: Added.
* fast/regions/resources/helper.js: Added.
(rectToArray):
(areEqualNumbers):
(areEqualRects):
(assertEqualRects):
(testBoundingRects):

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (93727 => 93728)


--- trunk/LayoutTests/ChangeLog	2011-08-24 20:17:43 UTC (rev 93727)
+++ trunk/LayoutTests/ChangeLog	2011-08-24 20:20:57 UTC (rev 93728)
@@ -1,3 +1,29 @@
+2011-08-24  Alexandru Chiculita  <[email protected]>
+
+        [CSSRegions] Fix Element::getBoundingClientRect and Element::getClientRects for content flow
+        https://bugs.webkit.org/show_bug.cgi?id=66641
+
+        Original author of the patch is Mihnea Ovidenie <[email protected]>.
+
+        Reviewed by David Hyatt.
+
+        * fast/regions/flowed-content-bounding-client-rect-expected.txt: Added.
+        * fast/regions/flowed-content-bounding-client-rect-horizontal-bt-expected.txt: Added.
+        * fast/regions/flowed-content-bounding-client-rect-horizontal-bt.html: Added.
+        * fast/regions/flowed-content-bounding-client-rect-vertical-expected.txt: Added.
+        * fast/regions/flowed-content-bounding-client-rect-vertical-rl-expected.txt: Added.
+        * fast/regions/flowed-content-bounding-client-rect-vertical-rl.html: Added.
+        * fast/regions/flowed-content-bounding-client-rect-vertical.html: Added.
+        * fast/regions/flowed-content-bounding-client-rect.html: Added.
+        * fast/regions/flowed-content-transform-bounding-client-rect-expected.txt: Added.
+        * fast/regions/flowed-content-transform-bounding-client-rect.html: Added.
+        * fast/regions/resources/helper.js: Added.
+        (rectToArray):
+        (areEqualNumbers):
+        (areEqualRects):
+        (assertEqualRects):
+        (testBoundingRects):
+
 2011-08-24  Nate Chapin  <[email protected]>
 
         Test for https://bugs.webkit.org/show_bug.cgi?id=45202.

Added: trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-expected.txt (0 => 93728)


--- trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-expected.txt	2011-08-24 20:20:57 UTC (rev 93728)
@@ -0,0 +1 @@
+PASS

Added: trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-horizontal-bt-expected.txt (0 => 93728)


--- trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-horizontal-bt-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-horizontal-bt-expected.txt	2011-08-24 20:20:57 UTC (rev 93728)
@@ -0,0 +1 @@
+PASS

Added: trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-horizontal-bt.html (0 => 93728)


--- trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-horizontal-bt.html	                        (rev 0)
+++ trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-horizontal-bt.html	2011-08-24 20:20:57 UTC (rev 93728)
@@ -0,0 +1,55 @@
+<!DOCTYPE html>
+
+<link rel="stylesheet" href=""
+<script type="text/_javascript_" charset="utf-8" src=""
+
+<style>
+    html { -webkit-writing-mode: horizontal-bt; }
+
+    body { margin: 10px; }
+
+    #region1 {
+        position: absolute;
+        left: 100px;
+        top: 10px;
+        width: 50px;
+        height: 100px;
+    }
+
+    #region2 {
+        position: absolute;
+        top: 10px;
+        left: 200px;
+        width: 50px;
+        height: 50px;
+        padding: 10px 20px 30px 40px;
+        border: 1px solid black;
+    }
+    
+    .finished #region1, .finished #region2 {
+        display: none;
+    }
+</style>
+
+<div id="flow" class="flowArticle">
+    <div id="green" class="greenBox"></div>
+    <div id="blue" class="blueBox"></div>
+    <div id="orange" class="orangeBox"></div>
+</div>
+
+<div id="region1" class="regionArticle"></div>
+<div id="region2" class="regionArticle"></div>
+
+<script>
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+
+    var expectedBoundingRects = {
+        green: [60, 100, 110, 150, 50, 50],
+        blue: [10, 100, 60, 150, 50, 50],
+        orange: [21, 241, 71, 291, 50, 50]
+    };
+    
+    if (testBoundingRects(expectedBoundingRects))
+        document.body.className = "finished";
+</script>

Added: trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-vertical-expected.txt (0 => 93728)


--- trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-vertical-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-vertical-expected.txt	2011-08-24 20:20:57 UTC (rev 93728)
@@ -0,0 +1 @@
+PASS

Added: trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-vertical-rl-expected.txt (0 => 93728)


--- trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-vertical-rl-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-vertical-rl-expected.txt	2011-08-24 20:20:57 UTC (rev 93728)
@@ -0,0 +1 @@
+PASS

Added: trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-vertical-rl.html (0 => 93728)


--- trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-vertical-rl.html	                        (rev 0)
+++ trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-vertical-rl.html	2011-08-24 20:20:57 UTC (rev 93728)
@@ -0,0 +1,51 @@
+<!DOCTYPE html>
+
+<link rel="stylesheet" href=""
+<script type="text/_javascript_" charset="utf-8" src=""
+
+<style>
+    html { -webkit-writing-mode: vertical-rl; }
+
+    body { margin: 10px; }
+
+    #region1 {
+        position: absolute;
+        left: 100px;
+        width: 100px;
+        height: 50px;
+    }
+
+    #region2 {
+        position: absolute;
+        left: 200px;
+        width: 50px;
+        height: 50px;
+    }
+    
+    .finished #region1, .finished #region2 {
+        display: none;
+    }
+</style>
+
+<div id="flow" class="flowArticle">
+    <div id="green" class="greenBox"></div>
+    <div id="blue" class="blueBox"></div>
+    <div id="orange" class="orangeBox"></div>
+</div>
+
+<div id="region1" class="regionArticle"></div>
+<div id="region2" class="regionArticle"></div>
+
+<script>
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+
+    var expectedBoundingRects = {
+        green: [10, 150, 60, 200, 50, 50],
+        blue: [10, 100, 60, 150, 50, 50],
+        orange: [10, 200, 60, 250, 50, 50]
+    };
+    
+    if (testBoundingRects(expectedBoundingRects))
+        document.body.className = "finished";
+</script>

Added: trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-vertical.html (0 => 93728)


--- trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-vertical.html	                        (rev 0)
+++ trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect-vertical.html	2011-08-24 20:20:57 UTC (rev 93728)
@@ -0,0 +1,53 @@
+<!DOCTYPE html>
+
+<link rel="stylesheet" href=""
+<script type="text/_javascript_" charset="utf-8" src=""
+
+<style>
+    html { -webkit-writing-mode: vertical-lr; }
+
+    body { margin: 10px; }
+
+    #region1 {
+        position: absolute;
+        left: 100px;
+        width: 100px;
+        height: 50px;
+    }
+
+    #region2 {
+        position: absolute;
+        left: 240px;
+        width: 60px;
+        height: 70px;
+        padding: 10px 20px 30px 40px;
+        border: 1px solid black;
+    }
+    
+    .finished #region1, .finished #region2 {
+        display: none;
+    }
+</style>
+
+<div id="flow" class="flowArticle">
+    <div id="green" class="greenBox"></div>
+    <div id="blue" class="blueBox"></div>
+    <div id="orange" class="orangeBox"></div>
+</div>
+
+<div id="region1" class="regionArticle"></div>
+<div id="region2" class="regionArticle"></div>
+
+<script>
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+
+    var expectedBoundingRects = {
+        green: [10, 100, 60, 150, 50, 50],
+        blue: [10, 150, 60, 200, 50, 50],
+        orange: [21, 281, 71, 331, 50, 50]
+    };
+    
+    if (testBoundingRects(expectedBoundingRects))
+        document.body.className = "finished";
+</script>

Added: trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect.html (0 => 93728)


--- trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect.html	                        (rev 0)
+++ trunk/LayoutTests/fast/regions/flowed-content-bounding-client-rect.html	2011-08-24 20:20:57 UTC (rev 93728)
@@ -0,0 +1,60 @@
+<!DOCTYPE html>
+
+<link rel="stylesheet" href=""
+<script type="text/_javascript_" charset="utf-8" src=""
+
+<style>
+    body { margin: 10px; }
+
+    .box {
+        width: 50px;
+        height: 50px;
+        float: left;
+    }
+
+    #region1 {
+        position: absolute;
+        padding: 10px;
+    }
+
+    #region2 {
+        position: absolute;
+        left: 100px;
+        border: 10px solid black;
+    }
+
+    #region3 {
+        position: absolute;
+        left: 200px;
+        padding: 10px;
+        border: 10px solid black;
+    }
+    
+    .finished #region1, .finished #region2, .finished #region3 {
+        display: none;
+    }
+</style>
+
+<div class="flowArticle">
+    <div id="green" class="greenBox"></div>
+    <div id="blue" class="blueBox"></div>
+    <div id="orange" class="orangeBox"></div>
+</div>
+
+<div id="region1" class="regionArticle box"></div>
+<div id="region2" class="regionArticle box"></div>
+<div id="region3" class="regionArticle box"></div>
+
+<script>
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+    
+    var expectedBoundingRects = {
+        green: [20, 20, 70, 70, 50, 50],
+        blue: [20, 110, 70, 160, 50, 50],
+        orange: [30, 220, 80, 270, 50, 50]
+    };
+    
+    if (testBoundingRects(expectedBoundingRects))
+        document.body.className = "finished";
+</script>

Added: trunk/LayoutTests/fast/regions/flowed-content-transform-bounding-client-rect-expected.txt (0 => 93728)


--- trunk/LayoutTests/fast/regions/flowed-content-transform-bounding-client-rect-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/regions/flowed-content-transform-bounding-client-rect-expected.txt	2011-08-24 20:20:57 UTC (rev 93728)
@@ -0,0 +1 @@
+PASS

Added: trunk/LayoutTests/fast/regions/flowed-content-transform-bounding-client-rect.html (0 => 93728)


--- trunk/LayoutTests/fast/regions/flowed-content-transform-bounding-client-rect.html	                        (rev 0)
+++ trunk/LayoutTests/fast/regions/flowed-content-transform-bounding-client-rect.html	2011-08-24 20:20:57 UTC (rev 93728)
@@ -0,0 +1,45 @@
+<!DOCTYPE html>
+
+<link rel="stylesheet" href=""
+<script type="text/_javascript_" charset="utf-8" src=""
+
+<style>
+    body { margin: 10px; }
+
+    .box {
+        width: 50px;
+        height: 50px;
+        float: left;
+    }
+
+    #region1 { -webkit-transform: translate(10px, 10px); }
+    #region2 { -webkit-transform: translate(30px, 20px) rotate(45deg); }
+    #region3 { -webkit-transform: translate(70px, 30px) scale(2,2); }
+    
+    .finished #region1, .finished #region2, .finished #region3 {
+        display: none;
+    }
+</style>
+
+<div class="flowArticle">
+    <div id="green" class="greenBox"></div>
+    <div id="blue" class="blueBox"></div>
+    <div id="orange" class="orangeBox"></div>
+</div>
+<div id="region1" class="regionArticle box"></div>
+<div id="region2" class="regionArticle box"></div>
+<div id="region3" class="regionArticle box"></div>
+
+<script>
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+                                   
+    var expectedBoundingRects = {
+        green: [20, 20, 70, 70, 50, 50],
+        blue: [20, 80, 90, 150, 70, 70],
+        orange: [15, 155, 115, 255, 100, 100]
+    };
+    
+    if (testBoundingRects(expectedBoundingRects, 1))
+        document.body.className = "finished";
+</script>

Added: trunk/LayoutTests/fast/regions/resources/helper.js (0 => 93728)


--- trunk/LayoutTests/fast/regions/resources/helper.js	                        (rev 0)
+++ trunk/LayoutTests/fast/regions/resources/helper.js	2011-08-24 20:20:57 UTC (rev 93728)
@@ -0,0 +1,45 @@
+function rectToArray(rect) {
+    return [rect.top, rect.left, rect.bottom, rect.right, rect.width, rect.height];
+}
+
+function areEqualNumbers(actual, expected, tolerance) {
+    var diff = Math.abs(actual - expected);
+    return diff <= tolerance;
+}
+
+function areEqualRects(r1, r2, tolerance) {
+    if (r1.length != r2.length)
+        return false;
+    
+    for (var i = 0; i < r1.length; ++i)
+        if (!areEqualNumbers(r1[i], r2[i], tolerance))
+            return false;
+    
+    return true;
+}
+
+function assertEqualRects(results, name, actualRect, expectedRect, tolerance) {
+    if (areEqualRects(actualRect, expectedRect, tolerance))
+        return;
+
+    results.push("FAIL(" + name + " bounding rect was: [" + actualRect.join(", ") + "], expected: [" + expectedRect.join(", ") + "]");
+}
+
+function testBoundingRects(expectedBoundingRects, tolerance)
+{
+    if (tolerance === undefined)
+        tolerance = 0;
+
+    var results = [];
+
+    for (var name in expectedBoundingRects) {
+        if (!expectedBoundingRects.hasOwnProperty(name))
+            continue;
+        var rect = document.getElementById(name).getBoundingClientRect();
+        assertEqualRects(results, name, rectToArray(rect), expectedBoundingRects[name], tolerance);
+    }
+
+    document.write("<p>" + (results.length ? results.join("<br />") : "PASS") + "</p>");
+    
+    return !results.length;
+}
\ No newline at end of file

Modified: trunk/Source/WebCore/ChangeLog (93727 => 93728)


--- trunk/Source/WebCore/ChangeLog	2011-08-24 20:17:43 UTC (rev 93727)
+++ trunk/Source/WebCore/ChangeLog	2011-08-24 20:20:57 UTC (rev 93728)
@@ -1,3 +1,30 @@
+2011-08-24  Alexandru Chiculita  <[email protected]>
+
+        [CSSRegions] Fix Element::getBoundingClientRect and Element::getClientRects for content flow
+        https://bugs.webkit.org/show_bug.cgi?id=66641
+
+        Original author of the patch is Mihnea Ovidenie <[email protected]>.
+
+        Redirected the mapLocalToContainer method to the appropriate RenderRegion.
+
+        Note: RenderObject::absoluteQuads method needs some refactor to support multiple regions,
+        will do that in a separate bug.
+
+        Reviewed by David Hyatt.
+
+        Tests: fast/regions/flowed-content-bounding-client-rect-horizontal-bt.html
+               fast/regions/flowed-content-bounding-client-rect-vertical-rl.html
+               fast/regions/flowed-content-bounding-client-rect-vertical.html
+               fast/regions/flowed-content-bounding-client-rect.html
+               fast/regions/flowed-content-transform-bounding-client-rect.html
+
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::mapLocalToContainer):
+        * rendering/RenderFlowThread.cpp:
+        (WebCore::RenderFlowThread::renderRegionForLine):
+        (WebCore::RenderFlowThread::mapFromFlowToRegion):
+        * rendering/RenderFlowThread.h:
+
 2011-08-24  Alok Priyadarshi  <[email protected]>
 
         [chromium] Root layer is not updated when only a portion of tile is updated

Modified: trunk/Source/WebCore/rendering/RenderBox.cpp (93727 => 93728)


--- trunk/Source/WebCore/rendering/RenderBox.cpp	2011-08-24 20:17:43 UTC (rev 93727)
+++ trunk/Source/WebCore/rendering/RenderBox.cpp	2011-08-24 20:20:57 UTC (rev 93728)
@@ -41,9 +41,11 @@
 #include "Page.h"
 #include "PaintInfo.h"
 #include "RenderArena.h"
+#include "RenderFlowThread.h"
 #include "RenderInline.h"
 #include "RenderLayer.h"
 #include "RenderPart.h"
+#include "RenderRegion.h"
 #include "RenderTableCell.h"
 #include "RenderTheme.h"
 #include "RenderView.h"
@@ -1258,7 +1260,15 @@
         transformState.move(-containerOffset.width(), -containerOffset.height(), preserve3D ? TransformState::AccumulateTransform : TransformState::FlattenTransform);
         return;
     }
-    
+
+    if (o->isRenderFlowThread()) {
+        // Transform from render flow coordinates into region coordinates.
+        RenderRegion* region = toRenderFlowThread(o)->mapFromFlowToRegion(transformState);
+        if (region)
+            region->mapLocalToContainer(region->containerForRepaint(), fixed, useTransforms, transformState, wasFixed);
+        return;
+    }
+
     o->mapLocalToContainer(repaintContainer, fixed, useTransforms, transformState, wasFixed);
 }
 

Modified: trunk/Source/WebCore/rendering/RenderFlowThread.cpp (93727 => 93728)


--- trunk/Source/WebCore/rendering/RenderFlowThread.cpp	2011-08-24 20:17:43 UTC (rev 93727)
+++ trunk/Source/WebCore/rendering/RenderFlowThread.cpp	2011-08-24 20:20:57 UTC (rev 93728)
@@ -38,6 +38,7 @@
 #include "RenderLayer.h"
 #include "RenderRegion.h"
 #include "RenderView.h"
+#include "TransformState.h"
 
 namespace WebCore {
 
@@ -471,9 +472,6 @@
 {
     ASSERT(!m_regionsInvalidated);
     
-    // All the regions should start at 0.
-    ASSERT(position >= 0);
-    
     // If no region matches the position and extendLastRegion is true, it will return
     // the last valid region. It is similar to auto extending the size of the last region. 
     RenderRegion* lastValidRegion = 0;
@@ -485,6 +483,9 @@
         if (!region->isValid())
             continue;
 
+        if (position <= 0)
+            return region;
+
         LayoutRect regionRect = region->regionRect();
 
         if (useHorizontalWritingMode) {
@@ -514,4 +515,30 @@
 }
 
 
+RenderRegion* RenderFlowThread::mapFromFlowToRegion(TransformState& transformState) const
+{
+    if (!hasValidRegions())
+        return 0;
+
+    LayoutRect boxRect = transformState.mappedQuad().enclosingBoundingBox();
+    flipForWritingMode(boxRect);
+
+    // FIXME: We need to refactor RenderObject::absoluteQuads to be able to split the quads across regions,
+    // for now we just take the center of the mapped enclosing box and map it to a region.
+    // Note: Using the center in order to avoid rounding errors.
+
+    const bool extendLastRegion = true;
+    LayoutPoint center = boxRect.center();
+    RenderRegion* renderRegion = renderRegionForLine(isHorizontalWritingMode() ? center.y() : center.x(), extendLastRegion);
+    if (!renderRegion)
+        return 0;
+
+    LayoutRect flippedRegionRect(renderRegion->regionRect());
+    flipForWritingMode(flippedRegionRect);
+
+    transformState.move(renderRegion->contentBoxRect().location() - flippedRegionRect.location());
+
+    return renderRegion;
+}
+
 } // namespace WebCore

Modified: trunk/Source/WebCore/rendering/RenderFlowThread.h (93727 => 93728)


--- trunk/Source/WebCore/rendering/RenderFlowThread.h	2011-08-24 20:17:43 UTC (rev 93727)
+++ trunk/Source/WebCore/rendering/RenderFlowThread.h	2011-08-24 20:20:57 UTC (rev 93728)
@@ -103,6 +103,8 @@
     void disableRegionFitting() { m_regionFittingDisableCount++; }
     void enableRegionFitting() { ASSERT(m_regionFittingDisableCount > 0); m_regionFittingDisableCount--; }
 
+    RenderRegion* mapFromFlowToRegion(TransformState&) const;
+
 private:
     virtual const char* renderName() const { return "RenderFlowThread"; }
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to