mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:57:43 +00:00
LibWeb: Remove unecessary dependence on Window from CSS classes
These classes only needed Window to get at its realm. Pass a realm directly to construct CSS classes.
This commit is contained in:
parent
8de7e49a56
commit
a2ccb00e1d
37 changed files with 159 additions and 146 deletions
|
@ -5,6 +5,8 @@
|
|||
*/
|
||||
|
||||
#include <AK/TypeCasts.h>
|
||||
#include <LibWeb/Bindings/CSSRuleListPrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/CSS/CSSImportRule.h>
|
||||
#include <LibWeb/CSS/CSSMediaRule.h>
|
||||
#include <LibWeb/CSS/CSSRule.h>
|
||||
|
@ -15,22 +17,22 @@
|
|||
|
||||
namespace Web::CSS {
|
||||
|
||||
CSSRuleList* CSSRuleList::create(HTML::Window& window_object, JS::MarkedVector<CSSRule*> const& rules)
|
||||
CSSRuleList* CSSRuleList::create(JS::Realm& realm, JS::MarkedVector<CSSRule*> const& rules)
|
||||
{
|
||||
auto* rule_list = window_object.heap().allocate<CSSRuleList>(window_object.realm(), window_object);
|
||||
auto* rule_list = realm.heap().allocate<CSSRuleList>(realm, realm);
|
||||
for (auto* rule : rules)
|
||||
rule_list->m_rules.append(*rule);
|
||||
return rule_list;
|
||||
}
|
||||
|
||||
CSSRuleList::CSSRuleList(HTML::Window& window_object)
|
||||
: Bindings::LegacyPlatformObject(window_object.cached_web_prototype("CSSRuleList"))
|
||||
CSSRuleList::CSSRuleList(JS::Realm& realm)
|
||||
: Bindings::LegacyPlatformObject(Bindings::ensure_web_prototype<Bindings::CSSRuleListPrototype>(realm, "CSSRuleList"))
|
||||
{
|
||||
}
|
||||
|
||||
CSSRuleList* CSSRuleList::create_empty(HTML::Window& window_object)
|
||||
CSSRuleList* CSSRuleList::create_empty(JS::Realm& realm)
|
||||
{
|
||||
return window_object.heap().allocate<CSSRuleList>(window_object.realm(), window_object);
|
||||
return realm.heap().allocate<CSSRuleList>(realm, realm);
|
||||
}
|
||||
|
||||
void CSSRuleList::visit_edges(Cell::Visitor& visitor)
|
||||
|
@ -55,7 +57,7 @@ WebIDL::ExceptionOr<unsigned> CSSRuleList::insert_a_css_rule(Variant<StringView,
|
|||
|
||||
// 2. If index is greater than length, then throw an IndexSizeError exception.
|
||||
if (index > length)
|
||||
return WebIDL::IndexSizeError::create(global_object(), "CSS rule index out of bounds.");
|
||||
return WebIDL::IndexSizeError::create(realm(), "CSS rule index out of bounds.");
|
||||
|
||||
// 3. Set new rule to the results of performing parse a CSS rule on argument rule.
|
||||
// NOTE: The insert-a-css-rule spec expects `rule` to be a string, but the CSSStyleSheet.insertRule()
|
||||
|
@ -64,7 +66,7 @@ WebIDL::ExceptionOr<unsigned> CSSRuleList::insert_a_css_rule(Variant<StringView,
|
|||
CSSRule* new_rule = nullptr;
|
||||
if (rule.has<StringView>()) {
|
||||
new_rule = parse_css_rule(
|
||||
CSS::Parser::ParsingContext { static_cast<HTML::Window&>(global_object()) },
|
||||
CSS::Parser::ParsingContext { realm() },
|
||||
rule.get<StringView>());
|
||||
} else {
|
||||
new_rule = rule.get<CSSRule*>();
|
||||
|
@ -72,7 +74,7 @@ WebIDL::ExceptionOr<unsigned> CSSRuleList::insert_a_css_rule(Variant<StringView,
|
|||
|
||||
// 4. If new rule is a syntax error, throw a SyntaxError exception.
|
||||
if (!new_rule)
|
||||
return WebIDL::SyntaxError::create(global_object(), "Unable to parse CSS rule.");
|
||||
return WebIDL::SyntaxError::create(realm(), "Unable to parse CSS rule.");
|
||||
|
||||
// FIXME: 5. If new rule cannot be inserted into list at the zero-index position index due to constraints specified by CSS, then throw a HierarchyRequestError exception. [CSS21]
|
||||
|
||||
|
@ -93,7 +95,7 @@ WebIDL::ExceptionOr<void> CSSRuleList::remove_a_css_rule(u32 index)
|
|||
|
||||
// 2. If index is greater than or equal to length, then throw an IndexSizeError exception.
|
||||
if (index >= length)
|
||||
return WebIDL::IndexSizeError::create(global_object(), "CSS rule index out of bounds.");
|
||||
return WebIDL::IndexSizeError::create(realm(), "CSS rule index out of bounds.");
|
||||
|
||||
// 3. Set old rule to the indexth item in list.
|
||||
CSSRule& old_rule = m_rules[index];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue