MSHTML: Init nsWebBrowser window while creating nscontainer

Jacek Caban jack at itma.pwr.wroc.pl
Tue Aug 9 16:56:31 CDT 2005


nsWebBrowser's initialization is incomplete before
calling Create method. The problem is that we have
to init its window first and then we can't change its
parent. That's why we need to create one more
window (the parent of the nsWebBrowser window)
that is reparented to the HTMLDocument's window
after creating it. My next patches require to have
nsWebBrowser initialized.

Changelog:
    Init nsWebBrowser window while creating nscontainer
-------------- next part --------------
Index: dlls/mshtml/mshtml_private.h
===================================================================
RCS file: /home/wine/wine/dlls/mshtml/mshtml_private.h,v
retrieving revision 1.20
diff -u -p -r1.20 mshtml_private.h
--- dlls/mshtml/mshtml_private.h	9 Aug 2005 20:46:05 -0000	1.20
+++ dlls/mshtml/mshtml_private.h	9 Aug 2005 21:41:27 -0000
@@ -67,8 +67,6 @@ struct NSContainer {
     nsIBaseWindow *window;
 
     HWND hwnd;
-
-    LPWSTR url; /* hack! */
 };
 
 
Index: dlls/mshtml/nsembed.c
===================================================================
RCS file: /home/wine/wine/dlls/mshtml/nsembed.c,v
retrieving revision 1.2
diff -u -p -r1.2 nsembed.c
--- dlls/mshtml/nsembed.c	3 Aug 2005 21:27:03 -0000	1.2
+++ dlls/mshtml/nsembed.c	9 Aug 2005 21:41:27 -0000
@@ -67,6 +67,52 @@ static HINSTANCE hXPCOM = NULL;
 static nsIServiceManager *pServMgr = NULL;
 static nsIComponentManager *pCompMgr = NULL;
 
+static const WCHAR wszNsContainer[] = {'N','s','C','o','n','t','a','i','n','e','r',0};
+
+static ATOM nscontainer_class;
+
+static LRESULT WINAPI nsembed_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+    HTMLDocument *This;
+
+    static const WCHAR wszTHIS[] = {'T','H','I','S',0};
+
+    if(msg == WM_CREATE) {
+        This = *(HTMLDocument**)lParam;
+        SetPropW(hwnd, wszTHIS, This);
+    }else {
+        This = (HTMLDocument*)GetPropW(hwnd, wszTHIS);
+    }
+
+    switch(msg) {
+        case WM_SIZE:
+            TRACE("(%p)->(WM_SIZE)\n", This);
+
+            nsresult nsres;
+            nsres = nsIBaseWindow_SetSize(This->nscontainer->window,
+                    LOWORD(lParam), HIWORD(lParam), TRUE);
+            if(NS_FAILED(nsres))
+                WARN("SetSize failed: %08lx\n", nsres);
+    }
+
+    return DefWindowProcW(hwnd, msg, wParam, lParam);
+}
+
+
+static void register_nscontainer_class(void)
+{
+    static WNDCLASSEXW wndclass = {
+        sizeof(WNDCLASSEXW),
+        CS_DBLCLKS,
+        nsembed_proc,
+        0, 0, NULL, NULL, NULL, NULL, NULL,
+        wszNsContainer,
+        NULL,
+    };
+    wndclass.hInstance = hInst;
+    nscontainer_class = RegisterClassExW(&wndclass);
+}
+
 static BOOL get_mozilla_path(PRUnichar *gre_path)
 {
     DWORD res, type, i, size = MAX_PATH;
@@ -124,8 +170,6 @@ static BOOL get_mozctl_path(PRUnichar *g
     return TRUE;
 }
 
-
-
 static BOOL load_gecko()
 {
     nsresult nsres;
@@ -143,7 +187,7 @@ static BOOL load_gecko()
         return pCompMgr != NULL;
     tried_load = TRUE;
 
-    if(!(get_mozctl_path(gre_path) || get_mozilla_path(gre_path))) {
+    if(!get_mozctl_path(gre_path) && !get_mozilla_path(gre_path)) {
         MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
         return FALSE;
     }
@@ -157,8 +201,6 @@ static BOOL load_gecko()
         static WCHAR wszPATH[] = {'P','A','T','H',0};
         int len;
 
-        TRACE("here\n");
-
         GetEnvironmentVariableW(wszPATH, path_env, sizeof(path_env)/sizeof(WCHAR));
         len = strlenW(path_env);
         path_env[len++] = ';';
@@ -238,7 +280,6 @@ void close_gecko()
 
 void HTMLDocument_NSContainer_Init(HTMLDocument *This)
 {
-    NSContainer *ret;
     nsIWebBrowserSetup *wbsetup;
     nsresult nsres;
 
@@ -247,20 +288,19 @@ void HTMLDocument_NSContainer_Init(HTMLD
     if(!load_gecko())
         return;
 
-    ret = HeapAlloc(GetProcessHeap(), 0, sizeof(NSContainer));
-    ret->url = NULL;
+    This->nscontainer = HeapAlloc(GetProcessHeap(), 0, sizeof(NSContainer));
 
-    nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr,
-            NS_WEBBROWSER_CONTRACTID, NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser);
+    nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
+            NULL, &IID_nsIWebBrowser, (void**)&This->nscontainer->webbrowser);
     if(NS_FAILED(nsres))
         ERR("Creating WebBrowser failed: %08lx\n", nsres);
 
-    nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow,
-            (void**)&ret->window);
+    nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser, &IID_nsIBaseWindow,
+            (void**)&This->nscontainer->window);
     if(NS_FAILED(nsres))
         ERR("Could not get nsIBaseWindow interface: %08lx\n", nsres);
 
-    nsres = nsIWebBrowser_QueryInterface(ret->webbrowser,
+    nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser,
             &IID_nsIWebBrowserSetup, (void**)&wbsetup);
     if(NS_SUCCEEDED(nsres)) {
         nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, TRUE);
@@ -271,12 +311,30 @@ void HTMLDocument_NSContainer_Init(HTMLD
         ERR("Could not get nsIWebBrowserSetup interface\n");
     }
 
-    nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation,
-            (void**)&ret->navigation);
+    nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser, &IID_nsIWebNavigation,
+            (void**)&This->nscontainer->navigation);
     if(NS_FAILED(nsres))
         ERR("Could not get nsIWebNavigation interface: %08lx\n", nsres);
 
-    This->nscontainer = ret;
+    if(!nscontainer_class)
+        register_nscontainer_class();
+
+    This->nscontainer->hwnd = CreateWindowExW(0, wszNsContainer, NULL,
+            WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, 0, 0, 100, 100,
+            GetDesktopWindow(), NULL, hInst, This);
+
+    nsres = nsIBaseWindow_InitWindow(This->nscontainer->window, This->nscontainer->hwnd, NULL,
+            0, 0, 100, 100);
+    if(NS_SUCCEEDED(nsres)) {
+        nsres = nsIBaseWindow_Create(This->nscontainer->window);
+        if(NS_FAILED(nsres))
+            WARN("Creating window failed: %08lx\n", nsres);
+
+        nsIBaseWindow_SetVisibility(This->nscontainer->window, FALSE);
+        nsIBaseWindow_SetEnabled(This->nscontainer->window, FALSE);
+    }else {
+        ERR("InitWindow failed: %08lx\n", nsres);
+    }
 }
 
 void HTMLDocument_NSContainer_Destroy(HTMLDocument *This)
Index: dlls/mshtml/view.c
===================================================================
RCS file: /home/wine/wine/dlls/mshtml/view.c,v
retrieving revision 1.11
diff -u -p -r1.11 view.c
--- dlls/mshtml/view.c	1 Aug 2005 10:59:45 -0000	1.11
+++ dlls/mshtml/view.c	9 Aug 2005 21:41:28 -0000
@@ -71,35 +71,13 @@ static void paint_disabled(HWND hwnd) {
 
 static void activate_gecko(HTMLDocument *This)
 {
-    RECT rect;
-    nsresult nsres;
-
     TRACE("(%p) %p\n", This, This->nscontainer->window);
 
-    GetClientRect(This->hwnd, &rect);
-
-    nsres = nsIBaseWindow_InitWindow(This->nscontainer->window, This->hwnd, NULL,
-            0, 0, rect.right, rect.bottom);
-
-    if(nsres == NS_OK) {
-        nsres = nsIBaseWindow_Create(This->nscontainer->window);
-        if(NS_FAILED(nsres))
-            WARN("Creating window failed: %08lx\n", nsres);
+    SetParent(This->nscontainer->hwnd, This->hwnd);
+    ShowWindow(This->nscontainer->hwnd, SW_SHOW);
 
-        nsIBaseWindow_SetVisibility(This->nscontainer->window, TRUE);
-        nsIBaseWindow_SetEnabled(This->nscontainer->window, TRUE);
-    }else {
-        ERR("Initializing window failed: %08lx\n", nsres);
-    }
-
-    if(This->nscontainer->url) {
-        TRACE("Loading  url: %s\n", debugstr_w(This->nscontainer->url));
-        nsres = nsIWebNavigation_LoadURI(This->nscontainer->navigation, This->nscontainer->url,
-                LOAD_FLAGS_NONE, NULL, NULL, NULL);
-        if(NS_FAILED(nsres))
-            ERR("LoadURI failed: %08lx\n", nsres);
-        This->nscontainer->url = NULL;
-    }
+    nsIBaseWindow_SetVisibility(This->nscontainer->window, TRUE);
+    nsIBaseWindow_SetEnabled(This->nscontainer->window, TRUE);
 }
 
 static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
@@ -127,14 +105,9 @@ static LRESULT WINAPI serverwnd_proc(HWN
         break;
     case WM_SIZE:
         TRACE("(%p)->(WM_SIZE)\n", This);
-
-        if(This->nscontainer) {
-            nsresult nsres;
-            nsres = nsIBaseWindow_SetSize(This->nscontainer->window,
-                    LOWORD(lParam), HIWORD(lParam), TRUE);
-            if(NS_FAILED(nsres))
-                WARN("SetSize failed: %08lx\n", nsres);
-        }
+        if(This->nscontainer)
+            SetWindowPos(This->nscontainer->hwnd, NULL, 0, 0, LOWORD(lParam), HIWORD(lParam),
+                    SWP_NOZORDER | SWP_NOACTIVATE);
     }
         
     return DefWindowProcW(hwnd, msg, wParam, lParam);
Index: dlls/mshtml/persist.c
===================================================================
RCS file: /home/wine/wine/dlls/mshtml/persist.c,v
retrieving revision 1.6
diff -u -p -r1.6 persist.c
--- dlls/mshtml/persist.c	9 Aug 2005 20:46:05 -0000	1.6
+++ dlls/mshtml/persist.c	9 Aug 2005 21:41:28 -0000
@@ -265,17 +265,12 @@ static HRESULT WINAPI PersistMoniker_Loa
         }
         TRACE("got url: %s\n", debugstr_w(url));
 
-        if(This->hwnd) {
-            nsres = nsIWebNavigation_LoadURI(This->nscontainer->navigation, url,
-                    LOAD_FLAGS_NONE, NULL, NULL, NULL);
-            if(NS_SUCCEEDED(nsres))
-                return S_OK;
-            else
-                WARN("LoadURI failed: %08lx\n", nsres);
-        }else {
-            This->nscontainer->url = url;
+        nsres = nsIWebNavigation_LoadURI(This->nscontainer->navigation, url,
+                LOAD_FLAGS_NONE, NULL, NULL, NULL);
+        if(NS_SUCCEEDED(nsres))
             return S_OK;
-        }
+        else
+            WARN("LoadURI failed: %08lx\n", nsres);
     }    
 
     /* FIXME: Use grfMode */


More information about the wine-patches mailing list