diff options
author | Daniel Carl <danielcarl@gmx.de> | 2015-04-26 23:30:36 +0200 |
---|---|---|
committer | Daniel Carl <danielcarl@gmx.de> | 2015-04-26 23:39:29 +0200 |
commit | a58e134dcb9e820476a6ce0924002447ca0f8cc2 (patch) | |
tree | ee04833dbbd021f88d860dfa3d0ae30af55838fd /src/dom.c | |
parent | af19c0c481e44fbb873d60c33cd1724747faa949 (diff) |
Check for dom focus/blur event on window object cleared (#201).
This allows us to track also focus changes within frames and iframes also if
they are loaded dynamically. The previous logic added the event listeners to
the document on WEBKIT_LOAD_FINISHED, but if there where later created iframes
in the dom, these where not observers for focus events.
This is only a first attempt to fix the focus issue and does break the logic
behind `set strict-focus=on`.
Diffstat (limited to 'src/dom.c')
-rw-r--r-- | src/dom.c | 45 |
1 files changed, 25 insertions, 20 deletions
@@ -30,37 +30,40 @@ static gboolean editable_focus_cb(Element *element, Event *event); static Element *get_active_element(Document *doc); -void dom_check_auto_insert(WebKitWebView *view) +void dom_check_auto_insert(Document *doc) { Element *active; HtmlElement *element; - Document *doc = webkit_web_view_get_dom_document(view); - /* FIrst check for current active element that bocomes focused before we + /* First check for current active element that becomes focused before we * could add the evnet observers. */ - active = get_active_element(doc); - 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 vim 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); + 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 vim 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); + } } element = webkit_dom_document_get_body(doc); if (!element) { element = WEBKIT_DOM_HTML_ELEMENT(webkit_dom_document_get_document_element(doc)); } - /* add event listener to track focus and blur events on the document */ - webkit_dom_event_target_add_event_listener( - WEBKIT_DOM_EVENT_TARGET(element), "blur", G_CALLBACK(editable_blur_cb), true, NULL - ); - webkit_dom_event_target_add_event_listener( - WEBKIT_DOM_EVENT_TARGET(element), "focus", G_CALLBACK(editable_focus_cb), true, NULL - ); + if (element) { + /* add event listener to track focus and blur events on the document */ + webkit_dom_event_target_add_event_listener( + WEBKIT_DOM_EVENT_TARGET(element), "blur", G_CALLBACK(editable_blur_cb), true, NULL + ); + webkit_dom_event_target_add_event_listener( + WEBKIT_DOM_EVENT_TARGET(element), "focus", G_CALLBACK(editable_focus_cb), true, NULL + ); + } } /** @@ -251,6 +254,7 @@ static gboolean auto_insert(Element *element) static gboolean editable_blur_cb(Element *element, Event *event) { + g_message("blur"); if (vb.mode->id == 'i') { vb_enter('n'); } @@ -259,6 +263,7 @@ static gboolean editable_blur_cb(Element *element, Event *event) static gboolean editable_focus_cb(Element *element, Event *event) { + g_message("focus"); auto_insert((Element*)webkit_dom_event_get_target(event)); return false; |