1/* 2 * Copyright (C) 2012 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#ifndef ScrollingStateNode_h 27#define ScrollingStateNode_h 28 29#if ENABLE(THREADED_SCROLLING) || USE(COORDINATED_GRAPHICS) 30 31#include "PlatformLayer.h" 32#include "ScrollingCoordinator.h" 33#include <wtf/OwnPtr.h> 34#include <wtf/PassOwnPtr.h> 35#include <wtf/Vector.h> 36 37#if PLATFORM(MAC) 38#include <wtf/RetainPtr.h> 39#endif 40 41namespace WebCore { 42 43class GraphicsLayer; 44class ScrollingStateTree; 45class TextStream; 46 47class ScrollingStateNode { 48public: 49 ScrollingStateNode(ScrollingStateTree*, ScrollingNodeID); 50 virtual ~ScrollingStateNode(); 51 52 virtual bool isScrollingNode() { return false; } 53 virtual bool isFixedNode() { return false; } 54 virtual bool isStickyNode() { return false; } 55 56 virtual PassOwnPtr<ScrollingStateNode> clone() = 0; 57 PassOwnPtr<ScrollingStateNode> cloneAndReset(); 58 void cloneAndResetChildren(ScrollingStateNode*); 59 60 enum { 61 ScrollLayer = 0, 62 NumStateNodeBits = 1 63 }; 64 typedef unsigned ChangedProperties; 65 66 bool hasChangedProperties() const { return m_changedProperties; } 67 bool hasChangedProperty(unsigned propertyBit) { return m_changedProperties & (1 << propertyBit); } 68 void resetChangedProperties() { m_changedProperties = 0; } 69 void setPropertyChanged(unsigned propertyBit) { m_changedProperties |= (1 << propertyBit); } 70 71 virtual void syncLayerPositionForViewportRect(const LayoutRect& /*viewportRect*/) { } 72 73 GraphicsLayer* graphicsLayer() { return m_graphicsLayer; } 74 PlatformLayer* platformScrollLayer() const; 75 void setScrollLayer(GraphicsLayer*); 76 void setScrollPlatformLayer(PlatformLayer*); 77 78 ScrollingStateTree* scrollingStateTree() const { return m_scrollingStateTree; } 79 void setScrollingStateTree(ScrollingStateTree* tree) { m_scrollingStateTree = tree; } 80 81 ScrollingNodeID scrollingNodeID() const { return m_nodeID; } 82 83 ScrollingStateNode* parent() const { return m_parent; } 84 void setParent(ScrollingStateNode* parent) { m_parent = parent; } 85 86 Vector<OwnPtr<ScrollingStateNode> >* children() const { return m_children.get(); } 87 88 void appendChild(PassOwnPtr<ScrollingStateNode>); 89 void removeChild(ScrollingStateNode*); 90 91 String scrollingStateTreeAsText() const; 92 93protected: 94 ScrollingStateNode(const ScrollingStateNode&); 95 static void writeIndent(TextStream&, int indent); 96 97 ScrollingStateTree* m_scrollingStateTree; 98 99private: 100 void dump(TextStream&, int indent) const; 101 102 virtual void dumpProperties(TextStream&, int indent) const = 0; 103 ChangedProperties changedProperties() const { return m_changedProperties; } 104 void willBeRemovedFromStateTree(); 105 106 ScrollingNodeID m_nodeID; 107 ChangedProperties m_changedProperties; 108 109 ScrollingStateNode* m_parent; 110 OwnPtr<Vector<OwnPtr<ScrollingStateNode> > > m_children; 111 112#if PLATFORM(MAC) 113 RetainPtr<PlatformLayer> m_platformScrollLayer; 114#endif 115 GraphicsLayer* m_graphicsLayer; 116 117}; 118 119} // namespace WebCore 120 121#endif // ENABLE(THREADED_SCROLLING) || USE(COORDINATED_GRAPHICS) 122 123#endif // ScrollingStateNode_h 124