mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-06-11 02:13:56 +09: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
Notes:
sideshowbarker
2024-07-18 01:33:20 +09:00
Author: https://github.com/awesomekling
Commit: 68c8d23e39
3 changed files with 19 additions and 7 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue