diff --git a/Libraries/LibDevTools/Actors/PageStyleActor.cpp b/Libraries/LibDevTools/Actors/PageStyleActor.cpp index 796d1330a9e..9adf529aa68 100644 --- a/Libraries/LibDevTools/Actors/PageStyleActor.cpp +++ b/Libraries/LibDevTools/Actors/PageStyleActor.cpp @@ -4,7 +4,6 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include #include #include #include @@ -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("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::create(DevToolsServer& devtools, String name, WeakPtr 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(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)); diff --git a/Libraries/LibDevTools/Actors/PageStyleActor.h b/Libraries/LibDevTools/Actors/PageStyleActor.h index f930435c673..54a9e70edc3 100644 --- a/Libraries/LibDevTools/Actors/PageStyleActor.h +++ b/Libraries/LibDevTools/Actors/PageStyleActor.h @@ -6,6 +6,7 @@ #pragma once +#include #include #include #include @@ -15,6 +16,7 @@ namespace DevTools { struct DOMNodeProperties { JsonObject computed_style; JsonObject node_box_sizing; + JsonArray fonts; }; class PageStyleActor final : public Actor { diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cpp index fea0f2d7d93..05f49dfdfbf 100644 --- a/Libraries/LibWebView/Application.cpp +++ b/Libraries/LibWebView/Application.cpp @@ -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), }); };