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/RenderGeometryMapStep.h" 30 #include "core/rendering/RenderObject.h" 31 #include "platform/geometry/FloatPoint.h" 32 #include "platform/geometry/FloatQuad.h" 33 #include "platform/geometry/IntSize.h" 34 #include "platform/geometry/LayoutSize.h" 35 #include "wtf/OwnPtr.h" 36 37 namespace blink { 38 39 class RenderLayer; 40 class RenderLayerModelObject; 41 class TransformationMatrix; 42 class TransformState; 43 44 // Can be used while walking the Renderer tree to cache data about offsets and transforms. 45 class RenderGeometryMap { 46 WTF_MAKE_NONCOPYABLE(RenderGeometryMap); 47 public: 48 RenderGeometryMap(MapCoordinatesFlags = UseTransforms); 49 ~RenderGeometryMap(); 50 mapCoordinatesFlags()51 MapCoordinatesFlags mapCoordinatesFlags() const { return m_mapCoordinatesFlags; } 52 absoluteRect(const FloatRect & rect)53 FloatRect absoluteRect(const FloatRect& rect) const 54 { 55 return mapToContainer(rect, 0).boundingBox(); 56 } 57 58 // Map to a container. Will assert that the container has been pushed onto this map. 59 // A null container maps through the RenderView (including its scale transform, if any). 60 // If the container is the RenderView, the scroll offset is applied, but not the scale. 61 FloatPoint mapToContainer(const FloatPoint&, const RenderLayerModelObject*) const; 62 FloatQuad mapToContainer(const FloatRect&, const RenderLayerModelObject*) const; 63 64 // Called by code walking the renderer or layer trees. 65 void pushMappingsToAncestor(const RenderLayer*, const RenderLayer* ancestorLayer); 66 void popMappingsToAncestor(const RenderLayer*); 67 void pushMappingsToAncestor(const RenderObject*, const RenderLayerModelObject* ancestorRenderer); 68 void popMappingsToAncestor(const RenderLayerModelObject*); 69 70 // The following methods should only be called by renderers inside a call to pushMappingsToAncestor(). 71 72 // Push geometry info between this renderer and some ancestor. The ancestor must be its container() or some 73 // stacking context between the renderer and its container. 74 void push(const RenderObject*, const LayoutSize&, bool accumulatingTransform = false, bool isNonUniform = false, bool isFixedPosition = false, bool hasTransform = false, LayoutSize offsetForFixedPosition = LayoutSize()); 75 void push(const RenderObject*, const TransformationMatrix&, bool accumulatingTransform = false, bool isNonUniform = false, bool isFixedPosition = false, bool hasTransform = false, LayoutSize offsetForFixedPosition = LayoutSize()); 76 77 private: 78 void mapToContainer(TransformState&, const RenderLayerModelObject* container = 0) const; 79 80 void stepInserted(const RenderGeometryMapStep&); 81 void stepRemoved(const RenderGeometryMapStep&); 82 hasNonUniformStep()83 bool hasNonUniformStep() const { return m_nonUniformStepsCount; } hasTransformStep()84 bool hasTransformStep() const { return m_transformedStepsCount; } hasFixedPositionStep()85 bool hasFixedPositionStep() const { return m_fixedStepsCount; } 86 87 #ifndef NDEBUG 88 void dumpSteps() const; 89 #endif 90 91 #if ENABLE(ASSERT) 92 bool isTopmostRenderView(const RenderObject* renderer) const; 93 #endif 94 95 typedef Vector<RenderGeometryMapStep, 32> RenderGeometryMapSteps; 96 97 size_t m_insertionPosition; 98 int m_nonUniformStepsCount; 99 int m_transformedStepsCount; 100 int m_fixedStepsCount; 101 RenderGeometryMapSteps m_mapping; 102 LayoutSize m_accumulatedOffset; 103 MapCoordinatesFlags m_mapCoordinatesFlags; 104 }; 105 106 } // namespace blink 107 108 #endif // RenderGeometryMap_h 109