mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
LibWeb/CSS: Add basic implementation of CSSMarginRule
This is a bit under-specced, specifically there's no definition of CSSMarginDescriptors so I've gone with CSSStyleProperties for now. Gets us 17 WPT subtests.
This commit is contained in:
parent
aa9fa88428
commit
870f24f181
Notes:
github-actions[bot]
2025-05-16 10:02:36 +00:00
Author: https://github.com/AtkinsSJ
Commit: 870f24f181
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4746
21 changed files with 233 additions and 32 deletions
77
Libraries/LibWeb/CSS/CSSMarginRule.cpp
Normal file
77
Libraries/LibWeb/CSS/CSSMarginRule.cpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Bindings/CSSMarginRulePrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/CSS/CSSMarginRule.h>
|
||||
#include <LibWeb/CSS/CSSStyleProperties.h>
|
||||
#include <LibWeb/WebIDL/ExceptionOr.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
GC_DEFINE_ALLOCATOR(CSSMarginRule);
|
||||
|
||||
GC::Ref<CSSMarginRule> CSSMarginRule::create(JS::Realm& realm, FlyString name, GC::Ref<CSSStyleProperties> style)
|
||||
{
|
||||
return realm.create<CSSMarginRule>(realm, move(name), style);
|
||||
}
|
||||
|
||||
CSSMarginRule::CSSMarginRule(JS::Realm& realm, FlyString name, GC::Ref<CSSStyleProperties> style)
|
||||
: CSSRule(realm, Type::Margin)
|
||||
, m_name(name.to_ascii_lowercase())
|
||||
, m_style(style)
|
||||
{
|
||||
m_style->set_parent_rule(*this);
|
||||
}
|
||||
|
||||
void CSSMarginRule::initialize(JS::Realm& realm)
|
||||
{
|
||||
WEB_SET_PROTOTYPE_FOR_INTERFACE(CSSMarginRule);
|
||||
Base::initialize(realm);
|
||||
}
|
||||
|
||||
String CSSMarginRule::serialized() const
|
||||
{
|
||||
// AD-HOC: There is currently no spec for serializing CSSMarginRule.
|
||||
StringBuilder builder;
|
||||
builder.appendff("@{} {{ ", m_name);
|
||||
if (m_style->length() > 0) {
|
||||
builder.append(m_style->serialized());
|
||||
builder.append(' ');
|
||||
}
|
||||
builder.append('}');
|
||||
|
||||
return builder.to_string_without_validation();
|
||||
}
|
||||
|
||||
void CSSMarginRule::visit_edges(Visitor& visitor)
|
||||
{
|
||||
Base::visit_edges(visitor);
|
||||
visitor.visit(m_style);
|
||||
}
|
||||
|
||||
// https://drafts.csswg.org/css-page-3/#syntax-page-selector
|
||||
bool is_margin_rule_name(StringView name)
|
||||
{
|
||||
return name.equals_ignoring_ascii_case("top-left-corner"sv)
|
||||
|| name.equals_ignoring_ascii_case("top-left"sv)
|
||||
|| name.equals_ignoring_ascii_case("top-center"sv)
|
||||
|| name.equals_ignoring_ascii_case("top-right"sv)
|
||||
|| name.equals_ignoring_ascii_case("top-right-corner"sv)
|
||||
|| name.equals_ignoring_ascii_case("bottom-left-corner"sv)
|
||||
|| name.equals_ignoring_ascii_case("bottom-left"sv)
|
||||
|| name.equals_ignoring_ascii_case("bottom-center"sv)
|
||||
|| name.equals_ignoring_ascii_case("bottom-right"sv)
|
||||
|| name.equals_ignoring_ascii_case("bottom-right-corner"sv)
|
||||
|| name.equals_ignoring_ascii_case("left-top"sv)
|
||||
|| name.equals_ignoring_ascii_case("left-middle"sv)
|
||||
|| name.equals_ignoring_ascii_case("left-bottom"sv)
|
||||
|| name.equals_ignoring_ascii_case("right-top"sv)
|
||||
|| name.equals_ignoring_ascii_case("right-middle"sv)
|
||||
|| name.equals_ignoring_ascii_case("right-bottom"sv);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue