- 论坛徽章:
- 0
|
@auth:gulunmu@163.com
@date:2008-04-13
@des:linux下应用gtkmozembed+gtk嵌入firefox,处理绘图完成后的dom树
code: test.cpp
#include <gtk/gtk.h>
#include <gtkmozembed.h>
#include "gtkmozembed_internal.h"
//#include "MozillaBrowserXPCOM.h"
//#include "XPCOMUtil.h"
#include <nsIURIContentListener.h>
#include <nsIWebBrowser.h>
#include "nsXPCOM.h"
#include "nscore.h"
#include "nsEmbedAPI.h"
#include "nsWeakReference.h"
#include "nsIWebBrowserChrome.h"
#include "nsIEmbeddingSiteWindow.h"
#include "nsCOMPtr.h"
#include "nsIInterfaceRequestor.h"
#include "nsEmbedString.h"
#include "nsIWebBrowser.h"
#include "widget/nsIBaseWindow.h"
#include "nsEmbedCID.h"
#include "nsComponentManagerUtils.h"
#include "nsIWebProgressListener.h"
#include "docshell/nsIWebNavigation.h"
#include "docshell/nsIDocShellTreeItem.h"
#include "iostream"
//dom
#include <nsIDOMCSSStyleDeclaration.h>
#include <nsIDOMDocument.h>
#include <nsIDOMDocumentFragment.h>
#include <nsIDOMDocumentRange.h>
#include <nsIDOMElement.h>
#include <nsIDOMElementCSSInlineStyle.h>
#include <nsIDOMMouseEvent.h>
//#include "nsIDOMNSHTMLElement.h"
//#include "nsIDOMNSRange.h"
#include <nsIDOMNodeList.h>
#include <nsIDOMRange.h>
#include <nsIDOMWindow.h>
#define HAS_WEBBROWSER 1
//extern void gtk_moz_embed_get_nsIWebBrowser(GtkMozEmbed *embed, nsIWebBrowser **retval);
int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *label;
GtkWidget *mozembed;
GtkWidget *container;
char *url;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
///////////////////////////////////////////////////////
mozembed = gtk_moz_embed_new();
gtk_signal_connect(GTK_OBJECT(mozembed), "destroy",
GTK_SIGNAL_FUNC(gtk_main_quit),
NULL);
gtk_container_add(GTK_CONTAINER(window), mozembed);
/////////////////////////////////////////////////////
gtk_widget_set_usize(window, 800,600);
gtk_widget_show(mozembed);
gtk_widget_show(label);
gtk_widget_show_all(window);
//url = (argc > 1) ? argv[1] : (char *)"www.google.com";
//gtk_moz_embed_load_url(GTK_MOZ_EMBED(mozembed), url);
////////////////////////////////////////////////////
#ifdef HAS_WEBBROWSER
nsCOMPtr<nsIBaseWindow> baseWindow;
nsCOMPtr<nsIWebBrowser> webBrowser;
nsresult rv;
gtk_moz_embed_get_nsIWebBrowser(GTK_MOZ_EMBED(mozembed), getter_AddRefs(webBrowser));
if( webBrowser == nsnull )
{
printf("webBrowser load error ");
return -1;
}
nsCOMPtr<nsIWebNavigation> webNav = do_QueryInterface(webBrowser, &rv);
if ( NS_FAILED(rv) ) return rv;
printf(" get nsIWebNavigation success.\n");
baseWindow = do_QueryInterface(webBrowser, &rv);
if ( NS_FAILED(rv) ) return rv;
printf("baseWindow queried.\n");
char asciiURI[] = "http://www.baidu.com";
nsString nsURI = NS_ConvertUTF8toUTF16( asciiURI, strlen(asciiURI) );
if(webNav)
webNav->LoadURI(nsURI.get(),
nsIWebNavigation::LOAD_FLAGS_NONE, // Load flags
nsnull, // Referring URI
nsnull, // Post data
nsnull);
printf("load uri success.\n");
//begin to deal dom
nsCOMPtr<nsIDOMWindow> DOMWindow;
nsCOMPtr<nsIDOMDocument> DOMDocument;
webBrowser->GetContentDOMWindow(getter_AddRefs(DOMWindow));
if(nsnull == DOMWindow) {
g_warning("could not retrieve DOM window...");
return -1;
}
rv = DOMWindow->GetDocument(getter_AddRefs(DOMDocument));
if( NS_FAILED(rv)) return rv;
//end ceal dom
#endif
//
////////////////////////////////////////////////////
gtk_main();
return 0;
}
makefile:
MOZ_ROOT=/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 -DDEGUG -D_DEBUG -DDEBUG_root -DTRACTING -fno-inline -O -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 ${MOZ_ROOT}/../config/gcc_hidden.h -DMOZILLA_STRICT_API -DOSTYPE="Linux2.6.23.1" -DOSARCH="Linux" -DBUILD_ID=0000000000 -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: TTest
#TTest: test.o
# g++ -o TTest $(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
TTest: test.o
g++ -o TTest $(LDFLAGS) `pkg-config --libs gtk+-2.0` test.o ${MOZ_ROOT}/embedding/base/libembed_base_s.a -L${MOZ_ROOT}/dist/lib -lxpcomglue ${MOZ_ROOT}/embedding/base/libembed_base_s.a -lgtkembedmoz
test.o:test.cpp
g++ -c $(CXXFLAGS) $(COMPILE_CFLAGS) `pkg-config --cflags gtk+-2.0` $< -o $@
clean:
rm *.o TTest |
|