Exemple #1
0
static void 
plugins_onclick_cb(WebKitDOMElement *element, WebKitDOMEvent *event, GList *gl) 
{
    WebKitDOMElement *e = g_object_get_data((gpointer)element, "dwb-plugin-element");
    ALLOWED(gl) = g_slist_append(ALLOWED(gl), e);
    WebKitDOMNode *parent = webkit_dom_node_get_parent_node(WEBKIT_DOM_NODE(element));
    WebKitDOMNode *child = webkit_dom_node_get_first_child(WEBKIT_DOM_NODE(element));
    webkit_dom_node_remove_child(WEBKIT_DOM_NODE(parent), child, NULL);
    webkit_dom_node_remove_child(parent, WEBKIT_DOM_NODE(element), NULL);
    webkit_dom_node_append_child(parent, WEBKIT_DOM_NODE(e), NULL);
    g_object_unref(parent);
}
Exemple #2
0
void
wgp_util_remove_all_children (WebKitDOMNode* parent)
{
	WebKitDOMNode* node;

	while (webkit_dom_node_has_child_nodes (parent)) {
		node =  webkit_dom_node_get_first_child (parent);
		webkit_dom_node_remove_child (parent, node, NULL);
	}
}
Exemple #3
0
void
plugins_create_click_element(WebKitDOMElement *element, GList *gl) 
{
    WebKitDOMNode *parent = webkit_dom_node_get_parent_node(WEBKIT_DOM_NODE(element));
    View *v = VIEW(gl);
    WebKitDOMElement *div;

    if (parent == NULL) 
        return;

    WebKitDOMDocument *doc = webkit_dom_node_get_owner_document(WEBKIT_DOM_NODE(element));
    WebKitDOMDOMWindow *win = webkit_dom_document_get_default_view(doc);

    WebKitDOMCSSStyleDeclaration *style = webkit_dom_dom_window_get_computed_style(win, element, "");
    char *width = webkit_dom_css_style_declaration_get_property_value(style, "width");
    char *height = webkit_dom_css_style_declaration_get_property_value(style, "height");
    char *top = webkit_dom_css_style_declaration_get_property_value(style, "top");
    char *left = webkit_dom_css_style_declaration_get_property_value(style, "left");
    char *position = webkit_dom_css_style_declaration_get_property_value(style, "position");
    int w, h;
    if (sscanf(width, "%dpx", &w) == 1 && w<72) 
        w = 72;
    if (sscanf(height, "%dpx", &h) == 1 && h<24) 
        h = 24;


    if (v->plugins->max <= v->plugins->created) 
    {
        div = webkit_dom_document_create_element(doc, "div", NULL);
        v->plugins->clicks = g_slist_prepend(v->plugins->clicks, div);
        v->plugins->max++;
    }
    else 
        div = g_slist_nth_data(v->plugins->clicks, v->plugins->created);
    webkit_dom_html_element_set_inner_html(WEBKIT_DOM_HTML_ELEMENT(div), 
            "<div style='display:table-cell;vertical-align:middle;text-align:center;color:#fff;background:#000;border:1px solid #666;font:11px monospace bold'>click to enable flash</div>", NULL);

    char *new_style = g_strdup_printf("position:%s;width:%dpx;height:%dpx;top:%s;left:%s;display:table;z-index:37000;", position, w, h, top, left);
    webkit_dom_element_set_attribute(div, "style", new_style, NULL);
    g_free(new_style);

    webkit_dom_element_set_attribute(div, "onclick", "return", NULL);

    g_object_set_data((gpointer)div, "dwb-plugin-element", element);

    webkit_dom_node_remove_child(parent, WEBKIT_DOM_NODE(element), NULL);
    webkit_dom_node_append_child(parent, WEBKIT_DOM_NODE(div), NULL);
    v->plugins->elements = g_slist_prepend(v->plugins->elements, element);

    webkit_dom_event_target_add_event_listener(WEBKIT_DOM_EVENT_TARGET(div), "click", G_CALLBACK(plugins_onclick_cb), true, gl);
    g_object_unref(style);
    g_object_unref(parent);
    v->plugins->created++;
}
static void
html_editor_image_dialog_set_url (EHTMLEditorImageDialog *dialog)
{
	WebKitDOMElement *link;
	const gchar *url;

	url = gtk_entry_get_text (GTK_ENTRY (dialog->priv->url_edit));
	link = e_html_editor_dom_node_find_parent_element (
		WEBKIT_DOM_NODE (dialog->priv->image), "A");

	if (link) {
		if (!url || !*url) {
			webkit_dom_node_insert_before (
				webkit_dom_node_get_parent_node (
					WEBKIT_DOM_NODE (link)),
				WEBKIT_DOM_NODE (dialog->priv->image),
				WEBKIT_DOM_NODE (link), NULL);
			webkit_dom_node_remove_child (
				webkit_dom_node_get_parent_node (
					WEBKIT_DOM_NODE (link)),
				WEBKIT_DOM_NODE (link), NULL);
		} else {
			webkit_dom_html_anchor_element_set_href (
				WEBKIT_DOM_HTML_ANCHOR_ELEMENT (link), url);
		}
	} else {
		if (url && *url) {
			WebKitDOMDocument *document;

			document = webkit_dom_node_get_owner_document (
					WEBKIT_DOM_NODE (dialog->priv->image));
			link = webkit_dom_document_create_element (
					document, "A", NULL);

			webkit_dom_html_anchor_element_set_href (
				WEBKIT_DOM_HTML_ANCHOR_ELEMENT (link), url);

			webkit_dom_node_insert_before (
				webkit_dom_node_get_parent_node (
					WEBKIT_DOM_NODE (dialog->priv->image)),
				WEBKIT_DOM_NODE (link),
				WEBKIT_DOM_NODE (dialog->priv->image), NULL);

			webkit_dom_node_append_child (
				WEBKIT_DOM_NODE (link),
				WEBKIT_DOM_NODE (dialog->priv->image), NULL);
		}
	}
}
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 */
}