// 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); } }
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); }
int edit_element_cb(const char *contents, gpointer data) { struct edit_element_cb_args *args; WebKitDOMHTMLTextAreaElement *ta; WebKitDOMHTMLInputElement *el; args = (struct edit_element_cb_args*)data; if (!args || !args->active) return (0); el = (WebKitDOMHTMLInputElement*)args->active; ta = (WebKitDOMHTMLTextAreaElement*)args->active; if (WEBKIT_DOM_IS_HTML_INPUT_ELEMENT(el)) webkit_dom_html_input_element_set_value(el, contents); else if (WEBKIT_DOM_IS_HTML_TEXT_AREA_ELEMENT(ta)) webkit_dom_html_text_area_element_set_value(ta, contents); return (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); }