mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-23 02:42:11 +03:00
Rudimentary Event object binding
This commit is contained in:
parent
1284731d1a
commit
e3a5fcf816
145
javascript/duktape/Event.bnd
Normal file
145
javascript/duktape/Event.bnd
Normal file
@ -0,0 +1,145 @@
|
||||
/* Event binding for browser using duktape and libdom
|
||||
*
|
||||
* Copyright 2015 Vincent Sanders <vince@netsurf-browser.org>
|
||||
* Copyright 2015 Daniel Silverstone <dsilvers@netsurf-browser.org>
|
||||
*
|
||||
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
||||
*
|
||||
* Released under the terms of the MIT License,
|
||||
* http://www.opensource.org/licenses/mit-license
|
||||
*/
|
||||
|
||||
class Event {
|
||||
private dom_event *evt;
|
||||
};
|
||||
|
||||
init Event (struct dom_event *evt)
|
||||
%{
|
||||
priv->evt = evt;
|
||||
dom_event_ref(evt);
|
||||
%}
|
||||
|
||||
/* Note: many of these could be automatics once nsgenbind gets there. */
|
||||
|
||||
getter Event::type ()
|
||||
%{
|
||||
dom_string *ret;
|
||||
dom_exception exc;
|
||||
|
||||
exc = dom_event_get_type(priv->evt, &ret);
|
||||
if (exc != DOM_NO_ERR) return 0;
|
||||
if (ret == NULL) {
|
||||
duk_push_lstring(ctx, "", 0);
|
||||
} else {
|
||||
duk_push_lstring(ctx, dom_string_data(ret),
|
||||
dom_string_length(ret));
|
||||
dom_string_unref(ret);
|
||||
}
|
||||
|
||||
return 1;
|
||||
%}
|
||||
|
||||
getter Event::target ()
|
||||
%{
|
||||
/** @todo Decide HTF this works wrt. Window as an event target */
|
||||
dom_node *et;
|
||||
dom_exception exc;
|
||||
|
||||
exc = dom_event_get_target(priv->evt, &et);
|
||||
if (exc != DOM_NO_ERR) return 0;
|
||||
|
||||
dukky_push_node(ctx, et);
|
||||
return 1;
|
||||
%}
|
||||
|
||||
getter Event::currentTarget ()
|
||||
%{
|
||||
/** @todo Decide HTF this works wrt. Window as an event target */
|
||||
dom_node *et;
|
||||
dom_exception exc;
|
||||
|
||||
exc = dom_event_get_current_target(priv->evt, &et);
|
||||
if (exc != DOM_NO_ERR) return 0;
|
||||
|
||||
dukky_push_node(ctx, et);
|
||||
return 1;
|
||||
%}
|
||||
|
||||
getter Event::eventPhase ()
|
||||
%{
|
||||
dom_exception exc;
|
||||
dom_event_flow_phase phase;
|
||||
|
||||
exc = dom_event_get_event_phase(priv->evt, &phase);
|
||||
if (exc != DOM_NO_ERR) return 0;
|
||||
|
||||
duk_push_uint(ctx, phase);
|
||||
return 1;
|
||||
%}
|
||||
|
||||
method Event::stopPropagation ()
|
||||
%{
|
||||
dom_exception exc;
|
||||
|
||||
exc = dom_event_stop_propagation(priv->evt);
|
||||
if (exc != DOM_NO_ERR) return 0;
|
||||
|
||||
return 0;
|
||||
%}
|
||||
|
||||
method Event::stopImmediatePropagation ()
|
||||
%{
|
||||
dom_exception exc;
|
||||
|
||||
exc = dom_event_stop_immediate_propagation(priv->evt);
|
||||
if (exc != DOM_NO_ERR) return 0;
|
||||
|
||||
return 0;
|
||||
%}
|
||||
|
||||
getter Event::bubbles ()
|
||||
%{
|
||||
dom_exception exc;
|
||||
bool ret;
|
||||
|
||||
exc = dom_event_get_bubbles(priv->evt, &ret);
|
||||
if (exc != DOM_NO_ERR) return 0;
|
||||
|
||||
duk_push_boolean(ctx, ret);
|
||||
return 1;
|
||||
%}
|
||||
|
||||
getter Event::cancelable ()
|
||||
%{
|
||||
dom_exception exc;
|
||||
bool ret;
|
||||
|
||||
exc = dom_event_get_cancelable(priv->evt, &ret);
|
||||
if (exc != DOM_NO_ERR) return 0;
|
||||
|
||||
duk_push_boolean(ctx, ret);
|
||||
return 1;
|
||||
%}
|
||||
|
||||
method Event::preventDefault ()
|
||||
%{
|
||||
dom_exception exc;
|
||||
|
||||
exc = dom_event_prevent_default(priv->evt);
|
||||
if (exc != DOM_NO_ERR) return 0;
|
||||
|
||||
return 0;
|
||||
%}
|
||||
|
||||
getter Event::defaultPrevented ()
|
||||
%{
|
||||
dom_exception exc;
|
||||
bool ret;
|
||||
|
||||
exc = dom_event_is_default_prevented(priv->evt, &ret);
|
||||
if (exc != DOM_NO_ERR) return 0;
|
||||
|
||||
duk_push_boolean(ctx, ret);
|
||||
return 1;
|
||||
%}
|
||||
|
@ -62,6 +62,38 @@ struct dom_html_br_element;
|
||||
#include "Location.bnd"
|
||||
#include "Navigator.bnd"
|
||||
|
||||
/* events */
|
||||
|
||||
#include "Event.bnd"
|
||||
|
||||
init MutationEvent(struct dom_mutation_event *evt::evt);
|
||||
init UIEvent(struct dom_ui_event *evt::evt);
|
||||
init TextEvent(struct dom_text_event *evt::evt);
|
||||
init MutationNameEvent(struct dom_mutation_name_event *evt::evt);
|
||||
init MouseWheelEvent(struct dom_mouse_wheel_event *evt::evt);
|
||||
init MouseMultiWheelEvent(struct dom_mouse_multi_wheel_event *evt::evt);
|
||||
init MouseEvent(struct dom_mouse_event *evt::evt);
|
||||
init KeyboardEvent(struct dom_keyboard_event *evt::evt);
|
||||
init DocumentEvent(struct dom_document_event *evt::evt);
|
||||
init CustomEvent(struct dom_custom_event *evt::evt);
|
||||
init CompositionEvent(struct dom_ui_event *evt::evt);
|
||||
init WheelEvent(struct dom_mouse_event *evt::evt);
|
||||
init FocusEvent(struct dom_ui_event *evt::evt);
|
||||
init StorageEvent(struct dom_event *evt::evt);
|
||||
init CloseEvent(struct dom_event *evt::evt);
|
||||
init MessageEvent(struct dom_event *evt::evt);
|
||||
init ErrorEvent(struct dom_event *evt::evt);
|
||||
init BeforeUnloadEvent(struct dom_event *evt::evt);
|
||||
init PageTransitionEvent(struct dom_event *evt::evt);
|
||||
init HashChangeEvent(struct dom_event *evt::evt);
|
||||
init PopStateEvent(struct dom_event *evt::evt);
|
||||
init DragEvent(struct dom_mouse_event *evt::evt);
|
||||
init RelatedEvent(struct dom_event *evt::evt);
|
||||
init AutocompleteErrorEvent(struct dom_event *evt::evt);
|
||||
init TrackEvent(struct dom_event *evt::evt);
|
||||
|
||||
|
||||
/* html elements */
|
||||
#include "HTMLElement.bnd"
|
||||
|
||||
/* specialisations of html_element */
|
||||
|
Loading…
Reference in New Issue
Block a user