static Element *get_active_element(Document *doc);
-void dom_check_auto_insert(Document *doc)
+void dom_auto_insert_unless_strict_focus(Document *doc)
{
- Element *active;
- HtmlElement *element;
+ Element *active = webkit_dom_html_document_get_active_element(WEBKIT_DOM_HTML_DOCUMENT(doc));
- /* First check for current active element that becomes focused before we
- * could add the evnet observers. */
- 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);
}
}
+}
+
+void dom_install_focus_blur_callbacks(Document *doc)
+{
+ HtmlElement *element = webkit_dom_document_get_body(doc);
- element = webkit_dom_document_get_body(doc);
if (!element) {
element = WEBKIT_DOM_HTML_ELEMENT(webkit_dom_document_get_document_element(doc));
}
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
);
}
}
+void dom_check_auto_insert(Document *doc)
+{
+ dom_auto_insert_unless_strict_focus(doc);
+ dom_install_focus_blur_callbacks(doc);
+}
+
/**
* Remove focus from active and editable elements.
*/
static gboolean editable_focus_cb(Element *element, Event *event)
{
- auto_insert((Element*)webkit_dom_event_get_target(event));
+ if (vb.state.done_loading_page || !vb.config.strict_focus) {
+ auto_insert((Element*)webkit_dom_event_get_target(event));
+ }
return false;
}
#define HtmlInputElement WebKitDOMHTMLInputElement
#define HtmlTextareaElement WebKitDOMHTMLTextAreaElement
+void dom_install_focus_blur_callbacks(Document *doc);
+void dom_auto_insert_unless_strict_focus(Document *doc);
void dom_check_auto_insert(Document *doc);
void dom_clear_focus(WebKitWebView *view);
gboolean dom_focus_input(Document *doc);
/* clear possible set marks */
marks_clear();
+
break;
case WEBKIT_LOAD_FIRST_VISUALLY_NON_EMPTY_LAYOUT:
}
WebKitWebFrame *frame = webkit_web_view_get_main_frame(view);
- dom_check_auto_insert(webkit_web_frame_get_dom_document(frame));
+ dom_install_focus_blur_callbacks(webkit_web_frame_get_dom_document(frame));
+ vb.state.done_loading_page = false;
break;
"signal::should-show-delete-interface-for-element", G_CALLBACK(gtk_false), NULL,
"signal::resource-request-starting", G_CALLBACK(webview_request_starting_cb), NULL,
"signal::navigation-policy-decision-requested", G_CALLBACK(navigation_decision_requested_cb), NULL,
+ "signal::onload-event", G_CALLBACK(onload_event_cb), NULL,
NULL
);
return false;
}
+static void onload_event_cb(WebKitWebView *view, WebKitWebFrame *frame,
+ gpointer user_data)
+{
+ Document *doc = webkit_web_frame_get_dom_document(frame);
+ dom_auto_insert_unless_strict_focus(doc);
+ vb.state.done_loading_page = true;
+}
+
static void hover_link_cb(WebKitWebView *webview, const char *title, const char *link)
{
char *message;