gdi32: Clip solid pen regions to the DIB rectangle to avoid overflows.
[wine.git] / dlls / mshtml / mutation.c
blob12c5c987530faa1541640dbc48a3971cd87a54aa
1 /*
2 * Copyright 2008 Jacek Caban for CodeWeavers
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.
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.
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
19 #include "config.h"
21 #include <stdarg.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "winreg.h"
29 #include "ole2.h"
30 #include "shlguid.h"
32 #include "mshtml_private.h"
33 #include "htmlevent.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 #define IE_MAJOR_VERSION 7
40 #define IE_MINOR_VERSION 0
42 static const IID NS_ICONTENTUTILS_CID =
43 {0x762C4AE7,0xB923,0x422F,{0xB9,0x7E,0xB9,0xBF,0xC1,0xEF,0x7B,0xF0}};
45 static nsIContentUtils *content_utils;
47 static PRUnichar *handle_insert_comment(HTMLDocumentNode *doc, const PRUnichar *comment)
49 int majorv = 0, minorv = 0;
50 const PRUnichar *ptr, *end;
51 PRUnichar *buf;
52 DWORD len;
54 enum {
55 CMP_EQ,
56 CMP_LT,
57 CMP_LTE,
58 CMP_GT,
59 CMP_GTE
60 } cmpt = CMP_EQ;
62 static const PRUnichar endifW[] = {'<','!','[','e','n','d','i','f',']'};
64 if(comment[0] != '[' || comment[1] != 'i' || comment[2] != 'f')
65 return NULL;
67 ptr = comment+3;
68 while(isspaceW(*ptr))
69 ptr++;
71 if(ptr[0] == 'l' && ptr[1] == 't') {
72 ptr += 2;
73 if(*ptr == 'e') {
74 cmpt = CMP_LTE;
75 ptr++;
76 }else {
77 cmpt = CMP_LT;
79 }else if(ptr[0] == 'g' && ptr[1] == 't') {
80 ptr += 2;
81 if(*ptr == 'e') {
82 cmpt = CMP_GTE;
83 ptr++;
84 }else {
85 cmpt = CMP_GT;
89 if(!isspaceW(*ptr++))
90 return NULL;
91 while(isspaceW(*ptr))
92 ptr++;
94 if(ptr[0] != 'I' || ptr[1] != 'E')
95 return NULL;
97 ptr +=2;
98 if(!isspaceW(*ptr++))
99 return NULL;
100 while(isspaceW(*ptr))
101 ptr++;
103 if(!isdigitW(*ptr))
104 return NULL;
105 while(isdigitW(*ptr))
106 majorv = majorv*10 + (*ptr++ - '0');
108 if(*ptr == '.') {
109 ptr++;
110 if(!isdigitW(*ptr))
111 return NULL;
112 while(isdigitW(*ptr))
113 minorv = minorv*10 + (*ptr++ - '0');
116 while(isspaceW(*ptr))
117 ptr++;
118 if(ptr[0] != ']' || ptr[1] != '>')
119 return NULL;
120 ptr += 2;
122 len = strlenW(ptr);
123 if(len < sizeof(endifW)/sizeof(WCHAR))
124 return NULL;
126 end = ptr + len-sizeof(endifW)/sizeof(WCHAR);
127 if(memcmp(end, endifW, sizeof(endifW)))
128 return NULL;
130 switch(cmpt) {
131 case CMP_EQ:
132 if(majorv == IE_MAJOR_VERSION && minorv == IE_MINOR_VERSION)
133 break;
134 return NULL;
135 case CMP_LT:
136 if(majorv > IE_MAJOR_VERSION)
137 break;
138 if(majorv == IE_MAJOR_VERSION && minorv > IE_MINOR_VERSION)
139 break;
140 return NULL;
141 case CMP_LTE:
142 if(majorv > IE_MAJOR_VERSION)
143 break;
144 if(majorv == IE_MAJOR_VERSION && minorv >= IE_MINOR_VERSION)
145 break;
146 return NULL;
147 case CMP_GT:
148 if(majorv < IE_MAJOR_VERSION)
149 break;
150 if(majorv == IE_MAJOR_VERSION && minorv < IE_MINOR_VERSION)
151 break;
152 return NULL;
153 case CMP_GTE:
154 if(majorv < IE_MAJOR_VERSION)
155 break;
156 if(majorv == IE_MAJOR_VERSION && minorv <= IE_MINOR_VERSION)
157 break;
158 return NULL;
161 buf = heap_alloc((end-ptr+1)*sizeof(WCHAR));
162 if(!buf)
163 return NULL;
165 memcpy(buf, ptr, (end-ptr)*sizeof(WCHAR));
166 buf[end-ptr] = 0;
168 return buf;
171 static nsresult run_insert_comment(HTMLDocumentNode *doc, nsISupports *comment_iface, nsISupports *arg2)
173 const PRUnichar *comment;
174 nsIDOMComment *nscomment;
175 PRUnichar *replace_html;
176 nsAString comment_str;
177 nsresult nsres;
179 nsres = nsISupports_QueryInterface(comment_iface, &IID_nsIDOMComment, (void**)&nscomment);
180 if(NS_FAILED(nsres)) {
181 ERR("Could not get nsIDOMComment iface:%08x\n", nsres);
182 return nsres;
185 nsAString_Init(&comment_str, NULL);
186 nsres = nsIDOMComment_GetData(nscomment, &comment_str);
187 if(NS_FAILED(nsres))
188 return nsres;
190 nsAString_GetData(&comment_str, &comment);
191 replace_html = handle_insert_comment(doc, comment);
192 nsAString_Finish(&comment_str);
194 if(replace_html) {
195 HRESULT hres;
197 hres = replace_node_by_html(doc->nsdoc, (nsIDOMNode*)nscomment, replace_html);
198 heap_free(replace_html);
199 if(FAILED(hres))
200 nsres = NS_ERROR_FAILURE;
204 nsIDOMComment_Release(nscomment);
205 return nsres;
208 static nsresult run_bind_to_tree(HTMLDocumentNode *doc, nsISupports *nsiface, nsISupports *arg2)
210 nsIDOMNode *nsnode;
211 HTMLDOMNode *node;
212 nsresult nsres;
213 HRESULT hres;
215 TRACE("(%p)->(%p)\n", doc, nsiface);
217 nsres = nsISupports_QueryInterface(nsiface, &IID_nsIDOMNode, (void**)&nsnode);
218 if(NS_FAILED(nsres))
219 return nsres;
221 hres = get_node(doc, nsnode, TRUE, &node);
222 nsIDOMNode_Release(nsnode);
223 if(FAILED(hres)) {
224 ERR("Could not get node\n");
225 return nsres;
228 if(node->vtbl->bind_to_tree)
229 node->vtbl->bind_to_tree(node);
231 node_release(node);
232 return nsres;
235 /* Calls undocumented 69 cmd of CGID_Explorer */
236 static void call_explorer_69(HTMLDocumentObj *doc)
238 IOleCommandTarget *olecmd;
239 VARIANT var;
240 HRESULT hres;
242 if(!doc->client)
243 return;
245 hres = IOleClientSite_QueryInterface(doc->client, &IID_IOleCommandTarget, (void**)&olecmd);
246 if(FAILED(hres))
247 return;
249 VariantInit(&var);
250 hres = IOleCommandTarget_Exec(olecmd, &CGID_Explorer, 69, 0, NULL, &var);
251 IOleCommandTarget_Release(olecmd);
252 if(SUCCEEDED(hres) && V_VT(&var) != VT_NULL)
253 FIXME("handle result\n");
256 static void parse_complete(HTMLDocumentObj *doc)
258 TRACE("(%p)\n", doc);
260 if(doc->usermode == EDITMODE)
261 init_editor(&doc->basedoc);
263 call_explorer_69(doc);
264 if(doc->view_sink)
265 IAdviseSink_OnViewChange(doc->view_sink, DVASPECT_CONTENT, -1);
266 call_property_onchanged(&doc->basedoc.cp_propnotif, 1005);
267 call_explorer_69(doc);
269 if(doc->is_webbrowser && doc->usermode != EDITMODE)
270 IDocObjectService_FireNavigateComplete2(doc->doc_object_service, &doc->basedoc.window->base.IHTMLWindow2_iface, 0);
272 /* FIXME: IE7 calls EnableModelless(TRUE), EnableModelless(FALSE) and sets interactive state here */
275 static nsresult run_end_load(HTMLDocumentNode *This, nsISupports *arg1, nsISupports *arg2)
277 TRACE("(%p)\n", This);
279 if(!This->basedoc.doc_obj)
280 return NS_OK;
282 if(This == This->basedoc.doc_obj->basedoc.doc_node) {
284 * This should be done in the worker thread that parses HTML,
285 * but we don't have such thread (Gecko parses HTML for us).
287 parse_complete(This->basedoc.doc_obj);
290 set_ready_state(This->basedoc.window, READYSTATE_INTERACTIVE);
291 return NS_OK;
294 static nsresult run_insert_script(HTMLDocumentNode *doc, nsISupports *script_iface, nsISupports *parser_iface)
296 nsIDOMHTMLScriptElement *nsscript;
297 nsIParser *nsparser = NULL;
298 nsresult nsres;
300 TRACE("(%p)->(%p)\n", doc, script_iface);
302 nsres = nsISupports_QueryInterface(script_iface, &IID_nsIDOMHTMLScriptElement, (void**)&nsscript);
303 if(NS_FAILED(nsres)) {
304 ERR("Could not get nsIDOMHTMLScriptElement: %08x\n", nsres);
305 return nsres;
308 if(parser_iface) {
309 nsres = nsISupports_QueryInterface(parser_iface, &IID_nsIParser, (void**)&nsparser);
310 if(NS_FAILED(nsres)) {
311 ERR("Could not get nsIParser iface: %08x\n", nsres);
312 nsparser = NULL;
316 if(nsparser)
317 nsIParser_BeginEvaluatingParserInsertedScript(nsparser);
319 doc_insert_script(doc->basedoc.window->base.inner_window, nsscript);
321 if(nsparser) {
322 nsIParser_EndEvaluatingParserInsertedScript(nsparser);
323 nsIParser_Release(nsparser);
326 nsIDOMHTMLScriptElement_Release(nsscript);
327 return NS_OK;
330 typedef struct nsRunnable nsRunnable;
332 typedef nsresult (*runnable_proc_t)(HTMLDocumentNode*,nsISupports*,nsISupports*);
334 struct nsRunnable {
335 nsIRunnable nsIRunnable_iface;
337 LONG ref;
339 runnable_proc_t proc;
341 HTMLDocumentNode *doc;
342 nsISupports *arg1;
343 nsISupports *arg2;
346 static inline nsRunnable *impl_from_nsIRunnable(nsIRunnable *iface)
348 return CONTAINING_RECORD(iface, nsRunnable, nsIRunnable_iface);
351 static nsresult NSAPI nsRunnable_QueryInterface(nsIRunnable *iface,
352 nsIIDRef riid, void **result)
354 nsRunnable *This = impl_from_nsIRunnable(iface);
356 if(IsEqualGUID(riid, &IID_nsISupports)) {
357 TRACE("(%p)->(IID_nsISupports %p)\n", This, result);
358 *result = &This->nsIRunnable_iface;
359 }else if(IsEqualGUID(riid, &IID_nsIRunnable)) {
360 TRACE("(%p)->(IID_nsIRunnable %p)\n", This, result);
361 *result = &This->nsIRunnable_iface;
362 }else {
363 *result = NULL;
364 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
365 return NS_NOINTERFACE;
368 nsISupports_AddRef((nsISupports*)*result);
369 return NS_OK;
372 static nsrefcnt NSAPI nsRunnable_AddRef(nsIRunnable *iface)
374 nsRunnable *This = impl_from_nsIRunnable(iface);
375 LONG ref = InterlockedIncrement(&This->ref);
377 TRACE("(%p) ref=%d\n", This, ref);
379 return ref;
382 static nsrefcnt NSAPI nsRunnable_Release(nsIRunnable *iface)
384 nsRunnable *This = impl_from_nsIRunnable(iface);
385 LONG ref = InterlockedDecrement(&This->ref);
387 TRACE("(%p) ref=%d\n", This, ref);
389 if(!ref) {
390 htmldoc_release(&This->doc->basedoc);
391 if(This->arg1)
392 nsISupports_Release(This->arg1);
393 if(This->arg2)
394 nsISupports_Release(This->arg2);
395 heap_free(This);
398 return ref;
401 static nsresult NSAPI nsRunnable_Run(nsIRunnable *iface)
403 nsRunnable *This = impl_from_nsIRunnable(iface);
405 return This->proc(This->doc, This->arg1, This->arg2);
408 static const nsIRunnableVtbl nsRunnableVtbl = {
409 nsRunnable_QueryInterface,
410 nsRunnable_AddRef,
411 nsRunnable_Release,
412 nsRunnable_Run
415 static void add_script_runner(HTMLDocumentNode *This, runnable_proc_t proc, nsISupports *arg1, nsISupports *arg2)
417 nsRunnable *runnable;
419 runnable = heap_alloc_zero(sizeof(*runnable));
420 if(!runnable)
421 return;
423 runnable->nsIRunnable_iface.lpVtbl = &nsRunnableVtbl;
424 runnable->ref = 1;
426 htmldoc_addref(&This->basedoc);
427 runnable->doc = This;
428 runnable->proc = proc;
430 if(arg1)
431 nsISupports_AddRef(arg1);
432 runnable->arg1 = arg1;
434 if(arg2)
435 nsISupports_AddRef(arg2);
436 runnable->arg2 = arg2;
438 nsIContentUtils_AddScriptRunner(content_utils, &runnable->nsIRunnable_iface);
440 nsIRunnable_Release(&runnable->nsIRunnable_iface);
443 static inline HTMLDocumentNode *impl_from_nsIDocumentObserver(nsIDocumentObserver *iface)
445 return CONTAINING_RECORD(iface, HTMLDocumentNode, nsIDocumentObserver_iface);
448 static nsresult NSAPI nsDocumentObserver_QueryInterface(nsIDocumentObserver *iface,
449 nsIIDRef riid, void **result)
451 HTMLDocumentNode *This = impl_from_nsIDocumentObserver(iface);
453 if(IsEqualGUID(&IID_nsISupports, riid)) {
454 TRACE("(%p)->(IID_nsISupports, %p)\n", This, result);
455 *result = &This->nsIDocumentObserver_iface;
456 }else if(IsEqualGUID(&IID_nsIMutationObserver, riid)) {
457 TRACE("(%p)->(IID_nsIMutationObserver %p)\n", This, result);
458 *result = &This->nsIDocumentObserver_iface;
459 }else if(IsEqualGUID(&IID_nsIDocumentObserver, riid)) {
460 TRACE("(%p)->(IID_nsIDocumentObserver %p)\n", This, result);
461 *result = &This->nsIDocumentObserver_iface;
462 }else {
463 *result = NULL;
464 TRACE("(%p)->(%s %p)\n", This, debugstr_guid(riid), result);
465 return NS_NOINTERFACE;
468 htmldoc_addref(&This->basedoc);
469 return NS_OK;
472 static nsrefcnt NSAPI nsDocumentObserver_AddRef(nsIDocumentObserver *iface)
474 HTMLDocumentNode *This = impl_from_nsIDocumentObserver(iface);
475 return htmldoc_addref(&This->basedoc);
478 static nsrefcnt NSAPI nsDocumentObserver_Release(nsIDocumentObserver *iface)
480 HTMLDocumentNode *This = impl_from_nsIDocumentObserver(iface);
481 return htmldoc_release(&This->basedoc);
484 static void NSAPI nsDocumentObserver_CharacterDataWillChange(nsIDocumentObserver *iface,
485 nsIDocument *aDocument, nsIContent *aContent, void /*CharacterDataChangeInfo*/ *aInfo)
489 static void NSAPI nsDocumentObserver_CharacterDataChanged(nsIDocumentObserver *iface,
490 nsIDocument *aDocument, nsIContent *aContent, void /*CharacterDataChangeInfo*/ *aInfo)
494 static void NSAPI nsDocumentObserver_AttributeWillChange(nsIDocumentObserver *iface, nsIDocument *aDocument,
495 nsIContent *aContent, PRInt32 aNameSpaceID, nsIAtom *aAttribute, PRInt32 aModType)
499 static void NSAPI nsDocumentObserver_AttributeChanged(nsIDocumentObserver *iface, nsIDocument *aDocument,
500 nsIContent *aContent, PRInt32 aNameSpaceID, nsIAtom *aAttribute, PRInt32 aModType)
504 static void NSAPI nsDocumentObserver_ContentAppended(nsIDocumentObserver *iface, nsIDocument *aDocument,
505 nsIContent *aContainer, nsIContent *aFirstNewContent, PRInt32 aNewIndexInContainer)
509 static void NSAPI nsDocumentObserver_ContentInserted(nsIDocumentObserver *iface, nsIDocument *aDocument,
510 nsIContent *aContainer, nsIContent *aChild, PRInt32 aIndexInContainer)
514 static void NSAPI nsDocumentObserver_ContentRemoved(nsIDocumentObserver *iface, nsIDocument *aDocument,
515 nsIContent *aContainer, nsIContent *aChild, PRInt32 aIndexInContainer,
516 nsIContent *aProviousSibling)
520 static void NSAPI nsDocumentObserver_NodeWillBeDestroyed(nsIDocumentObserver *iface, const nsINode *aNode)
524 static void NSAPI nsDocumentObserver_ParentChainChanged(nsIDocumentObserver *iface, nsIContent *aContent)
528 static void NSAPI nsDocumentObserver_BeginUpdate(nsIDocumentObserver *iface, nsIDocument *aDocument,
529 nsUpdateType aUpdateType)
533 static void NSAPI nsDocumentObserver_EndUpdate(nsIDocumentObserver *iface, nsIDocument *aDocument,
534 nsUpdateType aUpdateType)
538 static void NSAPI nsDocumentObserver_BeginLoad(nsIDocumentObserver *iface, nsIDocument *aDocument)
542 static void NSAPI nsDocumentObserver_EndLoad(nsIDocumentObserver *iface, nsIDocument *aDocument)
544 HTMLDocumentNode *This = impl_from_nsIDocumentObserver(iface);
546 TRACE("(%p)\n", This);
548 if(This->skip_mutation_notif)
549 return;
551 This->content_ready = TRUE;
552 add_script_runner(This, run_end_load, NULL, NULL);
555 static void NSAPI nsDocumentObserver_ContentStatesChanged(nsIDocumentObserver *iface, nsIDocument *aDocument,
556 nsIContent *aContent, nsEventStates *aStateMask)
560 static void NSAPI nsDocumentObserver_DocumentStatesChanged(nsIDocumentObserver *iface, nsIDocument *aDocument,
561 nsEventStates *aStateMask)
565 static void NSAPI nsDocumentObserver_StyleSheetAdded(nsIDocumentObserver *iface, nsIDocument *aDocument,
566 nsIStyleSheet *aStyleSheet, cpp_bool aDocumentSheet)
570 static void NSAPI nsDocumentObserver_StyleSheetRemoved(nsIDocumentObserver *iface, nsIDocument *aDocument,
571 nsIStyleSheet *aStyleSheet, cpp_bool aDocumentSheet)
575 static void NSAPI nsDocumentObserver_StyleSheetApplicableStateChanged(nsIDocumentObserver *iface,
576 nsIDocument *aDocument, nsIStyleSheet *aStyleSheet, cpp_bool aApplicable)
580 static void NSAPI nsDocumentObserver_StyleRuleChanged(nsIDocumentObserver *iface, nsIDocument *aDocument,
581 nsIStyleSheet *aStyleSheet, nsIStyleRule *aOldStyleRule, nsIStyleSheet *aNewStyleRule)
585 static void NSAPI nsDocumentObserver_StyleRuleAdded(nsIDocumentObserver *iface, nsIDocument *aDocument,
586 nsIStyleSheet *aStyleSheet, nsIStyleRule *aStyleRule)
590 static void NSAPI nsDocumentObserver_StyleRuleRemoved(nsIDocumentObserver *iface, nsIDocument *aDocument,
591 nsIStyleSheet *aStyleSheet, nsIStyleRule *aStyleRule)
595 static void NSAPI nsDocumentObserver_BindToDocument(nsIDocumentObserver *iface, nsIDocument *aDocument,
596 nsIContent *aContent)
598 HTMLDocumentNode *This = impl_from_nsIDocumentObserver(iface);
599 nsIDOMHTMLIFrameElement *nsiframe;
600 nsIDOMHTMLFrameElement *nsframe;
601 nsIDOMComment *nscomment;
602 nsIDOMElement *nselem;
603 nsresult nsres;
605 TRACE("(%p)\n", This);
607 nsres = nsIContent_QueryInterface(aContent, &IID_nsIDOMElement, (void**)&nselem);
608 if(NS_SUCCEEDED(nsres)) {
609 check_event_attr(This, nselem);
610 nsIDOMElement_Release(nselem);
613 nsres = nsIContent_QueryInterface(aContent, &IID_nsIDOMComment, (void**)&nscomment);
614 if(NS_SUCCEEDED(nsres)) {
615 TRACE("comment node\n");
617 add_script_runner(This, run_insert_comment, (nsISupports*)nscomment, NULL);
618 nsIDOMComment_Release(nscomment);
621 nsres = nsIContent_QueryInterface(aContent, &IID_nsIDOMHTMLIFrameElement, (void**)&nsiframe);
622 if(NS_SUCCEEDED(nsres)) {
623 TRACE("iframe node\n");
625 add_script_runner(This, run_bind_to_tree, (nsISupports*)nsiframe, NULL);
626 nsIDOMHTMLIFrameElement_Release(nsiframe);
629 nsres = nsIContent_QueryInterface(aContent, &IID_nsIDOMHTMLFrameElement, (void**)&nsframe);
630 if(NS_SUCCEEDED(nsres)) {
631 TRACE("frame node\n");
633 add_script_runner(This, run_bind_to_tree, (nsISupports*)nsframe, NULL);
634 nsIDOMHTMLFrameElement_Release(nsframe);
638 static void NSAPI nsDocumentObserver_AttemptToExecuteScript(nsIDocumentObserver *iface, nsIContent *aContent,
639 nsIParser *aParser, cpp_bool *aBlock)
641 HTMLDocumentNode *This = impl_from_nsIDocumentObserver(iface);
642 nsIDOMHTMLScriptElement *nsscript;
643 nsresult nsres;
645 TRACE("(%p)->(%p %p %p)\n", This, aContent, aParser, aBlock);
647 nsres = nsIContent_QueryInterface(aContent, &IID_nsIDOMHTMLScriptElement, (void**)&nsscript);
648 if(NS_SUCCEEDED(nsres)) {
649 TRACE("script node\n");
651 add_script_runner(This, run_insert_script, (nsISupports*)nsscript, (nsISupports*)aParser);
652 nsIDOMHTMLScriptElement_Release(nsscript);
656 static const nsIDocumentObserverVtbl nsDocumentObserverVtbl = {
657 nsDocumentObserver_QueryInterface,
658 nsDocumentObserver_AddRef,
659 nsDocumentObserver_Release,
660 nsDocumentObserver_CharacterDataWillChange,
661 nsDocumentObserver_CharacterDataChanged,
662 nsDocumentObserver_AttributeWillChange,
663 nsDocumentObserver_AttributeChanged,
664 nsDocumentObserver_ContentAppended,
665 nsDocumentObserver_ContentInserted,
666 nsDocumentObserver_ContentRemoved,
667 nsDocumentObserver_NodeWillBeDestroyed,
668 nsDocumentObserver_ParentChainChanged,
669 nsDocumentObserver_BeginUpdate,
670 nsDocumentObserver_EndUpdate,
671 nsDocumentObserver_BeginLoad,
672 nsDocumentObserver_EndLoad,
673 nsDocumentObserver_ContentStatesChanged,
674 nsDocumentObserver_DocumentStatesChanged,
675 nsDocumentObserver_StyleSheetAdded,
676 nsDocumentObserver_StyleSheetRemoved,
677 nsDocumentObserver_StyleSheetApplicableStateChanged,
678 nsDocumentObserver_StyleRuleChanged,
679 nsDocumentObserver_StyleRuleAdded,
680 nsDocumentObserver_StyleRuleRemoved,
681 nsDocumentObserver_BindToDocument,
682 nsDocumentObserver_AttemptToExecuteScript
685 void init_document_mutation(HTMLDocumentNode *doc)
687 nsIDocument *nsdoc;
688 nsresult nsres;
690 doc->nsIDocumentObserver_iface.lpVtbl = &nsDocumentObserverVtbl;
692 nsres = nsIDOMHTMLDocument_QueryInterface(doc->nsdoc, &IID_nsIDocument, (void**)&nsdoc);
693 if(NS_FAILED(nsres)) {
694 ERR("Could not get nsIDocument: %08x\n", nsres);
695 return;
698 nsIContentUtils_AddDocumentObserver(content_utils, nsdoc, &doc->nsIDocumentObserver_iface);
699 nsIDocument_Release(nsdoc);
702 void release_document_mutation(HTMLDocumentNode *doc)
704 nsIDocument *nsdoc;
705 nsresult nsres;
707 nsres = nsIDOMHTMLDocument_QueryInterface(doc->nsdoc, &IID_nsIDocument, (void**)&nsdoc);
708 if(NS_FAILED(nsres)) {
709 ERR("Could not get nsIDocument: %08x\n", nsres);
710 return;
713 nsIContentUtils_RemoveDocumentObserver(content_utils, nsdoc, &doc->nsIDocumentObserver_iface);
714 nsIDocument_Release(nsdoc);
717 void init_mutation(nsIComponentManager *component_manager)
719 nsIFactory *factory;
720 nsresult nsres;
722 if(!component_manager) {
723 if(content_utils) {
724 nsIContentUtils_Release(content_utils);
725 content_utils = NULL;
727 return;
730 nsres = nsIComponentManager_GetClassObject(component_manager, &NS_ICONTENTUTILS_CID,
731 &IID_nsIFactory, (void**)&factory);
732 if(NS_FAILED(nsres)) {
733 ERR("Could not create nsIContentUtils service: %08x\n", nsres);
734 return;
737 nsres = nsIFactory_CreateInstance(factory, NULL, &IID_nsIContentUtils, (void**)&content_utils);
738 nsIFactory_Release(factory);
739 if(NS_FAILED(nsres))
740 ERR("Could not create nsIContentUtils instance: %08x\n", nsres);