Beispiel #1
0
static void test_dom_document_get_elements_by_tag_name(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(document);
    WebKitDOMNodeList* list = webkit_dom_document_get_elements_by_tag_name(document, "li");
    g_assert(list);
    gulong length = webkit_dom_node_list_get_length(list);
    g_assert_cmpint(length, ==, 3);

    guint i;

    for (i = 0; i < length; i++) {
        WebKitDOMNode* item = webkit_dom_node_list_item(list, i);
        g_assert(item);
        WebKitDOMElement* element = (WebKitDOMElement*)item;
        g_assert(element);
        g_assert_cmpstr(webkit_dom_element_get_tag_name(element), ==, "LI");
        WebKitDOMHTMLElement* htmlElement = (WebKitDOMHTMLElement*)element;
        char* n = g_strdup_printf("%d", i+1);
        g_assert_cmpstr(webkit_dom_html_element_get_inner_text(htmlElement), ==, n);
        g_free(n);
    }

    g_object_unref(list);
}
Beispiel #2
0
static void
load_status_cb (GObject* object, GParamSpec* pspec, gpointer data) {
    WebKitDOMDocument *document;
    WebKitWebView *web_view;
    WebKitLoadStatus status;
    Ctx *ctx;
    gulong count;
    gint64 now, elapsed;

    ctx = (Ctx *) data;
    web_view = WEBKIT_WEB_VIEW(object);
    status = webkit_web_view_get_load_status(web_view);
    if (status != WEBKIT_LOAD_FINISHED) {
        return;
    }

    /* We now know that the document has been loaded */
    g_main_loop_quit(ctx->loop);
    now = g_get_monotonic_time();
    printf("Document loaded in %lldms\n", TO_MS(now - (ctx->start_time)));

    document = webkit_web_view_get_dom_document(web_view);
    count = walk_dom(WEBKIT_DOM_NODE(document));
    elapsed = g_get_monotonic_time() - now;
    printf("Document has %ld nodes and took %lldms to walk\n", count, TO_MS(elapsed));
}
Beispiel #3
0
static void test_dom_document_get_links(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(document);
    WebKitDOMHTMLCollection *collection = webkit_dom_document_get_links(document);
    g_assert(collection);
    gulong length = webkit_dom_html_collection_get_length(collection);
    g_assert_cmpint(length, ==, 3);

    guint i;

    for (i = 0; i < length; i++) {
        static const char* names[] = { "blank", "google", "webkit" };
        static const char* uris[] = { "about:blank", "http://www.google.com/", "http://www.webkit.org/" };
        WebKitDOMNode *node = webkit_dom_html_collection_item(collection, i);
        g_assert(node);
        WebKitDOMElement* element = (WebKitDOMElement*)node;
        g_assert_cmpstr(webkit_dom_element_get_tag_name(element), ==, "A");
        WebKitDOMHTMLElement *htmlElement = (WebKitDOMHTMLElement*)element;
        g_assert_cmpstr(webkit_dom_html_element_get_inner_text(htmlElement), ==, names[i]);
        WebKitDOMHTMLAnchorElement *anchor = (WebKitDOMHTMLAnchorElement*)element;
        g_assert_cmpstr(webkit_dom_html_anchor_element_get_href(anchor), ==, uris[i]);
    }
    g_object_unref(collection);
}
Beispiel #4
0
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);
}
Beispiel #5
0
void wqq_qqchat_append_time(WqqQQChat * chat, GDateTime * dt)
{
	g_return_if_fail(WQQ_IS_QQCHAT(chat));

	while (chat->loading) {
		gtk_main_iteration_do(TRUE);
	}

	gchar *now = g_date_time_format(dt, "%m-%d %k:%M");

	WebKitDOMDocument *doc =
		webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(chat->webview));
	WebKitDOMElement *body = webkit_dom_document_query_selector(doc,
																"body",
																NULL);
	WebKitDOMElement *div = webkit_dom_document_create_element(doc,
															   "div",
															   NULL);
	WebKitDOMElement *span = webkit_dom_document_create_element(doc,
																"span",
																NULL);
	webkit_dom_element_set_attribute(div, "class", "chat_time", NULL);
	webkit_dom_node_set_text_content(WEBKIT_DOM_NODE(span), now, NULL);
	webkit_dom_node_append_child(WEBKIT_DOM_NODE(body),
								 WEBKIT_DOM_NODE(div), NULL);
	webkit_dom_node_append_child(WEBKIT_DOM_NODE(div),
								 WEBKIT_DOM_NODE(span), NULL);
	g_free(now);
}
Beispiel #6
0
static void load_status_callback(WebKitWebView* webView, GParamSpec* spec, DomDomviewFixture* fixture)
{
    WebKitLoadStatus status = webkit_web_view_get_load_status(webView);
    if (status == WEBKIT_LOAD_FINISHED) {
        WebKitDOMDocument* document;
        WebKitDOMDOMWindow* domWindow;
        WebKitDOMElement* element;
        WebKitDOMEvent* event;
        glong clientX, clientY;

        document = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(fixture->webView));
        g_assert(document);
        domWindow = webkit_dom_document_get_default_view(document);
        g_assert(domWindow);
        fixture->domWindow = domWindow;

        element = webkit_dom_document_get_element_by_id(document, "test");
        g_assert(element);
        event = webkit_dom_document_create_event(document, "MouseEvent", NULL);
        g_assert(event);
        g_assert(WEBKIT_DOM_IS_EVENT(event));
        g_assert(WEBKIT_DOM_IS_MOUSE_EVENT(event));
        clientX = webkit_dom_element_get_client_left(element);
        clientY = webkit_dom_element_get_client_top(element);
        webkit_dom_mouse_event_init_mouse_event(WEBKIT_DOM_MOUSE_EVENT(event),
                                                "click", TRUE, TRUE,
                                                fixture->domWindow, 0, 0, 0, clientX, clientY,
                                                FALSE, FALSE, FALSE, FALSE,
                                                1, WEBKIT_DOM_EVENT_TARGET(element));
        webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(element), "click", G_CALLBACK(clicked_cb), false, fixture);
        g_assert(fixture->clicked == FALSE);
        webkit_dom_event_target_dispatch_event(WEBKIT_DOM_EVENT_TARGET(element), event, NULL);
    }

}
void
e_editor_selection_unlink (EEditorSelection *selection)
{
	WebKitDOMDocument *document;

	g_return_if_fail (E_IS_EDITOR_SELECTION (selection));

	document = webkit_web_view_get_dom_document (selection->priv->webview);
	webkit_dom_document_exec_command (document, "unlink", FALSE, "");
}
wxString wxWebViewWebKit::GetPageText() const
{
    WebKitDOMDocument* doc; 
    WebKitDOMHTMLElement* body;

    doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view));
    body = webkit_dom_document_get_body(WEBKIT_DOM_DOCUMENT(doc));
    return wxString(webkit_dom_html_element_get_inner_text(WEBKIT_DOM_HTML_ELEMENT(body)), 
                    wxConvUTF8);
}
Beispiel #9
0
void
plugins_load_status_cb(WebKitWebView *wv, GParamSpec *p, GList *gl) 
{
    WebKitLoadStatus status = webkit_web_view_get_load_status(wv);
    if (status == WEBKIT_LOAD_COMMITTED) 
    {
        WebKitDOMDocument *doc = webkit_web_view_get_dom_document(wv);
        WebKitDOMDOMWindow *win = webkit_dom_document_get_default_view(doc);
        webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(win), "beforeload", G_CALLBACK(plugins_before_load_cb), true, gl);
        webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(win), "beforeunload", G_CALLBACK(plugins_before_unload_cb), true, gl);
    }
}
Beispiel #10
0
void wxWebViewWebKit::ClearSelection()
{
    WebKitDOMDocument* doc; 
    WebKitDOMDOMWindow* win;
    WebKitDOMDOMSelection* sel;

    doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view));
    win = webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc));
    sel = webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win));
    webkit_dom_dom_selection_remove_all_ranges(WEBKIT_DOM_DOM_SELECTION(sel));

}
void
e_editor_selection_unindent (EEditorSelection *selection)
{
	WebKitDOMDocument *document;

	g_return_if_fail (E_IS_EDITOR_SELECTION (selection));

	document = webkit_web_view_get_dom_document (selection->priv->webview);
	webkit_dom_document_exec_command (document, "outdent", FALSE, "");

	g_object_notify (G_OBJECT (selection), "indented");
}
void
e_editor_selection_create_link (EEditorSelection *selection,
				const gchar *uri)
{
	WebKitDOMDocument *document;

	g_return_if_fail (E_IS_EDITOR_SELECTION (selection));
	g_return_if_fail (uri && *uri);

	document = webkit_web_view_get_dom_document (selection->priv->webview);
	webkit_dom_document_exec_command (document, "createLink", FALSE, uri);
}
void
e_editor_selection_insert_image (EEditorSelection *selection,
				 const gchar *image_uri)
{
	WebKitDOMDocument *document;

	g_return_if_fail (E_IS_EDITOR_SELECTION (selection));
	g_return_if_fail (image_uri != NULL);

	document = webkit_web_view_get_dom_document (selection->priv->webview);
	webkit_dom_document_exec_command (
			document, "insertImage", FALSE, image_uri);
}
void
e_editor_selection_set_font_name (EEditorSelection *selection,
				  const gchar *font_name)
{
	WebKitDOMDocument *document;

	g_return_if_fail (E_IS_EDITOR_SELECTION (selection));

	document = webkit_web_view_get_dom_document (selection->priv->webview);
	webkit_dom_document_exec_command (document, "fontName", FALSE, "");

	g_object_notify (G_OBJECT (selection), "font-name");
}
void
e_editor_selection_insert_html (EEditorSelection *selection,
				const gchar *html_text)
{
	WebKitDOMDocument *document;

	g_return_if_fail (E_IS_EDITOR_SELECTION (selection));
	g_return_if_fail (html_text != NULL);

	document = webkit_web_view_get_dom_document (selection->priv->webview);
	webkit_dom_document_exec_command (
			document, "insertHTML", FALSE, html_text);
}
Beispiel #16
0
static void test_dom_node_insertion(DomNodeFixture* fixture, gconstpointer data)
{
    WebKitDOMDocument* document;
    WebKitDOMHTMLElement* body;
    WebKitDOMElement* p, *div;
    WebKitDOMNodeList* list;
    WebKitDOMNode* node;

    document = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(fixture->webView));
    g_assert(document);
    body = webkit_dom_document_get_body(document);
    g_assert(body);
    g_assert(WEBKIT_DOM_IS_HTML_ELEMENT(body));

    /* Body shouldn't have any children at this point */
    g_assert(webkit_dom_node_has_child_nodes(WEBKIT_DOM_NODE(body)) == FALSE);

    /* Insert one P element */
    p = webkit_dom_document_create_element(document, "P", NULL);
    webkit_dom_node_append_child(WEBKIT_DOM_NODE(body), WEBKIT_DOM_NODE(p), NULL);

    /* Now it should have one, the same that we inserted */
    g_assert(webkit_dom_node_has_child_nodes(WEBKIT_DOM_NODE(body)));
    list = webkit_dom_node_get_child_nodes(WEBKIT_DOM_NODE(body));
    g_assert_cmpint(webkit_dom_node_list_get_length(list), ==, 1);
    node = webkit_dom_node_list_item(list, 0);
    g_assert(node);
    g_assert(webkit_dom_node_is_same_node(WEBKIT_DOM_NODE(p), node));
    g_object_unref(list);

    /* Replace the P tag with a DIV tag */
    div = webkit_dom_document_create_element(document, "DIV", NULL);
    webkit_dom_node_replace_child(WEBKIT_DOM_NODE(body), WEBKIT_DOM_NODE(div), WEBKIT_DOM_NODE(p), NULL);
    g_assert(webkit_dom_node_has_child_nodes(WEBKIT_DOM_NODE(body)));
    list = webkit_dom_node_get_child_nodes(WEBKIT_DOM_NODE(body));
    g_assert_cmpint(webkit_dom_node_list_get_length(list), ==, 1);
    node = webkit_dom_node_list_item(list, 0);
    g_assert(node);
    g_assert(webkit_dom_node_is_same_node(WEBKIT_DOM_NODE(div), node));
    g_object_unref(list);

    /* Now remove the tag */
    webkit_dom_node_remove_child(WEBKIT_DOM_NODE(body), node, NULL);
    list = webkit_dom_node_get_child_nodes(WEBKIT_DOM_NODE(body));
    g_assert_cmpint(webkit_dom_node_list_get_length(list), ==, 0);
    g_object_unref(list);

    /* TODO: insert_before, which does not seem to be working correctly */
}
Beispiel #17
0
wxString wxWebViewWebKit::GetSelectedText() const
{
    WebKitDOMDocument* doc; 
    WebKitDOMDOMWindow* win;
    WebKitDOMDOMSelection* sel;
    WebKitDOMRange* range;

    doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(web_view));
    win = webkit_dom_document_get_default_view(WEBKIT_DOM_DOCUMENT(doc));
    sel = webkit_dom_dom_window_get_selection(WEBKIT_DOM_DOM_WINDOW(win));
    range = webkit_dom_dom_selection_get_range_at(WEBKIT_DOM_DOM_SELECTION(sel), 
                                                  0, NULL);
    return wxString(webkit_dom_range_get_text(WEBKIT_DOM_RANGE(range)), 
                    wxConvUTF8);
}
Beispiel #18
0
void
window_object_cleared_cb(WebKitWebView *webview, WebKitWebFrame *frame,
        JSGlobalContextRef *context, JSObjectRef *object) {
    (void) frame; (void) context; (void) object;
#if WEBKIT_CHECK_VERSION (1, 3, 13)
    // Take this opportunity to set some callbacks on the DOM
    WebKitDOMDocument *document = webkit_web_view_get_dom_document (webview);
    webkit_dom_event_target_add_event_listener (WEBKIT_DOM_EVENT_TARGET (document),
        "focus", G_CALLBACK(dom_focus_cb), TRUE, NULL);
    webkit_dom_event_target_add_event_listener (WEBKIT_DOM_EVENT_TARGET (document),
        "blur", G_CALLBACK(dom_focus_cb), TRUE, NULL);
#else
	(void) webview;
#endif
}
void
e_editor_selection_set_background_color (EEditorSelection *selection,
					const gchar *color)
{
	WebKitDOMDocument *document;

	g_return_if_fail (E_IS_EDITOR_SELECTION (selection));
	g_return_if_fail (color && *color);

	document = webkit_web_view_get_dom_document (selection->priv->webview);
	webkit_dom_document_exec_command (
		document, "backColor", FALSE, color);

	g_object_notify (G_OBJECT (selection), "background-color");
}
void
e_editor_selection_set_font_size (EEditorSelection *selection,
				  guint font_size)
{
	WebKitDOMDocument *document;
	gchar *size_str;

	g_return_if_fail (E_IS_EDITOR_SELECTION (selection));

	document = webkit_web_view_get_dom_document (selection->priv->webview);
	size_str = g_strdup_printf("%d", font_size);
	webkit_dom_document_exec_command (document, "fontSize", FALSE, size_str);
	g_free (size_str);

	g_object_notify (G_OBJECT (selection), "font-size");
}
Beispiel #21
0
static void test_dom_document_title(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(document);
    gchar* title = webkit_dom_document_get_title(document);
    g_assert(title);
    g_assert_cmpstr(title, ==, "This is the title");
    g_free(title);
    webkit_dom_document_set_title(document, "This is the second title");
    title = webkit_dom_document_get_title(document);
    g_assert(title);
    g_assert_cmpstr(title, ==, "This is the second title");
    g_free(title);
}
void
e_editor_selection_set_monospaced (EEditorSelection *selection,
				   gboolean monospaced)
{
	WebKitDOMDocument *document;
	WebKitDOMRange *range;
	gboolean is_monospaced;

	g_return_if_fail (E_IS_EDITOR_SELECTION (selection));

	is_monospaced = e_editor_selection_get_monospaced (selection) ? TRUE : FALSE;
	if ((is_monospaced ? TRUE : FALSE) == (monospaced ? TRUE : FALSE)) {
		return;
	}

	range = editor_selection_get_current_range (selection);
	if (!range) {
		return;
	}

	document = webkit_web_view_get_dom_document (selection->priv->webview);
	if (monospaced) {
		WebKitDOMElement *wrapper;
		gchar *html;

		wrapper = webkit_dom_document_create_element (document, "TT", NULL);
		webkit_dom_node_append_child (
			WEBKIT_DOM_NODE (wrapper),
			WEBKIT_DOM_NODE (webkit_dom_range_clone_contents (range, NULL)),
			NULL);

		html = webkit_dom_html_element_get_outer_html (
				WEBKIT_DOM_HTML_ELEMENT (wrapper));
		e_editor_selection_insert_html (selection, html);
	} else {
		/* XXX This removes _all_ formatting that the selection has.
		 *     In theory it's possible to write a code that would remove
		 *     the <TT> from selection using advanced DOM manipulation,
		 *     but right now I don't really feel like writing it all... */
		webkit_dom_document_exec_command (
			document, "removeFormat", FALSE, "");
	}

	g_object_notify (G_OBJECT (selection), "monospaced");
}
Beispiel #23
0
static void
mark_links(GtkButton *button, WebKitWebView *view)
{
    WebKitDOMDocument* document = webkit_web_view_get_dom_document(view);
    WebKitDOMHTMLCollection *collection = webkit_dom_document_get_links(document);
    gulong length = webkit_dom_html_collection_get_length(collection);
    guint i;

    for (i = 0; i < length; i++) {
        WebKitDOMNode *node = webkit_dom_html_collection_item(collection, i);
        WebKitDOMElement* element = (WebKitDOMElement*)node;
        WebKitDOMCSSStyleDeclaration *style = webkit_dom_element_get_style(element);
        webkit_dom_css_style_declaration_set_property(style, "-webkit-transition", "top 1s ease-in", "", NULL);
        webkit_dom_css_style_declaration_set_property(style, "top", "25px", "", NULL);
        webkit_dom_css_style_declaration_set_property(style, "position", "relative", "", NULL);
        g_timeout_add(1000, (GSourceFunc)bounce_back, style);
    }
}
void
e_editor_selection_set_bold (EEditorSelection *selection,
			     gboolean bold)
{
	WebKitDOMDocument *document;

	g_return_if_fail (E_IS_EDITOR_SELECTION (selection));

	if ((e_editor_selection_get_bold (selection) ? TRUE : FALSE)
				== (bold ? TRUE : FALSE)) {
		return;
	}

	document = webkit_web_view_get_dom_document (selection->priv->webview);
	webkit_dom_document_exec_command (document, "bold", FALSE, "");

	g_object_notify (G_OBJECT (selection), "bold");
}
Beispiel #25
0
int
edit_element(struct tab *t, struct karg *a)
{
	WebKitDOMHTMLDocument		*doc;
	WebKitDOMElement		*active_element;
	WebKitDOMHTMLTextAreaElement	*ta;
	WebKitDOMHTMLInputElement	*el;
	char				*contents;
	struct edit_element_cb_args	*args;

	if (external_editor == NULL){
		show_oops(t,"Setting external_editor not set");
		return (0);
	}

	doc = (WebKitDOMHTMLDocument*)webkit_web_view_get_dom_document(t->wv);
	active_element = webkit_dom_html_document_get_active_element(doc);
	el = (WebKitDOMHTMLInputElement*)active_element;
	ta = (WebKitDOMHTMLTextAreaElement*)active_element;

	if (doc == NULL || active_element == NULL ||
	    (WEBKIT_DOM_IS_HTML_INPUT_ELEMENT(el) == 0 &&
	    WEBKIT_DOM_IS_HTML_TEXT_AREA_ELEMENT(ta) == 0)) {
		show_oops(t, "No active text element!");
		return (1);
	}

	contents = "";
	if (WEBKIT_DOM_IS_HTML_INPUT_ELEMENT(el))
		contents = webkit_dom_html_input_element_get_value(el);
	else if (WEBKIT_DOM_IS_HTML_TEXT_AREA_ELEMENT(ta))
		contents = webkit_dom_html_text_area_element_get_value(ta);

	if ((args = g_malloc(sizeof(struct edit_element_cb_args))) == NULL)
		return (1);

	args->tab = t;
	args->active = active_element;

	open_external_editor(t, contents, &edit_element_cb,  args);

	return (0);
}
Beispiel #26
0
static void test_dom_document_get_element_by_id(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(document);
    WebKitDOMElement* element = webkit_dom_document_get_element_by_id(document, "testok");
    g_assert(element);
    element = webkit_dom_document_get_element_by_id(document, "this-id-does-not-exist");
    g_assert(element == 0);
    /* The DOM spec says the return value is undefined when there's
     * more than one element with the same id; in our case the first
     * one will be returned */
    element = webkit_dom_document_get_element_by_id(document, "testbad");
    g_assert(element);
    WebKitDOMHTMLElement* htmlElement = (WebKitDOMHTMLElement*)element;
    g_assert_cmpstr(webkit_dom_html_element_get_inner_text(htmlElement), ==, "first");
}
static gint
get_caret_position (EHTMLEditorView *view)
{
	WebKitDOMDocument *document;
	WebKitDOMDOMWindow *window;
	WebKitDOMDOMSelection *selection;
	WebKitDOMRange *range;
	gint range_count;
	WebKitDOMNodeList *nodes;
	gulong ii, length;

	document = webkit_web_view_get_dom_document (WEBKIT_WEB_VIEW (view));
	window = webkit_dom_document_get_default_view (document);
	selection = webkit_dom_dom_window_get_selection (window);

	if (webkit_dom_dom_selection_get_range_count (selection) < 1)
		return 0;

	range = webkit_dom_dom_selection_get_range_at (selection, 0, NULL);
	range_count = 0;
	nodes = webkit_dom_node_get_child_nodes (
		webkit_dom_node_get_parent_node (
			webkit_dom_dom_selection_get_anchor_node (
				selection)));
	length = webkit_dom_node_list_get_length (nodes);
	for (ii = 0; ii < length; ii++) {
		WebKitDOMNode *node;

		node = webkit_dom_node_list_item (nodes, ii);
		if (webkit_dom_node_is_same_node (
			node, webkit_dom_dom_selection_get_anchor_node (selection))) {

			break;
		} else if (WEBKIT_DOM_IS_TEXT (node)) {
			gchar *text = webkit_dom_node_get_text_content (node);
			range_count += strlen (text);
			g_free (text);
		}
	}

	g_object_unref (nodes);
	return webkit_dom_range_get_start_offset (range, NULL) + range_count;
}
static WebKitDOMRange *
editor_selection_get_current_range (EEditorSelection *selection)
{
  WebKitDOMDocument *document;
  WebKitDOMDOMWindow *window;
  WebKitDOMDOMSelection *dom_selection;

  document = webkit_web_view_get_dom_document (selection->priv->webview);
  window = webkit_dom_document_get_default_view (document);

  if (!window)
    return NULL;

  dom_selection = webkit_dom_dom_window_get_selection (window);
  
  if (webkit_dom_dom_selection_get_range_count (dom_selection) < 1)
    return NULL;

  return webkit_dom_dom_selection_get_range_at (dom_selection, 0, NULL);
}
Beispiel #29
0
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);
}
Beispiel #30
0
/**
 * Set focus to the first found editable element and returns if a element was
 * found to focus.
 */
gboolean dom_focus_input(WebKitWebView *view)
{
    gboolean found = false;
    WebKitDOMNode *html, *node;
    WebKitDOMDocument *doc;
    WebKitDOMDOMWindow *win;
    WebKitDOMNodeList *list;
    WebKitDOMXPathNSResolver *resolver;
    WebKitDOMXPathResult* result;

    doc  = webkit_web_view_get_dom_document(view);
    win  = webkit_dom_document_get_default_view(doc);
    list = webkit_dom_document_get_elements_by_tag_name(doc, "html");
    if (!list) {
        return false;
    }

    html     = webkit_dom_node_list_item(list, 0);
    resolver = webkit_dom_document_create_ns_resolver(doc, html);
    if (!resolver) {
        return false;
    }

    result = webkit_dom_document_evaluate(
        doc, "//input[not(@type) or @type='text' or @type='password']|//textarea",
        html, resolver, 0, NULL, NULL
    );
    if (!result) {
        return false;
    }
    while ((node = webkit_dom_xpath_result_iterate_next(result, NULL))) {
        if (element_is_visible(win, WEBKIT_DOM_ELEMENT(node))) {
            webkit_dom_element_focus(WEBKIT_DOM_ELEMENT(node));
            found = true;
            break;
        }
    }
    g_object_unref(list);

    return found;
}