]>
Commit | Line | Data |
---|---|---|
a90939db JF |
1 | /* |
2 | * Copyright (C) 2009 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 TransformState_h | |
27 | #define TransformState_h | |
28 | ||
29 | #include "FloatPoint.h" | |
30 | #include "FloatQuad.h" | |
31 | #include "IntSize.h" | |
32 | #include "TransformationMatrix.h" | |
33 | #include <wtf/Noncopyable.h> | |
34 | #include <wtf/PassRefPtr.h> | |
35 | #include <wtf/OwnPtr.h> | |
36 | #include <wtf/RefCounted.h> | |
37 | ||
38 | namespace WebCore { | |
39 | ||
40 | class TransformState : Noncopyable { | |
41 | public: | |
42 | enum TransformDirection { ApplyTransformDirection, UnapplyInverseTransformDirection }; | |
43 | enum TransformAccumulation { FlattenTransform, AccumulateTransform }; | |
44 | ||
45 | // If quad is non-null, it will be mapped | |
46 | TransformState(TransformDirection mappingDirection, const FloatPoint& p, const FloatQuad* quad = 0) | |
47 | : m_lastPlanarPoint(p) | |
48 | , m_accumulatingTransform(false) | |
49 | , m_mapQuad(quad != 0) | |
50 | , m_direction(mappingDirection) | |
51 | { | |
52 | if (quad) | |
53 | m_lastPlanarQuad = *quad; | |
54 | } | |
55 | ||
56 | void move(const IntSize& s, TransformAccumulation accumulate = FlattenTransform) | |
57 | { | |
58 | move(s.width(), s.height(), accumulate); | |
59 | } | |
60 | ||
61 | void move(int x, int y, TransformAccumulation = FlattenTransform); | |
62 | void applyTransform(const TransformationMatrix& transformFromContainer, TransformAccumulation = FlattenTransform); | |
63 | void flatten(); | |
64 | ||
65 | // Return the coords of the point or quad in the last flattened layer | |
66 | FloatPoint lastPlanarPoint() const { return m_lastPlanarPoint; } | |
67 | FloatQuad lastPlanarQuad() const { return m_lastPlanarQuad; } | |
68 | ||
69 | // Return the point or quad mapped through the current transform | |
70 | FloatPoint mappedPoint() const; | |
71 | FloatQuad mappedQuad() const; | |
72 | ||
73 | private: | |
74 | void flattenWithTransform(const TransformationMatrix&); | |
75 | ||
76 | FloatPoint m_lastPlanarPoint; | |
77 | FloatQuad m_lastPlanarQuad; | |
78 | ||
79 | // We only allocate the transform if we need to | |
80 | OwnPtr<TransformationMatrix> m_accumulatedTransform; | |
81 | bool m_accumulatingTransform; | |
82 | bool m_mapQuad; | |
83 | TransformDirection m_direction; | |
84 | }; | |
85 | ||
86 | class HitTestingTransformState : public RefCounted<HitTestingTransformState> { | |
87 | public: | |
88 | static PassRefPtr<HitTestingTransformState> create(const FloatPoint& p, const FloatQuad& quad) | |
89 | { | |
90 | return adoptRef(new HitTestingTransformState(p, quad)); | |
91 | } | |
92 | ||
93 | static PassRefPtr<HitTestingTransformState> create(const HitTestingTransformState& other) | |
94 | { | |
95 | return adoptRef(new HitTestingTransformState(other)); | |
96 | } | |
97 | ||
98 | enum TransformAccumulation { FlattenTransform, AccumulateTransform }; | |
99 | void translate(int x, int y, TransformAccumulation); | |
100 | void applyTransform(const TransformationMatrix& transformFromContainer, TransformAccumulation); | |
101 | ||
102 | FloatPoint mappedPoint() const; | |
103 | FloatQuad mappedQuad() const; | |
104 | void flatten(); | |
105 | ||
106 | FloatPoint m_lastPlanarPoint; | |
107 | FloatQuad m_lastPlanarQuad; | |
108 | TransformationMatrix m_accumulatedTransform; | |
109 | bool m_accumulatingTransform; | |
110 | ||
111 | private: | |
112 | HitTestingTransformState(const FloatPoint& p, const FloatQuad& quad) | |
113 | : m_lastPlanarPoint(p) | |
114 | , m_lastPlanarQuad(quad) | |
115 | , m_accumulatingTransform(false) | |
116 | { | |
117 | } | |
118 | ||
119 | HitTestingTransformState(const HitTestingTransformState& other) | |
120 | : RefCounted<HitTestingTransformState>() | |
121 | , m_lastPlanarPoint(other.m_lastPlanarPoint) | |
122 | , m_lastPlanarQuad(other.m_lastPlanarQuad) | |
123 | , m_accumulatedTransform(other.m_accumulatedTransform) | |
124 | , m_accumulatingTransform(other.m_accumulatingTransform) | |
125 | { | |
126 | } | |
127 | ||
128 | void flattenWithTransform(const TransformationMatrix&); | |
129 | }; | |
130 | ||
131 | } // namespace WebCore | |
132 | ||
133 | #endif // TransformState_h |