[MSHTML]
[reactos.git] / reactos / dll / win32 / mshtml / htmlelem.c
1 /*
2 * Copyright 2006 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 #include "mshtml_private.h"
20
21 static const WCHAR aW[] = {'A',0};
22 static const WCHAR bodyW[] = {'B','O','D','Y',0};
23 static const WCHAR buttonW[] = {'B','U','T','T','O','N',0};
24 static const WCHAR embedW[] = {'E','M','B','E','D',0};
25 static const WCHAR formW[] = {'F','O','R','M',0};
26 static const WCHAR frameW[] = {'F','R','A','M','E',0};
27 static const WCHAR headW[] = {'H','E','A','D',0};
28 static const WCHAR iframeW[] = {'I','F','R','A','M','E',0};
29 static const WCHAR imgW[] = {'I','M','G',0};
30 static const WCHAR inputW[] = {'I','N','P','U','T',0};
31 static const WCHAR labelW[] = {'L','A','B','E','L',0};
32 static const WCHAR linkW[] = {'L','I','N','K',0};
33 static const WCHAR metaW[] = {'M','E','T','A',0};
34 static const WCHAR objectW[] = {'O','B','J','E','C','T',0};
35 static const WCHAR optionW[] = {'O','P','T','I','O','N',0};
36 static const WCHAR scriptW[] = {'S','C','R','I','P','T',0};
37 static const WCHAR selectW[] = {'S','E','L','E','C','T',0};
38 static const WCHAR styleW[] = {'S','T','Y','L','E',0};
39 static const WCHAR tableW[] = {'T','A','B','L','E',0};
40 static const WCHAR tdW[] = {'T','D',0};
41 static const WCHAR textareaW[] = {'T','E','X','T','A','R','E','A',0};
42 static const WCHAR title_tagW[]= {'T','I','T','L','E',0};
43 static const WCHAR trW[] = {'T','R',0};
44
45 typedef struct {
46 const WCHAR *name;
47 HRESULT (*constructor)(HTMLDocumentNode*,nsIDOMHTMLElement*,HTMLElement**);
48 } tag_desc_t;
49
50 static const tag_desc_t tag_descs[] = {
51 {aW, HTMLAnchorElement_Create},
52 {bodyW, HTMLBodyElement_Create},
53 {buttonW, HTMLButtonElement_Create},
54 {embedW, HTMLEmbedElement_Create},
55 {formW, HTMLFormElement_Create},
56 {frameW, HTMLFrameElement_Create},
57 {headW, HTMLHeadElement_Create},
58 {iframeW, HTMLIFrame_Create},
59 {imgW, HTMLImgElement_Create},
60 {inputW, HTMLInputElement_Create},
61 {labelW, HTMLLabelElement_Create},
62 {linkW, HTMLLinkElement_Create},
63 {metaW, HTMLMetaElement_Create},
64 {objectW, HTMLObjectElement_Create},
65 {optionW, HTMLOptionElement_Create},
66 {scriptW, HTMLScriptElement_Create},
67 {selectW, HTMLSelectElement_Create},
68 {styleW, HTMLStyleElement_Create},
69 {tableW, HTMLTable_Create},
70 {tdW, HTMLTableCell_Create},
71 {textareaW, HTMLTextAreaElement_Create},
72 {title_tagW, HTMLTitleElement_Create},
73 {trW, HTMLTableRow_Create}
74 };
75
76 static const tag_desc_t *get_tag_desc(const WCHAR *tag_name)
77 {
78 DWORD min=0, max=sizeof(tag_descs)/sizeof(*tag_descs)-1, i;
79 int r;
80
81 while(min <= max) {
82 i = (min+max)/2;
83 r = strcmpW(tag_name, tag_descs[i].name);
84 if(!r)
85 return tag_descs+i;
86
87 if(r < 0)
88 max = i-1;
89 else
90 min = i+1;
91 }
92
93 return NULL;
94 }
95
96 HRESULT replace_node_by_html(nsIDOMHTMLDocument *nsdoc, nsIDOMNode *nsnode, const WCHAR *html)
97 {
98 nsIDOMDocumentFragment *nsfragment;
99 nsIDOMNode *nsparent;
100 nsIDOMRange *range;
101 nsAString html_str;
102 nsresult nsres;
103 HRESULT hres = S_OK;
104
105 nsres = nsIDOMHTMLDocument_CreateRange(nsdoc, &range);
106 if(NS_FAILED(nsres)) {
107 ERR("CreateRange failed: %08x\n", nsres);
108 return E_FAIL;
109 }
110
111 nsAString_InitDepend(&html_str, html);
112 nsIDOMRange_CreateContextualFragment(range, &html_str, &nsfragment);
113 nsIDOMRange_Release(range);
114 nsAString_Finish(&html_str);
115 if(NS_FAILED(nsres)) {
116 ERR("CreateContextualFragment failed: %08x\n", nsres);
117 return E_FAIL;
118 }
119
120 nsres = nsIDOMNode_GetParentNode(nsnode, &nsparent);
121 if(NS_SUCCEEDED(nsres) && nsparent) {
122 nsIDOMNode *nstmp;
123
124 nsres = nsIDOMNode_ReplaceChild(nsparent, (nsIDOMNode*)nsfragment, nsnode, &nstmp);
125 nsIDOMNode_Release(nsparent);
126 if(NS_FAILED(nsres)) {
127 ERR("ReplaceChild failed: %08x\n", nsres);
128 hres = E_FAIL;
129 }else if(nstmp) {
130 nsIDOMNode_Release(nstmp);
131 }
132 }else {
133 ERR("GetParentNode failed: %08x\n", nsres);
134 hres = E_FAIL;
135 }
136
137 nsIDOMDocumentFragment_Release(nsfragment);
138 return hres;
139 }
140
141 typedef struct
142 {
143 DispatchEx dispex;
144 IHTMLFiltersCollection IHTMLFiltersCollection_iface;
145
146 LONG ref;
147 } HTMLFiltersCollection;
148
149 static inline HTMLFiltersCollection *impl_from_IHTMLFiltersCollection(IHTMLFiltersCollection *iface)
150 {
151 return CONTAINING_RECORD(iface, HTMLFiltersCollection, IHTMLFiltersCollection_iface);
152 }
153
154 static IHTMLFiltersCollection *HTMLFiltersCollection_Create(void);
155
156 static inline HTMLElement *impl_from_IHTMLElement(IHTMLElement *iface)
157 {
158 return CONTAINING_RECORD(iface, HTMLElement, IHTMLElement_iface);
159 }
160
161 HRESULT create_nselem(HTMLDocumentNode *doc, const WCHAR *tag, nsIDOMHTMLElement **ret)
162 {
163 nsIDOMElement *nselem;
164 nsAString tag_str;
165 nsresult nsres;
166
167 if(!doc->nsdoc) {
168 WARN("NULL nsdoc\n");
169 return E_UNEXPECTED;
170 }
171
172 nsAString_InitDepend(&tag_str, tag);
173 nsres = nsIDOMHTMLDocument_CreateElement(doc->nsdoc, &tag_str, &nselem);
174 nsAString_Finish(&tag_str);
175 if(NS_FAILED(nsres)) {
176 ERR("CreateElement failed: %08x\n", nsres);
177 return E_FAIL;
178 }
179
180 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLElement, (void**)ret);
181 nsIDOMElement_Release(nselem);
182 if(NS_FAILED(nsres)) {
183 ERR("Could not get nsIDOMHTMLElement iface: %08x\n", nsres);
184 return E_FAIL;
185 }
186
187 return S_OK;
188 }
189
190 HRESULT create_element(HTMLDocumentNode *doc, const WCHAR *tag, HTMLElement **ret)
191 {
192 nsIDOMHTMLElement *nselem;
193 HRESULT hres;
194
195 /* Use owner doc if called on document fragment */
196 if(!doc->nsdoc)
197 doc = doc->node.doc;
198
199 hres = create_nselem(doc, tag, &nselem);
200 if(FAILED(hres))
201 return hres;
202
203 hres = HTMLElement_Create(doc, (nsIDOMNode*)nselem, TRUE, ret);
204 nsIDOMHTMLElement_Release(nselem);
205 return hres;
206 }
207
208 static HRESULT WINAPI HTMLElement_QueryInterface(IHTMLElement *iface,
209 REFIID riid, void **ppv)
210 {
211 HTMLElement *This = impl_from_IHTMLElement(iface);
212
213 return IHTMLDOMNode_QueryInterface(&This->node.IHTMLDOMNode_iface, riid, ppv);
214 }
215
216 static ULONG WINAPI HTMLElement_AddRef(IHTMLElement *iface)
217 {
218 HTMLElement *This = impl_from_IHTMLElement(iface);
219
220 return IHTMLDOMNode_AddRef(&This->node.IHTMLDOMNode_iface);
221 }
222
223 static ULONG WINAPI HTMLElement_Release(IHTMLElement *iface)
224 {
225 HTMLElement *This = impl_from_IHTMLElement(iface);
226
227 return IHTMLDOMNode_Release(&This->node.IHTMLDOMNode_iface);
228 }
229
230 static HRESULT WINAPI HTMLElement_GetTypeInfoCount(IHTMLElement *iface, UINT *pctinfo)
231 {
232 HTMLElement *This = impl_from_IHTMLElement(iface);
233 return IDispatchEx_GetTypeInfoCount(&This->node.dispex.IDispatchEx_iface, pctinfo);
234 }
235
236 static HRESULT WINAPI HTMLElement_GetTypeInfo(IHTMLElement *iface, UINT iTInfo,
237 LCID lcid, ITypeInfo **ppTInfo)
238 {
239 HTMLElement *This = impl_from_IHTMLElement(iface);
240 return IDispatchEx_GetTypeInfo(&This->node.dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
241 }
242
243 static HRESULT WINAPI HTMLElement_GetIDsOfNames(IHTMLElement *iface, REFIID riid,
244 LPOLESTR *rgszNames, UINT cNames,
245 LCID lcid, DISPID *rgDispId)
246 {
247 HTMLElement *This = impl_from_IHTMLElement(iface);
248 return IDispatchEx_GetIDsOfNames(&This->node.dispex.IDispatchEx_iface, riid, rgszNames, cNames,
249 lcid, rgDispId);
250 }
251
252 static HRESULT WINAPI HTMLElement_Invoke(IHTMLElement *iface, DISPID dispIdMember,
253 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
254 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
255 {
256 HTMLElement *This = impl_from_IHTMLElement(iface);
257 return IDispatchEx_Invoke(&This->node.dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
258 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
259 }
260
261 static HRESULT WINAPI HTMLElement_setAttribute(IHTMLElement *iface, BSTR strAttributeName,
262 VARIANT AttributeValue, LONG lFlags)
263 {
264 HTMLElement *This = impl_from_IHTMLElement(iface);
265 HRESULT hres;
266 DISPID dispid, dispidNamed = DISPID_PROPERTYPUT;
267 DISPPARAMS dispParams;
268 EXCEPINFO excep;
269
270 TRACE("(%p)->(%s %s %08x)\n", This, debugstr_w(strAttributeName), debugstr_variant(&AttributeValue), lFlags);
271
272 hres = IDispatchEx_GetDispID(&This->node.dispex.IDispatchEx_iface, strAttributeName,
273 fdexNameCaseInsensitive | fdexNameEnsure, &dispid);
274 if(FAILED(hres))
275 return hres;
276
277 dispParams.cArgs = 1;
278 dispParams.cNamedArgs = 1;
279 dispParams.rgdispidNamedArgs = &dispidNamed;
280 dispParams.rgvarg = &AttributeValue;
281
282 hres = IDispatchEx_InvokeEx(&This->node.dispex.IDispatchEx_iface, dispid,
283 LOCALE_SYSTEM_DEFAULT, DISPATCH_PROPERTYPUT, &dispParams, NULL, &excep, NULL);
284 return hres;
285 }
286
287 static HRESULT WINAPI HTMLElement_getAttribute(IHTMLElement *iface, BSTR strAttributeName,
288 LONG lFlags, VARIANT *AttributeValue)
289 {
290 HTMLElement *This = impl_from_IHTMLElement(iface);
291 DISPID dispid;
292 HRESULT hres;
293 DISPPARAMS dispParams = {NULL, NULL, 0, 0};
294 EXCEPINFO excep;
295
296 TRACE("(%p)->(%s %08x %p)\n", This, debugstr_w(strAttributeName), lFlags, AttributeValue);
297
298 hres = IDispatchEx_GetDispID(&This->node.dispex.IDispatchEx_iface, strAttributeName,
299 fdexNameCaseInsensitive, &dispid);
300 if(hres == DISP_E_UNKNOWNNAME) {
301 V_VT(AttributeValue) = VT_NULL;
302 return S_OK;
303 }
304
305 if(FAILED(hres)) {
306 V_VT(AttributeValue) = VT_NULL;
307 return hres;
308 }
309
310 hres = IDispatchEx_InvokeEx(&This->node.dispex.IDispatchEx_iface, dispid, LOCALE_SYSTEM_DEFAULT,
311 DISPATCH_PROPERTYGET, &dispParams, AttributeValue, &excep, NULL);
312
313 return hres;
314 }
315
316 static HRESULT WINAPI HTMLElement_removeAttribute(IHTMLElement *iface, BSTR strAttributeName,
317 LONG lFlags, VARIANT_BOOL *pfSuccess)
318 {
319 HTMLElement *This = impl_from_IHTMLElement(iface);
320
321 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(strAttributeName), lFlags, pfSuccess);
322
323 return remove_prop(&This->node.dispex, strAttributeName, pfSuccess);
324 }
325
326 static HRESULT WINAPI HTMLElement_put_className(IHTMLElement *iface, BSTR v)
327 {
328 HTMLElement *This = impl_from_IHTMLElement(iface);
329 nsAString classname_str;
330 nsresult nsres;
331
332 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
333
334 if(!This->nselem) {
335 FIXME("NULL nselem\n");
336 return E_NOTIMPL;
337 }
338
339 nsAString_InitDepend(&classname_str, v);
340 nsres = nsIDOMHTMLElement_SetClassName(This->nselem, &classname_str);
341 nsAString_Finish(&classname_str);
342 if(NS_FAILED(nsres))
343 ERR("SetClassName failed: %08x\n", nsres);
344
345 return S_OK;
346 }
347
348 static HRESULT WINAPI HTMLElement_get_className(IHTMLElement *iface, BSTR *p)
349 {
350 HTMLElement *This = impl_from_IHTMLElement(iface);
351 nsAString class_str;
352 nsresult nsres;
353
354 TRACE("(%p)->(%p)\n", This, p);
355
356 if(!This->nselem) {
357 FIXME("NULL nselem\n");
358 return E_NOTIMPL;
359 }
360
361 nsAString_Init(&class_str, NULL);
362 nsres = nsIDOMHTMLElement_GetClassName(This->nselem, &class_str);
363 return return_nsstr(nsres, &class_str, p);
364 }
365
366 static HRESULT WINAPI HTMLElement_put_id(IHTMLElement *iface, BSTR v)
367 {
368 HTMLElement *This = impl_from_IHTMLElement(iface);
369 nsAString id_str;
370 nsresult nsres;
371
372 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
373
374 if(!This->nselem) {
375 FIXME("nselem == NULL\n");
376 return S_OK;
377 }
378
379 nsAString_InitDepend(&id_str, v);
380 nsres = nsIDOMHTMLElement_SetId(This->nselem, &id_str);
381 nsAString_Finish(&id_str);
382 if(NS_FAILED(nsres))
383 ERR("SetId failed: %08x\n", nsres);
384
385 return S_OK;
386 }
387
388 static HRESULT WINAPI HTMLElement_get_id(IHTMLElement *iface, BSTR *p)
389 {
390 HTMLElement *This = impl_from_IHTMLElement(iface);
391 nsAString id_str;
392 nsresult nsres;
393
394 TRACE("(%p)->(%p)\n", This, p);
395
396 if(!This->nselem) {
397 *p = NULL;
398 return S_OK;
399 }
400
401 nsAString_Init(&id_str, NULL);
402 nsres = nsIDOMHTMLElement_GetId(This->nselem, &id_str);
403 return return_nsstr(nsres, &id_str, p);
404 }
405
406 static HRESULT WINAPI HTMLElement_get_tagName(IHTMLElement *iface, BSTR *p)
407 {
408 HTMLElement *This = impl_from_IHTMLElement(iface);
409 nsAString tag_str;
410 nsresult nsres;
411
412 TRACE("(%p)->(%p)\n", This, p);
413
414 if(!This->nselem) {
415 static const WCHAR comment_tagW[] = {'!',0};
416
417 WARN("NULL nselem, assuming comment\n");
418
419 *p = SysAllocString(comment_tagW);
420 return *p ? S_OK : E_OUTOFMEMORY;
421 }
422
423 nsAString_Init(&tag_str, NULL);
424 nsres = nsIDOMHTMLElement_GetTagName(This->nselem, &tag_str);
425 return return_nsstr(nsres, &tag_str, p);
426 }
427
428 static HRESULT WINAPI HTMLElement_get_parentElement(IHTMLElement *iface, IHTMLElement **p)
429 {
430 HTMLElement *This = impl_from_IHTMLElement(iface);
431 IHTMLDOMNode *node;
432 HRESULT hres;
433
434 TRACE("(%p)->(%p)\n", This, p);
435
436 hres = IHTMLDOMNode_get_parentNode(&This->node.IHTMLDOMNode_iface, &node);
437 if(FAILED(hres))
438 return hres;
439
440 hres = IHTMLDOMNode_QueryInterface(node, &IID_IHTMLElement, (void**)p);
441 IHTMLDOMNode_Release(node);
442 if(FAILED(hres))
443 *p = NULL;
444
445 return S_OK;
446 }
447
448 static HRESULT WINAPI HTMLElement_get_style(IHTMLElement *iface, IHTMLStyle **p)
449 {
450 HTMLElement *This = impl_from_IHTMLElement(iface);
451
452 TRACE("(%p)->(%p)\n", This, p);
453
454 if(!This->style) {
455 HRESULT hres;
456
457 hres = HTMLStyle_Create(This, &This->style);
458 if(FAILED(hres))
459 return hres;
460 }
461
462 *p = &This->style->IHTMLStyle_iface;
463 IHTMLStyle_AddRef(*p);
464 return S_OK;
465 }
466
467 static HRESULT WINAPI HTMLElement_put_onhelp(IHTMLElement *iface, VARIANT v)
468 {
469 HTMLElement *This = impl_from_IHTMLElement(iface);
470 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
471 return E_NOTIMPL;
472 }
473
474 static HRESULT WINAPI HTMLElement_get_onhelp(IHTMLElement *iface, VARIANT *p)
475 {
476 HTMLElement *This = impl_from_IHTMLElement(iface);
477 FIXME("(%p)->(%p)\n", This, p);
478 return E_NOTIMPL;
479 }
480
481 static HRESULT WINAPI HTMLElement_put_onclick(IHTMLElement *iface, VARIANT v)
482 {
483 HTMLElement *This = impl_from_IHTMLElement(iface);
484
485 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
486
487 return set_node_event(&This->node, EVENTID_CLICK, &v);
488 }
489
490 static HRESULT WINAPI HTMLElement_get_onclick(IHTMLElement *iface, VARIANT *p)
491 {
492 HTMLElement *This = impl_from_IHTMLElement(iface);
493
494 TRACE("(%p)->(%p)\n", This, p);
495
496 return get_node_event(&This->node, EVENTID_CLICK, p);
497 }
498
499 static HRESULT WINAPI HTMLElement_put_ondblclick(IHTMLElement *iface, VARIANT v)
500 {
501 HTMLElement *This = impl_from_IHTMLElement(iface);
502
503 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
504
505 return set_node_event(&This->node, EVENTID_DBLCLICK, &v);
506 }
507
508 static HRESULT WINAPI HTMLElement_get_ondblclick(IHTMLElement *iface, VARIANT *p)
509 {
510 HTMLElement *This = impl_from_IHTMLElement(iface);
511
512 TRACE("(%p)->(%p)\n", This, p);
513
514 return get_node_event(&This->node, EVENTID_DBLCLICK, p);
515 }
516
517 static HRESULT WINAPI HTMLElement_put_onkeydown(IHTMLElement *iface, VARIANT v)
518 {
519 HTMLElement *This = impl_from_IHTMLElement(iface);
520
521 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
522
523 return set_node_event(&This->node, EVENTID_KEYDOWN, &v);
524 }
525
526 static HRESULT WINAPI HTMLElement_get_onkeydown(IHTMLElement *iface, VARIANT *p)
527 {
528 HTMLElement *This = impl_from_IHTMLElement(iface);
529
530 TRACE("(%p)->(%p)\n", This, p);
531
532 return get_node_event(&This->node, EVENTID_KEYDOWN, p);
533 }
534
535 static HRESULT WINAPI HTMLElement_put_onkeyup(IHTMLElement *iface, VARIANT v)
536 {
537 HTMLElement *This = impl_from_IHTMLElement(iface);
538
539 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
540
541 return set_node_event(&This->node, EVENTID_KEYUP, &v);
542 }
543
544 static HRESULT WINAPI HTMLElement_get_onkeyup(IHTMLElement *iface, VARIANT *p)
545 {
546 HTMLElement *This = impl_from_IHTMLElement(iface);
547 FIXME("(%p)->(%p)\n", This, p);
548 return E_NOTIMPL;
549 }
550
551 static HRESULT WINAPI HTMLElement_put_onkeypress(IHTMLElement *iface, VARIANT v)
552 {
553 HTMLElement *This = impl_from_IHTMLElement(iface);
554
555 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
556
557 return set_node_event(&This->node, EVENTID_KEYPRESS, &v);
558 }
559
560 static HRESULT WINAPI HTMLElement_get_onkeypress(IHTMLElement *iface, VARIANT *p)
561 {
562 HTMLElement *This = impl_from_IHTMLElement(iface);
563
564 TRACE("(%p)->(%p)\n", This, p);
565
566 return get_node_event(&This->node, EVENTID_KEYPRESS, p);
567 }
568
569 static HRESULT WINAPI HTMLElement_put_onmouseout(IHTMLElement *iface, VARIANT v)
570 {
571 HTMLElement *This = impl_from_IHTMLElement(iface);
572
573 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
574
575 return set_node_event(&This->node, EVENTID_MOUSEOUT, &v);
576 }
577
578 static HRESULT WINAPI HTMLElement_get_onmouseout(IHTMLElement *iface, VARIANT *p)
579 {
580 HTMLElement *This = impl_from_IHTMLElement(iface);
581
582 TRACE("(%p)->(%p)\n", This, p);
583
584 return get_node_event(&This->node, EVENTID_MOUSEOUT, p);
585 }
586
587 static HRESULT WINAPI HTMLElement_put_onmouseover(IHTMLElement *iface, VARIANT v)
588 {
589 HTMLElement *This = impl_from_IHTMLElement(iface);
590
591 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
592
593 return set_node_event(&This->node, EVENTID_MOUSEOVER, &v);
594 }
595
596 static HRESULT WINAPI HTMLElement_get_onmouseover(IHTMLElement *iface, VARIANT *p)
597 {
598 HTMLElement *This = impl_from_IHTMLElement(iface);
599
600 TRACE("(%p)->(%p)\n", This, p);
601
602 return get_node_event(&This->node, EVENTID_MOUSEOVER, p);
603 }
604
605 static HRESULT WINAPI HTMLElement_put_onmousemove(IHTMLElement *iface, VARIANT v)
606 {
607 HTMLElement *This = impl_from_IHTMLElement(iface);
608
609 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
610
611 return set_node_event(&This->node, EVENTID_MOUSEMOVE, &v);
612 }
613
614 static HRESULT WINAPI HTMLElement_get_onmousemove(IHTMLElement *iface, VARIANT *p)
615 {
616 HTMLElement *This = impl_from_IHTMLElement(iface);
617
618 TRACE("(%p)->(%p)\n", This, p);
619
620 return get_node_event(&This->node, EVENTID_MOUSEMOVE, p);
621 }
622
623 static HRESULT WINAPI HTMLElement_put_onmousedown(IHTMLElement *iface, VARIANT v)
624 {
625 HTMLElement *This = impl_from_IHTMLElement(iface);
626
627 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
628
629 return set_node_event(&This->node, EVENTID_MOUSEDOWN, &v);
630 }
631
632 static HRESULT WINAPI HTMLElement_get_onmousedown(IHTMLElement *iface, VARIANT *p)
633 {
634 HTMLElement *This = impl_from_IHTMLElement(iface);
635
636 TRACE("(%p)->(%p)\n", This, p);
637
638 return get_node_event(&This->node, EVENTID_MOUSEDOWN, p);
639 }
640
641 static HRESULT WINAPI HTMLElement_put_onmouseup(IHTMLElement *iface, VARIANT v)
642 {
643 HTMLElement *This = impl_from_IHTMLElement(iface);
644
645 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
646
647 return set_node_event(&This->node, EVENTID_MOUSEUP, &v);
648 }
649
650 static HRESULT WINAPI HTMLElement_get_onmouseup(IHTMLElement *iface, VARIANT *p)
651 {
652 HTMLElement *This = impl_from_IHTMLElement(iface);
653
654 TRACE("(%p)->(%p)\n", This, p);
655
656 return get_node_event(&This->node, EVENTID_MOUSEUP, p);
657 }
658
659 static HRESULT WINAPI HTMLElement_get_document(IHTMLElement *iface, IDispatch **p)
660 {
661 HTMLElement *This = impl_from_IHTMLElement(iface);
662
663 TRACE("(%p)->(%p)\n", This, p);
664
665 if(!p)
666 return E_POINTER;
667
668 if(This->node.vtbl->get_document)
669 return This->node.vtbl->get_document(&This->node, p);
670
671 *p = (IDispatch*)&This->node.doc->basedoc.IHTMLDocument2_iface;
672 IDispatch_AddRef(*p);
673 return S_OK;
674 }
675
676 static const WCHAR titleW[] = {'t','i','t','l','e',0};
677
678 static HRESULT WINAPI HTMLElement_put_title(IHTMLElement *iface, BSTR v)
679 {
680 HTMLElement *This = impl_from_IHTMLElement(iface);
681 nsAString title_str;
682 nsresult nsres;
683
684 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
685
686 if(!This->nselem) {
687 VARIANT *var;
688 HRESULT hres;
689
690 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, TRUE, &var);
691 if(FAILED(hres))
692 return hres;
693
694 VariantClear(var);
695 V_VT(var) = VT_BSTR;
696 V_BSTR(var) = v ? SysAllocString(v) : NULL;
697 return S_OK;
698 }
699
700 nsAString_InitDepend(&title_str, v);
701 nsres = nsIDOMHTMLElement_SetTitle(This->nselem, &title_str);
702 nsAString_Finish(&title_str);
703 if(NS_FAILED(nsres))
704 ERR("SetTitle failed: %08x\n", nsres);
705
706 return S_OK;
707 }
708
709 static HRESULT WINAPI HTMLElement_get_title(IHTMLElement *iface, BSTR *p)
710 {
711 HTMLElement *This = impl_from_IHTMLElement(iface);
712 nsAString title_str;
713 nsresult nsres;
714
715 TRACE("(%p)->(%p)\n", This, p);
716
717 if(!This->nselem) {
718 VARIANT *var;
719 HRESULT hres;
720
721 hres = dispex_get_dprop_ref(&This->node.dispex, titleW, FALSE, &var);
722 if(hres == DISP_E_UNKNOWNNAME) {
723 *p = NULL;
724 }else if(V_VT(var) != VT_BSTR) {
725 FIXME("title = %s\n", debugstr_variant(var));
726 return E_FAIL;
727 }else {
728 *p = V_BSTR(var) ? SysAllocString(V_BSTR(var)) : NULL;
729 }
730
731 return S_OK;
732 }
733
734 nsAString_Init(&title_str, NULL);
735 nsres = nsIDOMHTMLElement_GetTitle(This->nselem, &title_str);
736 return return_nsstr(nsres, &title_str, p);
737 }
738
739 static HRESULT WINAPI HTMLElement_put_language(IHTMLElement *iface, BSTR v)
740 {
741 HTMLElement *This = impl_from_IHTMLElement(iface);
742 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
743 return E_NOTIMPL;
744 }
745
746 static HRESULT WINAPI HTMLElement_get_language(IHTMLElement *iface, BSTR *p)
747 {
748 HTMLElement *This = impl_from_IHTMLElement(iface);
749 FIXME("(%p)->(%p)\n", This, p);
750 return E_NOTIMPL;
751 }
752
753 static HRESULT WINAPI HTMLElement_put_onselectstart(IHTMLElement *iface, VARIANT v)
754 {
755 HTMLElement *This = impl_from_IHTMLElement(iface);
756
757 TRACE("(%p)->(%s)\n", This, debugstr_variant(&v));
758
759 return set_node_event(&This->node, EVENTID_SELECTSTART, &v);
760 }
761
762 static HRESULT WINAPI HTMLElement_get_onselectstart(IHTMLElement *iface, VARIANT *p)
763 {
764 HTMLElement *This = impl_from_IHTMLElement(iface);
765
766 TRACE("(%p)->(%p)\n", This, p);
767
768 return get_node_event(&This->node, EVENTID_SELECTSTART, p);
769 }
770
771 static HRESULT WINAPI HTMLElement_scrollIntoView(IHTMLElement *iface, VARIANT varargStart)
772 {
773 HTMLElement *This = impl_from_IHTMLElement(iface);
774 FIXME("(%p)->(%s)\n", This, debugstr_variant(&varargStart));
775 return E_NOTIMPL;
776 }
777
778 static HRESULT WINAPI HTMLElement_contains(IHTMLElement *iface, IHTMLElement *pChild,
779 VARIANT_BOOL *pfResult)
780 {
781 HTMLElement *This = impl_from_IHTMLElement(iface);
782 HTMLElement *child;
783 cpp_bool result;
784 nsresult nsres;
785
786 TRACE("(%p)->(%p %p)\n", This, pChild, pfResult);
787
788 child = unsafe_impl_from_IHTMLElement(pChild);
789 if(!child) {
790 ERR("not our element\n");
791 return E_FAIL;
792 }
793
794 nsres = nsIDOMNode_Contains(This->node.nsnode, child->node.nsnode, &result);
795 if(NS_FAILED(nsres)) {
796 ERR("failed\n");
797 return E_FAIL;
798 }
799
800 *pfResult = result ? VARIANT_TRUE : VARIANT_FALSE;
801 return S_OK;
802 }
803
804 static HRESULT WINAPI HTMLElement_get_sourceIndex(IHTMLElement *iface, LONG *p)
805 {
806 HTMLElement *This = impl_from_IHTMLElement(iface);
807 FIXME("(%p)->(%p)\n", This, p);
808 return E_NOTIMPL;
809 }
810
811 static HRESULT WINAPI HTMLElement_get_recordNumber(IHTMLElement *iface, VARIANT *p)
812 {
813 HTMLElement *This = impl_from_IHTMLElement(iface);
814 FIXME("(%p)->(%p)\n", This, p);
815 return E_NOTIMPL;
816 }
817
818 static HRESULT WINAPI HTMLElement_put_lang(IHTMLElement *iface, BSTR v)
819 {
820 HTMLElement *This = impl_from_IHTMLElement(iface);
821 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
822 return E_NOTIMPL;
823 }
824
825 static HRESULT WINAPI HTMLElement_get_lang(IHTMLElement *iface, BSTR *p)
826 {
827 HTMLElement *This = impl_from_IHTMLElement(iface);
828 FIXME("(%p)->(%p)\n", This, p);
829 return E_NOTIMPL;
830 }
831
832 static HRESULT WINAPI HTMLElement_get_offsetLeft(IHTMLElement *iface, LONG *p)
833 {
834 HTMLElement *This = impl_from_IHTMLElement(iface);
835 nsresult nsres;
836
837 TRACE("(%p)->(%p)\n", This, p);
838
839 nsres = nsIDOMHTMLElement_GetOffsetLeft(This->nselem, p);
840 if(NS_FAILED(nsres)) {
841 ERR("GetOffsetLeft failed: %08x\n", nsres);
842 return E_FAIL;
843 }
844
845 return S_OK;
846 }
847
848 static HRESULT WINAPI HTMLElement_get_offsetTop(IHTMLElement *iface, LONG *p)
849 {
850 HTMLElement *This = impl_from_IHTMLElement(iface);
851 nsresult nsres;
852
853 TRACE("(%p)->(%p)\n", This, p);
854
855 nsres = nsIDOMHTMLElement_GetOffsetTop(This->nselem, p);
856 if(NS_FAILED(nsres)) {
857 ERR("GetOffsetTop failed: %08x\n", nsres);
858 return E_FAIL;
859 }
860
861 return S_OK;
862 }
863
864 static HRESULT WINAPI HTMLElement_get_offsetWidth(IHTMLElement *iface, LONG *p)
865 {
866 HTMLElement *This = impl_from_IHTMLElement(iface);
867 nsresult nsres;
868
869 TRACE("(%p)->(%p)\n", This, p);
870
871 nsres = nsIDOMHTMLElement_GetOffsetWidth(This->nselem, p);
872 if(NS_FAILED(nsres)) {
873 ERR("GetOffsetWidth failed: %08x\n", nsres);
874 return E_FAIL;
875 }
876
877 return S_OK;
878 }
879
880 static HRESULT WINAPI HTMLElement_get_offsetHeight(IHTMLElement *iface, LONG *p)
881 {
882 HTMLElement *This = impl_from_IHTMLElement(iface);
883 nsresult nsres;
884
885 TRACE("(%p)->(%p)\n", This, p);
886
887 nsres = nsIDOMHTMLElement_GetOffsetHeight(This->nselem, p);
888 if(NS_FAILED(nsres)) {
889 ERR("GetOffsetHeight failed: %08x\n", nsres);
890 return E_FAIL;
891 }
892
893 return S_OK;
894 }
895
896 static HRESULT WINAPI HTMLElement_get_offsetParent(IHTMLElement *iface, IHTMLElement **p)
897 {
898 HTMLElement *This = impl_from_IHTMLElement(iface);
899 nsIDOMElement *nsparent;
900 nsresult nsres;
901 HRESULT hres;
902
903 TRACE("(%p)->(%p)\n", This, p);
904
905 nsres = nsIDOMHTMLElement_GetOffsetParent(This->nselem, &nsparent);
906 if(NS_FAILED(nsres)) {
907 ERR("GetOffsetParent failed: %08x\n", nsres);
908 return E_FAIL;
909 }
910
911 if(nsparent) {
912 HTMLDOMNode *node;
913
914 hres = get_node(This->node.doc, (nsIDOMNode*)nsparent, TRUE, &node);
915 nsIDOMElement_Release(nsparent);
916 if(FAILED(hres))
917 return hres;
918
919 hres = IHTMLDOMNode_QueryInterface(&node->IHTMLDOMNode_iface, &IID_IHTMLElement, (void**)p);
920 node_release(node);
921 }else {
922 *p = NULL;
923 hres = S_OK;
924 }
925
926 return hres;
927 }
928
929 static HRESULT WINAPI HTMLElement_put_innerHTML(IHTMLElement *iface, BSTR v)
930 {
931 HTMLElement *This = impl_from_IHTMLElement(iface);
932 nsAString html_str;
933 nsresult nsres;
934
935 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
936
937 if(!This->nselem) {
938 FIXME("NULL nselem\n");
939 return E_NOTIMPL;
940 }
941
942 nsAString_InitDepend(&html_str, v);
943 nsres = nsIDOMHTMLElement_SetInnerHTML(This->nselem, &html_str);
944 nsAString_Finish(&html_str);
945 if(NS_FAILED(nsres)) {
946 FIXME("SetInnerHtml failed %08x\n", nsres);
947 return E_FAIL;
948 }
949
950 return S_OK;
951 }
952
953 static HRESULT WINAPI HTMLElement_get_innerHTML(IHTMLElement *iface, BSTR *p)
954 {
955 HTMLElement *This = impl_from_IHTMLElement(iface);
956 nsAString html_str;
957 nsresult nsres;
958
959 TRACE("(%p)->(%p)\n", This, p);
960
961 if(!This->nselem) {
962 FIXME("NULL nselem\n");
963 return E_NOTIMPL;
964 }
965
966 nsAString_Init(&html_str, NULL);
967 nsres = nsIDOMHTMLElement_GetInnerHTML(This->nselem, &html_str);
968 return return_nsstr(nsres, &html_str, p);
969 }
970
971 static HRESULT WINAPI HTMLElement_put_innerText(IHTMLElement *iface, BSTR v)
972 {
973 HTMLElement *This = impl_from_IHTMLElement(iface);
974 nsIDOMNode *nschild, *tmp;
975 nsIDOMText *text_node;
976 nsAString text_str;
977 nsresult nsres;
978
979 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
980
981 while(1) {
982 nsres = nsIDOMHTMLElement_GetLastChild(This->nselem, &nschild);
983 if(NS_FAILED(nsres)) {
984 ERR("GetLastChild failed: %08x\n", nsres);
985 return E_FAIL;
986 }
987 if(!nschild)
988 break;
989
990 nsres = nsIDOMHTMLElement_RemoveChild(This->nselem, nschild, &tmp);
991 nsIDOMNode_Release(nschild);
992 if(NS_FAILED(nsres)) {
993 ERR("RemoveChild failed: %08x\n", nsres);
994 return E_FAIL;
995 }
996 nsIDOMNode_Release(tmp);
997 }
998
999 nsAString_InitDepend(&text_str, v);
1000 nsres = nsIDOMHTMLDocument_CreateTextNode(This->node.doc->nsdoc, &text_str, &text_node);
1001 nsAString_Finish(&text_str);
1002 if(NS_FAILED(nsres)) {
1003 ERR("CreateTextNode failed: %08x\n", nsres);
1004 return E_FAIL;
1005 }
1006
1007 nsres = nsIDOMHTMLElement_AppendChild(This->nselem, (nsIDOMNode*)text_node, &tmp);
1008 if(NS_FAILED(nsres)) {
1009 ERR("AppendChild failed: %08x\n", nsres);
1010 return E_FAIL;
1011 }
1012
1013 nsIDOMNode_Release(tmp);
1014 return S_OK;
1015 }
1016
1017 static HRESULT WINAPI HTMLElement_get_innerText(IHTMLElement *iface, BSTR *p)
1018 {
1019 HTMLElement *This = impl_from_IHTMLElement(iface);
1020
1021 TRACE("(%p)->(%p)\n", This, p);
1022
1023 return get_node_text(&This->node, p);
1024 }
1025
1026 static HRESULT WINAPI HTMLElement_put_outerHTML(IHTMLElement *iface, BSTR v)
1027 {
1028 HTMLElement *This = impl_from_IHTMLElement(iface);
1029
1030 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
1031
1032 return replace_node_by_html(This->node.doc->nsdoc, This->node.nsnode, v);
1033 }
1034
1035 static HRESULT WINAPI HTMLElement_get_outerHTML(IHTMLElement *iface, BSTR *p)
1036 {
1037 HTMLElement *This = impl_from_IHTMLElement(iface);
1038 nsAString html_str;
1039 HRESULT hres;
1040
1041 WARN("(%p)->(%p) semi-stub\n", This, p);
1042
1043 nsAString_Init(&html_str, NULL);
1044 hres = nsnode_to_nsstring(This->node.nsnode, &html_str);
1045 if(SUCCEEDED(hres)) {
1046 const PRUnichar *html;
1047
1048 nsAString_GetData(&html_str, &html);
1049 *p = SysAllocString(html);
1050 if(!*p)
1051 hres = E_OUTOFMEMORY;
1052 }
1053
1054 nsAString_Finish(&html_str);
1055
1056 TRACE("ret %s\n", debugstr_w(*p));
1057 return hres;
1058 }
1059
1060 static HRESULT WINAPI HTMLElement_put_outerText(IHTMLElement *iface, BSTR v)
1061 {
1062 HTMLElement *This = impl_from_IHTMLElement(iface);
1063 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
1064 return E_NOTIMPL;
1065 }
1066
1067 static HRESULT WINAPI HTMLElement_get_outerText(IHTMLElement *iface, BSTR *p)
1068 {
1069 HTMLElement *This = impl_from_IHTMLElement(iface);
1070 FIXME("(%p)->(%p)\n", This, p);
1071 return E_NOTIMPL;
1072 }
1073
1074 HRESULT insert_adjacent_node(HTMLElement *This, const WCHAR *where, nsIDOMNode *nsnode, HTMLDOMNode **ret_node)
1075 {
1076 nsIDOMNode *ret_nsnode;
1077 nsresult nsres;
1078 HRESULT hres = S_OK;
1079
1080 static const WCHAR beforebeginW[] = {'b','e','f','o','r','e','b','e','g','i','n',0};
1081 static const WCHAR afterbeginW[] = {'a','f','t','e','r','b','e','g','i','n',0};
1082 static const WCHAR beforeendW[] = {'b','e','f','o','r','e','e','n','d',0};
1083 static const WCHAR afterendW[] = {'a','f','t','e','r','e','n','d',0};
1084
1085 if (!strcmpiW(where, beforebeginW)) {
1086 nsIDOMNode *parent;
1087
1088 nsres = nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1089 if(NS_FAILED(nsres))
1090 return E_FAIL;
1091
1092 if(!parent)
1093 return E_INVALIDARG;
1094
1095 nsres = nsIDOMNode_InsertBefore(parent, nsnode, This->node.nsnode, &ret_nsnode);
1096 nsIDOMNode_Release(parent);
1097 }else if(!strcmpiW(where, afterbeginW)) {
1098 nsIDOMNode *first_child;
1099
1100 nsres = nsIDOMNode_GetFirstChild(This->node.nsnode, &first_child);
1101 if(NS_FAILED(nsres))
1102 return E_FAIL;
1103
1104 nsres = nsIDOMNode_InsertBefore(This->node.nsnode, nsnode, first_child, &ret_nsnode);
1105 if(NS_FAILED(nsres))
1106 return E_FAIL;
1107
1108 if (first_child)
1109 nsIDOMNode_Release(first_child);
1110 }else if (!strcmpiW(where, beforeendW)) {
1111 nsres = nsIDOMNode_AppendChild(This->node.nsnode, nsnode, &ret_nsnode);
1112 }else if (!strcmpiW(where, afterendW)) {
1113 nsIDOMNode *next_sibling, *parent;
1114
1115 nsres = nsIDOMNode_GetParentNode(This->node.nsnode, &parent);
1116 if(NS_FAILED(nsres))
1117 return E_FAIL;
1118 if(!parent)
1119 return E_INVALIDARG;
1120
1121 nsres = nsIDOMNode_GetNextSibling(This->node.nsnode, &next_sibling);
1122 if(NS_SUCCEEDED(nsres)) {
1123 if(next_sibling) {
1124 nsres = nsIDOMNode_InsertBefore(parent, nsnode, next_sibling, &ret_nsnode);
1125 nsIDOMNode_Release(next_sibling);
1126 }else {
1127 nsres = nsIDOMNode_AppendChild(parent, nsnode, &ret_nsnode);
1128 }
1129 }
1130
1131 nsIDOMNode_Release(parent);
1132 }else {
1133 ERR("invalid where: %s\n", debugstr_w(where));
1134 return E_INVALIDARG;
1135 }
1136
1137 if (NS_FAILED(nsres))
1138 return E_FAIL;
1139
1140 if(ret_node)
1141 hres = get_node(This->node.doc, ret_nsnode, TRUE, ret_node);
1142 nsIDOMNode_Release(ret_nsnode);
1143 return hres;
1144 }
1145
1146 static HRESULT WINAPI HTMLElement_insertAdjacentHTML(IHTMLElement *iface, BSTR where,
1147 BSTR html)
1148 {
1149 HTMLElement *This = impl_from_IHTMLElement(iface);
1150 nsIDOMRange *range;
1151 nsIDOMNode *nsnode;
1152 nsAString ns_html;
1153 nsresult nsres;
1154 HRESULT hr;
1155
1156 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(html));
1157
1158 if(!This->node.doc->nsdoc) {
1159 WARN("NULL nsdoc\n");
1160 return E_UNEXPECTED;
1161 }
1162
1163 nsres = nsIDOMHTMLDocument_CreateRange(This->node.doc->nsdoc, &range);
1164 if(NS_FAILED(nsres))
1165 {
1166 ERR("CreateRange failed: %08x\n", nsres);
1167 return E_FAIL;
1168 }
1169
1170 nsIDOMRange_SetStartBefore(range, This->node.nsnode);
1171
1172 nsAString_InitDepend(&ns_html, html);
1173 nsres = nsIDOMRange_CreateContextualFragment(range, &ns_html, (nsIDOMDocumentFragment **)&nsnode);
1174 nsAString_Finish(&ns_html);
1175 nsIDOMRange_Release(range);
1176
1177 if(NS_FAILED(nsres) || !nsnode)
1178 {
1179 ERR("CreateTextNode failed: %08x\n", nsres);
1180 return E_FAIL;
1181 }
1182
1183 hr = insert_adjacent_node(This, where, nsnode, NULL);
1184 nsIDOMNode_Release(nsnode);
1185 return hr;
1186 }
1187
1188 static HRESULT WINAPI HTMLElement_insertAdjacentText(IHTMLElement *iface, BSTR where,
1189 BSTR text)
1190 {
1191 HTMLElement *This = impl_from_IHTMLElement(iface);
1192 nsIDOMNode *nsnode;
1193 nsAString ns_text;
1194 nsresult nsres;
1195 HRESULT hr;
1196
1197 TRACE("(%p)->(%s %s)\n", This, debugstr_w(where), debugstr_w(text));
1198
1199 if(!This->node.doc->nsdoc) {
1200 WARN("NULL nsdoc\n");
1201 return E_UNEXPECTED;
1202 }
1203
1204
1205 nsAString_InitDepend(&ns_text, text);
1206 nsres = nsIDOMHTMLDocument_CreateTextNode(This->node.doc->nsdoc, &ns_text, (nsIDOMText **)&nsnode);
1207 nsAString_Finish(&ns_text);
1208
1209 if(NS_FAILED(nsres) || !nsnode)
1210 {
1211 ERR("CreateTextNode failed: %08x\n", nsres);
1212 return E_FAIL;
1213 }
1214
1215 hr = insert_adjacent_node(This, where, nsnode, NULL);
1216 nsIDOMNode_Release(nsnode);
1217
1218 return hr;
1219 }
1220
1221 static HRESULT WINAPI HTMLElement_get_parentTextEdit(IHTMLElement *iface, IHTMLElement **p)
1222 {
1223 HTMLElement *This = impl_from_IHTMLElement(iface);
1224 FIXME("(%p)->(%p)\n", This, p);
1225 return E_NOTIMPL;
1226 }
1227
1228 static HRESULT WINAPI HTMLElement_get_isTextEdit(IHTMLElement *iface, VARIANT_BOOL *p)
1229 {
1230 HTMLElement *This = impl_from_IHTMLElement(iface);
1231 FIXME("(%p)->(%p)\n", This, p);
1232 return E_NOTIMPL;
1233 }
1234
1235 static HRESULT WINAPI HTMLElement_click(IHTMLElement *iface)
1236 {
1237 HTMLElement *This = impl_from_IHTMLElement(iface);
1238
1239 TRACE("(%p)\n", This);
1240
1241 return call_fire_event(&This->node, EVENTID_CLICK);
1242 }
1243
1244 static HRESULT WINAPI HTMLElement_get_filters(IHTMLElement *iface,
1245 IHTMLFiltersCollection **p)
1246 {
1247 HTMLElement *This = impl_from_IHTMLElement(iface);
1248 TRACE("(%p)->(%p)\n", This, p);
1249
1250 if(!p)
1251 return E_POINTER;
1252
1253 *p = HTMLFiltersCollection_Create();
1254
1255 return S_OK;
1256 }
1257
1258 static HRESULT WINAPI HTMLElement_put_ondragstart(IHTMLElement *iface, VARIANT v)
1259 {
1260 HTMLElement *This = impl_from_IHTMLElement(iface);
1261 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1262 return E_NOTIMPL;
1263 }
1264
1265 static HRESULT WINAPI HTMLElement_get_ondragstart(IHTMLElement *iface, VARIANT *p)
1266 {
1267 HTMLElement *This = impl_from_IHTMLElement(iface);
1268 FIXME("(%p)->(%p)\n", This, p);
1269 return E_NOTIMPL;
1270 }
1271
1272 static HRESULT WINAPI HTMLElement_toString(IHTMLElement *iface, BSTR *String)
1273 {
1274 HTMLElement *This = impl_from_IHTMLElement(iface);
1275 FIXME("(%p)->(%p)\n", This, String);
1276 return E_NOTIMPL;
1277 }
1278
1279 static HRESULT WINAPI HTMLElement_put_onbeforeupdate(IHTMLElement *iface, VARIANT v)
1280 {
1281 HTMLElement *This = impl_from_IHTMLElement(iface);
1282 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1283 return E_NOTIMPL;
1284 }
1285
1286 static HRESULT WINAPI HTMLElement_get_onbeforeupdate(IHTMLElement *iface, VARIANT *p)
1287 {
1288 HTMLElement *This = impl_from_IHTMLElement(iface);
1289 FIXME("(%p)->(%p)\n", This, p);
1290 return E_NOTIMPL;
1291 }
1292
1293 static HRESULT WINAPI HTMLElement_put_onafterupdate(IHTMLElement *iface, VARIANT v)
1294 {
1295 HTMLElement *This = impl_from_IHTMLElement(iface);
1296 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1297 return E_NOTIMPL;
1298 }
1299
1300 static HRESULT WINAPI HTMLElement_get_onafterupdate(IHTMLElement *iface, VARIANT *p)
1301 {
1302 HTMLElement *This = impl_from_IHTMLElement(iface);
1303 FIXME("(%p)->(%p)\n", This, p);
1304 return E_NOTIMPL;
1305 }
1306
1307 static HRESULT WINAPI HTMLElement_put_onerrorupdate(IHTMLElement *iface, VARIANT v)
1308 {
1309 HTMLElement *This = impl_from_IHTMLElement(iface);
1310 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1311 return E_NOTIMPL;
1312 }
1313
1314 static HRESULT WINAPI HTMLElement_get_onerrorupdate(IHTMLElement *iface, VARIANT *p)
1315 {
1316 HTMLElement *This = impl_from_IHTMLElement(iface);
1317 FIXME("(%p)->(%p)\n", This, p);
1318 return E_NOTIMPL;
1319 }
1320
1321 static HRESULT WINAPI HTMLElement_put_onrowexit(IHTMLElement *iface, VARIANT v)
1322 {
1323 HTMLElement *This = impl_from_IHTMLElement(iface);
1324 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1325 return E_NOTIMPL;
1326 }
1327
1328 static HRESULT WINAPI HTMLElement_get_onrowexit(IHTMLElement *iface, VARIANT *p)
1329 {
1330 HTMLElement *This = impl_from_IHTMLElement(iface);
1331 FIXME("(%p)->(%p)\n", This, p);
1332 return E_NOTIMPL;
1333 }
1334
1335 static HRESULT WINAPI HTMLElement_put_onrowenter(IHTMLElement *iface, VARIANT v)
1336 {
1337 HTMLElement *This = impl_from_IHTMLElement(iface);
1338 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1339 return E_NOTIMPL;
1340 }
1341
1342 static HRESULT WINAPI HTMLElement_get_onrowenter(IHTMLElement *iface, VARIANT *p)
1343 {
1344 HTMLElement *This = impl_from_IHTMLElement(iface);
1345 FIXME("(%p)->(%p)\n", This, p);
1346 return E_NOTIMPL;
1347 }
1348
1349 static HRESULT WINAPI HTMLElement_put_ondatasetchanged(IHTMLElement *iface, VARIANT v)
1350 {
1351 HTMLElement *This = impl_from_IHTMLElement(iface);
1352 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1353 return E_NOTIMPL;
1354 }
1355
1356 static HRESULT WINAPI HTMLElement_get_ondatasetchanged(IHTMLElement *iface, VARIANT *p)
1357 {
1358 HTMLElement *This = impl_from_IHTMLElement(iface);
1359 FIXME("(%p)->(%p)\n", This, p);
1360 return E_NOTIMPL;
1361 }
1362
1363 static HRESULT WINAPI HTMLElement_put_ondataavailable(IHTMLElement *iface, VARIANT v)
1364 {
1365 HTMLElement *This = impl_from_IHTMLElement(iface);
1366
1367 FIXME("(%p)->(%s) semi-stub\n", This, debugstr_variant(&v));
1368
1369 return set_node_event(&This->node, EVENTID_DATAAVAILABLE, &v);
1370 }
1371
1372 static HRESULT WINAPI HTMLElement_get_ondataavailable(IHTMLElement *iface, VARIANT *p)
1373 {
1374 HTMLElement *This = impl_from_IHTMLElement(iface);
1375
1376 TRACE("(%p)->(%p)\n", This, p);
1377
1378 return get_node_event(&This->node, EVENTID_DATAAVAILABLE, p);
1379 }
1380
1381 static HRESULT WINAPI HTMLElement_put_ondatasetcomplete(IHTMLElement *iface, VARIANT v)
1382 {
1383 HTMLElement *This = impl_from_IHTMLElement(iface);
1384 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1385 return E_NOTIMPL;
1386 }
1387
1388 static HRESULT WINAPI HTMLElement_get_ondatasetcomplete(IHTMLElement *iface, VARIANT *p)
1389 {
1390 HTMLElement *This = impl_from_IHTMLElement(iface);
1391 FIXME("(%p)->(%p)\n", This, p);
1392 return E_NOTIMPL;
1393 }
1394
1395 static HRESULT WINAPI HTMLElement_put_onfilterchange(IHTMLElement *iface, VARIANT v)
1396 {
1397 HTMLElement *This = impl_from_IHTMLElement(iface);
1398 FIXME("(%p)->(%s)\n", This, debugstr_variant(&v));
1399 return E_NOTIMPL;
1400 }
1401
1402 static HRESULT WINAPI HTMLElement_get_onfilterchange(IHTMLElement *iface, VARIANT *p)
1403 {
1404 HTMLElement *This = impl_from_IHTMLElement(iface);
1405 FIXME("(%p)->(%p)\n", This, p);
1406 return E_NOTIMPL;
1407 }
1408
1409 static HRESULT WINAPI HTMLElement_get_children(IHTMLElement *iface, IDispatch **p)
1410 {
1411 HTMLElement *This = impl_from_IHTMLElement(iface);
1412 nsIDOMNodeList *nsnode_list;
1413 nsresult nsres;
1414
1415 TRACE("(%p)->(%p)\n", This, p);
1416
1417 nsres = nsIDOMNode_GetChildNodes(This->node.nsnode, &nsnode_list);
1418 if(NS_FAILED(nsres)) {
1419 ERR("GetChildNodes failed: %08x\n", nsres);
1420 return E_FAIL;
1421 }
1422
1423 *p = (IDispatch*)create_collection_from_nodelist(This->node.doc, nsnode_list);
1424
1425 nsIDOMNodeList_Release(nsnode_list);
1426 return S_OK;
1427 }
1428
1429 static HRESULT WINAPI HTMLElement_get_all(IHTMLElement *iface, IDispatch **p)
1430 {
1431 HTMLElement *This = impl_from_IHTMLElement(iface);
1432
1433 TRACE("(%p)->(%p)\n", This, p);
1434
1435 *p = (IDispatch*)create_all_collection(&This->node, FALSE);
1436 return S_OK;
1437 }
1438
1439 static const IHTMLElementVtbl HTMLElementVtbl = {
1440 HTMLElement_QueryInterface,
1441 HTMLElement_AddRef,
1442 HTMLElement_Release,
1443 HTMLElement_GetTypeInfoCount,
1444 HTMLElement_GetTypeInfo,
1445 HTMLElement_GetIDsOfNames,
1446 HTMLElement_Invoke,
1447 HTMLElement_setAttribute,
1448 HTMLElement_getAttribute,
1449 HTMLElement_removeAttribute,
1450 HTMLElement_put_className,
1451 HTMLElement_get_className,
1452 HTMLElement_put_id,
1453 HTMLElement_get_id,
1454 HTMLElement_get_tagName,
1455 HTMLElement_get_parentElement,
1456 HTMLElement_get_style,
1457 HTMLElement_put_onhelp,
1458 HTMLElement_get_onhelp,
1459 HTMLElement_put_onclick,
1460 HTMLElement_get_onclick,
1461 HTMLElement_put_ondblclick,
1462 HTMLElement_get_ondblclick,
1463 HTMLElement_put_onkeydown,
1464 HTMLElement_get_onkeydown,
1465 HTMLElement_put_onkeyup,
1466 HTMLElement_get_onkeyup,
1467 HTMLElement_put_onkeypress,
1468 HTMLElement_get_onkeypress,
1469 HTMLElement_put_onmouseout,
1470 HTMLElement_get_onmouseout,
1471 HTMLElement_put_onmouseover,
1472 HTMLElement_get_onmouseover,
1473 HTMLElement_put_onmousemove,
1474 HTMLElement_get_onmousemove,
1475 HTMLElement_put_onmousedown,
1476 HTMLElement_get_onmousedown,
1477 HTMLElement_put_onmouseup,
1478 HTMLElement_get_onmouseup,
1479 HTMLElement_get_document,
1480 HTMLElement_put_title,
1481 HTMLElement_get_title,
1482 HTMLElement_put_language,
1483 HTMLElement_get_language,
1484 HTMLElement_put_onselectstart,
1485 HTMLElement_get_onselectstart,
1486 HTMLElement_scrollIntoView,
1487 HTMLElement_contains,
1488 HTMLElement_get_sourceIndex,
1489 HTMLElement_get_recordNumber,
1490 HTMLElement_put_lang,
1491 HTMLElement_get_lang,
1492 HTMLElement_get_offsetLeft,
1493 HTMLElement_get_offsetTop,
1494 HTMLElement_get_offsetWidth,
1495 HTMLElement_get_offsetHeight,
1496 HTMLElement_get_offsetParent,
1497 HTMLElement_put_innerHTML,
1498 HTMLElement_get_innerHTML,
1499 HTMLElement_put_innerText,
1500 HTMLElement_get_innerText,
1501 HTMLElement_put_outerHTML,
1502 HTMLElement_get_outerHTML,
1503 HTMLElement_put_outerText,
1504 HTMLElement_get_outerText,
1505 HTMLElement_insertAdjacentHTML,
1506 HTMLElement_insertAdjacentText,
1507 HTMLElement_get_parentTextEdit,
1508 HTMLElement_get_isTextEdit,
1509 HTMLElement_click,
1510 HTMLElement_get_filters,
1511 HTMLElement_put_ondragstart,
1512 HTMLElement_get_ondragstart,
1513 HTMLElement_toString,
1514 HTMLElement_put_onbeforeupdate,
1515 HTMLElement_get_onbeforeupdate,
1516 HTMLElement_put_onafterupdate,
1517 HTMLElement_get_onafterupdate,
1518 HTMLElement_put_onerrorupdate,
1519 HTMLElement_get_onerrorupdate,
1520 HTMLElement_put_onrowexit,
1521 HTMLElement_get_onrowexit,
1522 HTMLElement_put_onrowenter,
1523 HTMLElement_get_onrowenter,
1524 HTMLElement_put_ondatasetchanged,
1525 HTMLElement_get_ondatasetchanged,
1526 HTMLElement_put_ondataavailable,
1527 HTMLElement_get_ondataavailable,
1528 HTMLElement_put_ondatasetcomplete,
1529 HTMLElement_get_ondatasetcomplete,
1530 HTMLElement_put_onfilterchange,
1531 HTMLElement_get_onfilterchange,
1532 HTMLElement_get_children,
1533 HTMLElement_get_all
1534 };
1535
1536 HTMLElement *unsafe_impl_from_IHTMLElement(IHTMLElement *iface)
1537 {
1538 return iface->lpVtbl == &HTMLElementVtbl ? impl_from_IHTMLElement(iface) : NULL;
1539 }
1540
1541 static inline HTMLElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
1542 {
1543 return CONTAINING_RECORD(iface, HTMLElement, node);
1544 }
1545
1546 HRESULT HTMLElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
1547 {
1548 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1549
1550 *ppv = NULL;
1551
1552 if(IsEqualGUID(&IID_IUnknown, riid)) {
1553 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1554 *ppv = &This->IHTMLElement_iface;
1555 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
1556 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
1557 *ppv = &This->IHTMLElement_iface;
1558 }else if(IsEqualGUID(&IID_IHTMLElement, riid)) {
1559 TRACE("(%p)->(IID_IHTMLElement %p)\n", This, ppv);
1560 *ppv = &This->IHTMLElement_iface;
1561 }else if(IsEqualGUID(&IID_IHTMLElement2, riid)) {
1562 TRACE("(%p)->(IID_IHTMLElement2 %p)\n", This, ppv);
1563 *ppv = &This->IHTMLElement2_iface;
1564 }else if(IsEqualGUID(&IID_IHTMLElement3, riid)) {
1565 TRACE("(%p)->(IID_IHTMLElement3 %p)\n", This, ppv);
1566 *ppv = &This->IHTMLElement3_iface;
1567 }else if(IsEqualGUID(&IID_IHTMLElement4, riid)) {
1568 TRACE("(%p)->(IID_IHTMLElement4 %p)\n", This, ppv);
1569 *ppv = &This->IHTMLElement4_iface;
1570 }else if(IsEqualGUID(&IID_IConnectionPointContainer, riid)) {
1571 TRACE("(%p)->(IID_IConnectionPointContainer %p)\n", This, ppv);
1572 *ppv = &This->cp_container.IConnectionPointContainer_iface;
1573 }
1574
1575 if(*ppv) {
1576 IHTMLElement_AddRef(&This->IHTMLElement_iface);
1577 return S_OK;
1578 }
1579
1580 return HTMLDOMNode_QI(&This->node, riid, ppv);
1581 }
1582
1583 void HTMLElement_destructor(HTMLDOMNode *iface)
1584 {
1585 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1586
1587 ConnectionPointContainer_Destroy(&This->cp_container);
1588
1589 if(This->style) {
1590 This->style->elem = NULL;
1591 IHTMLStyle_Release(&This->style->IHTMLStyle_iface);
1592 }
1593 if(This->runtime_style) {
1594 This->runtime_style->elem = NULL;
1595 IHTMLStyle_Release(&This->runtime_style->IHTMLStyle_iface);
1596 }
1597 if(This->attrs) {
1598 HTMLDOMAttribute *attr;
1599
1600 LIST_FOR_EACH_ENTRY(attr, &This->attrs->attrs, HTMLDOMAttribute, entry)
1601 attr->elem = NULL;
1602
1603 This->attrs->elem = NULL;
1604 IHTMLAttributeCollection_Release(&This->attrs->IHTMLAttributeCollection_iface);
1605 }
1606
1607 heap_free(This->filter);
1608
1609 HTMLDOMNode_destructor(&This->node);
1610 }
1611
1612 HRESULT HTMLElement_clone(HTMLDOMNode *iface, nsIDOMNode *nsnode, HTMLDOMNode **ret)
1613 {
1614 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1615 HTMLElement *new_elem;
1616 HRESULT hres;
1617
1618 hres = HTMLElement_Create(This->node.doc, nsnode, FALSE, &new_elem);
1619 if(FAILED(hres))
1620 return hres;
1621
1622 if(This->filter) {
1623 new_elem->filter = heap_strdupW(This->filter);
1624 if(!new_elem->filter) {
1625 IHTMLElement_Release(&This->IHTMLElement_iface);
1626 return E_OUTOFMEMORY;
1627 }
1628 }
1629
1630 *ret = &new_elem->node;
1631 return S_OK;
1632 }
1633
1634 HRESULT HTMLElement_handle_event(HTMLDOMNode *iface, DWORD eid, nsIDOMEvent *event, BOOL *prevent_default)
1635 {
1636 HTMLElement *This = impl_from_HTMLDOMNode(iface);
1637
1638 switch(eid) {
1639 case EVENTID_KEYDOWN: {
1640 nsIDOMKeyEvent *key_event;
1641 nsresult nsres;
1642
1643 nsres = nsIDOMEvent_QueryInterface(event, &IID_nsIDOMKeyEvent, (void**)&key_event);
1644 if(NS_SUCCEEDED(nsres)) {
1645 UINT32 code = 0;
1646
1647 nsIDOMKeyEvent_GetKeyCode(key_event, &code);
1648
1649 switch(code) {
1650 case VK_F1: /* DOM_VK_F1 */
1651 TRACE("F1 pressed\n");
1652 fire_event(This->node.doc, EVENTID_HELP, TRUE, This->node.nsnode, NULL, NULL);
1653 *prevent_default = TRUE;
1654 }
1655
1656 nsIDOMKeyEvent_Release(key_event);
1657 }
1658 }
1659 }
1660
1661 return S_OK;
1662 }
1663
1664 cp_static_data_t HTMLElementEvents2_data = { HTMLElementEvents2_tid, NULL /* FIXME */, TRUE };
1665
1666 const cpc_entry_t HTMLElement_cpc[] = {
1667 HTMLELEMENT_CPC,
1668 {NULL}
1669 };
1670
1671 static const NodeImplVtbl HTMLElementImplVtbl = {
1672 HTMLElement_QI,
1673 HTMLElement_destructor,
1674 HTMLElement_cpc,
1675 HTMLElement_clone,
1676 HTMLElement_handle_event,
1677 HTMLElement_get_attr_col
1678 };
1679
1680 static inline HTMLElement *impl_from_DispatchEx(DispatchEx *iface)
1681 {
1682 return CONTAINING_RECORD(iface, HTMLElement, node.dispex);
1683 }
1684
1685 static HRESULT HTMLElement_get_dispid(DispatchEx *dispex, BSTR name,
1686 DWORD grfdex, DISPID *pid)
1687 {
1688 HTMLElement *This = impl_from_DispatchEx(dispex);
1689
1690 if(This->node.vtbl->get_dispid)
1691 return This->node.vtbl->get_dispid(&This->node, name, grfdex, pid);
1692
1693 return DISP_E_UNKNOWNNAME;
1694 }
1695
1696 static HRESULT HTMLElement_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
1697 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei,
1698 IServiceProvider *caller)
1699 {
1700 HTMLElement *This = impl_from_DispatchEx(dispex);
1701
1702 if(This->node.vtbl->invoke)
1703 return This->node.vtbl->invoke(&This->node, id, lcid, flags,
1704 params, res, ei, caller);
1705
1706 ERR("(%p): element has no invoke method\n", This);
1707 return E_NOTIMPL;
1708 }
1709
1710 static HRESULT HTMLElement_populate_props(DispatchEx *dispex)
1711 {
1712 HTMLElement *This = impl_from_DispatchEx(dispex);
1713 nsIDOMMozNamedAttrMap *attrs;
1714 nsIDOMAttr *attr;
1715 nsAString nsstr;
1716 const PRUnichar *str;
1717 BSTR name;
1718 VARIANT value;
1719 unsigned i;
1720 UINT32 len;
1721 DISPID id;
1722 nsresult nsres;
1723 HRESULT hres;
1724
1725 if(!This->nselem)
1726 return S_FALSE;
1727
1728 nsres = nsIDOMHTMLElement_GetAttributes(This->nselem, &attrs);
1729 if(NS_FAILED(nsres))
1730 return E_FAIL;
1731
1732 nsres = nsIDOMMozNamedAttrMap_GetLength(attrs, &len);
1733 if(NS_FAILED(nsres)) {
1734 nsIDOMMozNamedAttrMap_Release(attrs);
1735 return E_FAIL;
1736 }
1737
1738 nsAString_Init(&nsstr, NULL);
1739 for(i=0; i<len; i++) {
1740 nsres = nsIDOMMozNamedAttrMap_Item(attrs, i, &attr);
1741 if(NS_FAILED(nsres))
1742 continue;
1743
1744 nsres = nsIDOMAttr_GetNodeName(attr, &nsstr);
1745 if(NS_FAILED(nsres)) {
1746 nsIDOMAttr_Release(attr);
1747 continue;
1748 }
1749
1750 nsAString_GetData(&nsstr, &str);
1751 name = SysAllocString(str);
1752 if(!name) {
1753 nsIDOMAttr_Release(attr);
1754 continue;
1755 }
1756
1757 hres = IDispatchEx_GetDispID(&dispex->IDispatchEx_iface, name, fdexNameCaseInsensitive, &id);
1758 if(hres != DISP_E_UNKNOWNNAME) {
1759 nsIDOMAttr_Release(attr);
1760 SysFreeString(name);
1761 continue;
1762 }
1763
1764 nsres = nsIDOMAttr_GetNodeValue(attr, &nsstr);
1765 nsIDOMAttr_Release(attr);
1766 if(NS_FAILED(nsres)) {
1767 SysFreeString(name);
1768 continue;
1769 }
1770
1771 nsAString_GetData(&nsstr, &str);
1772 V_VT(&value) = VT_BSTR;
1773 if(*str) {
1774 V_BSTR(&value) = SysAllocString(str);
1775 if(!V_BSTR(&value)) {
1776 SysFreeString(name);
1777 continue;
1778 }
1779 } else
1780 V_BSTR(&value) = NULL;
1781
1782 IHTMLElement_setAttribute(&This->IHTMLElement_iface, name, value, 0);
1783 SysFreeString(name);
1784 VariantClear(&value);
1785 }
1786 nsAString_Finish(&nsstr);
1787
1788 nsIDOMMozNamedAttrMap_Release(attrs);
1789 return S_OK;
1790 }
1791
1792 static const tid_t HTMLElement_iface_tids[] = {
1793 HTMLELEMENT_TIDS,
1794 0
1795 };
1796
1797 static dispex_static_data_vtbl_t HTMLElement_dispex_vtbl = {
1798 NULL,
1799 HTMLElement_get_dispid,
1800 HTMLElement_invoke,
1801 HTMLElement_populate_props
1802 };
1803
1804 static dispex_static_data_t HTMLElement_dispex = {
1805 &HTMLElement_dispex_vtbl,
1806 DispHTMLUnknownElement_tid,
1807 NULL,
1808 HTMLElement_iface_tids
1809 };
1810
1811 void HTMLElement_Init(HTMLElement *This, HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, dispex_static_data_t *dispex_data)
1812 {
1813 This->IHTMLElement_iface.lpVtbl = &HTMLElementVtbl;
1814
1815 HTMLElement2_Init(This);
1816 HTMLElement3_Init(This);
1817
1818 if(dispex_data && !dispex_data->vtbl)
1819 dispex_data->vtbl = &HTMLElement_dispex_vtbl;
1820 init_dispex(&This->node.dispex, (IUnknown*)&This->IHTMLElement_iface,
1821 dispex_data ? dispex_data : &HTMLElement_dispex);
1822
1823 if(nselem) {
1824 HTMLDOMNode_Init(doc, &This->node, (nsIDOMNode*)nselem);
1825
1826 /* No AddRef, share reference with HTMLDOMNode */
1827 assert((nsIDOMNode*)nselem == This->node.nsnode);
1828 This->nselem = nselem;
1829 }
1830
1831 This->node.cp_container = &This->cp_container;
1832 ConnectionPointContainer_Init(&This->cp_container, (IUnknown*)&This->IHTMLElement_iface, This->node.vtbl->cpc_entries);
1833 }
1834
1835 HRESULT HTMLElement_Create(HTMLDocumentNode *doc, nsIDOMNode *nsnode, BOOL use_generic, HTMLElement **ret)
1836 {
1837 nsIDOMHTMLElement *nselem;
1838 nsAString class_name_str;
1839 const PRUnichar *class_name;
1840 const tag_desc_t *tag;
1841 HTMLElement *elem;
1842 nsresult nsres;
1843 HRESULT hres;
1844
1845 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMHTMLElement, (void**)&nselem);
1846 if(NS_FAILED(nsres))
1847 return E_FAIL;
1848
1849 nsAString_Init(&class_name_str, NULL);
1850 nsIDOMHTMLElement_GetTagName(nselem, &class_name_str);
1851
1852 nsAString_GetData(&class_name_str, &class_name);
1853
1854 tag = get_tag_desc(class_name);
1855 if(tag) {
1856 hres = tag->constructor(doc, nselem, &elem);
1857 }else if(use_generic) {
1858 hres = HTMLGenericElement_Create(doc, nselem, &elem);
1859 }else {
1860 elem = heap_alloc_zero(sizeof(HTMLElement));
1861 if(elem) {
1862 elem->node.vtbl = &HTMLElementImplVtbl;
1863 HTMLElement_Init(elem, doc, nselem, &HTMLElement_dispex);
1864 hres = S_OK;
1865 }else {
1866 hres = E_OUTOFMEMORY;
1867 }
1868 }
1869
1870 TRACE("%s ret %p\n", debugstr_w(class_name), elem);
1871
1872 nsIDOMHTMLElement_Release(nselem);
1873 nsAString_Finish(&class_name_str);
1874 if(FAILED(hres))
1875 return hres;
1876
1877 *ret = elem;
1878 return S_OK;
1879 }
1880
1881 HRESULT get_elem(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **ret)
1882 {
1883 HTMLDOMNode *node;
1884 HRESULT hres;
1885
1886 hres = get_node(doc, (nsIDOMNode*)nselem, TRUE, &node);
1887 if(FAILED(hres))
1888 return hres;
1889
1890 *ret = impl_from_HTMLDOMNode(node);
1891 return S_OK;
1892 }
1893
1894 /* interface IHTMLFiltersCollection */
1895 static HRESULT WINAPI HTMLFiltersCollection_QueryInterface(IHTMLFiltersCollection *iface, REFIID riid, void **ppv)
1896 {
1897 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1898
1899 TRACE("%p %s %p\n", This, debugstr_guid( riid ), ppv );
1900
1901 if(IsEqualGUID(&IID_IUnknown, riid)) {
1902 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
1903 *ppv = &This->IHTMLFiltersCollection_iface;
1904 }else if(IsEqualGUID(&IID_IHTMLFiltersCollection, riid)) {
1905 TRACE("(%p)->(IID_IHTMLFiltersCollection %p)\n", This, ppv);
1906 *ppv = &This->IHTMLFiltersCollection_iface;
1907 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
1908 return *ppv ? S_OK : E_NOINTERFACE;
1909 }
1910
1911 if(*ppv) {
1912 IUnknown_AddRef((IUnknown*)*ppv);
1913 return S_OK;
1914 }
1915
1916 FIXME("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
1917 return E_NOINTERFACE;
1918 }
1919
1920 static ULONG WINAPI HTMLFiltersCollection_AddRef(IHTMLFiltersCollection *iface)
1921 {
1922 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1923 LONG ref = InterlockedIncrement(&This->ref);
1924
1925 TRACE("(%p) ref=%d\n", This, ref);
1926
1927 return ref;
1928 }
1929
1930 static ULONG WINAPI HTMLFiltersCollection_Release(IHTMLFiltersCollection *iface)
1931 {
1932 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1933 LONG ref = InterlockedDecrement(&This->ref);
1934
1935 TRACE("(%p) ref=%d\n", This, ref);
1936
1937 if(!ref)
1938 {
1939 heap_free(This);
1940 }
1941
1942 return ref;
1943 }
1944
1945 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfoCount(IHTMLFiltersCollection *iface, UINT *pctinfo)
1946 {
1947 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1948 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
1949 }
1950
1951 static HRESULT WINAPI HTMLFiltersCollection_GetTypeInfo(IHTMLFiltersCollection *iface,
1952 UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
1953 {
1954 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1955 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
1956 }
1957
1958 static HRESULT WINAPI HTMLFiltersCollection_GetIDsOfNames(IHTMLFiltersCollection *iface,
1959 REFIID riid, LPOLESTR *rgszNames, UINT cNames,
1960 LCID lcid, DISPID *rgDispId)
1961 {
1962 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1963 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
1964 lcid, rgDispId);
1965 }
1966
1967 static HRESULT WINAPI HTMLFiltersCollection_Invoke(IHTMLFiltersCollection *iface, DISPID dispIdMember, REFIID riid,
1968 LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult,
1969 EXCEPINFO *pExcepInfo, UINT *puArgErr)
1970 {
1971 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1972 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
1973 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
1974 }
1975
1976 static HRESULT WINAPI HTMLFiltersCollection_get_length(IHTMLFiltersCollection *iface, LONG *p)
1977 {
1978 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1979
1980 if(!p)
1981 return E_POINTER;
1982
1983 FIXME("(%p)->(%p) Always returning 0\n", This, p);
1984 *p = 0;
1985
1986 return S_OK;
1987 }
1988
1989 static HRESULT WINAPI HTMLFiltersCollection_get__newEnum(IHTMLFiltersCollection *iface, IUnknown **p)
1990 {
1991 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1992 FIXME("(%p)->(%p)\n", This, p);
1993 return E_NOTIMPL;
1994 }
1995
1996 static HRESULT WINAPI HTMLFiltersCollection_item(IHTMLFiltersCollection *iface, VARIANT *pvarIndex, VARIANT *pvarResult)
1997 {
1998 HTMLFiltersCollection *This = impl_from_IHTMLFiltersCollection(iface);
1999 FIXME("(%p)->(%p, %p)\n", This, pvarIndex, pvarResult);
2000 return E_NOTIMPL;
2001 }
2002
2003 static const IHTMLFiltersCollectionVtbl HTMLFiltersCollectionVtbl = {
2004 HTMLFiltersCollection_QueryInterface,
2005 HTMLFiltersCollection_AddRef,
2006 HTMLFiltersCollection_Release,
2007 HTMLFiltersCollection_GetTypeInfoCount,
2008 HTMLFiltersCollection_GetTypeInfo,
2009 HTMLFiltersCollection_GetIDsOfNames,
2010 HTMLFiltersCollection_Invoke,
2011 HTMLFiltersCollection_get_length,
2012 HTMLFiltersCollection_get__newEnum,
2013 HTMLFiltersCollection_item
2014 };
2015
2016 static HRESULT HTMLFiltersCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
2017 {
2018 WCHAR *ptr;
2019 int idx = 0;
2020
2021 for(ptr = name; *ptr && isdigitW(*ptr); ptr++)
2022 idx = idx*10 + (*ptr-'0');
2023 if(*ptr)
2024 return DISP_E_UNKNOWNNAME;
2025
2026 *dispid = MSHTML_DISPID_CUSTOM_MIN + idx;
2027 TRACE("ret %x\n", *dispid);
2028 return S_OK;
2029 }
2030
2031 static HRESULT HTMLFiltersCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid, WORD flags, DISPPARAMS *params,
2032 VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2033 {
2034 TRACE("(%p)->(%x %x %x %p %p %p)\n", dispex, id, lcid, flags, params, res, ei);
2035
2036 V_VT(res) = VT_DISPATCH;
2037 V_DISPATCH(res) = NULL;
2038
2039 FIXME("always returning NULL\n");
2040
2041 return S_OK;
2042 }
2043
2044 static const dispex_static_data_vtbl_t HTMLFiltersCollection_dispex_vtbl = {
2045 NULL,
2046 HTMLFiltersCollection_get_dispid,
2047 HTMLFiltersCollection_invoke,
2048 NULL
2049 };
2050
2051 static const tid_t HTMLFiltersCollection_iface_tids[] = {
2052 IHTMLFiltersCollection_tid,
2053 0
2054 };
2055 static dispex_static_data_t HTMLFiltersCollection_dispex = {
2056 &HTMLFiltersCollection_dispex_vtbl,
2057 IHTMLFiltersCollection_tid,
2058 NULL,
2059 HTMLFiltersCollection_iface_tids
2060 };
2061
2062 static IHTMLFiltersCollection *HTMLFiltersCollection_Create(void)
2063 {
2064 HTMLFiltersCollection *ret = heap_alloc(sizeof(HTMLFiltersCollection));
2065
2066 ret->IHTMLFiltersCollection_iface.lpVtbl = &HTMLFiltersCollectionVtbl;
2067 ret->ref = 1;
2068
2069 init_dispex(&ret->dispex, (IUnknown*)&ret->IHTMLFiltersCollection_iface,
2070 &HTMLFiltersCollection_dispex);
2071
2072 return &ret->IHTMLFiltersCollection_iface;
2073 }
2074
2075 /* interface IHTMLAttributeCollection */
2076 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection(IHTMLAttributeCollection *iface)
2077 {
2078 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection_iface);
2079 }
2080
2081 static HRESULT WINAPI HTMLAttributeCollection_QueryInterface(IHTMLAttributeCollection *iface, REFIID riid, void **ppv)
2082 {
2083 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2084
2085 *ppv = NULL;
2086
2087 if(IsEqualGUID(&IID_IUnknown, riid)) {
2088 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
2089 *ppv = &This->IHTMLAttributeCollection_iface;
2090 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection, riid)) {
2091 TRACE("(%p)->(IID_IHTMLAttributeCollection %p)\n", This, ppv);
2092 *ppv = &This->IHTMLAttributeCollection_iface;
2093 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection2, riid)) {
2094 TRACE("(%p)->(IID_IHTMLAttributeCollection2 %p)\n", This, ppv);
2095 *ppv = &This->IHTMLAttributeCollection2_iface;
2096 }else if(IsEqualGUID(&IID_IHTMLAttributeCollection3, riid)) {
2097 TRACE("(%p)->(IID_IHTMLAttributeCollection3 %p)\n", This, ppv);
2098 *ppv = &This->IHTMLAttributeCollection3_iface;
2099 }else if(dispex_query_interface(&This->dispex, riid, ppv)) {
2100 return *ppv ? S_OK : E_NOINTERFACE;
2101 }
2102
2103 if(*ppv) {
2104 IUnknown_AddRef((IUnknown*)*ppv);
2105 return S_OK;
2106 }
2107
2108 WARN("(%p)->(%s %p)\n", This, debugstr_guid(riid), ppv);
2109 return E_NOINTERFACE;
2110 }
2111
2112 static ULONG WINAPI HTMLAttributeCollection_AddRef(IHTMLAttributeCollection *iface)
2113 {
2114 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2115 LONG ref = InterlockedIncrement(&This->ref);
2116
2117 TRACE("(%p) ref=%d\n", This, ref);
2118
2119 return ref;
2120 }
2121
2122 static ULONG WINAPI HTMLAttributeCollection_Release(IHTMLAttributeCollection *iface)
2123 {
2124 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2125 LONG ref = InterlockedDecrement(&This->ref);
2126
2127 TRACE("(%p) ref=%d\n", This, ref);
2128
2129 if(!ref) {
2130 while(!list_empty(&This->attrs)) {
2131 HTMLDOMAttribute *attr = LIST_ENTRY(list_head(&This->attrs), HTMLDOMAttribute, entry);
2132
2133 list_remove(&attr->entry);
2134 attr->elem = NULL;
2135 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2136 }
2137
2138 heap_free(This);
2139 }
2140
2141 return ref;
2142 }
2143
2144 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfoCount(IHTMLAttributeCollection *iface, UINT *pctinfo)
2145 {
2146 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2147 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2148 }
2149
2150 static HRESULT WINAPI HTMLAttributeCollection_GetTypeInfo(IHTMLAttributeCollection *iface, UINT iTInfo,
2151 LCID lcid, ITypeInfo **ppTInfo)
2152 {
2153 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2154 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2155 }
2156
2157 static HRESULT WINAPI HTMLAttributeCollection_GetIDsOfNames(IHTMLAttributeCollection *iface, REFIID riid,
2158 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2159 {
2160 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2161 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2162 lcid, rgDispId);
2163 }
2164
2165 static HRESULT WINAPI HTMLAttributeCollection_Invoke(IHTMLAttributeCollection *iface, DISPID dispIdMember,
2166 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2167 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2168 {
2169 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2170 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2171 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2172 }
2173
2174 static HRESULT get_attr_dispid_by_idx(HTMLAttributeCollection *This, LONG *idx, DISPID *dispid)
2175 {
2176 IDispatchEx *dispex = &This->elem->node.dispex.IDispatchEx_iface;
2177 DISPID id = DISPID_STARTENUM;
2178 LONG len = -1;
2179 HRESULT hres;
2180
2181 FIXME("filter non-enumerable attributes out\n");
2182
2183 while(1) {
2184 hres = IDispatchEx_GetNextDispID(dispex, fdexEnumAll, id, &id);
2185 if(FAILED(hres))
2186 return hres;
2187 else if(hres == S_FALSE)
2188 break;
2189
2190 len++;
2191 if(len == *idx)
2192 break;
2193 }
2194
2195 if(dispid) {
2196 *dispid = id;
2197 return *idx==len ? S_OK : DISP_E_UNKNOWNNAME;
2198 }
2199
2200 *idx = len+1;
2201 return S_OK;
2202 }
2203
2204 static inline HRESULT get_attr_dispid_by_name(HTMLAttributeCollection *This, BSTR name, DISPID *id)
2205 {
2206 HRESULT hres;
2207
2208 if(name[0]>='0' && name[0]<='9') {
2209 WCHAR *end_ptr;
2210 LONG idx;
2211
2212 idx = strtoulW(name, &end_ptr, 10);
2213 if(!*end_ptr) {
2214 hres = get_attr_dispid_by_idx(This, &idx, id);
2215 if(SUCCEEDED(hres))
2216 return hres;
2217 }
2218 }
2219
2220 if(!This->elem) {
2221 WARN("NULL elem\n");
2222 return E_UNEXPECTED;
2223 }
2224
2225 hres = IDispatchEx_GetDispID(&This->elem->node.dispex.IDispatchEx_iface,
2226 name, fdexNameCaseInsensitive, id);
2227 return hres;
2228 }
2229
2230 static inline HRESULT get_domattr(HTMLAttributeCollection *This, DISPID id, LONG *list_pos, HTMLDOMAttribute **attr)
2231 {
2232 HTMLDOMAttribute *iter;
2233 LONG pos = 0;
2234 HRESULT hres;
2235
2236 *attr = NULL;
2237 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2238 if(iter->dispid == id) {
2239 *attr = iter;
2240 break;
2241 }
2242 pos++;
2243 }
2244
2245 if(!*attr) {
2246 if(!This->elem) {
2247 WARN("NULL elem\n");
2248 return E_UNEXPECTED;
2249 }
2250
2251 hres = HTMLDOMAttribute_Create(NULL, This->elem, id, attr);
2252 if(FAILED(hres))
2253 return hres;
2254 }
2255
2256 IHTMLDOMAttribute_AddRef(&(*attr)->IHTMLDOMAttribute_iface);
2257 if(list_pos)
2258 *list_pos = pos;
2259 return S_OK;
2260 }
2261
2262 static HRESULT WINAPI HTMLAttributeCollection_get_length(IHTMLAttributeCollection *iface, LONG *p)
2263 {
2264 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2265 HRESULT hres;
2266
2267 TRACE("(%p)->(%p)\n", This, p);
2268
2269 *p = -1;
2270 hres = get_attr_dispid_by_idx(This, p, NULL);
2271 return hres;
2272 }
2273
2274 static HRESULT WINAPI HTMLAttributeCollection__newEnum(IHTMLAttributeCollection *iface, IUnknown **p)
2275 {
2276 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2277 FIXME("(%p)->(%p)\n", This, p);
2278 return E_NOTIMPL;
2279 }
2280
2281 static HRESULT WINAPI HTMLAttributeCollection_item(IHTMLAttributeCollection *iface, VARIANT *name, IDispatch **ppItem)
2282 {
2283 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection(iface);
2284 HTMLDOMAttribute *attr;
2285 DISPID id;
2286 HRESULT hres;
2287
2288 TRACE("(%p)->(%s %p)\n", This, debugstr_variant(name), ppItem);
2289
2290 switch(V_VT(name)) {
2291 case VT_I4:
2292 hres = get_attr_dispid_by_idx(This, &V_I4(name), &id);
2293 break;
2294 case VT_BSTR:
2295 hres = get_attr_dispid_by_name(This, V_BSTR(name), &id);
2296 break;
2297 default:
2298 FIXME("unsupported name %s\n", debugstr_variant(name));
2299 hres = E_NOTIMPL;
2300 }
2301 if(hres == DISP_E_UNKNOWNNAME)
2302 return E_INVALIDARG;
2303 if(FAILED(hres))
2304 return hres;
2305
2306 hres = get_domattr(This, id, NULL, &attr);
2307 if(FAILED(hres))
2308 return hres;
2309
2310 *ppItem = (IDispatch*)&attr->IHTMLDOMAttribute_iface;
2311 return S_OK;
2312 }
2313
2314 static const IHTMLAttributeCollectionVtbl HTMLAttributeCollectionVtbl = {
2315 HTMLAttributeCollection_QueryInterface,
2316 HTMLAttributeCollection_AddRef,
2317 HTMLAttributeCollection_Release,
2318 HTMLAttributeCollection_GetTypeInfoCount,
2319 HTMLAttributeCollection_GetTypeInfo,
2320 HTMLAttributeCollection_GetIDsOfNames,
2321 HTMLAttributeCollection_Invoke,
2322 HTMLAttributeCollection_get_length,
2323 HTMLAttributeCollection__newEnum,
2324 HTMLAttributeCollection_item
2325 };
2326
2327 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection2(IHTMLAttributeCollection2 *iface)
2328 {
2329 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection2_iface);
2330 }
2331
2332 static HRESULT WINAPI HTMLAttributeCollection2_QueryInterface(IHTMLAttributeCollection2 *iface, REFIID riid, void **ppv)
2333 {
2334 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2335 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2336 }
2337
2338 static ULONG WINAPI HTMLAttributeCollection2_AddRef(IHTMLAttributeCollection2 *iface)
2339 {
2340 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2341 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2342 }
2343
2344 static ULONG WINAPI HTMLAttributeCollection2_Release(IHTMLAttributeCollection2 *iface)
2345 {
2346 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2347 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2348 }
2349
2350 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfoCount(IHTMLAttributeCollection2 *iface, UINT *pctinfo)
2351 {
2352 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2353 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2354 }
2355
2356 static HRESULT WINAPI HTMLAttributeCollection2_GetTypeInfo(IHTMLAttributeCollection2 *iface, UINT iTInfo,
2357 LCID lcid, ITypeInfo **ppTInfo)
2358 {
2359 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2360 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2361 }
2362
2363 static HRESULT WINAPI HTMLAttributeCollection2_GetIDsOfNames(IHTMLAttributeCollection2 *iface, REFIID riid,
2364 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2365 {
2366 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2367 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2368 lcid, rgDispId);
2369 }
2370
2371 static HRESULT WINAPI HTMLAttributeCollection2_Invoke(IHTMLAttributeCollection2 *iface, DISPID dispIdMember,
2372 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2373 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2374 {
2375 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2376 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2377 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2378 }
2379
2380 static HRESULT WINAPI HTMLAttributeCollection2_getNamedItem(IHTMLAttributeCollection2 *iface, BSTR bstrName,
2381 IHTMLDOMAttribute **newretNode)
2382 {
2383 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2384 HTMLDOMAttribute *attr;
2385 DISPID id;
2386 HRESULT hres;
2387
2388 TRACE("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2389
2390 hres = get_attr_dispid_by_name(This, bstrName, &id);
2391 if(hres == DISP_E_UNKNOWNNAME) {
2392 *newretNode = NULL;
2393 return S_OK;
2394 } else if(FAILED(hres)) {
2395 return hres;
2396 }
2397
2398 hres = get_domattr(This, id, NULL, &attr);
2399 if(FAILED(hres))
2400 return hres;
2401
2402 *newretNode = &attr->IHTMLDOMAttribute_iface;
2403 return S_OK;
2404 }
2405
2406 static HRESULT WINAPI HTMLAttributeCollection2_setNamedItem(IHTMLAttributeCollection2 *iface,
2407 IHTMLDOMAttribute *ppNode, IHTMLDOMAttribute **newretNode)
2408 {
2409 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2410 FIXME("(%p)->(%p %p)\n", This, ppNode, newretNode);
2411 return E_NOTIMPL;
2412 }
2413
2414 static HRESULT WINAPI HTMLAttributeCollection2_removeNamedItem(IHTMLAttributeCollection2 *iface,
2415 BSTR bstrName, IHTMLDOMAttribute **newretNode)
2416 {
2417 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection2(iface);
2418 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), newretNode);
2419 return E_NOTIMPL;
2420 }
2421
2422 static const IHTMLAttributeCollection2Vtbl HTMLAttributeCollection2Vtbl = {
2423 HTMLAttributeCollection2_QueryInterface,
2424 HTMLAttributeCollection2_AddRef,
2425 HTMLAttributeCollection2_Release,
2426 HTMLAttributeCollection2_GetTypeInfoCount,
2427 HTMLAttributeCollection2_GetTypeInfo,
2428 HTMLAttributeCollection2_GetIDsOfNames,
2429 HTMLAttributeCollection2_Invoke,
2430 HTMLAttributeCollection2_getNamedItem,
2431 HTMLAttributeCollection2_setNamedItem,
2432 HTMLAttributeCollection2_removeNamedItem
2433 };
2434
2435 static inline HTMLAttributeCollection *impl_from_IHTMLAttributeCollection3(IHTMLAttributeCollection3 *iface)
2436 {
2437 return CONTAINING_RECORD(iface, HTMLAttributeCollection, IHTMLAttributeCollection3_iface);
2438 }
2439
2440 static HRESULT WINAPI HTMLAttributeCollection3_QueryInterface(IHTMLAttributeCollection3 *iface, REFIID riid, void **ppv)
2441 {
2442 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2443 return IHTMLAttributeCollection_QueryInterface(&This->IHTMLAttributeCollection_iface, riid, ppv);
2444 }
2445
2446 static ULONG WINAPI HTMLAttributeCollection3_AddRef(IHTMLAttributeCollection3 *iface)
2447 {
2448 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2449 return IHTMLAttributeCollection_AddRef(&This->IHTMLAttributeCollection_iface);
2450 }
2451
2452 static ULONG WINAPI HTMLAttributeCollection3_Release(IHTMLAttributeCollection3 *iface)
2453 {
2454 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2455 return IHTMLAttributeCollection_Release(&This->IHTMLAttributeCollection_iface);
2456 }
2457
2458 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfoCount(IHTMLAttributeCollection3 *iface, UINT *pctinfo)
2459 {
2460 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2461 return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
2462 }
2463
2464 static HRESULT WINAPI HTMLAttributeCollection3_GetTypeInfo(IHTMLAttributeCollection3 *iface, UINT iTInfo,
2465 LCID lcid, ITypeInfo **ppTInfo)
2466 {
2467 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2468 return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
2469 }
2470
2471 static HRESULT WINAPI HTMLAttributeCollection3_GetIDsOfNames(IHTMLAttributeCollection3 *iface, REFIID riid,
2472 LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
2473 {
2474 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2475 return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
2476 lcid, rgDispId);
2477 }
2478
2479 static HRESULT WINAPI HTMLAttributeCollection3_Invoke(IHTMLAttributeCollection3 *iface, DISPID dispIdMember,
2480 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
2481 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
2482 {
2483 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2484 return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid,
2485 wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
2486 }
2487
2488 static HRESULT WINAPI HTMLAttributeCollection3_getNamedItem(IHTMLAttributeCollection3 *iface, BSTR bstrName,
2489 IHTMLDOMAttribute **ppNodeOut)
2490 {
2491 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2492 return IHTMLAttributeCollection2_getNamedItem(&This->IHTMLAttributeCollection2_iface, bstrName, ppNodeOut);
2493 }
2494
2495 static HRESULT WINAPI HTMLAttributeCollection3_setNamedItem(IHTMLAttributeCollection3 *iface,
2496 IHTMLDOMAttribute *pNodeIn, IHTMLDOMAttribute **ppNodeOut)
2497 {
2498 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2499 FIXME("(%p)->(%p %p)\n", This, pNodeIn, ppNodeOut);
2500 return E_NOTIMPL;
2501 }
2502
2503 static HRESULT WINAPI HTMLAttributeCollection3_removeNamedItem(IHTMLAttributeCollection3 *iface,
2504 BSTR bstrName, IHTMLDOMAttribute **ppNodeOut)
2505 {
2506 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2507 FIXME("(%p)->(%s %p)\n", This, debugstr_w(bstrName), ppNodeOut);
2508 return E_NOTIMPL;
2509 }
2510
2511 static HRESULT WINAPI HTMLAttributeCollection3_item(IHTMLAttributeCollection3 *iface, LONG index, IHTMLDOMAttribute **ppNodeOut)
2512 {
2513 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2514 HTMLDOMAttribute *attr;
2515 DISPID id;
2516 HRESULT hres;
2517
2518 TRACE("(%p)->(%d %p)\n", This, index, ppNodeOut);
2519
2520 hres = get_attr_dispid_by_idx(This, &index, &id);
2521 if(hres == DISP_E_UNKNOWNNAME)
2522 return E_INVALIDARG;
2523 if(FAILED(hres))
2524 return hres;
2525
2526 hres = get_domattr(This, id, NULL, &attr);
2527 if(FAILED(hres))
2528 return hres;
2529
2530 *ppNodeOut = &attr->IHTMLDOMAttribute_iface;
2531 return S_OK;
2532 }
2533
2534 static HRESULT WINAPI HTMLAttributeCollection3_get_length(IHTMLAttributeCollection3 *iface, LONG *p)
2535 {
2536 HTMLAttributeCollection *This = impl_from_IHTMLAttributeCollection3(iface);
2537 return IHTMLAttributeCollection_get_length(&This->IHTMLAttributeCollection_iface, p);
2538 }
2539
2540 static const IHTMLAttributeCollection3Vtbl HTMLAttributeCollection3Vtbl = {
2541 HTMLAttributeCollection3_QueryInterface,
2542 HTMLAttributeCollection3_AddRef,
2543 HTMLAttributeCollection3_Release,
2544 HTMLAttributeCollection3_GetTypeInfoCount,
2545 HTMLAttributeCollection3_GetTypeInfo,
2546 HTMLAttributeCollection3_GetIDsOfNames,
2547 HTMLAttributeCollection3_Invoke,
2548 HTMLAttributeCollection3_getNamedItem,
2549 HTMLAttributeCollection3_setNamedItem,
2550 HTMLAttributeCollection3_removeNamedItem,
2551 HTMLAttributeCollection3_item,
2552 HTMLAttributeCollection3_get_length
2553 };
2554
2555 static inline HTMLAttributeCollection *HTMLAttributeCollection_from_DispatchEx(DispatchEx *iface)
2556 {
2557 return CONTAINING_RECORD(iface, HTMLAttributeCollection, dispex);
2558 }
2559
2560 static HRESULT HTMLAttributeCollection_get_dispid(DispatchEx *dispex, BSTR name, DWORD flags, DISPID *dispid)
2561 {
2562 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2563 HTMLDOMAttribute *attr;
2564 LONG pos;
2565 HRESULT hres;
2566
2567 TRACE("(%p)->(%s %x %p)\n", This, debugstr_w(name), flags, dispid);
2568
2569 hres = get_attr_dispid_by_name(This, name, dispid);
2570 if(FAILED(hres))
2571 return hres;
2572
2573 hres = get_domattr(This, *dispid, &pos, &attr);
2574 if(FAILED(hres))
2575 return hres;
2576 IHTMLDOMAttribute_Release(&attr->IHTMLDOMAttribute_iface);
2577
2578 *dispid = MSHTML_DISPID_CUSTOM_MIN+pos;
2579 return S_OK;
2580 }
2581
2582 static HRESULT HTMLAttributeCollection_invoke(DispatchEx *dispex, DISPID id, LCID lcid,
2583 WORD flags, DISPPARAMS *params, VARIANT *res, EXCEPINFO *ei, IServiceProvider *caller)
2584 {
2585 HTMLAttributeCollection *This = HTMLAttributeCollection_from_DispatchEx(dispex);
2586
2587 TRACE("(%p)->(%x %x %x %p %p %p %p)\n", This, id, lcid, flags, params, res, ei, caller);
2588
2589 switch(flags) {
2590 case DISPATCH_PROPERTYGET: {
2591 HTMLDOMAttribute *iter;
2592 DWORD pos;
2593
2594 pos = id-MSHTML_DISPID_CUSTOM_MIN;
2595
2596 LIST_FOR_EACH_ENTRY(iter, &This->attrs, HTMLDOMAttribute, entry) {
2597 if(!pos) {
2598 IHTMLDOMAttribute_AddRef(&iter->IHTMLDOMAttribute_iface);
2599 V_VT(res) = VT_DISPATCH;
2600 V_DISPATCH(res) = (IDispatch*)&iter->IHTMLDOMAttribute_iface;
2601 return S_OK;
2602 }
2603 pos--;
2604 }
2605
2606 WARN("invalid arg\n");
2607 return E_INVALIDARG;
2608 }
2609
2610 default:
2611 FIXME("unimplemented flags %x\n", flags);
2612 return E_NOTIMPL;
2613 }
2614 }
2615
2616 static const dispex_static_data_vtbl_t HTMLAttributeCollection_dispex_vtbl = {
2617 NULL,
2618 HTMLAttributeCollection_get_dispid,
2619 HTMLAttributeCollection_invoke,
2620 NULL
2621 };
2622
2623 static const tid_t HTMLAttributeCollection_iface_tids[] = {
2624 IHTMLAttributeCollection_tid,
2625 IHTMLAttributeCollection2_tid,
2626 IHTMLAttributeCollection3_tid,
2627 0
2628 };
2629
2630 static dispex_static_data_t HTMLAttributeCollection_dispex = {
2631 &HTMLAttributeCollection_dispex_vtbl,
2632 DispHTMLAttributeCollection_tid,
2633 NULL,
2634 HTMLAttributeCollection_iface_tids
2635 };
2636
2637 HRESULT HTMLElement_get_attr_col(HTMLDOMNode *iface, HTMLAttributeCollection **ac)
2638 {
2639 HTMLElement *This = impl_from_HTMLDOMNode(iface);
2640
2641 if(This->attrs) {
2642 IHTMLAttributeCollection_AddRef(&This->attrs->IHTMLAttributeCollection_iface);
2643 *ac = This->attrs;
2644 return S_OK;
2645 }
2646
2647 This->attrs = heap_alloc_zero(sizeof(HTMLAttributeCollection));
2648 if(!This->attrs)
2649 return E_OUTOFMEMORY;
2650
2651 This->attrs->IHTMLAttributeCollection_iface.lpVtbl = &HTMLAttributeCollectionVtbl;
2652 This->attrs->IHTMLAttributeCollection2_iface.lpVtbl = &HTMLAttributeCollection2Vtbl;
2653 This->attrs->IHTMLAttributeCollection3_iface.lpVtbl = &HTMLAttributeCollection3Vtbl;
2654 This->attrs->ref = 2;
2655
2656 This->attrs->elem = This;
2657 list_init(&This->attrs->attrs);
2658 init_dispex(&This->attrs->dispex, (IUnknown*)&This->attrs->IHTMLAttributeCollection_iface,
2659 &HTMLAttributeCollection_dispex);
2660
2661 *ac = This->attrs;
2662 return S_OK;
2663 }