Changeset 205505 in webkit
- Timestamp:
- Sep 6, 2016, 2:18:06 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r205503 r205505 1 2016-09-06 Simon Fraser <simon.fraser@apple.com> 2 3 Align element.scroll() / scrollTo() / scrollBy() with the CSSOM specification 4 https://bugs.webkit.org/show_bug.cgi?id=161610 5 6 Reviewed by Darin Adler, Chris Dumez. 7 8 * fast/dom/Element/scrolling-funtions-on-body-expected.txt: Added. 9 * fast/dom/Element/scrolling-funtions-on-body-quirks-expected.txt: Added. 10 * fast/dom/Element/scrolling-funtions-on-body-quirks.html: Added. 11 * fast/dom/Element/scrolling-funtions-on-body.html: Added. 12 * fast/dom/Element/scrolling-funtions-on-element-expected.txt: Added. 13 * fast/dom/Element/scrolling-funtions-on-element.html: Added. 14 1 15 2016-09-06 Ryan Haddad <ryanhaddad@apple.com> 2 16 -
trunk/Source/WebCore/ChangeLog
r205504 r205505 1 2016-09-06 Simon Fraser <simon.fraser@apple.com> 2 3 Align element.scroll() / scrollTo() / scrollBy() with the CSSOM specification 4 https://bugs.webkit.org/show_bug.cgi?id=161610 5 6 Reviewed by Darin Adler, Chris Dumez. 7 8 Implement Element.scroll(), scrollBy() and scrollTo() with x,y and ScrollToOptions 9 on Element, according to <https://drafts.csswg.org/cssom-view/#element-scrolling-members> 10 11 WebKit's behavior of treating scrolls on the body element in both quirks and strict mode 12 is preserved. 13 14 Tests: fast/dom/Element/scrolling-funtions-on-body-quirks.html 15 fast/dom/Element/scrolling-funtions-on-body.html 16 fast/dom/Element/scrolling-funtions-on-element.html 17 18 * dom/Element.cpp: 19 (WebCore::Element::scrollBy): 20 (WebCore::normalizeNonFiniteValue): 21 (WebCore::Element::scrollTo): 22 * dom/Element.h: 23 * dom/Element.idl: 24 * html/HTMLBodyElement.cpp: 25 (WebCore::HTMLBodyElement::scrollTo): 26 * html/HTMLBodyElement.h: 27 1 28 2016-09-06 Saam Barati <sbarati@apple.com> 2 29 -
trunk/Source/WebCore/dom/Element.cpp
r205468 r205505 685 685 renderer()->scrollRectToVisible(SelectionRevealMode::Reveal, bounds, ScrollAlignment::alignToEdgeIfNotVisible, ScrollAlignment::alignToEdgeIfNotVisible); 686 686 } 687 687 688 void Element::scrollBy(const ScrollToOptions& options) 689 { 690 return scrollBy(options.left.valueOr(0), options.top.valueOr(0)); 691 } 692 693 static inline double normalizeNonFiniteValue(double f) 694 { 695 return std::isfinite(f) ? f : 0; 696 } 697 698 void Element::scrollBy(double x, double y) 699 { 700 scrollTo(scrollLeft() + normalizeNonFiniteValue(x), scrollTop() + normalizeNonFiniteValue(y)); 701 } 702 703 void Element::scrollTo(const ScrollToOptions& options) 704 { 705 // If the element is the root element and document is in quirks mode, terminate these steps. 706 // Note that WebKit always uses quirks mode document scrolling behavior. See Document::scrollingElement(). 707 if (this == document().documentElement()) 708 return; 709 710 document().updateLayoutIgnorePendingStylesheets(); 711 712 // If the element does not have any associated CSS layout box, the element has no associated scrolling box, 713 // or the element has no overflow, terminate these steps. 714 RenderBox* renderer = renderBox(); 715 if (!renderer || !renderer->hasOverflowClip()) 716 return; 717 718 // Normalize non-finite values for left and top dictionary members of options, if present. 719 double x = options.left ? normalizeNonFiniteValue(options.left.value()) : adjustForAbsoluteZoom(renderer->scrollLeft(), *renderer); 720 double y = options.top ? normalizeNonFiniteValue(options.top.value()) : adjustForAbsoluteZoom(renderer->scrollTop(), *renderer); 721 722 renderer->setScrollLeft(clampToInteger(x * renderer->style().effectiveZoom())); 723 renderer->setScrollTop(clampToInteger(y * renderer->style().effectiveZoom())); 724 } 725 726 void Element::scrollTo(double x, double y) 727 { 728 scrollTo({ x, y }); 729 } 730 688 731 void Element::scrollByUnits(int units, ScrollGranularity granularity) 689 732 { … … 827 870 document().updateLayoutIgnorePendingStylesheets(); 828 871 829 if ( RenderBox* renderer = renderBox()) {872 if (auto* renderer = renderBox()) { 830 873 LayoutUnit clientLeft = subpixelMetricsEnabled(renderer->document()) ? renderer->clientLeft() : LayoutUnit(roundToInt(renderer->clientLeft())); 831 874 return convertToNonSubpixelValueIfNeeded(adjustLayoutUnitForAbsoluteZoom(clientLeft, *renderer).toDouble(), renderer->document()); … … 838 881 document().updateLayoutIgnorePendingStylesheets(); 839 882 840 if ( RenderBox* renderer = renderBox()) {883 if (auto* renderer = renderBox()) { 841 884 LayoutUnit clientTop = subpixelMetricsEnabled(renderer->document()) ? renderer->clientTop() : LayoutUnit(roundToInt(renderer->clientTop())); 842 885 return convertToNonSubpixelValueIfNeeded(adjustLayoutUnitForAbsoluteZoom(clientTop, *renderer).toDouble(), renderer->document()); … … 851 894 if (!document().hasLivingRenderTree()) 852 895 return 0; 896 853 897 RenderView& renderView = *document().renderView(); 854 898 … … 871 915 if (!document().hasLivingRenderTree()) 872 916 return 0; 917 873 918 RenderView& renderView = *document().renderView(); 874 919 … … 890 935 document().updateLayoutIgnorePendingStylesheets(); 891 936 892 if ( RenderBox* rend= renderBox())893 return adjustForAbsoluteZoom(rend ->scrollLeft(), *rend);937 if (auto* renderer = renderBox()) 938 return adjustForAbsoluteZoom(renderer->scrollLeft(), *renderer); 894 939 return 0; 895 940 } … … 899 944 document().updateLayoutIgnorePendingStylesheets(); 900 945 901 if (RenderBox* rend = renderBox())902 return adjustForAbsoluteZoom(rend ->scrollTop(), *rend);946 if (RenderBox* renderer = renderBox()) 947 return adjustForAbsoluteZoom(renderer->scrollTop(), *renderer); 903 948 return 0; 904 949 } … … 908 953 document().updateLayoutIgnorePendingStylesheets(); 909 954 910 if ( RenderBox* renderer = renderBox()) {955 if (auto* renderer = renderBox()) { 911 956 renderer->setScrollLeft(static_cast<int>(newLeft * renderer->style().effectiveZoom())); 912 957 if (auto* scrollableArea = renderer->layer()) … … 919 964 document().updateLayoutIgnorePendingStylesheets(); 920 965 921 if ( RenderBox* renderer = renderBox()) {966 if (auto* renderer = renderBox()) { 922 967 renderer->setScrollTop(static_cast<int>(newTop * renderer->style().effectiveZoom())); 923 968 if (auto* scrollableArea = renderer->layer()) … … 929 974 { 930 975 document().updateLayoutIfDimensionsOutOfDate(*this, WidthDimensionsCheck); 931 if ( RenderBox* rend= renderBox())932 return adjustForAbsoluteZoom(rend ->scrollWidth(), *rend);976 if (auto* renderer = renderBox()) 977 return adjustForAbsoluteZoom(renderer->scrollWidth(), *renderer); 933 978 return 0; 934 979 } … … 937 982 { 938 983 document().updateLayoutIfDimensionsOutOfDate(*this, HeightDimensionsCheck); 939 if ( RenderBox* rend= renderBox())940 return adjustForAbsoluteZoom(rend ->scrollHeight(), *rend);984 if (auto* renderer = renderBox()) 985 return adjustForAbsoluteZoom(renderer->scrollHeight(), *renderer); 941 986 return 0; 942 987 } -
trunk/Source/WebCore/dom/Element.h
r205468 r205505 137 137 WEBCORE_EXPORT void scrollIntoViewIfNotVisible(bool centerIfNotVisible = true); 138 138 139 struct ScrollToOptions { 140 Optional<double> left; 141 Optional<double> top; 142 }; 143 144 void scrollBy(const ScrollToOptions&); 145 void scrollBy(double x, double y); 146 virtual void scrollTo(const ScrollToOptions&); 147 void scrollTo(double x, double y); 148 139 149 WEBCORE_EXPORT void scrollByLines(int lines); 140 150 WEBCORE_EXPORT void scrollByPages(int pages); … … 158 168 WEBCORE_EXPORT double clientWidth(); 159 169 WEBCORE_EXPORT double clientHeight(); 170 160 171 virtual int scrollLeft(); 161 172 virtual int scrollTop(); -
trunk/Source/WebCore/dom/Element.idl
r205280 r205505 72 72 readonly attribute double clientHeight; 73 73 74 attribute long scrollLeft; 75 attribute long scrollTop; 74 attribute long scrollLeft; // FIXME: should be unrestricted double 75 attribute long scrollTop; // FIXME: should be unrestricted double 76 76 readonly attribute long scrollWidth; 77 77 readonly attribute long scrollHeight; … … 81 81 void scrollIntoView(optional boolean alignWithTop = true); 82 82 83 sequence<DOMString> getAttributeNames();84 85 83 void scrollIntoViewIfNeeded(optional boolean centerIfNeeded = true); 84 85 [ImplementedAs=scrollTo] void scroll(optional ScrollToOptions options); 86 [ImplementedAs=scrollTo] void scroll(unrestricted double x, unrestricted double y); 87 88 void scrollTo(optional ScrollToOptions options); 89 void scrollTo(unrestricted double x, unrestricted double y); 90 91 void scrollBy(optional ScrollToOptions option); 92 void scrollBy(unrestricted double x, unrestricted double y); 93 86 94 void scrollByLines(optional long lines = 0); 87 95 void scrollByPages(optional long pages = 0); 96 97 sequence<DOMString> getAttributeNames(); 88 98 89 99 HTMLCollection getElementsByClassName(DOMString name); … … 179 189 }; 180 190 191 // FIXME: Support ScrollBehavior. 192 dictionary ScrollToOptions { 193 unrestricted double left; 194 unrestricted double top; 195 }; 196 181 197 Element implements Animatable; 182 198 Element implements ChildNode; -
trunk/Source/WebCore/html/HTMLBodyElement.cpp
r203324 r205505 28 28 #include "CSSParser.h" 29 29 #include "CSSValueKeywords.h" 30 #include "DOMWindow.h" 30 31 #include "EventNames.h" 31 32 #include "Frame.h" … … 295 296 } 296 297 298 void HTMLBodyElement::scrollTo(const ScrollToOptions& options) 299 { 300 if (isFirstBodyElementOfDocument()) { 301 // If the element is the HTML body element, document is in quirks mode, and the element is not potentially scrollable, 302 // invoke scroll() on window with options as the only argument, and terminate these steps. 303 // Note that WebKit always uses quirks mode document scrolling behavior. See Document::scrollingElement(). 304 // FIXME: Scrolling an independently scrollable body is broken: webkit.org/b/161612. 305 auto* window = document().domWindow(); 306 if (!window) 307 return; 308 309 window->scrollTo({ options.left, options.top }); 310 return; 311 } 312 return HTMLElement::scrollTo(options); 313 } 314 297 315 int HTMLBodyElement::scrollHeight() 298 316 { -
trunk/Source/WebCore/html/HTMLBodyElement.h
r203264 r205505 57 57 int scrollTop() final; 58 58 void setScrollTop(int) final; 59 60 void scrollTo(const ScrollToOptions&) final; 59 61 60 62 int scrollHeight() final;
Note:
See TracChangeset
for help on using the changeset viewer.