mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-23 12:36:51 +03:00
Merged revisions 8808,8862-8863 via svnmerge from
svn://svn.netsurf-browser.org/branches/paulblokus/textinput ........ r8808 | paulblokus | 2009-07-26 22:52:53 +0100 (Sun, 26 Jul 2009) | 2 lines don't recalculate height already aviable ........ r8862 | paulblokus | 2009-07-28 21:39:06 +0100 (Tue, 28 Jul 2009) | 2 lines added css.c and css.h files which caused svn errors after using svnmerge ........ r8863 | paulblokus | 2009-07-28 21:43:53 +0100 (Tue, 28 Jul 2009) | 3 lines changed textarea redraw logic little fix of KEY_DELETE_LINE_START jandling ........ svn path=/trunk/netsurf/; revision=8886
This commit is contained in:
parent
efc284836b
commit
39546fd504
@ -94,6 +94,9 @@ struct text_area {
|
|||||||
*/
|
*/
|
||||||
} caret_pos;
|
} caret_pos;
|
||||||
|
|
||||||
|
int caret_x; /**< cached X coordinate of the caret */
|
||||||
|
int caret_y; /**< cached Y coordinate of the caret */
|
||||||
|
|
||||||
int selection_start; /**< Character index of sel start(inclusive) */
|
int selection_start; /**< Character index of sel start(inclusive) */
|
||||||
int selection_end; /**< Character index of sel end(exclusive) */
|
int selection_end; /**< Character index of sel end(exclusive) */
|
||||||
|
|
||||||
@ -104,9 +107,8 @@ struct text_area {
|
|||||||
struct line_info *lines; /**< Line info array */
|
struct line_info *lines; /**< Line info array */
|
||||||
int line_height; /**< Line height obtained from style */
|
int line_height; /**< Line height obtained from style */
|
||||||
|
|
||||||
/** Callback functions for a redraw request */
|
/** Callback function for a redraw request */
|
||||||
textarea_start_redraw_callback redraw_start_callback;
|
textarea_redraw_request_callback redraw_request;
|
||||||
textarea_start_redraw_callback redraw_end_callback;
|
|
||||||
|
|
||||||
void *data; /** < Callback data for both callback functions */
|
void *data; /** < Callback data for both callback functions */
|
||||||
|
|
||||||
@ -144,12 +146,11 @@ static void textarea_normalise_text(struct text_area *ta,
|
|||||||
*/
|
*/
|
||||||
struct text_area *textarea_create(int x, int y, int width, int height,
|
struct text_area *textarea_create(int x, int y, int width, int height,
|
||||||
unsigned int flags, const plot_font_style_t *style,
|
unsigned int flags, const plot_font_style_t *style,
|
||||||
textarea_start_redraw_callback redraw_start_callback,
|
textarea_redraw_request_callback redraw_request, void *data)
|
||||||
textarea_end_redraw_callback redraw_end_callback, void *data)
|
|
||||||
{
|
{
|
||||||
struct text_area *ret;
|
struct text_area *ret;
|
||||||
|
|
||||||
if (redraw_start_callback == NULL || redraw_end_callback == NULL) {
|
if (redraw_request == NULL) {
|
||||||
LOG(("no callback provided"));
|
LOG(("no callback provided"));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
@ -160,8 +161,7 @@ struct text_area *textarea_create(int x, int y, int width, int height,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret->redraw_start_callback = redraw_start_callback;
|
ret->redraw_request = redraw_request;
|
||||||
ret->redraw_end_callback = redraw_end_callback;
|
|
||||||
ret->data = data;
|
ret->data = data;
|
||||||
ret->x = x;
|
ret->x = x;
|
||||||
ret->y = y;
|
ret->y = y;
|
||||||
@ -191,6 +191,8 @@ struct text_area *textarea_create(int x, int y, int width, int height,
|
|||||||
(style->size / FONT_SIZE_SCALE)))), 72));
|
(style->size / FONT_SIZE_SCALE)))), 72));
|
||||||
|
|
||||||
ret->caret_pos.line = ret->caret_pos.char_off = 0;
|
ret->caret_pos.line = ret->caret_pos.char_off = 0;
|
||||||
|
ret->caret_x = ret->x + MARGIN_LEFT;
|
||||||
|
ret->caret_y = ret->y;
|
||||||
ret->selection_start = -1;
|
ret->selection_start = -1;
|
||||||
ret->selection_end = -1;
|
ret->selection_end = -1;
|
||||||
|
|
||||||
@ -212,11 +214,8 @@ void textarea_set_position(struct text_area *ta, int x, int y)
|
|||||||
{
|
{
|
||||||
ta->x = x;
|
ta->x = x;
|
||||||
ta->y = y;
|
ta->y = y;
|
||||||
ta->redraw_start_callback(ta->data);
|
ta->redraw_request(ta->data, ta->x, ta->y, ta->x + ta->vis_width,
|
||||||
textarea_redraw(ta, ta->x, ta->y, ta->x + ta->vis_width,
|
|
||||||
ta->y + ta->vis_height);
|
ta->y + ta->vis_height);
|
||||||
textarea_set_caret(ta, textarea_get_caret(ta));
|
|
||||||
ta->redraw_start_callback(ta->data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -430,14 +429,10 @@ bool textarea_set_caret(struct text_area *ta, int caret)
|
|||||||
int index;
|
int index;
|
||||||
int x, y;
|
int x, y;
|
||||||
int x0, y0, x1, y1;
|
int x0, y0, x1, y1;
|
||||||
int height = 0;
|
|
||||||
|
|
||||||
|
|
||||||
if (ta->flags & TEXTAREA_READONLY)
|
if (ta->flags & TEXTAREA_READONLY)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
ta->redraw_start_callback(ta->data);
|
|
||||||
|
|
||||||
c_len = ta->text_utf8_len;
|
c_len = ta->text_utf8_len;
|
||||||
|
|
||||||
if (caret != -1 && (unsigned)caret > c_len)
|
if (caret != -1 && (unsigned)caret > c_len)
|
||||||
@ -472,7 +467,11 @@ bool textarea_set_caret(struct text_area *ta, int caret)
|
|||||||
|
|
||||||
y = ta->line_height * ta->caret_pos.line + ta->y - ta->scroll_y;
|
y = ta->line_height * ta->caret_pos.line + ta->y - ta->scroll_y;
|
||||||
|
|
||||||
textarea_redraw(ta, x - 1, y - 1, x + 1, y + height + 1);
|
/* set the caret coordinate beyond the redraw rectangle */
|
||||||
|
ta->caret_x = x - 2;
|
||||||
|
|
||||||
|
ta->redraw_request(ta->data, x - 1, y - 1, x + 1,
|
||||||
|
y + ta->line_height + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check if the caret has to be drawn at all */
|
/* check if the caret has to be drawn at all */
|
||||||
@ -496,10 +495,6 @@ bool textarea_set_caret(struct text_area *ta, int caret)
|
|||||||
ta->lines[i].b_length, c_len))
|
ta->lines[i].b_length, c_len))
|
||||||
ta->caret_pos.char_off++;
|
ta->caret_pos.char_off++;
|
||||||
|
|
||||||
if (textarea_scroll_visible(ta))
|
|
||||||
textarea_redraw(ta, ta->x, ta->y, ta->x + ta->vis_width,
|
|
||||||
ta->y + ta->vis_height);
|
|
||||||
|
|
||||||
/* Finally, redraw the caret */
|
/* Finally, redraw the caret */
|
||||||
index = textarea_get_caret(ta);
|
index = textarea_get_caret(ta);
|
||||||
if (index == -1)
|
if (index == -1)
|
||||||
@ -518,18 +513,23 @@ bool textarea_set_caret(struct text_area *ta, int caret)
|
|||||||
&x);
|
&x);
|
||||||
|
|
||||||
x += ta->x + MARGIN_LEFT - ta->scroll_x;
|
x += ta->x + MARGIN_LEFT - ta->scroll_x;
|
||||||
|
ta->caret_x = x;
|
||||||
y = ta->line_height * ta->caret_pos.line + ta->y - ta->scroll_y;
|
y = ta->line_height * ta->caret_pos.line + ta->y - ta->scroll_y;
|
||||||
|
ta->caret_y = y;
|
||||||
|
|
||||||
x0 = max(x - 1, ta->x + MARGIN_LEFT);
|
if (textarea_scroll_visible(ta))
|
||||||
y0 = max(y - 1, ta->y);
|
ta->redraw_request(ta->data, ta->x, ta->y,
|
||||||
x1 = min(x + 1, ta->x + ta->vis_width - MARGIN_RIGHT);
|
ta->x + ta->vis_width,
|
||||||
y1 = min(y + height + 1, ta->y + ta->vis_height);
|
ta->y + ta->vis_height);
|
||||||
|
else {
|
||||||
plot.clip(x0, y0, x1, y1);
|
x0 = max(x - 1, ta->x + MARGIN_LEFT);
|
||||||
plot.line(x, y, x, y + height, &pstyle_stroke_caret);
|
y0 = max(y - 1, ta->y);
|
||||||
|
x1 = min(x + 1, ta->x + ta->vis_width - MARGIN_RIGHT);
|
||||||
|
y1 = min(y + ta->line_height + 1,
|
||||||
|
ta->y + ta->vis_height);
|
||||||
|
ta->redraw_request(ta->data, x0, y0, x1, y1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
ta->redraw_end_callback(ta->data);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -732,6 +732,7 @@ bool textarea_reflow(struct text_area *ta, unsigned int line)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle redraw requests for text areas
|
* Handle redraw requests for text areas
|
||||||
*
|
*
|
||||||
@ -741,17 +742,24 @@ bool textarea_reflow(struct text_area *ta, unsigned int line)
|
|||||||
* \param x1 right X coordinate of redraw area
|
* \param x1 right X coordinate of redraw area
|
||||||
* \param y1 bottom Y coordinate of redraw area
|
* \param y1 bottom Y coordinate of redraw area
|
||||||
*/
|
*/
|
||||||
void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1)
|
void textarea_redraw(struct text_area *ta, int clip_x0, int clip_y0,
|
||||||
|
int clip_x1, int clip_y1)
|
||||||
{
|
{
|
||||||
int line0, line1, line;
|
int line0, line1, line;
|
||||||
int chars, offset;
|
int chars, offset;
|
||||||
unsigned int c_pos, c_len, b_start, b_end, line_len;
|
unsigned int c_pos, c_len, b_start, b_end, line_len;
|
||||||
char *line_text;
|
char *line_text;
|
||||||
|
int x0, x1, y0, y1;
|
||||||
plot_style_t plot_style_fill_bg = {
|
plot_style_t plot_style_fill_bg = {
|
||||||
.fill_type = PLOT_OP_TYPE_SOLID,
|
.fill_type = PLOT_OP_TYPE_SOLID,
|
||||||
.fill_colour = BACKGROUND_COL,
|
.fill_colour = BACKGROUND_COL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
x0 = clip_x0;
|
||||||
|
x1 = clip_x1;
|
||||||
|
y0 = clip_y0;
|
||||||
|
y1 = clip_y1;
|
||||||
|
|
||||||
if (x1 < ta->x || x0 > ta->x + ta->vis_width || y1 < ta->y ||
|
if (x1 < ta->x || x0 > ta->x + ta->vis_width || y1 < ta->y ||
|
||||||
y0 > ta->y + ta->vis_height)
|
y0 > ta->y + ta->vis_height)
|
||||||
/* Textarea outside the clipping rectangle */
|
/* Textarea outside the clipping rectangle */
|
||||||
@ -894,6 +902,14 @@ void textarea_redraw(struct text_area *ta, int x0, int y0, int x1, int y1)
|
|||||||
ta->lines[line].b_length,
|
ta->lines[line].b_length,
|
||||||
&ta->fstyle);
|
&ta->fstyle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (ta->caret_x >= clip_x0 && ta->caret_x <= clip_x1) {
|
||||||
|
if (ta->caret_y >= clip_y0 && ta->caret_y <= clip_y1)
|
||||||
|
plot.line(ta->caret_x, ta->caret_y, ta->caret_x,
|
||||||
|
ta->caret_y + ta->line_height,
|
||||||
|
&pstyle_stroke_caret);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1194,7 +1210,7 @@ bool textarea_keypress(struct text_area *ta, uint32_t key)
|
|||||||
return false;
|
return false;
|
||||||
ta->selection_start = ta->selection_end = -1;
|
ta->selection_start = ta->selection_end = -1;
|
||||||
} else {
|
} else {
|
||||||
if (textarea_replace_text(ta,
|
if (!textarea_replace_text(ta,
|
||||||
caret - ta->caret_pos.char_off,
|
caret - ta->caret_pos.char_off,
|
||||||
caret,
|
caret,
|
||||||
""))
|
""))
|
||||||
@ -1207,17 +1223,15 @@ bool textarea_keypress(struct text_area *ta, uint32_t key)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (caret != caret_init)
|
||||||
|
textarea_set_caret(ta, caret);
|
||||||
//TODO:redraw only the important part
|
//TODO:redraw only the important part
|
||||||
if (redraw) {
|
if (redraw) {
|
||||||
ta->redraw_start_callback(ta->data);
|
ta->redraw_request(ta->data, ta->x, ta->y,
|
||||||
textarea_redraw(ta, ta->x, ta->y, ta->x + ta->vis_width,
|
ta->x + ta->vis_width, ta->y + ta->vis_height);
|
||||||
ta->y + ta->vis_height);
|
|
||||||
ta->redraw_end_callback(ta->data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (caret != caret_init || redraw)
|
|
||||||
return textarea_set_caret(ta, caret);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1296,15 +1310,14 @@ bool textarea_mouse_action(struct text_area *ta, browser_mouse_state mouse,
|
|||||||
|
|
||||||
/* mouse button pressed above the text area, move caret */
|
/* mouse button pressed above the text area, move caret */
|
||||||
if (mouse & BROWSER_MOUSE_PRESS_1) {
|
if (mouse & BROWSER_MOUSE_PRESS_1) {
|
||||||
|
if (!(ta->flags & TEXTAREA_READONLY))
|
||||||
|
textarea_set_caret_xy(ta, x, y);
|
||||||
if (ta->selection_start != -1) {
|
if (ta->selection_start != -1) {
|
||||||
ta->selection_start = ta->selection_end = -1;
|
ta->selection_start = ta->selection_end = -1;
|
||||||
ta->redraw_start_callback(ta->data);
|
ta->redraw_request(ta->data, ta->x, ta->y,
|
||||||
textarea_redraw(ta, ta->x, ta->y, ta->x + ta->vis_width,
|
ta->x + ta->vis_width,
|
||||||
ta->y + ta->vis_height);
|
ta->y + ta->vis_height);
|
||||||
ta->redraw_end_callback(ta->data);
|
|
||||||
}
|
}
|
||||||
if (!(ta->flags & TEXTAREA_READONLY))
|
|
||||||
return textarea_set_caret_xy(ta, x, y);
|
|
||||||
}
|
}
|
||||||
else if (mouse & BROWSER_MOUSE_DRAG_1) {
|
else if (mouse & BROWSER_MOUSE_DRAG_1) {
|
||||||
ta->drag_start_char = textarea_get_xy_offset(ta, x, y);
|
ta->drag_start_char = textarea_get_xy_offset(ta, x, y);
|
||||||
@ -1363,11 +1376,6 @@ bool textarea_select(struct text_area *ta, int c_start, int c_end)
|
|||||||
ta->selection_start = c_start;
|
ta->selection_start = c_start;
|
||||||
ta->selection_end = c_end;
|
ta->selection_end = c_end;
|
||||||
|
|
||||||
ta->redraw_start_callback(ta->data);
|
|
||||||
textarea_redraw(ta, ta->x, ta->y, ta->x + ta->vis_width,
|
|
||||||
ta->y + ta->vis_height);
|
|
||||||
ta->redraw_end_callback(ta->data);
|
|
||||||
|
|
||||||
if (!(ta->flags & TEXTAREA_READONLY)) {
|
if (!(ta->flags & TEXTAREA_READONLY)) {
|
||||||
if (swap == -1)
|
if (swap == -1)
|
||||||
return textarea_set_caret(ta, c_end);
|
return textarea_set_caret(ta, c_end);
|
||||||
@ -1375,6 +1383,9 @@ bool textarea_select(struct text_area *ta, int c_start, int c_end)
|
|||||||
return textarea_set_caret(ta, c_start);
|
return textarea_set_caret(ta, c_start);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ta->redraw_request(ta->data, ta->x, ta->y, ta->x + ta->vis_width,
|
||||||
|
ta->y + ta->vis_height);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,13 +35,12 @@
|
|||||||
|
|
||||||
struct text_area;
|
struct text_area;
|
||||||
|
|
||||||
typedef void(*textarea_start_redraw_callback)(void *data);
|
typedef void(*textarea_redraw_request_callback)(void *data, int x, int y,
|
||||||
typedef void(*textarea_end_redraw_callback)(void *data);
|
int width, int height);
|
||||||
|
|
||||||
struct text_area *textarea_create(int x, int y, int width, int height,
|
struct text_area *textarea_create(int x, int y, int width, int height,
|
||||||
unsigned int flags, const plot_font_style_t *style,
|
unsigned int flags, const plot_font_style_t *style,
|
||||||
textarea_start_redraw_callback redraw_start_callback,
|
textarea_redraw_request_callback redraw_request, void *data);
|
||||||
textarea_end_redraw_callback redraw_end_callback, void *data);
|
|
||||||
void textarea_set_position(struct text_area *ta, int x, int y);
|
void textarea_set_position(struct text_area *ta, int x, int y);
|
||||||
void textarea_destroy(struct text_area *ta);
|
void textarea_destroy(struct text_area *ta);
|
||||||
bool textarea_set_text(struct text_area *ta, const char *text);
|
bool textarea_set_text(struct text_area *ta, const char *text);
|
||||||
|
Loading…
Reference in New Issue
Block a user