Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1024)

Unified Diff: Source/core/html/HTMLBodyElement.cpp

Issue 51553002: Fix body.scrollTop/Left for scrollable <body> tags (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « LayoutTests/fast/dom/Element/scrollTop-scrollLeft-body-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/core/html/HTMLBodyElement.cpp
diff --git a/Source/core/html/HTMLBodyElement.cpp b/Source/core/html/HTMLBodyElement.cpp
index 8c7b52c1a6e728f4af668f41aac51283bab893da..28554423bed4212612bbfbd4b60c7d6bff88fe56 100644
--- a/Source/core/html/HTMLBodyElement.cpp
+++ b/Source/core/html/HTMLBodyElement.cpp
@@ -36,6 +36,7 @@
#include "core/html/parser/HTMLParserIdioms.h"
#include "core/frame/Frame.h"
#include "core/frame/FrameView.h"
+#include "core/rendering/RenderBox.h"
namespace WebCore {
@@ -197,17 +198,28 @@ static int adjustForZoom(int value, Document* document)
return static_cast<int>(value / zoomFactor);
}
-// FIXME: There are cases where body.scrollLeft is allowed to return
-// non-zero values in both quirks and strict mode. It happens when
-// <body> has an overflow that is not the Frame overflow.
-// http://dev.w3.org/csswg/cssom-view/#dom-element-scrollleft
-// http://code.google.com/p/chromium/issues/detail?id=312435
+// Blink, Gecko and Presto's quirks mode implementations of overflow set to the
+// body element differ from IE's: the formers can create a scrollable area for the
+// body element that is not the same as the root elements's one. On IE's quirks mode
+// though, as body is the root element, body's and the root element's scrollable areas,
+// if any, are the same.
+// In order words, a <body> will only have an overflow clip (that differs from
+// documentElement's) if both html and body nodes have its overflow set to either hidden,
+// auto or scroll.
+// That said, Blink's {set}scroll{Top,Left} behaviors match Gecko's: even if there is a non-overflown
+// scrollable area, scrolling should not get propagated to the viewport in neither strict
+// or quirks modes.
int HTMLBodyElement::scrollLeft()
{
Document& document = this->document();
document.updateLayoutIgnorePendingStylesheets();
if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) {
+ RenderBox* render = renderBox();
+ if (!render)
+ return 0;
+ if (render->hasOverflowClip())
+ return adjustForAbsoluteZoom(render->scrollLeft(), render);
if (!document.inQuirksMode())
return 0;
}
@@ -222,6 +234,14 @@ void HTMLBodyElement::setScrollLeft(int scrollLeft)
document.updateLayoutIgnorePendingStylesheets();
if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) {
+ RenderBox* render = renderBox();
+ if (!render)
+ return;
+ if (render->hasOverflowClip()) {
+ // FIXME: Investigate how are other browsers casting to int (rounding, ceiling, ...).
+ render->setScrollLeft(static_cast<int>(scrollLeft * render->style()->effectiveZoom()));
+ return;
+ }
if (!document.inQuirksMode())
return;
}
@@ -241,6 +261,11 @@ int HTMLBodyElement::scrollTop()
document.updateLayoutIgnorePendingStylesheets();
if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) {
+ RenderBox* render = renderBox();
+ if (!render)
+ return 0;
+ if (render->hasOverflowClip())
+ return adjustForAbsoluteZoom(render->scrollTop(), render);
if (!document.inQuirksMode())
return 0;
}
@@ -255,6 +280,14 @@ void HTMLBodyElement::setScrollTop(int scrollTop)
document.updateLayoutIgnorePendingStylesheets();
if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) {
+ RenderBox* render = renderBox();
+ if (!render)
+ return;
+ if (render->hasOverflowClip()) {
+ // FIXME: Investigate how are other browsers casting to int (rounding, ceiling, ...).
+ render->setScrollTop(static_cast<int>(scrollTop * render->style()->effectiveZoom()));
+ return;
+ }
if (!document.inQuirksMode())
return;
}
« no previous file with comments | « LayoutTests/fast/dom/Element/scrollTop-scrollLeft-body-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698