1/*
2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Antti Koivisto (koivisto@kde.org)
4 * (C) 2000 Dirk Mueller (mueller@kde.org)
5 * Copyright (C) 2003, 2005-2008, 2017 Apple Inc. All rights reserved.
6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com)
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25#pragma once
26
27#include "FloatSize.h"
28#include "TransformationMatrix.h"
29#include <wtf/Forward.h>
30#include <wtf/RefCounted.h>
31#include <wtf/TypeCasts.h>
32
33namespace WebCore {
34
35// CSS Transforms (may become part of CSS3)
36
37class TransformOperation : public RefCounted<TransformOperation> {
38public:
39 enum OperationType {
40 SCALE_X, SCALE_Y, SCALE,
41 TRANSLATE_X, TRANSLATE_Y, TRANSLATE,
42 ROTATE,
43 ROTATE_Z = ROTATE,
44 SKEW_X, SKEW_Y, SKEW,
45 MATRIX,
46 SCALE_Z, SCALE_3D,
47 TRANSLATE_Z, TRANSLATE_3D,
48 ROTATE_X, ROTATE_Y, ROTATE_3D,
49 MATRIX_3D,
50 PERSPECTIVE,
51 IDENTITY, NONE
52 };
53
54 TransformOperation(OperationType type)
55 : m_type(type)
56 {
57 }
58 virtual ~TransformOperation() = default;
59
60 virtual Ref<TransformOperation> clone() const = 0;
61
62 virtual bool operator==(const TransformOperation&) const = 0;
63 bool operator!=(const TransformOperation& o) const { return !(*this == o); }
64
65 virtual bool isIdentity() const = 0;
66
67 // Return true if the borderBoxSize was used in the computation, false otherwise.
68 virtual bool apply(TransformationMatrix&, const FloatSize& borderBoxSize) const = 0;
69
70 virtual Ref<TransformOperation> blend(const TransformOperation* from, double progress, bool blendToIdentity = false) = 0;
71
72 OperationType type() const { return m_type; }
73 bool isSameType(const TransformOperation& other) const { return type() == other.type(); }
74
75 virtual bool isAffectedByTransformOrigin() const { return false; }
76
77 bool is3DOperation() const
78 {
79 OperationType opType = type();
80 return opType == SCALE_Z ||
81 opType == SCALE_3D ||
82 opType == TRANSLATE_Z ||
83 opType == TRANSLATE_3D ||
84 opType == ROTATE_X ||
85 opType == ROTATE_Y ||
86 opType == ROTATE_3D ||
87 opType == MATRIX_3D ||
88 opType == PERSPECTIVE;
89 }
90
91 virtual bool isRepresentableIn2D() const { return true; }
92
93 bool isRotateTransformOperationType() const
94 {
95 return type() == ROTATE_X || type() == ROTATE_Y || type() == ROTATE_Z || type() == ROTATE || type() == ROTATE_3D;
96 }
97
98 bool isScaleTransformOperationType() const
99 {
100 return type() == SCALE_X || type() == SCALE_Y || type() == SCALE_Z || type() == SCALE || type() == SCALE_3D;
101 }
102
103 bool isSkewTransformOperationType() const
104 {
105 return type() == SKEW_X || type() == SKEW_Y || type() == SKEW;
106 }
107
108 bool isTranslateTransformOperationType() const
109 {
110 return type() == TRANSLATE_X || type() == TRANSLATE_Y || type() == TRANSLATE_Z || type() == TRANSLATE || type() == TRANSLATE_3D;
111 }
112
113 virtual void dump(WTF::TextStream&) const = 0;
114
115private:
116 OperationType m_type;
117};
118
119WTF::TextStream& operator<<(WTF::TextStream&, TransformOperation::OperationType);
120WTF::TextStream& operator<<(WTF::TextStream&, const TransformOperation&);
121
122} // namespace WebCore
123
124#define SPECIALIZE_TYPE_TRAITS_TRANSFORMOPERATION(ToValueTypeName, predicate) \
125SPECIALIZE_TYPE_TRAITS_BEGIN(ToValueTypeName) \
126 static bool isType(const WebCore::TransformOperation& operation) { return operation.predicate; } \
127SPECIALIZE_TYPE_TRAITS_END()
128