htmlevent.h 5.24 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Copyright 2008 Jacek Caban for CodeWeavers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
 */

typedef enum {
20
    EVENTID_ABORT,
21
    EVENTID_BEFOREACTIVATE,
22
    EVENTID_BEFOREUNLOAD,
23
    EVENTID_BLUR,
24 25
    EVENTID_CHANGE,
    EVENTID_CLICK,
26
    EVENTID_CONTEXTMENU,
27
    EVENTID_DATAAVAILABLE,
28
    EVENTID_DBLCLICK,
29
    EVENTID_DOMCONTENTLOADED,
30
    EVENTID_DRAG,
31
    EVENTID_DRAGSTART,
32
    EVENTID_ERROR,
33
    EVENTID_FOCUS,
34
    EVENTID_FOCUSIN,
35
    EVENTID_FOCUSOUT,
36
    EVENTID_HELP,
37
    EVENTID_KEYDOWN,
38
    EVENTID_KEYPRESS,
39 40
    EVENTID_KEYUP,
    EVENTID_LOAD,
41
    EVENTID_MESSAGE,
42
    EVENTID_MOUSEDOWN,
43
    EVENTID_MOUSEMOVE,
44
    EVENTID_MOUSEOUT,
45
    EVENTID_MOUSEOVER,
46
    EVENTID_MOUSEUP,
47
    EVENTID_MOUSEWHEEL,
48
    EVENTID_PASTE,
49
    EVENTID_READYSTATECHANGE,
50
    EVENTID_RESIZE,
51
    EVENTID_SCROLL,
52
    EVENTID_SELECTIONCHANGE,
53
    EVENTID_SELECTSTART,
54
    EVENTID_SUBMIT,
55
    EVENTID_UNLOAD,
56 57 58
    EVENTID_LAST
} eventid_t;

59 60 61
typedef struct {
    DispatchEx dispex;
    IDOMEvent IDOMEvent_iface;
62
    IDOMUIEvent IDOMUIEvent_iface;
63
    IDOMMouseEvent IDOMMouseEvent_iface;
64
    IDOMKeyboardEvent IDOMKeyboardEvent_iface;
65 66 67 68

    LONG ref;

    nsIDOMEvent *nsevent;
69
    nsIDOMUIEvent *ui_event;
70
    nsIDOMMouseEvent *mouse_event;
71
    nsIDOMKeyEvent *keyboard_event;
72

73
    eventid_t event_id;
74
    WCHAR *type;
75
    EventTarget *target;
76
    EventTarget *current_target;
77
    ULONGLONG time_stamp;
78
    BOOL bubbles;
79
    BOOL cancelable;
80
    BOOL prevent_default;
81
    BOOL stop_propagation;
82
    BOOL stop_immediate_propagation;
83
    DOM_EVENT_PHASE phase;
84 85 86

    IHTMLEventObj *event_obj;
    BOOL no_event_obj;
87 88
} DOMEvent;

89
void check_event_attr(HTMLDocumentNode*,nsIDOMElement*) DECLSPEC_HIDDEN;
90
void release_event_target(EventTarget*) DECLSPEC_HIDDEN;
91
HRESULT set_event_handler(EventTarget*,eventid_t,VARIANT*) DECLSPEC_HIDDEN;
92
HRESULT get_event_handler(EventTarget*,eventid_t,VARIANT*) DECLSPEC_HIDDEN;
93
HRESULT attach_event(EventTarget*,BSTR,IDispatch*,VARIANT_BOOL*) DECLSPEC_HIDDEN;
94
HRESULT detach_event(EventTarget*,BSTR,IDispatch*) DECLSPEC_HIDDEN;
95
HRESULT fire_event(HTMLDOMNode*,const WCHAR*,VARIANT*,VARIANT_BOOL*) DECLSPEC_HIDDEN;
96
void update_doc_cp_events(HTMLDocumentNode*,cp_static_data_t*) DECLSPEC_HIDDEN;
97
HRESULT doc_init_events(HTMLDocumentNode*) DECLSPEC_HIDDEN;
98
void detach_events(HTMLDocumentNode *doc) DECLSPEC_HIDDEN;
99
HRESULT create_event_obj(IHTMLEventObj**) DECLSPEC_HIDDEN;
100
void bind_target_event(HTMLDocumentNode*,EventTarget*,const WCHAR*,IDispatch*) DECLSPEC_HIDDEN;
101
HRESULT ensure_doc_nsevent_handler(HTMLDocumentNode*,nsIDOMNode*,eventid_t) DECLSPEC_HIDDEN;
102

103
void dispatch_event(EventTarget*,DOMEvent*) DECLSPEC_HIDDEN;
104

105
HRESULT create_document_event(HTMLDocumentNode*,eventid_t,DOMEvent**) DECLSPEC_HIDDEN;
106
HRESULT create_document_event_str(HTMLDocumentNode*,const WCHAR*,IDOMEvent**) DECLSPEC_HIDDEN;
107
HRESULT create_event_from_nsevent(nsIDOMEvent*,DOMEvent**) DECLSPEC_HIDDEN;
108

109 110 111
void init_nsevents(HTMLDocumentNode*) DECLSPEC_HIDDEN;
void release_nsevents(HTMLDocumentNode*) DECLSPEC_HIDDEN;
void add_nsevent_listener(HTMLDocumentNode*,nsIDOMNode*,LPCWSTR) DECLSPEC_HIDDEN;
112
void detach_nsevent(HTMLDocumentNode*,const WCHAR*) DECLSPEC_HIDDEN;
113

114 115 116
/* We extend dispex vtbl for EventTarget functions to avoid separated vtbl. */
typedef struct {
    dispex_static_data_vtbl_t dispex_vtbl;
117
    nsISupports *(*get_gecko_target)(DispatchEx*);
118
    void (*bind_event)(DispatchEx*,eventid_t);
119
    EventTarget *(*get_parent_event_target)(DispatchEx*);
120
    HRESULT (*handle_event_default)(DispatchEx*,eventid_t,nsIDOMEvent*,BOOL*);
121
    ConnectionPointContainer *(*get_cp_container)(DispatchEx*);
122
    IHTMLEventObj *(*set_current_event)(DispatchEx*,IHTMLEventObj*);
123 124
} event_target_vtbl_t;

125 126
IHTMLEventObj *default_set_current_event(HTMLInnerWindow*,IHTMLEventObj*) DECLSPEC_HIDDEN;

127 128 129 130 131
static inline EventTarget *get_node_event_prop_target(HTMLDOMNode *node, eventid_t eid)
{
    return node->vtbl->get_event_prop_target ? node->vtbl->get_event_prop_target(node, eid) : &node->event_target;
}

132 133
static inline HRESULT set_node_event(HTMLDOMNode *node, eventid_t eid, VARIANT *var)
{
134
    return set_event_handler(get_node_event_prop_target(node, eid), eid, var);
135 136
}

137 138
static inline HRESULT get_node_event(HTMLDOMNode *node, eventid_t eid, VARIANT *var)
{
139
    return get_event_handler(get_node_event_prop_target(node, eid), eid, var);
140 141
}

142 143
static inline HRESULT set_doc_event(HTMLDocument *doc, eventid_t eid, VARIANT *var)
{
144
    return set_event_handler(&doc->doc_node->node.event_target, eid, var);
145
}
146 147 148

static inline HRESULT get_doc_event(HTMLDocument *doc, eventid_t eid, VARIANT *var)
{
149
    return get_event_handler(&doc->doc_node->node.event_target, eid, var);
150
}