diff options
author | Marco Pesenti Gritti <mpgritti@gmail.com> | 2008-10-15 02:33:21 (GMT) |
---|---|---|
committer | Marco Pesenti Gritti <mpgritti@gmail.com> | 2008-10-15 02:33:21 (GMT) |
commit | fe68d402ad560edd6bdb265a14cbd80b5f281ca7 (patch) | |
tree | 4d93a16ab81ac808742301c0bafedd063f10e53e | |
parent | d3fd80482ca4807c911173c50cc7b8ad2917fa4a (diff) |
Better way to map from dom window to view.
Give up on trying to allow to user the view before
it's realized, it's just not possible to do it with
current mozilla implementation.
-rw-r--r-- | python/__init__.py | 1 | ||||
-rw-r--r-- | python/hulahop.defs | 14 | ||||
-rw-r--r-- | python/webview.py | 21 | ||||
-rw-r--r-- | src/hulahop-web-view.cpp | 28 | ||||
-rw-r--r-- | src/hulahop-web-view.h | 2 | ||||
-rw-r--r-- | src/hulahop.cpp | 37 | ||||
-rw-r--r-- | src/hulahop.h | 11 |
7 files changed, 65 insertions, 49 deletions
diff --git a/python/__init__.py b/python/__init__.py index 983302e..a1fde26 100644 --- a/python/__init__.py +++ b/python/__init__.py @@ -27,6 +27,7 @@ from hulahop import config sys.path.insert(0, os.path.join(config.libxul_dir, 'python')) from hulahop._hulahop import shutdown +from hulahop._hulahop import get_view_for_window from hulahop import _hulahop _XO_DPI = 200 diff --git a/python/hulahop.defs b/python/hulahop.defs index 55c1733..cad4a28 100644 --- a/python/hulahop.defs +++ b/python/hulahop.defs @@ -5,12 +5,6 @@ (gtype-id "HULAHOP_TYPE_WEB_VIEW") ) -(define-method create_window - (of-object "HulahopWebView") - (c-name "hulahop_web_view_create_window") - (return-type "none") -) - (define-method grab_focus (of-object "HulahopWebView") (c-name "hulahop_web_view_grab_focus") @@ -76,3 +70,11 @@ (return-type "none") ) +(define-function get_view_for_window + (c-name "hulahop_get_view_for_window") + (return-type "HulahopWebView*") + (parameters + '("PyObject*" "dom_window") + ) +) + diff --git a/python/webview.py b/python/webview.py index b4dc51f..c257f9c 100644 --- a/python/webview.py +++ b/python/webview.py @@ -25,8 +25,6 @@ from xpcom import components from xpcom.components import interfaces from xpcom.nsError import * -_views = [] - class _Chrome: _com_interfaces_ = interfaces.nsIWebBrowserChrome, \ interfaces.nsIWebBrowserChrome2, \ @@ -147,6 +145,9 @@ class _Chrome: #logging.debug("nsIEmbeddingSiteWindow.get_visibility: %r" % self.web_view.get_toplevel().props.visible) return self.web_view.get_toplevel().props.visible + def get_webBrowser(self): + return self.web_view.browser + def get_chromeFlags(self): return self._chrome_flags @@ -206,6 +207,7 @@ class WebView(_hulahop.WebView): 'status' : (str, None, None, None, gobject.PARAM_READABLE) } + def __init__(self): _hulahop.WebView.__init__(self) @@ -226,15 +228,6 @@ class WebView(_hulahop.WebView): self._status = '' - self.create_window() - - self.connect('destroy', self.__destroy_cb) - - _views.append(self) - - def __destroy_cb(self): - _views.remove(self) - def _notify_title_changed(self): self.notify('title') @@ -278,9 +271,3 @@ class WebView(_hulahop.WebView): doc_shell = property(get_doc_shell) web_progress = property(get_web_progress) web_navigation = property(get_web_navigation) - -def lookup_view(chrome): - for view in _views: - if view._chrome == chrome: - return view - return None diff --git a/src/hulahop-web-view.cpp b/src/hulahop-web-view.cpp index eee333d..2317823 100644 --- a/src/hulahop-web-view.cpp +++ b/src/hulahop-web-view.cpp @@ -123,9 +123,12 @@ 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)); - - gtk_widget_reparent(web_view->mozilla_widget, widget); + if (web_view->mozilla_widget) { + gtk_widget_reparent(web_view->mozilla_widget, widget); + } else { + web_view->base_window->Create(); + web_view->mozilla_widget = GTK_BIN(web_view)->child; + } g_signal_connect_object(web_view->mozilla_widget, "focus-in-event", @@ -248,9 +251,9 @@ hulahop_web_view_init(HulahopWebView *web_view) web_view->base_window = do_QueryInterface(web_view->browser); - rv = web_view->base_window->InitWindow(web_view->offscreen_window, - nsnull, 0, 0, 100, 100); - g_assert(NS_SUCCEEDED(rv)); + rv = web_view->base_window->InitWindow(web_view, nsnull, 0, 0, 100, 100); + + GTK_WIDGET_UNSET_FLAGS(GTK_WIDGET(web_view), GTK_NO_WINDOW); } PyObject * @@ -281,19 +284,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..f54fecf 100644 --- a/src/hulahop-web-view.h +++ b/src/hulahop-web-view.h @@ -38,7 +38,6 @@ typedef struct _HulahopWebViewClass HulahopWebViewClass; 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 +47,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 |