mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 10:28:10 +00:00
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.
This commit is contained in:
parent
5088846606
commit
68c8d23e39
3 changed files with 19 additions and 7 deletions
|
@ -109,7 +109,7 @@ void InspectorWidget::set_dom_json(String json)
|
|||
return;
|
||||
|
||||
m_dom_json = json;
|
||||
m_dom_tree_view->set_model(Web::DOMTreeModel::create(m_dom_json->view()));
|
||||
m_dom_tree_view->set_model(Web::DOMTreeModel::create(m_dom_json->view(), *m_dom_tree_view));
|
||||
|
||||
if (m_pending_inspect_node_id.has_value()) {
|
||||
i32 node_id = m_pending_inspect_node_id.value();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue