* Slap *some* sense into our header inclusions.
[reactos.git] / reactos / dll / win32 / mshtml / mutation.c
1 /*
2 * Copyright 2008 Jacek Caban for CodeWeavers
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
8 *
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17 */
18
19 #define WIN32_NO_STATUS
20 #define _INC_WINDOWS
21 #define COM_NO_WINDOWS_H
22
23 #include <config.h>
24
25 #include <stdarg.h>
26
27 #define COBJMACROS
28
29 #include <windef.h>
30 #include <winbase.h>
31 //#include "winuser.h"
32 //#include "winreg.h"
33 #include <ole2.h>
34 #include <shlguid.h>
35
36 #include "mshtml_private.h"
37 #include "htmlevent.h"
38
39 #include <wine/debug.h>
40
41 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
42
43 enum {
44 MUTATION_BINDTOTREE,
45 MUTATION_COMMENT,
46 MUTATION_ENDLOAD,
47 MUTATION_SCRIPT
48 };
49
50 #define IE_MAJOR_VERSION 7
51 #define IE_MINOR_VERSION 0
52
53 static BOOL handle_insert_comment(HTMLDocumentNode *doc, const PRUnichar *comment)
54 {
55 DWORD len;
56 int majorv = 0, minorv = 0;
57 const PRUnichar *ptr, *end;
58 nsAString nsstr;
59 PRUnichar *buf;
60 nsresult nsres;
61
62 enum {
63 CMP_EQ,
64 CMP_LT,
65 CMP_LTE,
66 CMP_GT,
67 CMP_GTE
68 } cmpt = CMP_EQ;
69
70 static const PRUnichar endifW[] = {'<','!','[','e','n','d','i','f',']'};
71
72 if(comment[0] != '[' || comment[1] != 'i' || comment[2] != 'f')
73 return FALSE;
74
75 ptr = comment+3;
76 while(isspaceW(*ptr))
77 ptr++;
78
79 if(ptr[0] == 'l' && ptr[1] == 't') {
80 ptr += 2;
81 if(*ptr == 'e') {
82 cmpt = CMP_LTE;
83 ptr++;
84 }else {
85 cmpt = CMP_LT;
86 }
87 }else if(ptr[0] == 'g' && ptr[1] == 't') {
88 ptr += 2;
89 if(*ptr == 'e') {
90 cmpt = CMP_GTE;
91 ptr++;
92 }else {
93 cmpt = CMP_GT;
94 }
95 }
96
97 if(!isspaceW(*ptr++))
98 return FALSE;
99 while(isspaceW(*ptr))
100 ptr++;
101
102 if(ptr[0] != 'I' || ptr[1] != 'E')
103 return FALSE;
104
105 ptr +=2;
106 if(!isspaceW(*ptr++))
107 return FALSE;
108 while(isspaceW(*ptr))
109 ptr++;
110
111 if(!isdigitW(*ptr))
112 return FALSE;
113 while(isdigitW(*ptr))
114 majorv = majorv*10 + (*ptr++ - '0');
115
116 if(*ptr == '.') {
117 ptr++;
118 if(!isdigitW(*ptr))
119 return FALSE;
120 while(isdigitW(*ptr))
121 minorv = minorv*10 + (*ptr++ - '0');
122 }
123
124 while(isspaceW(*ptr))
125 ptr++;
126 if(ptr[0] != ']' || ptr[1] != '>')
127 return FALSE;
128 ptr += 2;
129
130 len = strlenW(ptr);
131 if(len < sizeof(endifW)/sizeof(WCHAR))
132 return FALSE;
133
134 end = ptr + len-sizeof(endifW)/sizeof(WCHAR);
135 if(memcmp(end, endifW, sizeof(endifW)))
136 return FALSE;
137
138 switch(cmpt) {
139 case CMP_EQ:
140 if(majorv == IE_MAJOR_VERSION && minorv == IE_MINOR_VERSION)
141 break;
142 return FALSE;
143 case CMP_LT:
144 if(majorv > IE_MAJOR_VERSION)
145 break;
146 if(majorv == IE_MAJOR_VERSION && minorv > IE_MINOR_VERSION)
147 break;
148 return FALSE;
149 case CMP_LTE:
150 if(majorv > IE_MAJOR_VERSION)
151 break;
152 if(majorv == IE_MAJOR_VERSION && minorv >= IE_MINOR_VERSION)
153 break;
154 return FALSE;
155 case CMP_GT:
156 if(majorv < IE_MAJOR_VERSION)
157 break;
158 if(majorv == IE_MAJOR_VERSION && minorv < IE_MINOR_VERSION)
159 break;
160 return FALSE;
161 case CMP_GTE:
162 if(majorv < IE_MAJOR_VERSION)
163 break;
164 if(majorv == IE_MAJOR_VERSION && minorv <= IE_MINOR_VERSION)
165 break;
166 return FALSE;
167 }
168
169 buf = heap_alloc((end-ptr+1)*sizeof(WCHAR));
170 if(!buf)
171 return FALSE;
172
173 memcpy(buf, ptr, (end-ptr)*sizeof(WCHAR));
174 buf[end-ptr] = 0;
175 nsAString_InitDepend(&nsstr, buf);
176
177 /* FIXME: Find better way to insert HTML to document. */
178 nsres = nsIDOMHTMLDocument_Write(doc->nsdoc, &nsstr);
179 nsAString_Finish(&nsstr);
180 heap_free(buf);
181 if(NS_FAILED(nsres)) {
182 ERR("Write failed: %08x\n", nsres);
183 return FALSE;
184 }
185
186 return TRUE;
187 }
188
189 static void add_script_runner(HTMLDocumentNode *This)
190 {
191 nsIDOMNSDocument *nsdoc;
192 nsresult nsres;
193
194 nsres = nsIDOMHTMLDocument_QueryInterface(This->nsdoc, &IID_nsIDOMNSDocument, (void**)&nsdoc);
195 if(NS_FAILED(nsres)) {
196 ERR("Could not get nsIDOMNSDocument: %08x\n", nsres);
197 return;
198 }
199
200 nsIDOMNSDocument_WineAddScriptRunner(nsdoc, NSRUNNABLE(This));
201 nsIDOMNSDocument_Release(nsdoc);
202 }
203
204 #define NSRUNNABLE_THIS(iface) DEFINE_THIS(HTMLDocumentNode, IRunnable, iface)
205
206 static nsresult NSAPI nsRunnable_QueryInterface(nsIRunnable *iface,
207 nsIIDRef riid, nsQIResult result)
208 {
209 HTMLDocumentNode *This = NSRUNNABLE_THIS(iface);
210
211 if(IsEqualGUID(riid, &IID_nsISupports)) {
212 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
213 *result = NSRUNNABLE(This);
214 }else if(IsEqualGUID(riid, &IID_nsIRunnable)) {
215 TRACE("(%p)->(IID_nsIRunnable %p)\n", This, result);
216 *result = NSRUNNABLE(This);
217 }else {
218 *result = NULL;
219 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
220 return NS_NOINTERFACE;
221 }
222
223 nsISupports_AddRef((nsISupports*)*result);
224 return NS_OK;
225 }
226
227 static nsrefcnt NSAPI nsRunnable_AddRef(nsIRunnable *iface)
228 {
229 HTMLDocumentNode *This = NSRUNNABLE_THIS(iface);
230 return htmldoc_addref(&This->basedoc);
231 }
232
233 static nsrefcnt NSAPI nsRunnable_Release(nsIRunnable *iface)
234 {
235 HTMLDocumentNode *This = NSRUNNABLE_THIS(iface);
236 return htmldoc_release(&This->basedoc);
237 }
238
239 static void push_mutation_queue(HTMLDocumentNode *doc, DWORD type, nsISupports *nsiface)
240 {
241 mutation_queue_t *elem;
242
243 elem = heap_alloc(sizeof(mutation_queue_t));
244 if(!elem)
245 return;
246
247 elem->next = NULL;
248 elem->type = type;
249 elem->nsiface = nsiface;
250 if(nsiface)
251 nsISupports_AddRef(nsiface);
252
253 if(doc->mutation_queue_tail) {
254 doc->mutation_queue_tail = doc->mutation_queue_tail->next = elem;
255 }else {
256 doc->mutation_queue = doc->mutation_queue_tail = elem;
257 add_script_runner(doc);
258 }
259 }
260
261 static void pop_mutation_queue(HTMLDocumentNode *doc)
262 {
263 mutation_queue_t *tmp = doc->mutation_queue;
264
265 if(!tmp)
266 return;
267
268 doc->mutation_queue = tmp->next;
269 if(!tmp->next)
270 doc->mutation_queue_tail = NULL;
271
272 if(tmp->nsiface)
273 nsISupports_Release(tmp->nsiface);
274 heap_free(tmp);
275 }
276
277 static void bind_to_tree(HTMLDocumentNode *doc, nsISupports *nsiface)
278 {
279 nsIDOMNode *nsnode;
280 HTMLDOMNode *node;
281 nsresult nsres;
282
283 nsres = nsISupports_QueryInterface(nsiface, &IID_nsIDOMNode, (void**)&nsnode);
284 if(NS_FAILED(nsres))
285 return;
286
287 node = get_node(doc, nsnode, TRUE);
288 nsIDOMNode_Release(nsnode);
289 if(!node) {
290 ERR("Could not get node\n");
291 return;
292 }
293
294 if(node->vtbl->bind_to_tree)
295 node->vtbl->bind_to_tree(node);
296 }
297
298 /* Calls undocumented 69 cmd of CGID_Explorer */
299 static void call_explorer_69(HTMLDocumentObj *doc)
300 {
301 IOleCommandTarget *olecmd;
302 VARIANT var;
303 HRESULT hres;
304
305 if(!doc->client)
306 return;
307
308 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
309 if(FAILED(hres))
310 return;
311
312 VariantInit(&var);
313 hres = IOleCommandTarget_Exec(olecmd, &CGID_Explorer, 69, 0, NULL, &var);
314 IOleCommandTarget_Release(olecmd);
315 if(SUCCEEDED(hres) && V_VT(&var) != VT_NULL)
316 FIXME("handle result\n");
317 }
318
319 static void parse_complete_proc(task_t *task)
320 {
321 HTMLDocumentObj *doc = ((docobj_task_t*)task)->doc;
322
323 TRACE("(%p)\n", doc);
324
325 if(doc->usermode == EDITMODE)
326 init_editor(&doc->basedoc);
327
328 call_explorer_69(doc);
329 if(doc->view_sink)
330 IAdviseSink_OnViewChange(doc->view_sink, DVASPECT_CONTENT, -1);
331 call_property_onchanged(&doc->basedoc.cp_propnotif, 1005);
332 call_explorer_69(doc);
333
334 /* FIXME: IE7 calls EnableModelless(TRUE), EnableModelless(FALSE) and sets interactive state here */
335
336 set_ready_state(doc->basedoc.window, READYSTATE_INTERACTIVE);
337 }
338
339 static void handle_end_load(HTMLDocumentNode *This)
340 {
341 docobj_task_t *task;
342
343 TRACE("\n");
344
345 if(!This->basedoc.doc_obj)
346 return;
347
348 if(This != This->basedoc.doc_obj->basedoc.doc_node) {
349 set_ready_state(This->basedoc.window, READYSTATE_INTERACTIVE);
350 return;
351 }
352
353 task = heap_alloc(sizeof(docobj_task_t));
354 if(!task)
355 return;
356
357 task->doc = This->basedoc.doc_obj;
358
359 /*
360 * This should be done in the worker thread that parses HTML,
361 * but we don't have such thread (Gecko parses HTML for us).
362 */
363 push_task(&task->header, &parse_complete_proc, This->basedoc.doc_obj->basedoc.task_magic);
364 }
365
366 static nsresult NSAPI nsRunnable_Run(nsIRunnable *iface)
367 {
368 HTMLDocumentNode *This = NSRUNNABLE_THIS(iface);
369 nsresult nsres;
370
371 TRACE("(%p)\n", This);
372
373 while(This->mutation_queue) {
374 switch(This->mutation_queue->type) {
375 case MUTATION_BINDTOTREE:
376 bind_to_tree(This, This->mutation_queue->nsiface);
377 break;
378
379 case MUTATION_COMMENT: {
380 nsIDOMComment *nscomment;
381 nsAString comment_str;
382 BOOL remove_comment = FALSE;
383
384 nsres = nsISupports_QueryInterface(This->mutation_queue->nsiface, &IID_nsIDOMComment, (void**)&nscomment);
385 if(NS_FAILED(nsres)) {
386 ERR("Could not get nsIDOMComment iface:%08x\n", nsres);
387 return NS_OK;
388 }
389
390 nsAString_Init(&comment_str, NULL);
391 nsres = nsIDOMComment_GetData(nscomment, &comment_str);
392 if(NS_SUCCEEDED(nsres)) {
393 const PRUnichar *comment;
394
395 nsAString_GetData(&comment_str, &comment);
396 remove_comment = handle_insert_comment(This, comment);
397 }
398
399 nsAString_Finish(&comment_str);
400
401 if(remove_comment) {
402 nsIDOMNode *nsparent, *tmp;
403 nsAString magic_str;
404
405 static const PRUnichar remove_comment_magicW[] =
406 {'#','!','w','i','n','e', 'r','e','m','o','v','e','!','#',0};
407
408 nsAString_InitDepend(&magic_str, remove_comment_magicW);
409 nsres = nsIDOMComment_SetData(nscomment, &magic_str);
410 nsAString_Finish(&magic_str);
411 if(NS_FAILED(nsres))
412 ERR("SetData failed: %08x\n", nsres);
413
414 nsIDOMComment_GetParentNode(nscomment, &nsparent);
415 if(nsparent) {
416 nsIDOMNode_RemoveChild(nsparent, (nsIDOMNode*)nscomment, &tmp);
417 nsIDOMNode_Release(nsparent);
418 nsIDOMNode_Release(tmp);
419 }
420 }
421
422 nsIDOMComment_Release(nscomment);
423 break;
424 }
425
426 case MUTATION_ENDLOAD:
427 handle_end_load(This);
428 break;
429
430 case MUTATION_SCRIPT: {
431 nsIDOMHTMLScriptElement *nsscript;
432
433 nsres = nsISupports_QueryInterface(This->mutation_queue->nsiface, &IID_nsIDOMHTMLScriptElement,
434 (void**)&nsscript);
435 if(NS_FAILED(nsres)) {
436 ERR("Could not get nsIDOMHTMLScriptElement: %08x\n", nsres);
437 break;
438 }
439
440 doc_insert_script(This->basedoc.window, nsscript);
441 nsIDOMHTMLScriptElement_Release(nsscript);
442 break;
443 }
444
445 default:
446 ERR("invalid type %d\n", This->mutation_queue->type);
447 }
448
449 pop_mutation_queue(This);
450 }
451
452 return S_OK;
453 }
454
455 #undef NSRUNNABLE_THIS
456
457 static const nsIRunnableVtbl nsRunnableVtbl = {
458 nsRunnable_QueryInterface,
459 nsRunnable_AddRef,
460 nsRunnable_Release,
461 nsRunnable_Run
462 };
463
464 #define NSDOCOBS_THIS(iface) DEFINE_THIS(HTMLDocumentNode, IDocumentObserver, iface)
465
466 static nsresult NSAPI nsDocumentObserver_QueryInterface(nsIDocumentObserver *iface,
467 nsIIDRef riid, nsQIResult result)
468 {
469 HTMLDocumentNode *This = NSDOCOBS_THIS(iface);
470
471 if(IsEqualGUID(&IID_nsISupports, riid)) {
472 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
473 *result = NSDOCOBS(This);
474 }else if(IsEqualGUID(&IID_nsIMutationObserver, riid)) {
475 TRACE("(%p)->(IID_nsIMutationObserver %p)\n", This, result);
476 *result = NSDOCOBS(This);
477 }else if(IsEqualGUID(&IID_nsIDocumentObserver, riid)) {
478 TRACE("(%p)->(IID_nsIDocumentObserver %p)\n", This, result);
479 *result = NSDOCOBS(This);
480 }else {
481 *result = NULL;
482 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
483 return NS_NOINTERFACE;
484 }
485
486 htmldoc_addref(&This->basedoc);
487 return NS_OK;
488 }
489
490 static nsrefcnt NSAPI nsDocumentObserver_AddRef(nsIDocumentObserver *iface)
491 {
492 HTMLDocumentNode *This = NSDOCOBS_THIS(iface);
493 return htmldoc_addref(&This->basedoc);
494 }
495
496 static nsrefcnt NSAPI nsDocumentObserver_Release(nsIDocumentObserver *iface)
497 {
498 HTMLDocumentNode *This = NSDOCOBS_THIS(iface);
499 return htmldoc_release(&This->basedoc);
500 }
501
502 static void NSAPI nsDocumentObserver_CharacterDataWillChange(nsIDocumentObserver *iface,
503 nsIDocument *aDocument, nsIContent *aContent, void /*CharacterDataChangeInfo*/ *aInfo)
504 {
505 }
506
507 static void NSAPI nsDocumentObserver_CharacterDataChanged(nsIDocumentObserver *iface,
508 nsIDocument *aDocument, nsIContent *aContent, void /*CharacterDataChangeInfo*/ *aInfo)
509 {
510 }
511
512 static void NSAPI nsDocumentObserver_AttributeWillChange(nsIDocumentObserver *iface, nsIDocument *aDocument,
513 nsIContent *aContent, PRInt32 aNameSpaceID, nsIAtom *aAttribute, PRInt32 aModType)
514 {
515 }
516
517 static void NSAPI nsDocumentObserver_AttributeChanged(nsIDocumentObserver *iface, nsIDocument *aDocument,
518 nsIContent *aContent, PRInt32 aNameSpaceID, nsIAtom *aAttribute, PRInt32 aModType, PRUint32 aStateMask)
519 {
520 }
521
522 static void NSAPI nsDocumentObserver_ContentAppended(nsIDocumentObserver *iface, nsIDocument *aDocument,
523 nsIContent *aContainer, PRInt32 aNewIndexInContainer)
524 {
525 }
526
527 static void NSAPI nsDocumentObserver_ContentInserted(nsIDocumentObserver *iface, nsIDocument *aDocument,
528 nsIContent *aContainer, nsIContent *aChild, PRInt32 aIndexInContainer)
529 {
530 }
531
532 static void NSAPI nsDocumentObserver_ContentRemoved(nsIDocumentObserver *iface, nsIDocument *aDocument,
533 nsIContent *aContainer, nsIContent *aChild, PRInt32 aIndexInContainer)
534 {
535 }
536
537 static void NSAPI nsDocumentObserver_NodeWillBeDestroyed(nsIDocumentObserver *iface, const nsINode *aNode)
538 {
539 }
540
541 static void NSAPI nsDocumentObserver_ParentChainChanged(nsIDocumentObserver *iface, nsIContent *aContent)
542 {
543 }
544
545 static void NSAPI nsDocumentObserver_BeginUpdate(nsIDocumentObserver *iface, nsIDocument *aDocument,
546 nsUpdateType aUpdateType)
547 {
548 }
549
550 static void NSAPI nsDocumentObserver_EndUpdate(nsIDocumentObserver *iface, nsIDocument *aDocument,
551 nsUpdateType aUpdateType)
552 {
553 }
554
555 static void NSAPI nsDocumentObserver_BeginLoad(nsIDocumentObserver *iface, nsIDocument *aDocument)
556 {
557 }
558
559 static void NSAPI nsDocumentObserver_EndLoad(nsIDocumentObserver *iface, nsIDocument *aDocument)
560 {
561 HTMLDocumentNode *This = NSDOCOBS_THIS(iface);
562
563 TRACE("\n");
564
565 This->content_ready = TRUE;
566 push_mutation_queue(This, MUTATION_ENDLOAD, NULL);
567 }
568
569 static void NSAPI nsDocumentObserver_ContentStatesChanged(nsIDocumentObserver *iface, nsIDocument *aDocument,
570 nsIContent *aContent1, nsIContent *aContent2, PRInt32 aStateMask)
571 {
572 }
573
574 static void NSAPI nsDocumentObserver_StyleSheetAdded(nsIDocumentObserver *iface, nsIDocument *aDocument,
575 nsIStyleSheet *aStyleSheet, PRBool aDocumentSheet)
576 {
577 }
578
579 static void NSAPI nsDocumentObserver_StyleSheetRemoved(nsIDocumentObserver *iface, nsIDocument *aDocument,
580 nsIStyleSheet *aStyleSheet, PRBool aDocumentSheet)
581 {
582 }
583
584 static void NSAPI nsDocumentObserver_StyleSheetApplicableStateChanged(nsIDocumentObserver *iface,
585 nsIDocument *aDocument, nsIStyleSheet *aStyleSheet, PRBool aApplicable)
586 {
587 }
588
589 static void NSAPI nsDocumentObserver_StyleRuleChanged(nsIDocumentObserver *iface, nsIDocument *aDocument,
590 nsIStyleSheet *aStyleSheet, nsIStyleRule *aOldStyleRule, nsIStyleSheet *aNewStyleRule)
591 {
592 }
593
594 static void NSAPI nsDocumentObserver_StyleRuleAdded(nsIDocumentObserver *iface, nsIDocument *aDocument,
595 nsIStyleSheet *aStyleSheet, nsIStyleRule *aStyleRule)
596 {
597 }
598
599 static void NSAPI nsDocumentObserver_StyleRuleRemoved(nsIDocumentObserver *iface, nsIDocument *aDocument,
600 nsIStyleSheet *aStyleSheet, nsIStyleRule *aStyleRule)
601 {
602 }
603
604 static void NSAPI nsDocumentObserver_BindToDocument(nsIDocumentObserver *iface, nsIDocument *aDocument,
605 nsIContent *aContent)
606 {
607 HTMLDocumentNode *This = NSDOCOBS_THIS(iface);
608 nsIDOMHTMLIFrameElement *nsiframe;
609 nsIDOMHTMLFrameElement *nsframe;
610 nsIDOMComment *nscomment;
611 nsIDOMElement *nselem;
612 nsresult nsres;
613
614 TRACE("(%p)\n", This);
615
616 nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMElement, (void**)&nselem);
617 if(NS_SUCCEEDED(nsres)) {
618 check_event_attr(This, nselem);
619 nsIDOMElement_Release(nselem);
620 }
621
622 nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMComment, (void**)&nscomment);
623 if(NS_SUCCEEDED(nsres)) {
624 TRACE("comment node\n");
625
626 push_mutation_queue(This, MUTATION_COMMENT, (nsISupports*)nscomment);
627 nsIDOMComment_Release(nscomment);
628 }
629
630 nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMHTMLIFrameElement, (void**)&nsiframe);
631 if(NS_SUCCEEDED(nsres)) {
632 TRACE("iframe node\n");
633
634 push_mutation_queue(This, MUTATION_BINDTOTREE, (nsISupports*)nsiframe);
635 nsIDOMHTMLIFrameElement_Release(nsiframe);
636 }
637
638 nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMHTMLFrameElement, (void**)&nsframe);
639 if(NS_SUCCEEDED(nsres)) {
640 TRACE("frame node\n");
641
642 push_mutation_queue(This, MUTATION_BINDTOTREE, (nsISupports*)nsframe);
643 nsIDOMHTMLFrameElement_Release(nsframe);
644 }
645 }
646
647 static void NSAPI nsDocumentObserver_DoneAddingChildren(nsIDocumentObserver *iface, nsIContent *aContent,
648 PRBool aHaveNotified)
649 {
650 HTMLDocumentNode *This = NSDOCOBS_THIS(iface);
651 nsIDOMHTMLScriptElement *nsscript;
652 nsresult nsres;
653
654 TRACE("(%p)->(%p %x)\n", This, aContent, aHaveNotified);
655
656 nsres = nsISupports_QueryInterface(aContent, &IID_nsIDOMHTMLScriptElement, (void**)&nsscript);
657 if(NS_SUCCEEDED(nsres)) {
658 TRACE("script node\n");
659
660 push_mutation_queue(This, MUTATION_SCRIPT, (nsISupports*)nsscript);
661 nsIDOMHTMLScriptElement_Release(nsscript);
662 }
663 }
664
665 #undef NSMUTATIONOBS_THIS
666
667 static const nsIDocumentObserverVtbl nsDocumentObserverVtbl = {
668 nsDocumentObserver_QueryInterface,
669 nsDocumentObserver_AddRef,
670 nsDocumentObserver_Release,
671 nsDocumentObserver_CharacterDataWillChange,
672 nsDocumentObserver_CharacterDataChanged,
673 nsDocumentObserver_AttributeWillChange,
674 nsDocumentObserver_AttributeChanged,
675 nsDocumentObserver_ContentAppended,
676 nsDocumentObserver_ContentInserted,
677 nsDocumentObserver_ContentRemoved,
678 nsDocumentObserver_NodeWillBeDestroyed,
679 nsDocumentObserver_ParentChainChanged,
680 nsDocumentObserver_BeginUpdate,
681 nsDocumentObserver_EndUpdate,
682 nsDocumentObserver_BeginLoad,
683 nsDocumentObserver_EndLoad,
684 nsDocumentObserver_ContentStatesChanged,
685 nsDocumentObserver_StyleSheetAdded,
686 nsDocumentObserver_StyleSheetRemoved,
687 nsDocumentObserver_StyleSheetApplicableStateChanged,
688 nsDocumentObserver_StyleRuleChanged,
689 nsDocumentObserver_StyleRuleAdded,
690 nsDocumentObserver_StyleRuleRemoved,
691 nsDocumentObserver_BindToDocument,
692 nsDocumentObserver_DoneAddingChildren
693 };
694
695 void init_mutation(HTMLDocumentNode *doc)
696 {
697 nsIDOMNSDocument *nsdoc;
698 nsresult nsres;
699
700 doc->lpIDocumentObserverVtbl = &nsDocumentObserverVtbl;
701 doc->lpIRunnableVtbl = &nsRunnableVtbl;
702
703 nsres = nsIDOMHTMLDocument_QueryInterface(doc->nsdoc, &IID_nsIDOMNSDocument, (void**)&nsdoc);
704 if(NS_FAILED(nsres)) {
705 ERR("Could not get nsIDOMNSDocument: %08x\n", nsres);
706 return;
707 }
708
709 nsIDOMNSDocument_WineAddObserver(nsdoc, NSDOCOBS(doc));
710 nsIDOMNSDocument_Release(nsdoc);
711 }
712
713 void release_mutation(HTMLDocumentNode *doc)
714 {
715 nsIDOMNSDocument *nsdoc;
716 nsresult nsres;
717
718 nsres = nsIDOMHTMLDocument_QueryInterface(doc->nsdoc, &IID_nsIDOMNSDocument, (void**)&nsdoc);
719 if(NS_FAILED(nsres)) {
720 ERR("Could not get nsIDOMNSDocument: %08x\n", nsres);
721 return;
722 }
723
724 nsIDOMNSDocument_WineRemoveObserver(nsdoc, NSDOCOBS(doc));
725 nsIDOMNSDocument_Release(nsdoc);
726 }