Add CSSConditionRule and CSSGroupingRule
https://bugs.webkit.org/show_bug.cgi?id=216855

Reviewed by Sam Weinig.

LayoutTests/imported/w3c:

* web-platform-tests/css/conditional/idlharness-expected.txt:
* web-platform-tests/css/cssom/MediaList-expected.txt:
* web-platform-tests/css/cssom/cssimportrule-expected.txt:
* web-platform-tests/css/cssom/idlharness-expected.txt:
Updated expectations to expect more tests to pass.

Source/WebCore:

* CMakeLists.txt: Added CSSConditionRule.idl and CSSGroupingRule.idl.

* DerivedSources-input.xcfilelist: Updated.
* DerivedSources-output.xcfilelist: Updated.

* DerivedSources.make: Added CSSConditionRule.idl and CSSGroupingRule.idl.
* Headers.cmake: Added CSSConditionRule.h.
* Sources.txt: Add CSSConditionRule.cpp, JSCSSConditioRule.cpp,
and JSCSSGroupingRule.cpp.

* WebCore.xcodeproj/project.pbxproj: Added all the files.

* css/CSSConditionRule.cpp: Added.
* css/CSSConditionRule.h: Added.
* css/CSSConditionRule.idl: Added.

* css/CSSGroupingRule.cpp:
(WebCore::CSSGroupingRule::~CSSGroupingRule): Use a range-based for loop
and nullptr.
(WebCore::CSSGroupingRule::appendCSSTextForItems const): Use variadic
append to clean this up a bit.
(WebCore::CSSGroupingRule::item const): Use auto.

* css/CSSGroupingRule.h: Made m_groupRule private instead of protected.
Did some other tweaks.

* css/CSSGroupingRule.idl: Added.

* css/CSSImportRule.idl: Added [Exposed=Window], changed href to be a
USVString, added [SameObject, PutForwards=mediaText] to media
and [SameObject] to styleSheet.

* css/CSSMediaRule.cpp:
(WebCore::CSSMediaRule::CSSMediaRule): Derive from CSSConditionRule.
(WebCore::CSSMediaRule::mediaQueries const): Return a reference.
(WebCore::CSSMediaRule::cssText const): Streamline since we don't need a
null check.
(WebCore::CSSMediaRule::conditionText const): Added.
(WebCore::CSSMediaRule::setConditionText): Added.
(WebCore::CSSMediaRule::media const): Streamline since we don't need a
null check.
(WebCore::CSSMediaRule::reattach): Ditto.

* css/CSSMediaRule.h: Derive from CSSConditionRule.

* css/CSSMediaRule.idl: Derive from CSSConditionRule. Added
[Exposed=Window]. Added [SameObject, PutForwards=mediaText] to media.
Removed insertRule and deleteRule since they are now inherited from
CSSGroupingRule.

* css/CSSRule.h: Added MARGIN_RULE constant even though we don't have
that rule type. Moved inline functions out of the class body to help
clarity a bit.

* css/CSSRule.idl: Added [Exposed=Window], changed a few things to match
the specification.

* css/CSSStyleRule.idl: Added [Exposed=Window]. Added [SameObject]
to style.

* css/CSSStyleSheet.idl: Added [Exposed=Window].

* css/CSSSupportsRule.cpp:
(WebCore::CSSSupportsRule::CSSSupportsRule): Derive from CSSConditionRule.
(WebCore::CSSSupportsRule::create): Added.
(WebCore::CSSSupportsRule::cssText const): Use variadic append.
(WebCore::CSSSupportsRule::conditionText const): Updated to use groupRule.
(WebCore::CSSSupportsRule::setConditionText): Added. Not implemented yet.

* css/CSSSupportsRule.h: Derive from CSSConditionRule.

* css/CSSSupportsRule.idl: Derive from CSSConditionRule.
Added [Exposed=Window].

* css/MediaList.cpp:
(WebCore::MediaQuerySet::set): Use move instead of swap.

* css/MediaList.idl: Added [Exposed=Window] and marked mediaText as
the stringifier.

* css/StyleRule.cpp:
(WebCore::StyleRule::create): Moved here from the header.
(WebCore::StyleRule::copy const): Ditto.
(WebCore::StyleRulePage::create): Ditto.
(WebCore::StyleRuleGroup::StyleRuleGroup): Use move instead of swap.
(WebCore::StyleRuleMedia::create): Use move instead of swap.
(WebCore::StyleRuleMedia::copy const): Moved out of the header.
(WebCore::StyleRuleSupports::StyleRuleSupports): Ditto.
(WebCore::StyleRuleSupports::create): Ditto.
(WebCore::StyleRuleNamespace::StyleRuleNamespace): Ditto.
(WebCore::StyleRuleNamespace::create): Ditto.

* css/StyleRule.h: Moved function bodies out of the class
defintiion for clarity.

* css/StyleSheet.idl: Added [Exposed=Window] and
[SameObject, PutForwards=mediaText] for media.

* css/StyleSheetContents.cpp:
(WebCore::StyleSheetContents::parserAppendRule): Updated since
mediaQueries returns a reference.

* css/StyleSheetList.idl: Added [Exposed=Window].

* css/parser/CSSParserImpl.cpp:
(WebCore::CSSParserImpl::consumeMediaRule): Use WTFMove since
the create function now takes an rvalue reference.
(WebCore::CSSParserImpl::consumeSupportsRule): Ditto.

* style/RuleSet.cpp:
(WebCore::Style::RuleSet::addChildRules): Updated since mediaQueries
returns a reference.
* style/UserAgentStyle.cpp:
(WebCore::Style::UserAgentStyle::addToDefaultStyle): Ditto.

Source/WebKitLegacy/mac:

* DOM/DOMCSS.mm:
(kitClass): Added a default case since we don't intend to list every single rule type here.

LayoutTests:

* fast/dom/domListEnumeration-expected.txt:
* fast/dom/domListEnumeration.html:
Updated since toString is now implemented and enumerable.

* fast/dom/non-numeric-values-numeric-parameters-expected.txt:
* fast/dom/non-numeric-values-numeric-parameters.html:
Updated test and expectations since CSSMediaRule's deleteRule no longer allows omitting
the index to delete rule 0 (both non-standard and inconsistent with CSSStyleSheet).

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@267576 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/css/CSSConditionRule.cpp b/Source/WebCore/css/CSSConditionRule.cpp
new file mode 100644
index 0000000..eb0c25a
--- /dev/null
+++ b/Source/WebCore/css/CSSConditionRule.cpp
@@ -0,0 +1,40 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CSSConditionRule.h"
+
+namespace WebCore {
+
+CSSConditionRule::CSSConditionRule(StyleRuleGroup& group, CSSStyleSheet* parent)
+    : CSSGroupingRule(group, parent)
+{
+}
+
+} // namespace WebCore
diff --git a/Source/WebCore/css/CSSConditionRule.h b/Source/WebCore/css/CSSConditionRule.h
new file mode 100644
index 0000000..1f6245d
--- /dev/null
+++ b/Source/WebCore/css/CSSConditionRule.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "CSSGroupingRule.h"
+
+namespace WebCore {
+
+class CSSConditionRule : public CSSGroupingRule {
+public:
+    virtual String conditionText() const = 0;
+    virtual void setConditionText(const String&) = 0;
+
+protected:
+    CSSConditionRule(StyleRuleGroup&, CSSStyleSheet* parent);
+};
+
+} // namespace WebCore
diff --git a/Source/WebCore/css/CSSConditionRule.idl b/Source/WebCore/css/CSSConditionRule.idl
new file mode 100644
index 0000000..255de6b
--- /dev/null
+++ b/Source/WebCore/css/CSSConditionRule.idl
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+typedef USVString CSSOMString;
+
+[Exposed=Window] interface CSSConditionRule : CSSGroupingRule {
+    attribute CSSOMString conditionText;
+};
diff --git a/Source/WebCore/css/CSSGroupingRule.cpp b/Source/WebCore/css/CSSGroupingRule.cpp
index c6c5c39..3876127 100644
--- a/Source/WebCore/css/CSSGroupingRule.cpp
+++ b/Source/WebCore/css/CSSGroupingRule.cpp
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
- * Copyright (C) 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2012-2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -29,7 +29,6 @@
  */
 
 #include "config.h"
-
 #include "CSSGroupingRule.h"
 
 #include "CSSParser.h"
@@ -50,9 +49,9 @@
 CSSGroupingRule::~CSSGroupingRule()
 {
     ASSERT(m_childRuleCSSOMWrappers.size() == m_groupRule->childRules().size());
-    for (unsigned i = 0; i < m_childRuleCSSOMWrappers.size(); ++i) {
-        if (m_childRuleCSSOMWrappers[i])
-            m_childRuleCSSOMWrappers[i]->setParentRule(0);
+    for (auto& wrapper : m_childRuleCSSOMWrappers) {
+        if (wrapper)
+            wrapper->setParentRule(nullptr);
     }
 }
 
@@ -111,14 +110,10 @@
     return { };
 }
 
-void CSSGroupingRule::appendCssTextForItems(StringBuilder& result) const
+void CSSGroupingRule::appendCSSTextForItems(StringBuilder& result) const
 {
-    unsigned size = length();
-    for (unsigned i = 0; i < size; ++i) {
-        result.appendLiteral("  ");
-        result.append(item(i)->cssText());
-        result.append('\n');
-    }
+    for (unsigned i = 0, size = length(); i < size; ++i)
+        result.append("  ", item(i)->cssText(), '\n');
 }
 
 unsigned CSSGroupingRule::length() const
@@ -131,7 +126,7 @@
     if (index >= length())
         return nullptr;
     ASSERT(m_childRuleCSSOMWrappers.size() == m_groupRule->childRules().size());
-    RefPtr<CSSRule>& rule = m_childRuleCSSOMWrappers[index];
+    auto& rule = m_childRuleCSSOMWrappers[index];
     if (!rule)
         rule = m_groupRule->childRules()[index]->createCSSOMWrapper(const_cast<CSSGroupingRule*>(this));
     return rule.get();
diff --git a/Source/WebCore/css/CSSGroupingRule.h b/Source/WebCore/css/CSSGroupingRule.h
index f54a397..cf7aa98 100644
--- a/Source/WebCore/css/CSSGroupingRule.h
+++ b/Source/WebCore/css/CSSGroupingRule.h
@@ -1,7 +1,7 @@
 /*
  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
  * (C) 2002-2003 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2002, 2006, 2008, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2002-2020 Apple Inc. All rights reserved.
  * Copyright (C) 2006 Samuel Weinig (sam@webkit.org)
  *
  * This library is free software; you can redistribute it and/or
@@ -36,24 +36,19 @@
     virtual ~CSSGroupingRule();
 
     WEBCORE_EXPORT CSSRuleList& cssRules() const;
-
     WEBCORE_EXPORT ExceptionOr<unsigned> insertRule(const String& rule, unsigned index);
     WEBCORE_EXPORT ExceptionOr<void> deleteRule(unsigned index);
-        
-    // For CSSRuleList
     unsigned length() const;
     CSSRule* item(unsigned index) const;
 
 protected:
-    CSSGroupingRule(StyleRuleGroup& groupRule, CSSStyleSheet* parent);
-    
+    CSSGroupingRule(StyleRuleGroup&, CSSStyleSheet* parent);
+    const StyleRuleGroup& groupRule() const { return m_groupRule; }
     void reattach(StyleRuleBase&) override;
-
-    void appendCssTextForItems(StringBuilder&) const;
-
-    Ref<StyleRuleGroup> m_groupRule;
+    void appendCSSTextForItems(StringBuilder&) const;
 
 private:
+    Ref<StyleRuleGroup> m_groupRule;
     mutable Vector<RefPtr<CSSRule>> m_childRuleCSSOMWrappers;
     mutable std::unique_ptr<CSSRuleList> m_ruleListCSSOMWrapper;
 };
diff --git a/Source/WebCore/css/CSSGroupingRule.idl b/Source/WebCore/css/CSSGroupingRule.idl
new file mode 100644
index 0000000..18ee312
--- /dev/null
+++ b/Source/WebCore/css/CSSGroupingRule.idl
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above
+ *    copyright notice, this list of conditions and the following
+ *    disclaimer in the documentation and/or other materials
+ *    provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
+ * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
+ * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
+ * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+typedef USVString CSSOMString;
+
+[Exposed=Window]
+interface CSSGroupingRule : CSSRule {
+    [SameObject] readonly attribute CSSRuleList cssRules;
+    [MayThrowException] unsigned long insertRule(CSSOMString rule, optional unsigned long index = 0);
+    [MayThrowException] undefined deleteRule(unsigned long index);
+};
diff --git a/Source/WebCore/css/CSSImportRule.idl b/Source/WebCore/css/CSSImportRule.idl
index f56ef9f..0869647 100644
--- a/Source/WebCore/css/CSSImportRule.idl
+++ b/Source/WebCore/css/CSSImportRule.idl
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2020 Apple Inc. All rights reserved.
  * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
@@ -18,10 +18,10 @@
  * Boston, MA 02110-1301, USA.
  */
 
-// Introduced in DOM Level 2:
+[Exposed=Window]
 interface CSSImportRule : CSSRule {
-    readonly attribute DOMString? href;
-    readonly attribute MediaList media;
-    readonly attribute CSSStyleSheet styleSheet;
+    readonly attribute USVString href;
+    [SameObject, PutForwards=mediaText] readonly attribute MediaList media;
+    [SameObject] readonly attribute CSSStyleSheet styleSheet;
 };
 
diff --git a/Source/WebCore/css/CSSMediaRule.cpp b/Source/WebCore/css/CSSMediaRule.cpp
index 15e9dc0..e01ee54 100644
--- a/Source/WebCore/css/CSSMediaRule.cpp
+++ b/Source/WebCore/css/CSSMediaRule.cpp
@@ -1,7 +1,7 @@
 /**
  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
  * (C) 2002-2003 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2002, 2005, 2006, 2012 Apple Inc.
+ * Copyright (C) 2002-2020 Apple Inc.
  * Copyright (C) 2006 Samuel Weinig (sam@webkit.org)
  *
  * This library is free software; you can redistribute it and/or
@@ -31,7 +31,7 @@
 namespace WebCore {
 
 CSSMediaRule::CSSMediaRule(StyleRuleMedia& mediaRule, CSSStyleSheet* parent)
-    : CSSGroupingRule(mediaRule, parent)
+    : CSSConditionRule(mediaRule, parent)
 {
 }
 
@@ -41,38 +41,42 @@
         m_mediaCSSOMWrapper->clearParentRule();
 }
 
-MediaQuerySet* CSSMediaRule::mediaQueries() const
+MediaQuerySet& CSSMediaRule::mediaQueries() const
 {
-    return downcast<StyleRuleMedia>(m_groupRule.get()).mediaQueries();
+    return downcast<StyleRuleMedia>(groupRule()).mediaQueries();
 }
 
 String CSSMediaRule::cssText() const
 {
     StringBuilder result;
-    result.appendLiteral("@media ");
-    if (mediaQueries()) {
-        result.append(mediaQueries()->mediaText(), ' ');
-    }
-    result.appendLiteral("{ \n");
-    appendCssTextForItems(result);
+    result.append("@media ", conditionText(), " { \n");
+    appendCSSTextForItems(result);
     result.append('}');
     return result.toString();
 }
 
+String CSSMediaRule::conditionText() const
+{
+    return mediaQueries().mediaText();
+}
+
+void CSSMediaRule::setConditionText(const String& text)
+{
+    mediaQueries().set(text);
+}
+
 MediaList* CSSMediaRule::media() const
 {
-    if (!mediaQueries())
-        return nullptr;
     if (!m_mediaCSSOMWrapper)
-        m_mediaCSSOMWrapper = MediaList::create(mediaQueries(), const_cast<CSSMediaRule*>(this));
+        m_mediaCSSOMWrapper = MediaList::create(&mediaQueries(), const_cast<CSSMediaRule*>(this));
     return m_mediaCSSOMWrapper.get();
 }
 
 void CSSMediaRule::reattach(StyleRuleBase& rule)
 {
-    CSSGroupingRule::reattach(rule);
-    if (m_mediaCSSOMWrapper && mediaQueries())
-        m_mediaCSSOMWrapper->reattach(mediaQueries());
+    CSSConditionRule::reattach(rule);
+    if (m_mediaCSSOMWrapper)
+        m_mediaCSSOMWrapper->reattach(&mediaQueries());
 }
 
 } // namespace WebCore
diff --git a/Source/WebCore/css/CSSMediaRule.h b/Source/WebCore/css/CSSMediaRule.h
index 2160fac..4548c1d 100644
--- a/Source/WebCore/css/CSSMediaRule.h
+++ b/Source/WebCore/css/CSSMediaRule.h
@@ -1,7 +1,7 @@
 /*
  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
  * (C) 2002-2003 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2002, 2006, 2008, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2002-2020 Apple Inc. All rights reserved.
  * Copyright (C) 2006 Samuel Weinig (sam@webkit.org)
  *
  * This library is free software; you can redistribute it and/or
@@ -22,7 +22,7 @@
 
 #pragma once
 
-#include "CSSGroupingRule.h"
+#include "CSSConditionRule.h"
 
 namespace WebCore {
 
@@ -30,10 +30,9 @@
 class MediaQuerySet;
 class StyleRuleMedia;
 
-class CSSMediaRule final : public CSSGroupingRule {
+class CSSMediaRule final : public CSSConditionRule {
 public:
     static Ref<CSSMediaRule> create(StyleRuleMedia& rule, CSSStyleSheet* sheet) { return adoptRef(*new CSSMediaRule(rule, sheet)); }
-
     virtual ~CSSMediaRule();
 
     WEBCORE_EXPORT MediaList* media() const;
@@ -44,9 +43,11 @@
     CSSRule::Type type() const final { return MEDIA_RULE; }
     void reattach(StyleRuleBase&) final;
     String cssText() const final;
+    String conditionText() const final;
+    void setConditionText(const String&) final;
 
-    MediaQuerySet* mediaQueries() const;
-    
+    MediaQuerySet& mediaQueries() const;
+
     mutable RefPtr<MediaList> m_mediaCSSOMWrapper;
 };
 
diff --git a/Source/WebCore/css/CSSMediaRule.idl b/Source/WebCore/css/CSSMediaRule.idl
index 39af941..b02ce74 100644
--- a/Source/WebCore/css/CSSMediaRule.idl
+++ b/Source/WebCore/css/CSSMediaRule.idl
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2020 Apple Inc. All rights reserved.
  * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
@@ -18,10 +18,7 @@
  * Boston, MA 02110-1301, USA.
  */
 
-interface CSSMediaRule : CSSRule {
-    readonly attribute MediaList media;
-    readonly attribute CSSRuleList cssRules;
-
-    [MayThrowException] unsigned long insertRule(optional DOMString rule = "undefined", optional unsigned long index = 0);
-    [MayThrowException] undefined deleteRule(optional unsigned long index = 0);
+[Exposed=Window]
+interface CSSMediaRule : CSSConditionRule {
+    [SameObject, PutForwards=mediaText] readonly attribute MediaList media;
 };
diff --git a/Source/WebCore/css/CSSRule.h b/Source/WebCore/css/CSSRule.h
index 4da5b63..c034626 100644
--- a/Source/WebCore/css/CSSRule.h
+++ b/Source/WebCore/css/CSSRule.h
@@ -1,7 +1,7 @@
 /*
  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
  * (C) 2002-2003 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2002, 2006, 2007, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2002-2020 Apple Inc. All rights reserved.
  * Copyright (C) 2011 Andreas Kling (kling@webkit.org)
  *
  * This library is free software; you can redistribute it and/or
@@ -44,54 +44,31 @@
         MEDIA_RULE,
         FONT_FACE_RULE,
         PAGE_RULE,
-        // 7 was VARIABLES_RULE; we now match other browsers with 7 as
-        // KEYFRAMES_RULE:
-        // <https://bugs.webkit.org/show_bug.cgi?id=71293>.
         KEYFRAMES_RULE,
         KEYFRAME_RULE,
-        NAMESPACE_RULE = 10, // Matches other browsers.
+        MARGIN_RULE,
+        NAMESPACE_RULE,
         SUPPORTS_RULE = 12,
     };
 
     enum DeprecatedType {
-        WEBKIT_KEYFRAMES_RULE = 7,
-        WEBKIT_KEYFRAME_RULE = 8
+        WEBKIT_KEYFRAMES_RULE = KEYFRAMES_RULE,
+        WEBKIT_KEYFRAME_RULE = KEYFRAME_RULE
     };
 
     virtual Type type() const = 0;
     virtual String cssText() const = 0;
     virtual void reattach(StyleRuleBase&) = 0;
 
-    void setParentStyleSheet(CSSStyleSheet* styleSheet)
-    {
-        m_parentIsRule = false;
-        m_parentStyleSheet = styleSheet;
-    }
-
-    void setParentRule(CSSRule* rule)
-    {
-        m_parentIsRule = true;
-        m_parentRule = rule;
-    }
-
-    CSSStyleSheet* parentStyleSheet() const
-    {
-        if (m_parentIsRule)
-            return m_parentRule ? m_parentRule->parentStyleSheet() : 0;
-        return m_parentStyleSheet;
-    }
-
-    CSSRule* parentRule() const { return m_parentIsRule ? m_parentRule : 0; }
+    void setParentStyleSheet(CSSStyleSheet*);
+    void setParentRule(CSSRule*);
+    CSSStyleSheet* parentStyleSheet() const;
+    CSSRule* parentRule() const { return m_parentIsRule ? m_parentRule : nullptr; }
 
     WEBCORE_EXPORT ExceptionOr<void> setCssText(const String&);
 
 protected:
-    CSSRule(CSSStyleSheet* parent)
-        : m_hasCachedSelectorText(false)
-        , m_parentIsRule(false)
-        , m_parentStyleSheet(parent)
-    {
-    }
+    explicit CSSRule(CSSStyleSheet*);
 
     bool hasCachedSelectorText() const { return m_hasCachedSelectorText; }
     void setHasCachedSelectorText(bool hasCachedSelectorText) const { m_hasCachedSelectorText = hasCachedSelectorText; }
@@ -101,13 +78,38 @@
 private:
     mutable unsigned char m_hasCachedSelectorText : 1;
     unsigned char m_parentIsRule : 1;
-
     union {
         CSSRule* m_parentRule;
         CSSStyleSheet* m_parentStyleSheet;
     };
 };
 
+inline CSSRule::CSSRule(CSSStyleSheet* parent)
+    : m_hasCachedSelectorText(false)
+    , m_parentIsRule(false)
+    , m_parentStyleSheet(parent)
+{
+}
+
+inline void CSSRule::setParentStyleSheet(CSSStyleSheet* styleSheet)
+{
+    m_parentIsRule = false;
+    m_parentStyleSheet = styleSheet;
+}
+
+inline void CSSRule::setParentRule(CSSRule* rule)
+{
+    m_parentIsRule = true;
+    m_parentRule = rule;
+}
+
+inline CSSStyleSheet* CSSRule::parentStyleSheet() const
+{
+    if (m_parentIsRule)
+        return m_parentRule ? m_parentRule->parentStyleSheet() : nullptr;
+    return m_parentStyleSheet;
+}
+
 } // namespace WebCore
 
 #define SPECIALIZE_TYPE_TRAITS_CSS_RULE(ToValueTypeName, predicate) \
diff --git a/Source/WebCore/css/CSSRule.idl b/Source/WebCore/css/CSSRule.idl
index 2d406ba..b50aa08 100644
--- a/Source/WebCore/css/CSSRule.idl
+++ b/Source/WebCore/css/CSSRule.idl
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2020 Apple Inc. All rights reserved.
  * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
@@ -21,11 +21,16 @@
 [
     CustomToJSObject,
     ExportToWrappedFunction,
+    Exposed=Window,
     GenerateIsReachable,
     JSCustomHeader,
     JSCustomMarkFunction,
 ] interface CSSRule {
-    // RuleType
+    attribute DOMString? cssText;
+    readonly attribute CSSRule? parentRule;
+    readonly attribute CSSStyleSheet? parentStyleSheet;
+
+    readonly attribute unsigned short type;
     const unsigned short UNKNOWN_RULE = 0;
     const unsigned short STYLE_RULE = 1;
     const unsigned short CHARSET_RULE = 2;
@@ -35,17 +40,11 @@
     const unsigned short PAGE_RULE = 6;
     const unsigned short KEYFRAMES_RULE = 7;
     const unsigned short KEYFRAME_RULE = 8;
+    const unsigned short MARGIN_RULE = 9;
     const unsigned short NAMESPACE_RULE = 10;
     const unsigned short SUPPORTS_RULE = 12;
 
     // Legacy synonyms for the above, kept to avoid breaking existing content.
     const unsigned short WEBKIT_KEYFRAMES_RULE = 7;
     const unsigned short WEBKIT_KEYFRAME_RULE = 8;
-
-    readonly attribute unsigned short type;
-
-    attribute DOMString? cssText;
-
-    readonly attribute CSSStyleSheet? parentStyleSheet;
-    readonly attribute CSSRule? parentRule;
 };
diff --git a/Source/WebCore/css/CSSStyleRule.idl b/Source/WebCore/css/CSSStyleRule.idl
index 5ba61ec..7179571 100644
--- a/Source/WebCore/css/CSSStyleRule.idl
+++ b/Source/WebCore/css/CSSStyleRule.idl
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2020 Apple Inc. All rights reserved.
  * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
@@ -18,10 +18,8 @@
  * Boston, MA 02110-1301, USA.
  */
 
-// Introduced in DOM Level 2:
+[Exposed=Window]
 interface CSSStyleRule : CSSRule {
     attribute DOMString? selectorText;
-
-    [PutForwards=cssText] readonly attribute CSSStyleDeclaration style;
+    [SameObject, PutForwards=cssText] readonly attribute CSSStyleDeclaration style;
 };
-
diff --git a/Source/WebCore/css/CSSStyleSheet.idl b/Source/WebCore/css/CSSStyleSheet.idl
index ffa3876..782f9e0 100644
--- a/Source/WebCore/css/CSSStyleSheet.idl
+++ b/Source/WebCore/css/CSSStyleSheet.idl
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2020 Apple Inc. All rights reserved.
  * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
@@ -18,17 +18,14 @@
  * Boston, MA 02110-1301, USA.
  */
 
+[Exposed=Window]
 interface CSSStyleSheet : StyleSheet {
     readonly attribute CSSRule ownerRule;
     readonly attribute CSSRuleList cssRules;
-
     [MayThrowException] unsigned long insertRule(DOMString rule, optional unsigned long index = 0);
-
     [MayThrowException] undefined deleteRule(unsigned long index);
 
     readonly attribute CSSRuleList rules;
-
-    // The following two operations are WebKit-specific.
     [MayThrowException] long addRule(optional DOMString selector = "undefined", optional DOMString style = "undefined", optional unsigned long index);
     [MayThrowException] undefined removeRule(optional unsigned long index = 0);
 };
diff --git a/Source/WebCore/css/CSSSupportsRule.cpp b/Source/WebCore/css/CSSSupportsRule.cpp
index e13e13b..fc1dad8 100644
--- a/Source/WebCore/css/CSSSupportsRule.cpp
+++ b/Source/WebCore/css/CSSSupportsRule.cpp
@@ -1,4 +1,6 @@
-/* Copyright (C) 2012 Motorola Mobility Inc. All rights reserved.
+/*
+ * Copyright (C) 2012 Motorola Mobility Inc. All rights reserved.
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -35,27 +37,33 @@
 
 namespace WebCore {
 
-CSSSupportsRule::CSSSupportsRule(StyleRuleSupports& supportsRule, CSSStyleSheet* parent)
-    : CSSGroupingRule(supportsRule, parent)
+CSSSupportsRule::CSSSupportsRule(StyleRuleSupports& rule, CSSStyleSheet* parent)
+    : CSSConditionRule(rule, parent)
 {
 }
 
+Ref<CSSSupportsRule> CSSSupportsRule::create(StyleRuleSupports& rule, CSSStyleSheet* parent)
+{
+    return adoptRef(*new CSSSupportsRule(rule, parent));
+}
+
 String CSSSupportsRule::cssText() const
 {
     StringBuilder result;
-
-    result.appendLiteral("@supports ");
-    result.append(conditionText());
-    result.appendLiteral(" {\n");
-    appendCssTextForItems(result);
+    result.append("@supports ", conditionText(), " {\n");
+    appendCSSTextForItems(result);
     result.append('}');
-
     return result.toString();
 }
 
 String CSSSupportsRule::conditionText() const
 {
-    return downcast<StyleRuleSupports>(m_groupRule.get()).conditionText();
+    return downcast<StyleRuleSupports>(groupRule()).conditionText();
+}
+
+void CSSSupportsRule::setConditionText(const String&)
+{
+    // FIXME: Not implemented yet.
 }
 
 } // namespace WebCore
diff --git a/Source/WebCore/css/CSSSupportsRule.h b/Source/WebCore/css/CSSSupportsRule.h
index fe83650..e6ce4f6 100644
--- a/Source/WebCore/css/CSSSupportsRule.h
+++ b/Source/WebCore/css/CSSSupportsRule.h
@@ -1,4 +1,6 @@
-/* Copyright (C) 2012 Motorola Mobility Inc. All rights reserved.
+/*
+ * Copyright (C) 2012 Motorola Mobility Inc. All rights reserved.
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -28,29 +30,23 @@
 
 #pragma once
 
-#include "CSSGroupingRule.h"
+#include "CSSConditionRule.h"
 
 namespace WebCore {
 
 class CSSRule;
 class StyleRuleSupports;
 
-class CSSSupportsRule final : public CSSGroupingRule {
+class CSSSupportsRule final : public CSSConditionRule {
 public:
-    static Ref<CSSSupportsRule> create(StyleRuleSupports& rule, CSSStyleSheet* sheet)
-    {
-        return adoptRef(*new CSSSupportsRule(rule, sheet));
-    }
-
-    virtual ~CSSSupportsRule() = default;
+    static Ref<CSSSupportsRule> create(StyleRuleSupports&, CSSStyleSheet* parent);
 
     String cssText() const final;
-
-    String conditionText() const;
+    String conditionText() const final;
+    void setConditionText(const String&) final;
 
 private:
     CSSSupportsRule(StyleRuleSupports&, CSSStyleSheet*);
-
     CSSRule::Type type() const final { return SUPPORTS_RULE; }
 };
 
diff --git a/Source/WebCore/css/CSSSupportsRule.idl b/Source/WebCore/css/CSSSupportsRule.idl
index faa2a451..a053c21 100644
--- a/Source/WebCore/css/CSSSupportsRule.idl
+++ b/Source/WebCore/css/CSSSupportsRule.idl
@@ -1,4 +1,6 @@
-/* Copyright (C) 2012 Motorola Mobility Inc. All rights reserved.
+/*
+ * Copyright (C) 2012 Motorola Mobility Inc. All rights reserved.
+ * Copyright (C) 2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
@@ -26,10 +28,6 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-interface CSSSupportsRule : CSSRule {
-    readonly attribute CSSRuleList cssRules;
-    readonly attribute DOMString conditionText;
-
-    [MayThrowException] unsigned long insertRule(DOMString rule, optional unsigned long index = 0);
-    [MayThrowException] undefined deleteRule(unsigned long index);
+[Exposed=Window]
+interface CSSSupportsRule : CSSConditionRule {
 };
diff --git a/Source/WebCore/css/MediaList.cpp b/Source/WebCore/css/MediaList.cpp
index 2112f40..b49df1d 100644
--- a/Source/WebCore/css/MediaList.cpp
+++ b/Source/WebCore/css/MediaList.cpp
@@ -1,6 +1,6 @@
 /*
  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
- * Copyright (C) 2004-2017 Apple Inc. All rights reserved.
+ * Copyright (C) 2004-2020 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -82,7 +82,7 @@
 bool MediaQuerySet::set(const String& mediaString)
 {
     auto result = create(mediaString);
-    m_queries.swap(result->m_queries);
+    m_queries = WTFMove(result->m_queries);
     return true;
 }
 
diff --git a/Source/WebCore/css/MediaList.idl b/Source/WebCore/css/MediaList.idl
index 4741836..fec82b1 100644
--- a/Source/WebCore/css/MediaList.idl
+++ b/Source/WebCore/css/MediaList.idl
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2020 Apple Inc. All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -25,11 +25,12 @@
 
 [
     ExportToWrappedFunction,
+    Exposed=Window,
     GenerateIsReachable,
     ImplementationLacksVTable,
     JSCustomHeader,
 ] interface MediaList {
-    attribute [LegacyNullToEmptyString] DOMString mediaText;
+    stringifier attribute [LegacyNullToEmptyString] DOMString mediaText;
     readonly attribute unsigned long length;
 
     getter DOMString? item(unsigned long index);
diff --git a/Source/WebCore/css/StyleRule.cpp b/Source/WebCore/css/StyleRule.cpp
index ab53273..c83ca82 100644
--- a/Source/WebCore/css/StyleRule.cpp
+++ b/Source/WebCore/css/StyleRule.cpp
@@ -1,7 +1,7 @@
 /*
  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
  * (C) 2002-2003 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2002, 2005, 2006, 2008, 2012 Apple Inc. All rights reserved.
+ * Copyright (C) 2002-2020 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -187,6 +187,16 @@
 
 StyleRule::~StyleRule() = default;
 
+Ref<StyleRule> StyleRule::create(Ref<StylePropertiesBase>&& properties, bool hasDocumentSecurityOrigin, CSSSelectorList&& selectors)
+{
+    return adoptRef(*new StyleRule(WTFMove(properties), hasDocumentSecurityOrigin, WTFMove(selectors)));
+}
+
+Ref<StyleRule> StyleRule::copy() const
+{
+    return adoptRef(*new StyleRule(*this));
+}
+
 const StyleProperties& StyleRule::properties() const
 {
     if (m_properties->type() == DeferredPropertiesType)
@@ -253,6 +263,11 @@
 
 StyleRulePage::~StyleRulePage() = default;
 
+Ref<StyleRulePage> StyleRulePage::create(Ref<StyleProperties>&& properties, CSSSelectorList&& selectors)
+{
+    return adoptRef(*new StyleRulePage(WTFMove(properties), WTFMove(selectors)));
+}
+
 MutableStyleProperties& StyleRulePage::mutableProperties()
 {
     if (!is<MutableStyleProperties>(m_properties.get()))
@@ -299,15 +314,15 @@
     m_parser->parseKeyframeList(m_tokens, keyframesRule);
 }
     
-StyleRuleGroup::StyleRuleGroup(StyleRuleType type, Vector<RefPtr<StyleRuleBase>>& adoptRule)
+StyleRuleGroup::StyleRuleGroup(StyleRuleType type, Vector<RefPtr<StyleRuleBase>>&& rules)
     : StyleRuleBase(type)
+    , m_childRules(WTFMove(rules))
 {
-    m_childRules.swap(adoptRule);
 }
 
-StyleRuleGroup::StyleRuleGroup(StyleRuleType type, std::unique_ptr<DeferredStyleGroupRuleList>&& deferredRules)
+StyleRuleGroup::StyleRuleGroup(StyleRuleType type, std::unique_ptr<DeferredStyleGroupRuleList>&& rules)
     : StyleRuleBase(type)
-    , m_deferredRules(WTFMove(deferredRules))
+    , m_deferredRules(WTFMove(rules))
 {
 }
 
@@ -346,35 +361,48 @@
     m_deferredRules = nullptr;
 }
     
-StyleRuleMedia::StyleRuleMedia(Ref<MediaQuerySet>&& media, Vector<RefPtr<StyleRuleBase>>& adoptRules)
-    : StyleRuleGroup(StyleRuleType::Media, adoptRules)
+StyleRuleMedia::StyleRuleMedia(Ref<MediaQuerySet>&& media, Vector<RefPtr<StyleRuleBase>>&& rules)
+    : StyleRuleGroup(StyleRuleType::Media, WTFMove(rules))
     , m_mediaQueries(WTFMove(media))
 {
 }
 
-StyleRuleMedia::StyleRuleMedia(Ref<MediaQuerySet>&& media, std::unique_ptr<DeferredStyleGroupRuleList>&& deferredRules)
-    : StyleRuleGroup(StyleRuleType::Media, WTFMove(deferredRules))
+StyleRuleMedia::StyleRuleMedia(Ref<MediaQuerySet>&& media, std::unique_ptr<DeferredStyleGroupRuleList>&& rules)
+    : StyleRuleGroup(StyleRuleType::Media, WTFMove(rules))
     , m_mediaQueries(WTFMove(media))
 {
 }
 
-StyleRuleMedia::StyleRuleMedia(const StyleRuleMedia& o)
-    : StyleRuleGroup(o)
+StyleRuleMedia::StyleRuleMedia(const StyleRuleMedia& other)
+    : StyleRuleGroup(other)
+    , m_mediaQueries(other.m_mediaQueries->copy())
 {
-    if (o.m_mediaQueries)
-        m_mediaQueries = o.m_mediaQueries->copy();
 }
 
+Ref<StyleRuleMedia> StyleRuleMedia::create(Ref<MediaQuerySet>&& media, Vector<RefPtr<StyleRuleBase>>&& rules)
+{
+    return adoptRef(*new StyleRuleMedia(WTFMove(media), WTFMove(rules)));
+}
 
-StyleRuleSupports::StyleRuleSupports(const String& conditionText, bool conditionIsSupported, Vector<RefPtr<StyleRuleBase>>& adoptRules)
-    : StyleRuleGroup(StyleRuleType::Supports, adoptRules)
+Ref<StyleRuleMedia> StyleRuleMedia::create(Ref<MediaQuerySet>&& media, std::unique_ptr<DeferredStyleGroupRuleList>&& deferredChildRules)
+{
+    return adoptRef(*new StyleRuleMedia(WTFMove(media), WTFMove(deferredChildRules)));
+}
+
+Ref<StyleRuleMedia> StyleRuleMedia::copy() const
+{
+    return adoptRef(*new StyleRuleMedia(*this));
+}
+
+StyleRuleSupports::StyleRuleSupports(const String& conditionText, bool conditionIsSupported, Vector<RefPtr<StyleRuleBase>>&& rules)
+    : StyleRuleGroup(StyleRuleType::Supports, WTFMove(rules))
     , m_conditionText(conditionText)
     , m_conditionIsSupported(conditionIsSupported)
 {
 }
 
-StyleRuleSupports::StyleRuleSupports(const String& conditionText, bool conditionIsSupported, std::unique_ptr<DeferredStyleGroupRuleList>&& deferredRules)
-    : StyleRuleGroup(StyleRuleType::Supports, WTFMove(deferredRules))
+StyleRuleSupports::StyleRuleSupports(const String& conditionText, bool conditionIsSupported, std::unique_ptr<DeferredStyleGroupRuleList>&& rules)
+    : StyleRuleGroup(StyleRuleType::Supports, WTFMove(rules))
     , m_conditionText(conditionText)
     , m_conditionIsSupported(conditionIsSupported)
 {
@@ -387,6 +415,16 @@
 {
 }
 
+Ref<StyleRuleSupports> StyleRuleSupports::create(const String& conditionText, bool conditionIsSupported, Vector<RefPtr<StyleRuleBase>>&& rules)
+{
+    return adoptRef(*new StyleRuleSupports(conditionText, conditionIsSupported, WTFMove(rules)));
+}
+
+Ref<StyleRuleSupports> StyleRuleSupports::create(const String& conditionText, bool conditionIsSupported, std::unique_ptr<DeferredStyleGroupRuleList>&& rules)
+{
+    return adoptRef(*new StyleRuleSupports(conditionText, conditionIsSupported, WTFMove(rules)));
+}
+
 StyleRuleCharset::StyleRuleCharset()
     : StyleRuleBase(StyleRuleType::Charset)
 {
@@ -397,9 +435,7 @@
 {
 }
 
-StyleRuleCharset::~StyleRuleCharset() = default;
-
-StyleRuleNamespace::StyleRuleNamespace(AtomString prefix, AtomString uri)
+StyleRuleNamespace::StyleRuleNamespace(const AtomString& prefix, const AtomString& uri)
     : StyleRuleBase(StyleRuleType::Namespace)
     , m_prefix(prefix)
     , m_uri(uri)
@@ -415,4 +451,9 @@
 
 StyleRuleNamespace::~StyleRuleNamespace() = default;
 
+Ref<StyleRuleNamespace> StyleRuleNamespace::create(const AtomString& prefix, const AtomString& uri)
+{
+    return adoptRef(*new StyleRuleNamespace(prefix, uri));
+}
+
 } // namespace WebCore
diff --git a/Source/WebCore/css/StyleRule.h b/Source/WebCore/css/StyleRule.h
index b0999b5..08a7875 100644
--- a/Source/WebCore/css/StyleRule.h
+++ b/Source/WebCore/css/StyleRule.h
@@ -1,7 +1,7 @@
 /*
  * (C) 1999-2003 Lars Knoll (knoll@kde.org)
  * (C) 2002-2003 Dirk Mueller (mueller@kde.org)
- * Copyright (C) 2002, 2006, 2008, 2012, 2013 Apple Inc. All rights reserved.
+ * Copyright (C) 2002-2020 Apple Inc. All rights reserved.
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
@@ -59,30 +59,15 @@
 
     Ref<StyleRuleBase> copy() const;
 
-    void deref() const
-    {
-        if (derefBase())
-            const_cast<StyleRuleBase&>(*this).destroy();
-    }
+    void deref() const;
 
     // FIXME: There shouldn't be any need for the null parent version.
     Ref<CSSRule> createCSSOMWrapper(CSSStyleSheet* parentSheet = nullptr) const;
     Ref<CSSRule> createCSSOMWrapper(CSSRule* parentRule) const;
 
 protected:
-    StyleRuleBase(StyleRuleType type, bool hasDocumentSecurityOrigin = false)
-        : m_type(static_cast<unsigned>(type))
-        , m_hasDocumentSecurityOrigin(hasDocumentSecurityOrigin)
-    {
-    }
-
-    StyleRuleBase(const StyleRuleBase& o)
-        : WTF::RefCountedBase()
-        , m_type(o.m_type)
-        , m_hasDocumentSecurityOrigin(o.m_hasDocumentSecurityOrigin)
-    {
-    }
-
+    explicit StyleRuleBase(StyleRuleType, bool hasDocumentSecurityOrigin = false);
+    StyleRuleBase(const StyleRuleBase&);
     ~StyleRuleBase() = default;
 
     bool hasDocumentSecurityOrigin() const { return m_hasDocumentSecurityOrigin; }
@@ -101,44 +86,25 @@
 class StyleRule final : public StyleRuleBase {
     WTF_MAKE_STRUCT_FAST_ALLOCATED_WITH_HEAP_IDENTIFIER(StyleRule);
 public:
-    static Ref<StyleRule> create(Ref<StylePropertiesBase>&& properties, bool hasDocumentSecurityOrigin, CSSSelectorList&& selectors)
-    {
-        return adoptRef(*new StyleRule(WTFMove(properties), hasDocumentSecurityOrigin, WTFMove(selectors)));
-    }
-    
+    static Ref<StyleRule> create(Ref<StylePropertiesBase>&&, bool hasDocumentSecurityOrigin, CSSSelectorList&&);
+    Ref<StyleRule> copy() const;
     ~StyleRule();
 
     const CSSSelectorList& selectorList() const { return m_selectorList; }
-    
+
     const StyleProperties& properties() const;
     MutableStyleProperties& mutableProperties();
     const StyleProperties* propertiesWithoutDeferredParsing() const;
 
     using StyleRuleBase::hasDocumentSecurityOrigin;
 
-    void wrapperAdoptSelectorList(CSSSelectorList&& selectors)
-    {
-        m_selectorList = WTFMove(selectors);
-#if ENABLE(CSS_SELECTOR_JIT)
-        m_compiledSelectors = nullptr;
-#endif
-    }
-
-    Ref<StyleRule> copy() const { return adoptRef(*new StyleRule(*this)); }
+    void wrapperAdoptSelectorList(CSSSelectorList&&);
 
     Vector<RefPtr<StyleRule>> splitIntoMultipleRulesWithMaximumSelectorComponentCount(unsigned) const;
 
 #if ENABLE(CSS_SELECTOR_JIT)
-    CompiledSelector& compiledSelectorForListIndex(unsigned index) const
-    {
-        if (!m_compiledSelectors)
-            m_compiledSelectors = makeUniqueArray<CompiledSelector>(m_selectorList.listSize());
-        return m_compiledSelectors[index];
-    }
-    void releaseCompiledSelectors() const
-    {
-        m_compiledSelectors = nullptr;
-    }
+    CompiledSelector& compiledSelectorForListIndex(unsigned index) const;
+    void releaseCompiledSelectors() const { m_compiledSelectors = nullptr; }
 #endif
 
     static unsigned averageSizeInBytes();
@@ -157,11 +123,6 @@
 #endif
 };
 
-inline const StyleProperties* StyleRule::propertiesWithoutDeferredParsing() const
-{
-    return m_properties->type() != DeferredPropertiesType ? &downcast<StyleProperties>(m_properties.get()) : nullptr;
-}
-
 class StyleRuleFontFace final : public StyleRuleBase {
 public:
     static Ref<StyleRuleFontFace> create(Ref<StyleProperties>&& properties) { return adoptRef(*new StyleRuleFontFace(WTFMove(properties))); }
@@ -182,7 +143,7 @@
 
 class StyleRulePage final : public StyleRuleBase {
 public:
-    static Ref<StyleRulePage> create(Ref<StyleProperties>&& properties, CSSSelectorList&& selectors) { return adoptRef(*new StyleRulePage(WTFMove(properties), WTFMove(selectors))); }
+    static Ref<StyleRulePage> create(Ref<StyleProperties>&&, CSSSelectorList&&);
 
     ~StyleRulePage();
 
@@ -224,7 +185,7 @@
     void wrapperRemoveRule(unsigned);
     
 protected:
-    StyleRuleGroup(StyleRuleType, Vector<RefPtr<StyleRuleBase>>&);
+    StyleRuleGroup(StyleRuleType, Vector<RefPtr<StyleRuleBase>>&&);
     StyleRuleGroup(StyleRuleType, std::unique_ptr<DeferredStyleGroupRuleList>&&);
     StyleRuleGroup(const StyleRuleGroup&);
     
@@ -235,55 +196,34 @@
     mutable std::unique_ptr<DeferredStyleGroupRuleList> m_deferredRules;
 };
 
-inline const Vector<RefPtr<StyleRuleBase>>* StyleRuleGroup::childRulesWithoutDeferredParsing() const
-{
-    return !m_deferredRules ? &m_childRules : nullptr;
-}
-
 class StyleRuleMedia final : public StyleRuleGroup {
 public:
-    static Ref<StyleRuleMedia> create(Ref<MediaQuerySet>&& media, Vector<RefPtr<StyleRuleBase>>& adoptRules)
-    {
-        return adoptRef(*new StyleRuleMedia(WTFMove(media), adoptRules));
-    }
+    static Ref<StyleRuleMedia> create(Ref<MediaQuerySet>&&, Vector<RefPtr<StyleRuleBase>>&&);
+    static Ref<StyleRuleMedia> create(Ref<MediaQuerySet>&&, std::unique_ptr<DeferredStyleGroupRuleList>&&);
+    Ref<StyleRuleMedia> copy() const;
 
-    static Ref<StyleRuleMedia> create(Ref<MediaQuerySet>&& media, std::unique_ptr<DeferredStyleGroupRuleList>&& deferredChildRules)
-    {
-        return adoptRef(*new StyleRuleMedia(WTFMove(media), WTFMove(deferredChildRules)));
-    }
-
-    MediaQuerySet* mediaQueries() const { return m_mediaQueries.get(); }
-
-    Ref<StyleRuleMedia> copy() const { return adoptRef(*new StyleRuleMedia(*this)); }
+    MediaQuerySet& mediaQueries() const { return m_mediaQueries; }
 
 private:
-    StyleRuleMedia(Ref<MediaQuerySet>&&, Vector<RefPtr<StyleRuleBase>>& adoptRules);
+    StyleRuleMedia(Ref<MediaQuerySet>&&, Vector<RefPtr<StyleRuleBase>>&&);
     StyleRuleMedia(Ref<MediaQuerySet>&&, std::unique_ptr<DeferredStyleGroupRuleList>&&);
     StyleRuleMedia(const StyleRuleMedia&);
 
-    RefPtr<MediaQuerySet> m_mediaQueries;
+    Ref<MediaQuerySet> m_mediaQueries;
 };
 
 class StyleRuleSupports final : public StyleRuleGroup {
 public:
-    static Ref<StyleRuleSupports> create(const String& conditionText, bool conditionIsSupported, Vector<RefPtr<StyleRuleBase>>& adoptRules)
-    {
-        return adoptRef(*new StyleRuleSupports(conditionText, conditionIsSupported, adoptRules));
-    }
-    
-    static Ref<StyleRuleSupports> create(const String& conditionText, bool conditionIsSupported, std::unique_ptr<DeferredStyleGroupRuleList>&& deferredChildRules)
-    {
-        return adoptRef(*new StyleRuleSupports(conditionText, conditionIsSupported, WTFMove(deferredChildRules)));
-    }
+    static Ref<StyleRuleSupports> create(const String& conditionText, bool conditionIsSupported, Vector<RefPtr<StyleRuleBase>>&&);
+    static Ref<StyleRuleSupports> create(const String& conditionText, bool conditionIsSupported, std::unique_ptr<DeferredStyleGroupRuleList>&&);
+    Ref<StyleRuleSupports> copy() const { return adoptRef(*new StyleRuleSupports(*this)); }
 
     String conditionText() const { return m_conditionText; }
     bool conditionIsSupported() const { return m_conditionIsSupported; }
-    Ref<StyleRuleSupports> copy() const { return adoptRef(*new StyleRuleSupports(*this)); }
 
 private:
-    StyleRuleSupports(const String& conditionText, bool conditionIsSupported, Vector<RefPtr<StyleRuleBase>>& adoptRules);
+    StyleRuleSupports(const String& conditionText, bool conditionIsSupported, Vector<RefPtr<StyleRuleBase>>&&);
     StyleRuleSupports(const String& conditionText, bool conditionIsSupported, std::unique_ptr<DeferredStyleGroupRuleList>&&);
-    
     StyleRuleSupports(const StyleRuleSupports&);
 
     String m_conditionText;
@@ -293,23 +233,17 @@
 // This is only used by the CSS parser.
 class StyleRuleCharset final : public StyleRuleBase {
 public:
-    static Ref<StyleRuleCharset> create() { return adoptRef(*new StyleRuleCharset()); }
-    
-    ~StyleRuleCharset();
-    
+    static Ref<StyleRuleCharset> create() { return adoptRef(*new StyleRuleCharset); }
     Ref<StyleRuleCharset> copy() const { return adoptRef(*new StyleRuleCharset(*this)); }
 
 private:
-    explicit StyleRuleCharset();
+    StyleRuleCharset();
     StyleRuleCharset(const StyleRuleCharset&);
 };
 
 class StyleRuleNamespace final : public StyleRuleBase {
 public:
-    static Ref<StyleRuleNamespace> create(AtomString prefix, AtomString uri)
-    {
-        return adoptRef(*new StyleRuleNamespace(prefix, uri));
-    }
+    static Ref<StyleRuleNamespace> create(const AtomString& prefix, const AtomString& uri);
     
     ~StyleRuleNamespace();
 
@@ -319,13 +253,61 @@
     AtomString uri() const { return m_uri; }
 
 private:
-    StyleRuleNamespace(AtomString prefix, AtomString uri);
+    StyleRuleNamespace(const AtomString& prefix, const AtomString& uri);
     StyleRuleNamespace(const StyleRuleNamespace&);
-    
+
     AtomString m_prefix;
     AtomString m_uri;
 };
     
+inline StyleRuleBase::StyleRuleBase(StyleRuleType type, bool hasDocumentSecurityOrigin)
+    : m_type(static_cast<unsigned>(type))
+    , m_hasDocumentSecurityOrigin(hasDocumentSecurityOrigin)
+{
+}
+
+inline StyleRuleBase::StyleRuleBase(const StyleRuleBase& o)
+    : WTF::RefCountedBase()
+    , m_type(o.m_type)
+    , m_hasDocumentSecurityOrigin(o.m_hasDocumentSecurityOrigin)
+{
+}
+
+inline void StyleRuleBase::deref() const
+{
+    if (derefBase())
+        const_cast<StyleRuleBase&>(*this).destroy();
+}
+
+inline void StyleRule::wrapperAdoptSelectorList(CSSSelectorList&& selectors)
+{
+    m_selectorList = WTFMove(selectors);
+#if ENABLE(CSS_SELECTOR_JIT)
+    m_compiledSelectors = nullptr;
+#endif
+}
+
+#if ENABLE(CSS_SELECTOR_JIT)
+
+inline CompiledSelector& StyleRule::compiledSelectorForListIndex(unsigned index) const
+{
+    if (!m_compiledSelectors)
+        m_compiledSelectors = makeUniqueArray<CompiledSelector>(m_selectorList.listSize());
+    return m_compiledSelectors[index];
+}
+
+#endif
+
+inline const StyleProperties* StyleRule::propertiesWithoutDeferredParsing() const
+{
+    return m_properties->type() != DeferredPropertiesType ? &downcast<StyleProperties>(m_properties.get()) : nullptr;
+}
+
+inline const Vector<RefPtr<StyleRuleBase>>* StyleRuleGroup::childRulesWithoutDeferredParsing() const
+{
+    return !m_deferredRules ? &m_childRules : nullptr;
+}
+
 } // namespace WebCore
 
 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::StyleRule)
@@ -353,10 +335,9 @@
 SPECIALIZE_TYPE_TRAITS_END()
 
 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::StyleRuleKeyframe)
-static bool isType(const WebCore::StyleRuleBase& rule) { return rule.isKeyframeRule(); }
+    static bool isType(const WebCore::StyleRuleBase& rule) { return rule.isKeyframeRule(); }
 SPECIALIZE_TYPE_TRAITS_END()
 
 SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::StyleRuleCharset)
-static bool isType(const WebCore::StyleRuleBase& rule) { return rule.isCharsetRule(); }
+    static bool isType(const WebCore::StyleRuleBase& rule) { return rule.isCharsetRule(); }
 SPECIALIZE_TYPE_TRAITS_END()
-
diff --git a/Source/WebCore/css/StyleSheet.idl b/Source/WebCore/css/StyleSheet.idl
index 023850b..9ddebd8 100644
--- a/Source/WebCore/css/StyleSheet.idl
+++ b/Source/WebCore/css/StyleSheet.idl
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2020 Apple Inc. All rights reserved.
  * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
@@ -21,6 +21,7 @@
 [
     CustomToJSObject,
     ExportToWrappedFunction,
+    Exposed=Window,
     GenerateIsReachable,
     JSCustomHeader,
     JSCustomMarkFunction,
@@ -31,5 +32,5 @@
     readonly attribute StyleSheet parentStyleSheet;
     readonly attribute DOMString? href;
     readonly attribute DOMString? title;
-    readonly attribute MediaList media;
+    [SameObject, PutForwards=mediaText] readonly attribute MediaList media;
 };
diff --git a/Source/WebCore/css/StyleSheetContents.cpp b/Source/WebCore/css/StyleSheetContents.cpp
index 98b8dcf..d358b3b 100644
--- a/Source/WebCore/css/StyleSheetContents.cpp
+++ b/Source/WebCore/css/StyleSheetContents.cpp
@@ -152,7 +152,7 @@
     }
 
     if (is<StyleRuleMedia>(rule))
-        reportMediaQueryWarningIfNeeded(singleOwnerDocument(), downcast<StyleRuleMedia>(rule.get()).mediaQueries());
+        reportMediaQueryWarningIfNeeded(singleOwnerDocument(), &downcast<StyleRuleMedia>(rule.get()).mediaQueries());
 
     // NOTE: The selector list has to fit into RuleData. <http://webkit.org/b/118369>
     // If we're adding a rule with a huge number of selectors, split it up into multiple rules
diff --git a/Source/WebCore/css/StyleSheetList.idl b/Source/WebCore/css/StyleSheetList.idl
index 1139d31..87919f2 100644
--- a/Source/WebCore/css/StyleSheetList.idl
+++ b/Source/WebCore/css/StyleSheetList.idl
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2006-2020 Apple Inc. All rights reserved.
  * Copyright (C) 2006 Samuel Weinig <sam.weinig@gmail.com>
  *
  * This library is free software; you can redistribute it and/or
@@ -20,6 +20,7 @@
 
 [
     ExportToWrappedFunction,
+    Exposed=Window,
     GenerateIsReachable=ImplOwnerNodeRoot,
     ImplementationLacksVTable,
 ] interface StyleSheetList {
diff --git a/Source/WebCore/css/parser/CSSParserImpl.cpp b/Source/WebCore/css/parser/CSSParserImpl.cpp
index 60348bd..3147846 100644
--- a/Source/WebCore/css/parser/CSSParserImpl.cpp
+++ b/Source/WebCore/css/parser/CSSParserImpl.cpp
@@ -550,12 +550,12 @@
     if (m_observerWrapper)
         m_observerWrapper->observer().endRuleBody(m_observerWrapper->endOffset(block));
 
-    return StyleRuleMedia::create(MediaQueryParser::parseMediaQuerySet(prelude, MediaQueryParserContext(m_context)).releaseNonNull(), rules);
+    return StyleRuleMedia::create(MediaQueryParser::parseMediaQuerySet(prelude, MediaQueryParserContext(m_context)).releaseNonNull(), WTFMove(rules));
 }
 
 RefPtr<StyleRuleSupports> CSSParserImpl::consumeSupportsRule(CSSParserTokenRange prelude, CSSParserTokenRange block)
 {
-    CSSSupportsParser::SupportsResult supported = CSSSupportsParser::supportsCondition(prelude, *this, CSSSupportsParser::ForAtRule);
+    auto supported = CSSSupportsParser::supportsCondition(prelude, *this, CSSSupportsParser::ForAtRule);
     if (supported == CSSSupportsParser::Invalid)
         return nullptr; // Parse error, invalid @supports condition
 
@@ -577,7 +577,7 @@
     if (m_observerWrapper)
         m_observerWrapper->observer().endRuleBody(m_observerWrapper->endOffset(block));
 
-    return StyleRuleSupports::create(prelude.serialize().stripWhiteSpace(), supported, rules);
+    return StyleRuleSupports::create(prelude.serialize().stripWhiteSpace(), supported, WTFMove(rules));
 }
 
 RefPtr<StyleRuleFontFace> CSSParserImpl::consumeFontFaceRule(CSSParserTokenRange prelude, CSSParserTokenRange block)