顾名思义,WebPage就是指网页。这一点也可以从Webkit的WebCore的架构看出来:WebCore->page。在page目录下,实现了一些DOM的全局对象,比如Window,Timer,popup窗口,DOM的选择,焦点的控制、history等等。
总之,与WebView类似,WebPage就是WebCore用来编辑、查看网页内容的对象。
WebCore::page:
void setMainFrame();
Frame* mainFrame() const ;
BackForwardList* backForwardList() const;
bool goBack();
bool goForward();
bool canGoBackOrForward(int distance) const;
page的以下类的定义,需要平台实现,使得page具有缺省的client:
struct PageClients {
WTF_MAKE_NONCOPYABLE(PageClients); WTF_MAKE_FAST_ALLOCATED;
public:
PageClients();
~PageClients();
AlternativeTextClient* alternativeTextClient;
ChromeClient* chromeClient;
#if ENABLE(CONTEXT_MENUS)
ContextMenuClient* contextMenuClient;
#endif
EditorClient* editorClient;
DragClient* dragClient;
InspectorClient* inspectorClient;
RefPtr<BackForwardList> backForwardClient;
};
我们来看看Qt是如何实现的,Qt实现了一个QWebPage,里面的一些方法是为了呈现page而定义的:
QWebFrame * | mainFrame () const |
QWebHistory * | history () const |
QWebFrame * | currentFrame () const |
bool | findText ( const QString & subString, FindFlags options = 0 ) |
bool | focusNextPrevChild ( bool next ) |
bool | forwardUnsupportedContent () const |
QWebFrame * | frameAt ( const QPoint & pos ) const |
bool | hasSelection () const |
在QWebPagePrivate构造函数里,它会为WebCore::page构造这几个client:
Page::PageClients pageClients;
pageClients.chromeClient = new ChromeClientQt(q);
pageClients.contextMenuClient = new ContextMenuClientQt();
pageClients.editorClient = new EditorClientQt(q);
pageClients.dragClient = new DragClientQt(q);
pageClients.inspectorClient = new InspectorClientQt(q);
page = new Page(pageClients);
#0 WebCore::ChromeClientQt::ChromeClientQt (this=0xafde60, webPage=0xb08500)
at /opt/src/opt/src/mp50/framework/webkit/WebKit_123412/Source/WebKit/qt/WebCoreSupport/ChromeClientQt.cpp:94
#1 0x00007ffff563aaf1 in QWebPagePrivate::QWebPagePrivate (this=0xac3ac0, qq=0xb08500)
at /opt/src/opt/src/mp50/framework/webkit/WebKit_123412/Source/WebKit/qt/Api/qwebpage.cpp:326
#2 0x00007ffff56406c4 in QWebPage::QWebPage (this=0xb08500, parent=0xafde00)
at /opt/src/opt/src/mp50/framework/webkit/WebKit_123412/Source/WebKit/qt/Api/qwebpage.cpp:1935
#3 0x000000000046cc2c in WebPage::WebPage (this=0xb08500, parent=0xafde00) at webview.cpp:68
#4 0x000000000046df5c in WebView::WebView (this=0xafde00, parent=0x0) at webview.cpp:200
#5 0x0000000000466330 in TabWidget::newTab (this=0x90b080, makeCurrent=true) at tabwidget.cpp:446
#6 0x0000000000465f39 in TabWidget::webView (this=0x90b080, index=0) at tabwidget.cpp:394
#7 0x0000000000465a3b in TabWidget::currentChanged (this=0x90b080, index=0) at tabwidget.cpp:299
#8 0x0000000000466300 in TabWidget::newTab (this=0x90b080, makeCurrent=true) at tabwidget.cpp:441
#9 0x0000000000431622 in BrowserMainWindow::BrowserMainWindow (this=0x90b130, parent=0x0, flags=...) at browsermainwindow.cpp:146
#10 0x000000000042f5a1 in BrowserApplication::newMainWindow (this=0x7fffffffdd50) at browserapplication.cpp:372
#11 0x000000000047180a in main (argc=2, argv=0x7fffffffde78) at main.cpp:50