Exemple #1
0
static Element *get_active_element(Document *doc)
{
    char *tagname;
    Document *d = NULL;
    Element *active, *result = NULL;

    active = webkit_dom_html_document_get_active_element((void*)doc);
    if (!active) {
        return result;
    }
    tagname = webkit_dom_element_get_tag_name(active);

    if (!g_strcmp0(tagname, "FRAME")) {
        d = webkit_dom_html_frame_element_get_content_document(WEBKIT_DOM_HTML_FRAME_ELEMENT(active));
        result = get_active_element(d);
    } else if (!g_strcmp0(tagname, "IFRAME")) {
        d = webkit_dom_html_iframe_element_get_content_document(WEBKIT_DOM_HTML_IFRAME_ELEMENT(active));
        result = get_active_element(d);
    }
    g_free(tagname);

    if (result) {
        return result;
    }

    return active;
}
static gboolean
mail_shell_view_mail_display_needs_key (EMailDisplay *mail_display,
                                        gboolean with_input)
{
	gboolean needs_key = FALSE;

	if (gtk_widget_has_focus (GTK_WIDGET (mail_display))) {
		WebKitWebFrame *frame;
		WebKitDOMDocument *dom;
		WebKitDOMElement *element;
		gchar *name = NULL;

		frame = webkit_web_view_get_focused_frame (WEBKIT_WEB_VIEW (mail_display));
		if (!frame)
			return FALSE;
		dom = webkit_web_frame_get_dom_document (frame);
		element = webkit_dom_html_document_get_active_element (WEBKIT_DOM_HTML_DOCUMENT (dom));

		if (element)
			name = webkit_dom_node_get_node_name (WEBKIT_DOM_NODE (element));

		/* if INPUT or TEXTAREA has focus, then any key press should go there */
		if (name && ((with_input && g_ascii_strcasecmp (name, "INPUT") == 0) || g_ascii_strcasecmp (name, "TEXTAREA") == 0)) {
			needs_key = TRUE;
		}

		g_free (name);
	}

	return needs_key;
}
Exemple #3
0
void dom_check_auto_insert(Document *doc)
{
    Element *active = webkit_dom_html_document_get_active_element(WEBKIT_DOM_HTML_DOCUMENT(doc));

    if (active) {
        if (!vb.config.strict_focus) {
            auto_insert(active);
        } else if (vb.mode->id != 'i') {
            /* If strict-focus is enabled and the editable element becomes
             * focus, we explicitely remove the focus. But only if vimb isn't
             * in input mode at the time. This prevents from leaving input
             * mode that was started by user interaction like click to
             * editable element, or the 'gi' normal mode command. */
            webkit_dom_element_blur(active);
        }
    }
    dom_install_focus_blur_callbacks(doc);
}
Exemple #4
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);
}
Exemple #5
0
int
dom_is_input(struct tab *t, WebKitDOMElement **active)
{
	WebKitDOMDocument	*doc;
	WebKitDOMElement	*a;

	WebKitDOMHTMLFrameElement *frame;
	WebKitDOMHTMLIFrameElement *iframe;

	/* proof positive that OO is stupid */

	doc = webkit_web_view_get_dom_document(t->wv);

	/* unwind frames and iframes until the cows come home */
	for (;;) {
		a = webkit_dom_html_document_get_active_element(
		    (WebKitDOMHTMLDocument*)doc);
		if (a == NULL)
			return (0);

		/*
		 * I think this is a total hack because this property isn't
		 * set for textareas or input however, it is set for jquery
		 * textareas that do rich text.  Since this works around issues
		 * in RT we'll simply keep it!
		 *
		 * This might break some other stuff but for now it helps.
		 */
		if (webkit_dom_html_element_get_is_content_editable(
		    (WebKitDOMHTMLElement*)a)) {
			*active = a;
			return (1);
		}

		frame = (WebKitDOMHTMLFrameElement *)a;
		if (WEBKIT_DOM_IS_HTML_FRAME_ELEMENT(frame)) {
			doc = webkit_dom_html_frame_element_get_content_document(
			    frame);
			continue;
		}

		iframe = (WebKitDOMHTMLIFrameElement *)a;
		if (WEBKIT_DOM_IS_HTML_IFRAME_ELEMENT(iframe)) {
			doc = webkit_dom_html_iframe_element_get_content_document(
			    iframe);
			continue;
		}

		break;
	}

	if (a == NULL)
		return (0);

	if (WEBKIT_DOM_IS_HTML_INPUT_ELEMENT((WebKitDOMNode *)a) ||
	    WEBKIT_DOM_IS_HTML_TEXT_AREA_ELEMENT((WebKitDOMNode *)a)) {
		*active = a;
		return (1);
	}

	return (0);
}