Skip to content
Permalink
Browse files
Consider making CSSStyleSheet::rules() just an alias of CSSStyleSheet…
…::cssRules().

https://bugs.webkit.org/show_bug.cgi?id=197725

Patch by Tyler Wilcock <twilco.o@protonmail.com> on 2021-04-17
Reviewed by Darin Adler.

LayoutTests/imported/w3c:

To match other browsers and the below WPT, CSSStyleSheet.rules now aliases
CSSStyleSheet.cssRulesForBindings, meaning we pass two more tests.

* web-platform-tests/css/cssom/CSSStyleSheet-expected.txt:

Source/WebCore:

To match other browsers (Blink and Gecko) and pass a WPT, CSSStyleSheet.rules now aliases
CSSStyleSheet.cssRulesForBindings.  CSSStyleSheet.rulesForBindings is deleted.

Tested by
imported/w3c/web-platform-tests/css/cssom/CSSStyleSheet.html.

* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::rulesForBindings): Deleted.
(WebCore::CSSStyleSheet::rules): Deleted.

* css/CSSStyleSheet.h:
Change `rules()` to be an inlined alias for `cssRulesForBindings()`.

* css/CSSStyleSheet.idl:
Remove [ImplementedAs=rulesForBindings], as this function has been
deleted.

Source/WebKit:

CSSStyleSheet.rules has been changed to alias CSSStyleSheet.cssRulesForBindings.  Now,
to access just the CSSRuleList, CSSStyleSheet.cssRules must be called.

* WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMCSSStyleSheet.cpp:
(webkit_dom_css_style_sheet_get_rules):
Use CSSStyleSheet.cssRules instead of CSSStyleSheet.rules (deleted
with this patch) to get access to the CSSRuleList of this
stylesheet.

Source/WebKitLegacy/mac:

CSSStyleSheet.rules has been changed to alias CSSStyleSheet.cssRulesForBindings.  Now,
to access just the CSSRuleList, CSSStyleSheet.cssRules must be called.

* DOM/DOMCSSStyleSheet.mm:
(-[DOMCSSStyleSheet rules]):
Update this function to call IMPL->cssRules instead of IMPL->rules.

Canonical link: https://commits.webkit.org/236691@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@276209 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
twilco authored and webkit-commit-queue committed Apr 17, 2021
1 parent dad086a commit 9529e0642e661ef76bfb5bd72abb3efed37f945a
Showing 10 changed files with 76 additions and 29 deletions.
@@ -1,3 +1,15 @@
2021-04-17 Tyler Wilcock <twilco.o@protonmail.com>

Consider making CSSStyleSheet::rules() just an alias of CSSStyleSheet::cssRules().
https://bugs.webkit.org/show_bug.cgi?id=197725

Reviewed by Darin Adler.

To match other browsers and the below WPT, CSSStyleSheet.rules now aliases
CSSStyleSheet.cssRulesForBindings, meaning we pass two more tests.

* web-platform-tests/css/cssom/CSSStyleSheet-expected.txt:

2021-04-17 Tim Nguyen <ntim@apple.com>

Don't omit conic gradient starting angle when serializing when starting angle is under 0
@@ -13,7 +13,7 @@ PASS removeRule(1)
PASS addRule with #foo selectors
PASS addRule with no argument adds "undefined" selector
PASS addRule with index greater than length throws
FAIL cssRules and rules are the same object assert_equals: expected object "[object CSSRuleList]" but got object "[object CSSRuleList]"
PASS cssRules and rules are the same object
PASS cssRules returns the same object twice
FAIL rules returns the same object twice assert_equals: expected object "[object CSSRuleList]" but got object "[object CSSRuleList]"
PASS rules returns the same object twice

@@ -1,3 +1,27 @@
2021-04-17 Tyler Wilcock <twilco.o@protonmail.com>

Consider making CSSStyleSheet::rules() just an alias of CSSStyleSheet::cssRules().
https://bugs.webkit.org/show_bug.cgi?id=197725

Reviewed by Darin Adler.

To match other browsers (Blink and Gecko) and pass a WPT, CSSStyleSheet.rules now aliases
CSSStyleSheet.cssRulesForBindings. CSSStyleSheet.rulesForBindings is deleted.

Tested by
imported/w3c/web-platform-tests/css/cssom/CSSStyleSheet.html.

* css/CSSStyleSheet.cpp:
(WebCore::CSSStyleSheet::rulesForBindings): Deleted.
(WebCore::CSSStyleSheet::rules): Deleted.

* css/CSSStyleSheet.h:
Change `rules()` to be an inlined alias for `cssRulesForBindings()`.

* css/CSSStyleSheet.idl:
Remove [ImplementedAs=rulesForBindings], as this function has been
deleted.

2021-04-17 Tyler Wilcock <twilco.o@protonmail.com>

Media queries with max-width greater than 999999999px evaluate to false
@@ -254,26 +254,6 @@ bool CSSStyleSheet::canAccessRules() const
return document->securityOrigin().canRequest(baseURL);
}

ExceptionOr<Ref<CSSRuleList>> CSSStyleSheet::rulesForBindings()
{
auto rules = this->rules();
if (!rules)
return Exception { SecurityError, "Not allowed to access cross-origin stylesheet"_s };
return rules.releaseNonNull();
}

RefPtr<CSSRuleList> CSSStyleSheet::rules()
{
if (!canAccessRules())
return nullptr;
// IE behavior.
auto ruleList = StaticCSSRuleList::create();
unsigned ruleCount = length();
for (unsigned i = 0; i < ruleCount; ++i)
ruleList->rules().append(item(i));
return ruleList;
}

ExceptionOr<unsigned> CSSStyleSheet::insertRule(const String& ruleString, unsigned index)
{
ASSERT(m_childRuleCSSOMWrappers.isEmpty() || m_childRuleCSSOMWrappers.size() == m_contents->ruleCount());
@@ -20,6 +20,7 @@

#pragma once

#include "CSSRuleList.h"
#include "ExceptionOr.h"
#include "StyleSheet.h"
#include <memory>
@@ -33,7 +34,6 @@ namespace WebCore {
class CSSImportRule;
class CSSParser;
class CSSRule;
class CSSRuleList;
class CSSStyleSheet;
class CachedCSSStyleSheet;
class Document;
@@ -62,14 +62,13 @@ class CSSStyleSheet final : public StyleSheet {
bool disabled() const final { return m_isDisabled; }
void setDisabled(bool) final;

WEBCORE_EXPORT RefPtr<CSSRuleList> cssRules();
ExceptionOr<Ref<CSSRuleList>> cssRulesForBindings();
ExceptionOr<Ref<CSSRuleList>> rulesForBindings();
ExceptionOr<Ref<CSSRuleList>> rules() { return this->cssRulesForBindings(); }

WEBCORE_EXPORT RefPtr<CSSRuleList> cssRules();
WEBCORE_EXPORT ExceptionOr<unsigned> insertRule(const String& rule, unsigned index);
WEBCORE_EXPORT ExceptionOr<void> deleteRule(unsigned index);

WEBCORE_EXPORT RefPtr<CSSRuleList> rules();
WEBCORE_EXPORT ExceptionOr<int> addRule(const String& selector, const String& style, Optional<unsigned> index);
ExceptionOr<void> removeRule(unsigned index) { return deleteRule(index); }

@@ -26,7 +26,7 @@
unsigned long insertRule(DOMString rule, optional unsigned long index = 0);
undefined deleteRule(unsigned long index);

[ImplementedAs=rulesForBindings] readonly attribute CSSRuleList rules;
readonly attribute CSSRuleList rules;
long addRule(optional DOMString selector = "undefined", optional DOMString style = "undefined", optional unsigned long index);
undefined removeRule(optional unsigned long index = 0);
};
@@ -1,3 +1,19 @@
2021-04-17 Tyler Wilcock <twilco.o@protonmail.com>

Consider making CSSStyleSheet::rules() just an alias of CSSStyleSheet::cssRules().
https://bugs.webkit.org/show_bug.cgi?id=197725

Reviewed by Darin Adler.

CSSStyleSheet.rules has been changed to alias CSSStyleSheet.cssRulesForBindings. Now,
to access just the CSSRuleList, CSSStyleSheet.cssRules must be called.

* WebProcess/InjectedBundle/API/gtk/DOM/WebKitDOMCSSStyleSheet.cpp:
(webkit_dom_css_style_sheet_get_rules):
Use CSSStyleSheet.cssRules instead of CSSStyleSheet.rules (deleted
with this patch) to get access to the CSSRuleList of this
stylesheet.

2021-04-17 Sam Weinig <weinig@apple.com>

Move RuntimeEnabledFeatures to Settings (Part 1)
@@ -212,7 +212,7 @@ WebKitDOMCSSRuleList* webkit_dom_css_style_sheet_get_rules(WebKitDOMCSSStyleShee
WebCore::JSMainThreadNullState state;
g_return_val_if_fail(WEBKIT_DOM_IS_CSS_STYLE_SHEET(self), 0);
WebCore::CSSStyleSheet* item = WebKit::core(self);
RefPtr<WebCore::CSSRuleList> gobjectResult = WTF::getPtr(item->rules());
RefPtr<WebCore::CSSRuleList> gobjectResult = WTF::getPtr(item->cssRules());
return WebKit::kit(gobjectResult.get());
}

@@ -1,3 +1,17 @@
2021-04-17 Tyler Wilcock <twilco.o@protonmail.com>

Consider making CSSStyleSheet::rules() just an alias of CSSStyleSheet::cssRules().
https://bugs.webkit.org/show_bug.cgi?id=197725

Reviewed by Darin Adler.

CSSStyleSheet.rules has been changed to alias CSSStyleSheet.cssRulesForBindings. Now,
to access just the CSSRuleList, CSSStyleSheet.cssRules must be called.

* DOM/DOMCSSStyleSheet.mm:
(-[DOMCSSStyleSheet rules]):
Update this function to call IMPL->cssRules instead of IMPL->rules.

2021-04-16 Ryosuke Niwa <rniwa@webkit.org>

Deploy Ref/RefPtr in Editor
@@ -59,7 +59,9 @@ - (DOMCSSRuleList *)cssRules
- (DOMCSSRuleList *)rules
{
WebCore::JSMainThreadNullState state;
return kit(WTF::getPtr(IMPL->rules()));
// Calling IMPL->cssRules (not IMPL->rules) is intentional, as `rules` should just be an alias for `cssRules`.
// See https://bugs.webkit.org/show_bug.cgi?id=197725 for more information.
return kit(WTF::getPtr(IMPL->cssRules()));
}

- (unsigned)insertRule:(NSString *)rule index:(unsigned)index

0 comments on commit 9529e06

Please sign in to comment.