msvcrt: Simplify fseek implementation.
[wine/multimedia.git] / dlls / mshtml / htmlanchor.c
bloba7b87a80e53c1f066143fd7730b5bc753246837b
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 TRACE("target %s\n", debugstr_w(target));
91 if(*target && strcmpiW(target, _selfW)) {
92 if(!strcmpiW(target, _topW)) {
93 TRACE("target _top\n");
94 get_top_window(This->element.node.doc->basedoc.window, &window);
95 }else if(!strcmpiW(target, _parentW)) {
96 FIXME("Navigating to target _parent is not implemented\n");
97 nsAString_Finish(&target_str);
98 return S_OK;
99 }else {
100 HTMLOuterWindow *top_window;
102 get_top_window(This->element.node.doc->basedoc.window, &top_window);
104 hres = get_frame_by_name(top_window, target, TRUE, &window);
105 if(FAILED(hres) || !window) {
106 hres = navigate_anchor_window(This, target);
107 nsAString_Finish(&target_str);
108 return hres;
113 nsAString_Finish(&target_str);
115 nsAString_Init(&href_str, NULL);
116 nsres = nsIDOMHTMLAnchorElement_GetHref(This->nsanchor, &href_str);
117 if(NS_SUCCEEDED(nsres)) {
118 const PRUnichar *href;
120 nsAString_GetData(&href_str, &href);
121 if(*href) {
122 if(!window)
123 window = This->element.node.doc->basedoc.window;
124 hres = navigate_url(window, href, window->uri, BINDING_NAVIGATED);
125 }else {
126 TRACE("empty href\n");
127 hres = S_OK;
130 nsAString_Finish(&href_str);
131 return hres;
134 static inline HTMLAnchorElement *impl_from_IHTMLAnchorElement(IHTMLAnchorElement *iface)
136 return CONTAINING_RECORD(iface, HTMLAnchorElement, IHTMLAnchorElement_iface);
139 static HRESULT WINAPI HTMLAnchorElement_QueryInterface(IHTMLAnchorElement *iface,
140 REFIID riid, void **ppv)
142 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
144 return IHTMLDOMNode_QueryInterface(&This->element.node.IHTMLDOMNode_iface, riid, ppv);
147 static ULONG WINAPI HTMLAnchorElement_AddRef(IHTMLAnchorElement *iface)
149 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
151 return IHTMLDOMNode_AddRef(&This->element.node.IHTMLDOMNode_iface);
154 static ULONG WINAPI HTMLAnchorElement_Release(IHTMLAnchorElement *iface)
156 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
158 return IHTMLDOMNode_Release(&This->element.node.IHTMLDOMNode_iface);
161 static HRESULT WINAPI HTMLAnchorElement_GetTypeInfoCount(IHTMLAnchorElement *iface, UINT *pctinfo)
163 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
164 return IDispatchEx_GetTypeInfoCount(&This->element.node.dispex.IDispatchEx_iface, pctinfo);
167 static HRESULT WINAPI HTMLAnchorElement_GetTypeInfo(IHTMLAnchorElement *iface, UINT iTInfo,
168 LCID lcid, ITypeInfo **ppTInfo)
170 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
171 return IDispatchEx_GetTypeInfo(&This->element.node.dispex.IDispatchEx_iface, iTInfo, lcid,
172 ppTInfo);
175 static HRESULT WINAPI HTMLAnchorElement_GetIDsOfNames(IHTMLAnchorElement *iface, REFIID riid,
176 LPOLESTR *rgszNames, UINT cNames,
177 LCID lcid, DISPID *rgDispId)
179 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
180 return IDispatchEx_GetIDsOfNames(&This->element.node.dispex.IDispatchEx_iface, riid, rgszNames,
181 cNames, lcid, rgDispId);
184 static HRESULT WINAPI HTMLAnchorElement_Invoke(IHTMLAnchorElement *iface, DISPID dispIdMember,
185 REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
186 VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
188 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
189 return IDispatchEx_Invoke(&This->element.node.dispex.IDispatchEx_iface, dispIdMember, riid,
190 lcid, wFlags, pDispParams, pVarResult, pExcepInfo, puArgErr);
193 static HRESULT WINAPI HTMLAnchorElement_put_href(IHTMLAnchorElement *iface, BSTR v)
195 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
196 nsAString nsstr;
197 nsresult nsres;
199 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
201 nsAString_InitDepend(&nsstr, v);
202 nsres = nsIDOMHTMLAnchorElement_SetHref(This->nsanchor, &nsstr);
203 nsAString_Finish(&nsstr);
204 if(NS_FAILED(nsres))
205 return E_FAIL;
207 return S_OK;
210 static HRESULT WINAPI HTMLAnchorElement_get_href(IHTMLAnchorElement *iface, BSTR *p)
212 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
213 nsAString href_str;
214 nsresult nsres;
215 HRESULT hres;
217 TRACE("(%p)->(%p)\n", This, p);
219 nsAString_Init(&href_str, NULL);
220 nsres = nsIDOMHTMLAnchorElement_GetHref(This->nsanchor, &href_str);
221 if(NS_SUCCEEDED(nsres)) {
222 const PRUnichar *href;
224 nsAString_GetData(&href_str, &href);
225 hres = nsuri_to_url(href, TRUE, p);
226 }else {
227 ERR("GetHref failed: %08x\n", nsres);
228 hres = E_FAIL;
231 nsAString_Finish(&href_str);
232 return hres;
235 static HRESULT WINAPI HTMLAnchorElement_put_target(IHTMLAnchorElement *iface, BSTR v)
237 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
238 nsAString nsstr;
239 nsresult nsres;
241 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
243 nsAString_InitDepend(&nsstr, v);
244 nsres = nsIDOMHTMLAnchorElement_SetTarget(This->nsanchor, &nsstr);
245 nsAString_Finish(&nsstr);
246 if(NS_FAILED(nsres))
247 return E_FAIL;
249 return S_OK;
252 static HRESULT WINAPI HTMLAnchorElement_get_target(IHTMLAnchorElement *iface, BSTR *p)
254 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
255 nsAString target_str;
256 nsresult nsres;
258 TRACE("(%p)->(%p)\n", This, p);
260 nsAString_Init(&target_str, NULL);
261 nsres = nsIDOMHTMLAnchorElement_GetTarget(This->nsanchor, &target_str);
263 return return_nsstr(nsres, &target_str, p);
266 static HRESULT WINAPI HTMLAnchorElement_put_rel(IHTMLAnchorElement *iface, BSTR v)
268 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
269 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
270 return E_NOTIMPL;
273 static HRESULT WINAPI HTMLAnchorElement_get_rel(IHTMLAnchorElement *iface, BSTR *p)
275 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
276 FIXME("(%p)->(%p)\n", This, p);
277 return E_NOTIMPL;
280 static HRESULT WINAPI HTMLAnchorElement_put_rev(IHTMLAnchorElement *iface, BSTR v)
282 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
283 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
284 return E_NOTIMPL;
287 static HRESULT WINAPI HTMLAnchorElement_get_rev(IHTMLAnchorElement *iface, BSTR *p)
289 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
290 FIXME("(%p)->(%p)\n", This, p);
291 return E_NOTIMPL;
294 static HRESULT WINAPI HTMLAnchorElement_put_urn(IHTMLAnchorElement *iface, BSTR v)
296 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
297 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
298 return E_NOTIMPL;
301 static HRESULT WINAPI HTMLAnchorElement_get_urn(IHTMLAnchorElement *iface, BSTR *p)
303 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
304 FIXME("(%p)->(%p)\n", This, p);
305 return E_NOTIMPL;
308 static HRESULT WINAPI HTMLAnchorElement_put_Methods(IHTMLAnchorElement *iface, BSTR v)
310 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
311 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
312 return E_NOTIMPL;
315 static HRESULT WINAPI HTMLAnchorElement_get_Methods(IHTMLAnchorElement *iface, BSTR *p)
317 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
318 FIXME("(%p)->(%p)\n", This, p);
319 return E_NOTIMPL;
322 static HRESULT WINAPI HTMLAnchorElement_put_name(IHTMLAnchorElement *iface, BSTR v)
324 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
325 nsAString nsstr;
326 nsresult nsres;
328 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
330 nsAString_InitDepend(&nsstr, v);
331 nsres = nsIDOMHTMLAnchorElement_SetName(This->nsanchor, &nsstr);
332 nsAString_Finish(&nsstr);
333 if(NS_FAILED(nsres))
334 return E_FAIL;
336 return S_OK;
339 static HRESULT WINAPI HTMLAnchorElement_get_name(IHTMLAnchorElement *iface, BSTR *p)
341 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
342 nsAString name_str;
343 nsresult nsres;
345 TRACE("(%p)->(%p)\n", This, p);
347 nsAString_Init(&name_str, NULL);
348 nsres = nsIDOMHTMLAnchorElement_GetName(This->nsanchor, &name_str);
350 return return_nsstr(nsres, &name_str, p);
353 static HRESULT WINAPI HTMLAnchorElement_put_host(IHTMLAnchorElement *iface, BSTR v)
355 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
356 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
357 return E_NOTIMPL;
360 static HRESULT WINAPI HTMLAnchorElement_get_host(IHTMLAnchorElement *iface, BSTR *p)
362 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
363 FIXME("(%p)->(%p)\n", This, p);
364 return E_NOTIMPL;
367 static HRESULT WINAPI HTMLAnchorElement_put_hostname(IHTMLAnchorElement *iface, BSTR v)
369 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
370 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
371 return E_NOTIMPL;
374 static HRESULT WINAPI HTMLAnchorElement_get_hostname(IHTMLAnchorElement *iface, BSTR *p)
376 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
377 FIXME("(%p)->(%p)\n", This, p);
378 return E_NOTIMPL;
381 static HRESULT WINAPI HTMLAnchorElement_put_pathname(IHTMLAnchorElement *iface, BSTR v)
383 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
384 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
385 return E_NOTIMPL;
388 static HRESULT WINAPI HTMLAnchorElement_get_pathname(IHTMLAnchorElement *iface, BSTR *p)
390 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
391 FIXME("(%p)->(%p)\n", This, p);
392 return E_NOTIMPL;
395 static HRESULT WINAPI HTMLAnchorElement_put_port(IHTMLAnchorElement *iface, BSTR v)
397 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
398 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
399 return E_NOTIMPL;
402 static HRESULT WINAPI HTMLAnchorElement_get_port(IHTMLAnchorElement *iface, BSTR *p)
404 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
405 FIXME("(%p)->(%p)\n", This, p);
406 return E_NOTIMPL;
409 static HRESULT WINAPI HTMLAnchorElement_put_protocol(IHTMLAnchorElement *iface, BSTR v)
411 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
412 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
413 return E_NOTIMPL;
416 static HRESULT WINAPI HTMLAnchorElement_get_protocol(IHTMLAnchorElement *iface, BSTR *p)
418 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
419 FIXME("(%p)->(%p)\n", This, p);
420 return E_NOTIMPL;
423 static HRESULT WINAPI HTMLAnchorElement_put_search(IHTMLAnchorElement *iface, BSTR v)
425 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
426 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
427 return E_NOTIMPL;
430 static HRESULT WINAPI HTMLAnchorElement_get_search(IHTMLAnchorElement *iface, BSTR *p)
432 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
433 FIXME("(%p)->(%p)\n", This, p);
434 return E_NOTIMPL;
437 static HRESULT WINAPI HTMLAnchorElement_put_hash(IHTMLAnchorElement *iface, BSTR v)
439 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
440 FIXME("(%p)->(%s)\n", This, debugstr_w(v));
441 return E_NOTIMPL;
444 static HRESULT WINAPI HTMLAnchorElement_get_hash(IHTMLAnchorElement *iface, BSTR *p)
446 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
447 FIXME("(%p)->(%p)\n", This, p);
448 return E_NOTIMPL;
451 static HRESULT WINAPI HTMLAnchorElement_put_onblur(IHTMLAnchorElement *iface, VARIANT v)
453 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
455 TRACE("(%p)->()\n", This);
457 return IHTMLElement2_put_onblur(&This->element.IHTMLElement2_iface, v);
460 static HRESULT WINAPI HTMLAnchorElement_get_onblur(IHTMLAnchorElement *iface, VARIANT *p)
462 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
464 TRACE("(%p)->(%p)\n", This, p);
466 return IHTMLElement2_get_onblur(&This->element.IHTMLElement2_iface, p);
469 static HRESULT WINAPI HTMLAnchorElement_put_onfocus(IHTMLAnchorElement *iface, VARIANT v)
471 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
473 TRACE("(%p)->()\n", This);
475 return IHTMLElement2_put_onfocus(&This->element.IHTMLElement2_iface, v);
478 static HRESULT WINAPI HTMLAnchorElement_get_onfocus(IHTMLAnchorElement *iface, VARIANT *p)
480 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
482 TRACE("(%p)->(%p)\n", This, p);
484 return IHTMLElement2_get_onfocus(&This->element.IHTMLElement2_iface, p);
487 static HRESULT WINAPI HTMLAnchorElement_put_accessKey(IHTMLAnchorElement *iface, BSTR v)
489 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
491 TRACE("(%p)->(%s)\n", This, debugstr_w(v));
493 return IHTMLElement2_put_accessKey(&This->element.IHTMLElement2_iface, v);
496 static HRESULT WINAPI HTMLAnchorElement_get_accessKey(IHTMLAnchorElement *iface, BSTR *p)
498 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
500 TRACE("(%p)->(%p)\n", This, p);
502 return IHTMLElement2_get_accessKey(&This->element.IHTMLElement2_iface, p);
505 static HRESULT WINAPI HTMLAnchorElement_get_protocolLong(IHTMLAnchorElement *iface, BSTR *p)
507 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
508 FIXME("(%p)->(%p)\n", This, p);
509 return E_NOTIMPL;
512 static HRESULT WINAPI HTMLAnchorElement_get_mimeType(IHTMLAnchorElement *iface, BSTR *p)
514 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
515 FIXME("(%p)->(%p)\n", This, p);
516 return E_NOTIMPL;
519 static HRESULT WINAPI HTMLAnchorElement_get_nameProp(IHTMLAnchorElement *iface, BSTR *p)
521 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
522 FIXME("(%p)->(%p)\n", This, p);
523 return E_NOTIMPL;
526 static HRESULT WINAPI HTMLAnchorElement_put_tabIndex(IHTMLAnchorElement *iface, short v)
528 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
530 TRACE("(%p)->()\n", This);
532 return IHTMLElement2_put_tabIndex(&This->element.IHTMLElement2_iface, v);
535 static HRESULT WINAPI HTMLAnchorElement_get_tabIndex(IHTMLAnchorElement *iface, short *p)
537 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
539 TRACE("(%p)->(%p)\n", This, p);
541 return IHTMLElement2_get_tabIndex(&This->element.IHTMLElement2_iface, p);
544 static HRESULT WINAPI HTMLAnchorElement_focus(IHTMLAnchorElement *iface)
546 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
548 TRACE("(%p)\n", This);
550 return IHTMLElement2_focus(&This->element.IHTMLElement2_iface);
553 static HRESULT WINAPI HTMLAnchorElement_blur(IHTMLAnchorElement *iface)
555 HTMLAnchorElement *This = impl_from_IHTMLAnchorElement(iface);
557 TRACE("(%p)\n", This);
559 return IHTMLElement2_blur(&This->element.IHTMLElement2_iface);
562 static const IHTMLAnchorElementVtbl HTMLAnchorElementVtbl = {
563 HTMLAnchorElement_QueryInterface,
564 HTMLAnchorElement_AddRef,
565 HTMLAnchorElement_Release,
566 HTMLAnchorElement_GetTypeInfoCount,
567 HTMLAnchorElement_GetTypeInfo,
568 HTMLAnchorElement_GetIDsOfNames,
569 HTMLAnchorElement_Invoke,
570 HTMLAnchorElement_put_href,
571 HTMLAnchorElement_get_href,
572 HTMLAnchorElement_put_target,
573 HTMLAnchorElement_get_target,
574 HTMLAnchorElement_put_rel,
575 HTMLAnchorElement_get_rel,
576 HTMLAnchorElement_put_rev,
577 HTMLAnchorElement_get_rev,
578 HTMLAnchorElement_put_urn,
579 HTMLAnchorElement_get_urn,
580 HTMLAnchorElement_put_Methods,
581 HTMLAnchorElement_get_Methods,
582 HTMLAnchorElement_put_name,
583 HTMLAnchorElement_get_name,
584 HTMLAnchorElement_put_host,
585 HTMLAnchorElement_get_host,
586 HTMLAnchorElement_put_hostname,
587 HTMLAnchorElement_get_hostname,
588 HTMLAnchorElement_put_pathname,
589 HTMLAnchorElement_get_pathname,
590 HTMLAnchorElement_put_port,
591 HTMLAnchorElement_get_port,
592 HTMLAnchorElement_put_protocol,
593 HTMLAnchorElement_get_protocol,
594 HTMLAnchorElement_put_search,
595 HTMLAnchorElement_get_search,
596 HTMLAnchorElement_put_hash,
597 HTMLAnchorElement_get_hash,
598 HTMLAnchorElement_put_onblur,
599 HTMLAnchorElement_get_onblur,
600 HTMLAnchorElement_put_onfocus,
601 HTMLAnchorElement_get_onfocus,
602 HTMLAnchorElement_put_accessKey,
603 HTMLAnchorElement_get_accessKey,
604 HTMLAnchorElement_get_protocolLong,
605 HTMLAnchorElement_get_mimeType,
606 HTMLAnchorElement_get_nameProp,
607 HTMLAnchorElement_put_tabIndex,
608 HTMLAnchorElement_get_tabIndex,
609 HTMLAnchorElement_focus,
610 HTMLAnchorElement_blur
613 static inline HTMLAnchorElement *impl_from_HTMLDOMNode(HTMLDOMNode *iface)
615 return CONTAINING_RECORD(iface, HTMLAnchorElement, element.node);
618 static HRESULT HTMLAnchorElement_QI(HTMLDOMNode *iface, REFIID riid, void **ppv)
620 HTMLAnchorElement *This = impl_from_HTMLDOMNode(iface);
622 *ppv = NULL;
624 if(IsEqualGUID(&IID_IUnknown, riid)) {
625 TRACE("(%p)->(IID_IUnknown %p)\n", This, ppv);
626 *ppv = &This->IHTMLAnchorElement_iface;
627 }else if(IsEqualGUID(&IID_IDispatch, riid)) {
628 TRACE("(%p)->(IID_IDispatch %p)\n", This, ppv);
629 *ppv = &This->IHTMLAnchorElement_iface;
630 }else if(IsEqualGUID(&IID_IHTMLAnchorElement, riid)) {
631 TRACE("(%p)->(IID_IHTMLAnchorElement %p)\n", This, ppv);
632 *ppv = &This->IHTMLAnchorElement_iface;
635 if(*ppv) {
636 IUnknown_AddRef((IUnknown*)*ppv);
637 return S_OK;
640 return HTMLElement_QI(&This->element.node, riid, ppv);
643 static HRESULT HTMLAnchorElement_handle_event(HTMLDOMNode *iface, eventid_t eid, nsIDOMEvent *event, BOOL *prevent_default)
645 HTMLAnchorElement *This = impl_from_HTMLDOMNode(iface);
647 if(eid == EVENTID_CLICK) {
648 nsIDOMMouseEvent *mouse_event;
649 PRUint16 button;
650 nsresult nsres;
652 TRACE("CLICK\n");
654 nsres = nsIDOMEvent_QueryInterface(event, &IID_nsIDOMMouseEvent, (void**)&mouse_event);
655 assert(nsres == NS_OK);
657 nsres = nsIDOMMouseEvent_GetButton(mouse_event, &button);
658 assert(nsres == NS_OK);
660 nsIDOMMouseEvent_Release(mouse_event);
662 switch(button) {
663 case 0:
664 *prevent_default = TRUE;
665 return navigate_anchor(This);
666 case 1:
667 *prevent_default = TRUE;
668 return navigate_anchor_window(This, NULL);
669 default:
670 *prevent_default = FALSE;
671 return S_OK;
675 return HTMLElement_handle_event(&This->element.node, eid, event, prevent_default);
678 static const NodeImplVtbl HTMLAnchorElementImplVtbl = {
679 HTMLAnchorElement_QI,
680 HTMLElement_destructor,
681 HTMLElement_clone,
682 HTMLAnchorElement_handle_event,
683 HTMLElement_get_attr_col
686 static const tid_t HTMLAnchorElement_iface_tids[] = {
687 IHTMLAnchorElement_tid,
688 HTMLELEMENT_TIDS,
689 IHTMLTextContainer_tid,
690 IHTMLUniqueName_tid,
694 static dispex_static_data_t HTMLAnchorElement_dispex = {
695 NULL,
696 DispHTMLAnchorElement_tid,
697 NULL,
698 HTMLAnchorElement_iface_tids
701 HRESULT HTMLAnchorElement_Create(HTMLDocumentNode *doc, nsIDOMHTMLElement *nselem, HTMLElement **elem)
703 HTMLAnchorElement *ret;
704 nsresult nsres;
706 ret = heap_alloc_zero(sizeof(HTMLAnchorElement));
707 if(!ret)
708 return E_OUTOFMEMORY;
710 ret->IHTMLAnchorElement_iface.lpVtbl = &HTMLAnchorElementVtbl;
711 ret->element.node.vtbl = &HTMLAnchorElementImplVtbl;
713 HTMLElement_Init(&ret->element, doc, nselem, &HTMLAnchorElement_dispex);
715 nsres = nsIDOMHTMLElement_QueryInterface(nselem, &IID_nsIDOMHTMLAnchorElement, (void**)&ret->nsanchor);
717 /* Shere the reference with nsnode */
718 assert(nsres == NS_OK && (nsIDOMNode*)ret->nsanchor == ret->element.node.nsnode);
719 nsIDOMNode_Release(ret->element.node.nsnode);
721 *elem = &ret->element;
722 return S_OK;