blob: f8dcdb7e4b3219e3602d5bb6e4062ca106c9858b [file] [log] [blame]
antti@apple.com8be9b562012-02-28 17:44:18 +00001/*
2 * (C) 1999-2003 Lars Knoll (knoll@kde.org)
3 * (C) 2002-2003 Dirk Mueller (mueller@kde.org)
bfulgham@apple.comf760c502022-05-10 16:48:31 +00004 * Copyright (C) 2002-2022 Apple Inc. All rights reserved.
antti@apple.com8be9b562012-02-28 17:44:18 +00005 *
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#include "config.h"
23#include "StyleRule.h"
24
antti@apple.comc34471a2022-03-29 18:19:56 +000025#include "CSSContainerRule.h"
commit-queue@webkit.orgfef30932021-04-16 19:19:04 +000026#include "CSSCounterStyleRule.h"
antti@apple.comd09a7922012-04-02 19:50:34 +000027#include "CSSFontFaceRule.h"
mmaxfield@apple.com0e1f0c42021-09-21 08:24:36 +000028#include "CSSFontPaletteValuesRule.h"
antti@apple.comd09a7922012-04-02 19:50:34 +000029#include "CSSImportRule.h"
dino@apple.comd2a5e4c2014-11-15 23:02:43 +000030#include "CSSKeyframeRule.h"
31#include "CSSKeyframesRule.h"
antti@apple.com850cde42021-12-08 16:55:05 +000032#include "CSSLayerBlockRule.h"
33#include "CSSLayerStatementRule.h"
antti@apple.comd09a7922012-04-02 19:50:34 +000034#include "CSSMediaRule.h"
hyatt@apple.com1f589652016-12-10 18:31:13 +000035#include "CSSNamespaceRule.h"
antti@apple.comd09a7922012-04-02 19:50:34 +000036#include "CSSPageRule.h"
37#include "CSSStyleRule.h"
commit-queue@webkit.org03dd24f2013-01-16 11:30:50 +000038#include "CSSSupportsRule.h"
achristensen@apple.com26aaf302016-05-24 05:34:49 +000039#include "MediaList.h"
antti@apple.come5428c52013-11-28 20:53:22 +000040#include "StyleProperties.h"
antti@apple.com16396422012-05-24 15:07:29 +000041#include "StyleRuleImport.h"
antti@apple.comd09a7922012-04-02 19:50:34 +000042
antti@apple.com8be9b562012-02-28 17:44:18 +000043namespace WebCore {
44
commit-queue@webkit.org8177b032012-06-21 17:53:54 +000045struct SameSizeAsStyleRuleBase : public WTF::RefCountedBase {
hyatt@apple.comda947f72016-12-03 21:22:49 +000046 unsigned bitfields : 5;
commit-queue@webkit.org8177b032012-06-21 17:53:54 +000047};
48
ysuzuki@apple.com82d570e2022-03-26 22:19:31 +000049static_assert(sizeof(StyleRuleBase) == sizeof(SameSizeAsStyleRuleBase), "StyleRuleBase should stay small");
commit-queue@webkit.org8177b032012-06-21 17:53:54 +000050
ysuzuki@apple.com4642e112020-01-03 02:36:43 +000051DEFINE_ALLOCATOR_WITH_HEAP_IDENTIFIER(StyleRuleBase);
52DEFINE_ALLOCATOR_WITH_HEAP_IDENTIFIER(StyleRule);
53
yusukesuzuki@slowstart.orgae5a8bd2018-12-22 06:37:39 +000054Ref<CSSRule> StyleRuleBase::createCSSOMWrapper(CSSStyleSheet* parentSheet) const
antti@apple.comd09a7922012-04-02 19:50:34 +000055{
achristensen@apple.com26aaf302016-05-24 05:34:49 +000056 return createCSSOMWrapper(parentSheet, nullptr);
antti@apple.comd09a7922012-04-02 19:50:34 +000057}
58
yusukesuzuki@slowstart.orgae5a8bd2018-12-22 06:37:39 +000059Ref<CSSRule> StyleRuleBase::createCSSOMWrapper(CSSRule* parentRule) const
antti@apple.comd09a7922012-04-02 19:50:34 +000060{
achristensen@apple.com26aaf302016-05-24 05:34:49 +000061 return createCSSOMWrapper(nullptr, parentRule);
antti@apple.comd09a7922012-04-02 19:50:34 +000062}
63
64void StyleRuleBase::destroy()
65{
66 switch (type()) {
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +000067 case StyleRuleType::Style:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +000068 delete downcast<StyleRule>(this);
antti@apple.comd09a7922012-04-02 19:50:34 +000069 return;
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +000070 case StyleRuleType::Page:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +000071 delete downcast<StyleRulePage>(this);
antti@apple.comd09a7922012-04-02 19:50:34 +000072 return;
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +000073 case StyleRuleType::FontFace:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +000074 delete downcast<StyleRuleFontFace>(this);
antti@apple.comd09a7922012-04-02 19:50:34 +000075 return;
mmaxfield@apple.com0e1f0c42021-09-21 08:24:36 +000076 case StyleRuleType::FontPaletteValues:
77 delete downcast<StyleRuleFontPaletteValues>(this);
78 return;
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +000079 case StyleRuleType::Media:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +000080 delete downcast<StyleRuleMedia>(this);
antti@apple.comd09a7922012-04-02 19:50:34 +000081 return;
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +000082 case StyleRuleType::Supports:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +000083 delete downcast<StyleRuleSupports>(this);
commit-queue@webkit.org03dd24f2013-01-16 11:30:50 +000084 return;
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +000085 case StyleRuleType::Import:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +000086 delete downcast<StyleRuleImport>(this);
antti@apple.comd09a7922012-04-02 19:50:34 +000087 return;
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +000088 case StyleRuleType::Keyframes:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +000089 delete downcast<StyleRuleKeyframes>(this);
antti@apple.comd09a7922012-04-02 19:50:34 +000090 return;
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +000091 case StyleRuleType::Namespace:
hyatt@apple.comb048c562016-09-11 18:11:42 +000092 delete downcast<StyleRuleNamespace>(this);
93 return;
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +000094 case StyleRuleType::Keyframe:
hyatt@apple.come39aad32016-12-14 23:15:24 +000095 delete downcast<StyleRuleKeyframe>(this);
hyatt@apple.comb048c562016-09-11 18:11:42 +000096 return;
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +000097 case StyleRuleType::Charset:
hyatt@apple.com005da7c2016-10-24 18:18:09 +000098 delete downcast<StyleRuleCharset>(this);
99 return;
commit-queue@webkit.orgfef30932021-04-16 19:19:04 +0000100 case StyleRuleType::CounterStyle:
101 delete downcast<StyleRuleCounterStyle>(this);
102 return;
antti@apple.com850cde42021-12-08 16:55:05 +0000103 case StyleRuleType::LayerBlock:
104 case StyleRuleType::LayerStatement:
antti@apple.comd237ffd2021-08-27 17:43:04 +0000105 delete downcast<StyleRuleLayer>(this);
106 return;
antti@apple.com2ef5bc02021-12-10 13:28:28 +0000107 case StyleRuleType::Container:
108 delete downcast<StyleRuleContainer>(this);
109 return;
antti@apple.comf25e19f2021-12-11 18:28:39 +0000110 case StyleRuleType::Margin:
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000111 case StyleRuleType::Unknown:
antti@apple.comd09a7922012-04-02 19:50:34 +0000112 ASSERT_NOT_REACHED();
113 return;
114 }
115 ASSERT_NOT_REACHED();
116}
117
akling@apple.com689f7612014-12-14 08:21:05 +0000118Ref<StyleRuleBase> StyleRuleBase::copy() const
antti@apple.comca0770b2012-04-24 21:56:48 +0000119{
120 switch (type()) {
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000121 case StyleRuleType::Style:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +0000122 return downcast<StyleRule>(*this).copy();
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000123 case StyleRuleType::Page:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +0000124 return downcast<StyleRulePage>(*this).copy();
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000125 case StyleRuleType::FontFace:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +0000126 return downcast<StyleRuleFontFace>(*this).copy();
mmaxfield@apple.com0e1f0c42021-09-21 08:24:36 +0000127 case StyleRuleType::FontPaletteValues:
128 return downcast<StyleRuleFontPaletteValues>(*this).copy();
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000129 case StyleRuleType::Media:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +0000130 return downcast<StyleRuleMedia>(*this).copy();
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000131 case StyleRuleType::Supports:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +0000132 return downcast<StyleRuleSupports>(*this).copy();
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000133 case StyleRuleType::Keyframes:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +0000134 return downcast<StyleRuleKeyframes>(*this).copy();
commit-queue@webkit.orgfef30932021-04-16 19:19:04 +0000135 case StyleRuleType::CounterStyle:
136 return downcast<StyleRuleCounterStyle>(*this).copy();
antti@apple.com850cde42021-12-08 16:55:05 +0000137 case StyleRuleType::LayerBlock:
138 case StyleRuleType::LayerStatement:
antti@apple.comd237ffd2021-08-27 17:43:04 +0000139 return downcast<StyleRuleLayer>(*this).copy();
antti@apple.com2ef5bc02021-12-10 13:28:28 +0000140 case StyleRuleType::Container:
141 return downcast<StyleRuleContainer>(*this).copy();
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000142 case StyleRuleType::Import:
143 case StyleRuleType::Namespace:
hyatt@apple.comb048c562016-09-11 18:11:42 +0000144 // FIXME: Copy import and namespace rules.
akling@apple.com8c487df2013-10-20 10:49:10 +0000145 break;
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000146 case StyleRuleType::Unknown:
147 case StyleRuleType::Charset:
148 case StyleRuleType::Keyframe:
antti@apple.comf25e19f2021-12-11 18:28:39 +0000149 case StyleRuleType::Margin:
akling@apple.com8c487df2013-10-20 10:49:10 +0000150 break;
antti@apple.comca0770b2012-04-24 21:56:48 +0000151 }
akling@apple.com8c487df2013-10-20 10:49:10 +0000152 CRASH();
antti@apple.comca0770b2012-04-24 21:56:48 +0000153}
154
yusukesuzuki@slowstart.orgae5a8bd2018-12-22 06:37:39 +0000155Ref<CSSRule> StyleRuleBase::createCSSOMWrapper(CSSStyleSheet* parentSheet, CSSRule* parentRule) const
antti@apple.comd09a7922012-04-02 19:50:34 +0000156{
157 RefPtr<CSSRule> rule;
akling@apple.com39ce74c2014-10-03 04:38:19 +0000158 StyleRuleBase& self = const_cast<StyleRuleBase&>(*this);
antti@apple.comd09a7922012-04-02 19:50:34 +0000159 switch (type()) {
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000160 case StyleRuleType::Style:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +0000161 rule = CSSStyleRule::create(downcast<StyleRule>(self), parentSheet);
antti@apple.comd09a7922012-04-02 19:50:34 +0000162 break;
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000163 case StyleRuleType::Page:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +0000164 rule = CSSPageRule::create(downcast<StyleRulePage>(self), parentSheet);
antti@apple.comd09a7922012-04-02 19:50:34 +0000165 break;
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000166 case StyleRuleType::FontFace:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +0000167 rule = CSSFontFaceRule::create(downcast<StyleRuleFontFace>(self), parentSheet);
antti@apple.comd09a7922012-04-02 19:50:34 +0000168 break;
mmaxfield@apple.com0e1f0c42021-09-21 08:24:36 +0000169 case StyleRuleType::FontPaletteValues:
170 rule = CSSFontPaletteValuesRule::create(downcast<StyleRuleFontPaletteValues>(self), parentSheet);
171 break;
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000172 case StyleRuleType::Media:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +0000173 rule = CSSMediaRule::create(downcast<StyleRuleMedia>(self), parentSheet);
antti@apple.comd09a7922012-04-02 19:50:34 +0000174 break;
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000175 case StyleRuleType::Supports:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +0000176 rule = CSSSupportsRule::create(downcast<StyleRuleSupports>(self), parentSheet);
commit-queue@webkit.org03dd24f2013-01-16 11:30:50 +0000177 break;
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000178 case StyleRuleType::Import:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +0000179 rule = CSSImportRule::create(downcast<StyleRuleImport>(self), parentSheet);
antti@apple.comd09a7922012-04-02 19:50:34 +0000180 break;
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000181 case StyleRuleType::Keyframes:
cdumez@apple.com7687ecf2014-12-12 20:28:17 +0000182 rule = CSSKeyframesRule::create(downcast<StyleRuleKeyframes>(self), parentSheet);
antti@apple.comd09a7922012-04-02 19:50:34 +0000183 break;
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000184 case StyleRuleType::Namespace:
hyatt@apple.com1f589652016-12-10 18:31:13 +0000185 rule = CSSNamespaceRule::create(downcast<StyleRuleNamespace>(self), parentSheet);
186 break;
commit-queue@webkit.orgfef30932021-04-16 19:19:04 +0000187 case StyleRuleType::CounterStyle:
188 rule = CSSCounterStyleRule::create(downcast<StyleRuleCounterStyle>(self), parentSheet);
189 break;
antti@apple.com850cde42021-12-08 16:55:05 +0000190 case StyleRuleType::LayerBlock:
191 rule = CSSLayerBlockRule::create(downcast<StyleRuleLayer>(self), parentSheet);
192 break;
193 case StyleRuleType::LayerStatement:
194 rule = CSSLayerStatementRule::create(downcast<StyleRuleLayer>(self), parentSheet);
antti@apple.com24b9b5d2021-09-28 15:40:24 +0000195 break;
antti@apple.com2ef5bc02021-12-10 13:28:28 +0000196 case StyleRuleType::Container:
antti@apple.comc34471a2022-03-29 18:19:56 +0000197 rule = CSSContainerRule::create(downcast<StyleRuleContainer>(self), parentSheet);
antti@apple.com2ef5bc02021-12-10 13:28:28 +0000198 break;
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000199 case StyleRuleType::Unknown:
200 case StyleRuleType::Charset:
201 case StyleRuleType::Keyframe:
antti@apple.comf25e19f2021-12-11 18:28:39 +0000202 case StyleRuleType::Margin:
antti@apple.comd09a7922012-04-02 19:50:34 +0000203 ASSERT_NOT_REACHED();
yusukesuzuki@slowstart.orgae5a8bd2018-12-22 06:37:39 +0000204 break;
antti@apple.comd09a7922012-04-02 19:50:34 +0000205 }
yusukesuzuki@slowstart.orgae5a8bd2018-12-22 06:37:39 +0000206 ASSERT(rule);
207
antti@apple.comd09a7922012-04-02 19:50:34 +0000208 if (parentRule)
209 rule->setParentRule(parentRule);
yusukesuzuki@slowstart.orgae5a8bd2018-12-22 06:37:39 +0000210 return rule.releaseNonNull();
antti@apple.comd09a7922012-04-02 19:50:34 +0000211}
212
antti@apple.com52f660f2012-04-26 22:26:35 +0000213unsigned StyleRule::averageSizeInBytes()
214{
antti@apple.come5428c52013-11-28 20:53:22 +0000215 return sizeof(StyleRule) + sizeof(CSSSelector) + StyleProperties::averageSizeInBytes();
antti@apple.com52f660f2012-04-26 22:26:35 +0000216}
217
bfulgham@apple.com1ee843f2022-05-10 21:15:45 +0000218StyleRule::StyleRule(Ref<StyleProperties>&& properties, bool hasDocumentSecurityOrigin, CSSSelectorList&& selectors)
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000219 : StyleRuleBase(StyleRuleType::Style, hasDocumentSecurityOrigin)
aestes@apple.com13aae082016-01-02 08:03:08 +0000220 , m_properties(WTFMove(properties))
achristensen@apple.com37ead0f2018-08-13 23:36:09 +0000221 , m_selectorList(WTFMove(selectors))
antti@apple.com8be9b562012-02-28 17:44:18 +0000222{
223}
antti@apple.comd09a7922012-04-02 19:50:34 +0000224
antti@apple.comca0770b2012-04-24 21:56:48 +0000225StyleRule::StyleRule(const StyleRule& o)
226 : StyleRuleBase(o)
hyatt@apple.coma703cf22016-12-14 21:02:07 +0000227 , m_properties(o.properties().mutableCopy())
antti@apple.comca0770b2012-04-24 21:56:48 +0000228 , m_selectorList(o.m_selectorList)
pangle@apple.comebd2c582021-08-21 00:35:46 +0000229 , m_isSplitRule(o.m_isSplitRule)
230 , m_isLastRuleInSplitRule(o.m_isLastRuleInSplitRule)
antti@apple.comca0770b2012-04-24 21:56:48 +0000231{
232}
233
dbates@webkit.orgf21f3ae2017-10-19 23:48:45 +0000234StyleRule::~StyleRule() = default;
antti@apple.comd09a7922012-04-02 19:50:34 +0000235
bfulgham@apple.com1ee843f2022-05-10 21:15:45 +0000236Ref<StyleRule> StyleRule::create(Ref<StyleProperties>&& properties, bool hasDocumentSecurityOrigin, CSSSelectorList&& selectors)
darin@apple.com637194d2020-09-25 17:19:48 +0000237{
238 return adoptRef(*new StyleRule(WTFMove(properties), hasDocumentSecurityOrigin, WTFMove(selectors)));
239}
240
241Ref<StyleRule> StyleRule::copy() const
242{
243 return adoptRef(*new StyleRule(*this));
244}
245
antti@apple.come5428c52013-11-28 20:53:22 +0000246MutableStyleProperties& StyleRule::mutableProperties()
kling@webkit.org5e60b732012-05-29 12:25:07 +0000247{
drousso@apple.comb706fa02021-09-24 18:04:35 +0000248 if (!is<MutableStyleProperties>(m_properties))
hyatt@apple.coma703cf22016-12-14 21:02:07 +0000249 m_properties = properties().mutableCopy();
cdumez@apple.com9b2f708c2014-10-04 08:30:15 +0000250 return downcast<MutableStyleProperties>(m_properties.get());
kling@webkit.org5e60b732012-05-29 12:25:07 +0000251}
252
antti@apple.comc430d672017-12-07 23:58:39 +0000253Ref<StyleRule> StyleRule::createForSplitting(const Vector<const CSSSelector*>& selectors, Ref<StyleProperties>&& properties, bool hasDocumentSecurityOrigin)
akling@apple.com91d528d2013-07-08 15:53:54 +0000254{
antti@apple.comfeac3de2014-03-19 21:43:52 +0000255 ASSERT_WITH_SECURITY_IMPLICATION(!selectors.isEmpty());
achristensen@apple.com37ead0f2018-08-13 23:36:09 +0000256 auto selectorListArray = makeUniqueArray<CSSSelector>(selectors.size());
akling@apple.com91d528d2013-07-08 15:53:54 +0000257 for (unsigned i = 0; i < selectors.size(); ++i)
258 new (NotNull, &selectorListArray[i]) CSSSelector(*selectors.at(i));
259 selectorListArray[selectors.size() - 1].setLastInSelectorList();
pangle@apple.comebd2c582021-08-21 00:35:46 +0000260 auto styleRule = StyleRule::create(WTFMove(properties), hasDocumentSecurityOrigin, CSSSelectorList(WTFMove(selectorListArray)));
261 styleRule->markAsSplitRule();
262 return styleRule;
akling@apple.com91d528d2013-07-08 15:53:54 +0000263}
264
andersca@apple.comc3523f82013-10-18 23:41:24 +0000265Vector<RefPtr<StyleRule>> StyleRule::splitIntoMultipleRulesWithMaximumSelectorComponentCount(unsigned maxCount) const
akling@apple.com91d528d2013-07-08 15:53:54 +0000266{
akling@apple.comccc62452013-07-17 17:21:51 +0000267 ASSERT(selectorList().componentCount() > maxCount);
akling@apple.com91d528d2013-07-08 15:53:54 +0000268
andersca@apple.comc3523f82013-10-18 23:41:24 +0000269 Vector<RefPtr<StyleRule>> rules;
akling@apple.comccc62452013-07-17 17:21:51 +0000270 Vector<const CSSSelector*> componentsSinceLastSplit;
akling@apple.com91d528d2013-07-08 15:53:54 +0000271
272 for (const CSSSelector* selector = selectorList().first(); selector; selector = CSSSelectorList::next(selector)) {
akling@apple.comccc62452013-07-17 17:21:51 +0000273 Vector<const CSSSelector*, 8> componentsInThisSelector;
akling@apple.com91d528d2013-07-08 15:53:54 +0000274 for (const CSSSelector* component = selector; component; component = component->tagHistory())
akling@apple.comccc62452013-07-17 17:21:51 +0000275 componentsInThisSelector.append(component);
akling@apple.com91d528d2013-07-08 15:53:54 +0000276
antti@apple.comfeac3de2014-03-19 21:43:52 +0000277 if (componentsInThisSelector.size() + componentsSinceLastSplit.size() > maxCount && !componentsSinceLastSplit.isEmpty()) {
antti@apple.comc430d672017-12-07 23:58:39 +0000278 rules.append(createForSplitting(componentsSinceLastSplit, const_cast<StyleProperties&>(properties()), hasDocumentSecurityOrigin()));
akling@apple.comccc62452013-07-17 17:21:51 +0000279 componentsSinceLastSplit.clear();
akling@apple.com91d528d2013-07-08 15:53:54 +0000280 }
akling@apple.comccc62452013-07-17 17:21:51 +0000281
282 componentsSinceLastSplit.appendVector(componentsInThisSelector);
akling@apple.com91d528d2013-07-08 15:53:54 +0000283 }
284
akling@apple.comccc62452013-07-17 17:21:51 +0000285 if (!componentsSinceLastSplit.isEmpty())
antti@apple.comc430d672017-12-07 23:58:39 +0000286 rules.append(createForSplitting(componentsSinceLastSplit, const_cast<StyleProperties&>(properties()), hasDocumentSecurityOrigin()));
akling@apple.com91d528d2013-07-08 15:53:54 +0000287
pangle@apple.comebd2c582021-08-21 00:35:46 +0000288 if (!rules.isEmpty())
289 rules.last()->markAsLastRuleInSplitRule();
290
akling@apple.com91d528d2013-07-08 15:53:54 +0000291 return rules;
292}
293
achristensen@apple.com37ead0f2018-08-13 23:36:09 +0000294StyleRulePage::StyleRulePage(Ref<StyleProperties>&& properties, CSSSelectorList&& selectors)
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000295 : StyleRuleBase(StyleRuleType::Page)
aestes@apple.com13aae082016-01-02 08:03:08 +0000296 , m_properties(WTFMove(properties))
achristensen@apple.com37ead0f2018-08-13 23:36:09 +0000297 , m_selectorList(WTFMove(selectors))
antti@apple.com8be9b562012-02-28 17:44:18 +0000298{
antti@apple.comd09a7922012-04-02 19:50:34 +0000299}
300
antti@apple.comca0770b2012-04-24 21:56:48 +0000301StyleRulePage::StyleRulePage(const StyleRulePage& o)
302 : StyleRuleBase(o)
akling@apple.com2420f862013-04-13 20:03:20 +0000303 , m_properties(o.m_properties->mutableCopy())
antti@apple.comca0770b2012-04-24 21:56:48 +0000304 , m_selectorList(o.m_selectorList)
305{
306}
307
dbates@webkit.orgf21f3ae2017-10-19 23:48:45 +0000308StyleRulePage::~StyleRulePage() = default;
antti@apple.comd09a7922012-04-02 19:50:34 +0000309
darin@apple.com637194d2020-09-25 17:19:48 +0000310Ref<StyleRulePage> StyleRulePage::create(Ref<StyleProperties>&& properties, CSSSelectorList&& selectors)
311{
312 return adoptRef(*new StyleRulePage(WTFMove(properties), WTFMove(selectors)));
313}
314
antti@apple.come5428c52013-11-28 20:53:22 +0000315MutableStyleProperties& StyleRulePage::mutableProperties()
kling@webkit.org5e60b732012-05-29 12:25:07 +0000316{
drousso@apple.comb706fa02021-09-24 18:04:35 +0000317 if (!is<MutableStyleProperties>(m_properties))
akling@apple.com2420f862013-04-13 20:03:20 +0000318 m_properties = m_properties->mutableCopy();
cdumez@apple.com9b2f708c2014-10-04 08:30:15 +0000319 return downcast<MutableStyleProperties>(m_properties.get());
kling@webkit.org5e60b732012-05-29 12:25:07 +0000320}
321
akling@apple.com689f7612014-12-14 08:21:05 +0000322StyleRuleFontFace::StyleRuleFontFace(Ref<StyleProperties>&& properties)
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000323 : StyleRuleBase(StyleRuleType::FontFace)
aestes@apple.com13aae082016-01-02 08:03:08 +0000324 , m_properties(WTFMove(properties))
antti@apple.comd09a7922012-04-02 19:50:34 +0000325{
326}
327
antti@apple.comca0770b2012-04-24 21:56:48 +0000328StyleRuleFontFace::StyleRuleFontFace(const StyleRuleFontFace& o)
329 : StyleRuleBase(o)
akling@apple.com2420f862013-04-13 20:03:20 +0000330 , m_properties(o.m_properties->mutableCopy())
antti@apple.comca0770b2012-04-24 21:56:48 +0000331{
332}
333
dbates@webkit.orgf21f3ae2017-10-19 23:48:45 +0000334StyleRuleFontFace::~StyleRuleFontFace() = default;
antti@apple.comd09a7922012-04-02 19:50:34 +0000335
antti@apple.come5428c52013-11-28 20:53:22 +0000336MutableStyleProperties& StyleRuleFontFace::mutableProperties()
kling@webkit.org5e60b732012-05-29 12:25:07 +0000337{
drousso@apple.comb706fa02021-09-24 18:04:35 +0000338 if (!is<MutableStyleProperties>(m_properties))
akling@apple.com2420f862013-04-13 20:03:20 +0000339 m_properties = m_properties->mutableCopy();
cdumez@apple.com9b2f708c2014-10-04 08:30:15 +0000340 return downcast<MutableStyleProperties>(m_properties.get());
kling@webkit.org5e60b732012-05-29 12:25:07 +0000341}
342
mmaxfield@apple.com3b791c52021-10-07 23:05:49 +0000343StyleRuleFontPaletteValues::StyleRuleFontPaletteValues(const AtomString& name, const AtomString& fontFamily, std::optional<FontPaletteIndex> basePalette, Vector<FontPaletteValues::OverriddenColor>&& overrideColors)
mmaxfield@apple.com0e1f0c42021-09-21 08:24:36 +0000344 : StyleRuleBase(StyleRuleType::FontPaletteValues)
345 , m_name(name)
346 , m_fontFamily(fontFamily)
mmaxfield@apple.comebf86d82021-09-28 06:45:49 +0000347 , m_fontPaletteValues(basePalette, WTFMove(overrideColors))
mmaxfield@apple.com0e1f0c42021-09-21 08:24:36 +0000348{
349}
350
351StyleRuleFontPaletteValues::StyleRuleFontPaletteValues(const StyleRuleFontPaletteValues& o)
352 : StyleRuleBase(o)
353 , m_name(o.name())
354 , m_fontFamily(o.fontFamily())
355 , m_fontPaletteValues(o.m_fontPaletteValues)
356{
357}
358
359StyleRuleFontPaletteValues::~StyleRuleFontPaletteValues() = default;
hyatt@apple.coma703cf22016-12-14 21:02:07 +0000360
darin@apple.com637194d2020-09-25 17:19:48 +0000361StyleRuleGroup::StyleRuleGroup(StyleRuleType type, Vector<RefPtr<StyleRuleBase>>&& rules)
hyatt@apple.comda947f72016-12-03 21:22:49 +0000362 : StyleRuleBase(type)
darin@apple.com637194d2020-09-25 17:19:48 +0000363 , m_childRules(WTFMove(rules))
antti@apple.comd09a7922012-04-02 19:50:34 +0000364{
antti@apple.comd09a7922012-04-02 19:50:34 +0000365}
366
tasak@google.com44b7f4c2013-01-21 10:33:19 +0000367StyleRuleGroup::StyleRuleGroup(const StyleRuleGroup& o)
antti@apple.comca0770b2012-04-24 21:56:48 +0000368 : StyleRuleBase(o)
cdumez@apple.comda062e12022-02-17 17:17:46 +0000369 , m_childRules(o.childRules().map([](auto& rule) -> RefPtr<StyleRuleBase> { return rule->copy(); }))
antti@apple.comca0770b2012-04-24 21:56:48 +0000370{
antti@apple.comca0770b2012-04-24 21:56:48 +0000371}
372
hyatt@apple.coma703cf22016-12-14 21:02:07 +0000373const Vector<RefPtr<StyleRuleBase>>& StyleRuleGroup::childRules() const
374{
hyatt@apple.coma703cf22016-12-14 21:02:07 +0000375 return m_childRules;
376}
377
akling@apple.com689f7612014-12-14 08:21:05 +0000378void StyleRuleGroup::wrapperInsertRule(unsigned index, Ref<StyleRuleBase>&& rule)
antti@apple.comd09a7922012-04-02 19:50:34 +0000379{
aestes@apple.com13aae082016-01-02 08:03:08 +0000380 m_childRules.insert(index, WTFMove(rule));
antti@apple.com8be9b562012-02-28 17:44:18 +0000381}
382
tasak@google.com44b7f4c2013-01-21 10:33:19 +0000383void StyleRuleGroup::wrapperRemoveRule(unsigned index)
antti@apple.com8be9b562012-02-28 17:44:18 +0000384{
antti@apple.comd09a7922012-04-02 19:50:34 +0000385 m_childRules.remove(index);
386}
387
darin@apple.com637194d2020-09-25 17:19:48 +0000388StyleRuleMedia::StyleRuleMedia(Ref<MediaQuerySet>&& media, Vector<RefPtr<StyleRuleBase>>&& rules)
389 : StyleRuleGroup(StyleRuleType::Media, WTFMove(rules))
achristensen@apple.com26aaf302016-05-24 05:34:49 +0000390 , m_mediaQueries(WTFMove(media))
antti@apple.comd09a7922012-04-02 19:50:34 +0000391{
392}
393
darin@apple.com637194d2020-09-25 17:19:48 +0000394StyleRuleMedia::StyleRuleMedia(const StyleRuleMedia& other)
395 : StyleRuleGroup(other)
396 , m_mediaQueries(other.m_mediaQueries->copy())
antti@apple.comca0770b2012-04-24 21:56:48 +0000397{
398}
399
darin@apple.com637194d2020-09-25 17:19:48 +0000400Ref<StyleRuleMedia> StyleRuleMedia::create(Ref<MediaQuerySet>&& media, Vector<RefPtr<StyleRuleBase>>&& rules)
401{
402 return adoptRef(*new StyleRuleMedia(WTFMove(media), WTFMove(rules)));
403}
commit-queue@webkit.org03dd24f2013-01-16 11:30:50 +0000404
darin@apple.com637194d2020-09-25 17:19:48 +0000405Ref<StyleRuleMedia> StyleRuleMedia::copy() const
406{
407 return adoptRef(*new StyleRuleMedia(*this));
408}
409
410StyleRuleSupports::StyleRuleSupports(const String& conditionText, bool conditionIsSupported, Vector<RefPtr<StyleRuleBase>>&& rules)
411 : StyleRuleGroup(StyleRuleType::Supports, WTFMove(rules))
commit-queue@webkit.org03dd24f2013-01-16 11:30:50 +0000412 , m_conditionText(conditionText)
413 , m_conditionIsSupported(conditionIsSupported)
414{
415}
416
417StyleRuleSupports::StyleRuleSupports(const StyleRuleSupports& o)
tasak@google.com44b7f4c2013-01-21 10:33:19 +0000418 : StyleRuleGroup(o)
commit-queue@webkit.org03dd24f2013-01-16 11:30:50 +0000419 , m_conditionText(o.m_conditionText)
420 , m_conditionIsSupported(o.m_conditionIsSupported)
421{
422}
commit-queue@webkit.org03dd24f2013-01-16 11:30:50 +0000423
antti@apple.comd237ffd2021-08-27 17:43:04 +0000424
darin@apple.com637194d2020-09-25 17:19:48 +0000425Ref<StyleRuleSupports> StyleRuleSupports::create(const String& conditionText, bool conditionIsSupported, Vector<RefPtr<StyleRuleBase>>&& rules)
426{
427 return adoptRef(*new StyleRuleSupports(conditionText, conditionIsSupported, WTFMove(rules)));
428}
429
antti@apple.comd237ffd2021-08-27 17:43:04 +0000430StyleRuleLayer::StyleRuleLayer(Vector<CascadeLayerName>&& nameList)
antti@apple.com850cde42021-12-08 16:55:05 +0000431 : StyleRuleGroup(StyleRuleType::LayerStatement, Vector<RefPtr<StyleRuleBase>> { })
antti@apple.comd237ffd2021-08-27 17:43:04 +0000432 , m_nameVariant(WTFMove(nameList))
433{
434}
435
436StyleRuleLayer::StyleRuleLayer(CascadeLayerName&& name, Vector<RefPtr<StyleRuleBase>>&& rules)
antti@apple.com850cde42021-12-08 16:55:05 +0000437 : StyleRuleGroup(StyleRuleType::LayerBlock, WTFMove(rules))
antti@apple.comd237ffd2021-08-27 17:43:04 +0000438 , m_nameVariant(WTFMove(name))
439{
440}
441
antti@apple.comd237ffd2021-08-27 17:43:04 +0000442StyleRuleLayer::StyleRuleLayer(const StyleRuleLayer& other)
443 : StyleRuleGroup(other)
444 , m_nameVariant(other.m_nameVariant)
445{
446}
447
antti@apple.com325beca2021-09-27 16:27:00 +0000448Ref<StyleRuleLayer> StyleRuleLayer::createStatement(Vector<CascadeLayerName>&& nameList)
antti@apple.comd237ffd2021-08-27 17:43:04 +0000449{
450 return adoptRef(*new StyleRuleLayer(WTFMove(nameList)));
451}
452
antti@apple.com325beca2021-09-27 16:27:00 +0000453Ref<StyleRuleLayer> StyleRuleLayer::createBlock(CascadeLayerName&& name, Vector<RefPtr<StyleRuleBase>>&& rules)
antti@apple.comd237ffd2021-08-27 17:43:04 +0000454{
455 return adoptRef(*new StyleRuleLayer(WTFMove(name), WTFMove(rules)));
456}
457
antti@apple.com3e729cb2022-02-13 12:21:50 +0000458StyleRuleContainer::StyleRuleContainer(FilteredContainerQuery&& query, Vector<RefPtr<StyleRuleBase>>&& rules)
antti@apple.com2ef5bc02021-12-10 13:28:28 +0000459 : StyleRuleGroup(StyleRuleType::Container, WTFMove(rules))
antti@apple.com3e729cb2022-02-13 12:21:50 +0000460 , m_filteredQuery(WTFMove(query))
antti@apple.com2ef5bc02021-12-10 13:28:28 +0000461{
462}
463
antti@apple.com2ef5bc02021-12-10 13:28:28 +0000464StyleRuleContainer::StyleRuleContainer(const StyleRuleContainer& other)
465 : StyleRuleGroup(other)
antti@apple.com3e729cb2022-02-13 12:21:50 +0000466 , m_filteredQuery(other.m_filteredQuery)
antti@apple.com2ef5bc02021-12-10 13:28:28 +0000467{
468}
469
antti@apple.com3e729cb2022-02-13 12:21:50 +0000470Ref<StyleRuleContainer> StyleRuleContainer::create(FilteredContainerQuery&& query, Vector<RefPtr<StyleRuleBase>>&& rules)
antti@apple.com2ef5bc02021-12-10 13:28:28 +0000471{
472 return adoptRef(*new StyleRuleContainer(WTFMove(query), WTFMove(rules)));
473}
474
hyatt@apple.comb048c562016-09-11 18:11:42 +0000475StyleRuleCharset::StyleRuleCharset()
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000476 : StyleRuleBase(StyleRuleType::Charset)
hyatt@apple.comb048c562016-09-11 18:11:42 +0000477{
478}
479
480StyleRuleCharset::StyleRuleCharset(const StyleRuleCharset& o)
481 : StyleRuleBase(o)
482{
483}
484
darin@apple.com637194d2020-09-25 17:19:48 +0000485StyleRuleNamespace::StyleRuleNamespace(const AtomString& prefix, const AtomString& uri)
simon.fraser@apple.com7aa567342019-10-28 16:02:53 +0000486 : StyleRuleBase(StyleRuleType::Namespace)
hyatt@apple.comb048c562016-09-11 18:11:42 +0000487 , m_prefix(prefix)
488 , m_uri(uri)
489{
490}
491
492StyleRuleNamespace::StyleRuleNamespace(const StyleRuleNamespace& o)
493 : StyleRuleBase(o)
494 , m_prefix(o.m_prefix)
495 , m_uri(o.m_uri)
496{
497}
498
dbates@webkit.orgf21f3ae2017-10-19 23:48:45 +0000499StyleRuleNamespace::~StyleRuleNamespace() = default;
hyatt@apple.comb048c562016-09-11 18:11:42 +0000500
darin@apple.com637194d2020-09-25 17:19:48 +0000501Ref<StyleRuleNamespace> StyleRuleNamespace::create(const AtomString& prefix, const AtomString& uri)
502{
503 return adoptRef(*new StyleRuleNamespace(prefix, uri));
504}
505
antti@apple.com8be9b562012-02-28 17:44:18 +0000506} // namespace WebCore