mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-08 06:09:58 +00:00
LibWeb: Add MathML Element presentational hints
This commit is contained in:
parent
f1571c4217
commit
96b34ea744
Notes:
github-actions[bot]
2025-10-21 23:48:01 +00:00
Author: https://github.com/lpas
Commit: 96b34ea744
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6252
Reviewed-by: https://github.com/AtkinsSJ
Reviewed-by: https://github.com/gmta ✅
13 changed files with 380 additions and 2 deletions
70
Libraries/LibWeb/MathML/MathMLMspaceElement.cpp
Normal file
70
Libraries/LibWeb/MathML/MathMLMspaceElement.cpp
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/*
|
||||
* Copyright (c) 2025, Lorenz Ackermann, <me@lorenzackermann.xyz>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/HTML/Parser/HTMLParser.h>
|
||||
#include <LibWeb/MathML/AttributeNames.h>
|
||||
#include <LibWeb/MathML/MathMLMspaceElement.h>
|
||||
|
||||
namespace Web::MathML {
|
||||
|
||||
GC_DEFINE_ALLOCATOR(MathMLMspaceElement);
|
||||
|
||||
MathMLMspaceElement::MathMLMspaceElement(DOM::Document& document, DOM::QualifiedName qualified_name)
|
||||
: MathMLElement(document, move(qualified_name))
|
||||
{
|
||||
}
|
||||
|
||||
bool MathMLMspaceElement::is_presentational_hint(FlyString const& name) const
|
||||
{
|
||||
if (Base::is_presentational_hint(name))
|
||||
return true;
|
||||
return first_is_one_of(name, AttributeNames::width, AttributeNames::height, AttributeNames::depth);
|
||||
}
|
||||
|
||||
void MathMLMspaceElement::apply_presentational_hints(GC::Ref<CSS::CascadedProperties> cascaded_properties) const
|
||||
{
|
||||
Base::apply_presentational_hints(cascaded_properties);
|
||||
// https://w3c.github.io/mathml-core/#attribute-mspace-width
|
||||
// The width, height, depth, if present, must have a value that is a valid <length-percentage>.
|
||||
auto parse_non_percentage_value = [&](FlyString const& attribute_name) -> RefPtr<CSS::StyleValue const> {
|
||||
if (auto attribute = this->attribute(attribute_name); attribute.has_value()) {
|
||||
if (auto value = HTML::parse_dimension_value(attribute.value()); value && !value->is_percentage()) {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
};
|
||||
|
||||
// If the width attribute is present, valid and not a percentage then that attribute is used as a presentational hint
|
||||
// setting the element's width property to the corresponding value.
|
||||
if (auto width_value = parse_non_percentage_value(AttributeNames::width)) {
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Width, width_value.release_nonnull());
|
||||
}
|
||||
|
||||
// https://w3c.github.io/mathml-core/#attribute-mspace-height
|
||||
// If the height attribute is absent, invalid or a percentage then the requested line-ascent is 0. Otherwise the
|
||||
// requested line-ascent is the resolved value of the height attribute, clamping negative values to 0.
|
||||
auto height_value = parse_non_percentage_value(AttributeNames::height);
|
||||
// FIXME set the line-ascent
|
||||
|
||||
// If both the height and depth attributes are present, valid and not a percentage then they are used as a
|
||||
// presentational hint setting the element's height property to the concatenation of the
|
||||
// strings "calc(", the height attribute value, " + ", the depth attribute value, and ")". If only one of these
|
||||
// attributes is present, valid and not a percentage then it is treated as a presentational hint setting the
|
||||
// element's height property to the corresponding value.
|
||||
auto depth_value = parse_non_percentage_value(AttributeNames::depth);
|
||||
|
||||
if (height_value && depth_value) {
|
||||
// FIXME set the presentational hint to calculate height + depth
|
||||
} else if (height_value) {
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Height, height_value.release_nonnull());
|
||||
} else if (depth_value) {
|
||||
cascaded_properties->set_property_from_presentational_hint(CSS::PropertyID::Height, depth_value.release_nonnull());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue