Commit 2255e6fe authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

Init nsWebBrowser window while creating nscontainer.

parent 21e3ba8c
...@@ -67,8 +67,6 @@ struct NSContainer { ...@@ -67,8 +67,6 @@ struct NSContainer {
nsIBaseWindow *window; nsIBaseWindow *window;
HWND hwnd; HWND hwnd;
LPWSTR url; /* hack! */
}; };
......
...@@ -67,6 +67,52 @@ static HINSTANCE hXPCOM = NULL; ...@@ -67,6 +67,52 @@ static HINSTANCE hXPCOM = NULL;
static nsIServiceManager *pServMgr = NULL; static nsIServiceManager *pServMgr = NULL;
static nsIComponentManager *pCompMgr = 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;
nsresult nsres;
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);
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) static BOOL get_mozilla_path(PRUnichar *gre_path)
{ {
DWORD res, type, i, size = MAX_PATH; DWORD res, type, i, size = MAX_PATH;
...@@ -124,8 +170,6 @@ static BOOL get_mozctl_path(PRUnichar *gre_path) ...@@ -124,8 +170,6 @@ static BOOL get_mozctl_path(PRUnichar *gre_path)
return TRUE; return TRUE;
} }
static BOOL load_gecko() static BOOL load_gecko()
{ {
nsresult nsres; nsresult nsres;
...@@ -143,7 +187,7 @@ static BOOL load_gecko() ...@@ -143,7 +187,7 @@ static BOOL load_gecko()
return pCompMgr != NULL; return pCompMgr != NULL;
tried_load = TRUE; 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"); MESSAGE("Could not load Mozilla. HTML rendering will be disabled.\n");
return FALSE; return FALSE;
} }
...@@ -157,8 +201,6 @@ static BOOL load_gecko() ...@@ -157,8 +201,6 @@ static BOOL load_gecko()
static WCHAR wszPATH[] = {'P','A','T','H',0}; static WCHAR wszPATH[] = {'P','A','T','H',0};
int len; int len;
TRACE("here\n");
GetEnvironmentVariableW(wszPATH, path_env, sizeof(path_env)/sizeof(WCHAR)); GetEnvironmentVariableW(wszPATH, path_env, sizeof(path_env)/sizeof(WCHAR));
len = strlenW(path_env); len = strlenW(path_env);
path_env[len++] = ';'; path_env[len++] = ';';
...@@ -238,7 +280,6 @@ void close_gecko() ...@@ -238,7 +280,6 @@ void close_gecko()
void HTMLDocument_NSContainer_Init(HTMLDocument *This) void HTMLDocument_NSContainer_Init(HTMLDocument *This)
{ {
NSContainer *ret;
nsIWebBrowserSetup *wbsetup; nsIWebBrowserSetup *wbsetup;
nsresult nsres; nsresult nsres;
...@@ -247,20 +288,19 @@ void HTMLDocument_NSContainer_Init(HTMLDocument *This) ...@@ -247,20 +288,19 @@ void HTMLDocument_NSContainer_Init(HTMLDocument *This)
if(!load_gecko()) if(!load_gecko())
return; return;
ret = HeapAlloc(GetProcessHeap(), 0, sizeof(NSContainer)); This->nscontainer = HeapAlloc(GetProcessHeap(), 0, sizeof(NSContainer));
ret->url = NULL;
nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, nsres = nsIComponentManager_CreateInstanceByContractID(pCompMgr, NS_WEBBROWSER_CONTRACTID,
NS_WEBBROWSER_CONTRACTID, NULL, &IID_nsIWebBrowser, (void**)&ret->webbrowser); NULL, &IID_nsIWebBrowser, (void**)&This->nscontainer->webbrowser);
if(NS_FAILED(nsres)) if(NS_FAILED(nsres))
ERR("Creating WebBrowser failed: %08lx\n", nsres); ERR("Creating WebBrowser failed: %08lx\n", nsres);
nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIBaseWindow, nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser, &IID_nsIBaseWindow,
(void**)&ret->window); (void**)&This->nscontainer->window);
if(NS_FAILED(nsres)) if(NS_FAILED(nsres))
ERR("Could not get nsIBaseWindow interface: %08lx\n", 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); &IID_nsIWebBrowserSetup, (void**)&wbsetup);
if(NS_SUCCEEDED(nsres)) { if(NS_SUCCEEDED(nsres)) {
nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, TRUE); nsres = nsIWebBrowserSetup_SetProperty(wbsetup, SETUP_IS_CHROME_WRAPPER, TRUE);
...@@ -271,12 +311,30 @@ void HTMLDocument_NSContainer_Init(HTMLDocument *This) ...@@ -271,12 +311,30 @@ void HTMLDocument_NSContainer_Init(HTMLDocument *This)
ERR("Could not get nsIWebBrowserSetup interface\n"); ERR("Could not get nsIWebBrowserSetup interface\n");
} }
nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIWebNavigation, nsres = nsIWebBrowser_QueryInterface(This->nscontainer->webbrowser, &IID_nsIWebNavigation,
(void**)&ret->navigation); (void**)&This->nscontainer->navigation);
if(NS_FAILED(nsres)) if(NS_FAILED(nsres))
ERR("Could not get nsIWebNavigation interface: %08lx\n", 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) void HTMLDocument_NSContainer_Destroy(HTMLDocument *This)
......
...@@ -265,17 +265,12 @@ static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAva ...@@ -265,17 +265,12 @@ static HRESULT WINAPI PersistMoniker_Load(IPersistMoniker *iface, BOOL fFullyAva
} }
TRACE("got url: %s\n", debugstr_w(url)); TRACE("got url: %s\n", debugstr_w(url));
if(This->hwnd) {
nsres = nsIWebNavigation_LoadURI(This->nscontainer->navigation, url, nsres = nsIWebNavigation_LoadURI(This->nscontainer->navigation, url,
LOAD_FLAGS_NONE, NULL, NULL, NULL); LOAD_FLAGS_NONE, NULL, NULL, NULL);
if(NS_SUCCEEDED(nsres)) if(NS_SUCCEEDED(nsres))
return S_OK; return S_OK;
else else
WARN("LoadURI failed: %08lx\n", nsres); WARN("LoadURI failed: %08lx\n", nsres);
}else {
This->nscontainer->url = url;
return S_OK;
}
} }
/* FIXME: Use grfMode */ /* FIXME: Use grfMode */
......
...@@ -71,35 +71,13 @@ static void paint_disabled(HWND hwnd) { ...@@ -71,35 +71,13 @@ static void paint_disabled(HWND hwnd) {
static void activate_gecko(HTMLDocument *This) static void activate_gecko(HTMLDocument *This)
{ {
RECT rect;
nsresult nsres;
TRACE("(%p) %p\n", This, This->nscontainer->window); TRACE("(%p) %p\n", This, This->nscontainer->window);
GetClientRect(This->hwnd, &rect); SetParent(This->nscontainer->hwnd, This->hwnd);
ShowWindow(This->nscontainer->hwnd, SW_SHOW);
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);
nsIBaseWindow_SetVisibility(This->nscontainer->window, TRUE); nsIBaseWindow_SetVisibility(This->nscontainer->window, TRUE);
nsIBaseWindow_SetEnabled(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;
}
} }
static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
...@@ -127,14 +105,9 @@ static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM ...@@ -127,14 +105,9 @@ static LRESULT WINAPI serverwnd_proc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
break; break;
case WM_SIZE: case WM_SIZE:
TRACE("(%p)->(WM_SIZE)\n", This); TRACE("(%p)->(WM_SIZE)\n", This);
if(This->nscontainer)
if(This->nscontainer) { SetWindowPos(This->nscontainer->hwnd, NULL, 0, 0, LOWORD(lParam), HIWORD(lParam),
nsresult nsres; SWP_NOZORDER | SWP_NOACTIVATE);
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); return DefWindowProcW(hwnd, msg, wParam, lParam);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment