Author: andreia
Date: 2007-06-25 11:34:28 -0400 (Mon, 25 Jun 2007)
New Revision: 80689

Modified:
   trunk/mozembed/Mono.Mozilla/Callback.cs
   trunk/mozembed/Mono.Mozilla/ChangeLog
   trunk/mozembed/Mono.Mozilla/IWebBrowser.cs
   trunk/mozembed/tests/browser/WebBrowser.cs
   trunk/mozembed/xulbrowser/BrowserWindow.cpp
   trunk/mozembed/xulbrowser/BrowserWindow.h
   trunk/mozembed/xulbrowser/ChangeLog
   trunk/mozembed/xulbrowser/Widget.cpp
   trunk/mozembed/xulbrowser/Widget.h
   trunk/mozembed/xulbrowser/gtkWidget.cpp
   trunk/mozembed/xulbrowser/gtkWidget.h
   trunk/mozembed/xulbrowser/xulbrowser.cpp
   trunk/mozembed/xulbrowser/xulbrowser.h
Log:
Mono.Mozilla/:
* Callback.cs, IWebBrowser.cs, WebBrowser.cs: 
Change OnWidgetLoaded callback to send the new  
handle when it's called.

xulbrowser/:
* BrowserWindow.cpp: 
- Apart from a few changes in variable naming (out with the prefixes, eek), 
add initializations for session history and window creator. 
- When on gtk, get the native   mozilla widget that is the real drawing 
surface (not used for now, might come in handy later).
- Save the current uri in the object so it can be reloaded later 
(overload to the Navigate method).
- Add a lot of debug printlines (gtk only).
- Add implementation of nsIWindowCreator's CreateChromeWindow (this is gtk 
only as far as I can tell, windows does not need this, and xlib toolkit 
probably doesn't, either).

* BrowserWindow.h: normalize includes and variable naming, add extra Navigate 
overload and uri getters/setters.
        
* gtkWidget.cpp/h: Inherit it from window so it can be self-suficient. Add a 
new window signal (not used yet). Add a new constructor so it can also use a 
normal gtk window as parent instead of a XID.
        
* Widget.cpp/h: Add initialization of AppShell. This is absolutely required 
for the browser widget to work on linux, and is not mentioned *anywhere*. 
<grrrr>
Add thread support on linux/gtk (this gtk widget code should go somewhere 
else...)
        
* xulbrowser.cpp/h: Add thread to run the gtk main loop, and reroute all 
requests 
on linux/gtk to that thread so that things actually *work*.
New params class to help pass parameters to the gtk gui thread.

2007-06-25 Andreia Gaita <[EMAIL PROTECTED]>

Modified: trunk/mozembed/Mono.Mozilla/Callback.cs
===================================================================
--- trunk/mozembed/Mono.Mozilla/Callback.cs     2007-06-25 15:11:18 UTC (rev 
80688)
+++ trunk/mozembed/Mono.Mozilla/Callback.cs     2007-06-25 15:34:28 UTC (rev 
80689)
@@ -3,6 +3,7 @@
 
 namespace Mono.Mozilla {
        public delegate void CallbackDelegate();
+       public delegate void OnWidgetLoadedCallbackDelegate(IntPtr handle);
        public delegate void GetControlSizeCallbackDelegate(ref SizeInfo sz);
        public delegate void ResizeToCallbackDelegate(Int32 width, Int32 
height);
        public delegate void ShowTooltipCallbackDelegate(Int32 x, Int32 y, 
string tiptext);
@@ -24,7 +25,7 @@
        [StructLayout (LayoutKind.Sequential)]
        public struct CallbackBinder {
                
-               public CallbackDelegate                                 
EventOnWidgetLoaded;
+               public OnWidgetLoadedCallbackDelegate                           
EventOnWidgetLoaded;
                public CallbackDelegate                                 
EventJSStatus;
                public CallbackDelegate                                 
EventLinkStatus;
                public CallbackDelegate                                 
EventDestoryBrowser;
@@ -61,7 +62,7 @@
                
                public static CallbackBinder WrapIWebBrowser(IWebBrowser iwb) {
                        CallbackBinder cb = new CallbackBinder();
-                       cb.EventOnWidgetLoaded = new CallbackDelegate 
(iwb.OnWidgetLoaded);
+                       cb.EventOnWidgetLoaded = new 
OnWidgetLoadedCallbackDelegate(iwb.OnWidgetLoaded);
                        cb.GetControlSize = new 
GetControlSizeCallbackDelegate(iwb.GetControlSize);
                        cb.EventJSStatus = new CallbackDelegate(iwb.OnJSStatus);
                        cb.EventLinkStatus = new 
CallbackDelegate(iwb.OnLinkStatus);

Modified: trunk/mozembed/Mono.Mozilla/ChangeLog
===================================================================
--- trunk/mozembed/Mono.Mozilla/ChangeLog       2007-06-25 15:11:18 UTC (rev 
80688)
+++ trunk/mozembed/Mono.Mozilla/ChangeLog       2007-06-25 15:34:28 UTC (rev 
80689)
@@ -1,3 +1,9 @@
+2007-06-25 Andreia Gaita <[EMAIL PROTECTED]>
+
+       * Callback.cs, IWebBrowser.cs, WebBrowser.cs: 
+       Change OnWidgetLoaded callback to send the new  
+       handle when it's called.
+       
 2007-06-18     Andreia Gaita   <[EMAIL PROTECTED]>
 
        * initial checkin.
\ No newline at end of file

Modified: trunk/mozembed/Mono.Mozilla/IWebBrowser.cs
===================================================================
--- trunk/mozembed/Mono.Mozilla/IWebBrowser.cs  2007-06-25 15:11:18 UTC (rev 
80688)
+++ trunk/mozembed/Mono.Mozilla/IWebBrowser.cs  2007-06-25 15:34:28 UTC (rev 
80689)
@@ -6,7 +6,7 @@
 {      
        public interface IWebBrowser
        {
-               void OnWidgetLoaded();
+               void OnWidgetLoaded(IntPtr handle);
 
                
                

Modified: trunk/mozembed/tests/browser/WebBrowser.cs
===================================================================
--- trunk/mozembed/tests/browser/WebBrowser.cs  2007-06-25 15:11:18 UTC (rev 
80688)
+++ trunk/mozembed/tests/browser/WebBrowser.cs  2007-06-25 15:34:28 UTC (rev 
80689)
@@ -16,7 +16,6 @@
 
                public WebBrowser()
                {
-                       MozillaInvoke.xulbrowser_startup ();
                }
 
                public void Load () {
@@ -41,7 +40,8 @@
                }
                #region IWebBrowser Members
 
-               public void OnWidgetLoaded() {
+               public void OnWidgetLoaded (IntPtr handle) {
+                       xulbrowser = handle;
                        MessageBox.Show ("loaded");
                }
 
@@ -193,4 +193,4 @@
 
                #endregion
        }
-}
+}

Modified: trunk/mozembed/xulbrowser/BrowserWindow.cpp
===================================================================
--- trunk/mozembed/xulbrowser/BrowserWindow.cpp 2007-06-25 15:11:18 UTC (rev 
80688)
+++ trunk/mozembed/xulbrowser/BrowserWindow.cpp 2007-06-25 15:34:28 UTC (rev 
80689)
@@ -20,7 +20,14 @@
 // for getting the native mozilla drawing handle
 #include "nsIWidget.h"
 
+#ifdef NS_UNIX
+#include "gtkWidget.h"
+#include <gdk/gdk.h>
+#include <gtk/gtk.h>
+#endif 
 
+
+
 BrowserWindow::BrowserWindow (void)
 {
        owner = nsnull;
@@ -32,74 +39,117 @@
 {
        nsresult result;
 
-       mWebBrowser = do_CreateInstance( NS_WEBBROWSER_CONTRACTID );
-       if ( ! mWebBrowser )
+       webBrowser = do_CreateInstance( NS_WEBBROWSER_CONTRACTID );
+       if ( ! webBrowser )
                return NS_ERROR_FAILURE;
 
-    (void)mWebBrowser->SetContainerWindow( NS_STATIC_CAST( 
nsIWebBrowserChrome*, this ) );
+    (void)webBrowser->SetContainerWindow( NS_STATIC_CAST( 
nsIWebBrowserChrome*, this ) );
 
-    nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface( mWebBrowser );
+    nsCOMPtr<nsIDocShellTreeItem> dsti = do_QueryInterface( webBrowser );
     dsti->SetItemType( nsIDocShellTreeItem::typeContentWrapper );
 
-    mBaseWindow = do_QueryInterface( mWebBrowser );
+       webNav = do_QueryInterface(webBrowser);
+       sessionHistory = do_CreateInstance(NS_SHISTORY_CONTRACTID);
+       webNav->SetSessionHistory(sessionHistory);
+
+    nsCOMPtr<nsIWindowCreator> windowCreator (NS_STATIC_CAST(nsIWindowCreator 
*, this));
+
+    // Attach it via the watcher service
+    nsCOMPtr<nsIWindowWatcher> watcher = 
do_GetService(NS_WINDOWWATCHER_CONTRACTID);
+    if (watcher)
+      watcher->SetWindowCreator(windowCreator);
+
        
-       result = mBaseWindow->InitWindow( hwnd, nsnull,  0, 0, width, height );
-    result = mBaseWindow->Create();
+    baseWindow = do_QueryInterface( webBrowser );
+       
+       result = baseWindow->InitWindow( hwnd, nsnull,  0, 0, width, height );
+    result = baseWindow->Create();
 
     nsCOMPtr< nsIWebProgressListener > listener( NS_STATIC_CAST( 
nsIWebProgressListener*, this ) );
     nsCOMPtr< nsIWeakReference > thisListener( NS_GetWeakReference( listener ) 
);
-    (void)mWebBrowser->AddWebBrowserListener( thisListener, NS_GET_IID( 
nsIWebProgressListener ) );
+    (void)webBrowser->AddWebBrowserListener( thisListener, NS_GET_IID( 
nsIWebProgressListener ) );
 
-       mBaseWindow->SetVisibility( PR_TRUE );
+       baseWindow->SetVisibility( PR_TRUE );
 
-       mWebNav = do_QueryInterface( mWebBrowser, &result );
-       if ( NS_FAILED( result ) || ! mWebNav )
+       webNav = do_QueryInterface( webBrowser, &result );
+       if ( NS_FAILED( result ) || ! webNav )
        {
            return NS_ERROR_FAILURE;
        }
 
 
-    if ( mWebBrowser )
+    if ( webBrowser )
     {
+#ifdef NS_UNIX
                // save the window id of the newly created window
                nsCOMPtr<nsIWidget> mozWidget;
-               mBaseWindow->GetMainWidget(getter_AddRefs(mozWidget));
+               baseWindow->GetMainWidget(getter_AddRefs(mozWidget));
 
-               this->nativeMozWindow = NS_STATIC_CAST(Handle *, 
mozWidget->GetNativeData(NS_NATIVE_WINDOW));
+               GdkWindow *tmp_window = NS_STATIC_CAST(GdkWindow *, 
mozWidget->GetNativeData(NS_NATIVE_WINDOW));
+
+               // and, thanks to superwin we actually need the parent of that.
+               tmp_window = gdk_window_get_parent(tmp_window);
+               
+               // save the widget ID - it should be the mozarea of the window.
+               gpointer data = nsnull;
+               gdk_window_get_user_data(tmp_window, &data);
+               this->nativeMozWidget = NS_STATIC_CAST(Handle *, data);
+#endif         
                return NS_OK;
     }
 
     return NS_ERROR_FAILURE;
 }
 
-nsresult BrowserWindow::Navigate (const char *uri)
-{
-       if (mWebNav)
+nsresult BrowserWindow::Navigate (const char * uri)
+{
+#ifdef NS_UNIX
+       g_print("BrowserWindow::Navigate\n");
+#endif
+       this->uri = (const PRUnichar*)NS_ConvertUTF8toUTF16_external(uri).get();
+       return this->Navigate ();
+}
+
+nsresult BrowserWindow::Navigate ()
+{
+#ifdef NS_UNIX
+       g_print("BrowserWindow::Navigate2\n");
+#endif
+       if (webNav)
        {
-               mWebNav->LoadURI( reinterpret_cast< const PRUnichar* >( 
NS_ConvertUTF8toUTF16( uri ).get() ),
-                       nsIWebNavigation::LOAD_FLAGS_NONE,
-                               nsnull, nsnull, nsnull );
-
+               if (uri.Length())
+               {
+                       webNav->LoadURI( (const PRUnichar*)uri.get(),
+                               nsIWebNavigation::LOAD_FLAGS_NONE,
+                                       nsnull, nsnull, nsnull );
+               }
                return NS_OK;
        };
 
-       return NS_OK;
+       return NS_OK;
 }
+
+nsresult BrowserWindow::Show ()
+{
+       baseWindow = do_QueryInterface( webBrowser );
+       baseWindow->SetVisibility( PR_TRUE );
+       return NS_OK;
+}
 
-
 
////////////////////////////////////////////////////////////////////////////////
 //
 
 NS_IMPL_ADDREF(BrowserWindow)
 NS_IMPL_RELEASE(BrowserWindow)
 NS_INTERFACE_MAP_BEGIN(BrowserWindow)
-  NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
-  NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
-  NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
-  NS_INTERFACE_MAP_ENTRY(nsIURIContentListener)
-  NS_INTERFACE_MAP_ENTRY(nsSupportsWeakReference)
-  NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener)
-  NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebProgressListener)
+       NS_INTERFACE_MAP_ENTRY(nsIWebBrowserChrome)
+       NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
+       NS_INTERFACE_MAP_ENTRY(nsIWebProgressListener)
+       NS_INTERFACE_MAP_ENTRY(nsIURIContentListener)
+       NS_INTERFACE_MAP_ENTRY(nsSupportsWeakReference)
+       NS_INTERFACE_MAP_ENTRY(nsIDOMEventListener)
+       NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIWebProgressListener)
+       NS_INTERFACE_MAP_ENTRY(nsIWindowCreator)
 NS_INTERFACE_MAP_END
 
 
////////////////////////////////////////////////////////////////////////////////
@@ -110,9 +160,9 @@
 {
        if ( aIID.Equals( NS_GET_IID( nsIDOMWindow ) ) )
        {
-               if ( mWebBrowser )
+               if ( webBrowser )
                {
-                       return mWebBrowser->GetContentDOMWindow( ( 
nsIDOMWindow** )aInstancePtr );
+                       return webBrowser->GetContentDOMWindow( ( 
nsIDOMWindow** )aInstancePtr );
                };
 
                return NS_ERROR_NOT_INITIALIZED;
@@ -125,7 +175,7 @@
 /* void setStatus (in unsigned long statusType, in wstring status); */
 NS_IMETHODIMP BrowserWindow::SetStatus(PRUint32 statusType, const PRUnichar 
*status)
 {
-       mStatusText = (char *)NS_ConvertUTF16toUTF8( status ).get();
+       statusText = (char *)NS_ConvertUTF16toUTF8( status ).get();
 
        return NS_OK;
 }
@@ -134,17 +184,62 @@
 NS_IMETHODIMP BrowserWindow::GetWebBrowser(nsIWebBrowser * *aWebBrowser)
 {
        NS_ENSURE_ARG_POINTER( aWebBrowser );
-       *aWebBrowser = mWebBrowser;
+       *aWebBrowser = webBrowser;
        NS_IF_ADDREF( *aWebBrowser );
        return NS_OK;
 }
 NS_IMETHODIMP BrowserWindow::SetWebBrowser(nsIWebBrowser * aWebBrowser)
 {
        NS_ENSURE_ARG_POINTER( aWebBrowser );
-       mWebBrowser = aWebBrowser;
+       webBrowser = aWebBrowser;
        return NS_OK;
 }
 
+NS_IMETHODIMP 
+BrowserWindow::CreateChromeWindow(
+                       nsIWebBrowserChrome *aParent,
+                       PRUint32 aChromeFlags,
+                       nsIWebBrowserChrome **_retval)
+{
+#ifdef NS_UNIX
+       g_print("BrowserWindow::CreateChromeWindow\n");
+       NS_ENSURE_ARG_POINTER(_retval);
+
+       NativeEmbedWidget *newEmbed = nsnull;
+   
+    if (!this->owner)
+      return NS_ERROR_FAILURE;
+       
+
+       // check to make sure that we made a new window
+       if (!newEmbed)
+               return NS_ERROR_FAILURE;
+       
+       // The window _must_ be realized before we pass it back to the
+       // function that created it. Functions that create new windows
+       // will do things like GetDocShell() and the widget has to be
+       // realized before that can happen.
+       gtk_widget_realize(GTK_WIDGET(newEmbed));
+       
+       Widget *newOwner = NS_STATIC_CAST(Widget *, newEmbed->data);
+       
+       // set the chrome flag on the new window if it's a chrome open
+//     if (aChromeFlags & nsIWebBrowserChrome::CHROME_OPENAS_CHROME)
+//             newOwner->mIsChrome = PR_TRUE;
+       
+       *_retval = NS_STATIC_CAST(nsIWebBrowserChrome *, this);
+       
+       if (*_retval) {
+               NS_ADDREF(*_retval);
+               return NS_OK;
+       }
+       
+       return NS_ERROR_FAILURE;
+#endif
+
+       return NS_OK;
+}
+
 /* void onStateChange (in nsIWebProgress aWebProgress, in nsIRequest aRequest, 
in unsigned long aStateFlags, in nsresult aStatus); */
 NS_IMETHODIMP BrowserWindow::OnStateChange(nsIWebProgress* progress, 
nsIRequest* request,
                                                                                
   PRUint32 progressStateFlags, nsresult status)

Modified: trunk/mozembed/xulbrowser/BrowserWindow.h
===================================================================
--- trunk/mozembed/xulbrowser/BrowserWindow.h   2007-06-25 15:11:18 UTC (rev 
80688)
+++ trunk/mozembed/xulbrowser/BrowserWindow.h   2007-06-25 15:34:28 UTC (rev 
80689)
@@ -9,25 +9,32 @@
  * 
  */
 
-#include "nsIBaseWindow.h"
-#include "nsIDOMEventListener.h"
-#include "nsIDOMEventTarget.h"
-#include "nsIInterfaceRequestor.h"
-#include "nsIWebBrowserChrome.h"
-#include "nsIWebNavigation.h"
-#include "nsIWebProgress.h"
-#include "nsIWebProgressListener.h"
-#include "nsIURIContentListener.h"
+#include <nsIBaseWindow.h>
+#include <nsIDOMEventListener.h>
+#include <nsIDOMEventTarget.h>
+#include <nsIInterfaceRequestor.h>
+#include <nsIWebBrowserChrome.h>
+#include <nsIWebNavigation.h>
+#include <nsIWebProgress.h>
+#include <nsIWebProgressListener.h>
+#include <nsIURIContentListener.h>
 #include <nsIDOMEvent.h>
 #include <nsIDOMEventListener.h>
 #include <nsIDOMWindow.h>
 #include <nsIDOMKeyEvent.h>
 #include <nsIDOMMouseEvent.h>
-
-#include "nsIWeakReference.h"
-#include "nsWeakReference.h"
-#include "nsIWebBrowser.h"
 
+#include <nsIWeakReference.h>
+#include <nsWeakReference.h>
+#include <nsIWebBrowser.h>
+#include <nsIWidget.h>
+#include <nsISHistory.h>
+#include <nsIWindowCreator.h>
+#include <nsIWindowWatcher.h>
+
+#include <nsServiceManagerUtils.h>
+
+
 #include "Widget.h"
 
 #ifndef _BROWSERWINDOW_H_
@@ -41,7 +48,8 @@
        public nsIWebProgressListener,
        public nsIURIContentListener,
        public nsSupportsWeakReference,
-       public nsIDOMEventListener
+       public nsIDOMEventListener,
+       public nsIWindowCreator
 {
 
  public:
@@ -59,23 +67,36 @@
        NS_DECL_NSIWEBPROGRESSLISTENER
        NS_DECL_NSIURICONTENTLISTENER
        NS_DECL_NSIDOMEVENTLISTENER
+       NS_DECL_NSIWINDOWCREATOR
 
 
        nsresult Create ( Handle * hwnd, PRInt32 width, PRInt32 height);
-       nsresult Navigate (const char *uri);
+       nsresult Navigate (const char * uri);
+       nsresult Navigate ();
+       nsresult Show ();
+
+       Handle * getNativeWin () { return this->nativeMozWidget;}
        
        void setParent( Widget* owner ) { this->owner = owner; };
        Widget * getParent(  ) { return this->owner; };
-       Handle * getNativeWin () { return this->nativeMozWindow;}
+
+
+       void setUri( nsString uri ) { this->uri = uri; };
+       nsString getUri(  ) { return this->uri; };
        
 private:
 
-       Widget            *owner;
-       nsCOMPtr< nsIWebBrowser > mWebBrowser;
-       nsCOMPtr< nsIBaseWindow > mBaseWindow;
-       nsCOMPtr< nsIWebNavigation > mWebNav;
-       Handle * nativeMozWindow;
-       char * mStatusText;
+       Widget * owner;
+
+       nsCOMPtr<nsIWebBrowser>         webBrowser;
+       nsCOMPtr<nsIBaseWindow>         baseWindow;
+       nsCOMPtr<nsIWebNavigation>      webNav;
+       nsCOMPtr<nsISHistory>           sessionHistory;
+
+       nsString uri;
+       char * statusText;
+
+       Handle * nativeMozWidget;
 
 
 };

Modified: trunk/mozembed/xulbrowser/ChangeLog
===================================================================
--- trunk/mozembed/xulbrowser/ChangeLog 2007-06-25 15:11:18 UTC (rev 80688)
+++ trunk/mozembed/xulbrowser/ChangeLog 2007-06-25 15:34:28 UTC (rev 80689)
@@ -1,3 +1,40 @@
+2007-06-25 Andreia Gaita <[EMAIL PROTECTED]>
+
+       * BrowserWindow.cpp: 
+       - Apart from a few changes in variable 
+       naming (out with the prefixes, eek), add initializations 
+       for session history and window creator. 
+       - When on gtk, get the native   mozilla widget that is the 
+       real drawing surface (not used for now, might come in handy
+       later).
+       - Save the current uri in the object so it can be       reloaded 
+       later (overload to the Navigate method).
+       - Add a lot of debug printlines (gtk only).
+       - Add implementation of nsIWindowCreator's CreateChromeWindow 
+       (this is gtk only as far as I can tell, windows does not 
+       need this, and xlib toolkit probably doesn't, either).
+
+       * BrowserWindow.h: normalize includes and variable naming, 
+       add extra Navigate overload and uri 
+       getters/setters.
+       
+       * gtkWidget.cpp/h: Inherit it from window so it can be
+       self-suficient. Add a new window signal (not used yet).
+       Add a new constructor so it can also use a normal gtk window
+       as parent instead of a XID.
+       
+       * Widget.cpp/h: Add initialization of AppShell. This is 
+       absolutely required for the browser widget to work on 
+       linux, and is not mentioned *anywhere*. <grrrr>
+       Add thread support on linux/gtk (this gtk widget code
+       should go somewhere else...)
+       
+       * xulbrowser.cpp/h: Add thread to run the gtk main loop, 
+       and reroute all requests on linux/gtk to that thread so 
+       that things actually *work*.
+       New params class to help pass parameters to the gtk gui
+       thread.
+       
 2007-06-22 Andreia Gaita <[EMAIL PROTECTED]>
 
        * gtkWidget.cpp, gtkWidget.h: a custom gtk widget

Modified: trunk/mozembed/xulbrowser/Widget.cpp
===================================================================
--- trunk/mozembed/xulbrowser/Widget.cpp        2007-06-25 15:11:18 UTC (rev 
80688)
+++ trunk/mozembed/xulbrowser/Widget.cpp        2007-06-25 15:34:28 UTC (rev 
80689)
@@ -17,25 +17,31 @@
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
 #include "gtkWidget.h"
+#include <unistd.h>
 #endif 
 
 
 PRUint32 Widget::widgetCount = 0;
 
-#ifdef NS_UNIX
+static NS_DEFINE_CID(kAppShellCID, NS_APPSHELL_CID);
+
+#if 0
 static gboolean
 gtk_expose_event (GtkWidget *sender, GdkEventExpose *event, gpointer data)
 {
+       g_print("gtk_expose_event\n");
        gtk_signal_disconnect_by_func (GTK_OBJECT (sender),
                                  GTK_SIGNAL_FUNC (gtk_expose_event),
                                  data);        
        Widget * widget = NS_STATIC_CAST( Widget*, data );
        widget->CreateBrowserWindow ();
-       widget->events->EventOnWidgetLoaded();
+//     widget->events->EventOnWidgetLoaded();
 
 }
+
 #endif
 
+
 Widget::Widget (void)
 {
 }
@@ -50,6 +56,17 @@
                nsresult rv = GRE_Startup();
                if (NS_FAILED(rv))
                        return rv;
+               
+               nsCOMPtr<nsIAppShell> appShell;
+               appShell = do_CreateInstance(kAppShellCID);
+               if (!appShell) {
+                 NS_WARNING("Failed to create appshell in Widget::Load!\n");
+                 return -1;
+               }
+               sAppShell = appShell.get();
+               NS_ADDREF(sAppShell);
+               sAppShell->Create(0, nsnull);
+               sAppShell->Spinup();
 
        }
        this->events = events;
@@ -68,6 +85,20 @@
 nsresult 
 Widget::Init(Handle *hwnd, PRInt32 width, PRInt32 height)
 {
+       this->width = width;
+       this->height = height;
+       this->hwnd = hwnd;
+
+#ifdef NS_UNIX
+       gdk_threads_enter ();
+       GtkWidget *embed = 
native_embed_widget_foreign_new((GdkNativeWindow)(hwnd));
+       gtk_widget_set_usize(embed, width, height);
+       gtk_widget_show(embed);
+       gdk_threads_leave ();
+       this->hwnd = (Handle*)embed;
+#endif
+
+
        nsCOMPtr< nsIWebBrowser > newBrowser;
 
        browserWindow = new BrowserWindow ();
@@ -77,46 +108,21 @@
        browserWindow->AddRef ();
        browserWindow->SetChromeFlags( nsIWebBrowserChrome::CHROME_ALL );
 
-       this->width = width;
-       this->height = height;
-#ifdef NS_UNIX
-       gdk_window_set_debug_updates (TRUE);
 
-       GtkWidget * embed = native_embed_widget_new((GdkNativeWindow) (hwnd));
-       g_signal_connect (G_OBJECT (embed), "expose_event", G_CALLBACK 
(gtk_expose_event),this);
-       gtk_widget_show(embed);
-       this->hwnd = (Handle*)embed;
-       gtk_main();
-#else
-       this->hwnd = hwnd;
-#endif
-       
+
        this->CreateBrowserWindow ();
-       this->events->EventOnWidgetLoaded();
+       this->events->EventOnWidgetLoaded((Handle *)this);
+       return NS_OK;   
 }
 
 nsresult 
 Widget::CreateBrowserWindow()
 {
+       NS_WARNING("Widget::CreateBrowserWindow!\n");
        nsresult ret = browserWindow->Create( this->hwnd, this->width, 
this->height );
        Handle * nativeMozWindow = browserWindow->getNativeWin ();
-#ifdef NS_UNIX
-       // get the native drawing area
-       GdkWindow *tmp_window = (GdkWindow *)nativeMozWindow;
-       
-       // and, thanks to superwin we actually need the parent of that.
-       tmp_window = gdk_window_get_parent(tmp_window);
-       
-       // save the widget ID - it should be the mozarea of the window.
-       gpointer data = nsnull;
-       gdk_window_get_user_data(tmp_window, &data);
-       GtkWidget * mMozWindowWidget = NS_STATIC_CAST(GtkWidget *, data);
-
-       g_print ("new window=%x", mMozWindowWidget);
-#endif 
-       
        browserWindow->setParent( this );
-       browserWindow->Navigate ("http://www.google.com";);
+       browserWindow->Navigate ("http://www.mono-project.com";);
        return NS_OK;
 
 
@@ -124,8 +130,10 @@
 }
 
 
-nsresult Widget::Navigate (const char * uri)
-{
+nsresult 
+Widget::Navigate (const char * uri)
+{
+       NS_WARNING("Widget::Navigate!\n");
        if (browserWindow)
                return browserWindow->Navigate (uri);
 }

Modified: trunk/mozembed/xulbrowser/Widget.h
===================================================================
--- trunk/mozembed/xulbrowser/Widget.h  2007-06-25 15:11:18 UTC (rev 80688)
+++ trunk/mozembed/xulbrowser/Widget.h  2007-06-25 15:34:28 UTC (rev 80689)
@@ -53,7 +53,11 @@
                BrowserWindow *browserWindow;
                PRInt32 width;
                PRInt32 height;
+       
+               // the appshell we have created
+               nsIAppShell *sAppShell;
 
+
 };
 
 #endif

Modified: trunk/mozembed/xulbrowser/gtkWidget.cpp
===================================================================
--- trunk/mozembed/xulbrowser/gtkWidget.cpp     2007-06-25 15:11:18 UTC (rev 
80688)
+++ trunk/mozembed/xulbrowser/gtkWidget.cpp     2007-06-25 15:34:28 UTC (rev 
80689)
@@ -21,8 +21,11 @@
 static void    native_embed_widget_unmap(GtkWidget *widget);
 static gboolean native_embed_widget_expose(GtkWidget *widget, GdkEventExpose 
*event);
 
-static GtkWidgetClass *parent_class = NULL;
+static GtkWindowClass *parent_class = NULL;
 static GtkBinClass *bin_class = NULL;
+guint native_embed_widget_signals[EMBED_LAST_SIGNAL] = { 0 };
+
+
 G_DEFINE_TYPE (NativeEmbedWidget, native_embed_widget, GTK_TYPE_WINDOW)
 
 static void
@@ -35,7 +38,7 @@
        widget_class = GTK_WIDGET_CLASS(klass);
        object_class = GTK_OBJECT_CLASS(klass);
 
-       parent_class = (GtkWidgetClass*)gtk_type_class(gtk_widget_get_type());
+       parent_class = (GtkWindowClass*)gtk_type_class(gtk_window_get_type());
 
        widget_class->realize = native_embed_widget_realize;
        widget_class->unrealize = native_embed_widget_unrealize;
@@ -45,7 +48,16 @@
        widget_class->expose_event = native_embed_widget_expose;
        
        object_class->destroy = native_embed_widget_destroy;
+       
+       native_embed_widget_signals[NEW_WINDOW] =
+               gtk_signal_new("new_window",
+               GTK_RUN_FIRST,
+               G_OBJECT_CLASS_TYPE(klass),
+               GTK_SIGNAL_OFFSET(NativeEmbedWidgetClass, new_window),
+               gtk_marshal_NONE__POINTER_UINT,
+               GTK_TYPE_NONE, 2, GTK_TYPE_POINTER, GTK_TYPE_UINT);
 
+
 }
 
 static gboolean
@@ -74,14 +86,25 @@
        gtk_container_add(GTK_CONTAINER(embed), button);
        gtk_widget_show(button);
 */
+               
 }
 
 GtkWidget *
-native_embed_widget_new(GdkNativeWindow parent_id)
+native_embed_widget_new()
 {
+       
        g_print("native_embed_widget_new\n");
        NativeEmbedWidget * embed_widget = (NativeEmbedWidget *)g_object_new 
(GTK_TYPE_NATIVE_EMBED, NULL);
 
+       return GTK_WIDGET(embed_widget);
+}
+
+GtkWidget *
+native_embed_widget_foreign_new(GdkNativeWindow parent_id)
+{
+       g_print("native_embed_widget_new\n");
+       NativeEmbedWidget * embed_widget = (NativeEmbedWidget *)g_object_new 
(GTK_TYPE_NATIVE_EMBED, NULL);
+
        embed_widget->parent_window = gdk_window_lookup_for_display 
(gdk_display_get_default (), parent_id);
        
        if (!embed_widget->parent_window)
@@ -115,7 +138,6 @@
        g_return_if_fail(widget != NULL);
        g_return_if_fail(GTK_IS_NATIVE_EMBED(widget));
 
-       window = GTK_WINDOW (widget);
        embed_widget = GTK_NATIVE_EMBED(widget);
 
 
@@ -162,20 +184,16 @@
                                GDK_FOCUS_CHANGE_MASK);
        
        attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP;
-       attributes_mask |= (window->title ? GDK_WA_TITLE : 0);
-       attributes_mask |= (window->wmclass_name ? GDK_WA_WMCLASS : 0);
+//     attributes_mask |= (window->title ? GDK_WA_TITLE : 0);
+//     attributes_mask |= (window->wmclass_name ? GDK_WA_WMCLASS : 0);
        
+       if (!embed_widget->parent_window)
+               embed_widget->parent_window = gtk_widget_get_parent_window 
((GtkWidget*)embed_widget);
        widget->window = gdk_window_new (embed_widget->parent_window, 
&attributes, attributes_mask);
 
-       gdk_window_set_user_data (widget->window, window);
+       gdk_window_set_user_data (widget->window, embed_widget);
        widget->style = gtk_style_attach (widget->style, widget->window);
        gtk_style_set_background (widget->style, widget->window, 
GTK_STATE_NORMAL);
-       
-/*     
-       Widget *browserWidget = new Widget ();
-       browserWidget->Load ();
-       browserWidget->Init ((Handle*)embed_widget, attributes.width, 
attributes.height);
-*/
 }
 
 static void
@@ -220,7 +238,7 @@
 
        widget->allocation = *allocation;
 
-       g_print ("is realized=%d", GTK_WIDGET_REALIZED (widget));
+       g_print ("is realized=%d\n", GTK_WIDGET_REALIZED (widget));
        
        if (GTK_WIDGET_REALIZED (widget))
                gdk_window_move_resize (widget->window,
@@ -231,14 +249,14 @@
        
        if (bin->child && GTK_WIDGET_VISIBLE (bin->child))
        {
-               g_print ("is visible ");
+               g_print ("is visible \n");
                GtkAllocation child_allocation;
        
                child_allocation.x = child_allocation.y = GTK_CONTAINER 
(widget)->border_width;
                child_allocation.width = MAX (1, (gint)allocation->width - 
child_allocation.x * 2);
                child_allocation.height = MAX (1, (gint)allocation->height - 
child_allocation.y * 2);
                
-               g_print ("is visible %d %d", child_allocation.width, 
child_allocation.height);
+               g_print ("is visible %d %d\n", child_allocation.width, 
child_allocation.height);
                gtk_widget_size_allocate (bin->child, &child_allocation);
        }
 }

Modified: trunk/mozembed/xulbrowser/gtkWidget.h
===================================================================
--- trunk/mozembed/xulbrowser/gtkWidget.h       2007-06-25 15:11:18 UTC (rev 
80688)
+++ trunk/mozembed/xulbrowser/gtkWidget.h       2007-06-25 15:34:28 UTC (rev 
80689)
@@ -41,11 +41,53 @@
 struct _NativeEmbedWidgetClass
 {
        GtkWindowClass parent_class;
+       
+       void (* new_window) (NativeEmbedWidget *embed, 
+                                               NativeEmbedWidget **newEmbed,
+                                               guint chromemask);
+       
 };
 
-GtkWidget* native_embed_widget_new (GdkNativeWindow parent_id);
+GtkWidget* native_embed_widget_new (void);
+GtkWidget* native_embed_widget_foreign_new (GdkNativeWindow parent_id);
 
 
+enum {
+  LINK_MESSAGE,
+  JS_STATUS,
+  LOCATION,
+  TITLE,
+  PROGRESS,
+  PROGRESS_ALL,
+  NET_STATE,
+  NET_STATE_ALL,
+  NET_START,
+  NET_STOP,
+  NEW_WINDOW,
+  VISIBILITY,
+  DESTROY_BROWSER,
+  OPEN_URI,
+  SIZE_TO,
+  DOM_KEY_DOWN,
+  DOM_KEY_PRESS,
+  DOM_KEY_UP,
+  DOM_MOUSE_DOWN,
+  DOM_MOUSE_UP,
+  DOM_MOUSE_CLICK,
+  DOM_MOUSE_DBL_CLICK,
+  DOM_MOUSE_OVER,
+  DOM_MOUSE_OUT,
+  SECURITY_CHANGE,
+  STATUS_CHANGE,
+  DOM_ACTIVATE,
+  DOM_FOCUS_IN,
+  DOM_FOCUS_OUT,
+  EMBED_LAST_SIGNAL
+};
+
+extern guint native_embed_widget_signals[EMBED_LAST_SIGNAL];
+
+
 #ifdef __cplusplus
 }
 #endif

Modified: trunk/mozembed/xulbrowser/xulbrowser.cpp
===================================================================
--- trunk/mozembed/xulbrowser/xulbrowser.cpp    2007-06-25 15:11:18 UTC (rev 
80688)
+++ trunk/mozembed/xulbrowser/xulbrowser.cpp    2007-06-25 15:34:28 UTC (rev 
80689)
@@ -12,30 +12,156 @@
 #include "xulbrowser.h"
 #include "Widget.h"
 
-NS_METHOD_(void) xulbrowser_startup()
-{
-}
+#ifdef NS_UNIX
+#include <gtk/gtk.h>
+#include <gdk/gdkx.h>
+#include "gtkWidget.h"
+#include <unistd.h>
 
+GThread    *ui_thread_id;
+GAsyncQueue *queuein;
+GAsyncQueue *queueout;
+
+static void * gtk_startup (gpointer data);
+static gboolean gtk_init_done (gpointer data);
+static gboolean gtk_init (gpointer data);
+static gboolean gtk_createBrowserWindow (gpointer data);
+static gboolean gtk_navigate (gpointer data);
+static gboolean gtk_shutdown (gpointer data);
+#endif
+
 NS_METHOD_(Handle *)
 xulbrowser_init (CallbackBin *events)
 {
+#ifdef NS_UNIX
+       g_type_init();  
+       if (!g_thread_supported ()) g_thread_init (NULL);
+
+       queuein = g_async_queue_new ();
+       queueout = g_async_queue_new ();
+       
+       ui_thread_id = g_thread_create (gtk_startup, NULL, TRUE, NULL);
+       g_async_queue_pop (queueout);
+
+       g_idle_add (gtk_init, events);
+       return (Handle *)g_async_queue_pop (queueout);
+#else
        Widget *widget = new Widget ();
        widget->Load (events);
        return (Handle *)widget;
+#endif
 
 }
 
 NS_METHOD_(int)
 xulbrowser_createBrowserWindow (Handle *instance, Handle *hwnd, PRInt32 width, 
PRInt32 height)
 {
+       int ret = NS_ERROR_FAILURE;
        Widget *widget = (Widget *)instance;
+
+#ifdef NS_UNIX
+       Params * p = new Params (widget);
+       p->hwnd = hwnd;
+       p->width = width;
+       p->height = height;
+       g_idle_add (gtk_createBrowserWindow, p);
+       ret = *(int *)g_async_queue_pop (queueout);
+#else
        widget->Init (hwnd, width, height);
-       return NS_OK;
+       ret = NS_OK;
+#endif
+       
+       return ret;
 }
 
 NS_METHOD_(int)
 xulbrowser_navigate (Handle *instance, const char * uri)
 {
        Widget *widget = (Widget *)instance;
+#ifdef NS_UNIX
+       Params * p = new Params (widget);
+       p->uri = uri;
+       g_idle_add (gtk_navigate, &p);
+       return *(int *)g_async_queue_pop (queueout);
+#else
        return widget->Navigate (uri);
+#endif
 }
+
+
+#ifdef NS_UNIX
+static void *
+gtk_startup (gpointer data)
+{
+       g_print ("wakeup_gtk %p starting...\n", g_thread_self ());
+       gdk_threads_enter ();   
+
+       int argc = 0;
+       char **argv=NULL;
+       gtk_init(&argc, &argv);
+       gdk_window_set_debug_updates (TRUE);    
+       g_idle_add (gtk_init_done, NULL);
+       gtk_main();
+       gdk_threads_leave ();
+
+       return NULL;
+}
+
+static gboolean
+gtk_init_done (gpointer data)
+{
+       g_print ("callback_initdone %p \n", g_thread_self ());  
+       int p = 1;
+       g_async_queue_push (queueout, &p);
+}
+
+
+static gboolean
+gtk_init (gpointer data)
+{
+       CallbackBin *events = (CallbackBin *)data;
+       Widget *widget = new Widget ();
+
+       gdk_threads_enter ();
+       widget->Load (events);
+       gdk_threads_leave ();
+
+       g_async_queue_push (queueout, widget);
+}
+
+
+static gboolean
+gtk_createBrowserWindow (gpointer data)
+{
+       Params * p = (Params *)data;
+       Widget *widget = (Widget *)p->instance;
+       gdk_threads_enter ();
+       nsresult ret = widget->Init (p->hwnd, p->width, p->height);
+       gdk_threads_leave ();
+
+       g_async_queue_push (queueout, &ret);
+}
+
+static gboolean
+gtk_navigate (gpointer data)
+{
+       Params * p = (Params *)data;    
+       Widget *widget = (Widget *)p->instance;
+       gdk_threads_enter ();
+               
+       nsresult ret = widget->Navigate (p->uri);
+       gdk_threads_leave ();
+
+       g_async_queue_push (queueout, &ret);
+}
+
+
+static gboolean
+gtk_shutdown (gpointer data)
+{
+       g_print ("gtk_shutdown %p \n", g_thread_self ());       
+       gdk_threads_enter ();   
+       gtk_main_quit();
+       gdk_threads_leave ();
+}
+#endif

Modified: trunk/mozembed/xulbrowser/xulbrowser.h
===================================================================
--- trunk/mozembed/xulbrowser/xulbrowser.h      2007-06-25 15:11:18 UTC (rev 
80688)
+++ trunk/mozembed/xulbrowser/xulbrowser.h      2007-06-25 15:34:28 UTC (rev 
80689)
@@ -8,45 +8,51 @@
  * See the LICENSE file included with the distribution for details.
  * 
  */
-
-#ifndef _XULEMBED_H_
-#define _XULEMBED_H_
-
-//Gecko Embedding API
-#include <nsEmbedAPI.h>
-
-//XPCOM API
-#include <nsCOMPtr.h>
-#include <nsIComponentManager.h>
-#include <nsComponentManagerUtils.h>
-#include <nsEmbedCID.h>
-
-//XPCOMGlue API
-#include <nsXPCOMGlue.h>
-
-//MozillaString API
-#include <nsStringAPI.h>
-
-//WebBrowser
-#include <nsIWebBrowser.h>
-
-//WebBrowser Interface
-#include <nsIWebBrowserFocus.h>
-#include <nsIBaseWindow.h>
-#include <nsIWebNavigation.h>
-
-#ifdef WIN32
-#define NS_EXPORT_(type) __declspec(dllexport) type __stdcall
-#endif
-
+
+#ifndef _XULEMBED_H_
+#define _XULEMBED_H_
+
+//Gecko Embedding API
+#include <nsEmbedAPI.h>
+
+//XPCOM API
+#include <nsCOMPtr.h>
+#include <nsIComponentManager.h>
+#include <nsComponentManagerUtils.h>
+#include <nsEmbedCID.h>
+
+//XPCOMGlue API
+#include <nsXPCOMGlue.h>
+
+//MozillaString API
+#include <nsStringAPI.h>
+
+//WebBrowser
+#include <nsIWebBrowser.h>
+
+//WebBrowser Interface
+#include <nsIWebBrowserFocus.h>
+#include <nsIBaseWindow.h>
+#include <nsIWebNavigation.h>
+
+// for NS_APPSHELL_CID
+#include <nsWidgetsCID.h>
+#include <nsIAppShell.h>
+
+#ifdef WIN32
+#define NS_EXPORT_(type) __declspec(dllexport) type __stdcall
+#define STDCALL __stdcall
+#else
+#define STDCALL 
+#endif
+
 #ifdef __cplusplus
 extern "C"
 {
-#endif
-
-
-       typedef void * Handle;
-
+#endif
+
+       typedef void * Handle;
+
        typedef struct _SizeInfo SizeInfo;
        typedef struct _ModifierKeys ModifierKeys;
        typedef struct _MouseInfo MouseInfo;
@@ -55,7 +61,7 @@
 
        struct _CallbackBin
        {
-               void (*EventOnWidgetLoaded) (void);
+               void (STDCALL *EventOnWidgetLoaded) (Handle* handle);
                void (*EventJSStatus) (void);
                void (*EventLinkStatus) (void);
                void (*EventDestroyBrowser) (void);
@@ -92,7 +98,7 @@
                PRBool (*EventFocusOut) (PRInt32 detail);
                PRBool (*EventBeforeURIOpen) (const char* url);
        };                              
-
+
        typedef enum
        {
                EMBED_FLAG_START = 1,
@@ -134,21 +140,39 @@
        {
                PRUint32 charCode;
                PRUint32 keyCode;
-       };
-
-// Function Exports
-
-       NS_EXPORT_(void) xulbrowser_startup();
-       NS_EXPORT_(Handle *) xulbrowser_init (CallbackBin *events);
-       NS_EXPORT_(int) xulbrowser_createBrowserWindow (Handle *instance, 
Handle *hwnd, PRInt32 width, PRInt32 height);
-       NS_EXPORT_(int) xulbrowser_navigate (Handle *instance, const char * 
uri);
+       };
 
+// Function Exports
 
+       NS_EXPORT_(Handle *) xulbrowser_init (CallbackBin *events);
+       NS_EXPORT_(int) xulbrowser_createBrowserWindow (Handle *instance, 
Handle *hwnd, PRInt32 width, PRInt32 height);
+       NS_EXPORT_(int) xulbrowser_navigate (Handle *instance, const char * 
uri);
+
+
 #ifdef __cplusplus
 }
 #endif                         /* __cplusplus */
 
 
+class Widget;
+class Params {
+public:
+       Params(Widget *instance)
+       {
+               this->instance = instance;
+       }
 
+       ~Params ()
+       {
+       }
+       
+       Widget * instance;
+       Handle * hwnd;
+       PRInt32 width;
+       PRInt32 height;
+       const char * uri;
+       
+};
 
+
 #endif

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to