Truly independent web browser
/*
* Copyright (c) 2018-2022, Andreas Kling <[email protected]>
* Copyright (c) 2020-2021, the SerenityOS developers.
* Copyright (c) 2021-2026, Sam Atkins <[email protected]>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/CSS/Parser/Parser.h>
#include <LibWeb/SelectorRustFFI.h>
namespace Web::CSS::Parser {
Optional<SelectorList> Parser::parse_as_selector(Utf16View source, SelectorParsingMode mode)
{
return parse_selector_list_in_rust(source, m_declared_namespaces, false, mode == SelectorParsingMode::Forgiving);
}
Optional<Selector::PseudoElementSelector> Parser::parse_as_pseudo_element_selector(Utf16View input_view, PseudoElementParsingMode mode)
{
SelectorFFI::FfiUtf16View input {
.latin1 = input_view.has_latin1_storage() ? input_view.latin1_span().data() : nullptr,
.utf16 = input_view.has_latin1_storage() ? nullptr : reinterpret_cast<u16 const*>(input_view.utf16_span().data()),
.length = input_view.length_in_code_units(),
};
auto parsed = SelectorFFI::rust_selector_parse_pseudo_element(input, mode == PseudoElementParsingMode::ComputedStyle);
if (!parsed.selector)
return {};
auto selector = Selector::create(parsed.selector);
auto highlight_name = parsed.highlight_name ? Utf16FlyString::adopt_raw(parsed.highlight_name) : Utf16FlyString {};
auto pseudo_element = pseudo_element_from_ffi(parsed.pseudo_element);
if (!pseudo_element.has_value())
return {};
return Selector::PseudoElementSelector { pseudo_element.release_value(), selector->serialize(), move(highlight_name) };
}
}