[webkit-help] how webkit store root of dom tree

Adam Roben aroben at apple.com
Thu Jun 24 07:03:48 PDT 2010


On Jun 24, 2010, at 6:40 AM, Eric Zhou wrote:

> After parsing html, webkit should maintain a pointer pointing to the root of dom tree. I followed the parsing process, but the clue is broken at 
> HTMLTokenizer::State HTMLTokenizer::parseTag(SegmentedString& src, State state) --- in file htmlTokenizer.cpp.
> 
> To summarize this function:
> 
> HTMLTokenizer::State HTMLTokenizer::parseTag(SegmentedString& src, State state)
> {
> ...
> RefPtr<Node> n = processToken();
> ...
> }
> 
> where the "n" is the root node of dom tree. but after this "n" is not pointed by any other pointer and not passed out of this function.

> 
> My question is how webkit get the root of dom tree after this function?

processToken calls HTMLTreeBuilder::parseToken to create the Node. parseToken inserts the Node into the DOM before returning it. So by the time the Node is returned from processToken, it is already in the DOM.

HTMLTreeBuilder holds a pointer to a Document. From there you can work your way up to the DOMWindow, which is the root of the DOM.

-Adam



More information about the webkit-help mailing list