|
26 | 26 | #include "extension/clib/dom_document.h" |
27 | 27 | #include "common/luajs.h" |
28 | 28 | #include "common/luauniq.h" |
| 29 | +#include "common/util.h" |
29 | 30 | #include "extension/extension.h" |
30 | 31 |
|
31 | 32 | #define REG_KEY "luakit.uniq.registry.dom_element" |
@@ -649,34 +650,35 @@ luaH_dom_element_remove_event_listener(lua_State *L) |
649 | 650 | return 1; |
650 | 651 | } |
651 | 652 |
|
652 | | -#if WEBKIT_CHECK_VERSION(2,18,0) |
653 | 653 | static gint |
654 | 654 | luaH_dom_element_client_rects(lua_State *L) |
655 | 655 | { |
656 | 656 | dom_element_t *element = luaH_check_dom_element(L, 1); |
657 | | - WebKitDOMClientRectList *rects = webkit_dom_element_get_client_rects(element->element); |
658 | | - int num_rects = webkit_dom_client_rect_list_get_length(rects); |
| 657 | + JSCValue *rects = jsc_value_object_invoke_method(L_DOM_ELEMENT_TO_JSC_VALUE(element), "getClientRects", G_TYPE_NONE); |
| 658 | + |
| 659 | + JSCValue *length = jsc_value_object_get_property(rects, "length"); |
| 660 | + int num_rects = jsc_value_to_int32(length); |
| 661 | + g_object_unref(length); |
659 | 662 |
|
660 | 663 | lua_createtable(L, num_rects, 0); |
661 | 664 | for (int i = 0; i < num_rects; ++i) { |
662 | | - WebKitDOMClientRect* rect = webkit_dom_client_rect_list_item(rects, i); |
| 665 | + JSCValue *rect = jsc_value_object_get_property_at_index(rects, i); |
663 | 666 | lua_newtable(L); |
664 | | -#define PROP(prop) \ |
665 | | - lua_pushnumber(L, webkit_dom_client_rect_get_##prop(rect)); \ |
666 | | - lua_setfield(L, -2, #prop); |
667 | | - PROP(top) |
668 | | - PROP(right) |
669 | | - PROP(bottom) |
670 | | - PROP(left) |
671 | | - PROP(width) |
672 | | - PROP(height) |
673 | | -#undef PROP |
| 667 | + char *properties[] = {"top", "right", "bottom", "left", "width", "height"}; |
| 668 | + for (int j = 0; j < LENGTH(properties); j++) { |
| 669 | + JSCValue *property = jsc_value_object_get_property(rect, properties[j]); |
| 670 | + lua_pushnumber(L, jsc_value_to_int32(property)); |
| 671 | + lua_setfield(L, -2, properties[j]); |
| 672 | + g_object_unref(property); |
| 673 | + } |
674 | 674 | lua_rawseti(L, -2, i+1); |
| 675 | + g_object_unref(rect); |
675 | 676 | } |
676 | 677 |
|
| 678 | + g_object_unref(rects); |
| 679 | + |
677 | 680 | return 1; |
678 | 681 | } |
679 | | -#endif |
680 | 682 |
|
681 | 683 | static int luaH_dom_element_push_attribute(lua_State *L, char *attribute) |
682 | 684 | { |
@@ -769,9 +771,7 @@ luaH_dom_element_index(lua_State *L) |
769 | 771 | PF_CASE(SUBMIT, luaH_dom_element_submit) |
770 | 772 | PF_CASE(ADD_EVENT_LISTENER, luaH_dom_element_add_event_listener) |
771 | 773 | PF_CASE(REMOVE_EVENT_LISTENER, luaH_dom_element_remove_event_listener) |
772 | | -#if WEBKIT_CHECK_VERSION(2,18,0) |
773 | 774 | PF_CASE(CLIENT_RECTS, luaH_dom_element_client_rects) |
774 | | -#endif |
775 | 775 |
|
776 | 776 | case L_TK_CHILD_COUNT: |
777 | 777 | return luaH_dom_element_push_property(L, "childElementCount"); |
|
0 commit comments