webkit Page对象的分析
Page对象是webkit的核心对象之一,顾名思义,Page数据结构就是描述览器上我们打开的一个页面,这样一个页面包括很多部分,比如菜单控制,拖拽控制,页面显示,以及一些参数设置等。所以webkit中的Page对象里面也对应很多这样相关的对象,下面是一张表示这些对象关系的类图。
从上图中可以看出,Page里面主要是一些对象的组合,Page自身的代码并不是很多,里面的对象根据名字大概能够猜出个一二,下面主要讲一下两个比较重要的对象.
1. Frame
Frame应该是webcore里面最重要的一个核心对象,从page的角度上来看,页面就是有众多的Frame构成,当然,一定会有一个主Frame,Page中持有的这个Frame就是主Frame,也就是RootFrame,这个对象比较复杂,后面我会单独拿出来分析。
2. chrome
chrome是与显示相关的一个对象,比如刷新页面窗口,滚动窗口等,就会用到chrome中的接口,chrome也是连接webcore与webkit(指webkit的port部分)的核心对象。下面是一个关于chrome的类图
大家看到,chrome是继承自HostWindow,就是表示一个宿主窗口,这里贴出HostWindow的代码
- classHostWindow:publicNoncopyable{
- public:
- virtual~HostWindow(){}
- //Requeststhehostinvalidatethewindow,notthecontents.Ifimmediateistruedososynchronously,otherwiseasync.
- virtualvoidinvalidateWindow(constIntRect&updateRect,boolimmediate)=0;
- //Requeststhehostinvalidatethecontentsandthewindow.Ifimmediateistruedososynchronously,otherwiseasync.
- virtualvoidinvalidateContentsAndWindow(constIntRect&updateRect,boolimmediate)=0;
- //Requeststhehostscrollbackingstorebythespecifieddelta,recttoscroll,andcliprect.
- virtualvoidscroll(constIntSize&scrollDelta,constIntRect&rectToScroll,constIntRect&clipRect)=0;
- //Requeststhehostinvalidatethecontents,notthewindow.Thisistheslowpathforscrolling.
- virtualvoidinvalidateContentsForSlowScroll(constIntRect&updateRect,boolimmediate)=0;
- #ifENABLE(TILED_BACKING_STORE)
- //Requeststhehosttodotheactualscrolling.Thisisonlyusedincombinationwithatiledbackingstore.
- virtualvoiddelegatedScrollRequested(constIntSize&scrollDelta)=0;
- #endif
- //Methodsfordoingcoordinateconversionstoandfromscreencoordinates.
- virtualIntPointscreenToWindow(constIntPoint&)const=0;
- virtualIntRectwindowToScreen(constIntRect&)const=0;
- //Methodforretrievingthenativeclientofthepage.
- virtualPlatformPageClientplatformPageClient()const=0;
- //TonotifyWebKitofscrollbarmodechanges.
- virtualvoidscrollbarsModeDidChange()const=0;
- //Requestthatthecursorchange.
- virtualvoidsetCursor(constCursor&)=0;
- };
chrome中有一个ChromeClient,这个chromeClient都是由客户实现,这样webcore就能够和外面交互
附chrome代码
其实chrome的大部分功能都是委托给chromeclient实现。
chrome中有一个接口名如下:Page* Chrome::createWindow(Frame* frame, const FrameLoadRequest& request, const WindowFeatures& features, const NavigationAction& action) ;
其实就是创建一个新的窗口,那么在什么时候会用到此接口,比如打开一个新的标签页,这时候就需要创建一个新的窗口,所以,从这个角度来说,chromeclient就是为webcore里需要显示的内容提供一个场所,对需要涉及到的显示操作,提供一种实现。
WebChromeClient提供一种ChromeClient的实现,而实际的窗口相关的操作,都会定义在webview里面,所以不同的平台应该有不同WebView的实现。