Source/WebCore/ChangeLog

 12013-08-22 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 NOBODY (OOPS!).
 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.scrollLef
 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-21 Commit Queue <commit-queue@webkit.org>
232
333 Unreviewed, rolling out r154416.
154437

Source/WebCore/dom/Element.cpp

@@int Element::clientHeight()
763763
764764int Element::scrollLeft()
765765{
 766 bool inQuirksMode = document()->inQuirksMode();
 767 if (document()->documentElement() == this && inQuirksMode)
 768 return 0;
 769
766770 document()->updateLayoutIgnorePendingStylesheets();
 771
 772 if (document()->documentElement() == this) {
 773 if (RenderView* renderView = document()->renderView()) {
 774 if (FrameView* view = renderView->frameView())
 775 return adjustForAbsoluteZoom(view->scrollX(), renderView);
 776 }
 777 }
767778 if (RenderBox* rend = renderBox())
768779 return adjustForAbsoluteZoom(rend->scrollLeft(), rend);
769780 return 0;

@@int Element::scrollLeft()
771782
772783int Element::scrollTop()
773784{
 785 bool inQuirksMode = document()->inQuirksMode();
 786 if (document()->documentElement() == this && inQuirksMode)
 787 return 0;
 788
774789 document()->updateLayoutIgnorePendingStylesheets();
 790
 791 if (document()->documentElement() == this) {
 792 if (RenderView* renderView = document()->renderView()) {
 793 if (FrameView* view = renderView->frameView())
 794 return adjustForAbsoluteZoom(view->scrollY(), renderView);
 795 }
 796 }
775797 if (RenderBox* rend = renderBox())
776798 return adjustForAbsoluteZoom(rend->scrollTop(), rend);
777799 return 0;
154276

Source/WebCore/html/HTMLBodyElement.cpp

@@static int adjustForZoom(int value, Docu
262262int HTMLBodyElement::scrollLeft()
263263{
264264 // Update the document's layout.
265  Document* document = this->document();
266  document->updateLayoutIgnorePendingStylesheets();
 265 Document* document = this->document();
267266 FrameView* view = document->view();
268  return view ? adjustForZoom(view->scrollX(), document) : 0;
 267 if (document->inQuirksMode()) {
 268 document->updateLayoutIgnorePendingStylesheets();
 269 return view ? adjustForZoom(view->scrollX(), document) : 0;
 270 }
 271 return 0;
269272}
270273
271274void HTMLBodyElement::setScrollLeft(int scrollLeft)

@@void HTMLBodyElement::setScrollLeft(int
284287int HTMLBodyElement::scrollTop()
285288{
286289 // Update the document's layout.
287  Document* document = this->document();
288  document->updateLayoutIgnorePendingStylesheets();
 290 Document* document = this->document();
289291 FrameView* view = document->view();
290  return view ? adjustForZoom(view->scrollY(), document) : 0;
 292 if (document->inQuirksMode()) {
 293 document->updateLayoutIgnorePendingStylesheets();
 294 return view ? adjustForZoom(view->scrollY(), document) : 0;
 295 }
 296 return 0;
291297}
292298
293299void HTMLBodyElement::setScrollTop(int scrollTop)
154276

LayoutTests/ChangeLog

 12013-08-22 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 NOBODY (OOPS!).
 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 Rebaselining existing tests as per the new behavior. The test cases are changed to use
 29 quirks mode because it uses document.body.scrollTop/scrollLeft and as per the new code
 30 document.body.scrollTop/scrollLeft will return correct value if document is in quirk mode
 31 Also test cases have been modified so that it tests what it used to.
 32
1332013-08-21 Ryosuke Niwa <rniwa@webkit.org>
234
335 Update Mac test expectations.
154437

LayoutTests/fast/css/zoom-body-scroll-expected.txt

11Test for rdar://problem/6643103 Unscaled values from body.scrollHeight.
22
3 scrollHeight: 1000
4 scrollWidth: 1000
 3scrollHeight: 9999
 4scrollWidth: 9999
55
66Scrolling right to 50
77scrollLeft: 50
88
99Zooming in
10 scrollHeight: 1000
11 scrollWidth: 1000
12 scrollTop: 0
 10scrollHeight: 9999
 11scrollWidth: 9999
 12scrollTop: 100
1313scrollLeft: 50
1414
1515Scrolling down to 100
154276

LayoutTests/fast/css/zoom-body-scroll.html

1 <!DOCTYPE HTML>
21<html>
3 <body>
4  <div style="width: 1000px; height: 1000px; position: absolute; top: 0; left: 0;"></div>
 2<body onload="pageScroll()">
 3 <div style="width: 9999px; height: 9999px; position: absolute; top: 0; left: 0;"></div>
54 <div style="width: 100px; height: 100px; position: absolute; top: 100px; left: 0; background: green"></div>
65 <p>
76 Test for <i><a href="rdar://problem/6643103">rdar://problem/6643103</a>

1413 var console = document.getElementById("console");
1514 console.appendChild(document.createTextNode(message + "\n"));
1615 }
 16 function pageScroll() {
 17 window.scrollTo(50,100);
 18 setTimeout(bodyScroll(),3000);
 19 }
1720
18  if (window.testRunner) {
19  testRunner.dumpAsText();
20  var body = document.body;
21  log("scrollHeight: " + body.scrollHeight);
22  log("scrollWidth: " + body.scrollWidth);
 21 function bodyScroll() {
 22 if (window.testRunner) {
 23 testRunner.dumpAsText();
 24 var body = document.body;
 25 log("scrollHeight: " + body.scrollHeight);
 26 log("scrollWidth: " + body.scrollWidth);
2327
24  log("\nScrolling right to 50");
25  body.scrollLeft = 50;
26  log("scrollLeft: " + body.scrollLeft);
 28 log("\nScrolling right to 50");
 29 body.scrollLeft = 50;
 30 log("scrollLeft: " + body.scrollLeft);
2731
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);
 32 log("\nZooming in");
 33 eventSender.zoomPageIn();
 34 log("scrollHeight: " + body.scrollHeight);
 35 log("scrollWidth: " + body.scrollWidth);
 36 log("scrollTop: " + body.scrollTop);
 37 log("scrollLeft: " + body.scrollLeft);
3438
35  log("\nScrolling down to 100");
36  body.scrollTop = 100;
37  log("scrollTop: " + body.scrollTop);
 39 log("\nScrolling down to 100");
 40 body.scrollTop = 100;
 41 log("scrollTop: " + body.scrollTop);
3842
39  log("\nZooming back out");
40  eventSender.zoomPageOut();
41  log("scrollTop: " + body.scrollTop);
42  log("scrollLeft: " + body.scrollLeft);
 43 log("\nZooming back out");
 44 eventSender.zoomPageOut();
 45 log("scrollTop: " + body.scrollTop);
 46 log("scrollLeft: " + body.scrollLeft);
 47 }
4348 }
4449 </script>
4550</body>
154276

LayoutTests/fast/dom/Element/scrollLeft-Quirks-expected.txt

 1Tests that for quirks mode document.body.scrollLeft returns the scroll left value
 2
 3On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 4
 5
 6PASS 500 is window.pageXOffset
 7PASS 500 is document.body.scrollLeft
 8PASS 0 is document.documentElement.scrollLeft
 9PASS successfullyParsed is true
 10
 11TEST COMPLETE
 12
0

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

 1<html>
 2 <head>
 3 <style>
 4 div {
 5 height: 9999px;
 6 width:9999px;
 7 }
 8 </style>
 9 <script src="../../js/resources/js-test-pre.js"></script>
 10 <script>
 11 function runTest() {
 12 description('Tests that for quirks mode document.body.scrollLeft returns the scroll left value');
 13
 14 setTimeout(function() {
 15 window.scrollTo(500,0);
 16 shouldBe("500","window.pageXOffset");
 17 shouldBe("500","document.body.scrollLeft");
 18 shouldBe("0","document.documentElement.scrollLeft");
 19 finishJSTest();
 20 }, 0);
 21 }
 22 var jsTestIsAsync = true;
 23 </script>
 24 </head>
 25 <body onload="runTest()">
 26 <div></div>
 27 <script src="../../js/resources/js-test-post.js"></script>
 28 </body>
 29</html>
0

LayoutTests/fast/dom/Element/scrollLeft-expected.txt

 1Tests that for standard mode document.documentElement.scrollLeft returns the scroll left value
 2
 3On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 4
 5
 6PASS 500 is window.pageXOffset
 7PASS 0 is document.body.scrollLeft
 8PASS 500 is document.documentElement.scrollLeft
 9PASS successfullyParsed is true
 10
 11TEST COMPLETE
 12
0

LayoutTests/fast/dom/Element/scrollLeft.html

 1<!DOCTYPE html>
 2<html>
 3 <head>
 4 <style>
 5 div {
 6 height: 9999px;
 7 width:9999px;
 8 }
 9 </style>
 10 <script src="../../js/resources/js-test-pre.js"></script>
 11 <script>
 12 function runTest() {
 13 description('Tests that for standard mode document.documentElement.scrollLeft returns the scroll left value');
 14
 15 setTimeout(function() {
 16 window.scrollTo(500,0);
 17 shouldBe("500","window.pageXOffset");
 18 shouldBe("0","document.body.scrollLeft");
 19 shouldBe("500","document.documentElement.scrollLeft");
 20 finishJSTest();
 21 }, 0);
 22 }
 23 var jsTestIsAsync = true;
 24 </script>
 25 </head>
 26 <body onload="runTest()">
 27 <div></div>
 28 <script src="../../js/resources/js-test-post.js"></script>
 29 </body>
 30</html>
0

LayoutTests/fast/dom/Element/scrollTop-Quirks-expected.txt

 1Tests that for quirks mode document.body.scrollTop returns the scroll top value
 2
 3On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 4
 5
 6PASS 500 is window.pageYOffset
 7PASS 500 is document.body.scrollTop
 8PASS 0 is document.documentElement.scrollTop
 9PASS successfullyParsed is true
 10
 11TEST COMPLETE
 12
0

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

 1<html>
 2 <head>
 3 <style>
 4 div {
 5 height: 9999px;
 6 width:9999px;
 7 }
 8 </style>
 9 <script src="../../js/resources/js-test-pre.js"></script>
 10 <script>
 11 function runTest() {
 12 description('Tests that for quirks mode document.body.scrollTop returns the scroll top value');
 13
 14 setTimeout(function() {
 15 window.scrollTo(0,500);
 16 shouldBe("500","window.pageYOffset");
 17 shouldBe("500","document.body.scrollTop");
 18 shouldBe("0","document.documentElement.scrollTop");
 19 finishJSTest();
 20 }, 0);
 21 }
 22 var jsTestIsAsync = true;
 23 </script>
 24 </head>
 25 <body onload="runTest()">
 26 <div></div>
 27 <script src="../../js/resources/js-test-post.js"></script>
 28 </body>
 29</html>
0

LayoutTests/fast/dom/Element/scrollTop-expected.txt

 1Tests that for standard mode document.documentElement.scrollTop returns the scroll top value
 2
 3On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
 4
 5
 6PASS 500 is window.pageYOffset
 7PASS 0 is document.body.scrollTop
 8PASS 500 is document.documentElement.scrollTop
 9PASS successfullyParsed is true
 10
 11TEST COMPLETE
 12
0

LayoutTests/fast/dom/Element/scrollTop.html

 1<!DOCTYPE html>
 2<html>
 3 <head>
 4 <style>
 5 div {
 6 height: 9999px;
 7 width:9999px;
 8 }
 9 </style>
 10 <script src="../../js/resources/js-test-pre.js"></script>
 11 <script>
 12 function runTest() {
 13 description('Tests that for standard mode document.documentElement.scrollTop returns the scroll top value');
 14
 15 setTimeout(function() {
 16 window.scrollTo(0,500);
 17 shouldBe("500","window.pageYOffset");
 18 shouldBe("0","document.body.scrollTop");
 19 shouldBe("500","document.documentElement.scrollTop");
 20 finishJSTest();
 21 }, 0);
 22 }
 23 var jsTestIsAsync = true;
 24 </script>
 25 </head>
 26 <body onload="runTest()">
 27 <div></div>
 28 <script src="../../js/resources/js-test-post.js"></script>
 29 </body>
 30</html>
0

LayoutTests/fast/events/mouse-cursor.html

1 <!DOCTYPE html>
21<html>
32<head>
43<script src="../js/resources/js-test-pre.js"></script>
154276

LayoutTests/http/tests/navigation/anchor-frames-expected.txt

@@Tests that loading a frame with a URL th
88On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
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
1414PASS successfullyParsed is true
154276

LayoutTests/http/tests/navigation/anchor-frames-gbk-expected.txt

@@Tests that loading a frame with a URL th
88On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
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
1414PASS successfullyParsed is true
154276

LayoutTests/http/tests/navigation/resources/frame-with-anchor-gbk.html

1 <!DOCTYPE html>
21<html>
32<head>
43 <meta http-equiv="Content-Type" content="text/html; charset=gbk"/>
54 <script src="../../../js-test-resources/js-test-pre.js"></script>
65 <script>
76 function runTest() {
8  description('Tests that loading a frame with a URL that contains a fragment pointed at a named anchor actually scrolls to that anchor.');
 7 description('Tests that loading a frame with a URL that contains a fragment pointed at a named anchor actually scrolls to that anchor.');
98
109 // Check scroll position in a timeout to make sure that the anchor has
1110 // been scrolled to.
1211 setTimeout(function() {
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');
154276

LayoutTests/http/tests/navigation/resources/frame-with-anchor-same-origin.html

1 <!DOCTYPE html>
21<html>
32<head>
43 <script src="../../../js-test-resources/js-test-pre.js"></script>

1615 var jsTestIsAsync = true;
1716 </script>
1817</head>
19 <body>
 18<body onload="runTest()">
2019<!-- large same-origin grandchild frame -->
2120<iframe height="8000" width="8000" src="http://127.0.0.1:8000/navigation/resources/grandchild-with-anchor.html#anchor1" name="grandchild" onload="runTest()">
2221</iframe>
154276

LayoutTests/http/tests/navigation/resources/frame-with-anchor.html

1 <!DOCTYPE html>
21<html>
32<head>
43 <script src="../../../js-test-resources/js-test-pre.js"></script>
54 <script>
65 function runTest() {
7  description('Tests that loading a frame with a URL that contains a fragment pointed at a named anchor actually scrolls to that anchor.');
8 
 6 //description('Tests that loading a frame with a URL that contains a fragment pointed at a named anchor actually scrolls to that anchor.');
 7 alert(document.body.offsetHeight);
 8 alert(document.documentElement.clientHeight);
 9
910 // Check scroll position in a timeout to make sure that the anchor has
1011 // been scrolled to.
1112 setTimeout(function() {
1213 // Make sure that the body is taller than the viewport (i.e. scrolling is
1314 // required).
14  shouldBeTrue('document.body.offsetHeight > document.documentElement.clientHeight');
 15 shouldBeTrue('document.body.offsetHeight > window.innerHeight');
1516
1617 // We should be scrolled at least a little bit
1718 shouldBeTrue('document.body.scrollTop > 0');
154276

LayoutTests/platform/mac-wk2/tiled-drawing/tiled-drawing-scroll-position-page-cache-restoration.html

1 <!DOCTYPE html>
21<html>
32<head>
43 <script>
154276

LayoutTests/platform/mac-wk2/tiled-drawing/resources/scroll-and-load-page.html

1 <!DOCTYPE html>
21<html>
32<head>
43 <style>
154276