webkit page对象分析

http://blog.csdn.net/shunzi__1984/article/details/6243767

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的代码

  1. class HostWindow : public Noncopyable {  
  2. public:  
  3.     virtual ~HostWindow() { }  
  4.   
  5.     // Requests the host invalidate the window, not the contents.  If immediate is true do so synchronously, otherwise async.  
  6.     virtual void invalidateWindow(const IntRect& updateRect, bool immediate) = 0;  
  7.   
  8.     // Requests the host invalidate the contents and the window.  If immediate is true do so synchronously, otherwise async.  
  9.     virtual void invalidateContentsAndWindow(const IntRect& updateRect, bool immediate) = 0;  
  10.   
  11.     // Requests the host scroll backingstore by the specified delta, rect to scroll, and clip rect.  
  12.     virtual void scroll(const IntSize& scrollDelta, const IntRect& rectToScroll, const IntRect& clipRect) = 0;  
  13.   
  14.     // Requests the host invalidate the contents, not the window.  This is the slow path for scrolling.  
  15.     virtual void invalidateContentsForSlowScroll(const IntRect& updateRect, bool immediate) = 0;  
  16.   
  17. #if ENABLE(TILED_BACKING_STORE)  
  18.     // Requests the host to do the actual scrolling. This is only used in combination with a tiled backing store.  
  19.     virtual void delegatedScrollRequested(const IntSize& scrollDelta) = 0;  
  20. #endif  
  21.   
  22.     // Methods for doing coordinate conversions to and from screen coordinates.  
  23.     virtual IntPoint screenToWindow(const IntPoint&) const = 0;  
  24.     virtual IntRect windowToScreen(const IntRect&) const = 0;  
  25.   
  26.     // Method for retrieving the native client of the page.  
  27.     virtual PlatformPageClient platformPageClient() const = 0;  
  28.       
  29.     // To notify WebKit of scrollbar mode changes.  
  30.     virtual void scrollbarsModeDidChange() const = 0;  
  31.   
  32.     // Request that the cursor change.  
  33.     virtual void setCursor(const Cursor&) = 0;  
  34. };  

 chrome中有一个ChromeClient,这个chromeClient都是由客户实现,这样webcore就能够和外面交互

附chrome代码

  1.  class Chrome : public HostWindow {  
  2.     public:  
  3.         Chrome(Page*, ChromeClient*);  
  4.         ~Chrome();  
  5.   
  6.         ChromeClient* client() { return m_client; }  
  7.   
  8.         // HostWindow methods.  
  9.   
  10.         virtual void invalidateWindow(const IntRect&, bool);  
  11.         virtual void invalidateContentsAndWindow(const IntRect&, bool);  
  12.         virtual void invalidateContentsForSlowScroll(const IntRect&, bool);  
  13.         virtual void scroll(const IntSize&, const IntRect&, const IntRect&);  
  14. #if ENABLE(TILED_BACKING_STORE)  
  15.         virtual void delegatedScrollRequested(const IntSize& scrollDelta);  
  16. #endif  
  17.         virtual IntPoint screenToWindow(const IntPoint&) const;  
  18.         virtual IntRect windowToScreen(const IntRect&) const;  
  19.         virtual PlatformPageClient platformPageClient() const;  
  20.         virtual void scrollbarsModeDidChange() const;  
  21.         virtual void setCursor(const Cursor&);  
  22.   
  23.         void scrollRectIntoView(const IntRect&) const;  
  24.   
  25.         void contentsSizeChanged(Frame*, const IntSize&) const;  
  26.   
  27.         void setWindowRect(const FloatRect&) const;  
  28.         FloatRect windowRect() const;  
  29.   
  30.         FloatRect pageRect() const;  
  31.           
  32.         float scaleFactor();  
  33.   
  34.         void focus() const;  
  35.         void unfocus() const;  
  36.   
  37.         bool canTakeFocus(FocusDirection) const;  
  38.         void takeFocus(FocusDirection) const;  
  39.   
  40.         void focusedNodeChanged(Node*) const;  
  41.         void focusedFrameChanged(Frame*) const;  
  42.   
  43.         Page* createWindow(Frame*, const FrameLoadRequest&, const WindowFeatures&, const NavigationAction&) const;  
  44.         void show() const;  
  45.   
  46.         bool canRunModal() const;  
  47.         bool canRunModalNow() const;  
  48.         void runModal() const;  
  49.   
  50.         void setToolbarsVisible(boolconst;  
  51.         bool toolbarsVisible() const;  
  52.           
  53.         void setStatusbarVisible(boolconst;  
  54.         bool statusbarVisible() const;  
  55.           
  56.         void setScrollbarsVisible(boolconst;  
  57.         bool scrollbarsVisible() const;  
  58.           
  59.         void setMenubarVisible(boolconst;  
  60.         bool menubarVisible() const;  
  61.           
  62.         void setResizable(boolconst;  
  63.   
  64.         bool canRunBeforeUnloadConfirmPanel();  
  65.         bool runBeforeUnloadConfirmPanel(const String& message, Frame* frame);  
  66.   
  67.         void closeWindowSoon();  
  68.   
  69.         void runJavaScriptAlert(Frame*, const String&);  
  70.         bool runJavaScriptConfirm(Frame*, const String&);  
  71.         bool runJavaScriptPrompt(Frame*, const String& message, const String& defaultValue, String& result);  
  72.         void setStatusbarText(Frame*, const String&);  
  73.         bool shouldInterruptJavaScript();  
  74.   
  75.         IntRect windowResizerRect() const;  
  76.   
  77.         void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags);  
  78.   
  79.         void setToolTip(const HitTestResult&);  
  80.   
  81.         void print(Frame*);  
  82.   
  83.         // FIXME: Remove once all ports are using client-based geolocation. https://bugs.webkit.org/show_bug.cgi?id=40373  
  84.         // For client-based geolocation, these two methods have moved to GeolocationClient. https://bugs.webkit.org/show_bug.cgi?id=50061  
  85.         void requestGeolocationPermissionForFrame(Frame*, Geolocation*);  
  86.         void cancelGeolocationPermissionRequestForFrame(Frame*, Geolocation*);  
  87.   
  88.         void runOpenPanel(Frame*, PassRefPtr<FileChooser>);  
  89.         void chooseIconForFiles(const Vector<String>&, FileChooser*);  
  90.   
  91.         void dispatchViewportDataDidChange(const ViewportArguments&) const;  
  92.   
  93.         bool requiresFullscreenForVideoPlayback();  
  94.   
  95. #if PLATFORM(MAC)  
  96.         void focusNSView(NSView*);  
  97. #endif  
  98.   
  99. #if ENABLE(NOTIFICATIONS)  
  100.         NotificationPresenter* notificationPresenter() const;   
  101. #endif  
  102.   
  103.         bool selectItemWritingDirectionIsNatural();  
  104.         PassRefPtr<PopupMenu> createPopupMenu(PopupMenuClient*) const;  
  105.         PassRefPtr<SearchPopupMenu> createSearchPopupMenu(PopupMenuClient*) const;  
  106.   
  107. #if ENABLE(CONTEXT_MENUS)  
  108.         void showContextMenu();  
  109. #endif  
  110.   
  111.     private:  
  112.         Page* m_page;  
  113.         ChromeClient* m_client;  
  114.     };  

其实chrome的大部分功能都是委托给chromeclient实现。

 

chrome中有一个接口名如下:

Page* Chrome::createWindow(Frame* frame, const FrameLoadRequest& request, const WindowFeatures& features, const NavigationAction& action) ;

其实就是创建一个新的窗口,那么在什么时候会用到此接口,比如打开一个新的标签页,这时候就需要创建一个新的窗口,所以,从这个角度来说,chromeclient就是为webcore里需要显示的内容提供一个场所,对需要涉及到的显示操作,提供一种实现。

WebChromeClient提供一种ChromeClient的实现,而实际的窗口相关的操作,都会定义在webview里面,所以不同的平台应该有不同WebView的实现。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值