1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 09:27:35 +00:00

Browser: Port the Inspector to the WebView InspectorClient

This commit is contained in:
Timothy Flynn 2023-11-23 19:50:16 -05:00 committed by Andreas Kling
parent 1fe486cebe
commit 39e32e80cd
3 changed files with 70 additions and 182 deletions

View file

@ -9,61 +9,41 @@
#pragma once
#include "ElementSizePreviewWidget.h"
#include <AK/String.h>
#include <AK/StringView.h>
#include <LibGUI/Widget.h>
#include <LibWeb/CSS/Selector.h>
#include <LibWeb/Forward.h>
#include <LibWeb/Layout/BoxModelMetrics.h>
#include <LibWebView/Forward.h>
#include <LibWebView/OutOfProcessWebView.h>
namespace Browser {
class InspectorWidget final : public GUI::Widget {
C_OBJECT(InspectorWidget)
public:
struct Selection {
i32 dom_node_id { 0 };
Optional<Web::CSS::Selector::PseudoElement> pseudo_element {};
static NonnullRefPtr<InspectorWidget> create(WebView::OutOfProcessWebView& content_view);
virtual ~InspectorWidget();
bool operator==(Selection const& other) const
{
return dom_node_id == other.dom_node_id && pseudo_element == other.pseudo_element;
}
void inspect();
void reset();
ErrorOr<String> to_string() const
{
if (pseudo_element.has_value())
return String::formatted("id: {}, pseudo: {}", dom_node_id, Web::CSS::pseudo_element_name(pseudo_element.value()));
return String::formatted("id: {}", dom_node_id);
}
};
virtual ~InspectorWidget() = default;
void set_web_view(NonnullRefPtr<WebView::OutOfProcessWebView> web_view) { m_web_view = web_view; }
void set_dom_json(StringView);
void clear_dom_json();
void set_dom_node_properties_json(Selection, StringView computed_values_json, StringView resolved_values_json, StringView custom_properties_json, StringView node_box_sizing_json, StringView aria_properties_state_json);
void set_accessibility_json(StringView);
void set_selection(Selection);
void select_default_node();
void select_hovered_node();
private:
InspectorWidget();
explicit InspectorWidget(WebView::OutOfProcessWebView& content_view);
void set_selection(GUI::ModelIndex);
void load_style_json(StringView computed_values_json, StringView resolved_values_json, StringView custom_properties_json);
void update_node_box_model(StringView node_box_sizing_json);
void update_aria_properties_state_model(StringView aria_properties_state_json);
void clear_style_json();
void update_node_box_model(StringView node_box_sizing_json);
void clear_node_box_model();
RefPtr<WebView::OutOfProcessWebView> m_web_view;
void update_aria_properties_state_model(StringView aria_properties_state_json);
RefPtr<WebView::OutOfProcessWebView> m_inspector_view;
OwnPtr<WebView::InspectorClient> m_inspector_client;
RefPtr<GUI::TreeView> m_dom_tree_view;
RefPtr<GUI::TreeView> m_accessibility_tree_view;
RefPtr<GUI::TableView> m_computed_style_table_view;
RefPtr<GUI::TableView> m_resolved_style_table_view;
RefPtr<GUI::TableView> m_custom_properties_table_view;
@ -71,10 +51,6 @@ private:
RefPtr<ElementSizePreviewWidget> m_element_size_view;
Web::Layout::BoxModelMetrics m_node_box_sizing;
Optional<Selection> m_pending_selection;
Selection m_selection;
bool m_dom_loaded { false };
};
}