ReactOS 0.4.15-dev-8344-g0574987
htmlevent.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct HTMLEventObj HTMLEventObj
 

Enumerations

enum  eventid_t {
  EVENTID_ABORT , EVENTID_BEFOREUNLOAD , EVENTID_BLUR , EVENTID_CHANGE ,
  EVENTID_CLICK , EVENTID_CONTEXTMENU , EVENTID_DATAAVAILABLE , EVENTID_DBLCLICK ,
  EVENTID_DRAG , EVENTID_DRAGSTART , EVENTID_ERROR , EVENTID_FOCUS ,
  EVENTID_FOCUSIN , EVENTID_HELP , EVENTID_KEYDOWN , EVENTID_KEYPRESS ,
  EVENTID_KEYUP , EVENTID_LOAD , EVENTID_MOUSEDOWN , EVENTID_MOUSEMOVE ,
  EVENTID_MOUSEOUT , EVENTID_MOUSEOVER , EVENTID_MOUSEUP , EVENTID_MOUSEWHEEL ,
  EVENTID_PASTE , EVENTID_READYSTATECHANGE , EVENTID_RESIZE , EVENTID_SCROLL ,
  EVENTID_SELECTSTART , EVENTID_SUBMIT , EVENTID_LAST
}
 

Functions

eventid_t str_to_eid (LPCWSTR) DECLSPEC_HIDDEN
 
void check_event_attr (HTMLDocumentNode *, nsIDOMHTMLElement *) DECLSPEC_HIDDEN
 
void release_event_target (event_target_t *) DECLSPEC_HIDDEN
 
void fire_event (HTMLDocumentNode *, eventid_t, BOOL, nsIDOMNode *, nsIDOMEvent *, IDispatch *) DECLSPEC_HIDDEN
 
HRESULT set_event_handler (EventTarget *, eventid_t, VARIANT *) DECLSPEC_HIDDEN
 
HRESULT get_event_handler (EventTarget *, eventid_t, VARIANT *) DECLSPEC_HIDDEN
 
HRESULT attach_event (EventTarget *, BSTR, IDispatch *, VARIANT_BOOL *) DECLSPEC_HIDDEN
 
HRESULT detach_event (EventTarget *, BSTR, IDispatch *) DECLSPEC_HIDDEN
 
HRESULT dispatch_event (HTMLDOMNode *, const WCHAR *, VARIANT *, VARIANT_BOOL *) DECLSPEC_HIDDEN
 
HRESULT call_fire_event (HTMLDOMNode *, eventid_t) DECLSPEC_HIDDEN
 
void update_doc_cp_events (HTMLDocumentNode *, cp_static_data_t *) DECLSPEC_HIDDEN
 
HRESULT doc_init_events (HTMLDocumentNode *) DECLSPEC_HIDDEN
 
void detach_events (HTMLDocumentNode *doc) DECLSPEC_HIDDEN
 
HRESULT create_event_obj (IHTMLEventObj **) DECLSPEC_HIDDEN
 
void bind_target_event (HTMLDocumentNode *, EventTarget *, const WCHAR *, IDispatch *) DECLSPEC_HIDDEN
 
HRESULT ensure_doc_nsevent_handler (HTMLDocumentNode *, eventid_t) DECLSPEC_HIDDEN
 
void call_event_handlers (HTMLDocumentNode *, HTMLEventObj *, EventTarget *, ConnectionPointContainer *, eventid_t, IDispatch *)
 
void init_nsevents (HTMLDocumentNode *) DECLSPEC_HIDDEN
 
void release_nsevents (HTMLDocumentNode *) DECLSPEC_HIDDEN
 
void add_nsevent_listener (HTMLDocumentNode *, nsIDOMNode *, LPCWSTR) DECLSPEC_HIDDEN
 
void detach_nsevent (HTMLDocumentNode *, const WCHAR *) DECLSPEC_HIDDEN
 
static HRESULT set_node_event (HTMLDOMNode *node, eventid_t eid, VARIANT *var)
 
static HRESULT get_node_event (HTMLDOMNode *node, eventid_t eid, VARIANT *var)
 
static HRESULT set_doc_event (HTMLDocument *doc, eventid_t eid, VARIANT *var)
 
static HRESULT get_doc_event (HTMLDocument *doc, eventid_t eid, VARIANT *var)
 

Typedef Documentation

◆ HTMLEventObj

Definition at line 72 of file htmlevent.h.

Enumeration Type Documentation

◆ eventid_t

Enumerator
EVENTID_ABORT 
EVENTID_BEFOREUNLOAD 
EVENTID_BLUR 
EVENTID_CHANGE 
EVENTID_CLICK 
EVENTID_CONTEXTMENU 
EVENTID_DATAAVAILABLE 
EVENTID_DBLCLICK 
EVENTID_DRAG 
EVENTID_DRAGSTART 
EVENTID_ERROR 
EVENTID_FOCUS 
EVENTID_FOCUSIN 
EVENTID_HELP 
EVENTID_KEYDOWN 
EVENTID_KEYPRESS 
EVENTID_KEYUP 
EVENTID_LOAD 
EVENTID_MOUSEDOWN 
EVENTID_MOUSEMOVE 
EVENTID_MOUSEOUT 
EVENTID_MOUSEOVER 
EVENTID_MOUSEUP 
EVENTID_MOUSEWHEEL 
EVENTID_PASTE 
EVENTID_READYSTATECHANGE 
EVENTID_RESIZE 
EVENTID_SCROLL 
EVENTID_SELECTSTART 
EVENTID_SUBMIT 
EVENTID_LAST 

Definition at line 21 of file htmlevent.h.

21 {
53} eventid_t;
eventid_t
Definition: htmlevent.h:21
@ EVENTID_MOUSEWHEEL
Definition: htmlevent.h:45
@ EVENTID_PASTE
Definition: htmlevent.h:46
@ EVENTID_DRAGSTART
Definition: htmlevent.h:31
@ EVENTID_SUBMIT
Definition: htmlevent.h:51
@ EVENTID_BEFOREUNLOAD
Definition: htmlevent.h:23
@ EVENTID_BLUR
Definition: htmlevent.h:24
@ EVENTID_CHANGE
Definition: htmlevent.h:25
@ EVENTID_DBLCLICK
Definition: htmlevent.h:29
@ EVENTID_MOUSEOVER
Definition: htmlevent.h:43
@ EVENTID_DATAAVAILABLE
Definition: htmlevent.h:28
@ EVENTID_SCROLL
Definition: htmlevent.h:49
@ EVENTID_CONTEXTMENU
Definition: htmlevent.h:27
@ EVENTID_KEYPRESS
Definition: htmlevent.h:37
@ EVENTID_ABORT
Definition: htmlevent.h:22
@ EVENTID_CLICK
Definition: htmlevent.h:26
@ EVENTID_MOUSEOUT
Definition: htmlevent.h:42
@ EVENTID_ERROR
Definition: htmlevent.h:32
@ EVENTID_MOUSEUP
Definition: htmlevent.h:44
@ EVENTID_SELECTSTART
Definition: htmlevent.h:50
@ EVENTID_LAST
Definition: htmlevent.h:52
@ EVENTID_RESIZE
Definition: htmlevent.h:48
@ EVENTID_READYSTATECHANGE
Definition: htmlevent.h:47
@ EVENTID_HELP
Definition: htmlevent.h:35
@ EVENTID_KEYUP
Definition: htmlevent.h:38
@ EVENTID_KEYDOWN
Definition: htmlevent.h:36
@ EVENTID_FOCUSIN
Definition: htmlevent.h:34
@ EVENTID_MOUSEMOVE
Definition: htmlevent.h:41
@ EVENTID_DRAG
Definition: htmlevent.h:30
@ EVENTID_MOUSEDOWN
Definition: htmlevent.h:40
@ EVENTID_LOAD
Definition: htmlevent.h:39
@ EVENTID_FOCUS
Definition: htmlevent.h:33

Function Documentation

◆ add_nsevent_listener()

void add_nsevent_listener ( HTMLDocumentNode doc,
nsIDOMNode nsnode,
LPCWSTR  type 
)

Definition at line 346 of file nsevents.c.

347{
349 nsresult nsres;
350
351 if(nsnode)
352 nsres = nsIDOMNode_QueryInterface(nsnode, &IID_nsIDOMEventTarget, (void**)&target);
353 else
354 nsres = nsIDOMWindow_QueryInterface(doc->basedoc.window->nswindow, &IID_nsIDOMEventTarget, (void**)&target);
355 if(NS_FAILED(nsres)) {
356 ERR("Could not get nsIDOMEventTarget interface: %08x\n", nsres);
357 return;
358 }
359
361 TRUE);
362 nsIDOMEventTarget_Release(target);
363}
#define ERR(fmt,...)
Definition: precomp.h:57
#define TRUE
Definition: types.h:120
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLenum target
Definition: glext.h:7315
#define NS_FAILED(res)
static void init_event(nsIDOMEventTarget *target, const PRUnichar *type, nsIDOMEventListener *listener, BOOL capture)
Definition: nsevents.c:325
HTMLDocument basedoc
nsDocumentEventListener * nsevent_listener
HTMLOuterWindow * window
nsIDOMWindow * nswindow
nsEventListener htmlevent_listener
Definition: nsevents.c:36
nsIDOMEventListener nsIDOMEventListener_iface
Definition: nsevents.c:27

Referenced by ensure_doc_nsevent_handler().

◆ attach_event()

HRESULT attach_event ( EventTarget event_target,
BSTR  name,
IDispatch disp,
VARIANT_BOOL res 
)

Definition at line 1469 of file htmlevent.c.

1470{
1472 eventid_t eid;
1473 DWORD i = 0;
1474
1475 eid = attr_to_eid(name);
1476 if(eid == EVENTID_LAST) {
1477 WARN("Unknown event\n");
1478 *res = VARIANT_TRUE;
1479 return S_OK;
1480 }
1481
1482 data = get_event_target_data(event_target, TRUE);
1483 if(!data)
1484 return E_OUTOFMEMORY;
1485
1486 if(data->event_table[eid]) {
1487 while(i < data->event_table[eid]->handler_cnt && data->event_table[eid]->handlers[i])
1488 i++;
1489 if(i == data->event_table[eid]->handler_cnt && !alloc_handler_vector(data, eid, i+1))
1490 return E_OUTOFMEMORY;
1491 }else if(!alloc_handler_vector(data, eid, i+1)) {
1492 return E_OUTOFMEMORY;
1493 }
1494
1495 IDispatch_AddRef(disp);
1496 data->event_table[eid]->handlers[i] = disp;
1497
1498 bind_event(event_target, eid);
1499
1500 *res = VARIANT_TRUE;
1501 return S_OK;
1502}
#define WARN(fmt,...)
Definition: precomp.h:61
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLuint res
Definition: glext.h:9613
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
static BOOL alloc_handler_vector(event_target_t *event_target, eventid_t eid, int cnt)
Definition: htmlevent.c:1298
static event_target_t * get_event_target_data(EventTarget *event_target, BOOL alloc)
Definition: htmlevent.c:870
static void bind_event(EventTarget *event_target, eventid_t eid)
Definition: htmlevent.c:1357
static eventid_t attr_to_eid(LPCWSTR str)
Definition: htmlevent.c:230
#define S_OK
Definition: intsafe.h:52
Definition: name.c:39

Referenced by HTMLDocument3_attachEvent(), HTMLElement2_attachEvent(), and HTMLWindow3_attachEvent().

◆ bind_target_event()

void bind_target_event ( HTMLDocumentNode doc,
EventTarget event_target,
const WCHAR event,
IDispatch disp 
)

Definition at line 1534 of file htmlevent.c.

1535{
1536 eventid_t eid;
1537
1538 TRACE("(%p %p %s %p)\n", doc, event_target, debugstr_w(event), disp);
1539
1540 eid = attr_to_eid(event);
1541 if(eid == EVENTID_LAST) {
1542 WARN("Unsupported event %s\n", debugstr_w(event));
1543 return;
1544 }
1545
1546 set_event_handler_disp(event_target, eid, disp);
1547}
struct _cl_event * event
Definition: glext.h:7739
static HRESULT set_event_handler_disp(EventTarget *event_target, eventid_t eid, IDispatch *disp)
Definition: htmlevent.c:1382
#define debugstr_w
Definition: kernel32.h:32
#define TRACE(s)
Definition: solgame.cpp:4

Referenced by bind_event_scripts().

◆ call_event_handlers()

void call_event_handlers ( HTMLDocumentNode doc,
HTMLEventObj event_obj,
EventTarget event_target,
ConnectionPointContainer cp_container,
eventid_t  eid,
IDispatch this_obj 
)

Definition at line 952 of file htmlevent.c.

954{
956 const BOOL cancelable = event_info[eid].flags & EVENT_CANCELABLE;
957 VARIANT v;
959
960 if(data && data->event_table[eid] && data->event_table[eid]->handler_prop) {
961 DISPID named_arg = DISPID_THIS;
963 DISPPARAMS dp = {&arg, &named_arg, 1, 1};
964
965 V_VT(&arg) = VT_DISPATCH;
966 V_DISPATCH(&arg) = this_obj;
967 V_VT(&v) = VT_EMPTY;
968
969 TRACE("%s >>>\n", debugstr_w(event_info[eid].name));
970 hres = call_disp_func(data->event_table[eid]->handler_prop, &dp, &v);
971 if(hres == S_OK) {
972 TRACE("%s <<< %s\n", debugstr_w(event_info[eid].name), debugstr_variant(&v));
973
974 if(cancelable) {
975 if(V_VT(&v) == VT_BOOL) {
976 if(!V_BOOL(&v))
977 event_obj->prevent_default = TRUE;
978 }else if(V_VT(&v) != VT_EMPTY) {
979 FIXME("unhandled result %s\n", debugstr_variant(&v));
980 }
981 }
982 VariantClear(&v);
983 }else {
984 WARN("%s <<< %08x\n", debugstr_w(event_info[eid].name), hres);
985 }
986 }
987
988 if(data && data->event_table[eid] && data->event_table[eid]->handler_cnt) {
990 DISPPARAMS dp = {&arg, NULL, 1, 0};
991 int i;
992
993 V_VT(&arg) = VT_DISPATCH;
994 V_DISPATCH(&arg) = (IDispatch*)event_obj;
995
996 i = data->event_table[eid]->handler_cnt;
997 while(i--) {
998 if(data->event_table[eid]->handlers[i]) {
999 V_VT(&v) = VT_EMPTY;
1000
1001 TRACE("%s [%d] >>>\n", debugstr_w(event_info[eid].name), i);
1002 hres = call_disp_func(data->event_table[eid]->handlers[i], &dp, &v);
1003 if(hres == S_OK) {
1004 TRACE("%s [%d] <<<\n", debugstr_w(event_info[eid].name), i);
1005
1006 if(cancelable) {
1007 if(V_VT(&v) == VT_BOOL) {
1008 if(!V_BOOL(&v))
1009 event_obj->prevent_default = TRUE;
1010 }else if(V_VT(&v) != VT_EMPTY) {
1011 FIXME("unhandled result %s\n", debugstr_variant(&v));
1012 }
1013 }
1014 VariantClear(&v);
1015 }else {
1016 WARN("%s [%d] <<< %08x\n", debugstr_w(event_info[eid].name), i, hres);
1017 }
1018 }
1019 }
1020 }
1021
1022 /*
1023 * NOTE: CP events may require doc_obj reference, which we don't own. We make sure that
1024 * it's safe to call event handler by checking nsevent_listener, which is NULL for
1025 * detached documents.
1026 */
1027 if(cp_container && cp_container->forward_container)
1028 cp_container = cp_container->forward_container;
1029 if(cp_container && cp_container->cps && doc->nsevent_listener) {
1031 unsigned i, j;
1032
1033 for(j=0; cp_container->cp_entries[j].riid; j++) {
1034 cp = cp_container->cps + j;
1035 if(!cp->sinks_size || !is_cp_event(cp->data, event_info[eid].dispid))
1036 continue;
1037
1038 for(i=0; doc->nsevent_listener && i < cp->sinks_size; i++) {
1039 if(!cp->sinks[i].disp)
1040 continue;
1041
1042 V_VT(&v) = VT_EMPTY;
1043
1044 TRACE("cp %s [%u] >>>\n", debugstr_w(event_info[eid].name), i);
1045 hres = call_cp_func(cp->sinks[i].disp, event_info[eid].dispid,
1046 cp->data->pass_event_arg ? event_obj : NULL, &v);
1047 if(hres == S_OK) {
1048 TRACE("cp %s [%u] <<<\n", debugstr_w(event_info[eid].name), i);
1049
1050 if(cancelable) {
1051 if(V_VT(&v) == VT_BOOL) {
1052 if(!V_BOOL(&v))
1053 event_obj->prevent_default = TRUE;
1054 }else if(V_VT(&v) != VT_EMPTY) {
1055 FIXME("unhandled result %s\n", debugstr_variant(&v));
1056 }
1057 }
1058 VariantClear(&v);
1059 }else {
1060 WARN("cp %s [%u] <<< %08x\n", debugstr_w(event_info[eid].name), i, hres);
1061 }
1062 }
1063
1064 if(!doc->nsevent_listener)
1065 break;
1066 }
1067 }
1068}
#define FIXME(fmt,...)
Definition: precomp.h:53
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
@ VT_BOOL
Definition: compat.h:2306
@ VT_EMPTY
Definition: compat.h:2295
@ VT_DISPATCH
Definition: compat.h:2304
unsigned int BOOL
Definition: ntddk_ex.h:94
const GLdouble * v
Definition: gl.h:2040
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
static HRESULT call_disp_func(IDispatch *disp, DISPPARAMS *dp, VARIANT *retv)
Definition: htmlevent.c:883
#define EVENT_CANCELABLE
Definition: htmlevent.c:151
static BOOL is_cp_event(cp_static_data_t *data, DISPID dispid)
Definition: htmlevent.c:922
static const event_info_t event_info[]
Definition: htmlevent.c:154
static HRESULT call_cp_func(IDispatch *disp, DISPID dispid, HTMLEventObj *event_obj, VARIANT *retv)
Definition: htmlevent.c:904
POINT cp
Definition: magnifier.c:59
static const char * debugstr_variant(const VARIANT *var)
Definition: container.c:46
HRESULT hres
Definition: protocol.c:465
static VARIANTARG static DISPID
Definition: ordinal.c:52
struct stdole::DISPPARAMS DISPPARAMS
#define V_BOOL(A)
Definition: oleauto.h:224
#define V_VT(A)
Definition: oleauto.h:211
#define V_DISPATCH(A)
Definition: oleauto.h:239
#define DISPID_THIS
Definition: olectl.h:395
ConnectionPoint * cps
struct ConnectionPointContainer * forward_container
const cpc_entry_t * cp_entries
BOOL prevent_default
Definition: htmlevent.c:252
const IID * riid
DWORD flags
Definition: htmlevent.c:144
DISPID dispid
Definition: htmlevent.c:143
HRESULT WINAPI DECLSPEC_HOTPATCH VariantClear(VARIANTARG *pVarg)
Definition: variant.c:648
void * arg
Definition: msvc.h:10

Referenced by fire_event_obj(), and XMLHttpReqEventListener_HandleEvent().

◆ call_fire_event()

HRESULT call_fire_event ( HTMLDOMNode node,
eventid_t  eid 
)

Definition at line 1282 of file htmlevent.c.

1283{
1284 HRESULT hres;
1285
1286 if(node->vtbl->fire_event) {
1287 BOOL handled = FALSE;
1288
1289 hres = node->vtbl->fire_event(node, eid, &handled);
1290 if(handled)
1291 return hres;
1292 }
1293
1294 fire_event(node->doc, eid, TRUE, node->nsnode, NULL, NULL);
1295 return S_OK;
1296}
void fire_event(HTMLDocumentNode *doc, eventid_t eid, BOOL set_event, nsIDOMNode *target, nsIDOMEvent *nsevent, IDispatch *script_this)
Definition: htmlevent.c:1195
Definition: dlist.c:348

Referenced by HTMLElement_click().

◆ check_event_attr()

void check_event_attr ( HTMLDocumentNode doc,
nsIDOMHTMLElement nselem 
)

Definition at line 1559 of file htmlevent.c.

1560{
1561 const PRUnichar *attr_value;
1562 nsAString attr_value_str;
1563 IDispatch *disp;
1565 int i;
1566 nsresult nsres;
1567 HRESULT hres;
1568
1569 for(i=0; i < EVENTID_LAST; i++) {
1570 nsres = get_elem_attr_value(nselem, event_info[i].attr_name, &attr_value_str, &attr_value);
1571 if(NS_SUCCEEDED(nsres)) {
1572 if(!*attr_value)
1573 continue;
1574
1575 TRACE("%p.%s = %s\n", nselem, debugstr_w(event_info[i].attr_name), debugstr_w(attr_value));
1576
1577 disp = script_parse_event(doc->window, attr_value);
1578 if(disp) {
1579 hres = get_node(doc, (nsIDOMNode*)nselem, TRUE, &node);
1580 if(SUCCEEDED(hres)) {
1581 set_event_handler_disp(&node->event_target, i, disp);
1583 }
1584 IDispatch_Release(disp);
1585 }
1586 nsAString_Finish(&attr_value_str);
1587 }
1588 }
1589}
nsresult get_elem_attr_value(nsIDOMHTMLElement *nselem, const WCHAR *name, nsAString *val_str, const PRUnichar **val)
Definition: htmlelem.c:143
HRESULT get_node(HTMLDocumentNode *This, nsIDOMNode *nsnode, BOOL create, HTMLDOMNode **ret)
Definition: htmlnode.c:1339
IDispatch * script_parse_event(HTMLInnerWindow *, LPCWSTR) DECLSPEC_HIDDEN
Definition: script.c:1184
#define SUCCEEDED(hr)
Definition: intsafe.h:50
void nsAString_Finish(nsAString *) DECLSPEC_HIDDEN
Definition: nsembed.c:836
static void node_release(HTMLDOMNode *node)
#define NS_SUCCEEDED(res)
WCHAR PRUnichar
Definition: nsiface.idl:48
HTMLInnerWindow * window

Referenced by nsDocumentObserver_BindToDocument().

◆ create_event_obj()

HRESULT create_event_obj ( IHTMLEventObj **  ret)

Definition at line 858 of file htmlevent.c.

859{
861
862 event = create_event();
863 if(!event)
864 return E_OUTOFMEMORY;
865
866 *ret = &event->IHTMLEventObj_iface;
867 return S_OK;
868}
static HTMLEventObj * create_event(void)
Definition: htmlevent.c:816
int ret

Referenced by HTMLDocument4_createEventObject().

◆ detach_event()

HRESULT detach_event ( EventTarget event_target,
BSTR  name,
IDispatch disp 
)

Definition at line 1504 of file htmlevent.c.

1505{
1507 eventid_t eid;
1508 DWORD i = 0;
1509
1510 eid = attr_to_eid(name);
1511 if(eid == EVENTID_LAST) {
1512 WARN("Unknown event\n");
1513 return S_OK;
1514 }
1515
1516 data = get_event_target_data(event_target, FALSE);
1517 if(!data)
1518 return S_OK;
1519
1520 if(!data->event_table[eid])
1521 return S_OK;
1522
1523 while(i < data->event_table[eid]->handler_cnt) {
1524 if(data->event_table[eid]->handlers[i] == disp) {
1525 IDispatch_Release(data->event_table[eid]->handlers[i]);
1526 data->event_table[eid]->handlers[i] = NULL;
1527 }
1528 i++;
1529 }
1530
1531 return S_OK;
1532}

Referenced by HTMLDocument3_detachEvent(), HTMLElement2_detachEvent(), and HTMLWindow3_detachEvent().

◆ detach_events()

void detach_events ( HTMLDocumentNode doc)

Definition at line 1341 of file htmlevent.c.

1342{
1343 if(doc->event_vector) {
1344 int i;
1345
1346 for(i=0; i < EVENTID_LAST; i++) {
1347 if(doc->event_vector[i]) {
1349 doc->event_vector[i] = FALSE;
1350 }
1351 }
1352 }
1353
1354 release_nsevents(doc);
1355}
void release_nsevents(HTMLDocumentNode *) DECLSPEC_HIDDEN
Definition: nsevents.c:394
void detach_nsevent(HTMLDocumentNode *, const WCHAR *) DECLSPEC_HIDDEN
Definition: nsevents.c:389

Referenced by detach_inner_window(), and HTMLDocumentNode_destructor().

◆ detach_nsevent()

void detach_nsevent ( HTMLDocumentNode doc,
const WCHAR type 
)

Definition at line 389 of file nsevents.c.

390{
392}
static void detach_nslistener(HTMLDocumentNode *doc, const WCHAR *type, nsEventListener *listener, cpp_bool is_capture)
Definition: nsevents.c:365

Referenced by detach_events().

◆ dispatch_event()

HRESULT dispatch_event ( HTMLDOMNode node,
const WCHAR event_name,
VARIANT event_var,
VARIANT_BOOL cancelled 
)

Definition at line 1225 of file htmlevent.c.

1226{
1227 HTMLEventObj *event_obj = NULL;
1228 eventid_t eid;
1229 HRESULT hres;
1230
1231 eid = attr_to_eid(event_name);
1232 if(eid == EVENTID_LAST) {
1233 WARN("unknown event %s\n", debugstr_w(event_name));
1234 return E_INVALIDARG;
1235 }
1236
1237 if(event_var && V_VT(event_var) != VT_EMPTY && V_VT(event_var) != VT_ERROR) {
1238 if(V_VT(event_var) != VT_DISPATCH) {
1239 FIXME("event_var %s not supported\n", debugstr_variant(event_var));
1240 return E_NOTIMPL;
1241 }
1242
1243 if(V_DISPATCH(event_var)) {
1244 IHTMLEventObj *event_iface;
1245
1246 hres = IDispatch_QueryInterface(V_DISPATCH(event_var), &IID_IHTMLEventObj, (void**)&event_iface);
1247 if(FAILED(hres)) {
1248 FIXME("No IHTMLEventObj iface\n");
1249 return hres;
1250 }
1251
1252 event_obj = unsafe_impl_from_IHTMLEventObj(event_iface);
1253 if(!event_obj) {
1254 ERR("Not our IHTMLEventObj?\n");
1255 IHTMLEventObj_Release(event_iface);
1256 return E_FAIL;
1257 }
1258 }
1259 }
1260
1261 if(event_obj) {
1262 hres = set_event_info(event_obj, node, eid, NULL);
1263 if(SUCCEEDED(hres))
1264 fire_event_obj(node->doc, eid, event_obj, node->nsnode, NULL);
1265
1266 IHTMLEventObj_Release(&event_obj->IHTMLEventObj_iface);
1267 if(FAILED(hres))
1268 return hres;
1269 }else {
1270 if(!(event_info[eid].flags & EVENT_DEFAULTLISTENER)) {
1271 FIXME("not EVENT_DEFAULTEVENTHANDLER\n");
1272 return E_NOTIMPL;
1273 }
1274
1275 fire_event(node->doc, eid, TRUE, node->nsnode, NULL, NULL);
1276 }
1277
1278 *cancelled = VARIANT_TRUE; /* FIXME */
1279 return S_OK;
1280}
#define E_INVALIDARG
Definition: ddrawi.h:101
#define E_NOTIMPL
Definition: ddrawi.h:99
#define E_FAIL
Definition: ddrawi.h:102
@ VT_ERROR
Definition: compat.h:2305
GLbitfield flags
Definition: glext.h:7161
#define EVENT_DEFAULTLISTENER
Definition: htmlevent.c:147
static void fire_event_obj(HTMLDocumentNode *doc, eventid_t eid, HTMLEventObj *event_obj, nsIDOMNode *target, IDispatch *script_this)
Definition: htmlevent.c:1070
static HRESULT set_event_info(HTMLEventObj *event, HTMLDOMNode *target, eventid_t eid, nsIDOMEvent *nsevent)
Definition: htmlevent.c:832
static HTMLEventObj * unsafe_impl_from_IHTMLEventObj(IHTMLEventObj *iface)
Definition: htmlevent.c:799
#define FAILED(hr)
Definition: intsafe.h:51
IHTMLEventObj IHTMLEventObj_iface
Definition: htmlevent.c:244

Referenced by HTMLDocument4_fireEvent(), and HTMLElement3_fireEvent().

◆ doc_init_events()

HRESULT doc_init_events ( HTMLDocumentNode doc)

Definition at line 1591 of file htmlevent.c.

1592{
1593 unsigned i;
1594 HRESULT hres;
1595
1596 doc->event_vector = heap_alloc_zero(EVENTID_LAST*sizeof(BOOL));
1597 if(!doc->event_vector)
1598 return E_OUTOFMEMORY;
1599
1600 init_nsevents(doc);
1601
1602 for(i=0; i < EVENTID_LAST; i++) {
1605 if(FAILED(hres))
1606 return hres;
1607 }
1608 }
1609
1610 return S_OK;
1611}
#define EVENT_HASDEFAULTHANDLERS
Definition: htmlevent.c:152
HRESULT ensure_doc_nsevent_handler(HTMLDocumentNode *doc, eventid_t eid)
Definition: htmlevent.c:1319
void init_nsevents(HTMLDocumentNode *) DECLSPEC_HIDDEN
Definition: nsevents.c:413

Referenced by create_doc_from_nsdoc().

◆ ensure_doc_nsevent_handler()

HRESULT ensure_doc_nsevent_handler ( HTMLDocumentNode doc,
eventid_t  eid 
)

Definition at line 1319 of file htmlevent.c.

1320{
1321 nsIDOMNode *nsnode = NULL;
1322
1323 TRACE("%s\n", debugstr_w(event_info[eid].name));
1324
1325 if(!doc->nsdoc || doc->event_vector[eid] || !(event_info[eid].flags & (EVENT_DEFAULTLISTENER|EVENT_BIND_TO_BODY)))
1326 return S_OK;
1327
1329 nsnode = doc->node.nsnode;
1330 nsIDOMNode_AddRef(nsnode);
1331 }
1332
1333 doc->event_vector[eid] = TRUE;
1334 add_nsevent_listener(doc, nsnode, event_info[eid].name);
1335
1336 if(nsnode)
1337 nsIDOMNode_Release(nsnode);
1338 return S_OK;
1339}
#define EVENT_BIND_TO_BODY
Definition: htmlevent.c:150
void add_nsevent_listener(HTMLDocumentNode *, nsIDOMNode *, LPCWSTR) DECLSPEC_HIDDEN
Definition: nsevents.c:346
nsIDOMNode * nsnode
HTMLDOMNode node
nsIDOMHTMLDocument * nsdoc

Referenced by doc_init_events(), HTMLDocumentNode_bind_event(), and update_doc_cp_events().

◆ fire_event()

void fire_event ( HTMLDocumentNode doc,
eventid_t  eid,
BOOL  set_event,
nsIDOMNode target,
nsIDOMEvent nsevent,
IDispatch script_this 
)

Definition at line 1195 of file htmlevent.c.

1197{
1198 HTMLEventObj *event_obj = NULL;
1200 HRESULT hres;
1201
1202 if(set_event) {
1203 hres = get_node(doc, target, TRUE, &node);
1204 if(FAILED(hres))
1205 return;
1206
1207 event_obj = create_event();
1209 if(!event_obj)
1210 return;
1211
1212 hres = set_event_info(event_obj, node, eid, nsevent);
1213 if(FAILED(hres)) {
1214 IHTMLEventObj_Release(&event_obj->IHTMLEventObj_iface);
1215 return;
1216 }
1217 }
1218
1219 fire_event_obj(doc, eid, event_obj, target, script_this);
1220
1221 if(event_obj)
1222 IHTMLEventObj_Release(&event_obj->IHTMLEventObj_iface);
1223}

Referenced by call_fire_event(), dispatch_event(), fire_readystatechange_proc(), handle_htmlevent(), handle_load(), HTMLElement_handle_event(), notif_readystate(), nsContextMenuListener_OnShowContextMenu(), and set_script_elem_readystate().

◆ get_doc_event()

◆ get_event_handler()

HRESULT get_event_handler ( EventTarget event_target,
eventid_t  eid,
VARIANT var 
)

Definition at line 1447 of file htmlevent.c.

1448{
1450 VARIANT *v;
1451 HRESULT hres;
1452
1453 hres = dispex_get_dprop_ref(&event_target->dispex, event_info[eid].attr_name, FALSE, &v);
1454 if(SUCCEEDED(hres) && V_VT(v) != VT_EMPTY)
1455 return VariantCopy(var, v);
1456
1457 data = get_event_target_data(event_target, FALSE);
1458 if(data && data->event_table[eid] && data->event_table[eid]->handler_prop) {
1459 V_VT(var) = VT_DISPATCH;
1460 V_DISPATCH(var) = data->event_table[eid]->handler_prop;
1461 IDispatch_AddRef(V_DISPATCH(var));
1462 }else {
1463 V_VT(var) = VT_NULL;
1464 }
1465
1466 return S_OK;
1467}
@ VT_NULL
Definition: compat.h:2296
HRESULT dispex_get_dprop_ref(DispatchEx *This, const WCHAR *name, BOOL alloc, VARIANT **ret)
Definition: dispex.c:555
DispatchEx dispex
LPCWSTR attr_name
Definition: htmlevent.c:141
HRESULT WINAPI VariantCopy(VARIANTARG *pvargDest, VARIANTARG *pvargSrc)
Definition: variant.c:748

Referenced by get_node_event(), get_window_event(), and HTMLXMLHttpRequest_get_onreadystatechange().

◆ get_node_event()

◆ init_nsevents()

void init_nsevents ( HTMLDocumentNode doc)

Definition at line 413 of file nsevents.c.

414{
415 nsDocumentEventListener *listener;
417 nsresult nsres;
418
419 listener = heap_alloc(sizeof(nsDocumentEventListener));
420 if(!listener)
421 return;
422
423 TRACE("%p %p\n", doc, listener);
424
425 listener->ref = 1;
426 listener->doc = doc;
427
428 init_listener(&listener->blur_listener, listener, &blur_vtbl);
429 init_listener(&listener->focus_listener, listener, &focus_vtbl);
430 init_listener(&listener->keypress_listener, listener, &keypress_vtbl);
431 init_listener(&listener->load_listener, listener, &load_vtbl);
432 init_listener(&listener->htmlevent_listener, listener, &htmlevent_vtbl);
433
434 doc->nsevent_listener = listener;
435
436 nsres = nsIDOMWindow_QueryInterface(doc->basedoc.window->nswindow, &IID_nsIDOMEventTarget, (void**)&target);
437 if(NS_FAILED(nsres)) {
438 ERR("Could not get nsIDOMEventTarget interface: %08x\n", nsres);
439 return;
440 }
441
446
447 nsIDOMEventTarget_Release(target);
448}
static void * heap_alloc(size_t len)
Definition: appwiz.h:66
static const nsIDOMEventListenerVtbl blur_vtbl
Definition: nsevents.c:319
static void init_listener(nsEventListener *This, nsDocumentEventListener *listener, const nsIDOMEventListenerVtbl *vtbl)
Definition: nsevents.c:339
static const PRUnichar keypressW[]
Definition: nsevents.c:23
static const nsIDOMEventListenerVtbl keypress_vtbl
Definition: nsevents.c:321
static const PRUnichar blurW[]
Definition: nsevents.c:21
static const nsIDOMEventListenerVtbl htmlevent_vtbl
Definition: nsevents.c:323
static const nsIDOMEventListenerVtbl focus_vtbl
Definition: nsevents.c:320
static const nsIDOMEventListenerVtbl load_vtbl
Definition: nsevents.c:322
static const PRUnichar focusW[]
Definition: nsevents.c:22
static const PRUnichar loadW[]
Definition: nsevents.c:24
nsEventListener blur_listener
Definition: nsevents.c:32
HTMLDocumentNode * doc
Definition: nsevents.c:40
nsEventListener keypress_listener
Definition: nsevents.c:34
nsEventListener load_listener
Definition: nsevents.c:35
nsEventListener focus_listener
Definition: nsevents.c:33

Referenced by doc_init_events().

◆ release_event_target()

void release_event_target ( event_target_t event_target)

Definition at line 1613 of file htmlevent.c.

1614{
1615 int i;
1616 unsigned int j;
1617
1618 for(i=0; i < EVENTID_LAST; i++) {
1619 if(event_target->event_table[i]) {
1620 if(event_target->event_table[i]->handler_prop)
1621 IDispatch_Release(event_target->event_table[i]->handler_prop);
1622 for(j=0; j < event_target->event_table[i]->handler_cnt; j++)
1623 if(event_target->event_table[i]->handlers[j])
1624 IDispatch_Release(event_target->event_table[i]->handlers[j]);
1625 }
1626 }
1627
1628 heap_free(event_target);
1629}
static BOOL heap_free(void *mem)
Definition: appwiz.h:76
handler_vector_t * event_table[EVENTID_LAST]
Definition: htmlevent.c:28
IDispatch * handlers[0]
Definition: htmlevent.c:24
IDispatch * handler_prop
Definition: htmlevent.c:22
DWORD handler_cnt
Definition: htmlevent.c:23

Referenced by HTMLDocumentNode_destructor(), and HTMLDOMNode_destructor().

◆ release_nsevents()

void release_nsevents ( HTMLDocumentNode doc)

Definition at line 394 of file nsevents.c.

395{
397
398 TRACE("%p %p\n", doc, doc->nsevent_listener);
399
400 if(!listener)
401 return;
402
403 detach_nslistener(doc, blurW, &listener->blur_listener, TRUE);
404 detach_nslistener(doc, focusW, &listener->focus_listener, TRUE);
406 detach_nslistener(doc, loadW, &listener->load_listener, TRUE);
407
408 listener->doc = NULL;
409 release_listener(listener);
410 doc->nsevent_listener = NULL;
411}
static LONG release_listener(nsDocumentEventListener *This)
Definition: nsevents.c:43

Referenced by detach_events().

◆ set_doc_event()

◆ set_event_handler()

HRESULT set_event_handler ( EventTarget event_target,
eventid_t  eid,
VARIANT var 
)

Definition at line 1404 of file htmlevent.c.

1405{
1406 switch(V_VT(var)) {
1407 case VT_NULL:
1408 remove_event_handler(event_target, eid);
1409 return S_OK;
1410
1411 case VT_DISPATCH:
1412 return set_event_handler_disp(event_target, eid, V_DISPATCH(var));
1413
1414 case VT_BSTR: {
1415 VARIANT *v;
1416 HRESULT hres;
1417
1418 /*
1419 * Setting event handler to string is a rare case and we don't want to
1420 * complicate nor increase memory of event_target_t for that. Instead,
1421 * we store the value in DispatchEx, which can already handle custom
1422 * properties.
1423 */
1424 remove_event_handler(event_target, eid);
1425
1426 hres = dispex_get_dprop_ref(&event_target->dispex, event_info[eid].attr_name, TRUE, &v);
1427 if(FAILED(hres))
1428 return hres;
1429
1431 if(!V_BSTR(v))
1432 return E_OUTOFMEMORY;
1433 V_VT(v) = VT_BSTR;
1434 return S_OK;
1435 }
1436
1437 default:
1438 FIXME("not handler %s\n", debugstr_variant(var));
1439 /* fall through */
1440 case VT_EMPTY:
1441 return E_NOTIMPL;
1442 }
1443
1444 return S_OK;
1445}
@ VT_BSTR
Definition: compat.h:2303
static void remove_event_handler(EventTarget *event_target, eventid_t eid)
Definition: htmlevent.c:1365
BSTR WINAPI SysAllocString(LPCOLESTR str)
Definition: oleaut.c:238
#define V_BSTR(A)
Definition: oleauto.h:226

Referenced by HTMLXMLHttpRequest_put_onreadystatechange(), set_node_event(), and set_window_event().

◆ set_node_event()

◆ str_to_eid()

eventid_t str_to_eid ( LPCWSTR  str)

Definition at line 217 of file htmlevent.c.

218{
219 int i;
220
221 for(i=0; i < sizeof(event_info)/sizeof(event_info[0]); i++) {
222 if(!strcmpW(event_info[i].name, str))
223 return i;
224 }
225
226 ERR("unknown type %s\n", debugstr_w(str));
227 return EVENTID_LAST;
228}
#define strcmpW(s1, s2)
Definition: unicode.h:44
const WCHAR * str

Referenced by handle_htmlevent().

◆ update_doc_cp_events()

void update_doc_cp_events ( HTMLDocumentNode doc,
cp_static_data_t cp 
)

Definition at line 1549 of file htmlevent.c.

1550{
1551 int i;
1552
1553 for(i=0; i < EVENTID_LAST; i++) {
1556 }
1557}

Referenced by HTMLDocument_on_advise().