⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 view.c

📁 一个很有名的浏览器
💻 C
📖 第 1 页 / 共 3 页
字号:
	return FRAME_EVENT_REFRESH;}enum frame_event_statusmove_document_end(struct session *ses, struct document_view *doc_view){	int max_height;	assert(ses && doc_view && doc_view->vs && doc_view->document);	if_assert_failed return FRAME_EVENT_OK;	max_height = doc_view->document->height - doc_view->box.height;	doc_view->vs->x = 0;	int_lower_bound(&doc_view->vs->y, int_max(0, max_height));	if (ses->navigate_mode == NAVIGATE_CURSOR_ROUTING) {		/* Move to the last line of the document,		 * but preserve the column. This is done to avoid		 * moving the cursor backwards if it is already		 * on the last line but is not on the first column. */		move_cursor(ses, doc_view, ses->tab->x,			    doc_view->document->height - doc_view->vs->y);	} else {		find_link_page_up(doc_view);	}	return FRAME_EVENT_REFRESH;}enum frame_event_statusset_frame(struct session *ses, struct document_view *doc_view, int xxxx){	assert(ses && ses->doc_view && doc_view && doc_view->vs);	if_assert_failed return FRAME_EVENT_OK;	if (doc_view == ses->doc_view) return FRAME_EVENT_OK;	goto_uri(ses, doc_view->vs->uri);	ses->navigate_mode = NAVIGATE_LINKWISE;	return FRAME_EVENT_OK;}voidtoggle_plain_html(struct session *ses, struct document_view *doc_view, int xxxx){	assert(ses && doc_view && ses->tab && ses->tab->term);	if_assert_failed return;	if (!doc_view->vs) {		nowhere_box(ses->tab->term, NULL);		return;	}	doc_view->vs->plain = !doc_view->vs->plain;	draw_formatted(ses, 1);}voidtoggle_wrap_text(struct session *ses, struct document_view *doc_view, int xxxx){	assert(ses && doc_view && ses->tab && ses->tab->term);	if_assert_failed return;	if (!doc_view->vs) {		nowhere_box(ses->tab->term, NULL);		return;	}	doc_view->vs->wrap = !doc_view->vs->wrap;	draw_formatted(ses, 1);}/* Move the cursor to the document view co-ordinates provided as @x and @y, * scroll the document if necessary, put us in cursor-routing navigation mode if * that is not the current mode, and select any link under the cursor. */enum frame_event_statusmove_cursor(struct session *ses, struct document_view *doc_view, int x, int y){	enum frame_event_status status = FRAME_EVENT_REFRESH;	struct terminal *term = ses->tab->term;	struct box *box = &doc_view->box;	struct link *link;	/* If cursor was moved outside the document view scroll it, but only	 * within the document canvas */	if (!is_in_box(box, x, y)) {		int max_height = doc_view->document->height - doc_view->vs->y;		int max_width = doc_view->document->width - doc_view->vs->x;		if (y < box->y) {			status = vertical_scroll(ses, doc_view, y - box->y);		} else if (y >= box->y + box->height && y <= max_height) {			status = vertical_scroll(ses, doc_view,						 y - (box->y + box->height - 1));		} else if (x < box->x) {			status = horizontal_scroll(ses, doc_view, x - box->x);		} else if (x >= box->x + box->width && x <= max_width) {			status = horizontal_scroll(ses, doc_view,						   x - (box->x + box->width - 1));		}		/* If the view was not scrolled there's nothing more to do */		if (status != FRAME_EVENT_REFRESH)			return status;		/* Restrict the cursor position within the current view */		int_bounds(&x, box->x, box->x + box->width - 1);		int_bounds(&y, box->y, box->y + box->height - 1);	}	/* Scrolling could have changed the navigation mode */	ses->navigate_mode = NAVIGATE_CURSOR_ROUTING;	link = get_link_at_coordinates(doc_view, x - box->x, y - box->y);	if (link) {		doc_view->vs->current_link = link - doc_view->document->links;	} else {		doc_view->vs->current_link = -1;	}	/* Set the unblockable cursor position and update the window pointer so	 * stuff like the link menu will be drawn relative to the cursor. */	set_cursor(term, x, y, 0);	set_window_ptr(ses->tab, x, y);	return status;}enum frame_event_statusmove_cursor_rel(struct session *ses, struct document_view *view,	        int rx, int ry){	int count = ses->kbdprefix.repeat_count;	int x, y;	ses->kbdprefix.repeat_count = 0;	int_lower_bound(&count, 1);	x = ses->tab->x + rx*count;	y = ses->tab->y + ry*count;	return move_cursor(ses, view, x, y);}enum frame_event_statusmove_cursor_left(struct session *ses, struct document_view *view){	return move_cursor_rel(ses, view, -1, 0);}enum frame_event_statusmove_cursor_right(struct session *ses, struct document_view *view){	return move_cursor_rel(ses, view, 1, 0);}enum frame_event_statusmove_cursor_up(struct session *ses, struct document_view *view){	return move_cursor_rel(ses, view, 0, -1);}enum frame_event_statusmove_cursor_down(struct session *ses, struct document_view *view){	return move_cursor_rel(ses, view, 0, 1);}enum frame_event_statuscopy_current_link_to_clipboard(struct session *ses,			       struct document_view *doc_view,			       int xxx){	struct link *link;	struct uri *uri;	unsigned char *uristring;	link = get_current_link(doc_view);	if (!link) return FRAME_EVENT_OK;	uri = get_link_uri(ses, doc_view, link);	if (!uri) return FRAME_EVENT_OK;	uristring = get_uri_string(uri, URI_ORIGINAL);	done_uri(uri);	if (uristring) {		set_clipboard_text(uristring);		mem_free(uristring);	}	return FRAME_EVENT_OK;}inttry_jump_to_link_number(struct session *ses, struct document_view *doc_view){	int link_number = ses->kbdprefix.repeat_count - 1;	if (link_number < 0) return 1;	ses->kbdprefix.repeat_count = 0;	if (!doc_view) return 0;	if (link_number >= doc_view->document->nlinks)		return 0;	jump_to_link_number(ses, doc_view, link_number);	refresh_view(ses, doc_view, 0);	return 1;}#ifdef CONFIG_MARKSenum frame_event_statustry_mark_key(struct session *ses, struct document_view *doc_view,	     struct term_event *ev){	unsigned char mark = get_kbd_key(ev);	switch (ses->kbdprefix.mark) {		case KP_MARK_NOTHING:			return FRAME_EVENT_IGNORED;		case KP_MARK_SET:			/* It is intentional to set the mark			 * to NULL if !doc_view->vs. */			set_mark(mark, doc_view->vs);			break;		case KP_MARK_GOTO:			goto_mark(mark, doc_view->vs);			break;	}	ses->kbdprefix.repeat_count = 0;	ses->kbdprefix.mark = KP_MARK_NOTHING;	return FRAME_EVENT_REFRESH;}#endifstatic enum frame_event_statustry_prefix_key(struct session *ses, struct document_view *doc_view,	       struct term_event *ev){	struct document *document = doc_view->document;	struct document_options *doc_opts = &document->options;	int digit = get_kbd_key(ev) - '0';	if (digit < 0 || digit > 9)		return FRAME_EVENT_IGNORED;	if (get_kbd_modifier(ev)	    || !doc_opts->num_links_key	    || (doc_opts->num_links_key == 1 && !doc_opts->num_links_display)) {		/* Repeat count.		 * ses->kbdprefix.repeat_count is initialized to zero		 * the first time by init_session() calloc() call.		 * When used, it has to be reset to zero. */		ses->kbdprefix.repeat_count *= 10;		ses->kbdprefix.repeat_count += digit;		/* If too big, just restart from zero, so pressing		 * '0' six times or more will reset the count. */		if (ses->kbdprefix.repeat_count > 99999)			ses->kbdprefix.repeat_count = 0;		return FRAME_EVENT_OK;	}	if (digit >= 1 && !get_kbd_modifier(ev)) {		int nlinks = document->nlinks, length;		unsigned char d[2] = { get_kbd_key(ev), 0 };		ses->kbdprefix.repeat_count = 0;		if (!nlinks) return FRAME_EVENT_OK;		for (length = 1; nlinks; nlinks /= 10)			length++;		input_dialog(ses->tab->term, NULL,			     N_("Go to link"), N_("Enter link number"),			     ses, NULL,			     length, d, 1, document->nlinks, check_number,			     (void (*)(void *, unsigned char *)) goto_link_number, NULL);		return FRAME_EVENT_OK;	}	return FRAME_EVENT_IGNORED;}static enum frame_event_statustry_form_action(struct session *ses, struct document_view *doc_view,		struct link *link, struct term_event *ev){	enum frame_event_status status;	if (!link || !link_is_textinput(link))		return FRAME_EVENT_IGNORED;	status = field_op(ses, doc_view, link, ev);	if (status != FRAME_EVENT_IGNORED	    && ses->insert_mode == INSERT_MODE_ON) {		assert(link == get_current_link(doc_view));	}	return status;}static enum frame_event_statusframe_ev_kbd(struct session *ses, struct document_view *doc_view, struct term_event *ev){	enum frame_event_status status = FRAME_EVENT_IGNORED;	int accesskey_priority;#ifdef CONFIG_MARKS	status = try_mark_key(ses, doc_view, ev);	if (status != FRAME_EVENT_IGNORED)		return status;#endif	accesskey_priority = get_opt_int("document.browse.accesskey.priority");	if (accesskey_priority >= 2) {		status = try_document_key(ses, doc_view, ev);		if (status != FRAME_EVENT_IGNORED) {			/* The document ate the key! */			return status;		}	}	status = try_prefix_key(ses, doc_view, ev);	if (status != FRAME_EVENT_IGNORED)		return status;	if (accesskey_priority == 1) {		status = try_document_key(ses, doc_view, ev);		if (status != FRAME_EVENT_IGNORED) {			/* The document ate the key! */			return status;		}	}	return FRAME_EVENT_IGNORED;}#ifdef CONFIG_MOUSEstatic enum frame_event_statusframe_ev_mouse(struct session *ses, struct document_view *doc_view, struct term_event *ev){	int x = ev->info.mouse.x;	int y = ev->info.mouse.y;	struct link *link;	if (check_mouse_wheel(ev)) {		if (!check_mouse_action(ev, B_DOWN)) {			/* We handle only B_DOWN case... */		} else if (check_mouse_button(ev, B_WHEEL_UP)) {			return scroll_mouse_up(ses, doc_view);		} else if (check_mouse_button(ev, B_WHEEL_DOWN)) {			return scroll_mouse_down(ses, doc_view);		}		return FRAME_EVENT_OK;	}	link = get_link_at_coordinates(doc_view, x, y);	if (link) {		enum frame_event_status status = FRAME_EVENT_REFRESH;		doc_view->vs->current_link = link - doc_view->document->links;		if (!link_is_textinput(link)) {			status = FRAME_EVENT_OK;			refresh_view(ses, doc_view, 0);			if (check_mouse_button(ev, B_LEFT)			     || check_mouse_button(ev, B_MIDDLE)) {				if (check_mouse_action(ev, B_DOWN))					do_not_ignore_next_mouse_event(ses->tab->term);				else if (check_mouse_button(ev, B_LEFT))					status = enter(ses, doc_view, 0);				else if (check_mouse_button(ev, B_MIDDLE))					open_current_link_in_new_tab(ses, 1);			} else {				link_menu(ses->tab->term, NULL, ses);			}		}		return status;	}	if (check_mouse_button(ev, B_LEFT)) {		/* Clicking the edge of screen will scroll the document. */		int scrollmargin = get_opt_int("document.browse.scrolling.margin");		/* XXX: This is code duplication with kbd handlers. But		 * repeatcount-free here. */		if (y < scrollmargin) {			return scroll_mouse_up(ses, doc_view);		}		if (y >= doc_view->box.height - scrollmargin) {			return scroll_mouse_down(ses, doc_view);		}		if (x < scrollmargin * 2) {			return scroll_mouse_left(ses, doc_view);		}		if (x >= doc_view->box.width - scrollmargin * 2) {			return scroll_mouse_right(ses, doc_view);		}		return FRAME_EVENT_OK;	}	return FRAME_EVENT_IGNORED;}#endif /* CONFIG_MOUSE */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -