Title: [245534] trunk
Revision
245534
Author
[email protected]
Date
2019-05-20 13:32:35 -0700 (Mon, 20 May 2019)

Log Message

Range getBoundingClientRect returning zero rect on simple text node with <br> before it
https://bugs.webkit.org/show_bug.cgi?id=182181

Patch by Gabe Giosia <[email protected]> on 2019-05-20
Reviewed by Antti Koivisto.

Source/WebCore:

Correct rect of RenderText in a block element when used in a Range
over a line break element. The end offset was miscalculated.

Addded line-break case to fast/dom/Range/getBoundingClientRect.html

* rendering/SimpleLineLayoutFunctions.cpp:
(WebCore::SimpleLineLayout::collectAbsoluteQuadsForRange):
* rendering/SimpleLineLayoutResolver.cpp:
(WebCore::SimpleLineLayout::RunResolver::rangeForRendererWithOffsets const):

LayoutTests:

Test getBoundingClientRect with a Range that contains a line break.

* fast/dom/Range/getBoundingClientRect-expected.txt:
* fast/dom/Range/getBoundingClientRect.html:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (245533 => 245534)


--- trunk/LayoutTests/ChangeLog	2019-05-20 19:18:42 UTC (rev 245533)
+++ trunk/LayoutTests/ChangeLog	2019-05-20 20:32:35 UTC (rev 245534)
@@ -1,3 +1,15 @@
+2019-05-20  Gabe Giosia  <[email protected]>
+
+        Range getBoundingClientRect returning zero rect on simple text node with <br> before it
+        https://bugs.webkit.org/show_bug.cgi?id=182181
+
+        Reviewed by Antti Koivisto.
+        
+        Test getBoundingClientRect with a Range that contains a line break.
+
+        * fast/dom/Range/getBoundingClientRect-expected.txt:
+        * fast/dom/Range/getBoundingClientRect.html:
+
 2019-05-20  Ryan Haddad  <[email protected]>
 
         Unreviewed test gardening after r245482.

Modified: trunk/LayoutTests/fast/dom/Range/getBoundingClientRect-expected.txt (245533 => 245534)


--- trunk/LayoutTests/fast/dom/Range/getBoundingClientRect-expected.txt	2019-05-20 19:18:42 UTC (rev 245533)
+++ trunk/LayoutTests/fast/dom/Range/getBoundingClientRect-expected.txt	2019-05-20 20:32:35 UTC (rev 245534)
@@ -46,6 +46,14 @@
 PASS rect.right is rect.left + rect.width
 PASS rect.bottom is rect.top + rect.height
 
+Test 7
+PASS rect.left.toFixed(3) is "8.000"
+PASS rect.top.toFixed(3) is "2180.000"
+PASS rect.width.toFixed(3) is "192.000"
+PASS rect.height.toFixed(3) is "96.000"
+PASS rect.right is rect.left + rect.width
+PASS rect.bottom is rect.top + rect.height
+
 PASS successfullyParsed is true
 
 TEST COMPLETE

Modified: trunk/LayoutTests/fast/dom/Range/getBoundingClientRect.html (245533 => 245534)


--- trunk/LayoutTests/fast/dom/Range/getBoundingClientRect.html	2019-05-20 19:18:42 UTC (rev 245533)
+++ trunk/LayoutTests/fast/dom/Range/getBoundingClientRect.html	2019-05-20 20:32:35 UTC (rev 245534)
@@ -60,6 +60,10 @@
 
 <div class="box" id="test5">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.</div>
 
+<br><br>
+
+<div class="box" id="test7">Lorem ipsum <br> dolor sit <br> amet.</div>
+
 </div>
 <script>
     if (window.testRunner)
@@ -111,6 +115,7 @@
         /*4*/  { left: 0, top: 0, width: 0, height: 0 },
         /*5*/  { left: -14.574, top: 1761.947, width: 504.009, height: 535.849 },
         /*6*/  { left: 0, top: 0, width: 0, height: 0 },
+        /*7*/  { left: 8, top: 2180, width: 192, height: 96 },
     ];
 
     // Range over entire element.
@@ -161,6 +166,15 @@
     var range6 = document.createRange();
     rect = range6.getBoundingClientRect()
     testClientRect(rect, expectedResults[6 - 1]);
+    
+    // Range over subset that contains text and line break elements.
+    debug("Test 7")
+    var range7 = document.createRange();
+    range7.setStart(document.getElementById('test7').firstChild, 2);
+    range7.setEnd(document.getElementById('test7').lastChild, 2);
+    show(range7);
+    rect = range7.getBoundingClientRect()
+    testClientRect(rect, expectedResults[7 - 1]);
 
     if (window.testRunner) {
         var area = document.getElementById('testArea');

Modified: trunk/Source/WebCore/ChangeLog (245533 => 245534)


--- trunk/Source/WebCore/ChangeLog	2019-05-20 19:18:42 UTC (rev 245533)
+++ trunk/Source/WebCore/ChangeLog	2019-05-20 20:32:35 UTC (rev 245534)
@@ -1,3 +1,20 @@
+2019-05-20  Gabe Giosia  <[email protected]>
+
+        Range getBoundingClientRect returning zero rect on simple text node with <br> before it
+        https://bugs.webkit.org/show_bug.cgi?id=182181
+
+        Reviewed by Antti Koivisto.
+        
+        Correct rect of RenderText in a block element when used in a Range
+        over a line break element. The end offset was miscalculated.
+
+        Addded line-break case to fast/dom/Range/getBoundingClientRect.html
+
+        * rendering/SimpleLineLayoutFunctions.cpp:
+        (WebCore::SimpleLineLayout::collectAbsoluteQuadsForRange):
+        * rendering/SimpleLineLayoutResolver.cpp:
+        (WebCore::SimpleLineLayout::RunResolver::rangeForRendererWithOffsets const):
+
 2019-05-19  Brent Fulgham  <[email protected]>
 
         Unreviewed build fix after r245508.

Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp (245533 => 245534)


--- trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp	2019-05-20 19:18:42 UTC (rev 245533)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutFunctions.cpp	2019-05-20 20:32:35 UTC (rev 245534)
@@ -263,10 +263,9 @@
             quads.append(renderer.localToAbsoluteQuad(FloatQuad(runRect), UseTransforms, wasFixed));
             continue;
         }
-        ASSERT(start < run.end());
-        ASSERT(end > run.start());
         auto localStart = std::max(run.start(), start) - run.start();
         auto localEnd = std::min(run.end(), end) - run.start();
+        ASSERT(localStart <= localEnd);
         style.fontCascade().adjustSelectionRectForText(textRun, runRect, localStart, localEnd);
         quads.append(renderer.localToAbsoluteQuad(FloatQuad(runRect), UseTransforms, wasFixed));
     }

Modified: trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.cpp (245533 => 245534)


--- trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.cpp	2019-05-20 19:18:42 UTC (rev 245533)
+++ trunk/Source/WebCore/rendering/SimpleLineLayoutResolver.cpp	2019-05-20 20:32:35 UTC (rev 245534)
@@ -300,7 +300,8 @@
     ASSERT(startOffset <= endOffset);
     auto range = rangeForRenderer(renderer);
     auto it = range.begin();
-    // Advance to the firt run with the start offset inside.
+    auto localEnd = (*it).start() + endOffset;
+    // Advance to the first run with the start offset inside. Only the first node in a range can have a startOffset.
     while (it != range.end() && (*it).end() <= startOffset)
         ++it;
     if (it == range.end())
@@ -307,10 +308,10 @@
         return { end(), end() };
     auto rangeBegin = it;
     // Special case empty ranges that start at the edge of the run. Apparently normal line layout include those.
-    if (endOffset == startOffset && (*it).start() == endOffset)
+    if (localEnd == startOffset && (*it).start() == localEnd)
         return { rangeBegin, ++it };
     // Advance beyond the last run with the end offset.
-    while (it != range.end() && (*it).start() < endOffset)
+    while (it != range.end() && (*it).start() < localEnd)
         ++it;
     return { rangeBegin, it };
 }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to