Fix the issue that Web Audio test case fails on PR3.
[framework/web/webkit-efl.git] / Source / WebCore / rendering / RenderGeometryMap.h
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 "FloatPoint.h"
30 #include "FloatQuad.h"
31 #include "IntSize.h"
32 #include "RenderObject.h"
33 #include "TransformationMatrix.h"
34 #include <wtf/OwnPtr.h>
35
36 namespace WebCore {
37
38 class RenderLayer;
39
40 // Stores data about how to map from one renderer to its container.
41 struct RenderGeometryMapStep {
42     RenderGeometryMapStep(const RenderGeometryMapStep& o)
43         : m_renderer(o.m_renderer)
44         , m_offset(o.m_offset)
45         , m_accumulatingTransform(o.m_accumulatingTransform)
46         , m_isNonUniform(o.m_isNonUniform)
47         , m_isFixedPosition(o.m_isFixedPosition)
48         , m_hasTransform(o.m_hasTransform)
49     {
50         ASSERT(!o.m_transform);
51     }
52     RenderGeometryMapStep(const RenderObject* renderer, bool accumulatingTransform, bool isNonUniform, bool isFixedPosition, bool hasTransform)
53         : m_renderer(renderer)
54         , m_accumulatingTransform(accumulatingTransform)
55         , m_isNonUniform(isNonUniform)
56         , m_isFixedPosition(isFixedPosition)
57         , m_hasTransform(hasTransform)
58     {
59     }
60     const RenderObject* m_renderer;
61     LayoutSize m_offset;
62     OwnPtr<TransformationMatrix> m_transform; // Includes offset if non-null.
63     bool m_accumulatingTransform;
64     bool m_isNonUniform; // Mapping depends on the input point, e.g. because of CSS columns.
65     bool m_isFixedPosition;
66     bool m_hasTransform;
67 };
68
69 // Can be used while walking the Renderer tree to cache data about offsets and transforms.
70 class RenderGeometryMap {
71     WTF_MAKE_NONCOPYABLE(RenderGeometryMap);
72 public:
73     RenderGeometryMap();
74     ~RenderGeometryMap();
75
76     FloatPoint absolutePoint(const FloatPoint&) const;
77     FloatRect absoluteRect(const FloatRect&) const;
78     
79     // Called by code walking the renderer or layer trees.
80     void pushMappingsToAncestor(const RenderLayer*, const RenderLayer* ancestorLayer);
81     void popMappingsToAncestor(const RenderLayer*);
82     void pushMappingsToAncestor(const RenderObject*, const RenderBoxModelObject* ancestorRenderer);
83     void popMappingsToAncestor(const RenderBoxModelObject*);
84     
85     // The following methods should only be called by renderers inside a call to pushMappingsToAncestor().
86
87     // Push geometry info between this renderer and some ancestor. The ancestor must be its container() or some
88     // stacking context between the renderer and its container.
89     void push(const RenderObject*, const LayoutSize&, bool accumulatingTransform = false, bool isNonUniform = false, bool isFixedPosition = false, bool hasTransform = false);
90     void push(const RenderObject*, const TransformationMatrix&, bool accumulatingTransform = false, bool isNonUniform = false, bool isFixedPosition = false, bool hasTransform = false);
91
92     // RenderView gets special treatment, because it applies the scroll offset only for elements inside in fixed position.
93     void pushView(const RenderView*, const LayoutSize& scrollOffset, const TransformationMatrix* = 0);
94
95 private:
96     void mapToAbsolute(TransformState&) const;
97
98     void stepInserted(const RenderGeometryMapStep&);
99     void stepRemoved(const RenderGeometryMapStep&);
100     
101     bool hasNonUniformStep() const { return m_nonUniformStepsCount; }
102     bool hasTransformStep() const { return m_transformedStepsCount; }
103     bool hasFixedPositionStep() const { return m_fixedStepsCount; }
104
105     typedef Vector<RenderGeometryMapStep, 32> RenderGeometryMapSteps;
106
107     size_t m_insertionPosition;
108     int m_nonUniformStepsCount;
109     int m_transformedStepsCount;
110     int m_fixedStepsCount;
111     RenderGeometryMapSteps m_mapping;
112     LayoutSize m_accumulatedOffset;
113 };
114
115 } // namespace WebCore
116
117 namespace WTF {
118 // This is required for a struct with OwnPtr. We know RenderGeometryMapStep is simple enough that
119 // initializing to 0 and moving with memcpy (and then not destructing the original) will work.
120 template<> struct VectorTraits<WebCore::RenderGeometryMapStep> : SimpleClassVectorTraits { };
121 }
122
123 #endif // RenderGeometryMap_h