Working on Bug 63977, It became clear that we should have a way to beware "flattened tree" concept in XBL mean. Here is a rough idea: - At first, extract NodeFlattener from NodeRenderingContext. - Then expand its usage to where we should care about flattened tree: - Focus handling, - Text iteration, - And possibly more! NodeFlattener would look like this: ---- class NodeFlattener { public: Node* nextSibling() const; Node* previousSibling() const; Node* parent() const; Node* next() const; // dfs traversal like traverseNextNode() void moveToNextSibling(); .... // more moveTo family will come here. private: Node* m_node; ... // Pull a part of NodeRenderingContext state here. }; ---- NodeFlattener is like TreeWalker, but should be more lightweight. - It doesn't have script binding. - It's stack-based. Ideally, it would be great if the flattener can be used as a smart pointer for the node. But I think it isn't feasible because it has a many state which makes a copy operation bit expensive.
Bug 61110 might relates.
I think "Flattener" is a completely wrong term here. It's just a tree walker, aware of shadow DOM subtrees. Can we call it TreeIterator instead?
(In reply to comment #2) > I think "Flattener" is a completely wrong term here. It's just a tree walker, aware of shadow DOM subtrees. > > Can we call it TreeIterator instead? That sounds fine. It's a bit too generic though. We would also want to have non-shadow aware iterator... FlatTreeIterator?
I found that this change is hard to be done with only naive refactoring because there is no link from forwarded nodes to content elements. So I'm trying to introduce that link, which is tracked on Bug 64251 and Bug 64252.
I marked it DUPLICATE in favor of bug79197. https://bugs.webkit.org/show_bug.cgi?id=79197 If you have any concerns, please reopen this. *** This bug has been marked as a duplicate of bug 79197 ***