diff options
author | Andreas Kling <kling@serenityos.org> | 2021-11-02 19:32:26 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-11-02 22:30:06 +0100 |
commit | 68c8d23e39b697ead4488f2207952c2d8fdf78d6 (patch) | |
tree | 0b2a28050e68f7eff2787fadb9e2f655a9ce8aa6 /Userland/Libraries/LibWeb | |
parent | 50888466065ed3e24a93de39a74c849781707140 (diff) | |
download | serenity-68c8d23e39b697ead4488f2207952c2d8fdf78d6.zip |
LibWeb+Browser: Show DOM comments with syntax_comment color in inspector
This required a hack since models can't return a color role directly
from data(). I've added a FIXME about it.
Diffstat (limited to 'Userland/Libraries/LibWeb')
-rw-r--r-- | Userland/Libraries/LibWeb/DOMTreeModel.cpp | 17 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/DOMTreeModel.h | 7 |
2 files changed, 18 insertions, 6 deletions
diff --git a/Userland/Libraries/LibWeb/DOMTreeModel.cpp b/Userland/Libraries/LibWeb/DOMTreeModel.cpp index b0f6ea7ac8..2fa8d6997a 100644 --- a/Userland/Libraries/LibWeb/DOMTreeModel.cpp +++ b/Userland/Libraries/LibWeb/DOMTreeModel.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> + * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org> * Copyright (c) 2018-2020, Adam Hodgen <ant1441@gmail.com> * * SPDX-License-Identifier: BSD-2-Clause @@ -8,12 +8,15 @@ #include "DOMTreeModel.h" #include <AK/JsonObject.h> #include <AK/StringBuilder.h> +#include <LibGUI/TreeView.h> +#include <LibGfx/Palette.h> #include <ctype.h> namespace Web { -DOMTreeModel::DOMTreeModel(JsonObject dom_tree) - : m_dom_tree(move(dom_tree)) +DOMTreeModel::DOMTreeModel(JsonObject dom_tree, GUI::TreeView& tree_view) + : m_tree_view(tree_view) + , m_dom_tree(move(dom_tree)) { m_document_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/filetype-html.png")); m_element_icon.set_bitmap_for_size(16, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/inspector-object.png")); @@ -118,6 +121,14 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol auto node_name = node.get("name").as_string(); auto type = node.get("type").as_string_or("unknown"); + if (role == GUI::ModelRole::ForegroundColor) { + // FIXME: Allow models to return a foreground color *role*. + // Then we won't need to have a GUI::TreeView& member anymore. + if (type == "comment"sv) + return m_tree_view.palette().syntax_comment(); + return {}; + } + if (role == GUI::ModelRole::Icon) { if (type == "document") return m_document_icon; diff --git a/Userland/Libraries/LibWeb/DOMTreeModel.h b/Userland/Libraries/LibWeb/DOMTreeModel.h index 29af8dac4b..edee42e1df 100644 --- a/Userland/Libraries/LibWeb/DOMTreeModel.h +++ b/Userland/Libraries/LibWeb/DOMTreeModel.h @@ -16,13 +16,13 @@ namespace Web { class DOMTreeModel final : public GUI::Model { public: - static NonnullRefPtr<DOMTreeModel> create(StringView dom_tree) + static NonnullRefPtr<DOMTreeModel> create(StringView dom_tree, GUI::TreeView& tree_view) { 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())); + return adopt_ref(*new DOMTreeModel(json_or_error.value().as_object(), tree_view)); } virtual ~DOMTreeModel() override; @@ -36,7 +36,7 @@ public: GUI::ModelIndex index_for_node(i32 node_id) const; private: - explicit DOMTreeModel(JsonObject); + DOMTreeModel(JsonObject, GUI::TreeView&); ALWAYS_INLINE JsonObject const* get_parent(const JsonObject& o) const { @@ -54,6 +54,7 @@ private: void map_dom_nodes_to_parent(JsonObject const* parent, JsonObject const* child); + GUI::TreeView& m_tree_view; GUI::Icon m_document_icon; GUI::Icon m_element_icon; GUI::Icon m_text_icon; |