summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Ladybird/DOMNodeProperties.h19
-rw-r--r--Ladybird/InspectorWidget.h4
-rw-r--r--Ladybird/WebContentView.cpp22
-rw-r--r--Ladybird/WebContentView.h5
-rw-r--r--Userland/Applications/Browser/InspectorWidget.cpp6
-rw-r--r--Userland/Libraries/LibWebView/OutOfProcessWebView.cpp33
-rw-r--r--Userland/Libraries/LibWebView/OutOfProcessWebView.h12
-rw-r--r--Userland/Libraries/LibWebView/ViewImplementation.cpp35
-rw-r--r--Userland/Libraries/LibWebView/ViewImplementation.h16
9 files changed, 56 insertions, 96 deletions
diff --git a/Ladybird/DOMNodeProperties.h b/Ladybird/DOMNodeProperties.h
deleted file mode 100644
index d7880b8c30..0000000000
--- a/Ladybird/DOMNodeProperties.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright (c) 2022, MacDue <macdue@dueutil.tech>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#pragma once
-
-#include <AK/String.h>
-
-namespace Ladybird {
-
-struct DOMNodeProperties {
- String computed_style_json;
- String resolved_style_json;
- String custom_properties_json;
-};
-
-}
diff --git a/Ladybird/InspectorWidget.h b/Ladybird/InspectorWidget.h
index 6c566c5efd..e614309ab1 100644
--- a/Ladybird/InspectorWidget.h
+++ b/Ladybird/InspectorWidget.h
@@ -6,8 +6,8 @@
#pragma once
-#include "DOMNodeProperties.h"
#include "ModelTranslator.h"
+#include "WebContentView.h"
#include <AK/Optional.h>
#include <AK/StringView.h>
#include <LibWeb/CSS/Selector.h>
@@ -36,7 +36,7 @@ public:
void load_style_json(StringView computed_style_json, StringView resolved_style_json, StringView custom_properties_json);
void clear_style_json();
- Function<ErrorOr<DOMNodeProperties>(i32, Optional<Web::CSS::Selector::PseudoElement>)> on_dom_node_inspected;
+ Function<ErrorOr<WebContentView::DOMNodeProperties>(i32, Optional<Web::CSS::Selector::PseudoElement>)> on_dom_node_inspected;
Function<void()> on_close;
private:
diff --git a/Ladybird/WebContentView.cpp b/Ladybird/WebContentView.cpp
index 1709592170..f7ee8f9894 100644
--- a/Ladybird/WebContentView.cpp
+++ b/Ladybird/WebContentView.cpp
@@ -532,28 +532,6 @@ bool WebContentView::is_inspector_open() const
return m_inspector_widget && m_inspector_widget->isVisible();
}
-void WebContentView::inspect_dom_tree()
-{
- client().async_inspect_dom_tree();
-}
-
-ErrorOr<Ladybird::DOMNodeProperties> WebContentView::inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> pseudo_element)
-{
- auto response = client().inspect_dom_node(node_id, pseudo_element);
- if (!response.has_style())
- return Error::from_string_view("Inspected node returned no style"sv);
- return Ladybird::DOMNodeProperties {
- .computed_style_json = TRY(String::from_deprecated_string(response.take_computed_style())),
- .resolved_style_json = TRY(String::from_deprecated_string(response.take_resolved_style())),
- .custom_properties_json = TRY(String::from_deprecated_string(response.take_custom_properties())),
- };
-}
-
-void WebContentView::clear_inspected_dom_node()
-{
- (void)inspect_dom_node(0, {});
-}
-
void WebContentView::show_inspector()
{
ensure_inspector_widget();
diff --git a/Ladybird/WebContentView.h b/Ladybird/WebContentView.h
index e8a750aacc..c01b003ec4 100644
--- a/Ladybird/WebContentView.h
+++ b/Ladybird/WebContentView.h
@@ -25,8 +25,6 @@
#include <QAbstractScrollArea>
#include <QPointer>
-#include "DOMNodeProperties.h"
-
class QTextEdit;
class QLineEdit;
@@ -192,10 +190,7 @@ private:
void ensure_inspector_widget();
bool is_inspector_open() const;
- void inspect_dom_tree();
- void clear_inspected_dom_node();
void close_sub_widgets();
- ErrorOr<Ladybird::DOMNodeProperties> inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> pseudo_element);
qreal m_inverse_pixel_scaling_ratio { 1.0 };
bool m_should_show_line_box_borders { false };
diff --git a/Userland/Applications/Browser/InspectorWidget.cpp b/Userland/Applications/Browser/InspectorWidget.cpp
index b578804b3a..465470adf7 100644
--- a/Userland/Applications/Browser/InspectorWidget.cpp
+++ b/Userland/Applications/Browser/InspectorWidget.cpp
@@ -63,9 +63,9 @@ void InspectorWidget::set_selection(GUI::ModelIndex const index)
m_selection = move(selection);
auto maybe_inspected_node_properties = m_web_view->inspect_dom_node(m_selection.dom_node_id, m_selection.pseudo_element);
- if (maybe_inspected_node_properties.has_value()) {
- auto inspected_node_properties = maybe_inspected_node_properties.value();
- load_style_json(inspected_node_properties.computed_values_json, inspected_node_properties.resolved_values_json, inspected_node_properties.custom_properties_json);
+ if (!maybe_inspected_node_properties.is_error()) {
+ auto inspected_node_properties = maybe_inspected_node_properties.release_value();
+ load_style_json(inspected_node_properties.computed_style_json, inspected_node_properties.resolved_style_json, inspected_node_properties.custom_properties_json);
update_node_box_model(inspected_node_properties.node_box_sizing_json);
} else {
clear_style_json();
diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp
index 805bd699f3..6100294360 100644
--- a/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp
+++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.cpp
@@ -565,34 +565,6 @@ void OutOfProcessWebView::debug_request(DeprecatedString const& request, Depreca
client().async_debug_request(request, argument);
}
-void OutOfProcessWebView::inspect_dom_tree()
-{
- client().async_inspect_dom_tree();
-}
-
-Optional<OutOfProcessWebView::DOMNodeProperties> OutOfProcessWebView::inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> pseudo_element)
-{
- auto response = client().inspect_dom_node(node_id, pseudo_element);
- if (!response.has_style())
- return {};
- return DOMNodeProperties {
- .computed_values_json = response.computed_style(),
- .resolved_values_json = response.resolved_style(),
- .custom_properties_json = response.custom_properties(),
- .node_box_sizing_json = response.node_box_sizing()
- };
-}
-
-void OutOfProcessWebView::clear_inspected_dom_node()
-{
- client().inspect_dom_node(0, {});
-}
-
-i32 OutOfProcessWebView::get_hovered_node_id()
-{
- return client().get_hovered_node_id();
-}
-
void OutOfProcessWebView::js_console_input(DeprecatedString const& js_source)
{
client().async_js_console_input(js_source);
@@ -829,11 +801,6 @@ void OutOfProcessWebView::notify_server_did_finish_handling_input_event(bool eve
process_next_input_event();
}
-void OutOfProcessWebView::inspect_accessibility_tree()
-{
- client().async_inspect_accessibility_tree();
-}
-
void OutOfProcessWebView::notify_server_did_get_accessibility_tree(DeprecatedString const& accessibility_tree)
{
if (on_get_accessibility_tree)
diff --git a/Userland/Libraries/LibWebView/OutOfProcessWebView.h b/Userland/Libraries/LibWebView/OutOfProcessWebView.h
index b817d8f892..c3e694674f 100644
--- a/Userland/Libraries/LibWebView/OutOfProcessWebView.h
+++ b/Userland/Libraries/LibWebView/OutOfProcessWebView.h
@@ -41,18 +41,6 @@ public:
void debug_request(DeprecatedString const& request, DeprecatedString const& argument = {});
- void inspect_dom_tree();
- struct DOMNodeProperties {
- DeprecatedString computed_values_json;
- DeprecatedString resolved_values_json;
- DeprecatedString custom_properties_json;
- DeprecatedString node_box_sizing_json;
- };
- Optional<DOMNodeProperties> inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement>);
- void inspect_accessibility_tree();
- void clear_inspected_dom_node();
- i32 get_hovered_node_id();
-
void js_console_input(DeprecatedString const& js_source);
void js_console_request_messages(i32 start_index);
diff --git a/Userland/Libraries/LibWebView/ViewImplementation.cpp b/Userland/Libraries/LibWebView/ViewImplementation.cpp
index 800ade5d4f..0d6ba6bc90 100644
--- a/Userland/Libraries/LibWebView/ViewImplementation.cpp
+++ b/Userland/Libraries/LibWebView/ViewImplementation.cpp
@@ -4,6 +4,8 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/Error.h>
+#include <AK/String.h>
#include <LibWebView/ViewImplementation.h>
namespace WebView {
@@ -47,4 +49,37 @@ void ViewImplementation::get_source()
client().async_get_source();
}
+void ViewImplementation::inspect_dom_tree()
+{
+ client().async_inspect_dom_tree();
+}
+
+void ViewImplementation::inspect_accessibility_tree()
+{
+ client().async_inspect_accessibility_tree();
+}
+
+ErrorOr<ViewImplementation::DOMNodeProperties> ViewImplementation::inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> pseudo_element)
+{
+ auto response = client().inspect_dom_node(node_id, pseudo_element);
+ if (!response.has_style())
+ return Error::from_string_view("Inspected node returned no style"sv);
+ return DOMNodeProperties {
+ .computed_style_json = TRY(String::from_deprecated_string(response.take_computed_style())),
+ .resolved_style_json = TRY(String::from_deprecated_string(response.take_resolved_style())),
+ .custom_properties_json = TRY(String::from_deprecated_string(response.take_custom_properties())),
+ .node_box_sizing_json = TRY(String::from_deprecated_string(response.take_node_box_sizing())),
+ };
+}
+
+void ViewImplementation::clear_inspected_dom_node()
+{
+ client().inspect_dom_node(0, {});
+}
+
+i32 ViewImplementation::get_hovered_node_id()
+{
+ return client().get_hovered_node_id();
+}
+
}
diff --git a/Userland/Libraries/LibWebView/ViewImplementation.h b/Userland/Libraries/LibWebView/ViewImplementation.h
index fc0b173f6c..056f5154b3 100644
--- a/Userland/Libraries/LibWebView/ViewImplementation.h
+++ b/Userland/Libraries/LibWebView/ViewImplementation.h
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
+ * Copyright (c) 2023, Linus Groh <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -7,6 +8,7 @@
#pragma once
#include <AK/Forward.h>
+#include <AK/String.h>
#include <LibGfx/Forward.h>
#include <LibGfx/StandardCursor.h>
#include <LibWeb/Forward.h>
@@ -19,11 +21,25 @@ class ViewImplementation {
public:
virtual ~ViewImplementation() { }
+ struct DOMNodeProperties {
+ String computed_style_json;
+ String resolved_style_json;
+ String custom_properties_json;
+ String node_box_sizing_json;
+ };
+
void zoom_in();
void zoom_out();
void reset_zoom();
+
void get_source();
+ void inspect_dom_tree();
+ void inspect_accessibility_tree();
+ ErrorOr<DOMNodeProperties> inspect_dom_node(i32 node_id, Optional<Web::CSS::Selector::PseudoElement> pseudo_element);
+ void clear_inspected_dom_node();
+ i32 get_hovered_node_id();
+
virtual void notify_server_did_layout(Badge<WebContentClient>, Gfx::IntSize content_size) = 0;
virtual void notify_server_did_paint(Badge<WebContentClient>, i32 bitmap_id) = 0;
virtual void notify_server_did_invalidate_content_rect(Badge<WebContentClient>, Gfx::IntRect const&) = 0;