summaryrefslogtreecommitdiff
path: root/Ladybird/InspectorWidget.h
diff options
context:
space:
mode:
authorMacDue <macdue@dueutil.tech>2022-12-18 00:50:53 +0000
committerAndrew Kaster <andrewdkaster@gmail.com>2022-12-25 15:30:08 -0700
commitaa85a881581ff04fe86da6e0e253d1555e43710f (patch)
tree04eeba676cc370c0f258fb296c59778f738dee66 /Ladybird/InspectorWidget.h
parent0313814d3bd9164924d20c1eda7d61ebb532d22b (diff)
downloadserenity-aa85a881581ff04fe86da6e0e253d1555e43710f.zip
Ladybird: Reimplement the DOM inspector :^)
This has been broken since the switch to the multiprocess architecture (and even before then was very limited). This restores the previous functionally and also implements the ability to inspect individual elements (by selecting them in the tree view). The inspector also now correctly updates when navigating between pages.
Diffstat (limited to 'Ladybird/InspectorWidget.h')
-rw-r--r--Ladybird/InspectorWidget.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/Ladybird/InspectorWidget.h b/Ladybird/InspectorWidget.h
new file mode 100644
index 0000000000..ab367784be
--- /dev/null
+++ b/Ladybird/InspectorWidget.h
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2022, MacDue <macdue@dueutil.tech>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include "ModelTranslator.h"
+#include <AK/Optional.h>
+#include <AK/StringView.h>
+#include <LibWeb/CSS/Selector.h>
+#include <QWidget>
+
+class QTreeView;
+
+namespace Ladybird {
+
+class InspectorWidget final : public QWidget {
+ Q_OBJECT
+public:
+ InspectorWidget();
+ virtual ~InspectorWidget() = default;
+
+ struct Selection {
+ i32 dom_node_id { 0 };
+ Optional<Web::CSS::Selector::PseudoElement> pseudo_element {};
+ bool operator==(Selection const& other) const = default;
+ };
+
+ void clear_dom_json();
+ void set_dom_json(StringView dom_json);
+
+ Function<void(i32, Optional<Web::CSS::Selector::PseudoElement>)> on_dom_node_inspected;
+ Function<void()> on_close;
+
+private:
+ void set_selection(GUI::ModelIndex);
+ void closeEvent(QCloseEvent*) override;
+
+ QTreeView* m_tree_view { nullptr };
+ ModelTranslator m_dom_model {};
+ Selection m_selection;
+};
+
+}