WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED INVALID
Bug 59812
Refactor DOM tree traversal methods
https://bugs.webkit.org/show_bug.cgi?id=59812
Summary
Refactor DOM tree traversal methods
Roland Steiner
Reported
2011-04-29 11:16:51 PDT
Currently we have a slew of methods to climb the DOM tree in conjunction with shadow trees that should be pruned down: parent(), parentNode(), parentOrHostNode(), parentNodeGuaranteedHostFree(), shadowAncestorNode(), shadowTreeRootNode()... Conceptually we only need: Node parent() treeScope() Element shadowRoot() ShadowRoot shadowHost()
Attachments
WIP - add universalTraverseNextNode
(6.11 KB, patch)
2011-05-19 23:38 PDT
,
Hayato Ito
no flags
Details
Formatted Diff
Diff
View All
Add attachment
proposed patch, testcase, etc.
Roland Steiner
Comment 1
2011-05-18 21:40:19 PDT
ShadowRoot parentTreeScope() is also needed.
Dimitri Glazkov (Google)
Comment 2
2011-05-18 21:42:33 PDT
htmlediting is a great place to fish for those.
Dominic Cooney
Comment 3
2011-05-19 22:46:10 PDT
Per the discussion in
bug 54441
we should consider broadening the scope of this bug to not just simplify the number of accessors but provide traversals to simplify the actual uses of these.
Roland Steiner
Comment 4
2011-05-19 23:35:29 PDT
(In reply to
comment #3
)
> Per the discussion in
bug 54441
we should consider broadening the scope of this bug to not just simplify the number of accessors but provide traversals to simplify the actual uses of these.
IMHO refactoring more complex traversal methods (such as the Node::traverse...() functions) as discussed in
bug 54441
is IMHO a separate and orthogonal issue from paring down the accessors as described here (and therefore should be different bug entries).
Hayato Ito
Comment 5
2011-05-19 23:38:23 PDT
Created
attachment 94179
[details]
WIP - add universalTraverseNextNode
Hayato Ito
Comment 6
2011-05-19 23:43:07 PDT
Let me share my patch (work in progress). I am trying to add a new traverseNode family, which traverses also into a shadow dom and a document in a frame element. That function will be used in implementing a tab traversal. The function name is a tentative name. I'll try to implement a tab traversal using this function. Maybe I should file a new bug entry for this patch. (In reply to
comment #5
)
> Created an attachment (id=94179) [details] > WIP - add universalTraverseNextNode
Roland Steiner
Comment 7
2011-05-20 02:46:52 PDT
Comment on
attachment 94179
[details]
WIP - add universalTraverseNextNode View in context:
https://bugs.webkit.org/attachment.cgi?id=94179&action=review
Refering to the discussion in
bug 54441
, given that the functionality is getting rather complex and specific I'd also vote to move this into a separate class - or perhaps template that takes a traversal strategy trait (?).
> Source/WebCore/dom/Node.cpp:1143 > + if (renderer() && renderer()->isTextControl()) {
Once the conversion to new-style shadow DOM is finished, this shouldn't be necessary anymore :)
> Source/WebCore/dom/Node.cpp:1149 > + return firstChild();
The code traverses first the shadow DOM, then the "light" DOM children. For tab traversal it may be necessary to consider the order of <content> elements in the shadow DOM instead - i.e., jump to the appropriate light DOM child(ren) from the shadow DOM <content> node(s).
> Source/WebCore/dom/Node.cpp:2563 > +void Node::showTreeAndMarkDeeply(const Node* markedNode1, const char* markedLabel1, const Node* markedNode2, const char* markedLabel2) const
Isn't the declaration for this function missing in the header file?
Hayato Ito
Comment 8
2011-05-20 03:24:02 PDT
Thank you for the review. (In reply to
comment #7
)
> (From update of
attachment 94179
[details]
) > View in context:
https://bugs.webkit.org/attachment.cgi?id=94179&action=review
> > Refering to the discussion in
bug 54441
, given that the functionality is getting rather complex and specific I'd also vote to move this into a separate class - or perhaps template that takes a traversal strategy trait (?).
Yeah, I am not sure whether this functionality should belong to a Node class or not. Maybe I'll move that to FocusController class or other suitable locations. But I haven't decided yet where we should have it. A traversal strategy trait sounds nice, but we should be careful to implement a such a trait, which should not cause any performance impacts to existing traverseXXX functions. I don't have a clear idea about it as of now.
> > > Source/WebCore/dom/Node.cpp:1143 > > + if (renderer() && renderer()->isTextControl()) { > > Once the conversion to new-style shadow DOM is finished, this shouldn't be necessary anymore :)
Thank you for the info. I am assuming that we should have it as of now :)
> > > Source/WebCore/dom/Node.cpp:1149 > > + return firstChild(); > > The code traverses first the shadow DOM, then the "light" DOM children. For tab traversal it may be necessary to consider the order of <content> elements in the shadow DOM instead - i.e., jump to the appropriate light DOM child(ren) from the shadow DOM <content> node(s).
Nice point. Let me implement that in a next patch.
> > > Source/WebCore/dom/Node.cpp:2563 > > +void Node::showTreeAndMarkDeeply(const Node* markedNode1, const char* markedLabel1, const Node* markedNode2, const char* markedLabel2) const > > Isn't the declaration for this function missing in the header file?
True. I'll address it.
Dimitri Glazkov (Google)
Comment 9
2011-05-20 08:37:05 PDT
Comment on
attachment 94179
[details]
WIP - add universalTraverseNextNode View in context:
https://bugs.webkit.org/attachment.cgi?id=94179&action=review
> Source/WebCore/dom/Node.cpp:2541 > +void Node::showTreeForThisDeeply() const
Deeply sounds like a wrong word. What are you trying to communicate here?
Ryosuke Niwa
Comment 10
2011-05-20 11:19:52 PDT
Comment on
attachment 94179
[details]
WIP - add universalTraverseNextNode View in context:
https://bugs.webkit.org/attachment.cgi?id=94179&action=review
> Source/WebCore/dom/Node.cpp:1137 > +Node* Node::traverseNextNodeConsideringFrameAndShadow() const
Considering frame and shadow sound misleading because we certainly consider the existence of frame and shadow whenever we traverse nodes. Maybe traverseNextNodeAcrossFrameAndShadow?
> Source/WebCore/dom/Node.cpp:1142 > + if (shadowRoot(this)) > + return shadowRoot(this)->traverseNextNodeConsideringFrameAndShadow();
I would have saved the shadowRoot as a pointer here to avoid accessing rare data twice.
>>> Source/WebCore/dom/Node.cpp:1143 >>> + if (renderer() && renderer()->isTextControl()) { >> >> Once the conversion to new-style shadow DOM is finished, this shouldn't be necessary anymore :) > > Thank you for the info. I am assuming that we should have it as of now :)
The patch has been r+ed so it'll probably be landed before this patch gets r+.
> Source/WebCore/dom/Node.cpp:1157 > + if (nextSibling()) > + return nextSibling(); > + const Node* n = this; > + while (n && !n->nextSibling()) > + n = n->parentOrHostOrFrameNode(); > + if (n) > + return n->nextSibling(); > + return 0;
Why don't we just call traverseNextNode here instead? I would not like to see code duplication like this.
Hayato Ito
Comment 11
2011-05-22 19:21:56 PDT
Thank you for the review. As Roland said, this patch should be discussed in an another bug. It turned out that this patch is not so useful for tab traversing for focus (
bug 54441
), I don't have a strong reason to submit this anymore. I'll address your comments if I need this patch again. But that should be in an another bug. Thank you. (In reply to
comment #10
)
> (From update of
attachment 94179
[details]
) > View in context:
https://bugs.webkit.org/attachment.cgi?id=94179&action=review
> > > Source/WebCore/dom/Node.cpp:1137 > > +Node* Node::traverseNextNodeConsideringFrameAndShadow() const > > Considering frame and shadow sound misleading because we certainly consider the existence of frame and shadow whenever we traverse nodes. > > Maybe traverseNextNodeAcrossFrameAndShadow? > > > Source/WebCore/dom/Node.cpp:1142 > > + if (shadowRoot(this)) > > + return shadowRoot(this)->traverseNextNodeConsideringFrameAndShadow(); > > I would have saved the shadowRoot as a pointer here to avoid accessing rare data twice. > > >>> Source/WebCore/dom/Node.cpp:1143 > >>> + if (renderer() && renderer()->isTextControl()) { > >> > >> Once the conversion to new-style shadow DOM is finished, this shouldn't be necessary anymore :) > > > > Thank you for the info. I am assuming that we should have it as of now :) > > The patch has been r+ed so it'll probably be landed before this patch gets r+. > > > Source/WebCore/dom/Node.cpp:1157 > > + if (nextSibling()) > > + return nextSibling(); > > + const Node* n = this; > > + while (n && !n->nextSibling()) > > + n = n->parentOrHostOrFrameNode(); > > + if (n) > > + return n->nextSibling(); > > + return 0; > > Why don't we just call traverseNextNode here instead? I would not like to see code duplication like this.
Dimitri Glazkov (Google)
Comment 12
2011-06-08 14:25:51 PDT
Closing per last comment.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug