Title: [96152] trunk
Revision
96152
Author
[email protected]
Date
2011-09-27 13:55:00 -0700 (Tue, 27 Sep 2011)

Log Message

offsetTop/offsetLeft return the wrong values for horizontal-bt/vertical-rl writing modes
https://bugs.webkit.org/show_bug.cgi?id=68304

Reviewed by David Hyatt.

Source/WebCore:

When grabbing the x/y values of the RenderBox, we need to take writing mode
flipping into account.

Test: fast/dom/offset-position-writing-modes.html

* rendering/RenderBox.cpp:
(WebCore::RenderBox::locationIncludingFlipping):
* rendering/RenderBox.h:
(WebCore::RenderBox::yFlippedForWritingMode):
(WebCore::RenderBox::xFlippedForWritingMode):
* rendering/RenderBoxModelObject.cpp:
(WebCore::RenderBoxModelObject::offsetLeft):
(WebCore::RenderBoxModelObject::offsetTop):

LayoutTests:

* css3/flexbox/writing-modes-expected.txt:
* css3/flexbox/writing-modes.html:
* fast/dom/offset-position-writing-modes-expected.txt: Added.
* fast/dom/offset-position-writing-modes.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (96151 => 96152)


--- trunk/LayoutTests/ChangeLog	2011-09-27 20:54:16 UTC (rev 96151)
+++ trunk/LayoutTests/ChangeLog	2011-09-27 20:55:00 UTC (rev 96152)
@@ -1,3 +1,15 @@
+2011-09-27  Ojan Vafai  <[email protected]>
+
+        offsetTop/offsetLeft return the wrong values for horizontal-bt/vertical-rl writing modes
+        https://bugs.webkit.org/show_bug.cgi?id=68304
+
+        Reviewed by David Hyatt.
+
+        * css3/flexbox/writing-modes-expected.txt:
+        * css3/flexbox/writing-modes.html:
+        * fast/dom/offset-position-writing-modes-expected.txt: Added.
+        * fast/dom/offset-position-writing-modes.html: Added.
+
 2011-09-27  Tim Horton  <[email protected]>
 
         Rapidly refreshing a feMorphology[erode] with r=0 can sometimes cause display corruption

Modified: trunk/LayoutTests/css3/flexbox/writing-modes-expected.txt (96151 => 96152)


--- trunk/LayoutTests/css3/flexbox/writing-modes-expected.txt	2011-09-27 20:54:16 UTC (rev 96151)
+++ trunk/LayoutTests/css3/flexbox/writing-modes-expected.txt	2011-09-27 20:55:00 UTC (rev 96152)
@@ -12,6 +12,6 @@
 PASS
 PASS
 PASS
-Expected 580 for offsetLeft, but got 0. Expected 580 for offsetLeft, but got 0. Expected 580 for offsetLeft, but got 0.
-Expected 580 for offsetLeft, but got 0. Expected 180 for offsetTop, but got 0. Expected 580 for offsetLeft, but got 150. Expected 180 for offsetTop, but got 0. Expected 580 for offsetLeft, but got 450. Expected 180 for offsetTop, but got 0.
+PASS
+PASS
 

Modified: trunk/LayoutTests/css3/flexbox/writing-modes.html (96151 => 96152)


--- trunk/LayoutTests/css3/flexbox/writing-modes.html	2011-09-27 20:54:16 UTC (rev 96151)
+++ trunk/LayoutTests/css3/flexbox/writing-modes.html	2011-09-27 20:55:00 UTC (rev 96152)
@@ -158,7 +158,6 @@
   <div data-expected-height="250" style="height: -webkit-flex(1 1 400px);"></div>
 </div>
 
-<!-- FIXME: There's a bug where offsetLeft reports the wrong value in vertical-rl writing-mode.-->
 <div style="position:relative">
 <div class="flexbox vertical-rl">
   <div data-expected-height="150" data-offset-y="0" data-offset-x="580" style="height: -webkit-flex(1 0 0);"></div>
@@ -167,12 +166,11 @@
 </div>
 </div>
 
-<!-- FIXME: There's a bug where offsetTop reports the wrong value in horizontal-bt writing-mode.-->
 <div style="position:relative">
 <div class="flexbox bt" style="height:200px">
-  <div data-offset-y="180" data-offset-x="580" style="width: -webkit-flex(1 0 0);"></div>
-  <div data-offset-y="180" data-offset-x="580" style="width: -webkit-flex(2 0 0);"></div>
-  <div data-offset-y="180" data-offset-x="580" style="width: -webkit-flex(1 0 0);"></div>
+  <div data-expected-width="150" data-offset-y="180" data-offset-x="0" style="width: -webkit-flex(1 0 0);"></div>
+  <div data-expected-width="300" data-offset-y="180" data-offset-x="150" style="width: -webkit-flex(2 0 0);"></div>
+  <div data-expected-width="150" data-offset-y="180" data-offset-x="450" style="width: -webkit-flex(1 0 0);"></div>
 </div>
 </div>
 

Added: trunk/LayoutTests/fast/dom/offset-position-writing-modes-expected.txt (0 => 96152)


--- trunk/LayoutTests/fast/dom/offset-position-writing-modes-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/offset-position-writing-modes-expected.txt	2011-09-27 20:55:00 UTC (rev 96152)
@@ -0,0 +1,6 @@
+PASS document.getElementById("vertical").offsetLeft is 65
+PASS document.getElementById("horizontal").offsetTop is 65
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Property changes on: trunk/LayoutTests/fast/dom/offset-position-writing-modes-expected.txt
___________________________________________________________________

Added: svn:eol-style

Added: trunk/LayoutTests/fast/dom/offset-position-writing-modes.html (0 => 96152)


--- trunk/LayoutTests/fast/dom/offset-position-writing-modes.html	                        (rev 0)
+++ trunk/LayoutTests/fast/dom/offset-position-writing-modes.html	2011-09-27 20:55:00 UTC (rev 96152)
@@ -0,0 +1,23 @@
+<script src=""
+<div style="position:relative">
+<div style="-webkit-writing-mode: vertical-rl; background-color: green; width: 100px; height: 100px;">
+    <div style="width: 5px"></div>
+    <div id=vertical style="background-color: yellow; width: 10px; position: relative; left: -20px;"></div>
+</div>
+</div>
+
+<div style="position:relative">
+<div style="-webkit-writing-mode: horizontal-bt; background-color: red; width: 100px; height: 100px;">
+    <div style="height: 5px"></div>
+    <div id=horizontal style="background-color: orange; height: 10px; position: relative; top: -20px;"></div>
+</div>
+</div>
+
+<pre id=console></pre>
+
+<script>
+shouldBe('document.getElementById("vertical").offsetLeft', '65');
+shouldBe('document.getElementById("horizontal").offsetTop', '65');
+successfullyParsed = true;
+</script>
+<script src=""
Property changes on: trunk/LayoutTests/fast/dom/offset-position-writing-modes.html
___________________________________________________________________

Added: svn:eol-style

Modified: trunk/Source/WebCore/ChangeLog (96151 => 96152)


--- trunk/Source/WebCore/ChangeLog	2011-09-27 20:54:16 UTC (rev 96151)
+++ trunk/Source/WebCore/ChangeLog	2011-09-27 20:55:00 UTC (rev 96152)
@@ -1,3 +1,24 @@
+2011-09-27  Ojan Vafai  <[email protected]>
+
+        offsetTop/offsetLeft return the wrong values for horizontal-bt/vertical-rl writing modes
+        https://bugs.webkit.org/show_bug.cgi?id=68304
+
+        Reviewed by David Hyatt.
+
+        When grabbing the x/y values of the RenderBox, we need to take writing mode
+        flipping into account.
+
+        Test: fast/dom/offset-position-writing-modes.html
+
+        * rendering/RenderBox.cpp:
+        (WebCore::RenderBox::locationIncludingFlipping):
+        * rendering/RenderBox.h:
+        (WebCore::RenderBox::yFlippedForWritingMode):
+        (WebCore::RenderBox::xFlippedForWritingMode):
+        * rendering/RenderBoxModelObject.cpp:
+        (WebCore::RenderBoxModelObject::offsetLeft):
+        (WebCore::RenderBoxModelObject::offsetTop):
+
 2011-09-27  Tim Horton  <[email protected]>
 
         Rapidly refreshing a feMorphology[erode] with r=0 can sometimes cause display corruption

Modified: trunk/Source/WebCore/rendering/RenderBox.cpp (96151 => 96152)


--- trunk/Source/WebCore/rendering/RenderBox.cpp	2011-09-27 20:54:16 UTC (rev 96151)
+++ trunk/Source/WebCore/rendering/RenderBox.cpp	2011-09-27 20:55:00 UTC (rev 96152)
@@ -1383,9 +1383,9 @@
                 columnRect.moveBy(point);
                 o->adjustForColumns(offset, columnRect.location());
             } else
-                offset += locationOffsetIncludingFlipping();
+                offset += topLeftLocationOffset();
         } else
-            offset += locationOffsetIncludingFlipping();
+            offset += topLeftLocationOffset();
     }
 
     if (o->hasOverflowClip())
@@ -3649,10 +3649,18 @@
         rect.setX(width() - rect.maxX());
 }
 
-LayoutSize RenderBox::locationOffsetIncludingFlipping() const
+LayoutPoint RenderBox::topLeftLocation() const
 {
     RenderBlock* containerBlock = containingBlock();
     if (!containerBlock || containerBlock == this)
+        return location();
+    return containerBlock->flipForWritingMode(this, location(), RenderBox::ParentToChildFlippingAdjustment);
+}
+
+LayoutSize RenderBox::topLeftLocationOffset() const
+{
+    RenderBlock* containerBlock = containingBlock();
+    if (!containerBlock || containerBlock == this)
         return locationOffset();
     
     LayoutRect rect(frameRect());

Modified: trunk/Source/WebCore/rendering/RenderBox.h (96151 => 96152)


--- trunk/Source/WebCore/rendering/RenderBox.h	2011-09-27 20:54:16 UTC (rev 96151)
+++ trunk/Source/WebCore/rendering/RenderBox.h	2011-09-27 20:55:00 UTC (rev 96152)
@@ -49,6 +49,11 @@
     LayoutUnit width() const { return m_frameRect.width(); }
     LayoutUnit height() const { return m_frameRect.height(); }
 
+    // These represent your location relative to your container as a physical offset.
+    // In layout related methods you almost always want the logical location (e.g. x() and y()).
+    LayoutUnit top() const { return topLeftLocation().y(); }
+    LayoutUnit left() const { return topLeftLocation().x(); }
+
     void setX(LayoutUnit x) { m_frameRect.setX(x); }
     void setY(LayoutUnit y) { m_frameRect.setY(y); }
     void setWidth(LayoutUnit width) { m_frameRect.setWidth(width); }
@@ -402,7 +407,10 @@
     void flipForWritingMode(IntRect&) const;
     FloatPoint flipForWritingMode(const FloatPoint&) const;
     void flipForWritingMode(FloatRect&) const;
-    LayoutSize locationOffsetIncludingFlipping() const;
+    // These represent your location relative to your container as a physical offset.
+    // In layout related methods you almost always want the logical location (e.g. x() and y()).
+    LayoutPoint topLeftLocation() const;
+    LayoutSize topLeftLocationOffset() const;
 
     LayoutRect logicalVisualOverflowRectForPropagation(RenderStyle*) const;
     LayoutRect visualOverflowRectForPropagation(RenderStyle*) const;

Modified: trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp (96151 => 96152)


--- trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp	2011-09-27 20:54:16 UTC (rev 96151)
+++ trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp	2011-09-27 20:55:00 UTC (rev 96152)
@@ -438,7 +438,7 @@
         return 0;
     
     RenderBoxModelObject* offsetPar = offsetParent();
-    LayoutUnit xPos = (isBox() ? toRenderBox(this)->x() : 0);
+    LayoutUnit xPos = (isBox() ? toRenderBox(this)->left() : 0);
     
     // If the offsetParent of the element is null, or is the HTML body element,
     // return the distance between the canvas origin and the left border edge 
@@ -453,11 +453,11 @@
             while (curr && curr != offsetPar) {
                 // FIXME: What are we supposed to do inside SVG content?
                 if (curr->isBox() && !curr->isTableRow())
-                    xPos += toRenderBox(curr)->x();
+                    xPos += toRenderBox(curr)->left();
                 curr = curr->parent();
             }
             if (offsetPar->isBox() && offsetPar->isBody() && !offsetPar->isRelPositioned() && !offsetPar->isPositioned())
-                xPos += toRenderBox(offsetPar)->x();
+                xPos += toRenderBox(offsetPar)->left();
         }
     }
 
@@ -472,7 +472,7 @@
         return 0;
     
     RenderBoxModelObject* offsetPar = offsetParent();
-    LayoutUnit yPos = (isBox() ? toRenderBox(this)->y() : 0);
+    LayoutUnit yPos = (isBox() ? toRenderBox(this)->top() : 0);
     
     // If the offsetParent of the element is null, or is the HTML body element,
     // return the distance between the canvas origin and the top border edge 
@@ -487,11 +487,11 @@
             while (curr && curr != offsetPar) {
                 // FIXME: What are we supposed to do inside SVG content?
                 if (curr->isBox() && !curr->isTableRow())
-                    yPos += toRenderBox(curr)->y();
+                    yPos += toRenderBox(curr)->top();
                 curr = curr->parent();
             }
             if (offsetPar->isBox() && offsetPar->isBody() && !offsetPar->isRelPositioned() && !offsetPar->isPositioned())
-                yPos += toRenderBox(offsetPar)->y();
+                yPos += toRenderBox(offsetPar)->top();
         }
     }
     return yPos;

Modified: trunk/Source/WebCore/rendering/RenderLayer.cpp (96151 => 96152)


--- trunk/Source/WebCore/rendering/RenderLayer.cpp	2011-09-27 20:54:16 UTC (rev 96151)
+++ trunk/Source/WebCore/rendering/RenderLayer.cpp	2011-09-27 20:55:00 UTC (rev 96152)
@@ -707,7 +707,7 @@
         localPoint += inlineBoundingBoxOffset;
     } else if (RenderBox* box = renderBox()) {
         setSize(box->size());
-        localPoint += box->locationOffsetIncludingFlipping();
+        localPoint += box->topLeftLocationOffset();
     }
 
     // Clear our cached clip rect information.
@@ -721,13 +721,13 @@
             if (curr->isBox() && !curr->isTableRow()) {
                 // Rows and cells share the same coordinate space (that of the section).
                 // Omit them when computing our xpos/ypos.
-                localPoint += toRenderBox(curr)->locationOffsetIncludingFlipping();
+                localPoint += toRenderBox(curr)->topLeftLocationOffset();
             }
             curr = curr->parent();
         }
         if (curr->isBox() && curr->isTableRow()) {
             // Put ourselves into the row coordinate space.
-            localPoint -= toRenderBox(curr)->locationOffsetIncludingFlipping();
+            localPoint -= toRenderBox(curr)->topLeftLocationOffset();
         }
     }
     
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to