Skip to content

Commit

Permalink
event: add dom_event internal_type field
Browse files Browse the repository at this point in the history
dom_event internal field stores information about the dom_event type.
Pure libdom events will always have internal type set to 0.

If you pass your event casted as dom_event, use internal_type to store
your type information.
  • Loading branch information
krichprollsch committed Feb 8, 2024
1 parent c1de567 commit 540c430
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
8 changes: 8 additions & 0 deletions include/dom/events/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,12 @@ dom_exception _dom_event_set_is_trusted(dom_event *evt, bool trusted);
#define dom_event_set_is_trusted(e,t) _dom_event_set_is_trusted( \
(dom_event *) (e), (bool) (t))

dom_exception _dom_event_get_internal_type(dom_event *evt, int *result);
#define dom_event_get_internal_type(e,t) _dom_event_get_internal_type( \
(dom_event *) (e), (int *) (r))

dom_exception _dom_event_set_internal_type(dom_event *evt, int type);
#define dom_event_set_internal_type(e,t) _dom_event_set_internal_type( \
(dom_event *) (e), (int) (t))

#endif
30 changes: 30 additions & 0 deletions src/events/event.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ dom_exception _dom_event_initialise(dom_event *evt)
evt->is_initialised = false;
evt->is_trusted = true;

evt->internal_type = 0;

return DOM_NO_ERR;
}

Expand Down Expand Up @@ -396,3 +398,31 @@ dom_exception _dom_event_set_is_trusted(dom_event *evt, bool trusted)

return DOM_NO_ERR;
}

/**
* Get the internal type of this event
*
* \param evt The event object
* \param result The returned value
* \return DOM_NO_ERR.
*/
dom_exception _dom_event_get_internal_type(dom_event *evt, int *result)
{
*result = evt->internal_type;

return DOM_NO_ERR;
}

/**
* Set the internal type of this event
*
* \param evt The event object
* \param type The internal type
* \return DOM_NO_ERR.
*/
dom_exception _dom_event_set_internal_type(dom_event *evt, int type)
{
evt->internal_type = type;

return DOM_NO_ERR;
}
2 changes: 2 additions & 0 deletions src/events/event.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ struct dom_event {
bool in_dispatch; /**< Whether this event is in dispatch */
bool is_initialised; /**< Whether this event is initialised */
bool is_trusted; /**< Whether this event is trusted */

unsigned int internal_type; /**< always 0 for a pure libdom event. */
};

/* Destructor */
Expand Down

0 comments on commit 540c430

Please sign in to comment.