d3dcompiler: Store (and begin to use) location information for variables.
[wine/multimedia.git] / dlls / mshtml / htmlanchor.c
blob6e0fc7193f8249be9a9865d97bbe91c6516cacac
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>
21 #include <assert.h>
23 #define COBJMACROS
25 #include "windef.h"
26 #include "winbase.h"
27 #include "winuser.h"
28 #include "ole2.h"
30 #include "mshtml_private.h"
31 #include "htmlevent.h"
32 #include "binding.h"
34 #include "wine/debug.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(mshtml);
38 typedef struct {
39 HTMLElement element;
41 IHTMLAnchorElement IHTMLAnchorElement_iface;
43 nsIDOMHTMLAnchorElement *nsanchor;
44 } HTMLAnchorElement;
46 static HRESULT navigate_anchor_window(HTMLAnchorElement *This, const WCHAR *target)
48 nsAString href_str;
49 IUri *uri;
50 nsresult nsres;
51 HRESULT hres;
53 nsAString_Init(&href_str, NULL);
54 nsres = nsIDOMHTMLAnchorElement_GetHref(This->nsanchor, &href_str);
55 if(NS_SUCCEEDED(nsres)) {
56 const PRUnichar *href;
58 nsAString_GetData(&href_str, &href);
59 hres = create_relative_uri(This->element.node.doc->basedoc.window, href, &uri);
60 }else {
61 ERR("Could not get anchor href: %08x\n", nsres);
62 hres = E_FAIL;
64 nsAString_Finish(&href_str);
65 if(FAILED(hres))
66 return hres;
68 hres = navigate_new_window(This->element.node.doc->basedoc.window, uri, target, NULL);
69 IUri_Release(uri);
70 return hres;
73 static HRESULT navigate_anchor(HTMLAnchorElement *This)
75 nsAString href_str, target_str;
76 HTMLOuterWindow *window = NULL;
77 nsresult nsres;
78 HRESULT hres = E_FAIL;
80 static const WCHAR _parentW[] = {'p','a','r','e','n','t',0};
81 static const WCHAR _selfW[] = {'_','s','e','l','f',0};
82 static const WCHAR _topW[] = {'_','t','o','p',0};
84 nsAString_Init(&target_str, NULL);
85 nsres = nsIDOMHTMLAnchorElement_GetTarget(This->nsanchor, &target_str);
86 if(NS_SUCCEEDED(nsres)) {
87 const PRUnichar *target;
89 nsAString_GetData(&target_str, &target);
90 if(*target && strcmpiW(target, _selfW)) {
91 if(!strcmpiW(target, _topW)) {
92 TRACE("target _top\n");
93 get_top_window(This->element.node.doc->basedoc.window, &window);
94 }else if(!strcmpiW(target, _parentW)) {
95 FIXME("Navigating to target _parent is not implemented\n");
96 nsAString_Finish(&target_str);
97 return S_OK;
98 }else {
99 hres = navigate_anchor_window(This, target);
100 nsAString_Finish(&target_str);
101 return hres;
105 nsAString_Finish(&target_str);
107 nsAString_Init(&href_str, NULL);
108 nsres = nsIDOMHTMLAnchorElement_GetHref(This->nsanchor, &href_str);
109 if(NS_SUCCEEDED(nsres)) {
110 const PRUnichar *href;
112 nsAString_GetData(&href_str, &href);
113 if(*href) {
114 if(!window)
115 window = This->element.node.doc->basedoc.window;
116 hres = navigate_url(window, href, window->url);
117 }else {
118 TRACE("empty href\n");
119 hres = S_OK;
122 nsAString_Finish(&href_str);
123 return hres;
126 static inline HTMLAnchorElement *impl_from_IHTMLAnchorElement(IHTMLAnchorElement *iface)
128 return CONTAINING_RECORD(iface, HTMLAnchorElement, IHTMLAnchorElement_iface);
131 static HRESULT WINAPI HTMLAnchorElement_QueryInterface(IHTMLAnchorElement *iface,
132 REFIID riid, void **ppv)
134 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
136 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
139 static ULONG WINAPI HTMLAnchorElement_AddRef(IHTMLAnchorElement *iface)
141 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
143 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
146 static ULONG WINAPI HTMLAnchorElement_Release(IHTMLAnchorElement *iface)
148 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
150 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
153 static HRESULT WINAPI HTMLAnchorElement_GetTypeInfoCount(IHTMLAnchorElement *iface, UINT *pctinfo)
155 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
156 return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
159 static HRESULT WINAPI HTMLAnchorElement_GetTypeInfo(IHTMLAnchorElement *iface, UINT iTInfo,
160 LCID lcid, ITypeInfo **ppTInfo)
162 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
163 return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
164 ppTInfo);
167 static HRESULT WINAPI HTMLAnchorElement_GetIDsOfNames(IHTMLAnchorElement *iface, REFIID riid,
168 LPOLESTR *rgszNames, UINT cNames,
169 LCID lcid, DISPID *rgDispId)
171 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
172 return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
173 cNames, lcid, rgDispId);
176 static HRESULT WINAPI HTMLAnchorElement_Invoke(IHTMLAnchorElement *iface, DISPID dispIdMember,
177 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
178 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
180 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
181 return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
182 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
185 static HRESULT WINAPI HTMLAnchorElement_put_href(IHTMLAnchorElement *iface, BSTR v)
187 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
188 nsAString nsstr;
189 nsresult nsres;
191 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
193 nsAString_InitDepend(&nsstr, v);
194 nsres = nsIDOMHTMLAnchorElement_SetHref(This->nsanchor, &nsstr);
195 nsAString_Finish(&nsstr);
196 if(NS_FAILED(nsres))
197 return E_FAIL;
199 return S_OK;
202 static HRESULT WINAPI HTMLAnchorElement_get_href(IHTMLAnchorElement *iface, BSTR *p)
204 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
205 nsAString href_str;
206 nsresult nsres;
207 HRESULT hres;
209 TRACE("(%p)->(%p)\n", This, p);
211 nsAString_Init(&href_str, NULL);
212 nsres = nsIDOMHTMLAnchorElement_GetHref(This->nsanchor, &href_str);
213 if(NS_SUCCEEDED(nsres)) {
214 const PRUnichar *href;
216 nsAString_GetData(&href_str, &href);
217 hres = nsuri_to_url(href, TRUE, p);
218 }else {
219 ERR("GetHref failed: %08x\n", nsres);
220 hres = E_FAIL;
223 nsAString_Finish(&href_str);
224 return hres;
227 static HRESULT WINAPI HTMLAnchorElement_put_target(IHTMLAnchorElement *iface, BSTR v)
229 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
230 nsAString nsstr;
231 nsresult nsres;
233 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
235 nsAString_InitDepend(&nsstr, v);
236 nsres = nsIDOMHTMLAnchorElement_SetTarget(This->nsanchor, &nsstr);
237 nsAString_Finish(&nsstr);
238 if(NS_FAILED(nsres))
239 return E_FAIL;
241 return S_OK;
244 static HRESULT WINAPI HTMLAnchorElement_get_target(IHTMLAnchorElement *iface, BSTR *p)
246 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
247 nsAString target_str;
248 nsresult nsres;
250 TRACE("(%p)->(%p)\n", This, p);
252 nsAString_Init(&target_str, NULL);
253 nsres = nsIDOMHTMLAnchorElement_GetTarget(This->nsanchor, &target_str);
255 return return_nsstr(nsres, &target_str, p);
258 static HRESULT WINAPI HTMLAnchorElement_put_rel(IHTMLAnchorElement *iface, BSTR v)
260 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
261 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
262 return E_NOTIMPL;
265 static HRESULT WINAPI HTMLAnchorElement_get_rel(IHTMLAnchorElement *iface, BSTR *p)
267 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
268 FIXME("(%p)->(%p)\n", This, p);
269 return E_NOTIMPL;
272 static HRESULT WINAPI HTMLAnchorElement_put_rev(IHTMLAnchorElement *iface, BSTR v)
274 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
275 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
276 return E_NOTIMPL;
279 static HRESULT WINAPI HTMLAnchorElement_get_rev(IHTMLAnchorElement *iface, BSTR *p)
281 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
282 FIXME("(%p)->(%p)\n", This, p);
283 return E_NOTIMPL;
286 static HRESULT WINAPI HTMLAnchorElement_put_urn(IHTMLAnchorElement *iface, BSTR v)
288 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
289 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
290 return E_NOTIMPL;
293 static HRESULT WINAPI HTMLAnchorElement_get_urn(IHTMLAnchorElement *iface, BSTR *p)
295 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
296 FIXME("(%p)->(%p)\n", This, p);
297 return E_NOTIMPL;
300 static HRESULT WINAPI HTMLAnchorElement_put_Methods(IHTMLAnchorElement *iface, BSTR v)
302 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
303 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
304 return E_NOTIMPL;
307 static HRESULT WINAPI HTMLAnchorElement_get_Methods(IHTMLAnchorElement *iface, BSTR *p)
309 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
310 FIXME("(%p)->(%p)\n", This, p);
311 return E_NOTIMPL;
314 static HRESULT WINAPI HTMLAnchorElement_put_name(IHTMLAnchorElement *iface, BSTR v)
316 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
317 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
318 return E_NOTIMPL;
321 static HRESULT WINAPI HTMLAnchorElement_get_name(IHTMLAnchorElement *iface, BSTR *p)
323 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
324 FIXME("(%p)->(%p)\n", This, p);
325 return E_NOTIMPL;
328 static HRESULT WINAPI HTMLAnchorElement_put_host(IHTMLAnchorElement *iface, BSTR v)
330 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
331 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
332 return E_NOTIMPL;
335 static HRESULT WINAPI HTMLAnchorElement_get_host(IHTMLAnchorElement *iface, BSTR *p)
337 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
338 FIXME("(%p)->(%p)\n", This, p);
339 return E_NOTIMPL;
342 static HRESULT WINAPI HTMLAnchorElement_put_hostname(IHTMLAnchorElement *iface, BSTR v)
344 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
345 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
346 return E_NOTIMPL;
349 static HRESULT WINAPI HTMLAnchorElement_get_hostname(IHTMLAnchorElement *iface, BSTR *p)
351 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
352 FIXME("(%p)->(%p)\n", This, p);
353 return E_NOTIMPL;
356 static HRESULT WINAPI HTMLAnchorElement_put_pathname(IHTMLAnchorElement *iface, BSTR v)
358 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
359 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
360 return E_NOTIMPL;
363 static HRESULT WINAPI HTMLAnchorElement_get_pathname(IHTMLAnchorElement *iface, BSTR *p)
365 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
366 FIXME("(%p)->(%p)\n", This, p);
367 return E_NOTIMPL;
370 static HRESULT WINAPI HTMLAnchorElement_put_port(IHTMLAnchorElement *iface, BSTR v)
372 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
373 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
374 return E_NOTIMPL;
377 static HRESULT WINAPI HTMLAnchorElement_get_port(IHTMLAnchorElement *iface, BSTR *p)
379 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
380 FIXME("(%p)->(%p)\n", This, p);
381 return E_NOTIMPL;
384 static HRESULT WINAPI HTMLAnchorElement_put_protocol(IHTMLAnchorElement *iface, BSTR v)
386 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
387 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
388 return E_NOTIMPL;
391 static HRESULT WINAPI HTMLAnchorElement_get_protocol(IHTMLAnchorElement *iface, BSTR *p)
393 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
394 FIXME("(%p)->(%p)\n", This, p);
395 return E_NOTIMPL;
398 static HRESULT WINAPI HTMLAnchorElement_put_search(IHTMLAnchorElement *iface, BSTR v)
400 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
401 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
402 return E_NOTIMPL;
405 static HRESULT WINAPI HTMLAnchorElement_get_search(IHTMLAnchorElement *iface, BSTR *p)
407 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
408 FIXME("(%p)->(%p)\n", This, p);
409 return E_NOTIMPL;
412 static HRESULT WINAPI HTMLAnchorElement_put_hash(IHTMLAnchorElement *iface, BSTR v)
414 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
415 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
416 return E_NOTIMPL;
419 static HRESULT WINAPI HTMLAnchorElement_get_hash(IHTMLAnchorElement *iface, BSTR *p)
421 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
422 FIXME("(%p)->(%p)\n", This, p);
423 return E_NOTIMPL;
426 static HRESULT WINAPI HTMLAnchorElement_put_onblur(IHTMLAnchorElement *iface, VARIANT v)
428 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
430 TRACE("(%p)->()\n", This);
432 return IHTMLElement2_put_onblur(&This->element.IHTMLElement2_iface, v);
435 static HRESULT WINAPI HTMLAnchorElement_get_onblur(IHTMLAnchorElement *iface, VARIANT *p)
437 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
439 TRACE("(%p)->(%p)\n", This, p);
441 return IHTMLElement2_get_onblur(&This->element.IHTMLElement2_iface, p);
444 static HRESULT WINAPI HTMLAnchorElement_put_onfocus(IHTMLAnchorElement *iface, VARIANT v)
446 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
448 TRACE("(%p)->()\n", This);
450 return IHTMLElement2_put_onfocus(&This->element.IHTMLElement2_iface, v);
453 static HRESULT WINAPI HTMLAnchorElement_get_onfocus(IHTMLAnchorElement *iface, VARIANT *p)
455 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
457 TRACE("(%p)->(%p)\n", This, p);
459 return IHTMLElement2_get_onfocus(&This->element.IHTMLElement2_iface, p);
462 static HRESULT WINAPI HTMLAnchorElement_put_accessKey(IHTMLAnchorElement *iface, BSTR v)
464 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
466 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
468 return IHTMLElement2_put_accessKey(&This->element.IHTMLElement2_iface, v);
471 static HRESULT WINAPI HTMLAnchorElement_get_accessKey(IHTMLAnchorElement *iface, BSTR *p)
473 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
475 TRACE("(%p)->(%p)\n", This, p);
477 return IHTMLElement2_get_accessKey(&This->element.IHTMLElement2_iface, p);
480 static HRESULT WINAPI HTMLAnchorElement_get_protocolLong(IHTMLAnchorElement *iface, BSTR *p)
482 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
483 FIXME("(%p)->(%p)\n", This, p);
484 return E_NOTIMPL;
487 static HRESULT WINAPI HTMLAnchorElement_get_mimeType(IHTMLAnchorElement *iface, BSTR *p)
489 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
490 FIXME("(%p)->(%p)\n", This, p);
491 return E_NOTIMPL;
494 static HRESULT WINAPI HTMLAnchorElement_get_nameProp(IHTMLAnchorElement *iface, BSTR *p)
496 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
497 FIXME("(%p)->(%p)\n", This, p);
498 return E_NOTIMPL;
501 static HRESULT WINAPI HTMLAnchorElement_put_tabIndex(IHTMLAnchorElement *iface, short v)
503 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
505 TRACE("(%p)->()\n", This);
507 return IHTMLElement2_put_tabIndex(&This->element.IHTMLElement2_iface, v);
510 static HRESULT WINAPI HTMLAnchorElement_get_tabIndex(IHTMLAnchorElement *iface, short *p)
512 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
514 TRACE("(%p)->(%p)\n", This, p);
516 return IHTMLElement2_get_tabIndex(&This->element.IHTMLElement2_iface, p);
519 static HRESULT WINAPI HTMLAnchorElement_focus(IHTMLAnchorElement *iface)
521 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
523 TRACE("(%p)\n", This);
525 return IHTMLElement2_focus(&This->element.IHTMLElement2_iface);
528 static HRESULT WINAPI HTMLAnchorElement_blur(IHTMLAnchorElement *iface)
530 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
532 TRACE("(%p)\n", This);
534 return IHTMLElement2_blur(&This->element.IHTMLElement2_iface);
537 static const IHTMLAnchorElementVtbl HTMLAnchorElementVtbl = {
538 HTMLAnchorElement_QueryInterface,
539 HTMLAnchorElement_AddRef,
540 HTMLAnchorElement_Release,
541 HTMLAnchorElement_GetTypeInfoCount,
542 HTMLAnchorElement_GetTypeInfo,
543 HTMLAnchorElement_GetIDsOfNames,
544 HTMLAnchorElement_Invoke,
545 HTMLAnchorElement_put_href,
546 HTMLAnchorElement_get_href,
547 HTMLAnchorElement_put_target,
548 HTMLAnchorElement_get_target,
549 HTMLAnchorElement_put_rel,
550 HTMLAnchorElement_get_rel,
551 HTMLAnchorElement_put_rev,
552 HTMLAnchorElement_get_rev,
553 HTMLAnchorElement_put_urn,
554 HTMLAnchorElement_get_urn,
555 HTMLAnchorElement_put_Methods,
556 HTMLAnchorElement_get_Methods,
557 HTMLAnchorElement_put_name,
558 HTMLAnchorElement_get_name,
559 HTMLAnchorElement_put_host,
560 HTMLAnchorElement_get_host,
561 HTMLAnchorElement_put_hostname,
562 HTMLAnchorElement_get_hostname,
563 HTMLAnchorElement_put_pathname,
564 HTMLAnchorElement_get_pathname,
565 HTMLAnchorElement_put_port,
566 HTMLAnchorElement_get_port,
567 HTMLAnchorElement_put_protocol,
568 HTMLAnchorElement_get_protocol,
569 HTMLAnchorElement_put_search,
570 HTMLAnchorElement_get_search,
571 HTMLAnchorElement_put_hash,
572 HTMLAnchorElement_get_hash,
573 HTMLAnchorElement_put_onblur,
574 HTMLAnchorElement_get_onblur,
575 HTMLAnchorElement_put_onfocus,
576 HTMLAnchorElement_get_onfocus,
577 HTMLAnchorElement_put_accessKey,
578 HTMLAnchorElement_get_accessKey,
579 HTMLAnchorElement_get_protocolLong,
580 HTMLAnchorElement_get_mimeType,
581 HTMLAnchorElement_get_nameProp,
582 HTMLAnchorElement_put_tabIndex,
583 HTMLAnchorElement_get_tabIndex,
584 HTMLAnchorElement_focus,
585 HTMLAnchorElement_blur
588 static inline HTMLAnchorElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
590 return CONTAINING_RECORD(iface, HTMLAnchorElement, element.node);
593 static HRESULT HTMLAnchorElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
595 HTMLAnchorElement *This = impl_from_HTMLDOMNode(iface);
597 *ppv = NULL;
599 if(IsEqualGUID(&IID_IUnknown, riid)) {
600 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
601 *ppv = &This->IHTMLAnchorElement_iface;
602 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
603 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
604 *ppv = &This->IHTMLAnchorElement_iface;
605 }else if(IsEqualGUID(&IID_IHTMLAnchorElement, riid)) {
606 TRACE("(%p)->(IID_IHTMLAnchorElement %p)\n", This, ppv);
607 *ppv = &This->IHTMLAnchorElement_iface;
610 if(*ppv) {
611 IUnknown_AddRef((IUnknown*)*ppv);
612 return S_OK;
615 return HTMLElement_QI(&This->element.node, riid, ppv);
618 static HRESULT HTMLAnchorElement_handle_event(HTMLDOMNode *iface, eventid_t eid, nsIDOMEvent *event, BOOL *prevent_default)
620 HTMLAnchorElement *This = impl_from_HTMLDOMNode(iface);
622 if(eid == EVENTID_CLICK) {
623 nsIDOMMouseEvent *mouse_event;
624 PRUint16 button;
625 nsresult nsres;
627 TRACE("CLICK\n");
629 nsres = nsIDOMEvent_QueryInterface(event, &IID_nsIDOMMouseEvent, (void**)&mouse_event);
630 assert(nsres == NS_OK);
632 nsres = nsIDOMMouseEvent_GetButton(mouse_event, &button);
633 assert(nsres == NS_OK);
635 nsIDOMMouseEvent_Release(mouse_event);
637 switch(button) {
638 case 0:
639 *prevent_default = TRUE;
640 return navigate_anchor(This);
641 case 1:
642 *prevent_default = TRUE;
643 return navigate_anchor_window(This, NULL);
644 default:
645 *prevent_default = FALSE;
646 return S_OK;
650 return S_OK;
653 static const NodeImplVtbl HTMLAnchorElementImplVtbl = {
654 HTMLAnchorElement_QI,
655 HTMLElement_destructor,
656 HTMLElement_clone,
657 HTMLElement_get_attr_col,
658 NULL,
659 NULL,
660 HTMLAnchorElement_handle_event
663 static const tid_t HTMLAnchorElement_iface_tids[] = {
664 IHTMLAnchorElement_tid,
665 HTMLELEMENT_TIDS,
666 IHTMLTextContainer_tid,
667 IHTMLUniqueName_tid,
671 static dispex_static_data_t HTMLAnchorElement_dispex = {
672 NULL,
673 DispHTMLAnchorElement_tid,
674 NULL,
675 HTMLAnchorElement_iface_tids
678 HRESULT HTMLAnchorElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
680 HTMLAnchorElement *ret;
681 nsresult nsres;
683 ret = heap_alloc_zero(sizeof(HTMLAnchorElement));
684 if(!ret)
685 return E_OUTOFMEMORY;
687 ret->IHTMLAnchorElement_iface.lpVtbl = &HTMLAnchorElementVtbl;
688 ret->element.node.vtbl = &HTMLAnchorElementImplVtbl;
690 HTMLElement_Init(&ret->element, doc, nselem, &HTMLAnchorElement_dispex);
692 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLAnchorElement, (void**)&ret->nsanchor);
694 /* Shere the reference with nsnode */
695 assert(nsres == NS_OK && (nsIDOMNode*)ret->nsanchor == ret->element.node.nsnode);
696 nsIDOMNode_Release(ret->element.node.nsnode);
698 *elem = &ret->element;
699 return S_OK;