HTML contents manage box scrollbars, rather than browser_windows.

svn path=/trunk/netsurf/; revision=12519
This commit is contained in:
Michael Drake 2011-06-27 22:21:15 +00:00
parent 6f215b1f02
commit c9fe1b604e
10 changed files with 57 additions and 50 deletions

View File

@ -633,8 +633,6 @@ nserror browser_window_callback(hlcache_handle *c,
browser_window_remove_caret(bw);
bw->scrollbar = NULL;
if (bw->window)
gui_window_new_content(bw->window);
@ -708,7 +706,6 @@ nserror browser_window_callback(hlcache_handle *c,
else if (c == bw->current_content) {
bw->current_content = NULL;
browser_window_remove_caret(bw);
bw->scrollbar = NULL;
selection_init(bw->sel, NULL);
}
@ -1803,6 +1800,7 @@ void browser_window_mouse_drag_end(struct browser_window *bw,
}
selection_drag_end(bw->sel);
}
bw->drag_type = DRAGGING_NONE;
break;
case DRAGGING_OTHER:
@ -1810,19 +1808,14 @@ void browser_window_mouse_drag_end(struct browser_window *bw,
if (bw->visible_select_menu != NULL) {
form_select_mouse_drag_end(bw->visible_select_menu,
mouse, x, y);
}
if (bw->scrollbar != NULL) {
html_overflow_scroll_drag_end(bw->scrollbar,
mouse, x, y);
bw->drag_type = DRAGGING_NONE;
}
break;
default:
bw->drag_type = DRAGGING_NONE;
break;
}
bw->drag_type = DRAGGING_NONE;
}

View File

@ -114,10 +114,6 @@ struct browser_window {
unsigned int drag_resize_up : 1;
unsigned int drag_resize_down : 1;
/** Scroll capturing all mouse events, updated to any active HTML
* scrollbar, or NULL when no scrollbar drags active */
struct scrollbar *scrollbar;
/** Current fetch is download */
bool download;
@ -198,11 +194,6 @@ struct browser_window {
int status_miss; /**< Number of times status was really updated. */
};
struct browser_scrollbar_data {
struct browser_window *bw;
struct box *box;
};
extern struct browser_window *current_redraw_browser;
extern bool browser_reformat_pending;

View File

@ -37,6 +37,7 @@
#include "render/box.h"
#include "render/font.h"
#include "render/form.h"
#include "render/html_internal.h"
#include "render/layout.h"
#include "utils/log.h"
#include "utils/talloc.h"
@ -2168,7 +2169,7 @@ void textarea_reflow(struct browser_window *bw, struct box *textarea,
textarea->width = width;
textarea->height = height;
layout_calculate_descendant_bboxes(textarea);
box_handle_scrollbars(bw, textarea,
box_handle_scrollbars(c, textarea,
box_hscrollbar_present(textarea),
box_vscrollbar_present(textarea));
}
@ -2263,6 +2264,8 @@ bool word_right(const char *text, size_t len, size_t *poffset, size_t *pchars)
bool ensure_caret_visible(struct browser_window *bw, struct box *textarea)
{
html_content *html = (html_content *)
hlcache_handle_get_content(bw->current_content);
int cx, cy;
int scrollx, scrolly;
@ -2302,14 +2305,14 @@ bool ensure_caret_visible(struct browser_window *bw, struct box *textarea)
return false;
if (textarea->scroll_x != NULL) {
bw->scrollbar = textarea->scroll_x;
html->scrollbar = textarea->scroll_x;
scrollbar_set(textarea->scroll_x, scrollx, false);
bw->scrollbar = NULL;
html->scrollbar = NULL;
}
if (textarea->scroll_y != NULL) {
bw->scrollbar = textarea->scroll_x;
html->scrollbar = textarea->scroll_x;
scrollbar_set(textarea->scroll_y, scrolly, false);
bw->scrollbar = NULL;
html->scrollbar = NULL;
}
return true;

View File

@ -999,16 +999,16 @@ void box_dump(FILE *stream, struct box *box, unsigned int depth)
* Applies the given scroll setup to a box. This includes scroll
* creation/deletion as well as scroll dimension updates.
*
* \param bw browser window in which the box is located
* \param c content in which the box is located
* \param box the box to handle the scrolls for
* \param bottom whether the horizontal scrollbar should be present
* \param right whether the vertical scrollbar should be present
* \return true on success false otherwise
*/
bool box_handle_scrollbars(struct browser_window *bw, struct box *box,
bool box_handle_scrollbars(struct content *c, struct box *box,
bool bottom, bool right)
{
struct browser_scrollbar_data *data;
struct html_scrollbar_data *data;
int visible_width, visible_height;
int full_width, full_height;
@ -1043,13 +1043,13 @@ bool box_handle_scrollbars(struct browser_window *bw, struct box *box,
if (right) {
if (box->scroll_y == NULL) {
data = malloc(sizeof(struct browser_scrollbar_data));
data = malloc(sizeof(struct html_scrollbar_data));
if (data == NULL) {
LOG(("malloc failed"));
warn_user("NoMemory", 0);
return false;
}
data->bw = bw;
data->c = c;
data->box = box;
if (!scrollbar_create(false, visible_height,
full_height, visible_height,
@ -1063,13 +1063,13 @@ bool box_handle_scrollbars(struct browser_window *bw, struct box *box,
}
if (bottom) {
if (box->scroll_x == NULL) {
data = malloc(sizeof(struct browser_scrollbar_data));
data = malloc(sizeof(struct html_scrollbar_data));
if (data == NULL) {
LOG(("malloc failed"));
warn_user("NoMemory", 0);
return false;
}
data->bw = bw;
data->c = c;
data->box = box;
if (!scrollbar_create(true,
visible_width -

View File

@ -331,7 +331,7 @@ bool box_visible(struct box *box);
void box_dump(FILE *stream, struct box *box, unsigned int depth);
bool box_extract_link(const char *rel, const char *base, char **result);
bool box_handle_scrollbars(struct browser_window *bw, struct box *box,
bool box_handle_scrollbars(struct content *c, struct box *box,
bool bottom, bool right);
bool box_vscrollbar_present(const struct box *box);
bool box_hscrollbar_present(const struct box *box);

View File

@ -242,6 +242,7 @@ nserror html_create_html_data(html_content *c, const http_parameter *params)
c->page = NULL;
c->box = NULL;
c->font_func = &nsfont;
c->scrollbar = NULL;
nerror = http_parameter_list_find_item(params, "charset", &charset);
if (nerror == NSERROR_OK) {

View File

@ -85,6 +85,11 @@ struct content_html_object {
bool background; /**< This object is a background image. */
};
struct html_scrollbar_data {
struct content *c;
struct box *box;
};
/** Frame tree (<frameset>, <frame>) */
struct content_html_frames {
int cols; /** number of columns in frameset */

View File

@ -142,6 +142,7 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
plot_font_style_t fstyle;
int scroll_mouse_x = 0, scroll_mouse_y = 0;
int padding_left, padding_right, padding_top, padding_bottom;
html_content *html = (html_content *) c;
if (bw->visible_select_menu != NULL) {
@ -166,24 +167,30 @@ void html_mouse_action(struct content *c, struct browser_window *bw,
return;
}
if (bw->scrollbar != NULL) {
struct browser_scrollbar_data *data =
scrollbar_get_data(bw->scrollbar);
if (bw->drag_type != DRAGGING_NONE && !mouse &&
html->scrollbar != NULL) {
/* Scrollbar drag end */
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(bw->scrollbar)) {
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(bw->scrollbar, mouse,
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(bw->scrollbar, mouse,
status = scrollbar_mouse_action(html->scrollbar, mouse,
scroll_mouse_x, scroll_mouse_y);
}
@ -750,13 +757,13 @@ gui_pointer_shape get_pointer_shape(struct browser_window *bw, struct box *box,
/**
* Callback for in-page scrolls.
* Callback for in-page scrollbars.
*/
void html_overflow_scroll_callback(void *client_data,
struct scrollbar_msg_data *scrollbar_data)
{
struct browser_scrollbar_data *data = client_data;
struct browser_window *bw = data->bw;
struct html_scrollbar_data *data = client_data;
html_content *html = (html_content *)data->c;
struct box *box = data->box;
int x, y, box_x, box_y, diff_x, diff_y;
@ -779,27 +786,28 @@ void html_overflow_scroll_callback(void *client_data,
diff_x;
y = box_y + scrollbar_get_offset(box->scroll_y);
}
browser_window_redraw_rect(bw,
content__request_redraw((struct content *)html,
x + scrollbar_data->x0,
y + scrollbar_data->y0,
scrollbar_data->x1 - scrollbar_data->x0,
scrollbar_data->y1 - scrollbar_data->y0);
break;
case SCROLLBAR_MSG_MOVED:
html_redraw_a_box(bw->current_content, box);
html_redraw_a_box(html->bw->current_content, box);
break;
case SCROLLBAR_MSG_SCROLL_START:
browser_window_set_drag_type(bw, DRAGGING_OTHER);
browser_window_set_drag_type(html->bw, DRAGGING_OTHER);
bw->scrollbar = scrollbar_data->scrollbar;
gui_window_box_scroll_start(bw->window,
html->scrollbar = scrollbar_data->scrollbar;
gui_window_box_scroll_start(html->bw->window,
scrollbar_data->x0, scrollbar_data->y0,
scrollbar_data->x1, scrollbar_data->y1);
break;
case SCROLLBAR_MSG_SCROLL_FINISHED:
bw->scrollbar = NULL;
html->scrollbar = NULL;
browser_window_set_pointer(bw, GUI_POINTER_DEFAULT);
browser_window_set_pointer(html->bw,
GUI_POINTER_DEFAULT);
break;
}
}
@ -817,7 +825,7 @@ void html_overflow_scroll_drag_end(struct scrollbar *scrollbar,
browser_mouse_state mouse, int x, int y)
{
int scroll_mouse_x, scroll_mouse_y, box_x, box_y;
struct browser_scrollbar_data *data = scrollbar_get_data(scrollbar);
struct html_scrollbar_data *data = scrollbar_get_data(scrollbar);
struct box *box;
box = data->box;

View File

@ -84,6 +84,10 @@ typedef struct html_content {
struct html_content *page;
/** Box containing this, or NULL if not an object. */
struct box *box;
/** Scrollbar capturing all mouse events, updated to any active HTML
* scrollbar, or NULL when no scrollbar drags active */
struct scrollbar *scrollbar;
} html_content;

View File

@ -723,7 +723,9 @@ bool html_redraw_box(struct box *box, int x_parent, int y_parent,
has_x_scroll = box_hscrollbar_present(box);
has_y_scroll = box_vscrollbar_present(box);
if (!box_handle_scrollbars(current_redraw_browser, box,
/* TODO: pass content down, so we don't need
* current_redraw_browser here */
if (!box_handle_scrollbars(hlcache_handle_get_content(current_redraw_browser->current_content), box,
has_x_scroll, has_y_scroll))
return false;