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
+ );
+ }
}
/**
static gboolean editable_blur_cb(Element *element, Event *event)
{
+ g_message("blur");
if (vb.mode->id == 'i') {
vb_enter('n');
}
static gboolean editable_focus_cb(Element *element, Event *event)
{
+ g_message("focus");
auto_insert((Element*)webkit_dom_event_get_target(event));
return false;
WebKitWebFrame *frame, WebKitNetworkRequest *request,
WebKitWebNavigationAction *action, WebKitWebPolicyDecision *policy,
gpointer data);
+static void window_object_cleared_cb(GtkWidget *widget, WebKitWebFrame *frame,
+ JSContextRef js, JSObjectRef win, gpointer user_data);
static void hover_link_cb(WebKitWebView *webview, const char *title, const char *link);
static void title_changed_cb(WebKitWebView *webview, WebKitWebFrame *frame, const char *title);
static gboolean mimetype_decision_cb(WebKitWebView *webview,
update_title();
if (strncmp(uri, "about:", 6)) {
- dom_check_auto_insert(view);
history_add(HISTORY_URL, uri, webkit_web_view_get_title(view));
}
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::window-object-cleared", G_CALLBACK(window_object_cleared_cb), NULL,
NULL
);
return false;
}
+static void window_object_cleared_cb(GtkWidget *widget, WebKitWebFrame *frame,
+ JSContextRef js, JSObjectRef win, gpointer user_data)
+{
+ Document *doc = webkit_web_frame_get_dom_document(frame);
+ dom_check_auto_insert(doc);
+}
+
static void hover_link_cb(WebKitWebView *webview, const char *title, const char *link)
{
char *message;