2 * Copyright (C) 2012 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef RenderGeometryMap_h
27 #define RenderGeometryMap_h
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"
40 class RenderLayerModelObject;
44 // Stores data about how to map from one renderer to its container.
45 struct RenderGeometryMapStep {
46 RenderGeometryMapStep(const RenderGeometryMapStep& o)
47 : m_renderer(o.m_renderer)
48 , m_offset(o.m_offset)
49 , m_offsetForFixedPosition(o.m_offsetForFixedPosition)
50 , m_accumulatingTransform(o.m_accumulatingTransform)
51 , m_isNonUniform(o.m_isNonUniform)
52 , m_isFixedPosition(o.m_isFixedPosition)
53 , m_hasTransform(o.m_hasTransform)
55 ASSERT(!o.m_transform);
57 RenderGeometryMapStep(const RenderObject* renderer, bool accumulatingTransform, bool isNonUniform, bool isFixedPosition, bool hasTransform)
58 : m_renderer(renderer)
59 , m_accumulatingTransform(accumulatingTransform)
60 , m_isNonUniform(isNonUniform)
61 , m_isFixedPosition(isFixedPosition)
62 , m_hasTransform(hasTransform)
65 const RenderObject* m_renderer;
67 OwnPtr<TransformationMatrix> m_transform; // Includes offset if non-null.
68 LayoutSize m_offsetForFixedPosition;
69 bool m_accumulatingTransform;
70 bool m_isNonUniform; // Mapping depends on the input point, e.g. because of CSS columns.
71 bool m_isFixedPosition;
75 // Can be used while walking the Renderer tree to cache data about offsets and transforms.
76 class RenderGeometryMap {
77 WTF_MAKE_NONCOPYABLE(RenderGeometryMap);
79 RenderGeometryMap(MapCoordinatesFlags = UseTransforms);
82 MapCoordinatesFlags mapCoordinatesFlags() const { return m_mapCoordinatesFlags; }
84 FloatPoint absolutePoint(const FloatPoint& p) const
86 return mapToContainer(p, 0);
89 FloatRect absoluteRect(const FloatRect& rect) const
91 return mapToContainer(rect, 0).boundingBox();
94 // Map to a container. Will assert that the container has been pushed onto this map.
95 // A null container maps through the RenderView (including its scale transform, if any).
96 // If the container is the RenderView, the scroll offset is applied, but not the scale.
97 FloatPoint mapToContainer(const FloatPoint&, const RenderLayerModelObject*) const;
98 FloatQuad mapToContainer(const FloatRect&, const RenderLayerModelObject*) const;
100 // Called by code walking the renderer or layer trees.
101 void pushMappingsToAncestor(const RenderLayer*, const RenderLayer* ancestorLayer);
102 void popMappingsToAncestor(const RenderLayer*);
103 void pushMappingsToAncestor(const RenderObject*, const RenderLayerModelObject* ancestorRenderer);
104 void popMappingsToAncestor(const RenderLayerModelObject*);
106 // The following methods should only be called by renderers inside a call to pushMappingsToAncestor().
108 // Push geometry info between this renderer and some ancestor. The ancestor must be its container() or some
109 // stacking context between the renderer and its container.
110 void push(const RenderObject*, const LayoutSize&, bool accumulatingTransform = false, bool isNonUniform = false, bool isFixedPosition = false, bool hasTransform = false, LayoutSize offsetForFixedPosition = LayoutSize());
111 void push(const RenderObject*, const TransformationMatrix&, bool accumulatingTransform = false, bool isNonUniform = false, bool isFixedPosition = false, bool hasTransform = false, LayoutSize offsetForFixedPosition = LayoutSize());
114 void mapToContainer(TransformState&, const RenderLayerModelObject* container = 0) const;
116 void stepInserted(const RenderGeometryMapStep&);
117 void stepRemoved(const RenderGeometryMapStep&);
119 bool hasNonUniformStep() const { return m_nonUniformStepsCount; }
120 bool hasTransformStep() const { return m_transformedStepsCount; }
121 bool hasFixedPositionStep() const { return m_fixedStepsCount; }
128 bool isTopmostRenderView(const RenderObject* renderer) const;
131 typedef Vector<RenderGeometryMapStep, 32> RenderGeometryMapSteps;
133 size_t m_insertionPosition;
134 int m_nonUniformStepsCount;
135 int m_transformedStepsCount;
136 int m_fixedStepsCount;
137 RenderGeometryMapSteps m_mapping;
138 LayoutSize m_accumulatedOffset;
139 MapCoordinatesFlags m_mapCoordinatesFlags;
142 } // namespace WebCore
144 WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(WebCore::RenderGeometryMapStep);
146 #endif // RenderGeometryMap_h