diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h
index 644f6b0ab77..f20f673d682 100644
--- a/dlls/mshtml/mshtml_private.h
+++ b/dlls/mshtml/mshtml_private.h
@@ -143,6 +143,7 @@ struct NSContainer {
const nsIDOMEventListenerVtbl *lpDOMEventListenerVtbl;
nsEventListener keypress_listener;
+ nsEventListener load_listener;
nsIWebBrowser *webbrowser;
nsIWebNavigation *navigation;
@@ -357,6 +358,7 @@ void nsAString_Finish(nsAString*);
nsIInputStream *create_nsstream(const char*,PRInt32);
nsICommandParams *create_nscommand_params(void);
void nsnode_to_nsstring(nsIDOMNode*,nsAString*);
+nsIController *get_editor_controller(NSContainer*);
void init_nsevents(NSContainer*);
BSCallback *create_bscallback(IMoniker*);
diff --git a/dlls/mshtml/nsembed.c b/dlls/mshtml/nsembed.c
index 862e0841799..ebb4d07e556 100644
--- a/dlls/mshtml/nsembed.c
+++ b/dlls/mshtml/nsembed.c
@@ -589,7 +589,7 @@ void nsnode_to_nsstring(nsIDOMNode *nsdoc, nsAString *str)
nsIContentSerializer_Release(serializer);
}
-static nsIController *get_editor_controller(NSContainer *This)
+nsIController *get_editor_controller(NSContainer *This)
{
nsIController *ret = NULL;
nsIEditingSession *editing_session = NULL;
@@ -1532,7 +1532,6 @@ static const nsISupportsWeakReferenceVtbl nsSupportsWeakReferenceVtbl = {
NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent)
{
- nsIDOMWindow *dom_window;
nsIWebBrowserSetup *wbsetup;
nsIScrollable *scrollable;
NSContainer *ret;
@@ -1621,29 +1620,6 @@ NSContainer *NSContainer_Create(HTMLDocument *doc, NSContainer *parent)
if(NS_FAILED(nsres))
ERR("SetParentURIContentListener failed: %08x\n", nsres);
- nsres = nsIWebBrowser_GetContentDOMWindow(ret->webbrowser, &dom_window);
- if(NS_SUCCEEDED(nsres)) {
- nsIDOMEventTarget *target;
- nsres = nsIDOMWindow_QueryInterface(dom_window, &IID_nsIDOMEventTarget, (void**)&target);
- nsIDOMWindow_Release(dom_window);
- if(NS_SUCCEEDED(nsres)) {
- nsAString load_str;
- static const PRUnichar wsz_load[] = {'l','o','a','d',0};
-
- nsAString_Init(&load_str, wsz_load);
- nsres = nsIDOMEventTarget_AddEventListener(target, &load_str, NSEVENTLIST(ret), TRUE);
- nsAString_Finish(&load_str);
- if(NS_FAILED(nsres))
- ERR("AddEventTarget failed: %08x\n", nsres);
-
- nsIDOMEventTarget_Release(target);
- }else {
- ERR("Could not get nsIDOMEventTarget interface: %08x\n", nsres);
- }
- }else {
- ERR("GetContentDOMWindow failed: %08x\n", nsres);
- }
-
init_nsevents(ret);
nsres = nsIWebBrowser_QueryInterface(ret->webbrowser, &IID_nsIScrollable, (void**)&scrollable);
diff --git a/dlls/mshtml/nsevents.c b/dlls/mshtml/nsevents.c
index 887a169e328..2a04111dc77 100644
--- a/dlls/mshtml/nsevents.c
+++ b/dlls/mshtml/nsevents.c
@@ -86,6 +86,39 @@ static nsresult NSAPI handle_keypress(nsIDOMEventListener *iface,
return NS_OK;
}
+static nsresult NSAPI handle_load(nsIDOMEventListener *iface, nsIDOMEvent *event)
+{
+ NSContainer *This = NSEVENTLIST_THIS(iface)->This;
+ task_t *task;
+
+ TRACE("(%p)\n", This);
+
+ if(!This->doc)
+ return NS_OK;
+
+ if(This->editor_controller) {
+ nsIController_Release(This->editor_controller);
+ This->editor_controller = NULL;
+ }
+
+ if(This->doc->usermode == EDITMODE)
+ This->editor_controller = get_editor_controller(This);
+
+ task = mshtml_alloc(sizeof(task_t));
+
+ task->doc = This->doc;
+ task->task_id = TASK_PARSECOMPLETE;
+ task->next = NULL;
+
+ /*
+ * This should be done in the worker thread that parses HTML,
+ * but we don't have such thread (Gecko parses HTML for us).
+ */
+ push_task(task);
+
+ return NS_OK;
+}
+
#undef NSEVENTLIST_THIS
#define EVENTLISTENER_VTBL(handler) \
@@ -97,6 +130,7 @@ static nsresult NSAPI handle_keypress(nsIDOMEventListener *iface,
};
static const nsIDOMEventListenerVtbl keypress_vtbl = EVENTLISTENER_VTBL(handle_keypress);
+static const nsIDOMEventListenerVtbl load_vtbl = EVENTLISTENER_VTBL(handle_load);
static void init_event(nsIDOMEventTarget *target, const PRUnichar *type,
nsIDOMEventListener *listener, BOOL capture)
@@ -126,8 +160,10 @@ void init_nsevents(NSContainer *This)
nsresult nsres;
static const PRUnichar wsz_keypress[] = {'k','e','y','p','r','e','s','s',0};
+ static const PRUnichar wsz_load[] = {'l','o','a','d',0};
init_listener(&This->keypress_listener, This, &keypress_vtbl);
+ init_listener(&This->load_listener, This, &load_vtbl);
nsres = nsIWebBrowser_GetContentDOMWindow(This->webbrowser, &dom_window);
if(NS_FAILED(nsres)) {
@@ -143,6 +179,7 @@ void init_nsevents(NSContainer *This)
}
init_event(target, wsz_keypress, NSEVENTLIST(&This->keypress_listener), FALSE);
+ init_event(target, wsz_load, NSEVENTLIST(&This->load_listener), TRUE);
nsIDOMEventTarget_Release(target);
}