Browser: Reset the DOM Inspector's state when re-opening it
This resets the DOM Inspector to a default state when re-opening it, instead of it displaying the previous selection and properties, which may be outdated. This is closer to how Chrome and Firefox behave. Eventually, it probably makes sense to copy their behavior of selecting the `<body>` element by default.
This commit is contained in:
parent
97379ace25
commit
73c95bcd5f
Notes:
sideshowbarker
2024-07-18 04:51:37 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/73c95bcd5f4 Pull-request: https://github.com/SerenityOS/serenity/pull/9725 Issue: https://github.com/SerenityOS/serenity/issues/8935 Reviewed-by: https://github.com/awesomekling
3 changed files with 28 additions and 4 deletions
|
@ -52,10 +52,7 @@ void InspectorWidget::set_inspected_node(GUI::ModelIndex const index)
|
|||
auto inspected_node_properties = maybe_inspected_node_properties.value();
|
||||
load_style_json(inspected_node_properties.specified_values_json, inspected_node_properties.computed_values_json);
|
||||
} else {
|
||||
m_inspected_node_specified_values_json.clear();
|
||||
m_inspected_node_computed_values_json.clear();
|
||||
m_style_table_view->set_model(nullptr);
|
||||
m_computed_style_table_view->set_model(nullptr);
|
||||
clear_style_json();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,6 +85,18 @@ InspectorWidget::~InspectorWidget()
|
|||
{
|
||||
}
|
||||
|
||||
void InspectorWidget::select_default_node()
|
||||
{
|
||||
clear_style_json();
|
||||
|
||||
// FIXME: Select the <body> element, or else the root node.
|
||||
m_dom_tree_view->collapse_tree();
|
||||
m_dom_tree_view->set_cursor({}, GUI::AbstractView::SelectionUpdate::ClearIfNotSelected);
|
||||
|
||||
m_layout_tree_view->collapse_tree();
|
||||
m_layout_tree_view->set_cursor({}, GUI::AbstractView::SelectionUpdate::ClearIfNotSelected);
|
||||
}
|
||||
|
||||
void InspectorWidget::set_dom_json(String json)
|
||||
{
|
||||
if (m_dom_json.has_value() && m_dom_json.value() == json)
|
||||
|
@ -103,6 +112,8 @@ void InspectorWidget::set_dom_json(String json)
|
|||
i32 node_id = m_pending_inspect_node_id.value();
|
||||
m_pending_inspect_node_id.clear();
|
||||
set_inspected_node(node_id);
|
||||
} else {
|
||||
select_default_node();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -124,4 +135,12 @@ void InspectorWidget::load_style_json(String specified_values_json, String compu
|
|||
m_computed_style_table_view->set_model(Web::StylePropertiesModel::create(m_inspected_node_computed_values_json.value().view()));
|
||||
}
|
||||
|
||||
void InspectorWidget::clear_style_json()
|
||||
{
|
||||
m_inspected_node_specified_values_json.clear();
|
||||
m_inspected_node_computed_values_json.clear();
|
||||
m_style_table_view->set_model(nullptr);
|
||||
m_computed_style_table_view->set_model(nullptr);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,12 +22,14 @@ public:
|
|||
void set_dom_node_properties_json(i32 node_id, String specified_values_json, String computed_values_json);
|
||||
|
||||
void set_inspected_node(i32 node_id);
|
||||
void select_default_node();
|
||||
|
||||
private:
|
||||
InspectorWidget();
|
||||
|
||||
void set_inspected_node(GUI::ModelIndex);
|
||||
void load_style_json(String specified_values_json, String computed_values_json);
|
||||
void clear_style_json();
|
||||
|
||||
RefPtr<Web::OutOfProcessWebView> m_web_view;
|
||||
|
||||
|
|
|
@ -485,6 +485,9 @@ void Tab::show_inspector_window(Browser::Tab::InspectorTarget inspector_target)
|
|||
Optional<i32> hovered_node = m_web_content_view->get_hovered_node_id();
|
||||
VERIFY(hovered_node.has_value());
|
||||
m_dom_inspector_widget->set_inspected_node(hovered_node.value());
|
||||
} else {
|
||||
VERIFY(inspector_target == InspectorTarget::Document);
|
||||
m_dom_inspector_widget->select_default_node();
|
||||
}
|
||||
|
||||
auto* window = m_dom_inspector_widget->window();
|
||||
|
|
Loading…
Add table
Reference in a new issue