mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 11:12:45 +00:00 
			
		
		
		
	Ladybird: Support inspecting the accessibility tree
This allows viewing the ARIA accessibility tree Epigenetic added in #16430, but now in Ladybird!
This commit is contained in:
		
							parent
							
								
									56d8e36698
								
							
						
					
					
						commit
						40bfaff133
					
				
					 3 changed files with 40 additions and 13 deletions
				
			
		|  | @ -6,6 +6,7 @@ | |||
| 
 | ||||
| #define AK_DONT_REPLACE_STD | ||||
| 
 | ||||
| #include <LibWebView/AccessibilityTreeModel.h> | ||||
| #include <LibWebView/DOMTreeModel.h> | ||||
| #include <LibWebView/StylePropertiesModel.h> | ||||
| 
 | ||||
|  | @ -27,12 +28,21 @@ InspectorWidget::InspectorWidget() | |||
|     auto splitter = new QSplitter(this); | ||||
|     layout()->addWidget(splitter); | ||||
|     splitter->setOrientation(Qt::Vertical); | ||||
|     auto tree_view = new QTreeView; | ||||
|     tree_view->setHeaderHidden(true); | ||||
|     tree_view->expandToDepth(3); | ||||
|     splitter->addWidget(tree_view); | ||||
|     tree_view->setModel(&m_dom_model); | ||||
|     QObject::connect(tree_view->selectionModel(), &QItemSelectionModel::selectionChanged, | ||||
| 
 | ||||
|     auto add_tab = [&](auto* tab_widget, auto* widget, auto name) { | ||||
|         auto container = new QWidget; | ||||
|         container->setLayout(new QVBoxLayout); | ||||
|         container->layout()->addWidget(widget); | ||||
|         tab_widget->addTab(container, name); | ||||
|     }; | ||||
| 
 | ||||
|     auto top_tap_widget = new QTabWidget; | ||||
|     splitter->addWidget(top_tap_widget); | ||||
| 
 | ||||
|     auto dom_tree_view = new QTreeView; | ||||
|     dom_tree_view->setHeaderHidden(true); | ||||
|     dom_tree_view->setModel(&m_dom_model); | ||||
|     QObject::connect(dom_tree_view->selectionModel(), &QItemSelectionModel::selectionChanged, | ||||
|         [this](QItemSelection const& selected, QItemSelection const&) { | ||||
|             auto indexes = selected.indexes(); | ||||
|             if (indexes.size()) { | ||||
|  | @ -40,17 +50,20 @@ InspectorWidget::InspectorWidget() | |||
|                 set_selection(index); | ||||
|             } | ||||
|         }); | ||||
|     add_tab(top_tap_widget, dom_tree_view, "DOM"); | ||||
| 
 | ||||
|     auto accessibility_tree_view = new QTreeView; | ||||
|     accessibility_tree_view->setHeaderHidden(true); | ||||
|     accessibility_tree_view->setModel(&m_accessibility_model); | ||||
|     add_tab(top_tap_widget, accessibility_tree_view, "Accessibility"); | ||||
| 
 | ||||
|     auto add_table_tab = [&](auto* tab_widget, auto& model, auto name) { | ||||
|         auto container = new QWidget; | ||||
|         auto table_view = new QTableView; | ||||
|         table_view->setModel(&model); | ||||
|         container->setLayout(new QVBoxLayout); | ||||
|         container->layout()->addWidget(table_view); | ||||
|         table_view->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch); | ||||
|         table_view->verticalHeader()->setVisible(false); | ||||
|         table_view->horizontalHeader()->setVisible(false); | ||||
|         tab_widget->addTab(container, name); | ||||
|         add_tab(tab_widget, table_view, name); | ||||
|     }; | ||||
| 
 | ||||
|     auto node_tabs = new QTabWidget; | ||||
|  | @ -65,9 +78,16 @@ void InspectorWidget::set_dom_json(StringView dom_json) | |||
|     m_dom_model.set_underlying_model(WebView::DOMTreeModel::create(dom_json)); | ||||
| } | ||||
| 
 | ||||
| void InspectorWidget::set_accessibility_json(StringView accessibility_json) | ||||
| { | ||||
|     m_accessibility_model.set_underlying_model(WebView::AccessibilityTreeModel::create(accessibility_json)); | ||||
| } | ||||
| 
 | ||||
| void InspectorWidget::clear_dom_json() | ||||
| { | ||||
|     m_dom_model.set_underlying_model(nullptr); | ||||
|     // The accessibility tree is pretty much another form of the DOM tree, so should be cleared at the time time.
 | ||||
|     m_accessibility_model.set_underlying_model(nullptr); | ||||
|     clear_style_json(); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -33,6 +33,8 @@ public: | |||
|     void clear_dom_json(); | ||||
|     void set_dom_json(StringView dom_json); | ||||
| 
 | ||||
|     void set_accessibility_json(StringView accessibility_json); | ||||
| 
 | ||||
|     void load_style_json(StringView computed_style_json, StringView resolved_style_json, StringView custom_properties_json); | ||||
|     void clear_style_json(); | ||||
| 
 | ||||
|  | @ -46,6 +48,7 @@ private: | |||
|     Selection m_selection; | ||||
| 
 | ||||
|     ModelTranslator m_dom_model {}; | ||||
|     ModelTranslator m_accessibility_model {}; | ||||
|     ModelTranslator m_computed_style_model {}; | ||||
|     ModelTranslator m_resolved_style_model {}; | ||||
|     ModelTranslator m_custom_properties_model {}; | ||||
|  |  | |||
|  | @ -532,6 +532,7 @@ void WebContentView::show_inspector() | |||
|     ensure_inspector_widget(); | ||||
|     m_inspector_widget->show(); | ||||
|     inspect_dom_tree(); | ||||
|     inspect_accessibility_tree(); | ||||
| } | ||||
| 
 | ||||
| void WebContentView::update_zoom() | ||||
|  | @ -797,8 +798,10 @@ void WebContentView::notify_server_did_start_loading(Badge<WebContentClient>, AK | |||
| void WebContentView::notify_server_did_finish_loading(Badge<WebContentClient>, AK::URL const& url) | ||||
| { | ||||
|     m_url = url; | ||||
|     if (is_inspector_open()) | ||||
|     if (is_inspector_open()) { | ||||
|         inspect_dom_tree(); | ||||
|         inspect_accessibility_tree(); | ||||
|     } | ||||
|     if (on_load_finish) | ||||
|         on_load_finish(url); | ||||
| } | ||||
|  | @ -1050,9 +1053,10 @@ void WebContentView::notify_server_did_finish_handling_input_event(bool event_wa | |||
|     (void)event_was_accepted; | ||||
| } | ||||
| 
 | ||||
| void WebContentView::notify_server_did_get_accessibility_tree(DeprecatedString const&) | ||||
| void WebContentView::notify_server_did_get_accessibility_tree(DeprecatedString const& accessibility_json) | ||||
| { | ||||
|     dbgln("TODO: support accessibility tree in Ladybird"); | ||||
|     if (m_inspector_widget) | ||||
|         m_inspector_widget->set_accessibility_json(accessibility_json); | ||||
| } | ||||
| 
 | ||||
| ErrorOr<String> WebContentView::dump_layout_tree() | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 MacDue
						MacDue