diff --git a/Ladybird/AppKit/UI/Inspector.mm b/Ladybird/AppKit/UI/Inspector.mm index 6b3ca0a201..b956a6f0e3 100644 --- a/Ladybird/AppKit/UI/Inspector.mm +++ b/Ladybird/AppKit/UI/Inspector.mm @@ -5,6 +5,8 @@ */ #include +#include +#include #include #include @@ -24,6 +26,14 @@ static constexpr CGFloat const WINDOW_HEIGHT = 800; static NSString* const CSS_PROPERTY_COLUMN = @"Property"; static NSString* const CSS_VALUE_COLUMN = @"Value"; +template<> +struct AK::Traits : public GenericTraits { + static unsigned hash(NSDictionary* dictionary) + { + return [dictionary hash]; + } +}; + struct Selection { bool operator==(Selection const& other) const = default; @@ -34,6 +44,9 @@ struct Selection { @interface Inspector () { Selection m_selection; + + HashMap m_dom_node_to_parent_map; + HashMap m_node_id_to_dom_node_map; } @property (nonatomic, strong) Tab* tab; @@ -103,6 +116,8 @@ struct Selection { if (strong_self.dom_tree) { [strong_self.dom_tree_outline_view reloadItem:nil reloadChildren:YES]; [strong_self.dom_tree_outline_view sizeToFit]; + + [strong_self prepareDOMNodeMaps:strong_self.dom_tree parentNode:nil]; } else { strong_self.dom_tree = @{}; } @@ -138,6 +153,9 @@ struct Selection { { m_selection = {}; + m_dom_node_to_parent_map = {}; + m_node_id_to_dom_node_map = {}; + self.dom_tree = @{}; [self.dom_tree_outline_view reloadItem:nil reloadChildren:YES]; [self.dom_tree_outline_view sizeToFit]; @@ -229,6 +247,20 @@ struct Selection { } } +- (void)prepareDOMNodeMaps:(NSDictionary*)dom_node + parentNode:(NSDictionary*)parent_node +{ + m_dom_node_to_parent_map.set(dom_node, parent_node); + + if (id dom_node_id = [dom_node objectForKey:@"id"]) { + m_node_id_to_dom_node_map.set([dom_node_id intValue], dom_node); + } + + for (NSDictionary* child in [dom_node objectForKey:@"children"]) { + [self prepareDOMNodeMaps:child parentNode:dom_node]; + } +} + - (void)setSelection:(Selection)selection { if (selection == m_selection)