summaryrefslogtreecommitdiff
path: root/Userland/Applications/Browser/InspectorWidget.cpp
diff options
context:
space:
mode:
authorSam Atkins <atkinssj@gmail.com>2021-08-27 20:21:30 +0100
committerAndreas Kling <kling@serenityos.org>2021-09-02 22:16:41 +0200
commit73c95bcd5f4031a7049ec5af515208e14d2ee7b8 (patch)
tree4d687b1ad08b0ec27e3c864421c06b4236cb309e /Userland/Applications/Browser/InspectorWidget.cpp
parent97379ace25e07c2c5599e8d383278fbbff9d089d (diff)
downloadserenity-73c95bcd5f4031a7049ec5af515208e14d2ee7b8.zip
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.
Diffstat (limited to 'Userland/Applications/Browser/InspectorWidget.cpp')
-rw-r--r--Userland/Applications/Browser/InspectorWidget.cpp27
1 files changed, 23 insertions, 4 deletions
diff --git a/Userland/Applications/Browser/InspectorWidget.cpp b/Userland/Applications/Browser/InspectorWidget.cpp
index 3be62726a2..eaac3ae982 100644
--- a/Userland/Applications/Browser/InspectorWidget.cpp
+++ b/Userland/Applications/Browser/InspectorWidget.cpp
@@ -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);
+}
+
}