1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:18:11 +00:00
serenity/Userland/Libraries/LibWeb/Internals/Inspector.cpp
Shannon Booth 83758d4cdd LibWeb: Wrap PseudoElements stored in SimpleSelector in a class
No functional impact intended. This is just a more complicated way of
writing what we have now.

The goal of this commit is so that we are able to store the 'name' of a
pseudo element for use in serializing 'unknown -webkit-
pseudo-elements', see:

https://www.w3.org/TR/selectors-4/#compat

This is quite awkward, as in pretty much all cases just the selector
type enum is enough, but we will need to cache the name for serializing
these unknown selectors. I can't figure out any reason why we would need
this name anywhere else in the engine, so pretty much everywhere is
still just passing around this raw enum. But this change will allow us
to easily store the name inside of this new struct for when it is needed
for serialization, once those webkit unknown elements are supported by
our engine.
2023-12-11 16:54:59 +01:00

79 lines
2.8 KiB
C++

/*
* Copyright (c) 2023, Tim Flynn <trflynn89@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Runtime/Realm.h>
#include <LibJS/Runtime/VM.h>
#include <LibWeb/Bindings/InspectorPrototype.h>
#include <LibWeb/Bindings/Intrinsics.h>
#include <LibWeb/CSS/Selector.h>
#include <LibWeb/DOM/NamedNodeMap.h>
#include <LibWeb/HTML/BrowsingContext.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Internals/Inspector.h>
#include <LibWeb/Page/Page.h>
namespace Web::Internals {
JS_DEFINE_ALLOCATOR(Inspector);
Inspector::Inspector(JS::Realm& realm)
: Bindings::PlatformObject(realm)
{
}
Inspector::~Inspector() = default;
void Inspector::initialize(JS::Realm& realm)
{
Base::initialize(realm);
Object::set_prototype(&Bindings::ensure_web_prototype<Bindings::InspectorPrototype>(realm, "Inspector"_fly_string));
}
void Inspector::inspector_loaded()
{
global_object().browsing_context()->page().client().inspector_did_load();
}
void Inspector::inspect_dom_node(i32 node_id, Optional<i32> const& pseudo_element)
{
auto& page = global_object().browsing_context()->page();
page.client().inspector_did_select_dom_node(node_id, pseudo_element.map([](auto value) {
VERIFY(value < to_underlying(Web::CSS::Selector::PseudoElement::Type::PseudoElementCount));
return static_cast<Web::CSS::Selector::PseudoElement::Type>(value);
}));
}
void Inspector::set_dom_node_text(i32 node_id, String const& text)
{
global_object().browsing_context()->page().client().inspector_did_set_dom_node_text(node_id, text);
}
void Inspector::set_dom_node_tag(i32 node_id, String const& tag)
{
global_object().browsing_context()->page().client().inspector_did_set_dom_node_tag(node_id, tag);
}
void Inspector::add_dom_node_attributes(i32 node_id, JS::NonnullGCPtr<DOM::NamedNodeMap> attributes)
{
global_object().browsing_context()->page().client().inspector_did_add_dom_node_attributes(node_id, attributes);
}
void Inspector::replace_dom_node_attribute(i32 node_id, String const& name, JS::NonnullGCPtr<DOM::NamedNodeMap> replacement_attributes)
{
global_object().browsing_context()->page().client().inspector_did_replace_dom_node_attribute(node_id, name, replacement_attributes);
}
void Inspector::request_dom_tree_context_menu(i32 node_id, i32 client_x, i32 client_y, String const& type, Optional<String> const& tag, Optional<String> const& attribute_name, Optional<String> const& attribute_value)
{
global_object().browsing_context()->page().client().inspector_did_request_dom_tree_context_menu(node_id, { client_x, client_y }, type, tag, attribute_name, attribute_value);
}
void Inspector::execute_console_script(String const& script)
{
global_object().browsing_context()->page().client().inspector_did_execute_console_script(script);
}
}