Move parseFontFaceDescriptor to CSSPropertyParser.cpp
[chromium-blink-merge.git] / third_party / WebKit / Source / platform / geometry / TransformState.h
blob2bb16b6a88a59bd77ac31d6f7070d502b3277c18
1 /*
2 * Copyright (C) 2011 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
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.
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 TransformState_h
27 #define TransformState_h
29 #include "platform/geometry/FloatPoint.h"
30 #include "platform/geometry/FloatQuad.h"
31 #include "platform/geometry/IntSize.h"
32 #include "platform/geometry/LayoutSize.h"
33 #include "platform/transforms/AffineTransform.h"
34 #include "platform/transforms/TransformationMatrix.h"
35 #include "wtf/OwnPtr.h"
37 namespace blink {
39 class PLATFORM_EXPORT TransformState {
40 public:
41 enum TransformDirection { ApplyTransformDirection, UnapplyInverseTransformDirection };
42 enum TransformAccumulation { FlattenTransform, AccumulateTransform };
44 TransformState(TransformDirection mappingDirection, const FloatPoint& p, const FloatQuad& quad)
45 : m_lastPlanarPoint(p)
46 , m_lastPlanarQuad(quad)
47 , m_accumulatingTransform(false)
48 , m_mapPoint(true)
49 , m_mapQuad(true)
50 , m_direction(mappingDirection)
54 TransformState(TransformDirection mappingDirection, const FloatPoint& p)
55 : m_lastPlanarPoint(p)
56 , m_accumulatingTransform(false)
57 , m_mapPoint(true)
58 , m_mapQuad(false)
59 , m_direction(mappingDirection)
63 TransformState(TransformDirection mappingDirection, const FloatQuad& quad)
64 : m_lastPlanarQuad(quad)
65 , m_accumulatingTransform(false)
66 , m_mapPoint(false)
67 , m_mapQuad(true)
68 , m_direction(mappingDirection)
72 TransformState(const TransformState& other) { *this = other; }
74 TransformState& operator=(const TransformState&);
76 void setQuad(const FloatQuad& quad)
78 // FIXME: this assumes that the quad being added is in the coordinate system of the current state.
79 // This breaks if we're simultaneously mapping a point. https://bugs.webkit.org/show_bug.cgi?id=106680
80 ASSERT(!m_mapPoint);
81 m_accumulatedOffset = LayoutSize();
82 m_lastPlanarQuad = quad;
85 void move(LayoutUnit x, LayoutUnit y, TransformAccumulation accumulate = FlattenTransform)
87 move(LayoutSize(x, y), accumulate);
90 void move(const LayoutSize&, TransformAccumulation = FlattenTransform);
91 void move(const IntSize& size, TransformAccumulation accumulate = FlattenTransform)
93 move(LayoutSize(size), accumulate);
95 void applyTransform(const AffineTransform& transformFromContainer, TransformAccumulation = FlattenTransform, bool* wasClamped = 0);
96 void applyTransform(const TransformationMatrix& transformFromContainer, TransformAccumulation = FlattenTransform, bool* wasClamped = 0);
97 void flatten(bool* wasClamped = 0);
99 // Return the coords of the point or quad in the last flattened layer
100 FloatPoint lastPlanarPoint() const { return m_lastPlanarPoint; }
101 FloatQuad lastPlanarQuad() const { return m_lastPlanarQuad; }
103 // Return the point or quad mapped through the current transform
104 FloatPoint mappedPoint(bool* wasClamped = 0) const;
105 FloatQuad mappedQuad(bool* wasClamped = 0) const;
107 private:
108 void translateTransform(const LayoutSize&);
109 void translateMappedCoordinates(const LayoutSize&);
110 void flattenWithTransform(const TransformationMatrix&, bool* wasClamped);
111 void applyAccumulatedOffset();
113 FloatPoint m_lastPlanarPoint;
114 FloatQuad m_lastPlanarQuad;
116 // We only allocate the transform if we need to
117 OwnPtr<TransformationMatrix> m_accumulatedTransform;
118 LayoutSize m_accumulatedOffset;
119 bool m_accumulatingTransform;
120 bool m_mapPoint, m_mapQuad;
121 TransformDirection m_direction;
124 } // namespace blink
126 #endif // TransformState_h