diff options
-rw-r--r-- | inputfocus.c | 196 | ||||
-rw-r--r-- | xombrero.c | 36 | ||||
-rw-r--r-- | xombrero.conf | 102 | ||||
-rw-r--r-- | xombrero.h | 7 |
4 files changed, 105 insertions, 236 deletions
diff --git a/inputfocus.c b/inputfocus.c index fc6f259..9115e66 100644 --- a/inputfocus.c +++ b/inputfocus.c @@ -1,6 +1,5 @@ /* * Copyright (c) 2011 Marco Peereboom <marco@peereboom.us> - * Copyright (c) 2012 Josh Rickmar <jrick@devio.us> * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -19,43 +18,6 @@ #if WEBKIT_CHECK_VERSION(1, 5, 0) /* we got the DOM API we need */ - -void -focus_body(WebKitDOMDocument *doc) -{ - WebKitDOMNodeList *body = NULL; - WebKitDOMNode *n; - int i; - - body = webkit_dom_document_get_elements_by_tag_name(doc, "body"); - for (i = 0; i < webkit_dom_node_list_get_length(body); ++i) { - n = webkit_dom_node_list_item(body, i); - webkit_dom_element_focus((WebKitDOMElement *)n); -#if WEBKIT_CHECK_VERSION(1, 8, 0) - webkit_dom_html_element_click((WebKitDOMHTMLElement *)n); -#endif - break; - } -} - -int -node_is_valid_entry(WebKitDOMNode *n) -{ - if (n == NULL) - return (FALSE); - - if (WEBKIT_DOM_IS_HTML_INPUT_ELEMENT(n) && - webkit_dom_html_input_element_check_validity( - (WebKitDOMHTMLInputElement *)n)) - return (TRUE); - if (WEBKIT_DOM_IS_HTML_TEXT_AREA_ELEMENT(n) && - webkit_dom_html_text_area_element_check_validity( - (WebKitDOMHTMLTextAreaElement *)n)) - return (TRUE); - - return (FALSE); -} - int focus_input_document(struct tab *t, WebKitDOMDocument *doc) { @@ -75,16 +37,13 @@ focus_input_document(struct tab *t, WebKitDOMDocument *doc) n = webkit_dom_node_list_item(input, i); in = (WebKitDOMHTMLInputElement*)n; g_object_get(G_OBJECT(in), "type", &es, (char *)NULL); - if ((g_strcmp0("text", es) && g_strcmp0("password",es)) || + if ((!g_str_equal("text", es) && !g_str_equal("password",es)) || webkit_dom_html_input_element_get_disabled(in)) { /* skip not text */ g_free(es); continue; } webkit_dom_element_focus((WebKitDOMElement*)in); -#if WEBKIT_CHECK_VERSION(1, 8, 0) - webkit_dom_html_element_click((WebKitDOMHTMLElement*)in); -#endif g_free(es); rv = 1; /* found */ goto done; @@ -100,9 +59,6 @@ focus_input_document(struct tab *t, WebKitDOMDocument *doc) continue; } webkit_dom_element_focus((WebKitDOMElement*)ta); -#if WEBKIT_CHECK_VERSION(1, 8, 0) - webkit_dom_html_element_click((WebKitDOMHTMLElement*)ta); -#endif rv = 1; /* found */ goto done; } @@ -114,39 +70,19 @@ done: return (rv); } - -char * -get_element_text(WebKitDOMNode *n) -{ - if (WEBKIT_DOM_IS_HTML_INPUT_ELEMENT(n)) - return (g_strdup(webkit_dom_html_input_element_get_value( - (WebKitDOMHTMLInputElement *)n))); - else if (WEBKIT_DOM_IS_HTML_TEXT_AREA_ELEMENT(n)) - return (g_strdup(webkit_dom_html_text_area_element_get_value( - (WebKitDOMHTMLTextAreaElement *)n))); - return (NULL); -} - int focus_input(struct tab *t) { WebKitDOMDocument *doc; WebKitDOMNode *n; WebKitDOMNodeList *fl = NULL, *ifl = NULL; - WebKitDOMElement *a; - int i, fl_count, ifl_count, rv = 0; /* not found */ + int i, fl_count, ifl_count, rv = 0; WebKitDOMHTMLFrameElement *frame; WebKitDOMHTMLIFrameElement *iframe; /* * Here is what we are doing: - * - * If a textbox is already focused, leave it alone. - * - * Try the tab's previous active entry, for example if it was set by - * some javascript when the page loaded. - * * See if we got frames or iframes * * if we do focus on input or textarea in frame or in iframe @@ -157,30 +93,6 @@ focus_input(struct tab *t) doc = webkit_web_view_get_dom_document(t->wv); - /* try current active element */ - a = webkit_dom_html_document_get_active_element( - (WebKitDOMHTMLDocument*)doc); - if (node_is_valid_entry((WebKitDOMNode *)a)) { - rv = 1; /* found */ - goto done; - } - - /* try previous active element */ - if (node_is_valid_entry((WebKitDOMNode *)t->active)) { - webkit_dom_element_focus((WebKitDOMElement*)t->active); -#if WEBKIT_CHECK_VERSION(1, 8, 0) - webkit_dom_html_element_click((WebKitDOMHTMLElement*)t->active); -#endif - rv = 1; /* found */ - goto done; - } else { - t->active = NULL; - if (t->active_text) { - g_free(t->active_text); - t->active_text = NULL; - } - } - /* get frames */ fl = webkit_dom_document_get_elements_by_tag_name(doc, "frame"); fl_count = webkit_dom_node_list_get_length(fl); @@ -196,7 +108,7 @@ focus_input(struct tab *t) doc = webkit_dom_html_frame_element_get_content_document(frame); if (focus_input_document(t, doc)) { - rv = 1; /* focus */ + rv = 1; goto done; } } @@ -208,15 +120,16 @@ focus_input(struct tab *t) doc = webkit_dom_html_iframe_element_get_content_document(iframe); if (focus_input_document(t, doc)) { - rv = 1; /* found */ + rv = 1; goto done; } } /* if we made it here nothing got focused so use normal heuristic */ - if (focus_input_document(t, webkit_web_view_get_dom_document(t->wv))) - rv = 1; /* found */ - + if (focus_input_document(t, webkit_web_view_get_dom_document(t->wv))) { + rv = 1; + goto done; + } done: if (fl) g_object_unref(fl); @@ -227,7 +140,7 @@ done: } int -dom_is_input(struct tab *t, char **text) +dom_is_input(struct tab *t, WebKitDOMElement **active) { WebKitDOMDocument *doc; WebKitDOMElement *a; @@ -280,11 +193,7 @@ dom_is_input(struct tab *t, char **text) aa = (WebKitDOMHTMLElement*)a; if (WEBKIT_DOM_IS_HTML_ELEMENT(aa) && webkit_dom_html_element_get_is_content_editable(aa)) { - if (t->active == NULL) - t->active = a; - *text = get_element_text((WebKitDOMNode *)a); - if (t->active_text == NULL) - t->active_text = g_strdup(*text); + *active = a; return (1); } break; @@ -293,19 +202,9 @@ dom_is_input(struct tab *t, char **text) if (a == NULL) return (0); - if (node_is_valid_entry((WebKitDOMNode *)a)) { - if (!node_is_valid_entry((WebKitDOMNode *)t->active)) { - t->active = NULL; - if (t->active_text) { - g_free(t->active_text); - t->active_text = NULL; - } - } - if (t->active == NULL) - t->active = a; - *text = get_element_text((WebKitDOMNode *)a); - if (t->active_text == NULL) - t->active_text = g_strdup(*text); + if (WEBKIT_DOM_IS_HTML_INPUT_ELEMENT((WebKitDOMNode *)a) || + WEBKIT_DOM_IS_HTML_TEXT_AREA_ELEMENT((WebKitDOMNode *)a)) { + *active = a; return (1); } @@ -315,41 +214,35 @@ dom_is_input(struct tab *t, char **text) void * input_check_mode(struct tab *t) { - char *text = NULL; + WebKitDOMElement *active = NULL; - if (dom_is_input(t, &text)) { + if (dom_is_input(t, &active)) t->mode = XT_MODE_INSERT; - return (t->active); - } else - return (NULL); + + return (active); +} + +void +input_focus_blur(struct tab *t, void *active) +{ + /* active is (WebKitDOMElement*) */ + if (active) + webkit_dom_element_blur(active); } int command_mode(struct tab *t, struct karg *args) { - WebKitDOMDocument *doc; - WebKitDOMElement *a; + WebKitDOMElement *active = NULL; if (args->i == XT_MODE_COMMAND) { - doc = webkit_web_view_get_dom_document(t->wv); - a = webkit_dom_html_document_get_active_element( - (WebKitDOMHTMLDocument *)doc); - if (a) { - webkit_dom_element_blur(a); - focus_body(doc); - } + if (dom_is_input(t, &active)) + if (active) + webkit_dom_element_blur(active); t->mode = XT_MODE_COMMAND; - } else if (args->i == XT_MODE_INSERT && focus_input(t)) - t->mode = XT_MODE_INSERT; - else if (args->i == XT_MODE_HINT || args->i == XT_MODE_PASSTHROUGH) - t->mode = args->i; - - if (!node_is_valid_entry((WebKitDOMNode *)t->active)) { - t->active = NULL; - if (t->active_text) { - g_free(t->active_text); - t->active_text = NULL; - } + } else { + if (focus_input(t)) + t->mode = XT_MODE_INSERT; } return (XT_CB_HANDLED); @@ -358,8 +251,7 @@ command_mode(struct tab *t, struct karg *args) void input_autofocus(struct tab *t) { - struct karg args = {0}; - char *text = NULL; + WebKitDOMElement *active = NULL; if (autofocus_onload && t->tab_id == gtk_notebook_get_current_page(notebook)) { @@ -368,18 +260,11 @@ input_autofocus(struct tab *t) else t->mode = XT_MODE_COMMAND; } else { - if (dom_is_input(t, &text)) { - if (text != NULL && g_strcmp0(text, t->active_text)) - args.i = XT_MODE_INSERT; - else - args.i = XT_MODE_COMMAND; - } else - args.i = XT_MODE_COMMAND; - command_mode(t, &args); + if (dom_is_input(t, &active)) + if (active) + webkit_dom_element_blur(active); + t->mode = XT_MODE_COMMAND; } - - if (text) - g_free(text); } #else /* WEBKIT_CHECK_VERSION */ /* incomplete DOM API */ @@ -403,6 +288,13 @@ input_autofocus(struct tab *t) } } +void +input_focus_blur(struct tab *t, void *active) +{ + run_script(t, "hints.clearFocus();"); + t->mode = XT_MODE_COMMAND; +} + void * input_check_mode(struct tab *t) { diff --git a/xombrero.c b/xombrero.c index 53ac093..ea60b7f 100644 --- a/xombrero.c +++ b/xombrero.c @@ -475,7 +475,6 @@ hide_cmd(struct tab *t) history_at = NULL; /* just in case */ search_at = NULL; /* just in case */ - gtk_widget_set_can_focus(t->cmd, FALSE); gtk_widget_hide(t->cmd); } @@ -487,7 +486,6 @@ show_cmd(struct tab *t) history_at = NULL; search_at = NULL; gtk_widget_hide(t->oops); - gtk_widget_set_can_focus(t->cmd, TRUE); gtk_widget_show(t->cmd); } @@ -495,7 +493,6 @@ void hide_buffers(struct tab *t) { gtk_widget_hide(t->buffers); - gtk_widget_set_can_focus(t->buffers, FALSE); gtk_list_store_clear(buffers_store); } @@ -569,7 +566,6 @@ show_buffers(struct tab *t) gtk_tree_path_free(path); gtk_widget_show(t->buffers); - gtk_widget_set_can_focus(t->buffers, TRUE); gtk_widget_grab_focus(GTK_WIDGET(t->buffers)); } @@ -2802,7 +2798,7 @@ struct prompt_sub { int command(struct tab *t, struct karg *args) { - struct karg a = {0}; + struct karg a; int i; char *s = NULL, *sp = NULL, *sl = NULL; gchar **sv; @@ -2848,12 +2844,14 @@ command(struct tab *t, struct karg *args) break; case '.': t->mode = XT_MODE_HINT; + bzero(&a, sizeof a); a.i = 0; hint(t, &a); s = "."; break; case ',': t->mode = XT_MODE_HINT; + bzero(&a, sizeof a); a.i = XT_HINT_NEWTAB; hint(t, &a); s = ","; @@ -4209,15 +4207,6 @@ notify_load_status_cb(WebKitWebView* wview, GParamSpec* pspec, struct tab *t) g_free(base); #endif - /* DOM is changing, unreference the previous focused element */ -#if WEBKIT_CHECK_VERSION(1, 5, 0) - t->active = NULL; - if (t->active_text) { - g_free(t->active_text); - t->active_text = NULL; - } -#endif - /* take focus if we are visible */ focus_webview(t); t->focus_wv = 1; @@ -6939,7 +6928,6 @@ create_browser(struct tab *t) } w = gtk_scrolled_window_new(NULL, NULL); - gtk_widget_set_can_focus(w, FALSE); t->adjust_h = gtk_scrolled_window_get_hadjustment( GTK_SCROLLED_WINDOW(w)); t->adjust_v = gtk_scrolled_window_get_vadjustment( @@ -7053,13 +7041,16 @@ create_toolbar(struct tab *t) gtk_widget_set_sensitive(t->forward, FALSE); g_signal_connect(G_OBJECT(t->forward), "clicked", G_CALLBACK(forward_cb), t); - gtk_box_pack_start(GTK_BOX(b), t->forward, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(b), t->forward, FALSE, + FALSE, 0); /* stop button */ t->stop = create_button("Stop", GTK_STOCK_STOP, 0); gtk_widget_set_sensitive(t->stop, FALSE); - g_signal_connect(G_OBJECT(t->stop), "clicked", G_CALLBACK(stop_cb), t); - gtk_box_pack_start(GTK_BOX(b), t->stop, FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(t->stop), "clicked", + G_CALLBACK(stop_cb), t); + gtk_box_pack_start(GTK_BOX(b), t->stop, FALSE, + FALSE, 0); /* JS button */ t->js_toggle = create_button("JS-Toggle", enable_scripts ? @@ -7580,19 +7571,13 @@ create_new_tab(char *title, struct undo *u, int focus, int position) t->vbox = gtk_vbox_new(FALSE, 0); b = gtk_hbox_new(FALSE, 0); #endif - gtk_widget_set_can_focus(t->vbox, FALSE); /* label + button for tab */ t->tab_content = b; - gtk_widget_set_can_focus(t->tab_content, FALSE); t->user_agent_id = 0; t->http_accept_id = 0; -#if WEBKIT_CHECK_VERSION(1, 5, 0) - t->active = NULL; -#endif - #if GTK_CHECK_VERSION(2, 20, 0) t->spinner = gtk_spinner_new(); #endif @@ -7998,7 +7983,6 @@ create_button(char *name, char *stockid, int size) g_free(newstyle); #endif button = gtk_button_new(); - gtk_widget_set_can_focus(button, FALSE); gtk_button_set_focus_on_click(GTK_BUTTON(button), FALSE); gtk_icon_size = icon_size_map(size ? size : icon_size); @@ -8038,7 +8022,6 @@ create_canvas(void) vbox = gtk_vbox_new(FALSE, 0); #endif gtk_box_set_spacing(GTK_BOX(vbox), 0); - gtk_widget_set_can_focus(vbox, FALSE); notebook = GTK_NOTEBOOK(gtk_notebook_new()); #if !GTK_CHECK_VERSION(3, 0, 0) /* XXX seems to be needed with gtk+2 */ @@ -8049,7 +8032,6 @@ create_canvas(void) gtk_widget_set_can_focus(GTK_WIDGET(notebook), FALSE); abtn = gtk_button_new(); - gtk_widget_set_can_focus(abtn, FALSE); arrow = gtk_arrow_new(GTK_ARROW_DOWN, GTK_SHADOW_NONE); gtk_widget_set_name(abtn, "Arrow"); gtk_container_add(GTK_CONTAINER(abtn), arrow); diff --git a/xombrero.conf b/xombrero.conf index f04eddb..fa4d259 100644 --- a/xombrero.conf +++ b/xombrero.conf @@ -302,28 +302,28 @@ # keybinding = command,colon # keybinding = search,slash # keybinding = searchb,question -# keybinding = command_mode,!Escape +# keybinding = command_mode,Escape # keybinding = insert_mode,i -# keybinding = cookiejar,!M1-j -# keybinding = downloadmgr,!M1-d -# keybinding = history,!M1-h -# keybinding = print,!C-p -# keybinding = quitall,!C-q -# keybinding = restart,!M1-q -# keybinding = run_script,!M1-r -# keybinding = js toggle,!C-j -# keybinding = cookie toggle,!M1-c -# keybinding = togglesrc,!C-s +# keybinding = cookiejar,M1-j +# keybinding = downloadmgr,M1-d +# keybinding = history,M1-h +# keybinding = print,C-p +# keybinding = quitall,C-q +# keybinding = restart,M1-q +# keybinding = run_script,M1-r +# keybinding = js toggle,C-j +# keybinding = cookie toggle,M1-c +# keybinding = togglesrc,C-s # keybinding = yankuri,y # keybinding = pasteuricur,p # keybinding = pasteurinew,P -# keybinding = toplevel toggle,!F4 -# keybinding = help,!F1 -# keybinding = proxy toggle,!F2 +# keybinding = toplevel toggle,F4 +# keybinding = help,F1 +# keybinding = proxy toggle,F2 # keybinding = searchnext,n # keybinding = searchprevious,N -# keybinding = focusaddress,!F6 -# keybinding = focussearch,!F7 +# keybinding = focusaddress,F6 +# keybinding = focussearch,F7 # keybinding = hinting,f # keybinding = hinting,period # keybinding = hinting_newtab,S-F @@ -331,12 +331,12 @@ # keybinding = userstyle,s # keybinding = userstyle_global,S # keybinding = goback,BackSpace -# keybinding = goback,!M1-Left -# keybinding = goforward,!S-BackSpace -# keybinding = goforward,!M1-Right -# keybinding = reload,!F5 -# keybinding = reload,!C-r -# keybinding = reload,!C-l +# keybinding = goback,M1-Left +# keybinding = goforward,S-BackSpace +# keybinding = goforward,M1-Right +# keybinding = reload,F5 +# keybinding = reload,C-r +# keybinding = reload,C-l # keybinding = favorites,!M1-f # keybinding = scrolldown,j # keybinding = scrolldown,Down @@ -346,46 +346,46 @@ # keybinding = scrollbottom,End # keybinding = scrolltop,Home # keybinding = scrollpagedown,space -# keybinding = scrollpagedown,!C-f +# keybinding = scrollpagedown,C-f # keybinding = scrollpagedown,Page_Down -# keybinding = scrollhalfdown,!C-d +# keybinding = scrollhalfdown,C-d # keybinding = scrollpageup,Page_Up -# keybinding = scrollpageup,!C-b -# keybinding = scrollhalfup,!C-u +# keybinding = scrollpageup,C-b +# keybinding = scrollhalfup,C-u # keybinding = scrollright,l # keybinding = scrollright,Right # keybinding = scrollfarright,dollar # keybinding = scrollleft,h # keybinding = scrollleft,Left # keybinding = scrollfarleft,0 -# keybinding = statustoggle,!C-n -# keybinding = stop,!S-F5 -# keybinding = tabnew,!C-t +# keybinding = statustoggle,C-n +# keybinding = stop,S-F5 +# keybinding = tabnew,C-t # keybinding = tabclose,!C-w # keybinding = tabundoclose,U -# keybinding = tabnext 1,!C-1 -# keybinding = tabnext 2,!C-2 -# keybinding = tabnext 3,!C-3 -# keybinding = tabnext 4,!C-4 -# keybinding = tabnext 5,!C-5 -# keybinding = tabnext 6,!C-6 -# keybinding = tabnext 7,!C-7 -# keybinding = tabnext 8,!C-8 -# keybinding = tabnext 9,!C-9 -# keybinding = tabfirst,!C-less -# keybinding = tablast,!C-greater -# keybinding = tabprevious,!C-Left -# keybinding = tabnext,!C-Right -# keybinding = focusout,!C-minus -# keybinding = focusin,!C-equal -# keybinding = focusin,!C-plus -# keybinding = focusreset,!C-0 +# keybinding = tabnext 1,C-1 +# keybinding = tabnext 2,C-2 +# keybinding = tabnext 3,C-3 +# keybinding = tabnext 4,C-4 +# keybinding = tabnext 5,C-5 +# keybinding = tabnext 6,C-6 +# keybinding = tabnext 7,C-7 +# keybinding = tabnext 8,C-8 +# keybinding = tabnext 9,C-9 +# keybinding = tabfirst,C-less +# keybinding = tablast,C-greater +# keybinding = tabprevious,C-Left +# keybinding = tabnext,C-Right +# keybinding = focusout,C-minus +# keybinding = focusin,C-equal +# keybinding = focusin,C-plus +# keybinding = focusreset,C-0 # keybinding = editelement,!C-i -# keybinding = passthrough,!C-z -# keybinding = :open ,!F9 -# keybinding = :open <uri>,!F10 -# keybinding = :tabnew ,!F11 -# keybinding = :tabnew <uri>,!F12 +# keybinding = passthrough,C-z +# keybinding = :open ,F9 +# keybinding = :open <uri>,F10 +# keybinding = :tabnew ,F11 +# keybinding = :tabnew <uri>,F12 # parse the contents of another configuration file # include_config = ~/.xombrero_alternate.conf diff --git a/xombrero.h b/xombrero.h index 0e5328a..dda9e69 100644 --- a/xombrero.h +++ b/xombrero.h @@ -283,12 +283,6 @@ struct tab { WebKitWebInspector *inspector; GtkWidget *inspector_window; GtkWidget *inspector_view; - - /* focused text entry */ -#if WEBKIT_CHECK_VERSION(1, 5, 0) - WebKitDOMElement *active; - char *active_text; -#endif }; TAILQ_HEAD(tab_list, tab); @@ -569,6 +563,7 @@ int toggle_pl(struct tab *, struct karg *); /* input autofocus */ void input_autofocus(struct tab *); +void input_focus_blur(struct tab *, void *); void *input_check_mode(struct tab *); int command_mode(struct tab *, struct karg *); |