| 1 | /* |
| 2 | * Copyright (C) 2012, 2014-2015 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 23 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #pragma once |
| 27 | |
| 28 | #if ENABLE(ASYNC_SCROLLING) || USE(COORDINATED_GRAPHICS) |
| 29 | |
| 30 | #include "ScrollSnapOffsetsInfo.h" |
| 31 | #include "ScrollTypes.h" |
| 32 | #include "ScrollingCoordinator.h" |
| 33 | #include "ScrollingStateNode.h" |
| 34 | |
| 35 | #if PLATFORM(COCOA) |
| 36 | OBJC_CLASS NSScrollerImp; |
| 37 | #endif |
| 38 | |
| 39 | namespace WebCore { |
| 40 | |
| 41 | class ScrollingStateScrollingNode : public ScrollingStateNode { |
| 42 | public: |
| 43 | virtual ~ScrollingStateScrollingNode(); |
| 44 | |
| 45 | enum ChangedProperty { |
| 46 | ScrollableAreaSize = NumStateNodeBits, |
| 47 | TotalContentsSize, |
| 48 | ReachableContentsSize, |
| 49 | ParentRelativeScrollableRect, |
| 50 | ScrollPosition, |
| 51 | ScrollOrigin, |
| 52 | ScrollableAreaParams, |
| 53 | RequestedScrollPosition, |
| 54 | #if ENABLE(CSS_SCROLL_SNAP) |
| 55 | HorizontalSnapOffsets, |
| 56 | VerticalSnapOffsets, |
| 57 | HorizontalSnapOffsetRanges, |
| 58 | VerticalSnapOffsetRanges, |
| 59 | CurrentHorizontalSnapOffsetIndex, |
| 60 | CurrentVerticalSnapOffsetIndex, |
| 61 | #endif |
| 62 | ExpectsWheelEventTestTrigger, |
| 63 | ScrollContainerLayer, |
| 64 | ScrolledContentsLayer, |
| 65 | HorizontalScrollbarLayer, |
| 66 | VerticalScrollbarLayer, |
| 67 | PainterForScrollbar, |
| 68 | NumScrollingStateNodeBits // This must remain at the last position. |
| 69 | }; |
| 70 | |
| 71 | const FloatSize& scrollableAreaSize() const { return m_scrollableAreaSize; } |
| 72 | WEBCORE_EXPORT void setScrollableAreaSize(const FloatSize&); |
| 73 | |
| 74 | const FloatSize& totalContentsSize() const { return m_totalContentsSize; } |
| 75 | WEBCORE_EXPORT void setTotalContentsSize(const FloatSize&); |
| 76 | |
| 77 | const FloatSize& reachableContentsSize() const { return m_reachableContentsSize; } |
| 78 | WEBCORE_EXPORT void setReachableContentsSize(const FloatSize&); |
| 79 | |
| 80 | const LayoutRect& parentRelativeScrollableRect() const { return m_parentRelativeScrollableRect; } |
| 81 | WEBCORE_EXPORT void setParentRelativeScrollableRect(const LayoutRect&); |
| 82 | |
| 83 | const FloatPoint& scrollPosition() const { return m_scrollPosition; } |
| 84 | WEBCORE_EXPORT void setScrollPosition(const FloatPoint&); |
| 85 | |
| 86 | const IntPoint& scrollOrigin() const { return m_scrollOrigin; } |
| 87 | WEBCORE_EXPORT void setScrollOrigin(const IntPoint&); |
| 88 | |
| 89 | #if ENABLE(CSS_SCROLL_SNAP) |
| 90 | const Vector<float>& horizontalSnapOffsets() const { return m_snapOffsetsInfo.horizontalSnapOffsets; } |
| 91 | WEBCORE_EXPORT void setHorizontalSnapOffsets(const Vector<float>&); |
| 92 | |
| 93 | const Vector<float>& verticalSnapOffsets() const { return m_snapOffsetsInfo.verticalSnapOffsets; } |
| 94 | WEBCORE_EXPORT void setVerticalSnapOffsets(const Vector<float>&); |
| 95 | |
| 96 | const Vector<ScrollOffsetRange<float>>& horizontalSnapOffsetRanges() const { return m_snapOffsetsInfo.horizontalSnapOffsetRanges; } |
| 97 | WEBCORE_EXPORT void setHorizontalSnapOffsetRanges(const Vector<ScrollOffsetRange<float>>&); |
| 98 | |
| 99 | const Vector<ScrollOffsetRange<float>>& verticalSnapOffsetRanges() const { return m_snapOffsetsInfo.verticalSnapOffsetRanges; } |
| 100 | WEBCORE_EXPORT void setVerticalSnapOffsetRanges(const Vector<ScrollOffsetRange<float>>&); |
| 101 | |
| 102 | unsigned currentHorizontalSnapPointIndex() const { return m_currentHorizontalSnapPointIndex; } |
| 103 | WEBCORE_EXPORT void setCurrentHorizontalSnapPointIndex(unsigned); |
| 104 | |
| 105 | unsigned currentVerticalSnapPointIndex() const { return m_currentVerticalSnapPointIndex; } |
| 106 | WEBCORE_EXPORT void setCurrentVerticalSnapPointIndex(unsigned); |
| 107 | #endif |
| 108 | |
| 109 | const ScrollableAreaParameters& scrollableAreaParameters() const { return m_scrollableAreaParameters; } |
| 110 | WEBCORE_EXPORT void setScrollableAreaParameters(const ScrollableAreaParameters& params); |
| 111 | |
| 112 | const FloatPoint& requestedScrollPosition() const { return m_requestedScrollPosition; } |
| 113 | bool requestedScrollPositionRepresentsProgrammaticScroll() const { return m_requestedScrollPositionRepresentsProgrammaticScroll; } |
| 114 | WEBCORE_EXPORT void setRequestedScrollPosition(const FloatPoint&, bool representsProgrammaticScroll); |
| 115 | |
| 116 | bool expectsWheelEventTestTrigger() const { return m_expectsWheelEventTestTrigger; } |
| 117 | WEBCORE_EXPORT void setExpectsWheelEventTestTrigger(bool); |
| 118 | |
| 119 | const LayerRepresentation& scrollContainerLayer() const { return m_scrollContainerLayer; } |
| 120 | WEBCORE_EXPORT void setScrollContainerLayer(const LayerRepresentation&); |
| 121 | |
| 122 | // This is a layer with the contents that move. |
| 123 | const LayerRepresentation& scrolledContentsLayer() const { return m_scrolledContentsLayer; } |
| 124 | WEBCORE_EXPORT void setScrolledContentsLayer(const LayerRepresentation&); |
| 125 | |
| 126 | const LayerRepresentation& horizontalScrollbarLayer() const { return m_horizontalScrollbarLayer; } |
| 127 | WEBCORE_EXPORT void setHorizontalScrollbarLayer(const LayerRepresentation&); |
| 128 | |
| 129 | const LayerRepresentation& verticalScrollbarLayer() const { return m_verticalScrollbarLayer; } |
| 130 | WEBCORE_EXPORT void setVerticalScrollbarLayer(const LayerRepresentation&); |
| 131 | |
| 132 | #if PLATFORM(MAC) |
| 133 | NSScrollerImp *verticalScrollerImp() const { return m_verticalScrollerImp.get(); } |
| 134 | NSScrollerImp *horizontalScrollerImp() const { return m_horizontalScrollerImp.get(); } |
| 135 | #endif |
| 136 | void setScrollerImpsFromScrollbars(Scrollbar* verticalScrollbar, Scrollbar* horizontalScrollbar); |
| 137 | |
| 138 | protected: |
| 139 | ScrollingStateScrollingNode(ScrollingStateTree&, ScrollingNodeType, ScrollingNodeID); |
| 140 | ScrollingStateScrollingNode(const ScrollingStateScrollingNode&, ScrollingStateTree&); |
| 141 | |
| 142 | void setAllPropertiesChanged() override; |
| 143 | |
| 144 | void dumpProperties(WTF::TextStream&, ScrollingStateTreeAsTextBehavior) const override; |
| 145 | |
| 146 | private: |
| 147 | FloatSize m_scrollableAreaSize; |
| 148 | FloatSize m_totalContentsSize; |
| 149 | FloatSize m_reachableContentsSize; |
| 150 | LayoutRect m_parentRelativeScrollableRect; |
| 151 | FloatPoint m_scrollPosition; |
| 152 | FloatPoint m_requestedScrollPosition; |
| 153 | IntPoint m_scrollOrigin; |
| 154 | |
| 155 | #if ENABLE(CSS_SCROLL_SNAP) |
| 156 | ScrollSnapOffsetsInfo<float> m_snapOffsetsInfo; |
| 157 | unsigned m_currentHorizontalSnapPointIndex { 0 }; |
| 158 | unsigned m_currentVerticalSnapPointIndex { 0 }; |
| 159 | #endif |
| 160 | |
| 161 | LayerRepresentation m_scrollContainerLayer; |
| 162 | LayerRepresentation m_scrolledContentsLayer; |
| 163 | LayerRepresentation m_horizontalScrollbarLayer; |
| 164 | LayerRepresentation m_verticalScrollbarLayer; |
| 165 | |
| 166 | #if PLATFORM(MAC) |
| 167 | RetainPtr<NSScrollerImp> m_verticalScrollerImp; |
| 168 | RetainPtr<NSScrollerImp> m_horizontalScrollerImp; |
| 169 | #endif |
| 170 | |
| 171 | ScrollableAreaParameters m_scrollableAreaParameters; |
| 172 | |
| 173 | bool m_requestedScrollPositionRepresentsProgrammaticScroll { false }; |
| 174 | bool m_expectsWheelEventTestTrigger { false }; |
| 175 | }; |
| 176 | |
| 177 | } // namespace WebCore |
| 178 | |
| 179 | SPECIALIZE_TYPE_TRAITS_SCROLLING_STATE_NODE(ScrollingStateScrollingNode, isScrollingNode()) |
| 180 | |
| 181 | #endif // ENABLE(ASYNC_SCROLLING) || USE(COORDINATED_GRAPHICS) |
| 182 | |