2
* Copyright (C) 2019 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
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 INC. AND ITS CONTRIBUTORS ``AS IS''
14
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
* THE POSSIBILITY OF SUCH DAMAGE.
28
#include "CascadeLevel.h"
29
#include "ElementRuleCollector.h"
30
#include "StyleBuilderState.h"
39
class PropertyCascade {
40
WTF_MAKE_FAST_ALLOCATED;
42
enum IncludedProperties { All, InheritedOnly };
45
TextDirection textDirection;
46
WritingMode writingMode;
49
PropertyCascade(const MatchResult&, OptionSet<CascadeLevel>, IncludedProperties, Direction);
50
PropertyCascade(const PropertyCascade&, OptionSet<CascadeLevel>);
57
ScopeOrdinal styleScopeOrdinal;
58
CSSValue* cssValue[3]; // Values for link match states MatchDefault, MatchLink and MatchVisited
61
bool hasProperty(CSSPropertyID) const;
62
const Property& property(CSSPropertyID) const;
64
bool hasCustomProperty(const String&) const;
65
Property customProperty(const String&) const;
67
const Vector<Property, 8>& deferredProperties() const { return m_deferredProperties; }
68
const HashMap<AtomString, Property>& customProperties() const { return m_customProperties; }
70
Direction direction() const { return m_direction; }
72
const PropertyCascade* propertyCascadeForRollback(CascadeLevel) const;
75
void buildCascade(OptionSet<CascadeLevel>);
76
bool addNormalMatches(CascadeLevel);
77
void addImportantMatches(CascadeLevel);
78
bool addMatch(const MatchedProperties&, CascadeLevel, bool important);
80
void set(CSSPropertyID, CSSValue&, unsigned linkMatchType, CascadeLevel, ScopeOrdinal);
81
void setDeferred(CSSPropertyID, CSSValue&, unsigned linkMatchType, CascadeLevel, ScopeOrdinal);
82
static void setPropertyInternal(Property&, CSSPropertyID, CSSValue&, unsigned linkMatchType, CascadeLevel, ScopeOrdinal);
84
Direction resolveDirectionAndWritingMode(Direction inheritedDirection) const;
86
const MatchResult& m_matchResult;
87
const IncludedProperties m_includedProperties;
88
const Direction m_direction;
90
Property m_properties[numCSSProperties + 2];
91
std::bitset<numCSSProperties + 2> m_propertyIsPresent;
93
Vector<Property, 8> m_deferredProperties;
94
HashMap<AtomString, Property> m_customProperties;
96
mutable std::unique_ptr<const PropertyCascade> m_authorRollbackCascade;
97
mutable std::unique_ptr<const PropertyCascade> m_userRollbackCascade;
100
inline bool PropertyCascade::hasProperty(CSSPropertyID id) const
102
ASSERT(id < m_propertyIsPresent.size());
103
return m_propertyIsPresent[id];
106
inline const PropertyCascade::Property& PropertyCascade::property(CSSPropertyID id) const
108
return m_properties[id];
111
inline bool PropertyCascade::hasCustomProperty(const String& name) const
113
return m_customProperties.contains(name);
116
inline PropertyCascade::Property PropertyCascade::customProperty(const String& name) const
118
return m_customProperties.get(name);