2 * Copyright 2007 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
29 #include "mshtml_private.h"
30 #include "htmlevent.h"
32 #include "wine/debug.h"
34 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
39 IHTMLAnchorElement IHTMLAnchorElement_iface;
41 nsIDOMHTMLAnchorElement *nsanchor;
44 static HRESULT navigate_anchor(HTMLAnchorElement *This)
46 nsAString href_str, target_str;
48 HRESULT hres = E_FAIL;
50 static const WCHAR _selfW[] = {'_','s','e','l','f',0};
52 nsAString_Init(&target_str, NULL);
53 nsres = nsIDOMHTMLAnchorElement_GetTarget(This->nsanchor, &target_str);
54 if(NS_SUCCEEDED(nsres)) {
55 const PRUnichar *target;
57 nsAString_GetData(&target_str, &target);
58 if(*target && strcmpiW(target, _selfW)) {
59 FIXME("Navigating to target %s is not implemented\n", debugstr_w(target));
60 nsAString_Finish(&target_str);
64 nsAString_Finish(&target_str);
66 nsAString_Init(&href_str, NULL);
67 nsres = nsIDOMHTMLAnchorElement_GetHref(This->nsanchor, &href_str);
68 if(NS_SUCCEEDED(nsres)) {
69 const PRUnichar *href;
71 nsAString_GetData(&href_str, &href);
73 HTMLWindow *window = This->element.node.doc->basedoc.window;
74 hres = navigate_url(window, href, window->url);
76 TRACE("empty href\n");
80 nsAString_Finish(&href_str);
84 static inline HTMLAnchorElement *impl_from_IHTMLAnchorElement(IHTMLAnchorElement *iface)
86 return CONTAINING_RECORD(iface, HTMLAnchorElement, IHTMLAnchorElement_iface);
89 static HRESULT WINAPI HTMLAnchorElement_QueryInterface(IHTMLAnchorElement *iface,
90 REFIID riid, void **ppv)
92 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
94 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
97 static ULONG WINAPI HTMLAnchorElement_AddRef(IHTMLAnchorElement *iface)
99 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
101 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
104 static ULONG WINAPI HTMLAnchorElement_Release(IHTMLAnchorElement *iface)
106 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
108 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
111 static HRESULT WINAPI HTMLAnchorElement_GetTypeInfoCount(IHTMLAnchorElement *iface, UINT *pctinfo)
113 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
114 return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
117 static HRESULT WINAPI HTMLAnchorElement_GetTypeInfo(IHTMLAnchorElement *iface, UINT iTInfo,
118 LCID lcid, ITypeInfo **ppTInfo)
120 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
121 return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
125 static HRESULT WINAPI HTMLAnchorElement_GetIDsOfNames(IHTMLAnchorElement *iface, REFIID riid,
126 LPOLESTR *rgszNames, UINT cNames,
127 LCID lcid, DISPID *rgDispId)
129 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
130 return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
131 cNames, lcid, rgDispId);
134 static HRESULT WINAPI HTMLAnchorElement_Invoke(IHTMLAnchorElement *iface, DISPID dispIdMember,
135 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
136 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
138 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
139 return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
140 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
143 static HRESULT WINAPI HTMLAnchorElement_put_href(IHTMLAnchorElement *iface, BSTR v)
145 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
149 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
151 nsAString_InitDepend(&nsstr, v);
152 nsres = nsIDOMHTMLAnchorElement_SetHref(This->nsanchor, &nsstr);
153 nsAString_Finish(&nsstr);
160 static HRESULT WINAPI HTMLAnchorElement_get_href(IHTMLAnchorElement *iface, BSTR *p)
162 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
167 TRACE("(%p)->(%p)\n", This, p);
169 nsAString_Init(&href_str, NULL);
170 nsres = nsIDOMHTMLAnchorElement_GetHref(This->nsanchor, &href_str);
171 if(NS_SUCCEEDED(nsres)) {
172 const PRUnichar *href;
174 nsAString_GetData(&href_str, &href);
175 hres = nsuri_to_url(href, TRUE, p);
177 ERR("GetHref failed: %08x\n", nsres);
181 nsAString_Finish(&href_str);
185 static HRESULT WINAPI HTMLAnchorElement_put_target(IHTMLAnchorElement *iface, BSTR v)
187 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
191 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
193 nsAString_InitDepend(&nsstr, v);
194 nsres = nsIDOMHTMLAnchorElement_SetTarget(This->nsanchor, &nsstr);
195 nsAString_Finish(&nsstr);
202 static HRESULT WINAPI HTMLAnchorElement_get_target(IHTMLAnchorElement *iface, BSTR *p)
204 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
205 nsAString target_str;
208 TRACE("(%p)->(%p)\n", This, p);
210 nsAString_Init(&target_str, NULL);
211 nsres = nsIDOMHTMLAnchorElement_GetTarget(This->nsanchor, &target_str);
213 return return_nsstr(nsres, &target_str, p);
216 static HRESULT WINAPI HTMLAnchorElement_put_rel(IHTMLAnchorElement *iface, BSTR v)
218 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
219 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
223 static HRESULT WINAPI HTMLAnchorElement_get_rel(IHTMLAnchorElement *iface, BSTR *p)
225 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
226 FIXME("(%p)->(%p)\n", This, p);
230 static HRESULT WINAPI HTMLAnchorElement_put_rev(IHTMLAnchorElement *iface, BSTR v)
232 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
233 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
237 static HRESULT WINAPI HTMLAnchorElement_get_rev(IHTMLAnchorElement *iface, BSTR *p)
239 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
240 FIXME("(%p)->(%p)\n", This, p);
244 static HRESULT WINAPI HTMLAnchorElement_put_urn(IHTMLAnchorElement *iface, BSTR v)
246 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
247 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
251 static HRESULT WINAPI HTMLAnchorElement_get_urn(IHTMLAnchorElement *iface, BSTR *p)
253 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
254 FIXME("(%p)->(%p)\n", This, p);
258 static HRESULT WINAPI HTMLAnchorElement_put_Methods(IHTMLAnchorElement *iface, BSTR v)
260 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
261 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
265 static HRESULT WINAPI HTMLAnchorElement_get_Methods(IHTMLAnchorElement *iface, BSTR *p)
267 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
268 FIXME("(%p)->(%p)\n", This, p);
272 static HRESULT WINAPI HTMLAnchorElement_put_name(IHTMLAnchorElement *iface, BSTR v)
274 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
275 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
279 static HRESULT WINAPI HTMLAnchorElement_get_name(IHTMLAnchorElement *iface, BSTR *p)
281 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
282 FIXME("(%p)->(%p)\n", This, p);
286 static HRESULT WINAPI HTMLAnchorElement_put_host(IHTMLAnchorElement *iface, BSTR v)
288 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
289 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
293 static HRESULT WINAPI HTMLAnchorElement_get_host(IHTMLAnchorElement *iface, BSTR *p)
295 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
296 FIXME("(%p)->(%p)\n", This, p);
300 static HRESULT WINAPI HTMLAnchorElement_put_hostname(IHTMLAnchorElement *iface, BSTR v)
302 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
303 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
307 static HRESULT WINAPI HTMLAnchorElement_get_hostname(IHTMLAnchorElement *iface, BSTR *p)
309 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
310 FIXME("(%p)->(%p)\n", This, p);
314 static HRESULT WINAPI HTMLAnchorElement_put_pathname(IHTMLAnchorElement *iface, BSTR v)
316 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
317 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
321 static HRESULT WINAPI HTMLAnchorElement_get_pathname(IHTMLAnchorElement *iface, BSTR *p)
323 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
324 FIXME("(%p)->(%p)\n", This, p);
328 static HRESULT WINAPI HTMLAnchorElement_put_port(IHTMLAnchorElement *iface, BSTR v)
330 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
331 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
335 static HRESULT WINAPI HTMLAnchorElement_get_port(IHTMLAnchorElement *iface, BSTR *p)
337 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
338 FIXME("(%p)->(%p)\n", This, p);
342 static HRESULT WINAPI HTMLAnchorElement_put_protocol(IHTMLAnchorElement *iface, BSTR v)
344 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
345 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
349 static HRESULT WINAPI HTMLAnchorElement_get_protocol(IHTMLAnchorElement *iface, BSTR *p)
351 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
352 FIXME("(%p)->(%p)\n", This, p);
356 static HRESULT WINAPI HTMLAnchorElement_put_search(IHTMLAnchorElement *iface, BSTR v)
358 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
359 FIXME("(%p)->(%p)\n", This, debugstr_w(v));
363 static HRESULT WINAPI HTMLAnchorElement_get_search(IHTMLAnchorElement *iface, BSTR *p)
365 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
366 FIXME("(%p)->(%p)\n", This, p);
370 static HRESULT WINAPI HTMLAnchorElement_put_hash(IHTMLAnchorElement *iface, BSTR v)
372 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
373 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
377 static HRESULT WINAPI HTMLAnchorElement_get_hash(IHTMLAnchorElement *iface, BSTR *p)
379 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
380 FIXME("(%p)->(%p)\n", This, p);
384 static HRESULT WINAPI HTMLAnchorElement_put_onblur(IHTMLAnchorElement *iface, VARIANT v)
386 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
388 TRACE("(%p)->()\n", This);
390 return IHTMLElement2_put_onblur(&This->element.IHTMLElement2_iface, v);
393 static HRESULT WINAPI HTMLAnchorElement_get_onblur(IHTMLAnchorElement *iface, VARIANT *p)
395 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
397 TRACE("(%p)->(%p)\n", This, p);
399 return IHTMLElement2_get_onblur(&This->element.IHTMLElement2_iface, p);
402 static HRESULT WINAPI HTMLAnchorElement_put_onfocus(IHTMLAnchorElement *iface, VARIANT v)
404 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
406 TRACE("(%p)->()\n", This);
408 return IHTMLElement2_put_onfocus(&This->element.IHTMLElement2_iface, v);
411 static HRESULT WINAPI HTMLAnchorElement_get_onfocus(IHTMLAnchorElement *iface, VARIANT *p)
413 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
415 TRACE("(%p)->(%p)\n", This, p);
417 return IHTMLElement2_get_onfocus(&This->element.IHTMLElement2_iface, p);
420 static HRESULT WINAPI HTMLAnchorElement_put_accessKey(IHTMLAnchorElement *iface, BSTR v)
422 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
424 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
426 return IHTMLElement2_put_accessKey(&This->element.IHTMLElement2_iface, v);
429 static HRESULT WINAPI HTMLAnchorElement_get_accessKey(IHTMLAnchorElement *iface, BSTR *p)
431 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
433 TRACE("(%p)->(%p)\n", This, p);
435 return IHTMLElement2_get_accessKey(&This->element.IHTMLElement2_iface, p);
438 static HRESULT WINAPI HTMLAnchorElement_get_protocolLong(IHTMLAnchorElement *iface, BSTR *p)
440 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
441 FIXME("(%p)->(%p)\n", This, p);
445 static HRESULT WINAPI HTMLAnchorElement_get_mimeType(IHTMLAnchorElement *iface, BSTR *p)
447 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
448 FIXME("(%p)->(%p)\n", This, p);
452 static HRESULT WINAPI HTMLAnchorElement_get_nameProp(IHTMLAnchorElement *iface, BSTR *p)
454 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
455 FIXME("(%p)->(%p)\n", This, p);
459 static HRESULT WINAPI HTMLAnchorElement_put_tabIndex(IHTMLAnchorElement *iface, short v)
461 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
463 TRACE("(%p)->()\n", This);
465 return IHTMLElement2_put_tabIndex(&This->element.IHTMLElement2_iface, v);
468 static HRESULT WINAPI HTMLAnchorElement_get_tabIndex(IHTMLAnchorElement *iface, short *p)
470 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
472 TRACE("(%p)->(%p)\n", This, p);
474 return IHTMLElement2_get_tabIndex(&This->element.IHTMLElement2_iface, p);
477 static HRESULT WINAPI HTMLAnchorElement_focus(IHTMLAnchorElement *iface)
479 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
481 TRACE("(%p)\n", This);
483 return IHTMLElement2_focus(&This->element.IHTMLElement2_iface);
486 static HRESULT WINAPI HTMLAnchorElement_blur(IHTMLAnchorElement *iface)
488 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
490 TRACE("(%p)\n", This);
492 return IHTMLElement2_blur(&This->element.IHTMLElement2_iface);
495 static const IHTMLAnchorElementVtbl HTMLAnchorElementVtbl = {
496 HTMLAnchorElement_QueryInterface,
497 HTMLAnchorElement_AddRef,
498 HTMLAnchorElement_Release,
499 HTMLAnchorElement_GetTypeInfoCount,
500 HTMLAnchorElement_GetTypeInfo,
501 HTMLAnchorElement_GetIDsOfNames,
502 HTMLAnchorElement_Invoke,
503 HTMLAnchorElement_put_href,
504 HTMLAnchorElement_get_href,
505 HTMLAnchorElement_put_target,
506 HTMLAnchorElement_get_target,
507 HTMLAnchorElement_put_rel,
508 HTMLAnchorElement_get_rel,
509 HTMLAnchorElement_put_rev,
510 HTMLAnchorElement_get_rev,
511 HTMLAnchorElement_put_urn,
512 HTMLAnchorElement_get_urn,
513 HTMLAnchorElement_put_Methods,
514 HTMLAnchorElement_get_Methods,
515 HTMLAnchorElement_put_name,
516 HTMLAnchorElement_get_name,
517 HTMLAnchorElement_put_host,
518 HTMLAnchorElement_get_host,
519 HTMLAnchorElement_put_hostname,
520 HTMLAnchorElement_get_hostname,
521 HTMLAnchorElement_put_pathname,
522 HTMLAnchorElement_get_pathname,
523 HTMLAnchorElement_put_port,
524 HTMLAnchorElement_get_port,
525 HTMLAnchorElement_put_protocol,
526 HTMLAnchorElement_get_protocol,
527 HTMLAnchorElement_put_search,
528 HTMLAnchorElement_get_search,
529 HTMLAnchorElement_put_hash,
530 HTMLAnchorElement_get_hash,
531 HTMLAnchorElement_put_onblur,
532 HTMLAnchorElement_get_onblur,
533 HTMLAnchorElement_put_onfocus,
534 HTMLAnchorElement_get_onfocus,
535 HTMLAnchorElement_put_accessKey,
536 HTMLAnchorElement_get_accessKey,
537 HTMLAnchorElement_get_protocolLong,
538 HTMLAnchorElement_get_mimeType,
539 HTMLAnchorElement_get_nameProp,
540 HTMLAnchorElement_put_tabIndex,
541 HTMLAnchorElement_get_tabIndex,
542 HTMLAnchorElement_focus,
543 HTMLAnchorElement_blur
546 static inline HTMLAnchorElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
548 return CONTAINING_RECORD(iface, HTMLAnchorElement, element.node);
551 static HRESULT HTMLAnchorElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
553 HTMLAnchorElement *This = impl_from_HTMLDOMNode(iface);
557 if(IsEqualGUID(&IID_IUnknown, riid)) {
558 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
559 *ppv = &This->IHTMLAnchorElement_iface;
560 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
561 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
562 *ppv = &This->IHTMLAnchorElement_iface;
563 }else if(IsEqualGUID(&IID_IHTMLAnchorElement, riid)) {
564 TRACE("(%p)->(IID_IHTMLAnchorElement %p)\n", This, ppv);
565 *ppv = &This->IHTMLAnchorElement_iface;
569 IUnknown_AddRef((IUnknown*)*ppv);
573 return HTMLElement_QI(&This->element.node, riid, ppv);
576 static void HTMLAnchorElement_destructor(HTMLDOMNode *iface)
578 HTMLAnchorElement *This = impl_from_HTMLDOMNode(iface);
581 nsIDOMHTMLAnchorElement_Release(This->nsanchor);
583 HTMLElement_destructor(&This->element.node);
586 static HRESULT HTMLAnchorElement_handle_event(HTMLDOMNode *iface, eventid_t eid, BOOL *prevent_default)
588 HTMLAnchorElement *This = impl_from_HTMLDOMNode(iface);
590 if(eid == EVENTID_CLICK) {
592 *prevent_default = TRUE;
593 return navigate_anchor(This);
599 static const NodeImplVtbl HTMLAnchorElementImplVtbl = {
600 HTMLAnchorElement_QI,
601 HTMLAnchorElement_destructor,
603 HTMLElement_get_attr_col,
606 HTMLAnchorElement_handle_event
609 static const tid_t HTMLAnchorElement_iface_tids[] = {
610 IHTMLAnchorElement_tid,
612 IHTMLTextContainer_tid,
617 static dispex_static_data_t HTMLAnchorElement_dispex = {
619 DispHTMLAnchorElement_tid,
621 HTMLAnchorElement_iface_tids
624 HRESULT HTMLAnchorElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
626 HTMLAnchorElement *ret;
629 ret = heap_alloc_zero(sizeof(HTMLAnchorElement));
631 return E_OUTOFMEMORY;
633 ret->IHTMLAnchorElement_iface.lpVtbl = &HTMLAnchorElementVtbl;
634 ret->element.node.vtbl = &HTMLAnchorElementImplVtbl;
636 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLAnchorElement, (void**)&ret->nsanchor);
637 if(NS_FAILED(nsres)) {
638 ERR("Could not get nsIDOMHTMLAnchorElement iface: %08x\n", nsres);
643 HTMLElement_Init(&ret->element, doc, nselem, &HTMLAnchorElement_dispex);
645 *elem = &ret->element;