mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
LibWeb: Add method for listing all style sheets on a page
This will be used by the inspector, for showing style sheet contents. Identifying a specific style sheet is a bit tricky. Depending on where it came from, a style sheet may have a URL, it might be associated with a DOM element, both, or neither. This varied information is wrapped in a new StyleSheetIdentifier struct.
This commit is contained in:
parent
dd3b011f15
commit
51a426cc05
Notes:
github-actions[bot]
2024-09-03 09:13:10 +00:00
Author: https://github.com/AtkinsSJ
Commit: 51a426cc05
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/1168
Reviewed-by: https://github.com/trflynn89
10 changed files with 214 additions and 1 deletions
73
Userland/Libraries/LibWeb/CSS/StyleSheetIdentifier.cpp
Normal file
73
Userland/Libraries/LibWeb/CSS/StyleSheetIdentifier.cpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*
|
||||
* Copyright (c) 2024, Sam Atkins <sam@ladybird.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include "StyleSheetIdentifier.h"
|
||||
#include <LibIPC/Decoder.h>
|
||||
#include <LibIPC/Encoder.h>
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
StringView style_sheet_identifier_type_to_string(StyleSheetIdentifier::Type type)
|
||||
{
|
||||
switch (type) {
|
||||
case StyleSheetIdentifier::Type::StyleElement:
|
||||
return "StyleElement"sv;
|
||||
case StyleSheetIdentifier::Type::LinkElement:
|
||||
return "LinkElement"sv;
|
||||
case StyleSheetIdentifier::Type::ImportRule:
|
||||
return "ImportRule"sv;
|
||||
case StyleSheetIdentifier::Type::UserAgent:
|
||||
return "UserAgent"sv;
|
||||
case StyleSheetIdentifier::Type::UserStyle:
|
||||
return "UserStyle"sv;
|
||||
}
|
||||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
Optional<StyleSheetIdentifier::Type> style_sheet_identifier_type_from_string(StringView string)
|
||||
{
|
||||
if (string == "StyleElement"sv)
|
||||
return StyleSheetIdentifier::Type::StyleElement;
|
||||
if (string == "LinkElement"sv)
|
||||
return StyleSheetIdentifier::Type::LinkElement;
|
||||
if (string == "ImportRule"sv)
|
||||
return StyleSheetIdentifier::Type::ImportRule;
|
||||
if (string == "UserAgent"sv)
|
||||
return StyleSheetIdentifier::Type::UserAgent;
|
||||
if (string == "UserStyle"sv)
|
||||
return StyleSheetIdentifier::Type::UserStyle;
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
namespace IPC {
|
||||
|
||||
template<>
|
||||
ErrorOr<void> encode(Encoder& encoder, Web::CSS::StyleSheetIdentifier const& style_sheet_source)
|
||||
{
|
||||
TRY(encoder.encode(style_sheet_source.type));
|
||||
TRY(encoder.encode(style_sheet_source.dom_element_unique_id));
|
||||
TRY(encoder.encode(style_sheet_source.url));
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
template<>
|
||||
ErrorOr<Web::CSS::StyleSheetIdentifier> decode(Decoder& decoder)
|
||||
{
|
||||
auto type = TRY(decoder.decode<Web::CSS::StyleSheetIdentifier::Type>());
|
||||
auto dom_element_unique_id = TRY(decoder.decode<Optional<i32>>());
|
||||
auto url = TRY(decoder.decode<Optional<String>>());
|
||||
|
||||
return Web::CSS::StyleSheetIdentifier {
|
||||
.type = type,
|
||||
.dom_element_unique_id = move(dom_element_unique_id),
|
||||
.url = move(url),
|
||||
};
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue