static void test_dom_node_hierarchy_navigation(DomNodeFixture* fixture, gconstpointer data) { WebKitDOMDocument* document; WebKitDOMHTMLHeadElement* head; WebKitDOMHTMLBodyElement* body; WebKitDOMNodeList* list; WebKitDOMNode* ptr; gulong i, length; document = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(fixture->webView)); g_assert(document); g_assert(WEBKIT_DOM_IS_DOCUMENT(document)); head = webkit_dom_document_get_head(document); g_assert(head); g_assert(WEBKIT_DOM_IS_HTML_HEAD_ELEMENT(head)); /* Title, head's child */ g_assert(webkit_dom_node_has_child_nodes(WEBKIT_DOM_NODE(head))); list = webkit_dom_node_get_child_nodes(WEBKIT_DOM_NODE(head)); g_assert_cmpint(webkit_dom_node_list_get_length(list), ==, 1); ptr = webkit_dom_node_list_item(list, 0); g_assert(ptr); g_assert(WEBKIT_DOM_IS_HTML_TITLE_ELEMENT(ptr)); g_object_unref(list); /* Body, Head sibling */ ptr = webkit_dom_node_get_next_sibling(WEBKIT_DOM_NODE(head)); g_assert(ptr); body = WEBKIT_DOM_HTML_BODY_ELEMENT(ptr); g_assert(WEBKIT_DOM_IS_HTML_BODY_ELEMENT(body)); /* There is no third sibling */ ptr = webkit_dom_node_get_next_sibling(ptr); g_assert(ptr == NULL); /* Body's previous sibling is Head */ ptr = webkit_dom_node_get_previous_sibling(WEBKIT_DOM_NODE(body)); g_assert(ptr); g_assert(WEBKIT_DOM_IS_HTML_HEAD_ELEMENT(ptr)); /* Body has 3 children */ g_assert(webkit_dom_node_has_child_nodes(WEBKIT_DOM_NODE(body))); list = webkit_dom_node_get_child_nodes(WEBKIT_DOM_NODE(body)); length = webkit_dom_node_list_get_length(list); g_assert_cmpint(length, ==, 3); /* The three of them are P tags */ for (i = 0; i < length; i++) { ptr = webkit_dom_node_list_item(list, i); g_assert(ptr); g_assert(WEBKIT_DOM_IS_HTML_PARAGRAPH_ELEMENT(ptr)); } /* Go backwards */ for (i = 0; ptr; ptr = webkit_dom_node_get_previous_sibling(ptr), i++) /* Nothing */; g_assert_cmpint(i, ==, 3); g_object_unref(list); }
// active_element_change_cb is called when the active element is changed, and // updates bookkeeping and the main process. static void active_element_change_cb(WebKitDOMEventTarget *target, WebKitDOMEvent *event, gpointer user_data) { Exten *exten = user_data; WebKitDOMDocument *document; if(WEBKIT_DOM_IS_DOCUMENT(target)) { document = WEBKIT_DOM_DOCUMENT(target); } else { // target is a window. g_object_get(target, "document", &document, NULL); } WebKitDOMElement *active = webkit_dom_document_get_active_element(document); if(active == NULL || active == exten->active) { return; } if(WEBKIT_DOM_IS_HTML_IFRAME_ELEMENT(active)) { // The iframe document handles this, unless it isn't registered yet. // In this case, register it and call recursively. WebKitDOMDocument *doc = webkit_dom_html_iframe_element_get_content_document( WEBKIT_DOM_HTML_IFRAME_ELEMENT(active)); if(!g_hash_table_contains(exten->registered_documents, doc)) { frame_document_loaded(doc, exten); active_element_change_cb( WEBKIT_DOM_EVENT_TARGET(doc), NULL, exten); } return; } exten->active = active; exten->scroll_target = get_scroll_target(active); // Check whether the currently active element is an input element. // If this has changed, signal DBus. // // Input elements: // // WebKitDOMHTMLAppletElement // WebKitDOMHTMLEmbedElement // WebKitDOMHTMLInputElement // WebKitDOMHTMLTextAreaElement gboolean input_focus = ( WEBKIT_DOM_IS_HTML_APPLET_ELEMENT(active) || WEBKIT_DOM_IS_HTML_EMBED_ELEMENT(active) || WEBKIT_DOM_IS_HTML_INPUT_ELEMENT(active) || WEBKIT_DOM_IS_HTML_TEXT_AREA_ELEMENT(active)); if(input_focus != exten->last_input_focus) { exten->last_input_focus = input_focus; input_focus_changed( exten->page_id, input_focus, exten); } }
static void test_dom_document_insert_row(DomDocumentFixture* fixture, gconstpointer data) { g_assert(fixture); WebKitWebView* view = (WebKitWebView*)fixture->webView; g_assert(view); WebKitDOMDocument* document = webkit_web_view_get_dom_document(view); g_assert(WEBKIT_DOM_IS_DOCUMENT(document)); WebKitDOMElement* table = webkit_dom_document_get_element_by_id(document, "table"); g_assert(WEBKIT_DOM_IS_HTML_ELEMENT(table)); WebKitDOMHTMLCollection* rows = webkit_dom_html_table_element_get_rows(WEBKIT_DOM_HTML_TABLE_ELEMENT(table)); g_assert(WEBKIT_DOM_IS_HTML_COLLECTION(rows)); // Table is initially empty. g_assert_cmpint(webkit_dom_html_collection_get_length(rows), ==, 0); WebKitDOMHTMLElement* row = webkit_dom_html_table_element_insert_row(WEBKIT_DOM_HTML_TABLE_ELEMENT(table), -1, NULL); g_assert(WEBKIT_DOM_IS_HTML_TABLE_ROW_ELEMENT(row)); rows = webkit_dom_html_table_element_get_rows(WEBKIT_DOM_HTML_TABLE_ELEMENT(table)); g_assert(WEBKIT_DOM_IS_HTML_COLLECTION(rows)); g_assert_cmpint(webkit_dom_html_collection_get_length(rows), ==, 1); }