imagehlp: Use the IMAGE_FIRST_SECTION helper macro.
[wine.git] / dlls / mshtml / htmlanchor.c
blob8fc333f5bf4a7fcabe0bdab0a521a74f88487f00
1 /*
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
19 #include <stdarg.h>
20 #include <stdio.h>
22 #define COBJMACROS
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winuser.h"
27 #include "ole2.h"
29 #include "mshtml_private.h"
30 #include "htmlevent.h"
31 #include "binding.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
37 struct HTMLAnchorElement {
38 HTMLElement element;
40 IHTMLAnchorElement IHTMLAnchorElement_iface;
42 nsIDOMHTMLAnchorElement *nsanchor;
45 static HRESULT navigate_href_new_window(HTMLElement *element, nsAString *href_str, const WCHAR *target)
47 const PRUnichar *href;
48 IUri *uri;
49 HRESULT hres;
51 nsAString_GetData(href_str, &href);
52 hres = create_relative_uri(element->node.doc->outer_window, href, &uri);
53 if(FAILED(hres))
54 return hres;
56 hres = navigate_new_window(element->node.doc->outer_window, uri, target, NULL, NULL);
57 IUri_Release(uri);
58 return hres;
61 HTMLOuterWindow *get_target_window(HTMLOuterWindow *window, nsAString *target_str, BOOL *use_new_window)
63 HTMLOuterWindow *top_window, *ret_window;
64 const PRUnichar *target;
65 HRESULT hres;
67 *use_new_window = FALSE;
69 nsAString_GetData(target_str, &target);
70 TRACE("%s\n", debugstr_w(target));
72 if(!*target || !wcsicmp(target, L"_self")) {
73 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
74 return window;
77 if(!wcsicmp(target, L"_top")) {
78 get_top_window(window, &top_window);
79 IHTMLWindow2_AddRef(&top_window->base.IHTMLWindow2_iface);
80 return top_window;
83 if(!wcsicmp(target, L"_parent")) {
84 if(!window->parent) {
85 WARN("Window has no parent, treat as self\n");
86 IHTMLWindow2_AddRef(&window->base.IHTMLWindow2_iface);
87 return window;
90 IHTMLWindow2_AddRef(&window->parent->base.IHTMLWindow2_iface);
91 return window->parent;
94 get_top_window(window, &top_window);
96 hres = get_frame_by_name(top_window, target, TRUE, &ret_window);
97 if(FAILED(hres) || !ret_window) {
98 *use_new_window = TRUE;
99 return NULL;
102 IHTMLWindow2_AddRef(&ret_window->base.IHTMLWindow2_iface);
103 return ret_window;
106 static HRESULT navigate_href(HTMLElement *element, nsAString *href_str, nsAString *target_str)
108 HTMLOuterWindow *window;
109 BOOL use_new_window;
110 const PRUnichar *href;
111 HRESULT hres;
113 window = get_target_window(element->node.doc->outer_window, target_str, &use_new_window);
114 if(!window) {
115 if(use_new_window) {
116 const PRUnichar *target;
117 nsAString_GetData(target_str, &target);
118 return navigate_href_new_window(element, href_str, target);
119 }else {
120 return S_OK;
124 nsAString_GetData(href_str, &href);
125 if(*href) {
126 hres = navigate_url(window, href, window->uri_nofrag, BINDING_NAVIGATED);
127 }else {
128 TRACE("empty href\n");
129 hres = S_OK;
131 IHTMLWindow2_Release(&window->base.IHTMLWindow2_iface);
132 return hres;
135 HRESULT handle_link_click_event(HTMLElement *element, nsAString *href_str, nsAString *target_str,
136 nsIDOMEvent *event, BOOL *prevent_default)
138 nsIDOMMouseEvent *mouse_event;
139 INT16 button;
140 nsresult nsres;
141 HRESULT hres;
143 TRACE("CLICK\n");
145 nsres = nsIDOMEvent_QueryInterface(event, &IID_nsIDOMMouseEvent, (void**)&mouse_event);
146 assert(nsres == NS_OK);
148 nsres = nsIDOMMouseEvent_GetButton(mouse_event, &button);
149 assert(nsres == NS_OK);
151 nsIDOMMouseEvent_Release(mouse_event);
153 switch(button) {
154 case 0:
155 *prevent_default = TRUE;
156 hres = navigate_href(element, href_str, target_str);
157 break;
158 case 1:
159 *prevent_default = TRUE;
160 hres = navigate_href_new_window(element, href_str, NULL);
161 break;
162 default:
163 *prevent_default = FALSE;
164 hres = S_OK;
167 nsAString_Finish(href_str);
168 nsAString_Finish(target_str);
169 return hres;
172 static IUri *get_anchor_uri(HTMLAnchorElement *anchor)
174 nsAString href_str;
175 IUri *uri = NULL;
176 nsresult nsres;
178 nsAString_Init(&href_str, NULL);
179 nsres = nsIDOMHTMLAnchorElement_GetHref(anchor->nsanchor, &href_str);
180 if(NS_SUCCEEDED(nsres)) {
181 const PRUnichar *href;
183 nsAString_GetData(&href_str, &href);
184 create_uri(href, 0, &uri);
185 }else {
186 ERR("GetHref failed: %08lx\n", nsres);
189 nsAString_Finish(&href_str);
190 return uri;
193 static inline HTMLAnchorElement *impl_from_IHTMLAnchorElement(IHTMLAnchorElement *iface)
195 return CONTAINING_RECORD(iface, HTMLAnchorElement, IHTMLAnchorElement_iface);
198 static HRESULT WINAPI HTMLAnchorElement_QueryInterface(IHTMLAnchorElement *iface,
199 REFIID riid, void **ppv)
201 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
203 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
206 static ULONG WINAPI HTMLAnchorElement_AddRef(IHTMLAnchorElement *iface)
208 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
210 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
213 static ULONG WINAPI HTMLAnchorElement_Release(IHTMLAnchorElement *iface)
215 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
217 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
220 static HRESULT WINAPI HTMLAnchorElement_GetTypeInfoCount(IHTMLAnchorElement *iface, UINT *pctinfo)
222 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
223 return IDispatchEx_GetTypeInfoCount(&This->element.node.event_target.dispex.IDispatchEx_iface, pctinfo);
226 static HRESULT WINAPI HTMLAnchorElement_GetTypeInfo(IHTMLAnchorElement *iface, UINT iTInfo,
227 LCID lcid, ITypeInfo **ppTInfo)
229 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
230 return IDispatchEx_GetTypeInfo(&This->element.node.event_target.dispex.IDispatchEx_iface, iTInfo, lcid,
231 ppTInfo);
234 static HRESULT WINAPI HTMLAnchorElement_GetIDsOfNames(IHTMLAnchorElement *iface, REFIID riid,
235 LPOLESTR *rgszNames, UINT cNames,
236 LCID lcid, DISPID *rgDispId)
238 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
239 return IDispatchEx_GetIDsOfNames(&This->element.node.event_target.dispex.IDispatchEx_iface, riid, rgszNames,
240 cNames, lcid, rgDispId);
243 static HRESULT WINAPI HTMLAnchorElement_Invoke(IHTMLAnchorElement *iface, DISPID dispIdMember,
244 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
245 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
247 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
248 return IDispatchEx_Invoke(&This->element.node.event_target.dispex.IDispatchEx_iface, dispIdMember, riid,
249 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
252 static HRESULT WINAPI HTMLAnchorElement_put_href(IHTMLAnchorElement *iface, BSTR v)
254 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
255 nsAString nsstr;
256 nsresult nsres;
258 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
260 nsAString_InitDepend(&nsstr, v);
261 nsres = nsIDOMHTMLAnchorElement_SetHref(This->nsanchor, &nsstr);
262 nsAString_Finish(&nsstr);
263 if(NS_FAILED(nsres))
264 return E_FAIL;
266 return S_OK;
269 static HRESULT WINAPI HTMLAnchorElement_get_href(IHTMLAnchorElement *iface, BSTR *p)
271 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
272 nsAString href_str;
273 nsresult nsres;
274 HRESULT hres;
276 TRACE("(%p)->(%p)\n", This, p);
278 nsAString_Init(&href_str, NULL);
279 nsres = nsIDOMHTMLAnchorElement_GetHref(This->nsanchor, &href_str);
280 if(NS_SUCCEEDED(nsres)) {
281 const PRUnichar *href;
283 nsAString_GetData(&href_str, &href);
284 hres = nsuri_to_url(href, TRUE, p);
285 }else {
286 ERR("GetHref failed: %08lx\n", nsres);
287 hres = E_FAIL;
290 nsAString_Finish(&href_str);
291 return hres;
294 static HRESULT WINAPI HTMLAnchorElement_put_target(IHTMLAnchorElement *iface, BSTR v)
296 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
297 nsAString nsstr;
298 nsresult nsres;
300 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
302 nsAString_InitDepend(&nsstr, v);
303 nsres = nsIDOMHTMLAnchorElement_SetTarget(This->nsanchor, &nsstr);
304 nsAString_Finish(&nsstr);
305 if(NS_FAILED(nsres))
306 return E_FAIL;
308 return S_OK;
311 static HRESULT WINAPI HTMLAnchorElement_get_target(IHTMLAnchorElement *iface, BSTR *p)
313 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
314 nsAString target_str;
315 nsresult nsres;
317 TRACE("(%p)->(%p)\n", This, p);
319 nsAString_Init(&target_str, NULL);
320 nsres = nsIDOMHTMLAnchorElement_GetTarget(This->nsanchor, &target_str);
322 return return_nsstr(nsres, &target_str, p);
325 static HRESULT WINAPI HTMLAnchorElement_put_rel(IHTMLAnchorElement *iface, BSTR v)
327 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
328 nsAString nsstr;
329 nsresult nsres;
331 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
333 nsAString_InitDepend(&nsstr, v);
334 nsres = nsIDOMHTMLAnchorElement_SetRel(This->nsanchor, &nsstr);
335 nsAString_Finish(&nsstr);
336 if(NS_FAILED(nsres))
337 return E_FAIL;
339 return S_OK;
342 static HRESULT WINAPI HTMLAnchorElement_get_rel(IHTMLAnchorElement *iface, BSTR *p)
344 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
345 nsAString nsstr;
346 nsresult nsres;
348 TRACE("(%p)->(%p)\n", This, p);
350 nsAString_Init(&nsstr, NULL);
351 nsres = nsIDOMHTMLAnchorElement_GetRel(This->nsanchor, &nsstr);
352 return return_nsstr(nsres, &nsstr, p);
355 static HRESULT WINAPI HTMLAnchorElement_put_rev(IHTMLAnchorElement *iface, BSTR v)
357 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
358 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
359 return E_NOTIMPL;
362 static HRESULT WINAPI HTMLAnchorElement_get_rev(IHTMLAnchorElement *iface, BSTR *p)
364 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
365 FIXME("(%p)->(%p)\n", This, p);
366 return E_NOTIMPL;
369 static HRESULT WINAPI HTMLAnchorElement_put_urn(IHTMLAnchorElement *iface, BSTR v)
371 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
372 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
373 return E_NOTIMPL;
376 static HRESULT WINAPI HTMLAnchorElement_get_urn(IHTMLAnchorElement *iface, BSTR *p)
378 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
379 FIXME("(%p)->(%p)\n", This, p);
380 return E_NOTIMPL;
383 static HRESULT WINAPI HTMLAnchorElement_put_Methods(IHTMLAnchorElement *iface, BSTR v)
385 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
386 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
387 return E_NOTIMPL;
390 static HRESULT WINAPI HTMLAnchorElement_get_Methods(IHTMLAnchorElement *iface, BSTR *p)
392 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
393 FIXME("(%p)->(%p)\n", This, p);
394 return E_NOTIMPL;
397 static HRESULT WINAPI HTMLAnchorElement_put_name(IHTMLAnchorElement *iface, BSTR v)
399 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
400 nsAString nsstr;
401 nsresult nsres;
403 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
405 nsAString_InitDepend(&nsstr, v);
406 nsres = nsIDOMHTMLAnchorElement_SetName(This->nsanchor, &nsstr);
407 nsAString_Finish(&nsstr);
408 if(NS_FAILED(nsres))
409 return E_FAIL;
411 return S_OK;
414 static HRESULT WINAPI HTMLAnchorElement_get_name(IHTMLAnchorElement *iface, BSTR *p)
416 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
417 nsAString name_str;
418 nsresult nsres;
420 TRACE("(%p)->(%p)\n", This, p);
422 nsAString_Init(&name_str, NULL);
423 nsres = nsIDOMHTMLAnchorElement_GetName(This->nsanchor, &name_str);
425 return return_nsstr(nsres, &name_str, p);
428 static HRESULT WINAPI HTMLAnchorElement_put_host(IHTMLAnchorElement *iface, BSTR v)
430 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
431 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
432 return E_NOTIMPL;
435 static HRESULT WINAPI HTMLAnchorElement_get_host(IHTMLAnchorElement *iface, BSTR *p)
437 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
438 nsAString str;
439 nsresult nsres;
441 TRACE("(%p)->(%p)\n", This, p);
443 /* FIXME: IE always appends port number, even if it's implicit default number */
444 nsAString_InitDepend(&str, NULL);
445 nsres = nsIDOMHTMLAnchorElement_GetHost(This->nsanchor, &str);
446 return return_nsstr(nsres, &str, p);
449 static HRESULT WINAPI HTMLAnchorElement_put_hostname(IHTMLAnchorElement *iface, BSTR v)
451 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
452 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
453 return E_NOTIMPL;
456 static HRESULT WINAPI HTMLAnchorElement_get_hostname(IHTMLAnchorElement *iface, BSTR *p)
458 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
459 nsAString hostname_str;
460 nsresult nsres;
462 TRACE("(%p)->(%p)\n", This, p);
464 nsAString_Init(&hostname_str, NULL);
465 nsres = nsIDOMHTMLAnchorElement_GetHostname(This->nsanchor, &hostname_str);
466 return return_nsstr(nsres, &hostname_str, p);
469 static HRESULT WINAPI HTMLAnchorElement_put_pathname(IHTMLAnchorElement *iface, BSTR v)
471 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
472 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
473 return E_NOTIMPL;
476 static HRESULT WINAPI HTMLAnchorElement_get_pathname(IHTMLAnchorElement *iface, BSTR *p)
478 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
479 nsAString pathname_str;
480 nsresult nsres;
482 TRACE("(%p)->(%p)\n", This, p);
484 /* FIXME: IE prepends a slash for some protocols */
485 nsAString_Init(&pathname_str, NULL);
486 nsres = nsIDOMHTMLAnchorElement_GetPathname(This->nsanchor, &pathname_str);
487 return return_nsstr(nsres, &pathname_str, p);
490 static HRESULT WINAPI HTMLAnchorElement_put_port(IHTMLAnchorElement *iface, BSTR v)
492 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
493 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
494 return E_NOTIMPL;
497 static HRESULT WINAPI HTMLAnchorElement_get_port(IHTMLAnchorElement *iface, BSTR *p)
499 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
500 IUri *uri;
501 HRESULT hres;
502 DWORD port;
503 WCHAR buf[11];
504 int len;
505 BSTR str;
507 TRACE("(%p)->(%p)\n", This, p);
509 uri = get_anchor_uri(This);
510 if(!uri) {
511 WARN("Could not create IUri\n");
512 *p = NULL;
513 return S_OK;
516 hres = IUri_GetPort(uri, &port);
517 IUri_Release(uri);
518 if(FAILED(hres))
519 return hres;
520 if(hres != S_OK) {
521 *p = NULL;
522 return S_OK;
525 len = swprintf(buf, ARRAY_SIZE(buf), L"%u", port);
526 str = SysAllocStringLen(buf, len);
527 if (str)
528 *p = str;
529 else
530 hres = E_OUTOFMEMORY;
532 return hres;
535 static HRESULT WINAPI HTMLAnchorElement_put_protocol(IHTMLAnchorElement *iface, BSTR v)
537 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
538 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
539 return E_NOTIMPL;
542 static HRESULT WINAPI HTMLAnchorElement_get_protocol(IHTMLAnchorElement *iface, BSTR *p)
544 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
545 BSTR scheme;
546 size_t len;
547 IUri *uri;
548 HRESULT hres;
550 TRACE("(%p)->(%p)\n", This, p);
552 uri = get_anchor_uri(This);
553 if(!uri) {
554 WARN("Could not create IUri\n");
555 *p = NULL;
556 return S_OK;
559 hres = IUri_GetSchemeName(uri, &scheme);
560 IUri_Release(uri);
561 if(FAILED(hres))
562 return hres;
563 if(hres != S_OK) {
564 SysFreeString(scheme);
565 *p = NULL;
566 return S_OK;
569 len = SysStringLen(scheme);
570 if(len) {
571 *p = SysAllocStringLen(scheme, len + 1);
572 if(*p)
573 (*p)[len] = ':';
574 else
575 hres = E_OUTOFMEMORY;
576 }else {
577 *p = NULL;
579 SysFreeString(scheme);
580 return hres;
583 static HRESULT WINAPI HTMLAnchorElement_put_search(IHTMLAnchorElement *iface, BSTR v)
585 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
586 nsAString nsstr;
587 nsresult nsres;
589 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
591 nsAString_InitDepend(&nsstr, v);
592 nsres = nsIDOMHTMLAnchorElement_SetSearch(This->nsanchor, &nsstr);
593 nsAString_Finish(&nsstr);
594 if(NS_FAILED(nsres))
595 return E_FAIL;
597 return S_OK;
600 static HRESULT WINAPI HTMLAnchorElement_get_search(IHTMLAnchorElement *iface, BSTR *p)
602 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
603 nsAString search_str;
604 nsresult nsres;
606 TRACE("(%p)->(%p)\n", This, p);
608 nsAString_Init(&search_str, NULL);
609 nsres = nsIDOMHTMLAnchorElement_GetSearch(This->nsanchor, &search_str);
610 return return_nsstr(nsres, &search_str, p);
613 static HRESULT WINAPI HTMLAnchorElement_put_hash(IHTMLAnchorElement *iface, BSTR v)
615 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
616 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
617 return E_NOTIMPL;
620 static HRESULT WINAPI HTMLAnchorElement_get_hash(IHTMLAnchorElement *iface, BSTR *p)
622 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
623 nsAString hash_str;
624 nsresult nsres;
626 TRACE("(%p)->(%p)\n", This, p);
628 nsAString_Init(&hash_str, NULL);
629 nsres = nsIDOMHTMLAnchorElement_GetHash(This->nsanchor, &hash_str);
630 return return_nsstr(nsres, &hash_str, p);
633 static HRESULT WINAPI HTMLAnchorElement_put_onblur(IHTMLAnchorElement *iface, VARIANT v)
635 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
637 TRACE("(%p)->()\n", This);
639 return IHTMLElement2_put_onblur(&This->element.IHTMLElement2_iface, v);
642 static HRESULT WINAPI HTMLAnchorElement_get_onblur(IHTMLAnchorElement *iface, VARIANT *p)
644 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
646 TRACE("(%p)->(%p)\n", This, p);
648 return IHTMLElement2_get_onblur(&This->element.IHTMLElement2_iface, p);
651 static HRESULT WINAPI HTMLAnchorElement_put_onfocus(IHTMLAnchorElement *iface, VARIANT v)
653 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
655 TRACE("(%p)->()\n", This);
657 return IHTMLElement2_put_onfocus(&This->element.IHTMLElement2_iface, v);
660 static HRESULT WINAPI HTMLAnchorElement_get_onfocus(IHTMLAnchorElement *iface, VARIANT *p)
662 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
664 TRACE("(%p)->(%p)\n", This, p);
666 return IHTMLElement2_get_onfocus(&This->element.IHTMLElement2_iface, p);
669 static HRESULT WINAPI HTMLAnchorElement_put_accessKey(IHTMLAnchorElement *iface, BSTR v)
671 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
673 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
675 return IHTMLElement2_put_accessKey(&This->element.IHTMLElement2_iface, v);
678 static HRESULT WINAPI HTMLAnchorElement_get_accessKey(IHTMLAnchorElement *iface, BSTR *p)
680 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
682 TRACE("(%p)->(%p)\n", This, p);
684 return IHTMLElement2_get_accessKey(&This->element.IHTMLElement2_iface, p);
687 static HRESULT WINAPI HTMLAnchorElement_get_protocolLong(IHTMLAnchorElement *iface, BSTR *p)
689 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
690 FIXME("(%p)->(%p)\n", This, p);
691 return E_NOTIMPL;
694 static HRESULT WINAPI HTMLAnchorElement_get_mimeType(IHTMLAnchorElement *iface, BSTR *p)
696 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
697 FIXME("(%p)->(%p)\n", This, p);
698 return E_NOTIMPL;
701 static HRESULT WINAPI HTMLAnchorElement_get_nameProp(IHTMLAnchorElement *iface, BSTR *p)
703 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
704 FIXME("(%p)->(%p)\n", This, p);
705 return E_NOTIMPL;
708 static HRESULT WINAPI HTMLAnchorElement_put_tabIndex(IHTMLAnchorElement *iface, short v)
710 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
712 TRACE("(%p)->()\n", This);
714 return IHTMLElement2_put_tabIndex(&This->element.IHTMLElement2_iface, v);
717 static HRESULT WINAPI HTMLAnchorElement_get_tabIndex(IHTMLAnchorElement *iface, short *p)
719 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
721 TRACE("(%p)->(%p)\n", This, p);
723 return IHTMLElement2_get_tabIndex(&This->element.IHTMLElement2_iface, p);
726 static HRESULT WINAPI HTMLAnchorElement_focus(IHTMLAnchorElement *iface)
728 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
730 TRACE("(%p)\n", This);
732 return IHTMLElement2_focus(&This->element.IHTMLElement2_iface);
735 static HRESULT WINAPI HTMLAnchorElement_blur(IHTMLAnchorElement *iface)
737 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
739 TRACE("(%p)\n", This);
741 return IHTMLElement2_blur(&This->element.IHTMLElement2_iface);
744 static const IHTMLAnchorElementVtbl HTMLAnchorElementVtbl = {
745 HTMLAnchorElement_QueryInterface,
746 HTMLAnchorElement_AddRef,
747 HTMLAnchorElement_Release,
748 HTMLAnchorElement_GetTypeInfoCount,
749 HTMLAnchorElement_GetTypeInfo,
750 HTMLAnchorElement_GetIDsOfNames,
751 HTMLAnchorElement_Invoke,
752 HTMLAnchorElement_put_href,
753 HTMLAnchorElement_get_href,
754 HTMLAnchorElement_put_target,
755 HTMLAnchorElement_get_target,
756 HTMLAnchorElement_put_rel,
757 HTMLAnchorElement_get_rel,
758 HTMLAnchorElement_put_rev,
759 HTMLAnchorElement_get_rev,
760 HTMLAnchorElement_put_urn,
761 HTMLAnchorElement_get_urn,
762 HTMLAnchorElement_put_Methods,
763 HTMLAnchorElement_get_Methods,
764 HTMLAnchorElement_put_name,
765 HTMLAnchorElement_get_name,
766 HTMLAnchorElement_put_host,
767 HTMLAnchorElement_get_host,
768 HTMLAnchorElement_put_hostname,
769 HTMLAnchorElement_get_hostname,
770 HTMLAnchorElement_put_pathname,
771 HTMLAnchorElement_get_pathname,
772 HTMLAnchorElement_put_port,
773 HTMLAnchorElement_get_port,
774 HTMLAnchorElement_put_protocol,
775 HTMLAnchorElement_get_protocol,
776 HTMLAnchorElement_put_search,
777 HTMLAnchorElement_get_search,
778 HTMLAnchorElement_put_hash,
779 HTMLAnchorElement_get_hash,
780 HTMLAnchorElement_put_onblur,
781 HTMLAnchorElement_get_onblur,
782 HTMLAnchorElement_put_onfocus,
783 HTMLAnchorElement_get_onfocus,
784 HTMLAnchorElement_put_accessKey,
785 HTMLAnchorElement_get_accessKey,
786 HTMLAnchorElement_get_protocolLong,
787 HTMLAnchorElement_get_mimeType,
788 HTMLAnchorElement_get_nameProp,
789 HTMLAnchorElement_put_tabIndex,
790 HTMLAnchorElement_get_tabIndex,
791 HTMLAnchorElement_focus,
792 HTMLAnchorElement_blur
795 static inline HTMLAnchorElement *impl_from_DispatchEx(DispatchEx *iface)
797 return CONTAINING_RECORD(iface, HTMLAnchorElement, element.node.event_target.dispex);
800 static void *HTMLAnchorElement_query_interface(DispatchEx *dispex, REFIID riid)
802 HTMLAnchorElement *This = impl_from_DispatchEx(dispex);
804 if(IsEqualGUID(&IID_IHTMLAnchorElement, riid))
805 return &This->IHTMLAnchorElement_iface;
807 return HTMLElement_query_interface(&This->element.node.event_target.dispex, riid);
810 static void HTMLAnchorElement_traverse(DispatchEx *dispex, nsCycleCollectionTraversalCallback *cb)
812 HTMLAnchorElement *This = impl_from_DispatchEx(dispex);
813 HTMLDOMNode_traverse(dispex, cb);
815 if(This->nsanchor)
816 note_cc_edge((nsISupports*)This->nsanchor, "nsanchor", cb);
819 static void HTMLAnchorElement_unlink(DispatchEx *dispex)
821 HTMLAnchorElement *This = impl_from_DispatchEx(dispex);
822 HTMLDOMNode_unlink(dispex);
823 unlink_ref(&This->nsanchor);
826 static HRESULT HTMLAnchorElement_handle_event(DispatchEx *dispex, eventid_t eid, nsIDOMEvent *event, BOOL *prevent_default)
828 HTMLAnchorElement *This = impl_from_DispatchEx(dispex);
829 nsAString href_str, target_str;
830 nsresult nsres;
832 if(eid == EVENTID_CLICK) {
833 nsAString_Init(&href_str, NULL);
834 nsres = nsIDOMHTMLAnchorElement_GetHref(This->nsanchor, &href_str);
835 if (NS_FAILED(nsres)) {
836 ERR("Could not get anchor href: %08lx\n", nsres);
837 goto fallback;
840 nsAString_Init(&target_str, NULL);
841 nsres = nsIDOMHTMLAnchorElement_GetTarget(This->nsanchor, &target_str);
842 if (NS_FAILED(nsres)) {
843 ERR("Could not get anchor target: %08lx\n", nsres);
844 goto fallback;
847 return handle_link_click_event(&This->element, &href_str, &target_str, event, prevent_default);
849 fallback:
850 nsAString_Finish(&href_str);
851 nsAString_Finish(&target_str);
854 return HTMLElement_handle_event(&This->element.node.event_target.dispex, eid, event, prevent_default);
857 static const NodeImplVtbl HTMLAnchorElementImplVtbl = {
858 .clsid = &CLSID_HTMLAnchorElement,
859 .cpc_entries = HTMLElement_cpc,
860 .clone = HTMLElement_clone,
861 .get_attr_col = HTMLElement_get_attr_col,
864 static const event_target_vtbl_t HTMLAnchorElement_event_target_vtbl = {
866 HTMLELEMENT_DISPEX_VTBL_ENTRIES,
867 .query_interface= HTMLAnchorElement_query_interface,
868 .destructor = HTMLElement_destructor,
869 .traverse = HTMLAnchorElement_traverse,
870 .unlink = HTMLAnchorElement_unlink
872 HTMLELEMENT_EVENT_TARGET_VTBL_ENTRIES,
873 .handle_event = HTMLAnchorElement_handle_event
876 static const tid_t HTMLAnchorElement_iface_tids[] = {
877 IHTMLAnchorElement_tid,
878 HTMLELEMENT_TIDS,
882 static dispex_static_data_t HTMLAnchorElement_dispex = {
883 "HTMLAnchorElement",
884 &HTMLAnchorElement_event_target_vtbl.dispex_vtbl,
885 DispHTMLAnchorElement_tid,
886 HTMLAnchorElement_iface_tids,
887 HTMLElement_init_dispex_info
890 HRESULT HTMLAnchorElement_Create(HTMLDocumentNode *doc, nsIDOMElement *nselem, HTMLElement **elem)
892 HTMLAnchorElement *ret;
893 nsresult nsres;
895 ret = calloc(1, sizeof(HTMLAnchorElement));
896 if(!ret)
897 return E_OUTOFMEMORY;
899 ret->IHTMLAnchorElement_iface.lpVtbl = &HTMLAnchorElementVtbl;
900 ret->element.node.vtbl = &HTMLAnchorElementImplVtbl;
902 HTMLElement_Init(&ret->element, doc, nselem, &HTMLAnchorElement_dispex);
904 nsres = nsIDOMElement_QueryInterface(nselem, &IID_nsIDOMHTMLAnchorElement, (void**)&ret->nsanchor);
905 assert(nsres == NS_OK);
907 *elem = &ret->element;
908 return S_OK;