1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-11-04 08:17:17 -05:00

Add a "Form fields" entry to the link menu (if it is a form field)

The menu shows a list of all fields of a form, with the possibility to jump
right to that form field when selecting an entry. The menu text is the
basic form field label "Radio button", "Text field", etc. with the form
field name or alt text as the right menu text.

It introduces a new main action called link-form-menu with no default
binding.

Requested by Klaus Knopper, as a mean to improve accessibility for complex,
overloaded pages like ebay.com.
This commit is contained in:
Jonas Fonseca 2005-12-26 01:27:44 +01:00 committed by Jonas Fonseca
parent 452f31d773
commit 26b82953ce
5 changed files with 101 additions and 0 deletions

View File

@ -46,6 +46,7 @@ ACTION_(MAIN, "link-external-command", LINK_EXTERNAL_COMMAND, N__("Pass URI of c
ACTION_(MAIN, "link-follow", LINK_FOLLOW, N__("Follow the current link"), ACTION_REQUIRE_VIEW_STATE | ACTION_REQUIRE_LOCATION | ACTION_JUMP_TO_LINK | ACTION_REQUIRE_LINK),
ACTION_(MAIN, "link-follow-reload", LINK_FOLLOW_RELOAD, N__("Follow the current link, forcing reload of the target"), ACTION_REQUIRE_VIEW_STATE | ACTION_REQUIRE_LOCATION | ACTION_JUMP_TO_LINK | ACTION_REQUIRE_LINK),
ACTION_(MAIN, "link-menu", LINK_MENU, N__("Open the link context menu"), ACTION_REQUIRE_VIEW_STATE | ACTION_JUMP_TO_LINK | ACTION_REQUIRE_LINK),
ACTION_(MAIN, "link-form-menu", LINK_FORM_MENU, N__("Open the form fields menu"), ACTION_REQUIRE_VIEW_STATE | ACTION_JUMP_TO_LINK | ACTION_REQUIRE_LINK),
ACTION_(MAIN, "lua-console", LUA_CONSOLE, N__("Open a Lua console"), ACTION_RESTRICT_ANONYMOUS),
ACTION_(MAIN, "mark-goto", MARK_GOTO, N__("Go at a specified mark"), ACTION_REQUIRE_VIEW_STATE),
ACTION_(MAIN, "mark-set", MARK_SET, N__("Set a mark"), ACTION_REQUIRE_VIEW_STATE),

View File

@ -284,6 +284,10 @@ do_action(struct session *ses, enum main_action action_id, int verbose)
link_menu(term, NULL, ses);
break;
case ACT_MAIN_LINK_FORM_MENU:
link_form_menu(term, NULL, ses);
break;
case ACT_MAIN_LUA_CONSOLE:
#ifdef CONFIG_LUA
trigger_event_name("dialog-lua-console", ses);

View File

@ -1616,3 +1616,94 @@ get_form_info(struct session *ses, struct document_view *doc_view)
return str.source;
}
static void
link_form_menu_func(struct terminal *term, void *link_number_, void *ses_)
{
struct session *ses = ses_;
struct document_view *doc_view;
int link_number = (int) link_number_;
assert(term && ses);
if_assert_failed return;
doc_view = current_frame(ses);
if (!doc_view) return;
assert(doc_view->vs && doc_view->document);
if_assert_failed return;
jump_to_link_number(ses, doc_view, link_number);
}
void
link_form_menu(struct terminal *term, void *xxx, void *ses_)
{
struct session *ses = ses_;
struct document_view *doc_view;
struct link *link;
struct menu_item *mi;
struct form_control *fc;
struct form *form;
assert(term && ses);
if_assert_failed return;
doc_view = current_frame(ses);
if (!doc_view) return;
assert(doc_view->vs && doc_view->document);
if_assert_failed return;
link = get_current_link(doc_view);
if (!link) return;
assert(link_is_form(link));
fc = get_link_form_control(link);
if (!fc) return;
form = fc->form;
mi = new_menu(FREE_LIST | FREE_TEXT | NO_INTL);
if (!mi) return;
foreach (fc, form->items) {
unsigned char *text;
unsigned char *rtext;
int link_number;
struct string str;
switch (fc->type) {
case FC_HIDDEN:
continue;
case FC_SUBMIT:
case FC_IMAGE:
if (!form->action)
text = N_("Useless button");
else
text = N_("Submit button");
break;
default:
text = get_form_label(fc);
}
link_number = get_form_control_link(doc_view->document, fc);
if (link_number < 0
|| !init_string(&str))
continue;
assert(text);
add_to_string(&str, _(text, term));
rtext = fc->name;
if (!rtext) rtext = fc->alt;
add_to_menu(&mi, str.source, rtext, ACT_MAIN_NONE,
link_form_menu_func, (void *) link_number, 0);
}
do_menu(term, mi, ses, 1);
}

View File

@ -92,4 +92,6 @@ void submit_given_form(struct session *ses, struct document_view *doc_view, stru
void auto_submit_form(struct session *ses);
void do_reset_form(struct document_view *doc_view, struct form *form);
void link_form_menu(struct terminal *term, void *xxx, void *ses_);
#endif

View File

@ -1234,6 +1234,9 @@ link_menu(struct terminal *term, void *xxx, void *ses_)
add_menu_action(&mi, N_("~Reset form"), ACT_MAIN_RESET_FORM);
}
add_to_menu(&mi, N_("Form f~ields"), NULL, ACT_MAIN_LINK_FORM_MENU,
NULL, NULL, SUBMENU);
}
if (link->where_img) {