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"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(mshtml
);
37 struct HTMLAnchorElement
{
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
;
51 nsAString_GetData(href_str
, &href
);
52 hres
= create_relative_uri(element
->node
.doc
->outer_window
, href
, &uri
);
56 hres
= navigate_new_window(element
->node
.doc
->outer_window
, uri
, target
, NULL
, NULL
);
61 HTMLOuterWindow
*get_target_window(HTMLOuterWindow
*window
, nsAString
*target_str
, BOOL
*use_new_window
)
63 HTMLOuterWindow
*top_window
, *ret_window
;
64 const PRUnichar
*target
;
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
);
77 if(!wcsicmp(target
, L
"_top")) {
78 get_top_window(window
, &top_window
);
79 IHTMLWindow2_AddRef(&top_window
->base
.IHTMLWindow2_iface
);
83 if(!wcsicmp(target
, L
"_parent")) {
85 WARN("Window has no parent, treat as self\n");
86 IHTMLWindow2_AddRef(&window
->base
.IHTMLWindow2_iface
);
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
;
102 IHTMLWindow2_AddRef(&ret_window
->base
.IHTMLWindow2_iface
);
106 static HRESULT
navigate_href(HTMLElement
*element
, nsAString
*href_str
, nsAString
*target_str
)
108 HTMLOuterWindow
*window
;
110 const PRUnichar
*href
;
113 window
= get_target_window(element
->node
.doc
->outer_window
, target_str
, &use_new_window
);
116 const PRUnichar
*target
;
117 nsAString_GetData(target_str
, &target
);
118 return navigate_href_new_window(element
, href_str
, target
);
124 nsAString_GetData(href_str
, &href
);
126 hres
= navigate_url(window
, href
, window
->uri_nofrag
, BINDING_NAVIGATED
);
128 TRACE("empty href\n");
131 IHTMLWindow2_Release(&window
->base
.IHTMLWindow2_iface
);
135 HRESULT
handle_link_click_event(HTMLElement
*element
, nsAString
*href_str
, nsAString
*target_str
,
136 nsIDOMEvent
*event
, BOOL
*prevent_default
)
138 nsIDOMMouseEvent
*mouse_event
;
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
);
155 *prevent_default
= TRUE
;
156 hres
= navigate_href(element
, href_str
, target_str
);
159 *prevent_default
= TRUE
;
160 hres
= navigate_href_new_window(element
, href_str
, NULL
);
163 *prevent_default
= FALSE
;
167 nsAString_Finish(href_str
);
168 nsAString_Finish(target_str
);
172 static IUri
*get_anchor_uri(HTMLAnchorElement
*anchor
)
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
);
186 ERR("GetHref failed: %08lx\n", nsres
);
189 nsAString_Finish(&href_str
);
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
,
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
);
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
);
269 static HRESULT WINAPI
HTMLAnchorElement_get_href(IHTMLAnchorElement
*iface
, BSTR
*p
)
271 HTMLAnchorElement
*This
= impl_from_IHTMLAnchorElement(iface
);
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
);
286 ERR("GetHref failed: %08lx\n", nsres
);
290 nsAString_Finish(&href_str
);
294 static HRESULT WINAPI
HTMLAnchorElement_put_target(IHTMLAnchorElement
*iface
, BSTR v
)
296 HTMLAnchorElement
*This
= impl_from_IHTMLAnchorElement(iface
);
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
);
311 static HRESULT WINAPI
HTMLAnchorElement_get_target(IHTMLAnchorElement
*iface
, BSTR
*p
)
313 HTMLAnchorElement
*This
= impl_from_IHTMLAnchorElement(iface
);
314 nsAString target_str
;
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
);
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
);
342 static HRESULT WINAPI
HTMLAnchorElement_get_rel(IHTMLAnchorElement
*iface
, BSTR
*p
)
344 HTMLAnchorElement
*This
= impl_from_IHTMLAnchorElement(iface
);
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
));
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
);
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
));
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
);
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
));
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
);
397 static HRESULT WINAPI
HTMLAnchorElement_put_name(IHTMLAnchorElement
*iface
, BSTR v
)
399 HTMLAnchorElement
*This
= impl_from_IHTMLAnchorElement(iface
);
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
);
414 static HRESULT WINAPI
HTMLAnchorElement_get_name(IHTMLAnchorElement
*iface
, BSTR
*p
)
416 HTMLAnchorElement
*This
= impl_from_IHTMLAnchorElement(iface
);
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
));
435 static HRESULT WINAPI
HTMLAnchorElement_get_host(IHTMLAnchorElement
*iface
, BSTR
*p
)
437 HTMLAnchorElement
*This
= impl_from_IHTMLAnchorElement(iface
);
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
));
456 static HRESULT WINAPI
HTMLAnchorElement_get_hostname(IHTMLAnchorElement
*iface
, BSTR
*p
)
458 HTMLAnchorElement
*This
= impl_from_IHTMLAnchorElement(iface
);
459 nsAString hostname_str
;
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
));
476 static HRESULT WINAPI
HTMLAnchorElement_get_pathname(IHTMLAnchorElement
*iface
, BSTR
*p
)
478 HTMLAnchorElement
*This
= impl_from_IHTMLAnchorElement(iface
);
479 nsAString pathname_str
;
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
));
497 static HRESULT WINAPI
HTMLAnchorElement_get_port(IHTMLAnchorElement
*iface
, BSTR
*p
)
499 HTMLAnchorElement
*This
= impl_from_IHTMLAnchorElement(iface
);
507 TRACE("(%p)->(%p)\n", This
, p
);
509 uri
= get_anchor_uri(This
);
511 WARN("Could not create IUri\n");
516 hres
= IUri_GetPort(uri
, &port
);
525 len
= swprintf(buf
, ARRAY_SIZE(buf
), L
"%u", port
);
526 str
= SysAllocStringLen(buf
, len
);
530 hres
= E_OUTOFMEMORY
;
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
));
542 static HRESULT WINAPI
HTMLAnchorElement_get_protocol(IHTMLAnchorElement
*iface
, BSTR
*p
)
544 HTMLAnchorElement
*This
= impl_from_IHTMLAnchorElement(iface
);
550 TRACE("(%p)->(%p)\n", This
, p
);
552 uri
= get_anchor_uri(This
);
554 WARN("Could not create IUri\n");
559 hres
= IUri_GetSchemeName(uri
, &scheme
);
564 SysFreeString(scheme
);
569 len
= SysStringLen(scheme
);
571 *p
= SysAllocStringLen(scheme
, len
+ 1);
575 hres
= E_OUTOFMEMORY
;
579 SysFreeString(scheme
);
583 static HRESULT WINAPI
HTMLAnchorElement_put_search(IHTMLAnchorElement
*iface
, BSTR v
)
585 HTMLAnchorElement
*This
= impl_from_IHTMLAnchorElement(iface
);
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
);
600 static HRESULT WINAPI
HTMLAnchorElement_get_search(IHTMLAnchorElement
*iface
, BSTR
*p
)
602 HTMLAnchorElement
*This
= impl_from_IHTMLAnchorElement(iface
);
603 nsAString search_str
;
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
));
620 static HRESULT WINAPI
HTMLAnchorElement_get_hash(IHTMLAnchorElement
*iface
, BSTR
*p
)
622 HTMLAnchorElement
*This
= impl_from_IHTMLAnchorElement(iface
);
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
);
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
);
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
);
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_HTMLDOMNode(HTMLDOMNode
*iface
)
797 return CONTAINING_RECORD(iface
, HTMLAnchorElement
, element
.node
);
800 static HRESULT
HTMLAnchorElement_QI(HTMLDOMNode
*iface
, REFIID riid
, void **ppv
)
802 HTMLAnchorElement
*This
= impl_from_HTMLDOMNode(iface
);
806 if(IsEqualGUID(&IID_IUnknown
, riid
)) {
807 TRACE("(%p)->(IID_IUnknown %p)\n", This
, ppv
);
808 *ppv
= &This
->IHTMLAnchorElement_iface
;
809 }else if(IsEqualGUID(&IID_IDispatch
, riid
)) {
810 TRACE("(%p)->(IID_IDispatch %p)\n", This
, ppv
);
811 *ppv
= &This
->IHTMLAnchorElement_iface
;
812 }else if(IsEqualGUID(&IID_IHTMLAnchorElement
, riid
)) {
813 TRACE("(%p)->(IID_IHTMLAnchorElement %p)\n", This
, ppv
);
814 *ppv
= &This
->IHTMLAnchorElement_iface
;
818 IUnknown_AddRef((IUnknown
*)*ppv
);
822 return HTMLElement_QI(&This
->element
.node
, riid
, ppv
);
825 static HRESULT
HTMLAnchorElement_handle_event(HTMLDOMNode
*iface
, DWORD eid
, nsIDOMEvent
*event
, BOOL
*prevent_default
)
827 HTMLAnchorElement
*This
= impl_from_HTMLDOMNode(iface
);
828 nsAString href_str
, target_str
;
831 if(eid
== EVENTID_CLICK
) {
832 nsAString_Init(&href_str
, NULL
);
833 nsres
= nsIDOMHTMLAnchorElement_GetHref(This
->nsanchor
, &href_str
);
834 if (NS_FAILED(nsres
)) {
835 ERR("Could not get anchor href: %08lx\n", nsres
);
839 nsAString_Init(&target_str
, NULL
);
840 nsres
= nsIDOMHTMLAnchorElement_GetTarget(This
->nsanchor
, &target_str
);
841 if (NS_FAILED(nsres
)) {
842 ERR("Could not get anchor target: %08lx\n", nsres
);
846 return handle_link_click_event(&This
->element
, &href_str
, &target_str
, event
, prevent_default
);
849 nsAString_Finish(&href_str
);
850 nsAString_Finish(&target_str
);
853 return HTMLElement_handle_event(&This
->element
.node
, eid
, event
, prevent_default
);
856 static void HTMLAnchorElement_traverse(HTMLDOMNode
*iface
, nsCycleCollectionTraversalCallback
*cb
)
858 HTMLAnchorElement
*This
= impl_from_HTMLDOMNode(iface
);
861 note_cc_edge((nsISupports
*)This
->nsanchor
, "This->nsanchor", cb
);
864 static void HTMLAnchorElement_unlink(HTMLDOMNode
*iface
)
866 HTMLAnchorElement
*This
= impl_from_HTMLDOMNode(iface
);
869 nsIDOMHTMLAnchorElement
*nsanchor
= This
->nsanchor
;
871 This
->nsanchor
= NULL
;
872 nsIDOMHTMLAnchorElement_Release(nsanchor
);
876 static const NodeImplVtbl HTMLAnchorElementImplVtbl
= {
877 &CLSID_HTMLAnchorElement
,
878 HTMLAnchorElement_QI
,
879 HTMLElement_destructor
,
882 HTMLAnchorElement_handle_event
,
883 HTMLElement_get_attr_col
,
893 HTMLAnchorElement_traverse
,
894 HTMLAnchorElement_unlink
897 static const tid_t HTMLAnchorElement_iface_tids
[] = {
898 IHTMLAnchorElement_tid
,
903 static dispex_static_data_t HTMLAnchorElement_dispex
= {
904 L
"HTMLAnchorElement",
906 DispHTMLAnchorElement_tid
,
907 HTMLAnchorElement_iface_tids
,
908 HTMLElement_init_dispex_info
911 HRESULT
HTMLAnchorElement_Create(HTMLDocumentNode
*doc
, nsIDOMElement
*nselem
, HTMLElement
**elem
)
913 HTMLAnchorElement
*ret
;
916 ret
= calloc(1, sizeof(HTMLAnchorElement
));
918 return E_OUTOFMEMORY
;
920 ret
->IHTMLAnchorElement_iface
.lpVtbl
= &HTMLAnchorElementVtbl
;
921 ret
->element
.node
.vtbl
= &HTMLAnchorElementImplVtbl
;
923 HTMLElement_Init(&ret
->element
, doc
, nselem
, &HTMLAnchorElement_dispex
);
925 nsres
= nsIDOMElement_QueryInterface(nselem
, &IID_nsIDOMHTMLAnchorElement
, (void**)&ret
->nsanchor
);
926 assert(nsres
== NS_OK
);
928 *elem
= &ret
->element
;