Hi Markus! This patch works fine for me too. I'm not sure about the consequences, but I think it would be a better approach to use webkit functions like webkit_dom_html_text_area_element_set_value() instead of evaluating JavaScript. I suppose that using the c functions direct could be a little faster.
I attached a patch to show what I mean. This is only a sample, but it should be also possible to remove jsapi calls from _resume_from_editor() too. Daniel
From a9dea77aedf8f5997eacac62c4269aed3f583101 Mon Sep 17 00:00:00 2001 From: Daniel Carl <[email protected]> Date: Sat, 29 Sep 2012 15:15:13 +0200 Subject: [PATCH 1/1] Use webkit_dom_html* functions to get active element. --- main.c | 53 ++++++++++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/main.c b/main.c index 5acf509..f898606 100644 --- a/main.c +++ b/main.c @@ -1840,31 +1840,28 @@ open_editor(const Arg *arg) { gchar *temp_file_name = g_strdup("/tmp/vimprobableeditXXXXXX"); int temp_file_handle = -1; - /* check if active element is suitable for text editing */ - jsapi_evaluate_script("document.activeElement.tagName", &value, &message); - if (value == NULL) + WebKitDOMHTMLDocument *doc; + WebKitDOMElement *active_element; + WebKitDOMHTMLTextAreaElement *ta; + WebKitDOMHTMLInputElement *el; + + doc = (WebKitDOMHTMLDocument*)webkit_web_view_get_dom_document(webview); + if (doc == NULL) return FALSE; - tag = g_strdup(value); - if (strcmp(tag, "INPUT") == 0) { - /* extra check: type == text */ - jsapi_evaluate_script("document.activeElement.type", &value, &message); - if (strcmp(value, "text") != 0) { - g_free(value); - g_free(message); - return FALSE; - } - } else if (strcmp(tag, "TEXTAREA") != 0) { - g_free(value); - g_free(message); + + active_element = webkit_dom_html_document_get_active_element(doc); + if (active_element == NULL) return FALSE; - } - jsapi_evaluate_script("document.activeElement.value", &value, &message); - text = g_strdup(value); - if (text == NULL) { - g_free(value); - g_free(message); + + el = (WebKitDOMHTMLInputElement*)active_element; + ta = (WebKitDOMHTMLTextAreaElement*)active_element; + if (WEBKIT_DOM_IS_HTML_INPUT_ELEMENT(el) == 0 && WEBKIT_DOM_IS_HTML_TEXT_AREA_ELEMENT(ta) == 0) return FALSE; - } + + if (WEBKIT_DOM_IS_HTML_INPUT_ELEMENT(el)) + text = webkit_dom_html_input_element_get_value(el); + else if (WEBKIT_DOM_IS_HTML_TEXT_AREA_ELEMENT(ta)) + text = webkit_dom_html_text_area_element_get_value(ta); /* write text into temporary file */ temp_file_handle = mkstemp(temp_file_name); @@ -1901,14 +1898,12 @@ open_editor(const Arg *arg) { g_free(message); return FALSE; } - + /* mark the active text box as "under processing" */ - jsapi_evaluate_script( - "document.activeElement.disabled = true;" - "document.activeElement.originalBackground = " - " document.activeElement.style.background;" - "document.activeElement.style.background = '#aaaaaa';" - ,&value, &message); + if (WEBKIT_DOM_IS_HTML_INPUT_ELEMENT(el)) + webkit_dom_html_input_element_set_disabled(el, TRUE); + else if (WEBKIT_DOM_IS_HTML_TEXT_AREA_ELEMENT(ta)) + webkit_dom_html_input_element_set_disabled((WebKitDOMHTMLInputElement*)ta, TRUE); g_child_watch_add(child_pid, _resume_from_editor, temp_file_name); -- 1.7.9.5
signature.asc
Description: Digital signature
------------------------------------------------------------------------------ How fast is your code? 3 out of 4 devs don\\\'t know how their code performs in production. Find out how slow your code is with AppDynamics Lite. http://ad.doubleclick.net/clk;262219672;13503038;z? http://info.appdynamics.com/FreeJavaPerformanceDownload.html
_______________________________________________ Vimprobable-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/vimprobable-users
