mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-18 16:49:18 +03:00
issue click events at dom
This commit is contained in:
parent
22fbe5abfc
commit
3052864773
@ -51,7 +51,10 @@ jsobject *js_newcompartment(jscontext *ctx, void *win_priv, void *doc_priv);
|
|||||||
/* execute some javascript in a context */
|
/* execute some javascript in a context */
|
||||||
bool js_exec(jscontext *ctx, const char *txt, size_t txtlen);
|
bool js_exec(jscontext *ctx, const char *txt, size_t txtlen);
|
||||||
|
|
||||||
|
typedef struct dom_document dom_document;
|
||||||
|
typedef struct dom_node dom_node;
|
||||||
|
|
||||||
/* fire an event at a dom node */
|
/* fire an event at a dom node */
|
||||||
bool js_fire_event(jscontext *ctx, const char *type, void *target);
|
bool js_fire_event(jscontext *ctx, const char *type, dom_document *doc, dom_node *target);
|
||||||
|
|
||||||
#endif /* _NETSURF_JAVASCRIPT_JS_H_ */
|
#endif /* _NETSURF_JAVASCRIPT_JS_H_ */
|
||||||
|
@ -153,7 +153,7 @@ bool js_exec(jscontext *ctx, const char *txt, size_t txtlen)
|
|||||||
dom_exception _dom_event_create(dom_document *doc, dom_event **evt);
|
dom_exception _dom_event_create(dom_document *doc, dom_event **evt);
|
||||||
#define dom_event_create(d, e) _dom_event_create((dom_document *)(d), (dom_event **) (e))
|
#define dom_event_create(d, e) _dom_event_create((dom_document *)(d), (dom_event **) (e))
|
||||||
|
|
||||||
bool js_fire_event(jscontext *ctx, const char *type, void *target)
|
bool js_fire_event(jscontext *ctx, const char *type, dom_document *doc, dom_node *target)
|
||||||
{
|
{
|
||||||
JSContext *cx = (JSContext *)ctx;
|
JSContext *cx = (JSContext *)ctx;
|
||||||
dom_node *node = target;
|
dom_node *node = target;
|
||||||
@ -165,18 +165,23 @@ bool js_fire_event(jscontext *ctx, const char *type, void *target)
|
|||||||
dom_event *event;
|
dom_event *event;
|
||||||
dom_string *type_dom;
|
dom_string *type_dom;
|
||||||
|
|
||||||
if (node == NULL) {
|
|
||||||
/* deliver to window */
|
|
||||||
if (cx == NULL) {
|
if (cx == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
exc = dom_string_create((unsigned char*)type, strlen(type), &type_dom);
|
if (node == NULL) {
|
||||||
|
/* deliver manufactured event to window */
|
||||||
|
JSLOG("Dispatching event %s at window", type);
|
||||||
|
|
||||||
|
/* create and initialise and event object */
|
||||||
|
exc = dom_string_create((unsigned char*)type,
|
||||||
|
strlen(type),
|
||||||
|
&type_dom);
|
||||||
if (exc != DOM_NO_ERR) {
|
if (exc != DOM_NO_ERR) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
exc = dom_event_create(-1, &event);
|
exc = dom_event_create(doc, &event);
|
||||||
if (exc != DOM_NO_ERR) {
|
if (exc != DOM_NO_ERR) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -192,6 +197,7 @@ bool js_fire_event(jscontext *ctx, const char *type, void *target)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* dispatch event at the window object */
|
||||||
argv[0] = OBJECT_TO_JSVAL(jsevent);
|
argv[0] = OBJECT_TO_JSVAL(jsevent);
|
||||||
|
|
||||||
ret = JS_CallFunctionName(cx,
|
ret = JS_CallFunctionName(cx,
|
||||||
@ -200,6 +206,30 @@ bool js_fire_event(jscontext *ctx, const char *type, void *target)
|
|||||||
1,
|
1,
|
||||||
argv,
|
argv,
|
||||||
&rval);
|
&rval);
|
||||||
|
} else {
|
||||||
|
JSLOG("Dispatching event %s at %p", type, node);
|
||||||
|
|
||||||
|
/* create and initialise and event object */
|
||||||
|
exc = dom_string_create((unsigned char*)type,
|
||||||
|
strlen(type),
|
||||||
|
&type_dom);
|
||||||
|
if (exc != DOM_NO_ERR) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
exc = dom_event_create(doc, &event);
|
||||||
|
if (exc != DOM_NO_ERR) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
exc = dom_event_init(event, type_dom, true, true);
|
||||||
|
dom_string_unref(type_dom);
|
||||||
|
if (exc != DOM_NO_ERR) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
dom_event_target_dispatch_event(node, event, &ret);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret == JS_TRUE) {
|
if (ret == JS_TRUE) {
|
||||||
|
@ -336,7 +336,7 @@ void html_finish_conversion(html_content *c)
|
|||||||
* object, but with its target set to the Document object (and
|
* object, but with its target set to the Document object (and
|
||||||
* the currentTarget set to the Window object)
|
* the currentTarget set to the Window object)
|
||||||
*/
|
*/
|
||||||
js_fire_event(c->jscontext, "load", NULL);
|
js_fire_event(c->jscontext, "load", c->document, NULL);
|
||||||
|
|
||||||
/* convert dom tree to box tree */
|
/* convert dom tree to box tree */
|
||||||
LOG(("DOM to box (%p)", c));
|
LOG(("DOM to box (%p)", c));
|
||||||
|
@ -42,6 +42,7 @@
|
|||||||
#include "render/html_internal.h"
|
#include "render/html_internal.h"
|
||||||
#include "render/imagemap.h"
|
#include "render/imagemap.h"
|
||||||
#include "render/textinput.h"
|
#include "render/textinput.h"
|
||||||
|
#include "javascript/js.h"
|
||||||
#include "utils/messages.h"
|
#include "utils/messages.h"
|
||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
|
|
||||||
@ -323,6 +324,7 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
|
|||||||
int padding_left, padding_right, padding_top, padding_bottom;
|
int padding_left, padding_right, padding_top, padding_bottom;
|
||||||
browser_drag_type drag_type = browser_window_get_drag_type(bw);
|
browser_drag_type drag_type = browser_window_get_drag_type(bw);
|
||||||
union content_msg_data msg_data;
|
union content_msg_data msg_data;
|
||||||
|
struct dom_node *node = NULL;
|
||||||
|
|
||||||
if (drag_type != DRAGGING_NONE && !mouse &&
|
if (drag_type != DRAGGING_NONE && !mouse &&
|
||||||
html->visible_select_menu != NULL) {
|
html->visible_select_menu != NULL) {
|
||||||
@ -389,7 +391,8 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
|
|||||||
browser_window_set_drag_type(bw, DRAGGING_NONE, NULL);
|
browser_window_set_drag_type(bw, DRAGGING_NONE, NULL);
|
||||||
|
|
||||||
/* search the box tree for a link, imagemap, form control, or
|
/* search the box tree for a link, imagemap, form control, or
|
||||||
* box with scrollbars */
|
* box with scrollbars
|
||||||
|
*/
|
||||||
|
|
||||||
box = html->layout;
|
box = html->layout;
|
||||||
|
|
||||||
@ -397,14 +400,17 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
|
|||||||
box_x = box->margin[LEFT];
|
box_x = box->margin[LEFT];
|
||||||
box_y = box->margin[TOP];
|
box_y = box->margin[TOP];
|
||||||
|
|
||||||
while ((next_box = box_at_point(box, x, y, &box_x, &box_y)) !=
|
while ((next_box = box_at_point(box, x, y, &box_x, &box_y)) != NULL) {
|
||||||
NULL) {
|
|
||||||
box = next_box;
|
box = next_box;
|
||||||
|
|
||||||
if (box->style && css_computed_visibility(box->style) ==
|
if (box->style && css_computed_visibility(box->style) ==
|
||||||
CSS_VISIBILITY_HIDDEN)
|
CSS_VISIBILITY_HIDDEN)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if (box->node != NULL) {
|
||||||
|
node = box->node;
|
||||||
|
}
|
||||||
|
|
||||||
if (box->object) {
|
if (box->object) {
|
||||||
if (content_get_type(box->object) == CONTENT_HTML) {
|
if (content_get_type(box->object) == CONTENT_HTML) {
|
||||||
html_object_box = box;
|
html_object_box = box;
|
||||||
@ -447,11 +453,12 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
|
|||||||
|
|
||||||
pointer = get_pointer_shape(box, false);
|
pointer = get_pointer_shape(box, false);
|
||||||
|
|
||||||
if ((box->scroll_x != NULL || box->scroll_y != NULL) &&
|
|
||||||
drag_candidate == NULL)
|
|
||||||
drag_candidate = box;
|
|
||||||
|
|
||||||
if (box->scroll_y != NULL || box->scroll_x != NULL) {
|
if (box->scroll_y != NULL || box->scroll_x != NULL) {
|
||||||
|
|
||||||
|
if (drag_candidate == NULL) {
|
||||||
|
drag_candidate = box;
|
||||||
|
}
|
||||||
|
|
||||||
padding_left = box_x +
|
padding_left = box_x +
|
||||||
scrollbar_get_offset(box->scroll_x);
|
scrollbar_get_offset(box->scroll_x);
|
||||||
padding_right = padding_left + box->padding[LEFT] +
|
padding_right = padding_left + box->padding[LEFT] +
|
||||||
@ -842,6 +849,12 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
|
|||||||
content_broadcast(c, CONTENT_MSG_POINTER, msg_data);
|
content_broadcast(c, CONTENT_MSG_POINTER, msg_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* fire dom click event */
|
||||||
|
if ((mouse & BROWSER_MOUSE_CLICK_1) ||
|
||||||
|
(mouse & BROWSER_MOUSE_CLICK_2)) {
|
||||||
|
js_fire_event(html->jscontext, "click", html->document, node);
|
||||||
|
}
|
||||||
|
|
||||||
/* deferred actions that can cause this browser_window to be destroyed
|
/* deferred actions that can cause this browser_window to be destroyed
|
||||||
* and must therefore be done after set_status/pointer
|
* and must therefore be done after set_status/pointer
|
||||||
*/
|
*/
|
||||||
|
@ -6,9 +6,7 @@
|
|||||||
|
|
||||||
function addTextNode()
|
function addTextNode()
|
||||||
{
|
{
|
||||||
var newtext = document.createTextNode(" Some text added dynamically. ");
|
para.appendChild(document.createTextNode(" Some text added dynamically. "));
|
||||||
var para = document.getElementById("p1");
|
|
||||||
para.appendChild(newtext);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
@ -19,10 +17,14 @@ para.appendChild(newtext);
|
|||||||
<p id="p1">First line of paragraph.<br /></p>
|
<p id="p1">First line of paragraph.<br /></p>
|
||||||
</div><br />
|
</div><br />
|
||||||
|
|
||||||
<button onclick="addTextNode();">add another textNode.</button>
|
<button id="button1" >add another textNode.</button>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
var button = document.getElementById("button1");
|
||||||
|
var para = document.getElementById("p1");
|
||||||
|
|
||||||
window.onload = addTextNode;
|
window.onload = addTextNode;
|
||||||
|
button.onclick = addTextNode;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
Loading…
Reference in New Issue
Block a user