1 | /*
|
---|
2 | * (C) 1999-2003 Lars Knoll ([email protected])
|
---|
3 | * Copyright (C) 2004, 2005, 2006 Apple Inc.
|
---|
4 | * Copyright (C) 2013 Intel Corporation. All rights reserved.
|
---|
5 | *
|
---|
6 | * This library is free software; you can redistribute it and/or
|
---|
7 | * modify it under the terms of the GNU Library General Public
|
---|
8 | * License as published by the Free Software Foundation; either
|
---|
9 | * version 2 of the License, or (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This library is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | * Library General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU Library General Public License
|
---|
17 | * along with this library; see the file COPYING.LIB. If not, write to
|
---|
18 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
---|
19 | * Boston, MA 02110-1301, USA.
|
---|
20 | */
|
---|
21 |
|
---|
22 | #pragma once
|
---|
23 |
|
---|
24 | #include "CSSPropertyNames.h"
|
---|
25 | #include "CSSValue.h"
|
---|
26 | #include "WritingMode.h"
|
---|
27 | #include <wtf/RefPtr.h>
|
---|
28 |
|
---|
29 | namespace WebCore {
|
---|
30 |
|
---|
31 | struct StylePropertyMetadata {
|
---|
32 | StylePropertyMetadata(CSSPropertyID propertyID, bool isSetFromShorthand, int indexInShorthandsVector, bool important, bool implicit, bool inherited)
|
---|
33 | : m_propertyID(propertyID)
|
---|
34 | , m_isSetFromShorthand(isSetFromShorthand)
|
---|
35 | , m_indexInShorthandsVector(indexInShorthandsVector)
|
---|
36 | , m_important(important)
|
---|
37 | , m_implicit(implicit)
|
---|
38 | , m_inherited(inherited)
|
---|
39 | {
|
---|
40 | }
|
---|
41 |
|
---|
42 | CSSPropertyID shorthandID() const;
|
---|
43 |
|
---|
44 | bool operator==(const StylePropertyMetadata& other) const
|
---|
45 | {
|
---|
46 | return m_propertyID == other.m_propertyID
|
---|
47 | && m_isSetFromShorthand == other.m_isSetFromShorthand
|
---|
48 | && m_indexInShorthandsVector == other.m_indexInShorthandsVector
|
---|
49 | && m_important == other.m_important
|
---|
50 | && m_implicit == other.m_implicit
|
---|
51 | && m_inherited == other.m_inherited;
|
---|
52 | }
|
---|
53 |
|
---|
54 | uint16_t m_propertyID : 10;
|
---|
55 | uint16_t m_isSetFromShorthand : 1;
|
---|
56 | uint16_t m_indexInShorthandsVector : 2; // If this property was set as part of an ambiguous shorthand, gives the index in the shorthands vector.
|
---|
57 | uint16_t m_important : 1;
|
---|
58 | uint16_t m_implicit : 1; // Whether or not the property was set implicitly as the result of a shorthand.
|
---|
59 | uint16_t m_inherited : 1;
|
---|
60 | };
|
---|
61 |
|
---|
62 | class CSSProperty {
|
---|
63 | public:
|
---|
64 | CSSProperty(CSSPropertyID propertyID, RefPtr<CSSValue>&& value, bool important = false, bool isSetFromShorthand = false, int indexInShorthandsVector = 0, bool implicit = false)
|
---|
65 | : m_metadata(propertyID, isSetFromShorthand, indexInShorthandsVector, important, implicit, isInheritedProperty(propertyID))
|
---|
66 | , m_value(WTFMove(value))
|
---|
67 | {
|
---|
68 | }
|
---|
69 |
|
---|
70 | CSSPropertyID id() const { return static_cast<CSSPropertyID>(m_metadata.m_propertyID); }
|
---|
71 | bool isSetFromShorthand() const { return m_metadata.m_isSetFromShorthand; };
|
---|
72 | CSSPropertyID shorthandID() const { return m_metadata.shorthandID(); };
|
---|
73 | bool isImportant() const { return m_metadata.m_important; }
|
---|
74 |
|
---|
75 | CSSValue* value() const { return m_value.get(); }
|
---|
76 |
|
---|
77 | void wrapValueInCommaSeparatedList();
|
---|
78 |
|
---|
79 | static CSSPropertyID resolveDirectionAwareProperty(CSSPropertyID, TextDirection, WritingMode);
|
---|
80 | static CSSPropertyID unresolvePhysicalProperty(CSSPropertyID, TextDirection, WritingMode);
|
---|
81 | static bool isInheritedProperty(CSSPropertyID);
|
---|
82 | static Vector<String> aliasesForProperty(CSSPropertyID);
|
---|
83 | static bool isDirectionAwareProperty(CSSPropertyID);
|
---|
84 | static bool isInLogicalPropertyGroup(CSSPropertyID);
|
---|
85 | static bool areInSameLogicalPropertyGroupWithDifferentMappingLogic(CSSPropertyID, CSSPropertyID);
|
---|
86 | static bool isDescriptorOnly(CSSPropertyID);
|
---|
87 | static bool isColorProperty(CSSPropertyID);
|
---|
88 |
|
---|
89 | const StylePropertyMetadata& metadata() const { return m_metadata; }
|
---|
90 |
|
---|
91 | bool operator==(const CSSProperty& other) const
|
---|
92 | {
|
---|
93 | if (!(m_metadata == other.m_metadata))
|
---|
94 | return false;
|
---|
95 |
|
---|
96 | if (!m_value && !other.m_value)
|
---|
97 | return true;
|
---|
98 |
|
---|
99 | if (!m_value || !other.m_value)
|
---|
100 | return false;
|
---|
101 |
|
---|
102 | return m_value->equals(*other.m_value);
|
---|
103 | }
|
---|
104 |
|
---|
105 | private:
|
---|
106 | StylePropertyMetadata m_metadata;
|
---|
107 | RefPtr<CSSValue> m_value;
|
---|
108 | };
|
---|
109 |
|
---|
110 | typedef Vector<CSSProperty, 256> ParsedPropertyVector;
|
---|
111 |
|
---|
112 | } // namespace WebCore
|
---|
113 |
|
---|
114 | namespace WTF {
|
---|
115 | template <> struct VectorTraits<WebCore::CSSProperty> : VectorTraitsBase<false, WebCore::CSSProperty> {
|
---|
116 | static const bool canInitializeWithMemset = true;
|
---|
117 | static const bool canMoveWithMemcpy = true;
|
---|
118 | };
|
---|
119 | }
|
---|