📄 view.c
字号:
static enum frame_event_statusframe_ev(struct session *ses, struct document_view *doc_view, struct term_event *ev){ struct link *link; enum frame_event_status status; assertm(doc_view && doc_view->document, "document not formatted"); if_assert_failed return FRAME_EVENT_IGNORED; assert(ses && ev); if_assert_failed return FRAME_EVENT_IGNORED; /* When changing frame, vs may be NULL. See bug 525. */ if (!doc_view->vs) return FRAME_EVENT_IGNORED; link = get_current_link(doc_view); status = try_form_action(ses, doc_view, link, ev); if (status != FRAME_EVENT_IGNORED) return status; if (ev->ev == EVENT_KBD) { status = frame_ev_kbd(ses, doc_view, ev);#ifdef CONFIG_MOUSE } else if (ev->ev == EVENT_MOUSE) { status = frame_ev_mouse(ses, doc_view, ev);#endif /* CONFIG_MOUSE */ } else { status = FRAME_EVENT_IGNORED; } /* Is this assertion correct ? It is triggered when * pressing a checkbox or submit in elinks bugzilla. * XXX: I disabled it for now, please check. * --Zas if (ses->insert_mode == INSERT_MODE_ON) { assert(link == get_current_link(doc_view)); } */ return status;}struct document_view *current_frame(struct session *ses){ struct document_view *doc_view = NULL; int current_frame_number; assert(ses); if_assert_failed return NULL; if (!have_location(ses)) return NULL; current_frame_number = cur_loc(ses)->vs.current_link; if (current_frame_number == -1) current_frame_number = 0; foreach (doc_view, ses->scrn_frames) { if (document_has_frames(doc_view->document)) continue; if (!current_frame_number--) return doc_view; } doc_view = ses->doc_view; assert(doc_view && doc_view->document); if_assert_failed return NULL; if (document_has_frames(doc_view->document)) return NULL; return doc_view;}static enum frame_event_statussend_to_frame(struct session *ses, struct document_view *doc_view, struct term_event *ev){ enum frame_event_status status; assert(ses && ses->tab && ses->tab->term && ev); if_assert_failed return FRAME_EVENT_IGNORED; status = frame_ev(ses, doc_view, ev); if (status == FRAME_EVENT_REFRESH) refresh_view(ses, doc_view, 0); else print_screen_status(ses); return status;}#ifdef CONFIG_MOUSEstatic intdo_mouse_event(struct session *ses, struct term_event *ev, struct document_view *doc_view){ struct term_event evv; struct document_view *matched = NULL, *first = doc_view; assert(ses && ev); if_assert_failed return 0; if (!doc_view) return 0; do { assert(doc_view && doc_view->document); if_assert_failed return 0; assertm(doc_view->document->options.box.x == doc_view->box.x && doc_view->document->options.box.y == doc_view->box.y, "Jonas' 1.565 -> 1.566 patch sucks"); if_assert_failed return 0; if (check_mouse_position(ev, &doc_view->box)) { matched = doc_view; break; } next_frame(ses, 1); doc_view = current_frame(ses); } while (doc_view != first); if (!matched) return 0; if (doc_view != first) draw_formatted(ses, 0); copy_struct(&evv, ev); evv.info.mouse.x -= doc_view->box.x; evv.info.mouse.y -= doc_view->box.y; return send_to_frame(ses, doc_view, &evv);}/* Returns the session if event cleanup should be done or NULL if no cleanup is * needed. */static struct session *send_mouse_event(struct session *ses, struct document_view *doc_view, struct term_event *ev){ struct terminal *term = ses->tab->term; struct term_event_mouse *mouse = &ev->info.mouse; if (mouse->y == 0 && check_mouse_action(ev, B_DOWN) && !check_mouse_wheel(ev)) { struct window *m; activate_bfu_technology(ses, -1); m = term->windows.next; m->handler(m, ev); return ses; } /* Handle tabs navigation if tabs bar is displayed. */ if (ses->status.show_tabs_bar && mouse->y == term->height - 1 - !!ses->status.show_status_bar) { int tab_num = get_tab_number_by_xpos(term, mouse->x); struct window *tab = get_current_tab(term); if (check_mouse_action(ev, B_UP)) { if (check_mouse_button(ev, B_MIDDLE) && term->current_tab == tab_num && mouse->y == term->prev_mouse_event.y) { if (tab->data == ses) ses = NULL; close_tab(term, tab->data); } return ses; } if (check_mouse_button(ev, B_WHEEL_UP)) { switch_current_tab(ses, -1); } else if (check_mouse_button(ev, B_WHEEL_DOWN)) { switch_current_tab(ses, 1); } else if (tab_num != -1) { switch_to_tab(term, tab_num, -1); if (check_mouse_button(ev, B_MIDDLE)) { do_not_ignore_next_mouse_event(term); } else if (check_mouse_button(ev, B_RIGHT)) { tab_menu(tab->data, mouse->x, mouse->y, 1); } } return ses; } if (!do_mouse_event(ses, ev, doc_view) && check_mouse_button(ev, B_RIGHT)) { tab_menu(ses, mouse->x, mouse->y, 0); return NULL; }#ifdef CONFIG_LEDS if (ses->status.show_leds && mouse->y == term->height - 1 && mouse->x >= term->width - LEDS_COUNT - 3) { menu_leds_info(term, NULL, NULL); return NULL; }#endif return NULL;}#endif /* CONFIG_MOUSE *//* Returns the session if event cleanup should be done or NULL if no cleanup is * needed. */static struct session *send_kbd_event(struct session *ses, struct document_view *doc_view, struct term_event *ev){ int func_ref; enum main_action action; if (doc_view && send_to_frame(ses, doc_view, ev) != FRAME_EVENT_IGNORED) return NULL; action = kbd_action(KEYMAP_MAIN, ev, &func_ref); if (action == ACT_MAIN_QUIT) { if (check_kbd_key(ev, KBD_CTRL_C))quit: action = ACT_MAIN_REALLY_QUIT; } switch (do_action(ses, action, 0)) { case FRAME_EVENT_SESSION_DESTROYED: return NULL; case FRAME_EVENT_IGNORED: break; case FRAME_EVENT_OK: case FRAME_EVENT_REFRESH: return ses; } if (action == ACT_MAIN_SCRIPTING_FUNCTION) {#ifdef CONFIG_SCRIPTING trigger_event(func_ref, ses);#endif return NULL; } if (check_kbd_key(ev, KBD_CTRL_C)) goto quit; if (get_kbd_modifier(ev) & KBD_ALT) { struct window *win; get_kbd_modifier(ev) &= ~KBD_ALT; activate_bfu_technology(ses, -1); win = ses->tab->term->windows.next; win->handler(win, ev); if (ses->tab->term->windows.next == win) { delete_window(win); get_kbd_modifier(ev) |= KBD_ALT; return NULL; } if (doc_view && get_opt_int("document.browse.accesskey" ".priority") <= 0 && try_document_key(ses, doc_view, ev) == FRAME_EVENT_REFRESH) { /* The document ate the key! */ refresh_view(ses, doc_view, 0); return NULL; } return ses; } if (!(get_kbd_modifier(ev) & KBD_CTRL)) { switch (get_opt_int("document.browse.search.typeahead")) { case 0: return NULL; case 1: action = ACT_MAIN_SEARCH_TYPEAHEAD_LINK; break; case 2: action = ACT_MAIN_SEARCH_TYPEAHEAD_TEXT; break; default: INTERNAL("invalid value for document.browse.search.typeahead"); } /* FIXME: what if !doc_view ? --Zas */ search_typeahead(ses, doc_view, action); /* Cross your fingers -- I'm just asking * for an infinite loop! -- Miciah */ term_send_event(ses->tab->term, ev); } return NULL;}voidsend_event(struct session *ses, struct term_event *ev){ struct document_view *doc_view; assert(ses && ev); if_assert_failed return; doc_view = current_frame(ses); if (ev->ev == EVENT_KBD) { ses = send_kbd_event(ses, doc_view, ev); }#ifdef CONFIG_MOUSE if (ev->ev == EVENT_MOUSE) { ses = send_mouse_event(ses, doc_view, ev); }#endif /* CONFIG_MOUSE */ /* ses may disappear ie. in close_tab() */ if (ses) ses->kbdprefix.repeat_count = 0;}enum frame_event_statusdownload_link(struct session *ses, struct document_view *doc_view, int action){ struct link *link = get_current_link(doc_view); void (*download)(void *ses, unsigned char *file) = start_download; if (!link) return FRAME_EVENT_OK; if (ses->download_uri) { done_uri(ses->download_uri); ses->download_uri = NULL; } switch (action) { case ACT_MAIN_LINK_DOWNLOAD_RESUME: download = resume_download; case ACT_MAIN_LINK_DOWNLOAD: ses->download_uri = get_link_uri(ses, doc_view, link); break; case ACT_MAIN_LINK_DOWNLOAD_IMAGE: if (!link->where_img) break; ses->download_uri = get_uri(link->where_img, 0); break; default: INTERNAL("I think you forgot to take your medication, mental boy!"); return FRAME_EVENT_OK; } if (!ses->download_uri) return FRAME_EVENT_OK; set_session_referrer(ses, doc_view->document->uri); query_file(ses, ses->download_uri, ses, download, NULL, 1); return FRAME_EVENT_OK;}enum frame_event_statusview_image(struct session *ses, struct document_view *doc_view, int xxxx){ struct link *link = get_current_link(doc_view); if (link && link->where_img) goto_url(ses, link->where_img); return FRAME_EVENT_OK;}enum frame_event_statussave_as(struct session *ses, struct document_view *doc_view, int magic){ assert(ses); if_assert_failed return FRAME_EVENT_OK; if (!have_location(ses)) return FRAME_EVENT_OK; if (ses->download_uri) done_uri(ses->download_uri); ses->download_uri = get_uri_reference(cur_loc(ses)->vs.uri); assert(doc_view && doc_view->document && doc_view->document->uri); if_assert_failed return FRAME_EVENT_OK; set_session_referrer(ses, doc_view->document->uri); query_file(ses, ses->download_uri, ses, start_download, NULL, 1); return FRAME_EVENT_OK;}static voidsave_formatted_finish(struct terminal *term, int h, void *data, int resume){ struct document *document = data; assert(term && document); if_assert_failed return; if (h == -1) return; if (dump_to_file(document, h)) { info_box(term, 0, N_("Save error"), ALIGN_CENTER, N_("Error writing to file")); } close(h);}static voidsave_formatted(void *data, unsigned char *file){ struct session *ses = data; struct document_view *doc_view; assert(ses && ses->tab && ses->tab->term && file); if_assert_failed return; doc_view = current_frame(ses); assert(doc_view && doc_view->document); if_assert_failed return; create_download_file(ses->tab->term, file, NULL, 0, 0, save_formatted_finish, doc_view->document);}enum frame_event_statussave_formatted_dlg(struct session *ses, struct document_view *doc_view, int xxxx){ query_file(ses, doc_view->vs->uri, ses, save_formatted, NULL, 1); return FRAME_EVENT_OK;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -