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

LibWeb: Replace unused DOMTreeModel with DOMTreeJSONModel

The direct-Document-access DOMTreeModel is no longer used, since the DOM
Inspector has to access the Document remotely over IPC. This commit
removes it, and renames DOMTreeJSONModel to take its place, since it no
longer has to differentiate itself from the non-JSON one.

In case that didn't make sense:
- Delete DOMTreeModel
- Rename DOMTreeJSONModel -> DOMTreeModel
This commit is contained in:
Sam Atkins 2021-08-24 17:04:30 +01:00 committed by Andreas Kling
parent 57ee7b3d56
commit fe820f6d5a
6 changed files with 101 additions and 294 deletions

View file

@ -1,11 +1,14 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2018-2020, Adam Hodgen <ant1441@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/HashMap.h>
#include <AK/JsonObject.h>
#include <LibGUI/Model.h>
#include <LibWeb/Forward.h>
@ -13,9 +16,13 @@ namespace Web {
class DOMTreeModel final : public GUI::Model {
public:
static NonnullRefPtr<DOMTreeModel> create(DOM::Document& document)
static NonnullRefPtr<DOMTreeModel> create(StringView dom_tree)
{
return adopt_ref(*new DOMTreeModel(document));
auto json_or_error = JsonValue::from_string(dom_tree);
if (!json_or_error.has_value())
VERIFY_NOT_REACHED();
return adopt_ref(*new DOMTreeModel(json_or_error.value().as_object()));
}
virtual ~DOMTreeModel() override;
@ -26,16 +33,30 @@ public:
virtual GUI::ModelIndex index(int row, int column, const GUI::ModelIndex& parent = GUI::ModelIndex()) const override;
virtual GUI::ModelIndex parent_index(const GUI::ModelIndex&) const override;
GUI::ModelIndex index_for_node(DOM::Node*) const;
private:
explicit DOMTreeModel(DOM::Document&);
explicit DOMTreeModel(JsonObject);
NonnullRefPtr<DOM::Document> m_document;
ALWAYS_INLINE JsonObject const* get_parent(const JsonObject& o) const
{
auto parent_node = m_dom_node_to_parent_map.get(&o);
VERIFY(parent_node.has_value());
return *parent_node;
}
ALWAYS_INLINE static JsonArray const* get_children(const JsonObject& o)
{
if (auto const* maybe_children = o.get_ptr("children"); maybe_children)
return &maybe_children->as_array();
return nullptr;
}
void map_dom_nodes_to_parent(JsonObject const* parent, JsonObject const* child);
GUI::Icon m_document_icon;
GUI::Icon m_element_icon;
GUI::Icon m_text_icon;
JsonObject m_dom_tree;
HashMap<JsonObject const*, JsonObject const*> m_dom_node_to_parent_map;
};
}