diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-11-09 11:58:20 +0100 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-11-09 11:58:20 +0100 |
commit | 7fcb21c935a125398a40203747cfa73ca35b7728 (patch) | |
tree | 915e3f17362489660a6212a6fd802c3fb653a4cf | |
parent | 29b2117564a2bd29b3841122c1b6a835f7a7c6d6 (diff) | |
download | serenity-7fcb21c935a125398a40203747cfa73ca35b7728.zip |
LibHTML: Add document icon in DOMTreeModel and keep document alive
-rw-r--r-- | Libraries/LibHTML/DOMTreeModel.cpp | 8 | ||||
-rw-r--r-- | Libraries/LibHTML/DOMTreeModel.h | 3 |
2 files changed, 7 insertions, 4 deletions
diff --git a/Libraries/LibHTML/DOMTreeModel.cpp b/Libraries/LibHTML/DOMTreeModel.cpp index ff687e878b..580487645d 100644 --- a/Libraries/LibHTML/DOMTreeModel.cpp +++ b/Libraries/LibHTML/DOMTreeModel.cpp @@ -8,6 +8,7 @@ DOMTreeModel::DOMTreeModel(Document& document) : m_document(document) { + m_document_icon.set_bitmap_for_size(16, GraphicsBitmap::load_from_file("/res/icons/16x16/filetype-html.png")); m_element_icon.set_bitmap_for_size(16, GraphicsBitmap::load_from_file("/res/icons/16x16/inspector-object.png")); m_text_icon.set_bitmap_for_size(16, GraphicsBitmap::load_from_file("/res/icons/16x16/filetype-unknown.png")); } @@ -19,7 +20,7 @@ DOMTreeModel::~DOMTreeModel() GModelIndex DOMTreeModel::index(int row, int column, const GModelIndex& parent) const { if (!parent.is_valid()) { - return create_index(row, column, &m_document); + return create_index(row, column, m_document.ptr()); } auto& parent_node = *static_cast<Node*>(parent.internal_data()); return create_index(row, column, parent_node.child_at_index(row)); @@ -35,7 +36,7 @@ GModelIndex DOMTreeModel::parent_index(const GModelIndex& index) const // No grandparent? Parent is the document! if (!node.parent()->parent()) { - return create_index(0, 0, &m_document); + return create_index(0, 0, m_document.ptr()); } // Walk the grandparent's children to find the index of node's parent in its parent. @@ -89,6 +90,8 @@ GVariant DOMTreeModel::data(const GModelIndex& index, Role role) const { auto* node = static_cast<Node*>(index.internal_data()); if (role == Role::Icon) { + if (node->is_document()) + return m_document_icon; if (node->is_element()) return m_element_icon; // FIXME: More node type icons? @@ -96,7 +99,6 @@ GVariant DOMTreeModel::data(const GModelIndex& index, Role role) const } if (role == Role::Display) { if (node->is_text()) { - return String::format("%s", with_whitespace_collapsed(to<Text>(*node).data()).characters()); } return String::format("<%s>", node->tag_name().characters()); diff --git a/Libraries/LibHTML/DOMTreeModel.h b/Libraries/LibHTML/DOMTreeModel.h index 8c37a83dc1..ebbbab27a8 100644 --- a/Libraries/LibHTML/DOMTreeModel.h +++ b/Libraries/LibHTML/DOMTreeModel.h @@ -23,8 +23,9 @@ public: private: explicit DOMTreeModel(Document&); - Document& m_document; + NonnullRefPtr<Document> m_document; + GIcon m_document_icon; GIcon m_element_icon; GIcon m_text_icon; }; |