<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[172543] trunk/Source/WebCore</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/172543">172543</a></dd>
<dt>Author</dt> <dd>commit-queue@webkit.org</dd>
<dt>Date</dt> <dd>2014-08-13 17:16:03 -0700 (Wed, 13 Aug 2014)</dd>
</dl>
<h3>Log Message</h3>
<pre>Compute and store snap point positions
https://bugs.webkit.org/show_bug.cgi?id=135268
Patch by Wenson Hsieh <wenson_hsieh@apple.com> on 2014-08-13
Reviewed by Simon Fraser.
Working towards implementing a way to extract snap positions (i.e. LayoutUnits) from the parsed snap point properties from CSS,
as well as a way of storing the information. Supports both mainframe and overflow scrolling.
No changes in behavior. I will write tests when I implement snapping for iOS and Mac.
* WebCore.xcodeproj/project.pbxproj:
* page/FrameView.cpp:
(WebCore::FrameView::updateSnapOffsets): Invokes the static routine in AxisScrollSnapOffsets to update snap offsets for mainframe.
* page/FrameView.h:
* page/scrolling/AxisScrollSnapOffsets.cpp: Added.
(WebCore::appendAndSortChildSnapOffsets):
(WebCore::updateFromStyle):
(WebCore::updateSnapOffsetsForScrollableArea): Update the ScrollableArea's snap axes.
* page/scrolling/AxisScrollSnapOffsets.h: Added.
* platform/ScrollableArea.cpp:
(WebCore::ScrollableArea::setHorizontalSnapOffsets):
(WebCore::ScrollableArea::setVerticalSnapOffsets):
(WebCore::ScrollableArea::clearHorizontalSnapOffsets): Resets the unique_ptr for horizontal snap points.
(WebCore::ScrollableArea::clearVerticalSnapOffsets): Resets the unique_ptr for vertical snap points.
* platform/ScrollableArea.h:
(WebCore::ScrollableArea::horizontalSnapOffsets): Returns a pointer to the ScrollableArea's horizontal snap points.
(WebCore::ScrollableArea::verticalSnapOffsets): Returns a pointer to the ScrollableArea's vertical snap points.
(WebCore::ScrollableArea::updateSnapOffsets):
* rendering/RenderLayer.cpp:
(WebCore::RenderLayer::updateSnapOffsets): Invokes the static routine in AxisScrollSnapOffsets to update snap offsets for an overflow area.
* rendering/RenderLayer.h:</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCorepageFrameViewcpp">trunk/Source/WebCore/page/FrameView.cpp</a></li>
<li><a href="#trunkSourceWebCorepageFrameViewh">trunk/Source/WebCore/page/FrameView.h</a></li>
<li><a href="#trunkSourceWebCoreplatformScrollableAreacpp">trunk/Source/WebCore/platform/ScrollableArea.cpp</a></li>
<li><a href="#trunkSourceWebCoreplatformScrollableAreah">trunk/Source/WebCore/platform/ScrollableArea.h</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderLayercpp">trunk/Source/WebCore/rendering/RenderLayer.cpp</a></li>
<li><a href="#trunkSourceWebCorerenderingRenderLayerh">trunk/Source/WebCore/rendering/RenderLayer.h</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWebCorepagescrollingAxisScrollSnapOffsetscpp">trunk/Source/WebCore/page/scrolling/AxisScrollSnapOffsets.cpp</a></li>
<li><a href="#trunkSourceWebCorepagescrollingAxisScrollSnapOffsetsh">trunk/Source/WebCore/page/scrolling/AxisScrollSnapOffsets.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (172542 => 172543)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2014-08-13 23:55:10 UTC (rev 172542)
+++ trunk/Source/WebCore/ChangeLog        2014-08-14 00:16:03 UTC (rev 172543)
</span><span class="lines">@@ -1,3 +1,37 @@
</span><ins>+2014-08-13 Wenson Hsieh <wenson_hsieh@apple.com>
+
+ Compute and store snap point positions
+ https://bugs.webkit.org/show_bug.cgi?id=135268
+
+ Reviewed by Simon Fraser.
+
+ Working towards implementing a way to extract snap positions (i.e. LayoutUnits) from the parsed snap point properties from CSS,
+ as well as a way of storing the information. Supports both mainframe and overflow scrolling.
+
+ No changes in behavior. I will write tests when I implement snapping for iOS and Mac.
+
+ * WebCore.xcodeproj/project.pbxproj:
+ * page/FrameView.cpp:
+ (WebCore::FrameView::updateSnapOffsets): Invokes the static routine in AxisScrollSnapOffsets to update snap offsets for mainframe.
+ * page/FrameView.h:
+ * page/scrolling/AxisScrollSnapOffsets.cpp: Added.
+ (WebCore::appendAndSortChildSnapOffsets):
+ (WebCore::updateFromStyle):
+ (WebCore::updateSnapOffsetsForScrollableArea): Update the ScrollableArea's snap axes.
+ * page/scrolling/AxisScrollSnapOffsets.h: Added.
+ * platform/ScrollableArea.cpp:
+ (WebCore::ScrollableArea::setHorizontalSnapOffsets):
+ (WebCore::ScrollableArea::setVerticalSnapOffsets):
+ (WebCore::ScrollableArea::clearHorizontalSnapOffsets): Resets the unique_ptr for horizontal snap points.
+ (WebCore::ScrollableArea::clearVerticalSnapOffsets): Resets the unique_ptr for vertical snap points.
+ * platform/ScrollableArea.h:
+ (WebCore::ScrollableArea::horizontalSnapOffsets): Returns a pointer to the ScrollableArea's horizontal snap points.
+ (WebCore::ScrollableArea::verticalSnapOffsets): Returns a pointer to the ScrollableArea's vertical snap points.
+ (WebCore::ScrollableArea::updateSnapOffsets):
+ * rendering/RenderLayer.cpp:
+ (WebCore::RenderLayer::updateSnapOffsets): Invokes the static routine in AxisScrollSnapOffsets to update snap offsets for an overflow area.
+ * rendering/RenderLayer.h:
+
</ins><span class="cx"> 2014-08-13 Mark Rowe <mrowe@apple.com>
</span><span class="cx">
</span><span class="cx"> <https://webkit.org/b/135911> WebKit should build on Yosemite with the public SDK.
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (172542 => 172543)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-08-13 23:55:10 UTC (rev 172542)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2014-08-14 00:16:03 UTC (rev 172543)
</span><span class="lines">@@ -6245,6 +6245,8 @@
</span><span class="cx">                 F3F5CF1112ED81A80084C569 /* InspectorConsoleInstrumentation.h in Headers */ = {isa = PBXBuildFile; fileRef = F3F5CF1012ED81A80084C569 /* InspectorConsoleInstrumentation.h */; };
</span><span class="cx">                 F3F5CF1312ED81B30084C569 /* InspectorDatabaseInstrumentation.h in Headers */ = {isa = PBXBuildFile; fileRef = F3F5CF1212ED81B30084C569 /* InspectorDatabaseInstrumentation.h */; };
</span><span class="cx">                 F42FFB461984B71600F6837F /* LengthRepeat.h in Headers */ = {isa = PBXBuildFile; fileRef = F42FFB451984B71600F6837F /* LengthRepeat.h */; };
</span><ins>+                F45C231D1995B73B00A6E2E3 /* AxisScrollSnapOffsets.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F45C231B1995B73B00A6E2E3 /* AxisScrollSnapOffsets.cpp */; };
+                F45C231E1995B73B00A6E2E3 /* AxisScrollSnapOffsets.h in Headers */ = {isa = PBXBuildFile; fileRef = F45C231C1995B73B00A6E2E3 /* AxisScrollSnapOffsets.h */; settings = {ATTRIBUTES = (Private, ); }; };
</ins><span class="cx">                 F47A5E3E195B8C8A00483100 /* StyleScrollSnapPoints.h in Headers */ = {isa = PBXBuildFile; fileRef = F47A5E3B195B8C8A00483100 /* StyleScrollSnapPoints.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 F47A5E3F195B8E4800483100 /* StyleScrollSnapPoints.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F47A5E3A195B8C8A00483100 /* StyleScrollSnapPoints.cpp */; };
</span><span class="cx">                 F50664F7157F52DC00AC226F /* FormController.cpp in Sources */ = {isa = PBXBuildFile; fileRef = F50664F5157F52DC00AC226F /* FormController.cpp */; };
</span><span class="lines">@@ -13762,6 +13764,8 @@
</span><span class="cx">                 F3F5CF1012ED81A80084C569 /* InspectorConsoleInstrumentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorConsoleInstrumentation.h; sourceTree = "<group>"; };
</span><span class="cx">                 F3F5CF1212ED81B30084C569 /* InspectorDatabaseInstrumentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorDatabaseInstrumentation.h; sourceTree = "<group>"; };
</span><span class="cx">                 F42FFB451984B71600F6837F /* LengthRepeat.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LengthRepeat.h; sourceTree = "<group>"; };
</span><ins>+                F45C231B1995B73B00A6E2E3 /* AxisScrollSnapOffsets.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = AxisScrollSnapOffsets.cpp; sourceTree = "<group>"; };
+                F45C231C1995B73B00A6E2E3 /* AxisScrollSnapOffsets.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AxisScrollSnapOffsets.h; sourceTree = "<group>"; };
</ins><span class="cx">                 F47A5E3A195B8C8A00483100 /* StyleScrollSnapPoints.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = StyleScrollSnapPoints.cpp; path = style/StyleScrollSnapPoints.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 F47A5E3B195B8C8A00483100 /* StyleScrollSnapPoints.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = StyleScrollSnapPoints.h; path = style/StyleScrollSnapPoints.h; sourceTree = "<group>"; };
</span><span class="cx">                 F50664F5157F52DC00AC226F /* FormController.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FormController.cpp; sourceTree = "<group>"; };
</span><span class="lines">@@ -15137,6 +15141,8 @@
</span><span class="cx">                                 9391A99B1629D70000297330 /* ScrollingTreeScrollingNode.h */,
</span><span class="cx">                                 0F6383DB18615B29003E5DB5 /* ThreadedScrollingTree.cpp */,
</span><span class="cx">                                 0F6383DC18615B29003E5DB5 /* ThreadedScrollingTree.h */,
</span><ins>+                                F45C231B1995B73B00A6E2E3 /* AxisScrollSnapOffsets.cpp */,
+                                F45C231C1995B73B00A6E2E3 /* AxisScrollSnapOffsets.h */,
</ins><span class="cx">                         );
</span><span class="cx">                         path = scrolling;
</span><span class="cx">                         sourceTree = "<group>";
</span><span class="lines">@@ -24419,6 +24425,7 @@
</span><span class="cx">                                 A81369E0097374F600D74463 /* HTMLLegendElement.h in Headers */,
</span><span class="cx">                                 A8EA79F60A1916DF00A8EF5F /* HTMLLIElement.h in Headers */,
</span><span class="cx">                                 A871DC200A15205700B12A68 /* HTMLLinkElement.h in Headers */,
</span><ins>+                                F45C231E1995B73B00A6E2E3 /* AxisScrollSnapOffsets.h in Headers */,
</ins><span class="cx">                                 A8EA7D2C0A19385500A8EF5F /* HTMLMapElement.h in Headers */,
</span><span class="cx">                                 A8EA7CAB0A192B9C00A8EF5F /* HTMLMarqueeElement.h in Headers */,
</span><span class="cx">                                 E44613A50CD6331000FADA75 /* HTMLMediaElement.h in Headers */,
</span><span class="lines">@@ -27754,6 +27761,7 @@
</span><span class="cx">                                 B2AFFC7D0D00A5C10030074D /* FontCustomPlatformData.cpp in Sources */,
</span><span class="cx">                                 371F4F410D25B9AF00ECE0D5 /* FontData.cpp in Sources */,
</span><span class="cx">                                 37ACCF690DA414E70089E602 /* FontDescription.cpp in Sources */,
</span><ins>+                                F45C231D1995B73B00A6E2E3 /* AxisScrollSnapOffsets.cpp in Sources */,
</ins><span class="cx">                                 72626E020EF022FE00A07E20 /* FontFastPath.cpp in Sources */,
</span><span class="cx">                                 4A6E9FC713C17D570046A7F8 /* FontFeatureSettings.cpp in Sources */,
</span><span class="cx">                                 E44EE3A817577EBD00EEE8CF /* FontGenericFamilies.cpp in Sources */,
</span></span></pre></div>
<a id="trunkSourceWebCorepageFrameViewcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/FrameView.cpp (172542 => 172543)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/FrameView.cpp        2014-08-13 23:55:10 UTC (rev 172542)
+++ trunk/Source/WebCore/page/FrameView.cpp        2014-08-14 00:16:03 UTC (rev 172543)
</span><span class="lines">@@ -98,6 +98,10 @@
</span><span class="cx"> #include "TextAutosizer.h"
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+#if ENABLE(CSS_SCROLL_SNAP)
+#include "AxisScrollSnapOffsets.h"
+#endif
+
</ins><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx"> #include "DocumentLoader.h"
</span><span class="cx"> #include "LegacyTileCache.h"
</span><span class="lines">@@ -847,6 +851,21 @@
</span><span class="cx">
</span><span class="cx"> #endif // ENABLE(RUBBER_BANDING)
</span><span class="cx">
</span><ins>+#if ENABLE(CSS_SCROLL_SNAP)
+void FrameView::updateSnapOffsets()
+{
+ if (!frame().document())
+ return;
+
+ // FIXME: Should we allow specifying snap points through <html> tags too?
+ HTMLElement* body = frame().document()->body();
+ if (!renderView() || !body || !body->renderer())
+ return;
+
+ updateSnapOffsetsForScrollableArea(*this, *body, *renderView(), body->renderer()->style());
+}
+#endif
+
</ins><span class="cx"> bool FrameView::flushCompositingStateForThisFrame(Frame* rootFrameForFlush)
</span><span class="cx"> {
</span><span class="cx"> RenderView* renderView = this->renderView();
</span></span></pre></div>
<a id="trunkSourceWebCorepageFrameViewh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/page/FrameView.h (172542 => 172543)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/FrameView.h        2014-08-13 23:55:10 UTC (rev 172542)
+++ trunk/Source/WebCore/page/FrameView.h        2014-08-14 00:16:03 UTC (rev 172543)
</span><span class="lines">@@ -496,6 +496,10 @@
</span><span class="cx"> void setExposedRect(FloatRect);
</span><span class="cx"> FloatRect exposedRect() const { return m_exposedRect; }
</span><span class="cx">
</span><ins>+#if ENABLE(CSS_SCROLL_SNAP)
+ virtual void updateSnapOffsets() override;
+#endif
+
</ins><span class="cx"> protected:
</span><span class="cx"> virtual bool scrollContentsFastPath(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect) override;
</span><span class="cx"> virtual void scrollContentsSlowPath(const IntRect& updateRect) override;
</span></span></pre></div>
<a id="trunkSourceWebCorepagescrollingAxisScrollSnapOffsetscpp"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/page/scrolling/AxisScrollSnapOffsets.cpp (0 => 172543)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/AxisScrollSnapOffsets.cpp         (rev 0)
+++ trunk/Source/WebCore/page/scrolling/AxisScrollSnapOffsets.cpp        2014-08-14 00:16:03 UTC (rev 172543)
</span><span class="lines">@@ -0,0 +1,150 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "AxisScrollSnapOffsets.h"
+
+#include "HTMLCollection.h"
+#include "HTMLElement.h"
+#include "RenderBox.h"
+#include "ScrollableArea.h"
+
+#if ENABLE(CSS_SCROLL_SNAP)
+
+namespace WebCore {
+
+static void appendChildSnapOffsets(HTMLElement& parent, bool shouldAddHorizontalChildOffsets, Vector<LayoutUnit>& horizontalSnapOffsetSubsequence, bool shouldAddVerticalChildOffsets, Vector<LayoutUnit>& verticalSnapOffsetSubsequence)
+{
+ Element* child = parent.children()->collectionBegin();
+ // FIXME: Instead of traversing all children, register children with snap coordinates before appending to snapOffsetSubsequence.
+ while (child) {
+ if (RenderBox* box = child->renderBox()) {
+ LayoutUnit viewWidth = box->width();
+ LayoutUnit viewHeight = box->height();
+ // FIXME: Check behavior with CSS rotations.
+ FloatPoint position = box->localToContainerPoint(FloatPoint(), parent.renderBox());
+ for (SnapCoordinate coordinate : box->style().scrollSnapCoordinates()) {
+ LayoutUnit lastPotentialSnapPositionX = LayoutUnit(position.x()) + valueForLength(coordinate.first, viewWidth);
+ if (shouldAddHorizontalChildOffsets && lastPotentialSnapPositionX > 0)
+ horizontalSnapOffsetSubsequence.append(lastPotentialSnapPositionX);
+
+ LayoutUnit lastPotentialSnapPositionY = LayoutUnit(position.y()) + valueForLength(coordinate.second, viewHeight);
+ if (shouldAddVerticalChildOffsets && lastPotentialSnapPositionY > 0)
+ verticalSnapOffsetSubsequence.append(lastPotentialSnapPositionY);
+ }
+ }
+ child = child->nextElementSibling();
+ }
+}
+
+static void updateFromStyle(Vector<LayoutUnit>* snapOffsets, const RenderStyle& style, ScrollEventAxis axis, LayoutUnit viewSize, LayoutUnit scrollSize, Vector<LayoutUnit>& snapOffsetSubsequence)
+{
+ std::sort(snapOffsetSubsequence.begin(), snapOffsetSubsequence.end());
+ if (!snapOffsetSubsequence.size())
+ snapOffsetSubsequence.append(0);
+
+ bool isHorizontalAxis = axis == ScrollEventAxis::Horizontal;
+ bool hasRepeat = isHorizontalAxis ? style.scrollSnapHasRepeatX() : style.scrollSnapHasRepeatY();
+ LayoutUnit repeatOffset = valueForLength(isHorizontalAxis ? style.scrollSnapRepeatOffsetX() : style.scrollSnapRepeatOffsetY(), viewSize);
+ LayoutUnit destinationOffset = valueForLength(isHorizontalAxis ? style.scrollSnapDestinationX() : style.scrollSnapDestinationY(), viewSize);
+ LayoutUnit curSnapPositionShift = 0;
+ LayoutUnit maxScrollOffset = scrollSize - viewSize;
+ LayoutUnit lastSnapPosition = curSnapPositionShift;
+ snapOffsets->append(0);
+ do {
+ for (LayoutUnit snapPosition : snapOffsetSubsequence) {
+ LayoutUnit potentialSnapPosition = curSnapPositionShift + snapPosition - destinationOffset;
+ if (potentialSnapPosition <= 0)
+ continue;
+
+ if (potentialSnapPosition >= maxScrollOffset)
+ break;
+
+ snapOffsets->append(potentialSnapPosition);
+ lastSnapPosition = potentialSnapPosition + destinationOffset;
+ }
+ curSnapPositionShift = lastSnapPosition + repeatOffset;
+ } while (hasRepeat && curSnapPositionShift < maxScrollOffset);
+ // Always put a snap point on the maximum scroll offset.
+ // Not a part of the spec, but necessary to prevent unreachable content when snapping.
+ if (snapOffsets->last() != maxScrollOffset)
+ snapOffsets->append(maxScrollOffset);
+}
+
+void updateSnapOffsetsForScrollableArea(ScrollableArea& scrollableArea, HTMLElement& scrollingElement, const RenderBox& scrollingElementBox, const RenderStyle& scrollingElementStyle)
+{
+ if (scrollingElementStyle.scrollSnapType() == ScrollSnapType::None) {
+ scrollableArea.clearHorizontalSnapOffsets();
+ scrollableArea.clearVerticalSnapOffsets();
+ return;
+ }
+ LayoutUnit viewWidth = scrollingElementBox.width();
+ LayoutUnit viewHeight = scrollingElementBox.height();
+ LayoutUnit scrollWidth = scrollingElementBox.scrollWidth();
+ LayoutUnit scrollHeight = scrollingElementBox.scrollHeight();
+ bool canComputeHorizontalOffsets = scrollWidth > 0 && viewWidth > 0 && viewWidth < scrollWidth;
+ bool canComputeVerticalOffsets = scrollHeight > 0 && viewHeight > 0 && viewHeight < scrollHeight;
+ if (!canComputeHorizontalOffsets)
+ scrollableArea.clearHorizontalSnapOffsets();
+
+ if (!canComputeVerticalOffsets)
+ scrollableArea.clearVerticalSnapOffsets();
+
+ if (!canComputeHorizontalOffsets && !canComputeVerticalOffsets)
+ return;
+
+ Vector<LayoutUnit> horizontalSnapOffsetSubsequence;
+ Vector<LayoutUnit> verticalSnapOffsetSubsequence;
+ if (scrollingElementStyle.scrollSnapUsesElementsX() || scrollingElementStyle.scrollSnapUsesElementsY()) {
+ bool shouldAddHorizontalChildOffsets = scrollingElementStyle.scrollSnapUsesElementsX() && canComputeHorizontalOffsets;
+ bool shouldAddVerticalChildOffsets = scrollingElementStyle.scrollSnapUsesElementsY() && canComputeVerticalOffsets;
+ appendChildSnapOffsets(scrollingElement, shouldAddHorizontalChildOffsets, horizontalSnapOffsetSubsequence, shouldAddVerticalChildOffsets, verticalSnapOffsetSubsequence);
+ }
+
+ if (!scrollingElementStyle.scrollSnapUsesElementsX() && canComputeHorizontalOffsets) {
+ for (Length snapLength : scrollingElementStyle.scrollSnapOffsetsX())
+ horizontalSnapOffsetSubsequence.append(valueForLength(snapLength, viewWidth));
+ }
+
+ if (!scrollingElementStyle.scrollSnapUsesElementsY() && canComputeVerticalOffsets) {
+ for (Length snapLength : scrollingElementStyle.scrollSnapOffsetsY())
+ verticalSnapOffsetSubsequence.append(valueForLength(snapLength, viewHeight));
+ }
+
+ std::unique_ptr<Vector<LayoutUnit>> horizontalSnapOffsets = std::make_unique<Vector<LayoutUnit>>();
+ std::unique_ptr<Vector<LayoutUnit>> verticalSnapOffsets = std::make_unique<Vector<LayoutUnit>>();
+ if (canComputeHorizontalOffsets) {
+ updateFromStyle(horizontalSnapOffsets.get(), scrollingElementStyle, ScrollEventAxis::Horizontal, viewWidth, scrollWidth, horizontalSnapOffsetSubsequence);
+ scrollableArea.setHorizontalSnapOffsets(WTF::move(horizontalSnapOffsets));
+ }
+ if (canComputeVerticalOffsets) {
+ updateFromStyle(verticalSnapOffsets.get(), scrollingElementStyle, ScrollEventAxis::Vertical, viewHeight, scrollHeight, verticalSnapOffsetSubsequence);
+ scrollableArea.setVerticalSnapOffsets(WTF::move(verticalSnapOffsets));
+ }
+}
+
+} // namespace WebCore
+
+#endif // CSS_SCROLL_SNAP
</ins></span></pre></div>
<a id="trunkSourceWebCorepagescrollingAxisScrollSnapOffsetsh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/page/scrolling/AxisScrollSnapOffsets.h (0 => 172543)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/page/scrolling/AxisScrollSnapOffsets.h         (rev 0)
+++ trunk/Source/WebCore/page/scrolling/AxisScrollSnapOffsets.h        2014-08-14 00:16:03 UTC (rev 172543)
</span><span class="lines">@@ -0,0 +1,49 @@
</span><ins>+/*
+ * Copyright (C) 2014 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef AxisScrollSnapOffsets_h
+#define AxisScrollSnapOffsets_h
+
+#if ENABLE(CSS_SCROLL_SNAP)
+
+#include "LayoutUnit.h"
+#include "ScrollTypes.h"
+#include <wtf/PassOwnPtr.h>
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class HTMLElement;
+class RenderBox;
+class RenderStyle;
+class ScrollableArea;
+
+void updateSnapOffsetsForScrollableArea(ScrollableArea&, HTMLElement& scrollingElement, const RenderBox& scrollingElementBox, const RenderStyle& scrollingElementStyle);
+
+} // namespace WebCore
+
+#endif // CSS_SCROLL_SNAP
+
+#endif // AxisScrollSnapOffsets_h
</ins></span></pre></div>
<a id="trunkSourceWebCoreplatformScrollableAreacpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ScrollableArea.cpp (172542 => 172543)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ScrollableArea.cpp        2014-08-13 23:55:10 UTC (rev 172542)
+++ trunk/Source/WebCore/platform/ScrollableArea.cpp        2014-08-14 00:16:03 UTC (rev 172543)
</span><span class="lines">@@ -45,7 +45,11 @@
</span><span class="cx">
</span><span class="cx"> struct SameSizeAsScrollableArea {
</span><span class="cx"> virtual ~SameSizeAsScrollableArea();
</span><ins>+#if ENABLE(CSS_SCROLL_SNAP)
+ void* pointers[3];
+#else
</ins><span class="cx"> void* pointer;
</span><ins>+#endif
</ins><span class="cx"> IntPoint origin;
</span><span class="cx"> unsigned bitfields : 16;
</span><span class="cx"> };
</span><span class="lines">@@ -376,6 +380,28 @@
</span><span class="cx"> return layerForScrollCorner();
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#if ENABLE(CSS_SCROLL_SNAP)
+void ScrollableArea::setHorizontalSnapOffsets(std::unique_ptr<Vector<LayoutUnit>> horizontalSnapOffsets)
+{
+ m_horizontalSnapOffsets = WTF::move(horizontalSnapOffsets);
+}
+
+void ScrollableArea::setVerticalSnapOffsets(std::unique_ptr<Vector<LayoutUnit>> verticalSnapOffsets)
+{
+ m_verticalSnapOffsets = WTF::move(verticalSnapOffsets);
+}
+
+void ScrollableArea::clearHorizontalSnapOffsets()
+{
+ m_horizontalSnapOffsets = nullptr;
+}
+
+void ScrollableArea::clearVerticalSnapOffsets()
+{
+ m_verticalSnapOffsets = nullptr;
+}
+#endif
+
</ins><span class="cx"> void ScrollableArea::serviceScrollAnimations()
</span><span class="cx"> {
</span><span class="cx"> if (ScrollAnimator* scrollAnimator = existingScrollAnimator())
</span></span></pre></div>
<a id="trunkSourceWebCoreplatformScrollableAreah"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/platform/ScrollableArea.h (172542 => 172543)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/platform/ScrollableArea.h        2014-08-13 23:55:10 UTC (rev 172542)
+++ trunk/Source/WebCore/platform/ScrollableArea.h        2014-08-14 00:16:03 UTC (rev 172543)
</span><span class="lines">@@ -58,6 +58,16 @@
</span><span class="cx">
</span><span class="cx"> bool handleWheelEvent(const PlatformWheelEvent&);
</span><span class="cx">
</span><ins>+#if ENABLE(CSS_SCROLL_SNAP)
+ const Vector<LayoutUnit>* horizontalSnapOffsets() const { return m_horizontalSnapOffsets.get(); };
+ const Vector<LayoutUnit>* verticalSnapOffsets() const { return m_verticalSnapOffsets.get(); };
+ virtual void updateSnapOffsets() { };
+ void setHorizontalSnapOffsets(std::unique_ptr<Vector<LayoutUnit>>);
+ void setVerticalSnapOffsets(std::unique_ptr<Vector<LayoutUnit>>);
+ void clearHorizontalSnapOffsets();
+ void clearVerticalSnapOffsets();
+#endif
+
</ins><span class="cx"> #if ENABLE(TOUCH_EVENTS)
</span><span class="cx"> virtual bool isTouchScrollable() const { return false; }
</span><span class="cx"> virtual bool handleTouchEvent(const PlatformTouchEvent&);
</span><span class="lines">@@ -275,6 +285,11 @@
</span><span class="cx">
</span><span class="cx"> mutable OwnPtr<ScrollAnimator> m_scrollAnimator;
</span><span class="cx">
</span><ins>+#if ENABLE(CSS_SCROLL_SNAP)
+ std::unique_ptr<Vector<LayoutUnit>> m_horizontalSnapOffsets;
+ std::unique_ptr<Vector<LayoutUnit>> m_verticalSnapOffsets;
+#endif
+
</ins><span class="cx"> // There are 8 possible combinations of writing mode and direction. Scroll origin will be non-zero in the x or y axis
</span><span class="cx"> // if there is any reversed direction or writing-mode. The combinations are:
</span><span class="cx"> // writing-mode / direction scrollOrigin.x() set scrollOrigin.y() set
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderLayercpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderLayer.cpp (172542 => 172543)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderLayer.cpp        2014-08-13 23:55:10 UTC (rev 172542)
+++ trunk/Source/WebCore/rendering/RenderLayer.cpp        2014-08-14 00:16:03 UTC (rev 172543)
</span><span class="lines">@@ -122,6 +122,10 @@
</span><span class="cx"> #include "RenderLayerFilterInfo.h"
</span><span class="cx"> #endif
</span><span class="cx">
</span><ins>+#if ENABLE(CSS_SCROLL_SNAP)
+#include "AxisScrollSnapOffsets.h"
+#endif
+
</ins><span class="cx"> #define MIN_INTERSECT_FOR_REVEAL 32
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -3028,6 +3032,18 @@
</span><span class="cx"> return 0;
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+#if ENABLE(CSS_SCROLL_SNAP)
+void RenderLayer::updateSnapOffsets()
+{
+ // FIXME: Extend support beyond HTMLElements.
+ if (!enclosingElement() || !enclosingElement()->renderBox() || !enclosingElement()->isHTMLElement())
+ return;
+
+ RenderBox* box = enclosingElement()->renderBox();
+ updateSnapOffsetsForScrollableArea(*this, *toHTMLElement(enclosingElement()), *box, box->style());
+}
+#endif
+
</ins><span class="cx"> int RenderLayer::verticalScrollbarWidth(OverlayScrollbarSizeRelevancy relevancy) const
</span><span class="cx"> {
</span><span class="cx"> if (!m_vBar
</span></span></pre></div>
<a id="trunkSourceWebCorerenderingRenderLayerh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/rendering/RenderLayer.h (172542 => 172543)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/rendering/RenderLayer.h        2014-08-13 23:55:10 UTC (rev 172542)
+++ trunk/Source/WebCore/rendering/RenderLayer.h        2014-08-14 00:16:03 UTC (rev 172543)
</span><span class="lines">@@ -439,6 +439,9 @@
</span><span class="cx"> virtual Scrollbar* horizontalScrollbar() const override { return m_hBar.get(); }
</span><span class="cx"> virtual Scrollbar* verticalScrollbar() const override { return m_vBar.get(); }
</span><span class="cx"> virtual ScrollableArea* enclosingScrollableArea() const override;
</span><ins>+#if ENABLE(CSS_SCROLL_SNAP)
+ virtual void updateSnapOffsets() override;
+#endif
</ins><span class="cx">
</span><span class="cx"> #if PLATFORM(IOS)
</span><span class="cx"> #if ENABLE(TOUCH_EVENTS)
</span></span></pre>
</div>
</div>
</body>
</html>