diff options
-rw-r--r-- | Userland/Applications/Browser/InspectorWidget.cpp | 27 | ||||
-rw-r--r-- | Userland/Applications/Browser/InspectorWidget.h | 2 | ||||
-rw-r--r-- | Userland/Applications/Browser/Tab.cpp | 3 |
3 files changed, 28 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); +} + } diff --git a/Userland/Applications/Browser/InspectorWidget.h b/Userland/Applications/Browser/InspectorWidget.h index b56fe700cb..5c36d27ae5 100644 --- a/Userland/Applications/Browser/InspectorWidget.h +++ b/Userland/Applications/Browser/InspectorWidget.h @@ -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; diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index 49c5f42cad..cee913d7c4 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -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(); |