Mozilla研究—XUL視窗建立和事件處理

來源:互聯網
上載者:User

Mozilla研究—XUL視窗建立和事件處理

 

轉載時請註明出處和作者連絡方式:http://blog.csdn.net/absurd

作者連絡方式:李先靜<xianjimli at hotmail dot com>

更新時間:2007-3-25

 

mozilla是一個以瀏覽器為中心的軟體平台,它在我們平台中佔有重要地位。我們用它來實現WEB瀏覽器、WAP瀏覽器、郵件系統、電子書和協助閱讀器等應用程式。為此,我最近花了不少時間去閱讀mozilla的代碼和文檔,我將寫一系列的BLOG作為筆記,供有需要的朋友參考。本文介紹視窗建立和事件處理。

 

視窗建立

1.         對於提示視窗,像javascript中的alert/confirm等函數所開啟的。其過程如下:nsPromptService::DoDialogànsWindowWatcher::OpenWindowànsXULWindow::ShowModal。如果想要定製提示視窗的行為,比如在命令列下提示,可以重新實現nsIPromptService2/nsPIPromptService介面。

2.         對於正常視窗,其建立過程如下:nsWindowWatcher::OpenWindowà WindowCreator::CreateChromeWindow2ànsWindowConstructor。

 

視窗關閉

1.         在javascript中調用close函數關閉視窗。

2.         經XPConnect調用nsGlobalWindow::Close。

3.         nsGlobalWindow::Close調用nsGlobalWindow::ReallyCloseWindow去關閉視窗。

 

事件註冊

1.         在XUL文檔解析完成之後,nsXULDocument::PrepareToWalk去建立所有的nsXULElement。

2.         nsXULElement::Create調用nsXULElement::AddScriptEventListener去註冊事件處理函數。

3.         nsXULElement::AddScriptEventListener調用nsEventListenerManager:: AddScriptEventListener去註冊事件處理函數。

4.         nsEventListenerManager::AddScriptEventListener經nsJSContext,最終調用NS_NewJSEventListener去把javascript事件處理函數封裝成nsIDOMEventListener,並註冊到nsEventListenerManager中。

 

事件分發

1.         nsWindow.cpp 中的xxx_event_cb之類的函數把GTK+的事件轉寄給nsWindow::OnXxxEvent函數。

2.         nsCommonWidget::DispatchEvent把事件轉寄View註冊的回呼函數HandleEvent。

3.         nsView.cpp: HandleEvent通過事件的Widget找到當前的View,再找到對應的ViewManager,然後通過nsViewManager::DispatchEvent分發訊息。

4.         nsViewManager通過PresShell把訊息轉寄到對應的nsXULElement。

5.         nsXULElement通過nsEventListenerManager把訊息轉寄到nsJSEventListener。

6.         nsJSEventListener::HandleEvent再經javascript解譯器調用javascript的事件處理函數。

 

~~end~~

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.