void html_mouse_action(struct content *c, struct browser_window *bw,
		browser_mouse_state mouse, int x, int y)
{
	html_content *html = (html_content *) c;
	enum { ACTION_NONE, ACTION_SUBMIT, ACTION_GO } action = ACTION_NONE;
	const char *title = 0;
	nsurl *url = 0;
	const char *target = 0;
	char status_buffer[200];
	const char *status = 0;
	browser_pointer_shape pointer = BROWSER_POINTER_DEFAULT;
	bool imagemap = false;
	int box_x = 0, box_y = 0;
	int gadget_box_x = 0, gadget_box_y = 0;
	int html_object_pos_x = 0, html_object_pos_y = 0;
	int text_box_x = 0;
	struct box *url_box = 0;
	struct box *gadget_box = 0;
	struct box *text_box = 0;
	struct box *box;
	struct form_control *gadget = 0;
	hlcache_handle *object = NULL;
	struct box *html_object_box = NULL;
	struct browser_window *iframe = NULL;
	struct box *next_box;
	struct box *drag_candidate = NULL;
	struct scrollbar *scrollbar = NULL;
	plot_font_style_t fstyle;
	int scroll_mouse_x = 0, scroll_mouse_y = 0;
	int padding_left, padding_right, padding_top, padding_bottom;
	browser_drag_type drag_type = browser_window_get_drag_type(bw);
	union content_msg_data msg_data;
	struct dom_node *node = NULL;

	if (drag_type != DRAGGING_NONE && !mouse &&
			html->visible_select_menu != NULL) {
		/* drag end: select menu */
		form_select_mouse_drag_end(html->visible_select_menu,
				mouse, x, y);
	}

	if (html->visible_select_menu != NULL) {
		box = html->visible_select_menu->box;
		box_coords(box, &box_x, &box_y);

		box_x -= box->border[LEFT].width;
		box_y += box->height + box->border[BOTTOM].width +
				box->padding[BOTTOM] + box->padding[TOP];
		status = form_select_mouse_action(html->visible_select_menu,
				mouse, x - box_x, y - box_y);
		if (status != NULL) {
			msg_data.explicit_status_text = status;
			content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
		} else {
			int width, height;
			form_select_get_dimensions(html->visible_select_menu,
					&width, &height);
			html->visible_select_menu = NULL;
			browser_window_redraw_rect(bw, box_x, box_y,
					width, height);					
		}
		return;
	}

	if (!mouse && html->scrollbar != NULL) {
		/* drag end: scrollbar */
		html_overflow_scroll_drag_end(html->scrollbar, mouse, x, y);
	}

	if (html->scrollbar != NULL) {
		struct html_scrollbar_data *data =
				scrollbar_get_data(html->scrollbar);
		box = data->box;
		box_coords(box, &box_x, &box_y);
		if (scrollbar_is_horizontal(html->scrollbar)) {
			scroll_mouse_x = x - box_x ;
			scroll_mouse_y = y - (box_y + box->padding[TOP] +
					box->height + box->padding[BOTTOM] -
					SCROLLBAR_WIDTH);
			status = scrollbar_mouse_action(html->scrollbar, mouse,
					scroll_mouse_x, scroll_mouse_y);
		} else {
			scroll_mouse_x = x - (box_x + box->padding[LEFT] +
					box->width + box->padding[RIGHT] -
					SCROLLBAR_WIDTH);
			scroll_mouse_y = y - box_y;
			status = scrollbar_mouse_action(html->scrollbar, mouse, 
					scroll_mouse_x, scroll_mouse_y);
		}

		msg_data.explicit_status_text = status;
		content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
		return;
	}

	/* Content related drags handled by now */
	browser_window_set_drag_type(bw, DRAGGING_NONE, NULL);

	/* search the box tree for a link, imagemap, form control, or
	 * box with scrollbars 
	 */

	box = html->layout;

	/* Consider the margins of the html page now */
	box_x = box->margin[LEFT];
	box_y = box->margin[TOP];

	/* descend through visible boxes setting more specific values for:
	 * box - deepest box at point 
	 * html_object_box - html object
	 * html_object_pos_x - html object
	 * html_object_pos_y - html object
	 * object - non html object
	 * iframe - iframe
	 * url - href or imagemap
	 * target - href or imagemap or gadget
	 * url_box - href or imagemap
	 * imagemap - imagemap
	 * gadget - gadget
	 * gadget_box - gadget
	 * gadget_box_x - gadget
	 * gadget_box_y - gadget
	 * title - title
	 * pointer
	 *
	 * drag_candidate - first box with scroll
	 * padding_left - box with scroll
	 * padding_right
	 * padding_top
	 * padding_bottom
	 * scrollbar - inside padding box stops decent
	 * scroll_mouse_x - inside padding box stops decent
	 * scroll_mouse_y - inside padding box stops decent
	 * 
	 * text_box - text box
	 * text_box_x - text_box
	 */
	while ((next_box = box_at_point(box, x, y, &box_x, &box_y)) != NULL) {
		box = next_box;

		if ((box->style != NULL) && 
		    (css_computed_visibility(box->style) == 
		     CSS_VISIBILITY_HIDDEN)) {
			continue;
		}

		if (box->node != NULL) {
			node = box->node;
		}

		if (box->object) {
			if (content_get_type(box->object) == CONTENT_HTML) {
				html_object_box = box;
				html_object_pos_x = box_x;
				html_object_pos_y = box_y;
			} else {
				object = box->object;
			}
		}

		if (box->iframe) {
			iframe = box->iframe;
		}

		if (box->href) {
			url = box->href;
			target = box->target;
			url_box = box;
		}

		if (box->usemap) {
			url = imagemap_get(html, box->usemap,
					box_x, box_y, x, y, &target);
			if (url) {
				imagemap = true;
				url_box = box;
			}
		}

		if (box->gadget) {
			gadget = box->gadget;
			gadget_box = box;
			gadget_box_x = box_x;
			gadget_box_y = box_y;
			if (gadget->form)
				target = gadget->form->target;
		}

		if (box->title) {
			title = box->title;
		}

		pointer = get_pointer_shape(box, false);
		
		if ((box->scroll_x != NULL) || 
		    (box->scroll_y != NULL)) {

			if (drag_candidate == NULL) {
				drag_candidate = box;
			}

			padding_left = box_x +
					scrollbar_get_offset(box->scroll_x);
			padding_right = padding_left + box->padding[LEFT] +
					box->width + box->padding[RIGHT];
			padding_top = box_y +
					scrollbar_get_offset(box->scroll_y);
			padding_bottom = padding_top + box->padding[TOP] +
					box->height + box->padding[BOTTOM];
			
			if ((x > padding_left) && 
			    (x < padding_right) &&
			    (y > padding_top) && 
			    (y < padding_bottom)) {
				/* mouse inside padding box */
				
				if ((box->scroll_y != NULL) && 
				    (x > (padding_right - SCROLLBAR_WIDTH))) {
					/* mouse above vertical box scroll */
					
					scrollbar = box->scroll_y;
					scroll_mouse_x = x - (padding_right -
							     SCROLLBAR_WIDTH);
					scroll_mouse_y = y - padding_top;
					break;
				
				} else if ((box->scroll_x != NULL) &&
					   (y > (padding_bottom - SCROLLBAR_WIDTH))) {
					/* mouse above horizontal box scroll */
							
					scrollbar = box->scroll_x;
					scroll_mouse_x = x - padding_left;
					scroll_mouse_y = y - (padding_bottom -
							SCROLLBAR_WIDTH);
					break;
				}
			}
		}

		if (box->text && !box->object) {
			text_box = box;
			text_box_x = box_x;
		}
	}

	/* use of box_x, box_y, or content below this point is probably a
	 * mistake; they will refer to the last box returned by box_at_point */

	if (scrollbar) {
		status = scrollbar_mouse_action(scrollbar, mouse,
				scroll_mouse_x, scroll_mouse_y);
		pointer = BROWSER_POINTER_DEFAULT;
	} else if (gadget) {
		switch (gadget->type) {
		case GADGET_SELECT:
			status = messages_get("FormSelect");
			pointer = BROWSER_POINTER_MENU;
			if (mouse & BROWSER_MOUSE_CLICK_1 &&
			    nsoption_bool(core_select_menu)) {
				html->visible_select_menu = gadget;
				form_open_select_menu(c, gadget,
						form_select_menu_callback,
						c);
				pointer =  BROWSER_POINTER_DEFAULT;
			} else if (mouse & BROWSER_MOUSE_CLICK_1)
				gui_create_form_select_menu(bw, gadget);
			break;
		case GADGET_CHECKBOX:
			status = messages_get("FormCheckbox");
			if (mouse & BROWSER_MOUSE_CLICK_1) {
				gadget->selected = !gadget->selected;
				html__redraw_a_box(html, gadget_box);
			}
			break;
		case GADGET_RADIO:
			status = messages_get("FormRadio");
			if (mouse & BROWSER_MOUSE_CLICK_1)
				form_radio_set(html, gadget);
			break;
		case GADGET_IMAGE:
			if (mouse & BROWSER_MOUSE_CLICK_1) {
				gadget->data.image.mx = x - gadget_box_x;
				gadget->data.image.my = y - gadget_box_y;
			}
			/* drop through */
		case GADGET_SUBMIT:
			if (gadget->form) {
				snprintf(status_buffer, sizeof status_buffer,
						messages_get("FormSubmit"),
						gadget->form->action);
				status = status_buffer;
				pointer = get_pointer_shape(gadget_box, false);
				if (mouse & (BROWSER_MOUSE_CLICK_1 |
						BROWSER_MOUSE_CLICK_2))
					action = ACTION_SUBMIT;
			} else {
				status = messages_get("FormBadSubmit");
			}
			break;
		case GADGET_TEXTAREA:
			status = messages_get("FormTextarea");
			pointer = get_pointer_shape(gadget_box, false);

			if (mouse & (BROWSER_MOUSE_PRESS_1 |
					BROWSER_MOUSE_PRESS_2)) {
				if (text_box && selection_root(&html->sel) !=
						gadget_box)
					selection_init(&html->sel, gadget_box);

				textinput_textarea_click(c, mouse,
						gadget_box,
						gadget_box_x,
						gadget_box_y,
						x - gadget_box_x,
						y - gadget_box_y);
			}

			if (text_box) {
				int pixel_offset;
				size_t idx;

				font_plot_style_from_css(text_box->style, 
						&fstyle);

				nsfont.font_position_in_string(&fstyle,
					text_box->text,
					text_box->length,
					x - gadget_box_x - text_box->x,
					&idx,
					&pixel_offset);

				selection_click(&html->sel, mouse,
						text_box->byte_offset + idx);

				if (selection_dragging(&html->sel)) {
					browser_window_set_drag_type(bw,
							DRAGGING_SELECTION,
							NULL);
					status = messages_get("Selecting");
				}
			}
			else if (mouse & BROWSER_MOUSE_PRESS_1)
				selection_clear(&html->sel, true);
			break;
		case GADGET_TEXTBOX:
		case GADGET_PASSWORD:
			status = messages_get("FormTextbox");
			pointer = get_pointer_shape(gadget_box, false);

			if ((mouse & BROWSER_MOUSE_PRESS_1) &&
					!(mouse & (BROWSER_MOUSE_MOD_1 |
					BROWSER_MOUSE_MOD_2))) {
				textinput_input_click(c,
						gadget_box,
						gadget_box_x,
						gadget_box_y,
						x - gadget_box_x,
						y - gadget_box_y);
			}
			if (text_box) {
				int pixel_offset;
				size_t idx;

				if (mouse & (BROWSER_MOUSE_DRAG_1 |
						BROWSER_MOUSE_DRAG_2))
					selection_init(&html->sel, gadget_box);

				font_plot_style_from_css(text_box->style,
						&fstyle);

				nsfont.font_position_in_string(&fstyle,
					text_box->text,
					text_box->length,
					x - gadget_box_x - text_box->x,
					&idx,
					&pixel_offset);

				selection_click(&html->sel, mouse,
						text_box->byte_offset + idx);

				if (selection_dragging(&html->sel))
					browser_window_set_drag_type(bw,
							DRAGGING_SELECTION,
							NULL);
			}
			else if (mouse & BROWSER_MOUSE_PRESS_1)
				selection_clear(&html->sel, true);
			break;
		case GADGET_HIDDEN:
			/* not possible: no box generated */
			break;
		case GADGET_RESET:
			status = messages_get("FormReset");
			break;
		case GADGET_FILE:
			status = messages_get("FormFile");
			break;
		case GADGET_BUTTON:
			/* This gadget cannot be activated */
			status = messages_get("FormButton");
			break;
		}

	} else if (object && (mouse & BROWSER_MOUSE_MOD_2)) {

		if (mouse & BROWSER_MOUSE_DRAG_2) {
			msg_data.dragsave.type = CONTENT_SAVE_NATIVE;
			msg_data.dragsave.content = object;
			content_broadcast(c, CONTENT_MSG_DRAGSAVE, msg_data);

		} else if (mouse & BROWSER_MOUSE_DRAG_1) {
			msg_data.dragsave.type = CONTENT_SAVE_ORIG;
			msg_data.dragsave.content = object;
			content_broadcast(c, CONTENT_MSG_DRAGSAVE, msg_data);
		}

		/* \todo should have a drag-saving object msg */

	} else if (iframe) {
		int pos_x, pos_y;
		float scale = browser_window_get_scale(bw);

		browser_window_get_position(iframe, false, &pos_x, &pos_y);

		pos_x /= scale;
		pos_y /= scale;

		if (mouse & BROWSER_MOUSE_CLICK_1 ||
				mouse & BROWSER_MOUSE_CLICK_2) {
			browser_window_mouse_click(iframe, mouse,
					x - pos_x, y - pos_y);
		} else {
			browser_window_mouse_track(iframe, mouse,
					x - pos_x, y - pos_y);
		}
	} else if (html_object_box) {
		if (mouse & BROWSER_MOUSE_CLICK_1 ||
				mouse & BROWSER_MOUSE_CLICK_2) {
			content_mouse_action(html_object_box->object,
					bw, mouse,
					x - html_object_pos_x,
					y - html_object_pos_y);
		} else {
			content_mouse_track(html_object_box->object,
					bw, mouse,
					x - html_object_pos_x,
					y - html_object_pos_y);
		}
	} else if (url) {
		if (title) {
			snprintf(status_buffer, sizeof status_buffer, "%s: %s",
					nsurl_access(url), title);
			status = status_buffer;
		} else
			status = nsurl_access(url);

		pointer = get_pointer_shape(url_box, imagemap);

		if (mouse & BROWSER_MOUSE_CLICK_1 &&
				mouse & BROWSER_MOUSE_MOD_1) {
			/* force download of link */
			browser_window_go_post(bw, nsurl_access(url), 0, 0,
					false,
					nsurl_access(content_get_url(c)),
					true, true, 0);

		} else if (mouse & BROWSER_MOUSE_CLICK_2 &&
				mouse & BROWSER_MOUSE_MOD_1) {
			msg_data.savelink.url = nsurl_access(url);
			msg_data.savelink.title = title;
			content_broadcast(c, CONTENT_MSG_SAVELINK, msg_data);

		} else if (mouse & (BROWSER_MOUSE_CLICK_1 |
				BROWSER_MOUSE_CLICK_2))
			action = ACTION_GO;
	} else {
		bool done = false;

		/* frame resizing */
		if (browser_window_frame_resize_start(bw, mouse, x, y,
				&pointer)) {
			if (mouse & (BROWSER_MOUSE_DRAG_1 |
					BROWSER_MOUSE_DRAG_2)) {
				status = messages_get("FrameDrag");
			}
			done = true;
		}

		/* if clicking in the main page, remove the selection from any
		 * text areas */
		if (!done) {
			struct box *layout = html->layout;

			if (mouse && (mouse < BROWSER_MOUSE_MOD_1) &&
					selection_root(&html->sel) != layout) {
				selection_init(&html->sel, layout);
			}

			if (text_box) {
				int pixel_offset;
				size_t idx;

				font_plot_style_from_css(text_box->style,
						&fstyle);

				nsfont.font_position_in_string(&fstyle,
					text_box->text,
					text_box->length,
					x - text_box_x,
					&idx,
					&pixel_offset);

				if (selection_click(&html->sel, mouse,
						text_box->byte_offset + idx)) {
					/* key presses must be directed at the
					 * main browser window, paste text
					 * operations ignored */

					if (selection_dragging(&html->sel)) {
						browser_window_set_drag_type(bw,
							DRAGGING_SELECTION,
							NULL);
						status = messages_get(
								"Selecting");
					}

					done = true;
				}

			} else if (mouse & BROWSER_MOUSE_PRESS_1)
				selection_clear(&html->sel, true);
		}

		if (!done) {
			if (title)
				status = title;

			if (mouse & BROWSER_MOUSE_DRAG_1) {
				if (mouse & BROWSER_MOUSE_MOD_2) {
					msg_data.dragsave.type =
							CONTENT_SAVE_COMPLETE;
					msg_data.dragsave.content = NULL;
					content_broadcast(c,
							CONTENT_MSG_DRAGSAVE,
							msg_data);
				} else {
					if (drag_candidate == NULL) {
						browser_window_page_drag_start(
								bw, x, y);
					} else {
						html_box_drag_start(
								drag_candidate,
								x, y);
					}
					pointer = BROWSER_POINTER_MOVE;
				}
			}
			else if (mouse & BROWSER_MOUSE_DRAG_2) {
				if (mouse & BROWSER_MOUSE_MOD_2) {
					msg_data.dragsave.type =
							CONTENT_SAVE_SOURCE;
					msg_data.dragsave.content = NULL;
					content_broadcast(c,
							CONTENT_MSG_DRAGSAVE,
							msg_data);
				} else {
					if (drag_candidate == NULL) {
						browser_window_page_drag_start(
								bw, x, y);
					} else {
						html_box_drag_start(
								drag_candidate,
								x, y);
					}
					pointer = BROWSER_POINTER_MOVE;
				}
			}
		}
		if (mouse && mouse < BROWSER_MOUSE_MOD_1) {
			/* ensure key presses still act on the browser window */
			browser_window_remove_caret(bw);
		}
	}

	if (!iframe && !html_object_box) {
		msg_data.explicit_status_text = status;
		content_broadcast(c, CONTENT_MSG_STATUS, msg_data);

		msg_data.pointer = pointer;
		content_broadcast(c, CONTENT_MSG_POINTER, msg_data);
	}

	/* fire dom click event */
	if ((mouse & BROWSER_MOUSE_CLICK_1) ||
	    (mouse & BROWSER_MOUSE_CLICK_2)) {
		js_fire_event(html->jscontext, "click", html->document, node);
	}

	/* deferred actions that can cause this browser_window to be destroyed
	 * and must therefore be done after set_status/pointer
	 */
	switch (action) {
	case ACTION_SUBMIT:
		form_submit(content_get_url(c),
				browser_window_find_target(bw, target, mouse),
				gadget->form, gadget);
		break;
	case ACTION_GO:
		browser_window_go(browser_window_find_target(bw, target, mouse),
				nsurl_access(url),
				nsurl_access(content_get_url(c)), true);
		break;
	case ACTION_NONE:
		break;
	}
}
Esempio n. 2
0
/*
 * Exported function.  Documented in scrollbar.h
 */
const char *scrollbar_mouse_action(struct scrollbar *s,
		browser_mouse_state mouse, int x, int y)
{
	int x0, y0, x1, y1;
	int val;
	const char *status;
	bool h;

	/* we want mouse presses and mouse drags that were not started at the
	 * scrollbar indication bar to be launching actions on the scroll area
	 */
	bool but1 = ((mouse & BROWSER_MOUSE_PRESS_1) ||
			((mouse & BROWSER_MOUSE_HOLDING_1) &&
			(mouse & BROWSER_MOUSE_DRAG_ON) &&
			!s->dragging));
	bool but2 = ((mouse & BROWSER_MOUSE_PRESS_2) ||
			((mouse & BROWSER_MOUSE_HOLDING_2) &&
			(mouse & BROWSER_MOUSE_DRAG_ON) &&
			!s->dragging));

	h = s->horizontal;

	x0 = 0;
	y0 = 0;
	x1 = h ? s->length : SCROLLBAR_WIDTH;
	y1 = h ? SCROLLBAR_WIDTH : s->length;

	if (!s->dragging && !(x >= x0 && x <= x1 && y >= y0 && y <= y1)) {
		/* Not a drag and mouse outside scrollbar widget */
		return NULL;
	}


	if (h)
		val = x;
	else
		val = y;

	if (s->dragging) {
		val -= s->drag_start_coord;
		if (s->drag_content)
			val = -val;
		if (val != 0)
			scrollbar_set(s, s->drag_start_pos + val,
					!(s->drag_content));
		if (s->pair_drag) {
			scrollbar_mouse_action(s->pair, mouse, x, y);
			status = messages_get("ScrollBoth");
		} else
			status = messages_get(h ? "ScrollH" : "ScrollV");

		return status;
	}

	if (val < SCROLLBAR_WIDTH) {
		/* left/up arrow */
		
		status = messages_get(h ? "ScrollLeft" : "ScrollUp");
		if (but1)
			scrollbar_set(s, s->offset - SCROLLBAR_WIDTH, false);
		else if (but2)
			scrollbar_set(s, s->offset + SCROLLBAR_WIDTH, false);

	} else if (val < SCROLLBAR_WIDTH + s->bar_pos) {
		/* well between left/up arrow and bar */

		status = messages_get(h ? "ScrollPLeft" : "ScrollPUp");

		if (but1)
			scrollbar_set(s, s->offset - s->length, false);
		else if (but2)
			scrollbar_set(s, s->offset + s->length, false);

	} else if (val > s->length - SCROLLBAR_WIDTH) {
		/* right/down arrow */

		status = messages_get(h ? "ScrollRight" : "ScrollDown");

		if (but1)
			scrollbar_set(s, s->offset + SCROLLBAR_WIDTH, false);
		else if (but2)
			scrollbar_set(s, s->offset - SCROLLBAR_WIDTH, false);

	} else if (val > SCROLLBAR_WIDTH + s->bar_pos +
			s->bar_len) {
		/* well between right/down arrow and bar */

		status = messages_get(h ? "ScrollPRight" : "ScrollPDown");
		if (but1)
			scrollbar_set(s, s->offset + s->length, false);
		else if (but2)
			scrollbar_set(s, s->offset - s->length, false);
	}
	else {
		/* scrollbar position indication bar */
		
		status = messages_get(h ? "ScrollH" : "ScrollV");
	}

	
	if (mouse & (BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_2) &&
		   	(val >= SCROLLBAR_WIDTH + s->bar_pos
		   	&& val < SCROLLBAR_WIDTH + s->bar_pos +
		   			s->bar_len))
		/* The mouse event is a drag start on the scrollbar position
		 * indication bar. */
		scrollbar_drag_start_internal(s, x, y, false,
				(mouse & BROWSER_MOUSE_DRAG_2) ? true : false);

	return status;
}
Esempio n. 3
0
void html_mouse_action(struct content *c, struct browser_window *bw,
                       browser_mouse_state mouse, int x, int y)
{
    html_content *html = (html_content *) c;
    enum { ACTION_NONE, ACTION_SUBMIT, ACTION_GO } action = ACTION_NONE;
    const char *title = 0;
    nsurl *url = 0;
    const char *target = 0;
    char status_buffer[200];
    const char *status = 0;
    browser_pointer_shape pointer = BROWSER_POINTER_DEFAULT;
    bool imagemap = false;
    int box_x = 0, box_y = 0;
    int gadget_box_x = 0, gadget_box_y = 0;
    int html_object_pos_x = 0, html_object_pos_y = 0;
    int text_box_x = 0;
    struct box *url_box = 0;
    struct box *gadget_box = 0;
    struct box *text_box = 0;
    struct box *box;
    struct form_control *gadget = 0;
    hlcache_handle *object = NULL;
    struct box *html_object_box = NULL;
    struct browser_window *iframe = NULL;
    struct box *next_box;
    struct box *drag_candidate = NULL;
    struct scrollbar *scrollbar = NULL;
    plot_font_style_t fstyle;
    int scroll_mouse_x = 0, scroll_mouse_y = 0;
    int padding_left, padding_right, padding_top, padding_bottom;
    browser_drag_type drag_type = browser_window_get_drag_type(bw);
    union content_msg_data msg_data;
    struct dom_node *node = NULL;
    union html_drag_owner drag_owner;
    union html_selection_owner sel_owner;
    bool click = mouse & (BROWSER_MOUSE_PRESS_1 | BROWSER_MOUSE_PRESS_2 |
                          BROWSER_MOUSE_CLICK_1 | BROWSER_MOUSE_CLICK_2 |
                          BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_2);

    if (drag_type != DRAGGING_NONE && !mouse &&
            html->visible_select_menu != NULL) {
        /* drag end: select menu */
        form_select_mouse_drag_end(html->visible_select_menu,
                                   mouse, x, y);
    }

    if (html->visible_select_menu != NULL) {
        box = html->visible_select_menu->box;
        box_coords(box, &box_x, &box_y);

        box_x -= box->border[LEFT].width;
        box_y += box->height + box->border[BOTTOM].width +
                 box->padding[BOTTOM] + box->padding[TOP];
        status = form_select_mouse_action(html->visible_select_menu,
                                          mouse, x - box_x, y - box_y);
        if (status != NULL) {
            msg_data.explicit_status_text = status;
            content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
        } else {
            int width, height;
            form_select_get_dimensions(html->visible_select_menu,
                                       &width, &height);
            html->visible_select_menu = NULL;
            browser_window_redraw_rect(bw, box_x, box_y,
                                       width, height);
        }
        return;
    }

    if (html->drag_type == HTML_DRAG_SELECTION) {
        /* Selection drag */
        struct box *box;
        int dir = -1;
        int dx, dy;

        if (!mouse) {
            /* End of selection drag */
            int dir = -1;
            size_t idx;

            if (selection_dragging_start(&html->sel))
                dir = 1;

            idx = html_selection_drag_end(html, mouse, x, y, dir);

            if (idx != 0)
                selection_track(&html->sel, mouse, idx);

            drag_owner.no_owner = true;
            html_set_drag_type(html, HTML_DRAG_NONE,
                               drag_owner, NULL);
            return;
        }

        if (selection_dragging_start(&html->sel))
            dir = 1;

        box = box_pick_text_box(html, x, y, dir, &dx, &dy);

        if (box != NULL) {
            int pixel_offset;
            size_t idx;
            plot_font_style_t fstyle;

            font_plot_style_from_css(box->style, &fstyle);

            nsfont.font_position_in_string(&fstyle,
                                           box->text, box->length,
                                           dx, &idx, &pixel_offset);

            selection_track(&html->sel, mouse,
                            box->byte_offset + idx);
        }
        return;
    }

    if (html->drag_type == HTML_DRAG_SCROLLBAR) {
        struct scrollbar *scr = html->drag_owner.scrollbar;
        struct html_scrollbar_data *data = scrollbar_get_data(scr);

        if (!mouse) {
            /* drag end: scrollbar */
            html_overflow_scroll_drag_end(scr, mouse, x, y);
        }

        box = data->box;
        box_coords(box, &box_x, &box_y);
        if (scrollbar_is_horizontal(scr)) {
            scroll_mouse_x = x - box_x ;
            scroll_mouse_y = y - (box_y + box->padding[TOP] +
                                  box->height + box->padding[BOTTOM] -
                                  SCROLLBAR_WIDTH);
            status = scrollbar_mouse_status_to_message(
                         scrollbar_mouse_action(scr, mouse,
                                                scroll_mouse_x,
                                                scroll_mouse_y));
        } else {
            scroll_mouse_x = x - (box_x + box->padding[LEFT] +
                                  box->width + box->padding[RIGHT] -
                                  SCROLLBAR_WIDTH);
            scroll_mouse_y = y - box_y;
            status = scrollbar_mouse_status_to_message(
                         scrollbar_mouse_action(scr, mouse,
                                                scroll_mouse_x,
                                                scroll_mouse_y));
        }

        msg_data.explicit_status_text = status;
        content_broadcast(c, CONTENT_MSG_STATUS, msg_data);
        return;
    }

    if (html->drag_type == HTML_DRAG_TEXTAREA_SELECTION ||
            html->drag_type == HTML_DRAG_TEXTAREA_SCROLLBAR) {
        box = html->drag_owner.textarea;
        assert(box->gadget != NULL);
        assert(box->gadget->type == GADGET_TEXTAREA ||
               box->gadget->type == GADGET_PASSWORD ||
               box->gadget->type == GADGET_TEXTBOX);

        box_coords(box, &box_x, &box_y);
        textarea_mouse_action(box->gadget->data.text.ta, mouse,
                              x - box_x, y - box_y);

        /* TODO: Set appropriate statusbar message */
        return;
    }

    if (html->drag_type == HTML_DRAG_CONTENT_SELECTION ||
            html->drag_type == HTML_DRAG_CONTENT_SCROLL) {
        box = html->drag_owner.content;
        assert(box->object != NULL);

        box_coords(box, &box_x, &box_y);
        content_mouse_track(box->object, bw, mouse,
                            x - box_x, y - box_y);
        return;
    }

    if (html->drag_type == HTML_DRAG_CONTENT_SELECTION) {
        box = html->drag_owner.content;
        assert(box->object != NULL);

        box_coords(box, &box_x, &box_y);
        content_mouse_track(box->object, bw, mouse,
                            x - box_x, y - box_y);
        return;
    }

    /* Content related drags handled by now */
    assert(html->drag_type == HTML_DRAG_NONE);

    /* search the box tree for a link, imagemap, form control, or
     * box with scrollbars
     */

    box = html->layout;

    /* Consider the margins of the html page now */
    box_x = box->margin[LEFT];
    box_y = box->margin[TOP];

    /* descend through visible boxes setting more specific values for:
     * box - deepest box at point
     * html_object_box - html object
     * html_object_pos_x - html object
     * html_object_pos_y - html object
     * object - non html object
     * iframe - iframe
     * url - href or imagemap
     * target - href or imagemap or gadget
     * url_box - href or imagemap
     * imagemap - imagemap
     * gadget - gadget
     * gadget_box - gadget
     * gadget_box_x - gadget
     * gadget_box_y - gadget
     * title - title
     * pointer
     *
     * drag_candidate - first box with scroll
     * padding_left - box with scroll
     * padding_right
     * padding_top
     * padding_bottom
     * scrollbar - inside padding box stops decent
     * scroll_mouse_x - inside padding box stops decent
     * scroll_mouse_y - inside padding box stops decent
     *
     * text_box - text box
     * text_box_x - text_box
     */
    while ((next_box = box_at_point(box, x, y, &box_x, &box_y)) != NULL) {
        box = next_box;

        if ((box->style != NULL) &&
                (css_computed_visibility(box->style) ==
                 CSS_VISIBILITY_HIDDEN)) {
            continue;
        }

        if (box->node != NULL) {
            node = box->node;
        }

        if (box->object) {
            if (content_get_type(box->object) == CONTENT_HTML) {
                html_object_box = box;
                html_object_pos_x = box_x;
                html_object_pos_y = box_y;
            } else {
                object = box->object;
            }
        }

        if (box->iframe) {
            iframe = box->iframe;
        }

        if (box->href) {
            url = box->href;
            target = box->target;
            url_box = box;
        }

        if (box->usemap) {
            url = imagemap_get(html, box->usemap,
                               box_x, box_y, x, y, &target);
            if (url) {
                imagemap = true;
                url_box = box;
            }
        }

        if (box->gadget) {
            gadget = box->gadget;
            gadget_box = box;
            gadget_box_x = box_x;
            gadget_box_y = box_y;
            if (gadget->form)
                target = gadget->form->target;
        }

        if (box->title) {
            title = box->title;
        }

        pointer = get_pointer_shape(box, false);

        if ((box->scroll_x != NULL) ||
                (box->scroll_y != NULL)) {

            if (drag_candidate == NULL) {
                drag_candidate = box;
            }

            padding_left = box_x +
                           scrollbar_get_offset(box->scroll_x);
            padding_right = padding_left + box->padding[LEFT] +
                            box->width + box->padding[RIGHT];
            padding_top = box_y +
                          scrollbar_get_offset(box->scroll_y);
            padding_bottom = padding_top + box->padding[TOP] +
                             box->height + box->padding[BOTTOM];

            if ((x > padding_left) &&
                    (x < padding_right) &&
                    (y > padding_top) &&
                    (y < padding_bottom)) {
                /* mouse inside padding box */

                if ((box->scroll_y != NULL) &&
                        (x > (padding_right -
                              SCROLLBAR_WIDTH))) {
                    /* mouse above vertical box scroll */

                    scrollbar = box->scroll_y;
                    scroll_mouse_x = x - (padding_right -
                                          SCROLLBAR_WIDTH);
                    scroll_mouse_y = y - padding_top;
                    break;

                } else if ((box->scroll_x != NULL) &&
                           (y > (padding_bottom -
                                 SCROLLBAR_WIDTH))) {
                    /* mouse above horizontal box scroll */

                    scrollbar = box->scroll_x;
                    scroll_mouse_x = x - padding_left;
                    scroll_mouse_y = y - (padding_bottom -
                                          SCROLLBAR_WIDTH);
                    break;
                }
            }
        }

        if (box->text && !box->object) {
            text_box = box;
            text_box_x = box_x;
        }
    }

    /* use of box_x, box_y, or content below this point is probably a
     * mistake; they will refer to the last box returned by box_at_point */

    if (scrollbar) {
        status = scrollbar_mouse_status_to_message(
                     scrollbar_mouse_action(scrollbar, mouse,
                                            scroll_mouse_x,
                                            scroll_mouse_y));
        pointer = BROWSER_POINTER_DEFAULT;
    } else if (gadget) {
        textarea_mouse_status ta_status;

        switch (gadget->type) {
        case GADGET_SELECT:
            status = messages_get("FormSelect");
            pointer = BROWSER_POINTER_MENU;
            if (mouse & BROWSER_MOUSE_CLICK_1 &&
                    nsoption_bool(core_select_menu)) {
                html->visible_select_menu = gadget;
                form_open_select_menu(c, gadget,
                                      form_select_menu_callback,
                                      c);
                pointer = BROWSER_POINTER_DEFAULT;
            } else if (mouse & BROWSER_MOUSE_CLICK_1)
                gui_create_form_select_menu(bw, gadget);
            break;
        case GADGET_CHECKBOX:
            status = messages_get("FormCheckbox");
            if (mouse & BROWSER_MOUSE_CLICK_1) {
                gadget->selected = !gadget->selected;
                html__redraw_a_box(html, gadget_box);
            }
            break;
        case GADGET_RADIO:
            status = messages_get("FormRadio");
            if (mouse & BROWSER_MOUSE_CLICK_1)
                form_radio_set(html, gadget);
            break;
        case GADGET_IMAGE:
            if (mouse & BROWSER_MOUSE_CLICK_1) {
                gadget->data.image.mx = x - gadget_box_x;
                gadget->data.image.my = y - gadget_box_y;
            }
        /* drop through */
        case GADGET_SUBMIT:
            if (gadget->form) {
                snprintf(status_buffer, sizeof status_buffer,
                         messages_get("FormSubmit"),
                         gadget->form->action);
                status = status_buffer;
                pointer = get_pointer_shape(gadget_box, false);
                if (mouse & (BROWSER_MOUSE_CLICK_1 |
                             BROWSER_MOUSE_CLICK_2))
                    action = ACTION_SUBMIT;
            } else {
                status = messages_get("FormBadSubmit");
            }
            break;
        case GADGET_TEXTBOX:
        case GADGET_PASSWORD:
        case GADGET_TEXTAREA:
            if (gadget->type == GADGET_TEXTAREA)
                status = messages_get("FormTextarea");
            else
                status = messages_get("FormTextbox");

            if (click && (html->selection_type !=
                          HTML_SELECTION_TEXTAREA ||
                          html->selection_owner.textarea !=
                          gadget_box)) {
                sel_owner.none = true;
                html_set_selection(html, HTML_SELECTION_NONE,
                                   sel_owner, true);
            }

            ta_status = textarea_mouse_action(gadget->data.text.ta,
                                              mouse, x - gadget_box_x,
                                              y - gadget_box_y);

            if (ta_status & TEXTAREA_MOUSE_EDITOR) {
                pointer = get_pointer_shape(gadget_box, false);
            } else {
                pointer = BROWSER_POINTER_DEFAULT;
                status = scrollbar_mouse_status_to_message(
                             ta_status >> 3);
            }
            break;
        case GADGET_HIDDEN:
            /* not possible: no box generated */
            break;
        case GADGET_RESET:
            status = messages_get("FormReset");
            break;
        case GADGET_FILE:
            status = messages_get("FormFile");
            break;
        case GADGET_BUTTON:
            /* This gadget cannot be activated */
            status = messages_get("FormButton");
            break;
        }

    } else if (object && (mouse & BROWSER_MOUSE_MOD_2)) {