Serenity Operating System
at master 59 lines 2.2 kB view raw
1/* 2 * Copyright (c) 2022, Jonah Shafran <jonahshafran@gmail.com> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#pragma once 8 9#include <AK/JsonObject.h> 10#include <LibGUI/Model.h> 11#include <LibWeb/CSS/Selector.h> 12 13namespace WebView { 14 15class AccessibilityTreeModel final : public GUI::Model { 16public: 17 static NonnullRefPtr<AccessibilityTreeModel> create(StringView accessibility_tree, GUI::TreeView& tree_view) 18 { 19 auto json_or_error = JsonValue::from_string(accessibility_tree).release_value_but_fixme_should_propagate_errors(); 20 return adopt_ref(*new AccessibilityTreeModel(json_or_error.as_object(), &tree_view)); 21 } 22 23 static NonnullRefPtr<AccessibilityTreeModel> create(StringView accessibility_tree) 24 { 25 auto json_or_error = JsonValue::from_string(accessibility_tree).release_value_but_fixme_should_propagate_errors(); 26 return adopt_ref(*new AccessibilityTreeModel(json_or_error.as_object(), nullptr)); 27 } 28 29 virtual ~AccessibilityTreeModel() override; 30 31 virtual int row_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override; 32 virtual int column_count(GUI::ModelIndex const& = GUI::ModelIndex()) const override; 33 virtual GUI::Variant data(GUI::ModelIndex const&, GUI::ModelRole) const override; 34 virtual GUI::ModelIndex index(int row, int column, GUI::ModelIndex const& parent = GUI::ModelIndex()) const override; 35 virtual GUI::ModelIndex parent_index(GUI::ModelIndex const&) const override; 36 37private: 38 AccessibilityTreeModel(JsonObject, GUI::TreeView*); 39 40 ALWAYS_INLINE JsonObject const* get_parent(JsonObject const& o) const 41 { 42 auto parent_node = m_accessibility_node_to_parent_map.get(&o); 43 VERIFY(parent_node.has_value()); 44 return *parent_node; 45 } 46 47 ALWAYS_INLINE static Optional<JsonArray const&> const get_children(JsonObject const& o) 48 { 49 return o.get_array("children"sv); 50 } 51 52 void map_accessibility_nodes_to_parent(JsonObject const* parent, JsonObject const* child); 53 54 GUI::TreeView* m_tree_view { nullptr }; 55 JsonObject m_accessibility_tree; 56 HashMap<JsonObject const*, JsonObject const*> m_accessibility_node_to_parent_map; 57}; 58 59}