mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 21:22:46 +00:00 
			
		
		
		
	LibWebView+Ladybird: Move DOM inspection helpers to ViewImplementation
This commit is contained in:
		
							parent
							
								
									f313708237
								
							
						
					
					
						commit
						2428e3e675
					
				
					 9 changed files with 56 additions and 96 deletions
				
			
		|  | @ -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; | ||||
| }; | ||||
| 
 | ||||
| } | ||||
|  | @ -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: | ||||
|  |  | |||
|  | @ -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(); | ||||
|  |  | |||
|  | @ -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 }; | ||||
|  |  | |||
|  | @ -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(); | ||||
|  |  | |||
|  | @ -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) | ||||
|  |  | |||
|  | @ -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); | ||||
| 
 | ||||
|  |  | |||
|  | @ -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(); | ||||
| } | ||||
| 
 | ||||
| } | ||||
|  |  | |||
|  | @ -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; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Linus Groh
						Linus Groh