⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 92089 in webkit


Ignore:
Timestamp:
Jul 31, 2011, 2:05:26 PM (15 years ago)
Author:
weinig@apple.com
Message:

REGRESSION: getBoundingClientRect() method of Range incorrectly returns null for collapsed Range
https://bugs.webkit.org/show_bug.cgi?id=65324

Reviewed by Ryosuke Niwa.

Source/WebCore:

Update to more closely match the spec.

  • dom/Range.cpp:

(WebCore::Range::getClientRects):
Return an empty ClientRectList instead of null when the range is empty.

(WebCore::Range::getBoundingClientRect):
Always return a ClientRect, even for an empty bounding rect.

LayoutTests:

  • fast/dom/Range/getBoundingClientRect-expected.txt:
  • fast/dom/Range/getBoundingClientRect.html:
  • fast/dom/Range/getClientRects-expected.txt:
  • fast/dom/Range/getClientRects.html:

Add test cases for empty and collapsed ranges.

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r92088 r92089  
     12011-07-31  Sam Weinig  <sam@webkit.org>
     2
     3        REGRESSION: getBoundingClientRect() method of Range incorrectly returns null for collapsed Range
     4        https://bugs.webkit.org/show_bug.cgi?id=65324
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        * fast/dom/Range/getBoundingClientRect-expected.txt:
     9        * fast/dom/Range/getBoundingClientRect.html:
     10        * fast/dom/Range/getClientRects-expected.txt:
     11        * fast/dom/Range/getClientRects.html:
     12        Add test cases for empty and collapsed ranges.
     13
    1142011-07-29  Ryosuke Niwa  <rniwa@webkit.org>
    215
  • trunk/LayoutTests/fast/dom/Range/getBoundingClientRect-expected.txt

    r72826 r92089  
    2424
    2525Test 4
     26PASS rect.left.toFixed(3) is "0.000"
     27PASS rect.top.toFixed(3) is "0.000"
     28PASS rect.width.toFixed(3) is "0.000"
     29PASS rect.height.toFixed(3) is "0.000"
     30PASS rect.right is rect.left + rect.width
     31PASS rect.bottom is rect.top + rect.height
     32
     33Test 5
    2634PASS rect.left.toFixed(3) is "-14.574"
    27 PASS rect.top.toFixed(3) is "1329.947"
     35PASS rect.top.toFixed(3) is "1761.947"
    2836PASS rect.width.toFixed(3) is "504.009"
    2937PASS rect.height.toFixed(3) is "535.849"
     
    3139PASS Math.abs(rect.top + rect.height - rect.bottom) < 0.001 is true
    3240
     41Test 6
     42PASS rect.left.toFixed(3) is "0.000"
     43PASS rect.top.toFixed(3) is "0.000"
     44PASS rect.width.toFixed(3) is "0.000"
     45PASS rect.height.toFixed(3) is "0.000"
     46PASS rect.right is rect.left + rect.width
     47PASS rect.bottom is rect.top + rect.height
     48
    3349PASS successfullyParsed is true
    3450
  • trunk/LayoutTests/fast/dom/Range/getBoundingClientRect.html

    r72826 r92089  
    2828}
    2929
    30 #test4 {
     30#test5 {
    3131    -webkit-transform: translate(50px, 100px) rotate(50deg);
    3232}
     
    5757
    5858<div class="box" id="test4">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>
     59
     60<br><br>
     61
     62<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>
    5963
    6064</div>
     
    106110        /*2*/  { left: 8, top: 452, width: 400, height: 376 },
    107111        /*3*/  { left: 8, top: 1044, width: 400, height: 96 },
    108         /*4*/  { left: -14.574, top: 1329.947, width: 504.009, height: 535.849 },
     112        /*4*/  { left: 0, top: 0, width: 0, height: 0 },
     113        /*5*/  { left: -14.574, top: 1761.947, width: 504.009, height: 535.849 },
     114        /*6*/  { left: 0, top: 0, width: 0, height: 0 },
    109115    ];
    110116
     117    // Range over entire element.
    111118    debug("Test 1")
    112119    var range1 = document.createRange();
     
    116123    testClientRect(rect, expectedResults[1 - 1]);
    117124
     125    // Range over entire element's contents.
    118126    debug("Test 2")
    119127    var range2 = document.createRange();
     
    123131    testClientRect(rect, expectedResults[2 - 1]);
    124132
     133    // Range over subset of element's contents.
    125134    debug("Test 3")
    126135    var range3 = document.createRange();
     
    131140    testClientRect(rect, expectedResults[3 - 1]);
    132141
     142    // Collapsed range.
    133143    debug("Test 4")
    134144    var range4 = document.createRange();
    135145    range4.selectNodeContents(document.getElementById('test4'));
     146    range4.collapse(true);
    136147    show(range4);
     148   
     149    var blah = range4.getClientRects();
     150    debug(blah);
     151
    137152    rect = range4.getBoundingClientRect()
    138153    testClientRect(rect, expectedResults[4 - 1]);
     154
     155    // Range over transformed elements.
     156    debug("Test 5")
     157    var range5 = document.createRange();
     158    range5.selectNodeContents(document.getElementById('test5'));
     159    show(range5);
     160    rect = range5.getBoundingClientRect()
     161    testClientRect(rect, expectedResults[5 - 1]);
     162
     163    // Empty range.
     164    debug("Test 6")
     165    var range6 = document.createRange();
     166    rect = range6.getBoundingClientRect()
     167    testClientRect(rect, expectedResults[6 - 1]);
    139168
    140169    if (window.layoutTestController) {
  • trunk/LayoutTests/fast/dom/Range/getClientRects-expected.txt

    r91763 r92089  
    217217PASS rects[3].width is 18
    218218PASS rects[3].height is 360
     219Test 11
     220PASS rects.length is 0
    219221PASS successfullyParsed is true
    220222
  • trunk/LayoutTests/fast/dom/Range/getClientRects.html

    r91763 r92089  
    400400    shouldBe("rects[3].height", "360");
    401401
     402    debug("Test 11");
     403    var range11 = document.createRange();
     404    rects = range11.getClientRects();
     405    shouldBe("rects.length", "0");
     406
    402407    if (window.layoutTestController) {
    403408        var area = document.getElementById('testArea');
  • trunk/Source/WebCore/ChangeLog

    r92088 r92089  
     12011-07-31  Sam Weinig  <sam@webkit.org>
     2
     3        REGRESSION: getBoundingClientRect() method of Range incorrectly returns null for collapsed Range
     4        https://bugs.webkit.org/show_bug.cgi?id=65324
     5
     6        Reviewed by Ryosuke Niwa.
     7
     8        Update to more closely match the spec.
     9
     10        * dom/Range.cpp:
     11        (WebCore::Range::getClientRects):
     12        Return an empty ClientRectList instead of null when the range is empty.
     13
     14        (WebCore::Range::getBoundingClientRect):
     15        Always return a ClientRect, even for an empty bounding rect.
     16
    1172011-07-29  Ryosuke Niwa  <rniwa@webkit.org>
    218
  • trunk/Source/WebCore/dom/Range.cpp

    r90911 r92089  
    19111911{
    19121912    if (!m_start.container())
    1913         return 0;
     1913        return ClientRectList::create();
    19141914
    19151915    m_ownerDocument->updateLayoutIgnorePendingStylesheets();
     
    19231923PassRefPtr<ClientRect> Range::getBoundingClientRect() const
    19241924{
    1925     FloatRect rect = boundingRect();
    1926     return rect.isEmpty() ? 0 : ClientRect::create(rect);
     1925    return ClientRect::create(boundingRect());
    19271926}
    19281927
Note: See TracChangeset for help on using the changeset viewer.