HybridOS Specification 01-E Topic: WebKit Rendering and Drawing Author: Lionel gao Category: App Development Date: July 2019 Status: Proposal
Copyright Notice
Copyright (C) 2018, 2019 [FMSoft Technologies] All Rights Reserved.
Introduction
When the html document is downloaded, WebKit parses it's contents and generates the DOM-NODE tree (HTML-NODE tree), then parses the CSS style and HTML attributes, and generates the style objects of each node; then it generates the RenderObject of some node; RenderObject is responsible for rendering corresponding HTML nodes。 Here we focus on the rendering and rendering process.
Several explanations
-
Before RenderObject is generated, the CSS and HTML attributes of this node are known, and various attributes related to drawing are known. According to these attributes and the state of parent node and its sibling node, layout can be carried out to determine the drawing mode of the node and generate RenderObject objects.
-
The Render object generated by WebKit does not exactly correspond to the HTML tag one-to-one, but is related to the CSS attribute of the HTML tag. HTML tags such as tables have corresponding definitions in CSS. Therefore, in general, when adding a new HTML tag, the tag can be drawn by modifying the CSS attribute of the tag without adding RenderObject.
-
For drawing HTML plug-ins and Canvas tags, WebKit only reserves object's area, and then completes the specific drawing by plug-in code or Javascript itself.
-
For tags like view, that is, unlike plug-ins and Canvas tags, which cannot be defined using CSS attributes, a proprietary RenderObject object must be created.
-
Implementation of new HTML tag rendering: overload the member function createElementRenderer of base class in the new HTMLXXElement class under directory [WebCore/html]. If there is a CSS-related Render implementation, you can use it directly. Otherwise, you need to add the relevant Render implementation code in [WebCore/rendering], such as RenderHVMLView. Cpp and RenderHVMLView.h;
Main Steps to Realize
- Modify the file[WebCore/css/html.css],or add a new tag rule
- Override the function such as isPresentationAttribute,collectStyleForPresentationAttribute,addSubresourceAttributeURLs to support some attributes in files [WebCore/html/HTMLXXXXElement.cpp and HTMLXXXXElement.h]
- Use the createElementRenderer function's default realization or create a new render realized by ourself.
The code trace
- WebCore::HTMLViewElement::createElementRenderer (this=0x7fffc8303080, style=..., insertionPosition=...) at ../../Source/WebCore/html/HTMLViewElement.cpp:35
- 0x00007ffff15bb02e in WebCore::RenderTreeUpdater::createRenderer (this=0x7fffffffbff0, element=..., style=...) at ../../Source/WebCore/rendering/updating/RenderTreeUpdater.cpp:368
- 0x00007ffff15bad53 in WebCore::RenderTreeUpdater::updateElementRenderer (this=0x7fffffffbff0, element=..., update=...) at ../../Source/WebCore/rendering/updating/RenderTreeUpdater.cpp:328
- 0x00007ffff15ba45e in WebCore::RenderTreeUpdater::updateRenderTree (this=0x7fffffffbff0, root=...) at ../../Source/WebCore/rendering/updating/RenderTreeUpdater.cpp:192
- 0x00007ffff15b9e96 in WebCore::RenderTreeUpdater::commit (this=0x7fffffffbff0, styleUpdate=std::unique_ptr = {...}) at ../../Source/WebCore/rendering/updating/RenderTreeUpdater.cpp:120
- 0x00007ffff049994e in WebCore::Document::resolveStyle (this=0x7fffc8301ce0, type=WebCore::Document::ResolveStyleType::Normal) at ../../Source/WebCore/dom/Document.cpp:1950
- 0x00007ffff049a0ef in WebCore::Document::updateStyleIfNeeded (this=0x7fffc8301ce0) at ../../Source/WebCore/dom/Document.cpp:2055
- 0x00007ffff04aa3ce in WebCore::Document::finishedParsing (this=0x7fffc8301ce0) at ../../Source/WebCore/dom/Document.cpp:5693
- 0x00007ffff093d907 in WebCore::HTMLConstructionSite::finishedParsing (this=0x7fffcc776398) at ../../Source/WebCore/html/parser/HTMLConstructionSite.cpp:419
- 0x00007ffff098091a in WebCore::HTMLTreeBuilder::finished (this=0x7fffcc776378) at ../../Source/WebCore/html/parser/HTMLTreeBuilder.cpp:2843
- 0x00007ffff0941dfa in WebCore::HTMLDocumentParser::end (this=0x7fffc93fba00) at ../../Source/WebCore/html/parser/HTMLDocumentParser.cpp:428
- 0x00007ffff0941ec8 in WebCore::HTMLDocumentParser::attemptToRunDeferredScriptsAndEnd (this=0x7fffc93fba00) at ../../Source/WebCore/html/parser/HTMLDocumentParser.cpp:437
- 0x00007ffff0940aaf in WebCore::HTMLDocumentParser::prepareToStopParsing (this=0x7fffc93fba00) at ../../Source/WebCore/html/parser/HTMLDocumentParser.cpp:142
- 0x00007ffff0941f03 in WebCore::HTMLDocumentParser::attemptToEnd (this=0x7fffc93fba00) at ../../Source/WebCore/html/parser/HTMLDocumentParser.cpp:449
- 0x00007ffff0941fb3 in WebCore::HTMLDocumentParser::finish (this=0x7fffc93fba00) at ../../Source/WebCore/html/parser/HTMLDocumentParser.cpp:477
- 0x00007ffff0b502fe in WebCore::DocumentWriter::end (this=0x7fffcc7660b8) at ../../Source/WebCore/loader/DocumentWriter.cpp:273
- 0x00007ffff0b236b7 in WebCore::DocumentLoader::finishedLoading (this=0x7fffcc766000) at ../../Source/WebCore/loader/DocumentLoader.cpp:445
- 0x00007ffff0b2334a in WebCore::DocumentLoader::notifyFinished (this=0x7fffcc766000, resource=...) at ../../Source/WebCore/loader/DocumentLoader.cpp:392
- 0x00007ffff0c23f55 in WebCore::CachedResource::checkNotify (this=0x7fffc91f9000) at ../../Source/WebCore/loader/cache/CachedResource.cpp:352
- 0x00007ffff0c24052 in WebCore::CachedResource::finishLoading (this=0x7fffc91f9000) at ../../Source/WebCore/loader/cache/CachedResource.cpp:368
- 0x00007ffff0c2061a in WebCore::CachedRawResource::finishLoading (this=0x7fffc91f9000, data=0x7fffcc76c5e8) at ../../Source/WebCore/loader/cache/CachedRawResource.cpp:120
- 0x00007ffff0bd422a in WebCore::SubresourceLoader::didFinishLoading (this=0x7fffca1f9800, networkLoadMetrics=...) at ../../Source/WebCore/loader/SubresourceLoader.cpp:656
- 0x00007fffeece9cf6 in WebKit::WebResourceLoader::didFinishResourceLoad (this=0x7fffcc769740, networkLoadMetrics=...) at ../../Source/WebKit/WebProcess/Network/WebResourceLoader.cpp:164
- 0x00007fffee2d3ccf in IPC::callMemberFunctionImpl<WebKit::WebResourceLoader, void (WebKit::WebResourceLoader::)(WebCore::NetworkLoadMetrics const&), std::tupleWebCore::NetworkLoadMetrics, 0ul> ( object=0x7fffcc769740, function= (void (WebKit::WebResourceLoader::)(WebKit::WebResourceLoader * const, const WebCore::NetworkLoadMetrics &)) 0x7fffeece9c0a <WebKit::WebResourceLoader::didFinishResourceLoad(WebCore::NetworkLoadMetrics const&)>, args=...) at ../../Source/WebKit/Platform/IPC/HandleMessage.h:41
- 0x00007fffee2d35c5 in IPC::callMemberFunction<WebKit::WebResourceLoader, void (WebKit::WebResourceLoader::)(WebCore::NetworkLoadMetrics const&), std::tupleWebCore::NetworkLoadMetrics, std::integer_sequence<unsigned long, 0ul> > (args=..., object=0x7fffcc769740, function= (void (WebKit::WebResourceLoader::)(WebKit::WebResourceLoader * const, const WebCore::NetworkLoadMetrics &)) 0x7fffeece9c0a <WebKit::WebResourceLoader::didFinishResourceLoad(WebCore::NetworkLoadMetrics const&)>) at ../../Source/WebKit/Platform/IPC/HandleMessage.h:47
- 0x00007fffee2d2db1 in IPC::handleMessage<Messages::WebResourceLoader::DidFinishResourceLoad, WebKit::WebResourceLoader, void (WebKit::WebResourceLoader::)(WebCore::NetworkLoadMetrics const&)> ( decoder=..., object=0x7fffcc769740, function= (void (WebKit::WebResourceLoader::)(WebKit::WebResourceLoader * const, const WebCore::NetworkLoadMetrics &)) 0x7fffeece9c0a <WebKit::WebResourceLoader::didFinishResourceLoad(WebCore::NetworkLoadMetrics const&)>) at ../../Source/WebKit/Platform/IPC/HandleMessage.h:120
- 0x00007fffee2d22d7 in WebKit::WebResourceLoader::didReceiveWebResourceLoaderMessage (this=0x7fffcc769740, connection=..., decoder=...) at DerivedSources/WebKit/WebResourceLoaderMessageReceiver.cpp:64
- 0x00007fffeece3937 in WebKit::NetworkProcessConnection::didReceiveMessage (this=0x7fffcc7e80c0, connection=..., decoder=...) at ../../Source/WebKit/WebProcess/Network/NetworkProcessConnection.cpp:85
- 0x00007fffee5f7935 in IPC::Connection::dispatchMessage (this=0x7fffcc7e61e0, decoder=...) at ../../Source/WebKit/Platform/IPC/Connection.cpp:984
- 0x00007fffee5f7ac4 in IPC::Connection::dispatchMessage (this=0x7fffcc7e61e0, message=std::unique_ptrIPC::Decoder = {...}) at ../../Source/WebKit/Platform/IPC/Connection.cpp:1011
- 0x00007fffee5f8022 in IPC::Connection::dispatchOneIncomingMessage (this=0x7fffcc7e61e0) at ../../Source/WebKit/Platform/IPC/Connection.cpp:1080
- 0x00007fffee5f763b in IPC::Connection::<lambda()>::operator()(void) (__closure=0x7fffcc7d0058) at ../../Source/WebKit/Platform/IPC/Connection.cpp:962
- 0x00007fffee5ff74e in WTF::Detail::CallableWrapper<IPC::Connection::enqueueIncomingMessage(std::unique_ptrIPC::Decoder)::<lambda()>, void>::call(void) (this=0x7fffcc7d0050) at DerivedSources/ForwardingHeaders/wtf/Function.h:52
- 0x00007fffedff5bc6 in WTF::Function<void ()>::operator()() const (this=0x7fffffffce30) at DerivedSources/ForwardingHeaders/wtf/Function.h:79
- 0x00007fffdede815d in WTF::RunLoop::performWork (this=0x7fffcc7f8000) at ../../Source/WTF/wtf/RunLoop.cpp:106
- 0x00007fffdee61a98 in WTF::RunLoop::<lambda(gpointer)>::operator()(gpointer) const (__closure=0x0, userData=0x7fffcc7f8000) at ../../Source/WTF/wtf/glib/RunLoopGLib.cpp:68
- 0x00007fffdee61abc in WTF::RunLoop::<lambda(gpointer)>::_FUN(gpointer) () at ../../Source/WTF/wtf/glib/RunLoopGLib.cpp:70
- 0x00007fffdee61a4a in WTF::<lambda(GSource*, GSourceFunc, gpointer)>::operator()(GSource *, GSourceFunc, gpointer) const (__closure=0x0, source=0x5555556ba400, callback=0x7fffdee61a9f <WTF::RunLoop::<lambda(gpointer)>::_FUN(gpointer)>, userData=0x7fffcc7f8000) at ../../Source/WTF/wtf/glib/RunLoopGLib.cpp:45
- 0x00007fffdee61a79 in WTF::<lambda(GSource*, GSourceFunc, gpointer)>::_FUN(GSource *, GSourceFunc, gpointer) () at ../../Source/WTF/wtf/glib/RunLoopGLib.cpp:46
- 0x00007fffe10b69e5 in g_main_dispatch () at ../../Source/glib-2.58.1/glib/gmain.c:3182
- g_main_context_dispatch () at ../../Source/glib-2.58.1/glib/gmain.c:3847
- 0x00007fffe10b6db0 in g_main_context_iterate () at ../../Source/glib-2.58.1/glib/gmain.c:3920 ---Type to continue, or q to quit---
- 0x00007fffe10b70c2 in g_main_loop_run () at ../../Source/glib-2.58.1/glib/gmain.c:4116
- 0x00007fffdee61fa7 in WTF::RunLoop::run () at ../../Source/WTF/wtf/glib/RunLoopGLib.cpp:96
- 0x00007fffeef19c30 in WebKit::AuxiliaryProcessMain<WebKit::WebProcess, WebKit::WebProcessMain> (argc=3, argv=0x7fffffffd248) at ../../Source/WebKit/Shared/unix/AuxiliaryProcessMain.h:66
- 0x00007fffeef19ad0 in WebKit::WebProcessMainUnix (argc=3, argv=0x7fffffffd248) at ../../Source/WebKit/WebProcess/gtk/WebProcessMainGtk.cpp:67
- 0x0000555555554925 in main (argc=3, argv=0x7fffffffd248) at ../../Source/WebKit/WebProcess/EntryPoint/unix/WebProcessMain.cpp:52