1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 19:55:06 +00:00
serenity/Userland/Libraries/LibWeb/SVG/SVGMaskElement.cpp
Ali Mohammad Pur aeee98b3a1 AK+Everywhere: Remove the null state of DeprecatedString
This commit removes DeprecatedString's "null" state, and replaces all
its users with one of the following:
- A normal, empty DeprecatedString
- Optional<DeprecatedString>

Note that null states of DeprecatedFlyString/StringView/etc are *not*
affected by this commit. However, DeprecatedString::empty() is now
considered equal to a null StringView.
2023-10-13 18:33:21 +03:30

60 lines
1.9 KiB
C++

/*
* Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2023, MacDue <macdue@dueutil.tech>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Bindings/SVGMaskElementPrototype.h>
#include <LibWeb/DOM/Document.h>
#include <LibWeb/Layout/SVGGraphicsBox.h>
#include <LibWeb/SVG/AttributeNames.h>
#include <LibWeb/SVG/SVGMaskElement.h>
namespace Web::SVG {
SVGMaskElement::SVGMaskElement(DOM::Document& document, DOM::QualifiedName tag_name)
: SVGGraphicsElement(document, move(tag_name))
{
}
SVGMaskElement::~SVGMaskElement() = default;
void SVGMaskElement::initialize(JS::Realm& realm)
{
Base::initialize(realm);
set_prototype(&Bindings::ensure_web_prototype<Bindings::SVGMaskElementPrototype>(realm, "SVGMaskElement"));
}
JS::GCPtr<Layout::Node> SVGMaskElement::create_layout_node(NonnullRefPtr<CSS::StyleProperties> style)
{
return heap().allocate_without_realm<Layout::SVGGraphicsBox>(document(), *this, move(style));
}
void SVGMaskElement::attribute_changed(FlyString const& name, Optional<DeprecatedString> const& value)
{
SVGGraphicsElement::attribute_changed(name, value);
if (name == AttributeNames::maskUnits) {
m_mask_units = AttributeParser::parse_units(value.value_or(""));
} else if (name == AttributeNames::maskContentUnits) {
m_mask_content_units = AttributeParser::parse_units(value.value_or(""));
}
}
MaskContentUnits SVGMaskElement::mask_content_units() const
{
return m_mask_content_units.value_or(MaskContentUnits::UserSpaceOnUse);
}
MaskUnits SVGMaskElement::mask_units() const
{
return m_mask_units.value_or(MaskUnits::ObjectBoundingBox);
}
CSSPixelRect SVGMaskElement::resolve_masking_area(CSSPixelRect const& mask_target) const
{
// TODO: Resolve this based on the x, y, width, and height of the mask.
return mask_target.inflated(mask_target.size().scaled(CSSPixels(2) / 10));
}
}