1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-21 16:05:07 +00:00
serenity/Userland/Libraries/LibWebView/InspectorClient.h
Timothy Flynn 353642168a LibWebView: Don't wait for the DOM and a11y trees to load the Inspector
Provides a nicer experience on pages with large trees so that the window
isn't just a large blank screen while it is loading. Instead, send the
trees to the Inspector WebView once they have arrived and have been
transformed to HTML.

We Base64 encode the HTML to avoid needing to deal with all kinds of
nested quotes that may appear in the HTML. We could instead send the
JSON to the WebView, but generating the HTML in C++ feels a bit easier
for now.
2023-11-30 14:08:53 +01:00

43 lines
922 B
C++

/*
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/JsonValue.h>
#include <AK/StringView.h>
#include <LibWebView/ViewImplementation.h>
#pragma once
namespace WebView {
class InspectorClient {
public:
InspectorClient(ViewImplementation& content_web_view, ViewImplementation& inspector_web_view);
~InspectorClient();
void inspect();
void reset();
void select_hovered_node();
void select_default_node();
void clear_selection();
private:
void load_inspector();
String generate_dom_tree(JsonObject const&);
String generate_accessibility_tree(JsonObject const&);
void select_node(i32 node_id);
ViewImplementation& m_content_web_view;
ViewImplementation& m_inspector_web_view;
Optional<i32> m_body_node_id;
Optional<i32> m_pending_selection;
bool m_dom_tree_loaded { false };
};
}