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

Browser: Add "Inspect Element" to context menu :^)

This opens the DOM Inspector window, with the target element already
selected. (If the window is already open, it just selects the element.)

Note that this only applies to single-process mode for now. In OOP mode,
the "inspect element" action is disabled.
This commit is contained in:
Sam Atkins 2021-08-17 17:00:27 +01:00 committed by Andreas Kling
parent 8eef509c1b
commit 37f060b873
6 changed files with 69 additions and 19 deletions

View file

@ -28,6 +28,8 @@ void InspectorWidget::set_inspected_node(GUI::ModelIndex const index)
auto* node = static_cast<Web::DOM::Node*>(index.internal_data());
m_inspected_node = node;
m_document->set_inspected_node(node);
m_dom_tree_view->set_cursor(index, GUI::AbstractView::SelectionUpdate::Set);
m_dom_tree_view->expand_all_parents_of(index);
if (node && node->is_element()) {
auto& element = verify_cast<Web::DOM::Element>(*node);
if (element.specified_css_values()) {
@ -40,6 +42,17 @@ void InspectorWidget::set_inspected_node(GUI::ModelIndex const index)
}
}
void InspectorWidget::set_inspected_node(Web::DOM::Node* requested_node)
{
dbgln("Inspected node: {:p}", requested_node);
if (requested_node == nullptr) {
set_inspected_node(GUI::ModelIndex {});
return;
}
set_inspected_node(static_cast<Web::DOMTreeModel*>(m_dom_tree_view->model())->index_for_node(requested_node));
}
InspectorWidget::InspectorWidget()
{
set_layout<GUI::VerticalBoxLayout>();