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 "FloatPoint.h"
30
#include "FloatQuad.h"
32
#include "LayoutSize.h"
33
#include "RenderObject.h"
34
#include "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_accumulatingTransform(o.m_accumulatingTransform)
50
, m_isNonUniform(o.m_isNonUniform)
51
, m_isFixedPosition(o.m_isFixedPosition)
52
, m_hasTransform(o.m_hasTransform)
54
ASSERT(!o.m_transform);
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)
64
const RenderObject* m_renderer;
66
OwnPtr<TransformationMatrix> m_transform; // Includes offset if non-null.
67
bool m_accumulatingTransform;
68
bool m_isNonUniform; // Mapping depends on the input point, e.g. because of CSS columns.
69
bool m_isFixedPosition;
73
// Can be used while walking the Renderer tree to cache data about offsets and transforms.
74
class RenderGeometryMap {
75
WTF_MAKE_NONCOPYABLE(RenderGeometryMap);
77
RenderGeometryMap(MapCoordinatesFlags = UseTransforms | SnapOffsetForTransforms);
80
MapCoordinatesFlags mapCoordinatesFlags() const { return m_mapCoordinatesFlags; }
82
FloatPoint absolutePoint(const FloatPoint& p) const
84
return mapToContainer(p, 0);
87
FloatRect absoluteRect(const FloatRect& rect) const
89
return mapToContainer(rect, 0).boundingBox();
92
// Map to a container. Will assert that the container has been pushed onto this map.
93
// A null container maps through the RenderView (including its scale transform, if any).
94
// If the container is the RenderView, the scroll offset is applied, but not the scale.
95
FloatPoint mapToContainer(const FloatPoint&, const RenderLayerModelObject*) const;
96
FloatQuad mapToContainer(const FloatRect&, const RenderLayerModelObject*) const;
98
// Called by code walking the renderer or layer trees.
99
void pushMappingsToAncestor(const RenderLayer*, const RenderLayer* ancestorLayer);
100
void popMappingsToAncestor(const RenderLayer*);
101
void pushMappingsToAncestor(const RenderObject*, const RenderLayerModelObject* ancestorRenderer);
102
void popMappingsToAncestor(const RenderLayerModelObject*);
104
// The following methods should only be called by renderers inside a call to pushMappingsToAncestor().
106
// Push geometry info between this renderer and some ancestor. The ancestor must be its container() or some
107
// stacking context between the renderer and its container.
108
void push(const RenderObject*, const LayoutSize&, bool accumulatingTransform = false, bool isNonUniform = false, bool isFixedPosition = false, bool hasTransform = false);
109
void push(const RenderObject*, const TransformationMatrix&, bool accumulatingTransform = false, bool isNonUniform = false, bool isFixedPosition = false, bool hasTransform = false);
111
// RenderView gets special treatment, because it applies the scroll offset only for elements inside in fixed position.
112
void pushView(const RenderView*, const LayoutSize& scrollOffset, const TransformationMatrix* = 0);
115
void mapToContainer(TransformState&, const RenderLayerModelObject* container = 0) const;
117
void stepInserted(const RenderGeometryMapStep&);
118
void stepRemoved(const RenderGeometryMapStep&);
120
bool hasNonUniformStep() const { return m_nonUniformStepsCount; }
121
bool hasTransformStep() const { return m_transformedStepsCount; }
122
bool hasFixedPositionStep() const { return m_fixedStepsCount; }
124
typedef Vector<RenderGeometryMapStep, 32> RenderGeometryMapSteps;
126
size_t m_insertionPosition;
127
int m_nonUniformStepsCount;
128
int m_transformedStepsCount;
129
int m_fixedStepsCount;
130
RenderGeometryMapSteps m_mapping;
131
LayoutSize m_accumulatedOffset;
132
MapCoordinatesFlags m_mapCoordinatesFlags;
135
} // namespace WebCore
138
// This is required for a struct with OwnPtr. We know RenderGeometryMapStep is simple enough that
139
// initializing to 0 and moving with memcpy (and then not destructing the original) will work.
140
template<> struct VectorTraits<WebCore::RenderGeometryMapStep> : SimpleClassVectorTraits { };
143
#endif // RenderGeometryMap_h