查看RenderObject樹的內部表示,查看renderobject樹

來源:互聯網
上載者:User

查看RenderObject樹的內部表示,查看renderobject樹

      有時候我們需要知道自己寫的頁面排版的具體細節,DumpRenderTree是個不錯工具。它位於WebKit/WebKitBuild/[Debug|Release]/bin目錄下,直接運行會出錯:

gdb ./DumpRenderTree

./DumpRenderTree http://192.168.1.100/BoxModeofCSS.html


[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGABRT, Aborted.
0x00007ffff2e89cc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
56 ../nptl/sysdeps/unix/sysv/linux/raise.c: 沒有那個檔案或目錄.

    查看callstack:


(gdb) bt
#0  0x00007ffff2e89cc9 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56
#1  0x00007ffff2e8d0d8 in __GI_abort () at abort.c:89
#2  0x00007ffff37c3247 in qt_message_output (msgType=QtFatalMsg, 
    buf=0x654758 "\n\n", '-' <repeats 70 times>, "\nWEBKIT_TESTFONTS environment variable is not set correctly.\nThis variable has to point to the directory containing the fonts\nyo"...) at Qt/src/corelib/global/qglobal.cpp:2323
#3  0x00007ffff37c32f2 in qt_message(QtMsgType, const char *, typedef __va_list_tag __va_list_tag *) (msgType=QtFatalMsg, 
    msg=0x42ebc0 "\n\n", '-' <repeats 70 times>, "\nWEBKIT_TESTFONTS environment variable is not set correctly.\nThis variable has to point to the directory containing the fonts\nyo"..., ap=0x7fffffffd998) at Qt/src/corelib/global/qglobal.cpp:2369
#4  0x00007ffff37c389a in qFatal (
    msg=0x42ebc0 "\n\n", '-' <repeats 70 times>, "\nWEBKIT_TESTFONTS environment variable is not set correctly.\nThis variable has to point to the directory containing the fonts\nyo"...) at Qt/src/corelib/global/qglobal.cpp:2552
#5  0x0000000000425432 in WebKit::initializeTestFonts () Tools/DumpRenderTree/qt/QtInitializeTestFonts.cpp:62
#6  0x0000000000426bf0 in main (argc=2, argv=0x7fffffffdda8) Tools/DumpRenderTree/qt/main.cpp:147


     原來是沒有依賴的字型,隨便找一個字型:locate fonts.conf

WebKit-r174650/Tools/WebKitTestRunner/gtk/fonts/fonts.conf
WebKit/Tools/DumpRenderTree/chromium/fonts.conf
WebKit/Tools/DumpRenderTree/gtk/fonts/fonts.conf

export WEBKIT_TESTFONTS=/opt/src/webkit/Tools/DumpRenderTree/gtk/fonts/

這回就可以運行了:

./DumpRenderTree http://192.168.1.100/BoxModelofCSS.html
ERROR: Application Cache Storage: failed to execute statement "DELETE FROM CacheGroups" error "no such table: CacheGroups"
webkit/Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp(561) : bool WebCore::ApplicationCacheStorage::executeSQLCommand(const WTF::String&)
ERROR: Application Cache Storage: failed to execute statement "DELETE FROM Caches" error "no such table: Caches"
webkit//Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp(561) : bool WebCore::ApplicationCacheStorage::executeSQLCommand(const WTF::String&)
ERROR: Application Cache Storage: failed to execute statement "DELETE FROM Origins" error "no such table: Origins"
webkit//Source/WebCore/loader/appcache/ApplicationCacheStorage.cpp(561) : bool WebCore::ApplicationCacheStorage::executeSQLCommand(const WTF::String&)
Source:

<html><head>

<style type="text/css">
#adiv /*id 选æ‹å¨*/
{
width: 300px;
background-color: #efefef;
border: 10px solid black;
}
</style>
<style type="text/css">
.aclass /*class 选æ‹å¨*/
{
border: 5px solid red;
margin: 150px 100px 10px 40px;
padding: 15px 20px 25px 30px;
color: rgb(250,0,0);
}
</style>

</head>
<body>

<p>This layout mechanizm of CSS</p>
<div id="adiv">
<div class="aclass"> A B C D E F G H I J K L M N O P Q R S T</div>
</div>
</body></html>
Content-Type: text/plain
layer at (0,0) size 800x600
  RenderView at (0,0) size 800x600
layer at (0,0) size 800x600
  RenderBlock {HTML} at (0,0) size 800x600
    RenderBody {BODY} at (8,8) size 784x584
      RenderBlock {P} at (0,0) size 784x17
        RenderText {#text} at (0,0) size 448x17
          text run at (0,0) width 448: "This layout mechanizm of CSS"
      RenderBlock {DIV} at (0,33) size 320x349 [bgcolor=#EFEFEF] [border: (10px solid #000000)]
        RenderBlock {DIV} at (50,160) size 160x169 [color=#FA0000] [border: (5px solid #FF0000)]
          RenderText {#text} at (35,20) size 80x119
            text run at (35,20) width 80: "A B C"
            text run at (35,37) width 80: "D E F"
            text run at (35,54) width 80: "G H I"
            text run at (35,71) width 80: "J K L"
            text run at (35,88) width 80: "M N O"
            text run at (35,105) width 80: "P Q R"
            text run at (35,122) width 48: "S T"
#EOF
#EOF
#EOF
LEAK: 26 WebCoreNode

    紅色的是有些錯誤,別理他,沒事。藍色的是我寫的頁面,紫色的就是我們要的RenderObject樹,可視化的頁面元素列印也是按照樹型排列,好看吧。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.