Adding gtk embedding test application.

a=valeski@netscape.com - bug 43055
This commit is contained in:
dougt%netscape.com 2000-07-20 01:12:25 +00:00
parent 4777056ad6
commit 98c1304cbd
7 changed files with 377 additions and 3 deletions

View File

@ -706,9 +706,9 @@ embedding/browser/gtk/tests/Makefile
embedding/browser/photon/Makefile
embedding/browser/photon/src/Makefile
embedding/browser/photon/tests/Makefile
embedding/config/Makefile
embedding/tests/gtkEmbed/Makefile
"
#embedding/config/Makefile
#embedding/tests/gtkEmbed/Makefile
MAKEFILES_security="
security/Makefile

View File

@ -25,6 +25,6 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS=base browser
DIRS=base browser tests/gtkEmbed
include $(topsrcdir)/config/rules.mk

View File

@ -0,0 +1 @@
Makefile

View File

@ -0,0 +1,56 @@
#
# The contents of this file are subject to the Mozilla Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is the Mozilla browser.
#
# The Initial Developer of the Original Code is Christopher
# Blizzard. Portions created by Christopher Blizzard are
# Copyright (C) 1999, Mozilla. All Rights Reserved.
#
# Contributor(s):
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
CPPSRCS = WebBrowser.cpp \
main.cpp \
$(NULL)
PROGRAM = gtkEmbed
LIBS= \
$(DIST)/lib/libembed_base_s.$(LIB_SUFFIX) \
$(MOZ_COMPONENT_LIBS) \
-lgtksuperwin \
$(NULL)
ifndef MOZ_MONOLITHIC_TOOLKIT
EXTRA_DSO_LDOPTS += $(MOZ_GTK_LDFLAGS)
else
EXTRA_DSO_LDOPTS += $(TK_LIBS)
endif
include $(topsrcdir)/config/rules.mk
CXXFLAGS += $(MOZ_GTK_CFLAGS)

View File

@ -0,0 +1,170 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Doug Turner <dougt@netscape.com>
*/
#include "WebBrowser.h"
#include "nsCWebBrowser.h"
#include "nsWidgetsCID.h"
#include "nsIGenericFactory.h"
#include "nsString.h"
#include "nsXPIDLString.h"
#include "nsIURI.h"
#include "nsIWebProgress.h"
#include "nsIWebNavigation.h"
#include "nsIDocShell.h"
#include "nsIContentViewer.h"
#include "nsIContentViewerFile.h"
#include "nsIDocShell.h"
#include "nsIWebNavigation.h"
#include "nsIEditorShell.h"
#include "nsIDOMWindow.h"
#include "nsIScriptGlobalObject.h"
#include "nsIInterfaceRequestor.h"
#include "nsIDocShellTreeItem.h"
#include "nsIDocShellTreeOwner.h"
nsresult
ConvertDocShellToDOMWindow(nsIDocShell* aDocShell, nsIDOMWindow** aDOMWindow)
{
if (!aDOMWindow)
return NS_ERROR_FAILURE;
*aDOMWindow = nsnull;
nsCOMPtr<nsIScriptGlobalObject> scriptGlobalObject(do_GetInterface(aDocShell));
nsCOMPtr<nsIDOMWindow> domWindow(do_QueryInterface(scriptGlobalObject));
if (!domWindow)
return NS_ERROR_FAILURE;
*aDOMWindow = domWindow.get();
NS_ADDREF(*aDOMWindow);
return NS_OK;
}
WebBrowser::WebBrowser(){}
WebBrowser::~WebBrowser()
{
PRBool duh;
if (mEditor) // not good place for it!
mEditor->SaveDocument(PR_FALSE, PR_FALSE, &duh);
}
nsresult
WebBrowser::Init(nsNativeWidget widget, nsIWebBrowserChrome* aTopWindow)
{
nsresult rv;
mWebBrowser = do_CreateInstance(NS_WEBBROWSER_PROGID, &rv);
if (!mWebBrowser)
return NS_ERROR_FAILURE;
mBaseWindow = do_QueryInterface(mWebBrowser);
mTopWindow = aTopWindow;
mWebBrowser->SetTopLevelWindow(aTopWindow);
nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface(mWebBrowser);
dsti->SetItemType(nsIDocShellTreeItem::typeChromeWrapper);
rv = mBaseWindow->InitWindow( widget,
nsnull,
0,
0,
100,
100);
mBaseWindow->Create();
mBaseWindow->SetVisibility(PR_TRUE);
return rv;
}
nsresult
WebBrowser::GetWebBrowser(nsIWebBrowser **outBrowser)
{
*outBrowser = mWebBrowser;
NS_IF_ADDREF(*outBrowser);
return NS_OK;
}
nsresult
WebBrowser::GoTo(char* url)
{
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(mWebBrowser));
return webNav->LoadURI(NS_ConvertASCIItoUCS2(url).GetUnicode());
}
nsresult
WebBrowser::Edit(char* url)
{
nsresult rv;
mEditor = do_CreateInstance("component://netscape/editor/editorshell", &rv);
if (NS_FAILED(rv)) return rv;
nsCOMPtr <nsIDocShell> rootDocShell;
mWebBrowser->GetDocShell(getter_AddRefs(rootDocShell));
nsCOMPtr<nsIDOMWindow> domWindow;
ConvertDocShellToDOMWindow(rootDocShell, getter_AddRefs(domWindow));
mEditor->Init();
mEditor->SetEditorType(NS_ConvertASCIItoUCS2("html").GetUnicode());
mEditor->SetWebShellWindow(domWindow);
mEditor->SetContentWindow(domWindow);
return mEditor->LoadUrl(NS_ConvertASCIItoUCS2(url).GetUnicode());
}
nsresult
WebBrowser::Print(void)
{
nsCOMPtr <nsIDocShell> rootDocShell;
mWebBrowser->GetDocShell(getter_AddRefs(rootDocShell));
nsIContentViewer *pContentViewer = nsnull;
nsresult res = rootDocShell->GetContentViewer(&pContentViewer);
if (NS_SUCCEEDED(res))
{
nsCOMPtr<nsIContentViewerFile> spContentViewerFile = do_QueryInterface(pContentViewer);
spContentViewerFile->Print(PR_TRUE, nsnull);
NS_RELEASE(pContentViewer);
}
return NS_OK;
}
nsresult
WebBrowser::SetPositionAndSize(int x, int y, int cx, int cy)
{
return mBaseWindow->SetPositionAndSize(x, y, cx, cy, true);
}

View File

@ -0,0 +1,56 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is mozilla.org code.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Doug Turner <dougt@netscape.com>
*/
#ifndef __WebBrowser__
#define __WebBrowser__
#include "nsCOMPtr.h"
#include "nsIWidget.h"
#include "nsIBaseWindow.h"
#include "nsIWebBrowser.h"
#include "nsIEditorShell.h"
#include "nsIWebBrowserChrome.h"
class WebBrowser
{
public:
nsresult Init(nsNativeWidget widget, nsIWebBrowserChrome* aTopWindow);
nsresult SetPositionAndSize(int x, int y, int cx, int cy);
nsresult GoTo(char* url);
nsresult Edit(char* url);
nsresult Print(void);
nsresult GetWebBrowser(nsIWebBrowser **outBrowser);
WebBrowser();
virtual ~WebBrowser();
protected:
nsCOMPtr<nsIWebBrowser> mWebBrowser;
nsCOMPtr<nsIBaseWindow> mBaseWindow;
nsCOMPtr<nsIWebBrowserChrome> mTopWindow;
//for editing
nsCOMPtr<nsIEditorShell> mEditor;
};
#endif /* __WebBrowser__ */

View File

@ -0,0 +1,91 @@
//
// What follows is a hacked version the the sample hello
// world gtk app found: http://www.gtk.org/tutorial/gtk_tut-2.html
//
#include <gtk/gtk.h>
#include "nsEmbedAPI.h"
#include "WebBrowser.h"
#include "WebBrowserChrome.h"
#include "nsIEventQueueService.h"
#include "nsIServiceManager.h"
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
static gint io_identifier = 0;
static void
handle_event_queue(gpointer data, gint source, GdkInputCondition condition)
{
nsIEventQueue *eventQueue = (nsIEventQueue *)data;
eventQueue->ProcessPendingEvents();
}
int main( int argc,
char *argv[] )
{
nsresult rv;
NS_InitEmbedding("");
// set up the thread event queue
nsIEventQueueService* eventQService;
rv = nsServiceManager::GetService(kEventQueueServiceCID,
NS_GET_IID(nsIEventQueueService),
(nsISupports **)&eventQService);
if (NS_OK == rv)
{
// get our hands on the thread event queue
nsIEventQueue *eventQueue;
rv = eventQService->GetThreadEventQueue( NS_CURRENT_THREAD,
&eventQueue);
if (NS_FAILED(rv))
return FALSE;
io_identifier = gdk_input_add( eventQueue->GetEventQueueSelectFD(),
GDK_INPUT_READ,
handle_event_queue,
eventQueue);
NS_RELEASE(eventQService);
NS_RELEASE(eventQueue);
}
GtkWidget *window;
/* This is called in all GTK applications. Arguments are parsed
* from the command line and are returned to the application. */
gtk_init(&argc, &argv);
/* create a new window */
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_window_set_title (GTK_WINDOW (window), "Embedding is Fun!");
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
gtk_widget_realize (window);
WebBrowser *browser = new WebBrowser();
if (! browser)
return -1;
browser->Init(window,nsnull);
browser->SetPositionAndSize(0, 320, 400, 400);
browser->GoTo("http://people.netscape.com");
gtk_widget_show (window);
/* All GTK applications must have a gtk_main(). Control ends here
* and waits for an event to occur (like a key press or
* mouse event). */
gtk_main ();
return(0);
}