免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4809 | 回复: 2
打印 上一主题 下一主题

如何嵌入gecko引擎 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-01-04 11:19 |只看该作者 |倒序浏览
由于工作需要,研究了一下gecko的引擎嵌入的问题,花了三天多的时间,总算成功让gecko在Gtk控件下正确显示网页了。其实并不复杂,如果能找对正确的做法。基本思路是:
  • 下载mozilla的cvs代码。参考moziila官方的说明。这里重要的是要选择checkout
    xulrunner。我在多次尝试后,发现只有xulrunner能够正常的运行自己写的demo和embedding的demo,当然官方提供的
    TestGtkEmbed在browser下跑时也会有问题,如果不想走弯路,xulrunner是正确的选择。.mozconfig参考如下:
       

    ff_topsrc=/mnt/sda2/devel/mozilla

    . ${ff_topsrc}/xulrunner/config/mozconfig

    mk_add_options MOZ_OBJDIR=${ff_topsrc}/xulrunner-build

    ac_add_options --enable-application=xulrunner

    ac_add_options --enable-optimize

    ac_add_options --enable-default-toolkit=cairo-gtk2

    ac_add_options --enable-xft

    ac_add_options --enable-shared

    ac_add_options --disable-static

    ac_add_options --enable-debug

    ac_add_options --enable-libxul

    ac_add_options --disable-tests

       
       

  • 编译xulrunner。编译的.mozconfig文件中记得按照xulrunner编写,必须enable libxul。

编译完成后,你可以在编译目录(MOZ_OBJDIR)下找到所有需要的嵌入依赖的库和头文件,官方的称呼大概是GRE。以下是一个最简单的demo参
考,可以正确编译和运行。我在embeding/config目录下make
showbuild得到makefile的框架,然后根据需要做了一下修改。估计不需要这么麻烦,现在也懒得管了。
Makefile如下:
MOZ_ROOT=/mnt/sda2/devel/mozilla/xulrunner-build
LDFLAGS=-lpthread  -Wl,-rpath -Wl,${MOZ_ROOT}/dist/bin/ -Wl,-rpath -Wl,${MOZ_ROOT}/dist/lib  
-L${MOZ_ROOT}/dist/lib/ -lxpcom -lnspr4
CXXFLAGS= -ggdb -fno-rtti -fno-exceptions -Wall -Wconversion -Wpointer-arith -Wcast-align
-Woverloaded-virtual -Wsynth -Wno-ctor-dtor-privacy -Wno-non-virtual-dtor -Wno-long-long -pedantic
-fshort-wchar -pthread -pipe  -DNDEBUG -DTRIMMED -O -I/usr/include/gtk-2.0 -I/usr/lib/gtk-2.0/include
-I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/glib-2.0
-I/usr/lib/glib-2.0/include -I/usr/include/freetype2 -I/usr/include/libpng12
COMPILE_CFLAGS= -I ${MOZ_ROOT}/dist/include/system_wrappers
-include /mnt/sda2/devel/mozilla/config/gcc_hidden.h -DMOZILLA_STRICT_API
-DOSTYPE="Linux2.6.22" -DOSARCH=Linux  -I ${MOZ_ROOT}/dist/include/xpcom
-I${MOZ_ROOT}/dist/include/intl -I${MOZ_ROOT}/dist/include/embedcomponents
-I${MOZ_ROOT}/dist/include   -I${MOZ_ROOT}/dist/include/embed_base
-I${MOZ_ROOT}/dist/include/nspr -I${MOZ_ROOT}/dist/include/gtkembedmoz
-DMOZ_PNG_READ -DMOZ_PNG_WRITE   -I${MOZ_ROOT}/dist/sdk/include
-Wall -W -Wno-unused -Wpointer-arith -Wcast-align -Wno-long-long -pedantic
-pthread -pipe  -DNDEBUG -DTRIMMED -O   -include ${MOZ_ROOT}/mozilla-config.h
-DMOZILLA_CLIENT

all: test

test: test.o
    g++ -o test $(LDFLAGS) `pkg-config --libs gtk+-2.0` test.o ${MOZ_ROOT}/embedding/base/libembed_base_s.a ${MOZ_ROOT}/xpcom/glue/standalone/libxpcomglue.a


${MOZ_ROOT}/embedding/base/libembed_base_s.a


test.o: test.cpp

        g++ -c $(CXXFLAGS) $(COMPILE_CFLAGS) `pkg-config --cflags gtk+-2.0` test.cpp


clean:

        rm *.o test

test.cpp如下:

       
        文件:test.tar
        大小:20KB
        下载:
下载
       
有几个关键问题是:
  • 我的目的是将gecko嵌入QT中,但是后来发现gecko的nsIBaseWindow在内部管理的窗口是gtk句柄的,因
    此你是没法直接使用Qt或者其他的非Gtk控件作为容器父控件的。所以正确的做法是用一个GtkWindow作为容器,然后再将此控件嵌入QT的控件中。
  • 正确理解nsCOMPtr、nsWeakPtr等对象管理方法。错误的使用可能导致莫名奇妙的问题。
  • 更好的方法也可以是使用mozilla提供的libxpcomglue来作嵌入的初始化,它将帮组用户找到正确的GRE。
  • 如果要运行TestGtkEmbed,记住要export GRE_HOME=${MOZ_OBJDIR}/dist/bin/ 来指定GRE的目录。没有这一步,会提示说找不到GRE。然后在此目录使用./run-mozilla.sh ./TestGetEmbed运行测试。
                   
                   
                   

    本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/58649/showart_456395.html
  • 论坛徽章:
    0
    2 [报告]
    发表于 2017-06-12 18:30 |只看该作者
    他山界面开发框架 v22是一套基于Gecko v22 的开源收费跨平台界面解决方案。可使用xul, html(5), css(3), js 开发界面,支持js, c++互调,发行包大小13MB 。

    论坛徽章:
    0
    3 [报告]
    发表于 2017-06-12 19:06 |只看该作者
    他山界面开发框架 v22是一套基于Gecko v22 的开源收费跨平台界面解决方案。可使用xul, html(5), css(3), js 开发界面,支持js, c++互调,发行包大小13MB 。
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则 发表回复

      

    北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
    未成年举报专区
    中国互联网协会会员  联系我们:huangweiwei@itpub.net
    感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

    清除 Cookies - ChinaUnix - Archiver - WAP - TOP