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 COMPUTER, INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #ifndef RenderGeometryMap_h 27 #define RenderGeometryMap_h 28 29 #include "core/rendering/RenderObject.h" 30 #include "platform/geometry/FloatPoint.h" 31 #include "platform/geometry/FloatQuad.h" 32 #include "platform/geometry/IntSize.h" 33 #include "platform/geometry/LayoutSize.h" 34 #include "platform/transforms/TransformationMatrix.h" 35 #include "wtf/OwnPtr.h" 36 37 namespace WebCore { 38 39 class RenderLayer; 40 class RenderLayerModelObject; 41 class TransformState; 42 43 // Stores data about how to map from one renderer to its container. 44 struct RenderGeometryMapStep { 45 RenderGeometryMapStep(const RenderGeometryMapStep& o) 46 : m_renderer(o.m_renderer) 47 , m_offset(o.m_offset) 48 , m_offsetForFixedPosition(o.m_offsetForFixedPosition) 49 , m_accumulatingTransform(o.m_accumulatingTransform) 50 , m_isNonUniform(o.m_isNonUniform) 51 , m_isFixedPosition(o.m_isFixedPosition) 52 , m_hasTransform(o.m_hasTransform) 53 { 54 ASSERT(!o.m_transform); 55 } 56 RenderGeometryMapStep(const RenderObject* renderer, bool accumulatingTransform, bool isNonUniform, bool isFixedPosition, bool hasTransform) 57 : m_renderer(renderer) 58 , m_accumulatingTransform(accumulatingTransform) 59 , m_isNonUniform(isNonUniform) 60 , m_isFixedPosition(isFixedPosition) 61 , m_hasTransform(hasTransform) 62 { 63 } 64 const RenderObject* m_renderer; 65 LayoutSize m_offset; 66 OwnPtr<TransformationMatrix> m_transform; // Includes offset if non-null. 67 LayoutSize m_offsetForFixedPosition; 68 bool m_accumulatingTransform; 69 bool m_isNonUniform; // Mapping depends on the input point, e.g. because of CSS columns. 70 bool m_isFixedPosition; 71 bool m_hasTransform; 72 }; 73 74 // Can be used while walking the Renderer tree to cache data about offsets and transforms. 75 class RenderGeometryMap { 76 WTF_MAKE_NONCOPYABLE(RenderGeometryMap); 77 public: 78 RenderGeometryMap(MapCoordinatesFlags = UseTransforms); 79 ~RenderGeometryMap(); 80 81 MapCoordinatesFlags mapCoordinatesFlags() const { return m_mapCoordinatesFlags; } 82 83 FloatPoint absolutePoint(const FloatPoint& p) const 84 { 85 return mapToContainer(p, 0); 86 } 87 88 FloatRect absoluteRect(const FloatRect& rect) const 89 { 90 return mapToContainer(rect, 0).boundingBox(); 91 } 92 93 // Map to a container. Will assert that the container has been pushed onto this map. 94 // A null container maps through the RenderView (including its scale transform, if any). 95 // If the container is the RenderView, the scroll offset is applied, but not the scale. 96 FloatPoint mapToContainer(const FloatPoint&, const RenderLayerModelObject*) const; 97 FloatQuad mapToContainer(const FloatRect&, const RenderLayerModelObject*) const; 98 99 // Called by code walking the renderer or layer trees. 100 void pushMappingsToAncestor(const RenderLayer*, const RenderLayer* ancestorLayer); 101 void popMappingsToAncestor(const RenderLayer*); 102 void pushMappingsToAncestor(const RenderObject*, const RenderLayerModelObject* ancestorRenderer); 103 void popMappingsToAncestor(const RenderLayerModelObject*); 104 105 // The following methods should only be called by renderers inside a call to pushMappingsToAncestor(). 106 107 // Push geometry info between this renderer and some ancestor. The ancestor must be its container() or some 108 // stacking context between the renderer and its container. 109 void push(const RenderObject*, const LayoutSize&, bool accumulatingTransform = false, bool isNonUniform = false, bool isFixedPosition = false, bool hasTransform = false, LayoutSize offsetForFixedPosition = LayoutSize()); 110 void push(const RenderObject*, const TransformationMatrix&, bool accumulatingTransform = false, bool isNonUniform = false, bool isFixedPosition = false, bool hasTransform = false, LayoutSize offsetForFixedPosition = LayoutSize()); 111 112 private: 113 void mapToContainer(TransformState&, const RenderLayerModelObject* container = 0) const; 114 115 void stepInserted(const RenderGeometryMapStep&); 116 void stepRemoved(const RenderGeometryMapStep&); 117 118 bool hasNonUniformStep() const { return m_nonUniformStepsCount; } 119 bool hasTransformStep() const { return m_transformedStepsCount; } 120 bool hasFixedPositionStep() const { return m_fixedStepsCount; } 121 122 #ifndef NDEBUG 123 void dumpSteps() const; 124 #endif 125 126 #if ASSERT_ENABLED 127 bool isTopmostRenderView(const RenderObject* renderer) const; 128 #endif 129 130 typedef Vector<RenderGeometryMapStep, 32> RenderGeometryMapSteps; 131 132 size_t m_insertionPosition; 133 int m_nonUniformStepsCount; 134 int m_transformedStepsCount; 135 int m_fixedStepsCount; 136 RenderGeometryMapSteps m_mapping; 137 LayoutSize m_accumulatedOffset; 138 MapCoordinatesFlags m_mapCoordinatesFlags; 139 }; 140 141 } // namespace WebCore 142 143 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(WebCore::RenderGeometryMapStep); 144 145 #endif // RenderGeometryMap_h 146