mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 20:29:18 +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: 2ee3985fd1
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
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <AK/JsonObject.h>
|
|
||||||
#include <AK/JsonValue.h>
|
#include <AK/JsonValue.h>
|
||||||
#include <LibDevTools/Actors/InspectorActor.h>
|
#include <LibDevTools/Actors/InspectorActor.h>
|
||||||
#include <LibDevTools/Actors/PageStyleActor.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));
|
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)
|
NonnullRefPtr<PageStyleActor> PageStyleActor::create(DevToolsServer& devtools, String name, WeakPtr<InspectorActor> inspector)
|
||||||
{
|
{
|
||||||
return adopt_ref(*new PageStyleActor(devtools, move(name), move(inspector)));
|
return adopt_ref(*new PageStyleActor(devtools, move(name), move(inspector)));
|
||||||
|
@ -89,6 +119,12 @@ void PageStyleActor::handle_message(Message const& message)
|
||||||
{
|
{
|
||||||
JsonObject response;
|
JsonObject response;
|
||||||
|
|
||||||
|
if (message.type == "getAllUsedFontFaces"sv) {
|
||||||
|
response.set("fontFaces"sv, JsonArray {});
|
||||||
|
send_response(message, move(response));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (message.type == "getApplied"sv) {
|
if (message.type == "getApplied"sv) {
|
||||||
// FIXME: This provides information to the "styles" pane in the inspector tab, which allows toggling and editing
|
// 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.
|
// 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;
|
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") {
|
if (message.type == "isPositionEditable") {
|
||||||
response.set("value"sv, false);
|
response.set("value"sv, false);
|
||||||
send_response(message, move(response));
|
send_response(message, move(response));
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/JsonArray.h>
|
||||||
#include <AK/JsonObject.h>
|
#include <AK/JsonObject.h>
|
||||||
#include <AK/NonnullRefPtr.h>
|
#include <AK/NonnullRefPtr.h>
|
||||||
#include <LibDevTools/Actor.h>
|
#include <LibDevTools/Actor.h>
|
||||||
|
@ -15,6 +16,7 @@ namespace DevTools {
|
||||||
struct DOMNodeProperties {
|
struct DOMNodeProperties {
|
||||||
JsonObject computed_style;
|
JsonObject computed_style;
|
||||||
JsonObject node_box_sizing;
|
JsonObject node_box_sizing;
|
||||||
|
JsonArray fonts;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PageStyleActor final : public Actor {
|
class PageStyleActor final : public Actor {
|
||||||
|
|
|
@ -442,6 +442,7 @@ void Application::inspect_dom_node(DevTools::TabDescription const& description,
|
||||||
on_complete(DevTools::DOMNodeProperties {
|
on_complete(DevTools::DOMNodeProperties {
|
||||||
.computed_style = move(properties.computed_style),
|
.computed_style = move(properties.computed_style),
|
||||||
.node_box_sizing = move(properties.node_box_sizing),
|
.node_box_sizing = move(properties.node_box_sizing),
|
||||||
|
.fonts = move(properties.fonts),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue