* Mono.Mozilla/Base.cs, Mono.Mozilla/WebBrowser.cs: Separate initialization
authorAndreia Gaita <avidigal@novell.com>
Sun, 23 Nov 2008 06:02:44 +0000 (06:02 -0000)
committerAndreia Gaita <avidigal@novell.com>
Sun, 23 Nov 2008 06:02:44 +0000 (06:02 -0000)
in 3 stages so events can be registered before the window is actually created.
The creation of the window is now done only when a user requests something
from the binding (like opening a window, or rendering content)

2008-11-23  Andreia Gaita <shana@jitted.com>

svn path=/trunk/mcs/; revision=119732

mcs/class/Mono.WebBrowser/ChangeLog
mcs/class/Mono.WebBrowser/Mono.Mozilla/Base.cs
mcs/class/Mono.WebBrowser/Mono.Mozilla/WebBrowser.cs

index 638272c998e2cf7e00b73e8ffb81bd84166c84f1..38da68eb0a703a697faed8d8b34244e71c5eba31 100644 (file)
@@ -1,3 +1,10 @@
+2008-11-23  Andreia Gaita <shana@jitted.com> 
+
+       * Mono.Mozilla/Base.cs, Mono.Mozilla/WebBrowser.cs: Separate initialization 
+       in 3 stages so events can be registered before the window is actually created. 
+       The creation of the window is now done only when a user requests something
+       from the binding (like opening a window, or rendering content)
+
 2008-11-19  Andreia Gaita <shana@jitted.com> 
 
        * Mono.Mozilla/DOM/Node.cs, Mono.Mozilla/DOM/Window.cs: Fix comparison operators
index d1f59913c4d263bab8e287c5dfa555e40ab4cdaf..f6221a7d19eef162ecfc8822aabf19c843a72a75 100644 (file)
@@ -112,7 +112,7 @@ namespace Mono.Mozilla
                        IntPtr ptrCallback = Marshal.AllocHGlobal (Marshal.SizeOf (info.callback));
                        Marshal.StructureToPtr (info.callback, ptrCallback, true);
                        
-                       info.gluezilla = gluezilla_createBrowserWindow (ptrCallback, handle, width, height, Environment.CurrentDirectory, monoMozDir, control.platform);
+                       info.gluezilla = gluezilla_bind (ptrCallback, handle, width, height, Environment.CurrentDirectory, monoMozDir, control.platform);
                        lock (initLock) {
                                if (info.gluezilla == IntPtr.Zero) {
                                        Marshal.FreeHGlobal (ptrCallback);
@@ -125,6 +125,15 @@ namespace Mono.Mozilla
                        return true;
                }
 
+               public static bool Create (IWebBrowser control) {
+                       if (!isInitialized ())
+                               return false;
+                       BindingInfo info = getBinding (control);
+
+                       gluezilla_createBrowserWindow (info.gluezilla);
+                       return true;
+               }
+
                public static void Shutdown (IWebBrowser control)
                {
                        lock (initLock) {
@@ -278,11 +287,17 @@ namespace Mono.Mozilla
                private static extern short gluezilla_init (Platform platform, out Platform mozPlatform);
 
                [DllImport ("gluezilla")]
-               private static extern IntPtr gluezilla_shutdown (IntPtr instance);
+               private static extern IntPtr gluezilla_bind (IntPtr events, IntPtr hwnd,
+                                       Int32 width, Int32 height,
+                                       string startDir, string dataDir,
+                                       Platform platform);
 
                [DllImport ("gluezilla")]
-               private static extern IntPtr gluezilla_createBrowserWindow (/*IntPtr instance, */IntPtr events, IntPtr hwnd, Int32 width, Int32 height, string startDir, string dataDir, Platform platform);
-               
+               private static extern int gluezilla_createBrowserWindow (IntPtr instance);
+
+               [DllImport ("gluezilla")]
+               private static extern IntPtr gluezilla_shutdown (IntPtr instance);
+
                // layout
                [DllImport ("gluezilla")]
                private static extern int gluezilla_focus (IntPtr instance, FocusOption focus);
@@ -352,10 +367,6 @@ namespace Mono.Mozilla
                        string aBuf, 
                        uint aCount);
 
-               [DllImport ("gluezilla")]
-               [return: MarshalAs (UnmanagedType.Interface)]
-               public static extern nsIServiceManager  gluezilla_getServiceManager ();
-
                [DllImport ("gluezilla")]
                [return: MarshalAs (UnmanagedType.Interface)]
                public static extern nsIServiceManager  gluezilla_getServiceManager2 (IntPtr instance);
index 680be22e0bc738697f0f086b15a722b47a4c702b..ef08685675d862c18fe6d174475c9f2661e5604c 100644 (file)
@@ -38,19 +38,22 @@ namespace Mono.Mozilla
 {
        internal class WebBrowser : IWebBrowser
        {
-               private bool loaded;
-               private DOM.Document document;
+               bool loaded;
+               bool created = false;
+               bool creating = false;
+
+               DOM.Document document;
                
                internal DOM.Navigation navigation;
                internal Platform platform;
                internal Platform enginePlatform;
                internal Callback callbacks;
-               private System.ComponentModel.EventHandlerList events;
-               private System.ComponentModel.EventHandlerList domEvents;
+               System.ComponentModel.EventHandlerList events;
+               System.ComponentModel.EventHandlerList domEvents;
 
-               private string statusText;
+               string statusText;
 
-               private bool streamingMode;
+               bool streamingMode;
                
                internal Hashtable documents;
                
@@ -68,6 +71,16 @@ namespace Mono.Mozilla
                        return loaded;
                }
 
+               bool Created {
+                       get {
+                               if (!creating && !created) {
+                                       creating = true;
+                                       created = Base.Create (this);
+                               }
+                               return created;
+                       }
+               }
+
                public void Shutdown ()
                {
                        Base.Shutdown (this);
@@ -107,6 +120,8 @@ namespace Mono.Mozilla
 
                public INavigation Navigation {
                        get {
+                               if (!Created) return null;
+
                                if (navigation == null) {
                                        
                                        nsIWebNavigation webNav = Base.GetWebNavigation (this);
@@ -123,6 +138,7 @@ namespace Mono.Mozilla
                public bool Offline {
                        get {
                                bool ret;
+                               if (!Created) return true;
                                IOService.getOffline (out ret);
                                return ret;
                        }
@@ -242,30 +258,35 @@ namespace Mono.Mozilla
                #region Layout
                public void FocusIn (FocusOption focus)
                {
+                       if (!created) return;
                        Base.Focus (this, focus);
                }
                public void FocusOut ()
                {
+                       if (!created) return;
                        Base.Blur (this);
                }
                
                public void Activate ()
                {
+                       if (!created) return;
                        Base.Activate (this);
                }
                public void Deactivate ()
                {
+                       if (!created) return;
                        Base.Deactivate (this);
                }
 
                public void Resize (int width, int height)
                {
+                       if (!created) return;
                        Base.Resize (this, width, height);                      
                }
-               
 
                public void Render (byte[] data)
                {
+                       if (!Created) return;
                        if (data == null)
                                throw new ArgumentNullException ("data");
                        string html = System.Text.ASCIIEncoding.UTF8.GetString (data);
@@ -274,13 +295,14 @@ namespace Mono.Mozilla
 
                public void Render (string html)
                {
+                       if (!Created) return;
                        Render (html, "file:///", "text/html");
                }
 
                                
                public void Render (string html, string uri, string contentType)
                {
-                       
+                       if (!Created) return;
                        nsIWebBrowserStream stream;
                        if (Navigation != null) {
                                stream = (nsIWebBrowserStream) navigation.navigation;
@@ -305,6 +327,7 @@ namespace Mono.Mozilla
                }
                
                public void ExecuteScript (string script) {
+                       if (!Created) return;
                        Base.EvalScript (this, script);
                }