initial code checkin for the new gtk embedding widget. bug #31905. This is not feature complete and is not being built yet.

This commit is contained in:
blizzard%redhat.com 2000-03-23 23:55:18 +00:00
Родитель cc8f1f34bd
Коммит 10cdf9e2ce
10 изменённых файлов: 971 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,30 @@
#
# 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):
# Christopher Blizzard <blizzard@mozilla.org>
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS=src tests
include $(topsrcdir)/config/rules.mk

Просмотреть файл

@ -0,0 +1,279 @@
/*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
*/
#include "GtkMozEmbedChrome.h"
// this is a define to make sure that we don't call certain function
// before the object has been properly initialized
#define CHECK_IS_INIT() \
PR_BEGIN_MACRO \
if (!mIsInitialized) \
return NS_ERROR_NOT_INITIALIZED; \
PR_END_MACRO
// constructor and destructor
GtkMozEmbedChrome::GtkMozEmbedChrome()
{
NS_INIT_REFCNT();
}
GtkMozEmbedChrome::~GtkMozEmbedChrome()
{
}
// nsISupports interface
NS_IMPL_ADDREF(GtkMozEmbedChrome)
NS_IMPL_RELEASE(GtkMozEmbedChrome)
NS_INTERFACE_MAP_BEGIN(GtkMozEmbedChrome)
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIGtkEmbed)
NS_INTERFACE_MAP_ENTRY(nsIGtkEmbed)
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
NS_INTERFACE_MAP_ENTRY(nsIBaseWindow)
NS_INTERFACE_MAP_END
// nsIGtkEmbed interface
NS_IMETHODIMP GtkMozEmbedChrome::Init(GdkWindow *aParentWindow)
{
g_print("GtkMozEmbedChrome::Init\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
// nsIInterfaceRequestor interface
NS_IMETHODIMP GtkMozEmbedChrome::GetInterface(const nsIID &aIID, void** aInstancePtr)
{
g_print("GtkMozEmbedChrome::GetInterface\n");
return QueryInterface(aIID, aInstancePtr);
}
// nsIWebBrowserChrome interface
NS_IMETHODIMP GtkMozEmbedChrome::SetJSStatus(const PRUnichar *status)
{
g_print("GtkMozEmbedChrome::SetJSStatus\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::SetJSDefaultStatus(const PRUnichar *status)
{
g_print("GtkMozEmbedChrome::SetJSDefaultStatus\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::SetOverLink(const PRUnichar *link)
{
g_print("GtkMozEmbedChrome::SetOverLink\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::GetWebBrowser(nsIWebBrowser * *aWebBrowser)
{
g_print("GtkMozEmbedChrome::GetWebBrowser\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::SetWebBrowser(nsIWebBrowser * aWebBrowser)
{
g_print("GtkMozEmbedChrome::SetWebBrowser\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::GetChromeMask(PRUint32 *aChromeMask)
{
g_print("GtkMozEmbedChrome::GetChromeMask\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::SetChromeMask(PRUint32 aChromeMask)
{
g_print("GtkMozEmbedChrome::SetChromeMask\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::GetNewBrowser(PRUint32 chromeMask,
nsIWebBrowser **_retval)
{
g_print("GtkMozEmbedChrome::GetNewBrowser\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::FindNamedBrowser(const PRUnichar *aName,
nsIWebBrowser **_retval)
{
g_print("GtkMozEmbedChrome::FindNamedBrowser\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::SizeBrowserTo(PRInt32 aCX, PRInt32 aCY)
{
g_print("GtkMozEmbedChrome::SizeBrowserTo\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::ShowAsModal(void)
{
g_print("GtkMozEmbedChrome::ShowAsModal\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
// nsIBaseWindow interface
NS_IMETHODIMP GtkMozEmbedChrome::InitWindow(nativeWindow parentNativeWindow,
nsIWidget * parentWidget,
PRInt32 x, PRInt32 y,
PRInt32 cx, PRInt32 cy)
{
g_print("GtkMozEmbedChrome::InitWindow\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::Create(void)
{
g_print("GtkMozEmbedChrome::Create\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::Destroy(void)
{
g_print("GtkMozEmbedChrome::Destory\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::SetPosition(PRInt32 x, PRInt32 y)
{
g_print("GtkMozEmbedChrome::SetPosition\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::GetPosition(PRInt32 *x, PRInt32 *y)
{
g_print("GtkMozEmbedChrome::GetPosition\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::SetSize(PRInt32 cx, PRInt32 cy, PRBool fRepaint)
{
g_print("GtkMozEmbedChrome::SetSize\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::GetSize(PRInt32 *cx, PRInt32 *cy)
{
g_print("GtkMozEmbedChrome::GetSize\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::SetPositionAndSize(PRInt32 x, PRInt32 y,
PRInt32 cx, PRInt32 cy,
PRBool fRepaint)
{
g_print("GtkMozEmbedChrome::SetPositionAndSize\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::GetPositionAndSize(PRInt32 *x, PRInt32 *y,
PRInt32 *cx, PRInt32 *cy)
{
g_print("GtkMozEmbedChrome::GetPositionAndSize\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::Repaint(PRBool force)
{
g_print("GtkMozEmbedCHrome::Repaint\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::GetParentWidget(nsIWidget * *aParentWidget)
{
g_print("GtkMozEmbedChrome::GetParentWidget\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::SetParentWidget(nsIWidget * aParentWidget)
{
g_print("GtkMozEmbedChrome::SetParentWidget\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::GetParentNativeWindow(nativeWindow *aParentNativeWindow)
{
g_print("GtkMozEmbedChrome::GetParentNativeWindow\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::SetParentNativeWindow(nativeWindow aParentNativeWindow)
{
g_print("GtkMozEmbedChrome::SetParentNativeWindow\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::GetVisibility(PRBool *aVisibility)
{
g_print("GtkMozEmbedChrome::GetVisibility\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::SetVisibility(PRBool aVisibility)
{
g_print("GtkMozEmbedChrome::SetVisibility\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::GetMainWidget(nsIWidget * *aMainWidget)
{
g_print("GtkMozEmbedChrome::GetMainWidget\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::SetFocus(void)
{
g_print("GtkMozEmbedChrome::SetFocus\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::FocusAvailable(nsIBaseWindow *aCurrentFocus,
PRBool *aTookFocus)
{
g_print("GtkMozEmbedChrome::FocusAvailable\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::GetTitle(PRUnichar * *aTitle)
{
g_print("GtkMozEmbedChrome::GetTitle\n");
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP GtkMozEmbedChrome::SetTitle(const PRUnichar * aTitle)
{
g_print("GtkMozEmbedChrome::SetTitle\n");
return NS_ERROR_NOT_IMPLEMENTED;
}

Просмотреть файл

@ -0,0 +1,63 @@
/*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
*/
#ifndef __GtkMozEmbedChrome_h
#define __GtkMozEmbedChrome_h
// needed for the ever helpful nsCOMPtr
#include <nsCOMPtr.h>
// we will implement these interfaces
#include "nsIGtkEmbed.h"
#include "nsIWebBrowserChrome.h"
#include "nsIBaseWindow.h"
#include "nsIInterfaceRequestor.h"
// include our gtk stuff here
#include "gdksuperwin.h"
class GtkMozEmbedChrome : public nsIGtkEmbed,
public nsIWebBrowserChrome,
public nsIBaseWindow,
public nsIInterfaceRequestor
{
public:
GtkMozEmbedChrome();
virtual ~GtkMozEmbedChrome();
// nsIGtkEmbed
NS_IMETHOD Init(GdkWindow *aParentWindow);
NS_DECL_ISUPPORTS
NS_DECL_NSIINTERFACEREQUESTOR
NS_DECL_NSIWEBBROWSERCHROME
NS_DECL_NSIBASEWINDOW
private:
};
#endif /* __GtkMozEmbedChrome_h */

Просмотреть файл

@ -0,0 +1,50 @@
#
# 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):
# Christopher Blizzard <blizzard@mozilla.org>
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
LIBRARY_NAME = gtkembedmoz
REQUIRES = xpcom
CPPSRCS = \
GtkMozEmbedChrome.cpp \
nsSetupRegistry.cpp \
gtkmozembed.cpp
EXPORTS = \
gtkmozembed.h
EXTRA_DSO_LDOPTS = \
$(MKSHLIB_FORCE_ALL) \
$(SHARED_LIBRARY_LIBS) \
$(MKSHLIB_UNFORCE_ALL) \
$(MOZ_COMPONENT_LIBS) \
-lgtksuperwin \
$(NULL)
include $(topsrcdir)/config/rules.mk
CXXFLAGS += $(MOZ_GTK_CFLAGS)

Просмотреть файл

@ -0,0 +1,341 @@
/*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
*/
#include "gtkmozembed.h"
#include "nsIWebBrowser.h"
#include "nsCWebBrowser.h"
#include "nsIWebBrowserChrome.h"
#include "GtkMozEmbedChrome.h"
#include "nsIComponentManager.h"
#include "nsIWebNavigation.h"
#include "nsString.h"
#include "nsIEventQueueService.h"
#include "nsIServiceManager.h"
static NS_DEFINE_CID(kWebBrowserCID, NS_WEBBROWSER_CID);
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
class GtkMozEmbedPrivate
{
public:
nsCOMPtr<nsIWebBrowser> webBrowser;
nsCOMPtr<nsIGtkEmbed> embed;
GdkSuperWin *superwin;
};
static void
gtk_moz_embed_class_init(GtkMozEmbedClass *klass);
static void
gtk_moz_embed_init(GtkMozEmbed *embed);
/* GtkWidget methods */
static void
gtk_moz_embed_realize(GtkWidget *widget);
static void
gtk_moz_embed_size_allocate(GtkWidget *widget, GtkAllocation *allocation);
/* GtkObject methods */
static void
gtk_moz_embed_destroy(GtkObject *object);
/* signal handlers */
static void
gtk_moz_embed_handle_show(GtkWidget *widget, gpointer user_data);
/* event queue callback */
static void
gtk_moz_embed_handle_event_queue(gpointer data, gint source, GdkInputCondition condition);
static GtkWidgetClass *parent_class;
static PRBool NS_SetupRegistryCalled = PR_FALSE;
static PRBool ThreadQueueSetup = PR_FALSE;
extern "C" void NS_SetupRegistry();
GtkType
gtk_moz_embed_get_type(void)
{
static GtkType moz_embed_type = 0;
if (!moz_embed_type)
{
static const GtkTypeInfo moz_embed_info =
{
"GtkMozEmbed",
sizeof(GtkMozEmbed),
sizeof(GtkMozEmbedClass),
(GtkClassInitFunc)gtk_moz_embed_class_init,
(GtkObjectInitFunc)gtk_moz_embed_init,
0,
0,
0
};
moz_embed_type = gtk_type_unique(GTK_TYPE_WIDGET, &moz_embed_info);
}
return moz_embed_type;
}
static void
gtk_moz_embed_class_init(GtkMozEmbedClass *klass)
{
GtkWidgetClass *widget_class;
GtkObjectClass *object_class;
widget_class = GTK_WIDGET_CLASS(klass);
object_class = GTK_OBJECT_CLASS(klass);
parent_class = (GtkWidgetClass *)gtk_type_class(gtk_widget_get_type());
widget_class->realize = gtk_moz_embed_realize;
widget_class->size_allocate = gtk_moz_embed_size_allocate;
object_class->destroy = gtk_moz_embed_destroy;
// check to see if NS_SetupRegistry has been called
if (!NS_SetupRegistryCalled)
{
NS_SetupRegistry();
NS_SetupRegistryCalled = PR_TRUE;
}
// check to see if we have to set up our thread event queue
if (!ThreadQueueSetup)
{
nsIEventQueueService* eventQService;
nsresult rv;
rv = nsServiceManager::GetService(kEventQueueServiceCID,
NS_GET_IID(nsIEventQueueService),
(nsISupports **)&eventQService);
if (NS_OK == rv)
{
// create the event queue
rv = eventQService->CreateThreadEventQueue();
if (!NS_SUCCEEDED(rv))
g_print("Warning: Could not create the event queue for the the thread");
nsIEventQueue *eventQueue;
rv = eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &eventQueue);
if (!NS_SUCCEEDED(rv))
g_print("Warning: Could not create the thread event queue\n");
gdk_input_add(eventQueue->GetEventQueueSelectFD(),
GDK_INPUT_READ,
gtk_moz_embed_handle_event_queue,
eventQueue);
NS_RELEASE(eventQService);
}
ThreadQueueSetup = PR_TRUE;
}
}
static void
gtk_moz_embed_init(GtkMozEmbed *embed)
{
GtkMozEmbedPrivate *embed_private;
// create our private struct
embed_private = new GtkMozEmbedPrivate();
// create an nsIWebBrowser object
embed_private->webBrowser = do_CreateInstance(kWebBrowserCID);
// create our glue widget
GtkMozEmbedChrome *chrome = new GtkMozEmbedChrome();
embed_private->embed = do_QueryInterface((nsISupports *)(nsIGtkEmbed *) chrome);
// we haven't created our superwin yet
embed_private->superwin = NULL;
// hide it
embed->data = embed_private;
// this is how we hook into when show() is called on the widget
gtk_signal_connect(GTK_OBJECT(embed), "show",
GTK_SIGNAL_FUNC(gtk_moz_embed_handle_show), NULL);
// set our tree owner here
nsCOMPtr<nsIWebBrowserChrome> browserChrome = do_QueryInterface(embed_private->embed);
if (!browserChrome)
g_print("Warning: Failed to QI embed window to nsIWebBrowserChrome\n");
embed_private->webBrowser->SetTopLevelWindow(browserChrome);
}
GtkWidget *
gtk_moz_embed_new(void)
{
return GTK_WIDGET(gtk_type_new(gtk_moz_embed_get_type()));
}
void
gtk_moz_embed_load_url(GtkWidget *widget, char *url)
{
GtkMozEmbed *embed;
GtkMozEmbedPrivate *embed_private;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_MOZ_EMBED(widget));
embed = GTK_MOZ_EMBED(widget);
embed_private = (GtkMozEmbedPrivate *)embed->data;
nsCOMPtr<nsIWebNavigation> navigation = do_QueryInterface(embed_private->webBrowser);
if (!navigation)
g_print("Warning: failed to QI webBrowser to nsIWebNavigation\n");
nsString URLString;
URLString.SetString(url);
navigation->LoadURI(URLString.GetUnicode());
}
void
gtk_moz_embed_realize(GtkWidget *widget)
{
GtkMozEmbed *embed;
GtkMozEmbedPrivate *embed_private;
GdkWindowAttr attributes;
gint attributes_mask;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_MOZ_EMBED(widget));
embed = GTK_MOZ_EMBED(widget);
GTK_WIDGET_SET_FLAGS(widget, GTK_REALIZED);
attributes.window_type = GDK_WINDOW_CHILD;
attributes.x = widget->allocation.x;
attributes.y = widget->allocation.y;
attributes.width = widget->allocation.width;
attributes.height = widget->allocation.height;
attributes.wclass = GDK_INPUT_OUTPUT;
attributes.visual = gtk_widget_get_visual (widget);
attributes.colormap = gtk_widget_get_colormap (widget);
attributes.event_mask = gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK;
attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask);
gdk_window_set_user_data (widget->window, embed);
widget->style = gtk_style_attach (widget->style, widget->window);
gtk_style_set_background (widget->style, widget->window, GTK_STATE_NORMAL);
// now that we're realized, set up the nsIWebBrowser and nsIBaseWindow stuff
embed_private = (GtkMozEmbedPrivate *)embed->data;
// create our superwin
embed_private->superwin = gdk_superwin_new(widget->window, 0, 0,
widget->allocation.width, widget->allocation.height);
// check to see if we're supposed to be already visible
if (GTK_WIDGET_VISIBLE(widget))
{
gdk_window_show(embed_private->superwin->bin_window);
gdk_window_show(embed_private->superwin->shell_window);
gdk_window_show(widget->window);
}
// init our window
nsCOMPtr<nsIBaseWindow> webBrowserBaseWindow = do_QueryInterface(embed_private->webBrowser);
webBrowserBaseWindow->InitWindow(embed_private->superwin, NULL, 0, 0,
widget->allocation.width, widget->allocation.height);
webBrowserBaseWindow->Create();
PRBool visibility;
webBrowserBaseWindow->GetVisibility(&visibility);
if (GTK_WIDGET_VISIBLE(widget))
{
webBrowserBaseWindow->SetVisibility(PR_TRUE);
}
}
void
gtk_moz_embed_size_allocate(GtkWidget *widget, GtkAllocation *allocation)
{
GtkMozEmbed *embed;
GtkMozEmbedPrivate *embed_private;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_MOZ_EMBED(widget));
g_return_if_fail (allocation != NULL);
embed = GTK_MOZ_EMBED(widget);
embed_private = (GtkMozEmbedPrivate *)embed->data;
widget->allocation = *allocation;
if (GTK_WIDGET_REALIZED(widget))
{
gdk_window_move_resize(widget->window,
allocation->x, allocation->y,
allocation->width, allocation->height);
gdk_superwin_resize(embed_private->superwin, allocation->width, allocation->height);
// set the size of the base window
nsCOMPtr<nsIBaseWindow> webBrowserBaseWindow = do_QueryInterface(embed_private->webBrowser);
webBrowserBaseWindow->SetPositionAndSize(0, 0, allocation->width, allocation->height, PR_TRUE);
}
}
void
gtk_moz_embed_destroy(GtkObject *object)
{
GtkMozEmbed *embed;
GtkMozEmbedPrivate *embed_private;
g_return_if_fail(object != NULL);
g_return_if_fail(GTK_IS_MOZ_EMBED(object));
embed = GTK_MOZ_EMBED(object);
embed_private = (GtkMozEmbedPrivate *)embed->data;
if (embed_private)
{
embed_private->webBrowser = nsnull;
embed_private->embed = nsnull;
gtk_object_unref(GTK_OBJECT(embed_private->superwin));
delete embed_private;
embed->data = NULL;
}
}
static void
gtk_moz_embed_handle_show(GtkWidget *widget, gpointer user_data)
{
GtkMozEmbed *embed;
GtkMozEmbedPrivate *embed_private;
g_return_if_fail (widget != NULL);
g_return_if_fail (GTK_IS_MOZ_EMBED(widget));
embed = GTK_MOZ_EMBED(widget);
embed_private = (GtkMozEmbedPrivate *)embed->data;
// sometimes we get the show signal before we are actually realized
if (embed_private->superwin)
{
gdk_window_show(embed_private->superwin->bin_window);
gdk_window_show(embed_private->superwin->shell_window);
}
}
static void
gtk_moz_embed_handle_event_queue(gpointer data, gint source, GdkInputCondition condition)
{
nsIEventQueue *eventQueue = (nsIEventQueue *)data;
eventQueue->ProcessPendingEvents();
}

Просмотреть файл

@ -0,0 +1,59 @@
/*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
*/
#ifndef gtkmozembed_h
#define gtkmozembed_h
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#include <gtk/gtk.h>
#define GTK_TYPE_MOZ_EMBED (gtk_moz_embed_get_type())
#define GTK_MOZ_EMBED(obj) GTK_CHECK_CAST((obj), GTK_TYPE_MOZ_EMBED, GtkMozEmbed)
#define GTK_MOZ_EMBED_CLASS(klass) GTK_CHEK_CLASS_CAST((klass), GTK_TYPE_MOZ_EMBED, GtkMozEmbedClass)
#define GTK_IS_MOZ_EMBED(obj) GTK_CHECK_TYPE((obj), GTK_TYPE_MOZ_EMBED)
#define GTK_IS_MOZ_EMBED_CLASS(klass) GTK_CHECK_CLASS_TYPE((klass), GTK_TYPE_MOZ_EMBED)
typedef struct _GtkMozEmbed GtkMozEmbed;
typedef struct _GtkMozEmbedClass GtkMozEmbedClass;
struct _GtkMozEmbed
{
GtkWidget widget;
void *data;
};
struct _GtkMozEmbedClass
{
GtkWidgetClass parent_class;
};
extern GtkType gtk_moz_embed_get_type(void);
extern GtkWidget *gtk_moz_embed_new(void);
extern void gtk_moz_embed_load_url(GtkWidget *widget, char *url);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* gtkmozembed_h */

Просмотреть файл

@ -0,0 +1,42 @@
/*
* 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 mozilla.org code.
*
* The Initial Developer of the Original Code is Christopher Blizzard.
* Portions created by Christopher Blizzard are Copyright (C)
* Christopher Blizzard. All Rights Reserved.
*
* Contributor(s):
* Christopher Blizzard <blizzard@mozilla.org>
*/
#ifndef __nsIGtkEmbed_h__
#define __nsIGtkEmbed_h__
#include <gtk/gtk.h>
#define NS_IGTKEMBED_IID_STR "ebe19ea4-1dd1-11b2-bc20-8e8105516b2f"
#define NS_IGTKEMBED_IID \
{0xebe19ea4, 0x1dd1, 0x11b2, \
{ 0xbc, 0x20, 0x8e, 0x81, 0x05, 0x51, 0x6b, 0x2f }}
class nsIGtkEmbed : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_IGTKEMBED_IID)
NS_IMETHOD Init(GdkWindow *aParentWindow) = 0;
};
#endif /* __nsIGtkEmbed_h__ */

Просмотреть файл

@ -0,0 +1 @@
#include "../../../../webshell/tests/viewer/nsSetupRegistry.cpp"

Просмотреть файл

@ -0,0 +1,45 @@
#
# 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):
# Christopher Blizzard <blizzard@mozilla.org>
DEPTH = ../../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
CPPSRCS = \
TestGtkEmbed.cpp
SIMPLE_PROGRAMS = $(CPPSRCS:.cpp=)
LIBS = \
$(MKSHLIB_FORCE_ALL) \
$(SHARED_LIBRARY_LIBS) \
$(MKSHLIB_UNFORCE_ALL) \
$(MOZ_COMPONENT_LIBS) \
-lgtkembedmoz \
$(TK_LIBS) \
$(NULL)
include $(topsrcdir)/config/rules.mk
CXXFLAGS += $(MOZ_GTK_CFLAGS)

Просмотреть файл

@ -0,0 +1,61 @@
#include "gtkmozembed.h"
#include <gtk/gtk.h>
GtkWidget *toplevelwindow;
GtkWidget *box;
GtkWidget *entry;
GtkWidget *moz_embed;
static gboolean
destroy_cb(GtkWidget *widget, gpointer data);
static void
activate_cb(GtkEditable *widget, gpointer data);
int
main(int argc, char **argv)
{
gtk_init(&argc, &argv);
toplevelwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_signal_connect(GTK_OBJECT(toplevelwindow), "delete_event",
GTK_SIGNAL_FUNC(destroy_cb), NULL);
box = gtk_vbox_new(FALSE, 2);
gtk_container_add(GTK_CONTAINER(toplevelwindow), box);
gtk_widget_show(box);
entry = gtk_entry_new();
gtk_box_pack_start(GTK_BOX(box), entry, FALSE, FALSE, 1);
gtk_widget_show(entry);
gtk_signal_connect(GTK_OBJECT(entry), "activate",
GTK_SIGNAL_FUNC(activate_cb), NULL);
moz_embed = gtk_moz_embed_new();
gtk_widget_set_usize(moz_embed, 100, 100);
gtk_box_pack_end(GTK_BOX(box), moz_embed, TRUE, TRUE, 1);
gtk_widget_show(moz_embed);
gtk_widget_show(toplevelwindow);
gtk_main();
}
gboolean
destroy_cb(GtkWidget *widget, gpointer data)
{
gtk_widget_destroy(toplevelwindow);
gtk_main_quit();
return TRUE;
}
void
activate_cb(GtkEditable *widget, gpointer data)
{
gchar *text = gtk_editable_get_chars(widget, 0, -1);
g_print("activate_cb. data is %s\n", text);
gtk_moz_embed_load_url(moz_embed, text);
g_free(text);
}