diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index c03b7ada14..f22b0a1cab 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -2888,12 +2888,6 @@ RefPtr Parser::parse_css_value(ParsingContext const& context, Proper } } - // FIXME: This is a hack for the `opacity` property which should really take an - if (property_id == PropertyID::Opacity && component_value.is(Token::Type::Number)) { - String string = component_value.token().number_string_value(); - return LengthStyleValue::create(Length::make_px(strtof(string.characters(), nullptr))); - } - if (auto builtin = parse_builtin_value(context, component_value)) return builtin; diff --git a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp index 4a04f9c7e4..c0c5ee828a 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleProperties.cpp @@ -1,5 +1,6 @@ /* * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2021, Sam Atkins * * SPDX-License-Identifier: BSD-2-Clause */ @@ -298,14 +299,21 @@ Optional StyleProperties::z_index() const Optional StyleProperties::opacity() const { - auto value = property(CSS::PropertyID::Opacity); - if (!value.has_value()) + auto maybe_value = property(CSS::PropertyID::Opacity); + if (!maybe_value.has_value()) return {}; + auto& value = maybe_value.value(); - if (auto length = value.value()->to_length(); length.is_percentage()) - return clamp(static_cast(length.raw_value() / 100), 0.0f, 1.0f); - else - return clamp(static_cast(length.raw_value()), 0.0f, 1.0f); + if (value->is_numeric()) + return clamp(static_cast(*value).value(), 0.0f, 1.0f); + + if (value->is_length()) { + auto length = value->to_length(); + if (length.is_percentage()) + return clamp(length.raw_value() / 100.0f, 0.0f, 1.0f); + } + + return {}; } Optional StyleProperties::flex_direction() const