Replace WTF::move with WTFMove
[WebKit-https.git] / Source / WebCore / css / CSSProperty.cpp
1 /**
2  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3  * Copyright (C) 2004, 2005, 2006 Apple Inc.
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public License
16  * along with this library; see the file COPYING.LIB.  If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20
21 #include "config.h"
22 #include "CSSProperty.h"
23
24 #include "CSSValueList.h"
25 #include "RenderStyleConstants.h"
26 #include "StylePropertyShorthand.h"
27
28 #include <wtf/NeverDestroyed.h>
29 #include <wtf/text/StringBuilder.h>
30
31 namespace WebCore {
32
33 struct SameSizeAsCSSProperty {
34     uint32_t bitfields;
35     void* value;
36 };
37
38 COMPILE_ASSERT(sizeof(CSSProperty) == sizeof(SameSizeAsCSSProperty), CSSProperty_should_stay_small);
39
40 CSSPropertyID StylePropertyMetadata::shorthandID() const
41 {
42     if (!m_isSetFromShorthand)
43         return CSSPropertyInvalid;
44
45     Vector<StylePropertyShorthand> shorthands = matchingShorthandsForLonghand(static_cast<CSSPropertyID>(m_propertyID));
46     ASSERT(shorthands.size() && m_indexInShorthandsVector >= 0 && m_indexInShorthandsVector < shorthands.size());
47     return shorthands[m_indexInShorthandsVector].id();
48 }
49
50 void CSSProperty::wrapValueInCommaSeparatedList()
51 {
52     auto list = CSSValueList::createCommaSeparated();
53     list.get().append(m_value.releaseNonNull());
54     m_value = WTFMove(list);
55 }
56
57 static CSSPropertyID resolveToPhysicalProperty(TextDirection direction, WritingMode writingMode, LogicalBoxSide logicalSide, const StylePropertyShorthand& shorthand)
58 {
59     return shorthand.properties()[mapLogicalSideToPhysicalSide(makeTextFlow(writingMode, direction), logicalSide)];
60 }
61
62 enum LogicalExtent { LogicalWidth, LogicalHeight };
63
64 static CSSPropertyID resolveToPhysicalProperty(WritingMode writingMode, LogicalExtent logicalSide, const CSSPropertyID* properties)
65 {
66     if (writingMode == TopToBottomWritingMode || writingMode == BottomToTopWritingMode)
67         return properties[logicalSide];
68     return logicalSide == LogicalWidth ? properties[1] : properties[0];
69 }
70
71 static const StylePropertyShorthand& borderDirections()
72 {
73     static const CSSPropertyID properties[4] = { CSSPropertyBorderTop, CSSPropertyBorderRight, CSSPropertyBorderBottom, CSSPropertyBorderLeft };
74     static NeverDestroyed<StylePropertyShorthand> borderDirections(CSSPropertyBorder, properties);
75     return borderDirections;
76 }
77
78 CSSPropertyID CSSProperty::resolveDirectionAwareProperty(CSSPropertyID propertyID, TextDirection direction, WritingMode writingMode)
79 {
80     switch (propertyID) {
81     case CSSPropertyWebkitMarginEnd:
82         return resolveToPhysicalProperty(direction, writingMode, EndSide, marginShorthand());
83     case CSSPropertyWebkitMarginStart:
84         return resolveToPhysicalProperty(direction, writingMode, StartSide, marginShorthand());
85     case CSSPropertyWebkitMarginBefore:
86         return resolveToPhysicalProperty(direction, writingMode, BeforeSide, marginShorthand());
87     case CSSPropertyWebkitMarginAfter:
88         return resolveToPhysicalProperty(direction, writingMode, AfterSide, marginShorthand());
89     case CSSPropertyWebkitPaddingEnd:
90         return resolveToPhysicalProperty(direction, writingMode, EndSide, paddingShorthand());
91     case CSSPropertyWebkitPaddingStart:
92         return resolveToPhysicalProperty(direction, writingMode, StartSide, paddingShorthand());
93     case CSSPropertyWebkitPaddingBefore:
94         return resolveToPhysicalProperty(direction, writingMode, BeforeSide, paddingShorthand());
95     case CSSPropertyWebkitPaddingAfter:
96         return resolveToPhysicalProperty(direction, writingMode, AfterSide, paddingShorthand());
97     case CSSPropertyWebkitBorderEnd:
98         return resolveToPhysicalProperty(direction, writingMode, EndSide, borderDirections());
99     case CSSPropertyWebkitBorderStart:
100         return resolveToPhysicalProperty(direction, writingMode, StartSide, borderDirections());
101     case CSSPropertyWebkitBorderBefore:
102         return resolveToPhysicalProperty(direction, writingMode, BeforeSide, borderDirections());
103     case CSSPropertyWebkitBorderAfter:
104         return resolveToPhysicalProperty(direction, writingMode, AfterSide, borderDirections());
105     case CSSPropertyWebkitBorderEndColor:
106         return resolveToPhysicalProperty(direction, writingMode, EndSide, borderColorShorthand());
107     case CSSPropertyWebkitBorderStartColor:
108         return resolveToPhysicalProperty(direction, writingMode, StartSide, borderColorShorthand());
109     case CSSPropertyWebkitBorderBeforeColor:
110         return resolveToPhysicalProperty(direction, writingMode, BeforeSide, borderColorShorthand());
111     case CSSPropertyWebkitBorderAfterColor:
112         return resolveToPhysicalProperty(direction, writingMode, AfterSide, borderColorShorthand());
113     case CSSPropertyWebkitBorderEndStyle:
114         return resolveToPhysicalProperty(direction, writingMode, EndSide, borderStyleShorthand());
115     case CSSPropertyWebkitBorderStartStyle:
116         return resolveToPhysicalProperty(direction, writingMode, StartSide, borderStyleShorthand());
117     case CSSPropertyWebkitBorderBeforeStyle:
118         return resolveToPhysicalProperty(direction, writingMode, BeforeSide, borderStyleShorthand());
119     case CSSPropertyWebkitBorderAfterStyle:
120         return resolveToPhysicalProperty(direction, writingMode, AfterSide, borderStyleShorthand());
121     case CSSPropertyWebkitBorderEndWidth:
122         return resolveToPhysicalProperty(direction, writingMode, EndSide, borderWidthShorthand());
123     case CSSPropertyWebkitBorderStartWidth:
124         return resolveToPhysicalProperty(direction, writingMode, StartSide, borderWidthShorthand());
125     case CSSPropertyWebkitBorderBeforeWidth:
126         return resolveToPhysicalProperty(direction, writingMode, BeforeSide, borderWidthShorthand());
127     case CSSPropertyWebkitBorderAfterWidth:
128         return resolveToPhysicalProperty(direction, writingMode, AfterSide, borderWidthShorthand());
129     case CSSPropertyWebkitLogicalWidth: {
130         const CSSPropertyID properties[2] = { CSSPropertyWidth, CSSPropertyHeight };
131         return resolveToPhysicalProperty(writingMode, LogicalWidth, properties);
132     }
133     case CSSPropertyWebkitLogicalHeight: {
134         const CSSPropertyID properties[2] = { CSSPropertyWidth, CSSPropertyHeight };
135         return resolveToPhysicalProperty(writingMode, LogicalHeight, properties);
136     }
137     case CSSPropertyWebkitMinLogicalWidth: {
138         const CSSPropertyID properties[2] = { CSSPropertyMinWidth, CSSPropertyMinHeight };
139         return resolveToPhysicalProperty(writingMode, LogicalWidth, properties);
140     }
141     case CSSPropertyWebkitMinLogicalHeight: {
142         const CSSPropertyID properties[2] = { CSSPropertyMinWidth, CSSPropertyMinHeight };
143         return resolveToPhysicalProperty(writingMode, LogicalHeight, properties);
144     }
145     case CSSPropertyWebkitMaxLogicalWidth: {
146         const CSSPropertyID properties[2] = { CSSPropertyMaxWidth, CSSPropertyMaxHeight };
147         return resolveToPhysicalProperty(writingMode, LogicalWidth, properties);
148     }
149     case CSSPropertyWebkitMaxLogicalHeight: {
150         const CSSPropertyID properties[2] = { CSSPropertyMaxWidth, CSSPropertyMaxHeight };
151         return resolveToPhysicalProperty(writingMode, LogicalHeight, properties);
152     }
153     default:
154         return propertyID;
155     }
156 }
157
158 bool CSSProperty::isDirectionAwareProperty(CSSPropertyID propertyID)
159 {
160     switch (propertyID) {
161     case CSSPropertyWebkitBorderEndColor:
162     case CSSPropertyWebkitBorderEndStyle:
163     case CSSPropertyWebkitBorderEndWidth:
164     case CSSPropertyWebkitBorderStartColor:
165     case CSSPropertyWebkitBorderStartStyle:
166     case CSSPropertyWebkitBorderStartWidth:
167     case CSSPropertyWebkitBorderBeforeColor:
168     case CSSPropertyWebkitBorderBeforeStyle:
169     case CSSPropertyWebkitBorderBeforeWidth:
170     case CSSPropertyWebkitBorderAfterColor:
171     case CSSPropertyWebkitBorderAfterStyle:
172     case CSSPropertyWebkitBorderAfterWidth:
173     case CSSPropertyWebkitMarginEnd:
174     case CSSPropertyWebkitMarginStart:
175     case CSSPropertyWebkitMarginBefore:
176     case CSSPropertyWebkitMarginAfter:
177     case CSSPropertyWebkitPaddingEnd:
178     case CSSPropertyWebkitPaddingStart:
179     case CSSPropertyWebkitPaddingBefore:
180     case CSSPropertyWebkitPaddingAfter:
181     case CSSPropertyWebkitLogicalWidth:
182     case CSSPropertyWebkitLogicalHeight:
183     case CSSPropertyWebkitMinLogicalWidth:
184     case CSSPropertyWebkitMinLogicalHeight:
185     case CSSPropertyWebkitMaxLogicalWidth:
186     case CSSPropertyWebkitMaxLogicalHeight:
187         return true;
188     default:
189         return false;
190     }
191 }
192
193 } // namespace WebCore