Changeset 154614 in webkit


Ignore:
Timestamp:
Aug 26, 2013 10:48:49 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

<https://webkit.org/b/106133> document.body.scrollTop & document.documentElement.scrollTop differ cross-browser

Patch by Gurpreet Kaur <gur.trio@gmail.com> on 2013-08-26
Reviewed by Darin Adler.

Source/WebCore:

Webkit always uses document.body.scrollTop whether quirks or
standard mode. Similiar behaviour is for document.body.scrollLeft.
As per the specification webkit should return document.body.scrollTop
for quirks mode and document.documentElement.scrollTop for standard mode.
Same for document.body.scrollLeft and document.documentElement.scrollLeft.

Tests: fast/dom/Element/scrollLeft-Quirks.html

fast/dom/Element/scrollLeft.html
fast/dom/Element/scrollTop-Quirks.html
fast/dom/Element/scrollTop.html

  • dom/Element.cpp:

(WebCore::Element::scrollLeft):
(WebCore::Element::scrollTop):
If the element does not have any associated CSS layout box or the element
is the root element and the Document is in quirks mode return zero.
Else If the element is the root element return the value of scrollY
for scrollTop and scrollX for scrollLeft.

  • html/HTMLBodyElement.cpp:

(WebCore::HTMLBodyElement::scrollLeft):
(WebCore::HTMLBodyElement::scrollTop):
If the element is the HTML body element, the Document is in quirks mode,
return the value of scrollY for scrollTop and scrollX for scrollLeft.

LayoutTests:

  • fast/dom/Element/scrollLeft-Quirks-expected.txt: Added.
  • fast/dom/Element/scrollLeft-Quirks.html: Added.
  • fast/dom/Element/scrollLeft-expected.txt: Added.
  • fast/dom/Element/scrollLeft.html: Added.
  • fast/dom/Element/scrollTop-Quirks-expected.txt: Added.
  • fast/dom/Element/scrollTop-Quirks.html: Added.
  • fast/dom/Element/scrollTop-expected.txt: Added.
  • fast/dom/Element/scrollTop.html: Added.

Added new tests for verifying our behavior for document.body.scrollTop/scrollLeft and
document.documentElement.scrollTop/scrollLeft for both Quirks as well as Standard mode.

  • fast/css/zoom-body-scroll-expected.txt:
  • fast/css/zoom-body-scroll.html:
  • fast/events/mouse-cursor.html:
  • http/tests/navigation/anchor-frames-expected.txt:
  • http/tests/navigation/anchor-frames-gbk-expected.txt:
  • http/tests/navigation/resources/frame-with-anchor-gbk.html:
  • http/tests/navigation/resources/frame-with-anchor-same-origin.html:
  • http/tests/navigation/resources/frame-with-anchor.html:
  • platform/mac-wk2/tiled-drawing/resources/scroll-and-load-page.html:
  • platform/mac-wk2/tiled-drawing/tiled-drawing-scroll-position-page-cache-restoration.html:
  • platform/win/fast/css/zoom-body-scroll-expected.txt:

Rebaselining existing tests as per the new behavior. The test cases are changed to use
quirks mode because it uses document.body.scrollTop/scrollLeft and as per the new code
document.body.scrollTop/scrollLeft will return correct value if document is in quirk mode
Also test cases have been modified so that it tests what it used to.

Location:
trunk
Files:
8 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r154612 r154614  
     12013-08-26  Gurpreet Kaur  <gur.trio@gmail.com>
     2
     3        <https://webkit.org/b/106133> document.body.scrollTop & document.documentElement.scrollTop differ cross-browser
     4
     5        Reviewed by Darin Adler.
     6
     7        * fast/dom/Element/scrollLeft-Quirks-expected.txt: Added.
     8        * fast/dom/Element/scrollLeft-Quirks.html: Added.
     9        * fast/dom/Element/scrollLeft-expected.txt: Added.
     10        * fast/dom/Element/scrollLeft.html: Added.
     11        * fast/dom/Element/scrollTop-Quirks-expected.txt: Added.
     12        * fast/dom/Element/scrollTop-Quirks.html: Added.
     13        * fast/dom/Element/scrollTop-expected.txt: Added.
     14        * fast/dom/Element/scrollTop.html: Added.
     15        Added new tests for verifying our behavior for document.body.scrollTop/scrollLeft and
     16        document.documentElement.scrollTop/scrollLeft for both Quirks as well as Standard mode.
     17
     18        * fast/css/zoom-body-scroll-expected.txt:
     19        * fast/css/zoom-body-scroll.html:
     20        * fast/events/mouse-cursor.html:
     21        * http/tests/navigation/anchor-frames-expected.txt:
     22        * http/tests/navigation/anchor-frames-gbk-expected.txt:
     23        * http/tests/navigation/resources/frame-with-anchor-gbk.html:
     24        * http/tests/navigation/resources/frame-with-anchor-same-origin.html:
     25        * http/tests/navigation/resources/frame-with-anchor.html:
     26        * platform/mac-wk2/tiled-drawing/resources/scroll-and-load-page.html:
     27        * platform/mac-wk2/tiled-drawing/tiled-drawing-scroll-position-page-cache-restoration.html:
     28        * platform/win/fast/css/zoom-body-scroll-expected.txt:
     29        Rebaselining existing tests as per the new behavior. The test cases are changed to use
     30        quirks mode because it uses document.body.scrollTop/scrollLeft and as per the new code
     31        document.body.scrollTop/scrollLeft will return correct value if document is in quirk mode
     32        Also test cases have been modified so that it tests what it used to.
     33
    1342013-08-26  Gavin Barraclough  <barraclough@apple.com>
    235
  • trunk/LayoutTests/fast/css/zoom-body-scroll-expected.txt

    r53424 r154614  
    1010scrollHeight: 1000
    1111scrollWidth: 1000
    12 scrollTop: 0
     12scrollTop: 100
    1313scrollLeft: 50
    1414
  • trunk/LayoutTests/fast/css/zoom-body-scroll.html

    r120683 r154614  
    1 <!DOCTYPE HTML>
    21<html>
    3 <body>
     2<body onload="bodyScroll()">
    43    <div style="width: 1000px; height: 1000px; position: absolute; top: 0; left: 0;"></div>
    54    <div style="width: 100px; height: 100px; position: absolute; top: 100px; left: 0; background: green"></div>
     
    1615        }
    1716
    18         if (window.testRunner) {
    19             testRunner.dumpAsText();
    20             var body = document.body;
    21             log("scrollHeight: " + body.scrollHeight);
    22             log("scrollWidth: " + body.scrollWidth);
     17        function bodyScroll() {
     18            if (window.testRunner) {
     19                testRunner.dumpAsText();
     20                var body = document.body;
     21                window.scrollTo(50,100);
     22                log("scrollHeight: " + body.scrollHeight);
     23                log("scrollWidth: " + body.scrollWidth);
    2324
    24             log("\nScrolling right to 50");
    25             body.scrollLeft = 50;
    26             log("scrollLeft: " + body.scrollLeft);
     25                log("\nScrolling right to 50");
     26                body.scrollLeft = 50;
     27                log("scrollLeft: " + body.scrollLeft);
    2728
    28             log("\nZooming in");
    29             eventSender.zoomPageIn();
    30             log("scrollHeight: " + body.scrollHeight);
    31             log("scrollWidth: " + body.scrollWidth);
    32             log("scrollTop: " + body.scrollTop);
    33             log("scrollLeft: " + body.scrollLeft);
     29                log("\nZooming in");
     30                eventSender.zoomPageIn();
     31                log("scrollHeight: " + body.scrollHeight);
     32                log("scrollWidth: " + body.scrollWidth);
     33                log("scrollTop: " + body.scrollTop);
     34                log("scrollLeft: " + body.scrollLeft);
    3435
    35             log("\nScrolling down to 100");
    36             body.scrollTop = 100;
    37             log("scrollTop: " + body.scrollTop);
     36                log("\nScrolling down to 100");
     37                body.scrollTop = 100;
     38                log("scrollTop: " + body.scrollTop);
    3839
    39             log("\nZooming back out");
    40             eventSender.zoomPageOut();
    41             log("scrollTop: " + body.scrollTop);
    42             log("scrollLeft: " + body.scrollLeft);
     40                log("\nZooming back out");
     41                eventSender.zoomPageOut();
     42                log("scrollTop: " + body.scrollTop);
     43                log("scrollLeft: " + body.scrollLeft);
     44                        }
    4345        }
    4446    </script>
  • trunk/LayoutTests/fast/events/mouse-cursor.html

    r138857 r154614  
    1 <!DOCTYPE html>
    21<html>
    32<head>
     
    109<p id="description"></p>
    1110<p><a href=https://bugs.webkit.org/show_bug.cgi?id=100550>Bug 100550</a></p>
    12 <svg xmlns="http://www.w3.org/2000/svg" 
     11<svg xmlns="http://www.w3.org/2000/svg"
    1312     xmlns:xlink="http://www.w3.org/1999/xlink" width="0" height="0">
    1413  <defs>
     
    4645
    4746var testContainer = document.getElementById('test-container');
    48    
     47
    4948function runTests() {
    5049    // Can't do anything useful here without eventSender
     
    6968        testContainer.style.display = 'none';
    7069    }
    71    
     70
    7271    finishJSTest();
    7372}
  • trunk/LayoutTests/http/tests/navigation/anchor-frames-expected.txt

    r67033 r154614  
    99
    1010
    11 PASS document.body.offsetHeight > document.documentElement.clientHeight is true
     11PASS document.body.offsetHeight > window.innerHeight is true
    1212PASS document.body.scrollTop > 0 is true
    1313PASS document.body.scrollTop + document.documentElement.clientHeight > 2000 is true
  • trunk/LayoutTests/http/tests/navigation/anchor-frames-gbk-expected.txt

    r105691 r154614  
    99
    1010
    11 PASS document.body.offsetHeight > document.documentElement.clientHeight is true
     11PASS document.body.offsetHeight > window.innerHeight is true
    1212PASS document.body.scrollTop > 0 is true
    1313PASS document.body.scrollTop + document.documentElement.clientHeight > 2000 is true
  • trunk/LayoutTests/http/tests/navigation/resources/frame-with-anchor-gbk.html

    r105691 r154614  
    1 <!DOCTYPE html>
    21<html>
    32<head>
     
    1312          // Make sure that the body is taller than the viewport (i.e. scrolling is
    1413          // required).
    15           shouldBeTrue('document.body.offsetHeight > document.documentElement.clientHeight');
     14          shouldBeTrue('document.body.offsetHeight > window.innerHeight');
    1615         
    1716          // We should be scrolled at least a little bit
    1817          shouldBeTrue('document.body.scrollTop > 0');
    19          
     18
    2019          // And the bottom of the viewable area should be at least 2000 pixels from the top, due to the spacer element above.
    2120          shouldBeTrue('document.body.scrollTop + document.documentElement.clientHeight > 2000');
    2221
    23           finishJSTest();         
     22          finishJSTest();
    2423      }, 0);
    2524    }
    26    
     25
    2726    var jsTestIsAsync = true;
    28   </script> 
     27  </script>
    2928</head>
    3029<body onload="runTest()">
  • trunk/LayoutTests/http/tests/navigation/resources/frame-with-anchor-same-origin.html

    r114406 r154614  
    1 <!DOCTYPE html>
    21<html>
    32<head>
     
    1110          shouldBeTrue('document.body.scrollTop > 0');
    1211          shouldBeTrue('document.body.scrollLeft == 0');
    13           finishJSTest();         
     12          finishJSTest();
    1413      }, 0);
    1514    }
    1615    var jsTestIsAsync = true;
    17   </script> 
     16  </script>
    1817</head>
    1918<body>
  • trunk/LayoutTests/http/tests/navigation/resources/frame-with-anchor.html

    r99258 r154614  
    1 <!DOCTYPE html>
    21<html>
    32<head>
     
    1211          // Make sure that the body is taller than the viewport (i.e. scrolling is
    1312          // required).
    14           shouldBeTrue('document.body.offsetHeight > document.documentElement.clientHeight');
    15          
     13          shouldBeTrue('document.body.offsetHeight > window.innerHeight');
     14
    1615          // We should be scrolled at least a little bit
    1716          shouldBeTrue('document.body.scrollTop > 0');
    18          
     17
    1918          // And the bottom of the viewable area should be at least 2000 pixels from the top, due to the spacer element above.
    2019          shouldBeTrue('document.body.scrollTop + document.documentElement.clientHeight > 2000');
    21          
    22           finishJSTest();         
     20
     21          finishJSTest();
    2322      }, 0);
    2423    }
    25    
     24
    2625    var jsTestIsAsync = true;
    27   </script> 
     26  </script>
    2827</head>
    2928<body onload="runTest()">
  • trunk/LayoutTests/platform/mac-wk2/tiled-drawing/resources/scroll-and-load-page.html

    r142416 r154614  
    1 <!DOCTYPE html>
    21<html>
    32<head>
  • trunk/LayoutTests/platform/mac-wk2/tiled-drawing/tiled-drawing-scroll-position-page-cache-restoration.html

    r142416 r154614  
    1 <!DOCTYPE html>
    21<html>
    32<head>
     
    1110
    1211        window.finishedTest = function (layerTree)
    13         {   
     12        {
    1413            document.getElementById('layers').innerText = layerTree;
    1514            testRunner.notifyDone();
  • trunk/LayoutTests/platform/win/fast/css/zoom-body-scroll-expected.txt

    r149090 r154614  
    1010scrollHeight: 1000
    1111scrollWidth: 1000
    12 scrollTop: 0
     12scrollTop: 100
    1313scrollLeft: 50
    1414
     
    1717
    1818Zooming back out
    19 scrollTop: 99
    20 scrollLeft: 49
     19scrollTop: 100
     20scrollLeft: 50
    2121
  • trunk/Source/WebCore/ChangeLog

    r154613 r154614  
     12013-08-26  Gurpreet Kaur  <gur.trio@gmail.com>
     2
     3        <https://webkit.org/b/106133> document.body.scrollTop & document.documentElement.scrollTop differ cross-browser
     4
     5        Reviewed by Darin Adler.
     6
     7        Webkit always uses document.body.scrollTop whether quirks or
     8        standard mode. Similiar behaviour is for document.body.scrollLeft.
     9        As per the specification webkit should return document.body.scrollTop
     10        for quirks mode and document.documentElement.scrollTop for standard mode.
     11        Same for document.body.scrollLeft and document.documentElement.scrollLeft.
     12
     13        Tests: fast/dom/Element/scrollLeft-Quirks.html
     14               fast/dom/Element/scrollLeft.html
     15               fast/dom/Element/scrollTop-Quirks.html
     16               fast/dom/Element/scrollTop.html
     17
     18        * dom/Element.cpp:
     19        (WebCore::Element::scrollLeft):
     20        (WebCore::Element::scrollTop):
     21        If the element does not have any associated CSS layout box or the element
     22        is the root element and the Document is in quirks mode return zero.
     23        Else If the element is the root element return the value of scrollY
     24        for scrollTop and scrollX for scrollLeft.
     25        * html/HTMLBodyElement.cpp:
     26        (WebCore::HTMLBodyElement::scrollLeft):
     27        (WebCore::HTMLBodyElement::scrollTop):
     28        If the element is the HTML body element, the Document is in quirks mode,
     29        return the value of scrollY for scrollTop and scrollX for scrollLeft.
     30
    1312013-08-26  Antti Koivisto  <antti@apple.com>
    232
  • trunk/Source/WebCore/dom/Element.cpp

    r154541 r154614  
    761761int Element::scrollLeft()
    762762{
     763    if (document()->documentElement() == this && document()->inQuirksMode())
     764        return 0;
     765
    763766    document()->updateLayoutIgnorePendingStylesheets();
     767    if (document()->documentElement() == this) {
     768        if (RenderView* renderView = document()->renderView()) {
     769            if (FrameView* view = &renderView->frameView())
     770                return adjustForAbsoluteZoom(view->scrollX(), renderView);
     771        }
     772    }
    764773    if (RenderBox* rend = renderBox())
    765774        return adjustForAbsoluteZoom(rend->scrollLeft(), rend);
     
    769778int Element::scrollTop()
    770779{
     780    if (document()->documentElement() == this && document()->inQuirksMode())
     781        return 0;
     782
    771783    document()->updateLayoutIgnorePendingStylesheets();
     784    if (document()->documentElement() == this) {
     785        if (RenderView* renderView = document()->renderView()) {
     786            if (FrameView* view = &renderView->frameView())
     787                return adjustForAbsoluteZoom(view->scrollY(), renderView);
     788        }
     789    }
    772790    if (RenderBox* rend = renderBox())
    773791        return adjustForAbsoluteZoom(rend->scrollTop(), rend);
  • trunk/Source/WebCore/html/HTMLBodyElement.cpp

    r152889 r154614  
    262262int HTMLBodyElement::scrollLeft()
    263263{
    264     // Update the document's layout.
    265     Document* document = this->document();
     264    Document* document = this->document();
     265    if (!document->inQuirksMode())
     266        return 0;
    266267    document->updateLayoutIgnorePendingStylesheets();
    267268    FrameView* view = document->view();
     
    284285int HTMLBodyElement::scrollTop()
    285286{
    286     // Update the document's layout.
    287     Document* document = this->document();
     287    Document* document = this->document();
     288    if (!document->inQuirksMode())
     289        return 0;
    288290    document->updateLayoutIgnorePendingStylesheets();
    289291    FrameView* view = document->view();
Note: See TracChangeset for help on using the changeset viewer.