mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 19:45:12 +00:00
LibDevTools+LibWebView: Implement getting the used fonts for a DOM node
This also includes a request to get all fonts for a page, which we stub out for now as we don't have the IPC to retrieve all fonts.
This commit is contained in:
parent
f9e83af475
commit
2ee3985fd1
Notes:
github-actions[bot]
2025-03-13 20:57:45 +00:00
Author: https://github.com/trflynn89 Commit: https://github.com/LadybirdBrowser/ladybird/commit/2ee3985fd14 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3920
3 changed files with 52 additions and 1 deletions
|
@ -4,7 +4,6 @@
|
|||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <AK/JsonObject.h>
|
||||
#include <AK/JsonValue.h>
|
||||
#include <LibDevTools/Actors/InspectorActor.h>
|
||||
#include <LibDevTools/Actors/PageStyleActor.h>
|
||||
|
@ -72,6 +71,37 @@ static void received_computed_style(JsonObject& response, JsonObject const& comp
|
|||
response.set("computed"sv, move(computed));
|
||||
}
|
||||
|
||||
static void received_fonts(JsonObject& response, JsonArray const& fonts)
|
||||
{
|
||||
JsonArray font_faces;
|
||||
|
||||
fonts.for_each([&](JsonValue const& font) {
|
||||
if (!font.is_object())
|
||||
return;
|
||||
|
||||
auto name = font.as_object().get_string("name"sv).value_or({});
|
||||
auto weight = font.as_object().get_integer<i64>("weight"sv).value_or(0);
|
||||
|
||||
JsonObject font_face;
|
||||
font_face.set("CSSFamilyName"sv, name);
|
||||
font_face.set("CSSGeneric"sv, JsonValue {});
|
||||
font_face.set("format"sv, ""sv);
|
||||
font_face.set("localName"sv, ""sv);
|
||||
font_face.set("metadata"sv, ""sv);
|
||||
font_face.set("name"sv, name);
|
||||
font_face.set("srcIndex"sv, -1);
|
||||
font_face.set("style"sv, ""sv);
|
||||
font_face.set("URI"sv, ""sv);
|
||||
font_face.set("variationAxes"sv, JsonArray {});
|
||||
font_face.set("variationInstances"sv, JsonArray {});
|
||||
font_face.set("weight"sv, weight);
|
||||
|
||||
font_faces.must_append(move(font_face));
|
||||
});
|
||||
|
||||
response.set("fontFaces"sv, move(font_faces));
|
||||
}
|
||||
|
||||
NonnullRefPtr<PageStyleActor> PageStyleActor::create(DevToolsServer& devtools, String name, WeakPtr<InspectorActor> inspector)
|
||||
{
|
||||
return adopt_ref(*new PageStyleActor(devtools, move(name), move(inspector)));
|
||||
|
@ -89,6 +119,12 @@ void PageStyleActor::handle_message(Message const& message)
|
|||
{
|
||||
JsonObject response;
|
||||
|
||||
if (message.type == "getAllUsedFontFaces"sv) {
|
||||
response.set("fontFaces"sv, JsonArray {});
|
||||
send_response(message, move(response));
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.type == "getApplied"sv) {
|
||||
// FIXME: This provides information to the "styles" pane in the inspector tab, which allows toggling and editing
|
||||
// styles live. We do not yet support figuring out the list of styles that apply to a specific node.
|
||||
|
@ -121,6 +157,18 @@ void PageStyleActor::handle_message(Message const& message)
|
|||
return;
|
||||
}
|
||||
|
||||
if (message.type == "getUsedFontFaces"sv) {
|
||||
auto node = get_required_parameter<String>(message, "node"sv);
|
||||
if (!node.has_value())
|
||||
return;
|
||||
|
||||
inspect_dom_node(message, *node, [](auto& response, auto const& properties) {
|
||||
received_fonts(response, properties.fonts);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.type == "isPositionEditable") {
|
||||
response.set("value"sv, false);
|
||||
send_response(message, move(response));
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/JsonArray.h>
|
||||
#include <AK/JsonObject.h>
|
||||
#include <AK/NonnullRefPtr.h>
|
||||
#include <LibDevTools/Actor.h>
|
||||
|
@ -15,6 +16,7 @@ namespace DevTools {
|
|||
struct DOMNodeProperties {
|
||||
JsonObject computed_style;
|
||||
JsonObject node_box_sizing;
|
||||
JsonArray fonts;
|
||||
};
|
||||
|
||||
class PageStyleActor final : public Actor {
|
||||
|
|
|
@ -442,6 +442,7 @@ void Application::inspect_dom_node(DevTools::TabDescription const& description,
|
|||
on_complete(DevTools::DOMNodeProperties {
|
||||
.computed_style = move(properties.computed_style),
|
||||
.node_box_sizing = move(properties.node_box_sizing),
|
||||
.fonts = move(properties.fonts),
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue