Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2008-11-11 19:15:19 (GMT)
committer Jonas Smedegaard <dr@jones.dk>2008-11-11 19:15:19 (GMT)
commit79b51226ff0a6bb2d9d5a815948b5537119ef9bb (patch)
tree35cfc51c4f0ad9cd102d8775715226b38dd39de6 /src
parentb8468ef1e2a7eccd88d9fbd143be1e90d94f616c (diff)
parentb455d21f18aeedf7d15cd716f419fe85f1bd77fd (diff)
Merge commit 'v0.4.7' into upstream
Conflicts (add test, avoid debian/* ): tests/test-web-view.py
Diffstat (limited to 'src')
-rw-r--r--src/hulahop-web-view.cpp45
-rw-r--r--src/hulahop-web-view.h8
-rw-r--r--src/hulahop.cpp37
-rw-r--r--src/hulahop.h11
4 files changed, 70 insertions, 31 deletions
diff --git a/src/hulahop-web-view.cpp b/src/hulahop-web-view.cpp
index eee333d..9104b20 100644
--- a/src/hulahop-web-view.cpp
+++ b/src/hulahop-web-view.cpp
@@ -49,10 +49,6 @@ struct _HulahopWebView {
GtkWidget *mozilla_widget;
};
-struct _HulahopWebViewClass {
- GtkBinClass base_class;
-};
-
G_DEFINE_TYPE(HulahopWebView, hulahop_web_view, GTK_TYPE_BIN)
static GObjectClass *parent_class = NULL;
@@ -95,6 +91,13 @@ hulahop_web_view_unrealize(GtkWidget *widget)
GTK_WIDGET_CLASS(parent_class)->unrealize(widget);
}
+void
+hulahop_web_view_setup(HulahopWebView *web_view)
+{
+ web_view->base_window->Create();
+ web_view->mozilla_widget = GTK_BIN(web_view)->child;
+}
+
static void
hulahop_web_view_realize(GtkWidget *widget)
{
@@ -123,9 +126,13 @@ hulahop_web_view_realize(GtkWidget *widget)
widget->style = gtk_style_attach (widget->style, widget->window);
gtk_style_set_background(widget->style, widget->window, GTK_STATE_NORMAL);
- g_assert(GTK_IS_WIDGET(web_view->mozilla_widget));
+ if (web_view->mozilla_widget) {
+ gtk_widget_reparent(web_view->mozilla_widget, widget);
+ } else {
+ HULAHOP_WEB_VIEW_GET_CLASS(web_view)->setup(web_view);
+ }
- gtk_widget_reparent(web_view->mozilla_widget, widget);
+ g_assert(web_view->mozilla_widget);
g_signal_connect_object(web_view->mozilla_widget,
"focus-in-event",
@@ -228,7 +235,9 @@ hulahop_web_view_class_init(HulahopWebViewClass *web_view_class)
widget_class->unmap = hulahop_web_view_unmap;
widget_class->size_allocate = hulahop_web_view_size_allocate;
- gobject_class->dispose = hulahop_web_view_dispose;
+ gobject_class->dispose = hulahop_web_view_dispose;
+
+ web_view_class->setup = hulahop_web_view_setup;
}
static void
@@ -236,8 +245,6 @@ hulahop_web_view_init(HulahopWebView *web_view)
{
web_view->offscreen_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_realize(web_view->offscreen_window);
-
- nsresult rv;
web_view->browser = do_CreateInstance
("@mozilla.org/embedding/browser/nsWebBrowser;1");
@@ -247,10 +254,13 @@ hulahop_web_view_init(HulahopWebView *web_view)
item->SetItemType(nsIDocShellTreeItem::typeContentWrapper);
web_view->base_window = do_QueryInterface(web_view->browser);
+ g_assert(web_view->base_window);
- rv = web_view->base_window->InitWindow(web_view->offscreen_window,
- nsnull, 0, 0, 100, 100);
+ nsresult rv;
+ rv = web_view->base_window->InitWindow(web_view, nsnull, 0, 0, 100, 100);
g_assert(NS_SUCCEEDED(rv));
+
+ GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(web_view), GTK_NO_WINDOW);
}
PyObject *
@@ -281,19 +291,6 @@ hulahop_web_view_get_window_root(HulahopWebView *web_view)
}
void
-hulahop_web_view_create_window(HulahopWebView *web_view)
-{
- nsresult rv;
-
- rv = web_view->base_window->Create();
- g_assert(NS_SUCCEEDED(rv));
-
- web_view->mozilla_widget = GTK_BIN(web_view->offscreen_window)->child;
-
- GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(web_view), GTK_NO_WINDOW);
-}
-
-void
hulahop_web_view_grab_focus(HulahopWebView *web_view)
{
if (web_view->mozilla_widget) {
diff --git a/src/hulahop-web-view.h b/src/hulahop-web-view.h
index f832b7a..cd3b710 100644
--- a/src/hulahop-web-view.h
+++ b/src/hulahop-web-view.h
@@ -35,10 +35,15 @@ typedef struct _HulahopWebViewClass HulahopWebViewClass;
#define HULAHOP_IS_WEB_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), HULAHOP_TYPE_WEB_VIEW))
#define HULAHOP_WEB_VIEW_GET_CLASS(object) (G_TYPE_INSTANCE_GET_CLASS((object), HULAHOP_TYPE_WEB_VIEW, HulahopWebViewClass))
+struct _HulahopWebViewClass {
+ GtkBinClass base_class;
+
+ void (* setup) (HulahopWebView *web_view);
+};
+
GType hulahop_web_view_get_type (void);
void hulahop_web_view_grab_focus (HulahopWebView *web_view);
-void hulahop_web_view_create_window (HulahopWebView *web_view);
PyObject *hulahop_web_view_get_browser (HulahopWebView *web_view);
PyObject *hulahop_web_view_get_window_root (HulahopWebView *web_view);
@@ -48,7 +53,6 @@ void hulahop_web_view_pop_js_context (HulahopWebView *web_view);
void hulahop_web_view_evaluate_script (HulahopWebView *web_view,
const char *script);
-
G_END_DECLS
#endif
diff --git a/src/hulahop.cpp b/src/hulahop.cpp
index 3e3b963..6adc2e3 100644
--- a/src/hulahop.cpp
+++ b/src/hulahop.cpp
@@ -20,6 +20,12 @@
#include <nsCOMPtr.h>
#include <nsILocalFile.h>
#include <nsXULAppAPI.h>
+#include <nsIWindowWatcher.h>
+#include <nsIWebBrowser.h>
+#include <nsIWebBrowserChrome.h>
+#include <nsIDOMWindow.h>
+#include <nsIBaseWindow.h>
+#include <PyXPCOM.h>
#include "HulahopDirectoryProvider.h"
#include "hulahop.h"
@@ -87,3 +93,34 @@ hulahop_add_components_path(const char *path)
{
kDirectoryProvider.AddComponentsPath(path);
}
+
+HulahopWebView *
+hulahop_get_view_for_window(PyObject *dom_window)
+{
+ nsCOMPtr<nsIDOMWindow> domWindow;
+ Py_nsISupports::InterfaceFromPyObject(dom_window,
+ NS_GET_IID(nsIDOMWindow),
+ getter_AddRefs(domWindow),
+ PR_FALSE);
+ NS_ENSURE_TRUE(domWindow, NULL);
+
+ nsCOMPtr<nsIWindowWatcher> wwatch = do_GetService
+ ("@mozilla.org/embedcomp/window-watcher;1");
+ NS_ENSURE_TRUE(wwatch, NULL);
+
+ nsCOMPtr<nsIWebBrowserChrome> chrome;
+ wwatch->GetChromeForWindow(domWindow, getter_AddRefs(chrome));
+ NS_ENSURE_TRUE(chrome, NULL);
+
+ nsCOMPtr<nsIWebBrowser> browser;
+ chrome->GetWebBrowser(getter_AddRefs(browser));
+ NS_ENSURE_TRUE(browser, NULL);
+
+ nsCOMPtr<nsIBaseWindow> baseWindow = do_QueryInterface(browser);
+ NS_ENSURE_TRUE(baseWindow, NULL);
+
+ gpointer native_parent;
+ baseWindow->GetParentNativeWindow(&native_parent);
+
+ return HULAHOP_WEB_VIEW(native_parent);
+}
diff --git a/src/hulahop.h b/src/hulahop.h
index b678d7e..c8649ce 100644
--- a/src/hulahop.h
+++ b/src/hulahop.h
@@ -20,14 +20,15 @@
#ifndef __HULAHOP_H__
#define __HULAHOP_H__
-#include <glib.h>
+#include "hulahop-web-view.h"
G_BEGIN_DECLS
-gboolean hulahop_startup (void);
-void hulahop_shutdown (void);
-void hulahop_set_profile_path (const char *path);
-void hulahop_add_components_path (const char *path);
+gboolean hulahop_startup (void);
+void hulahop_shutdown (void);
+void hulahop_set_profile_path (const char *path);
+void hulahop_add_components_path (const char *path);
+HulahopWebView *hulahop_get_view_for_window (PyObject *dom_window);
G_END_DECLS