netsurf: branch master updated. 845dca45def00350df5866d27ff22eb492f355d9
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/845dca45def00350df586...
...commit http://git.netsurf-browser.org/netsurf.git/commit/845dca45def00350df5866d...
...tree http://git.netsurf-browser.org/netsurf.git/tree/845dca45def00350df5866d27...
The branch, master has been updated
via 845dca45def00350df5866d27ff22eb492f355d9 (commit)
from 9e3db46b67f45b57a683fe1ff3350f89a6387354 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/845dca45def00350df5...
commit 845dca45def00350df5866d27ff22eb492f355d9
Author: Vincent Sanders <vince(a)netsurf-browser.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
resume parse on sync script error as well as success
diff --git a/render/html_script.c b/render/html_script.c
index b27abf7..44b661d 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -336,6 +336,12 @@ convert_script_sync_cb(hlcache_handle *script,
s->already_started = true;
+ /* continue parse */
+ err = dom_hubbub_parser_pause(parent->parser, false);
+ if (err != DOM_HUBBUB_OK) {
+ LOG(("unpause returned 0x%x", err));
+ }
+
break;
case CONTENT_MSG_STATUS:
-----------------------------------------------------------------------
Summary of changes:
render/html_script.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)
diff --git a/render/html_script.c b/render/html_script.c
index b27abf7..44b661d 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -336,6 +336,12 @@ convert_script_sync_cb(hlcache_handle *script,
s->already_started = true;
+ /* continue parse */
+ err = dom_hubbub_parser_pause(parent->parser, false);
+ if (err != DOM_HUBBUB_OK) {
+ LOG(("unpause returned 0x%x", err));
+ }
+
break;
case CONTENT_MSG_STATUS:
--
NetSurf Browser
11 years, 1 month
netsurf: branch master updated. 9e3db46b67f45b57a683fe1ff3350f89a6387354
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/9e3db46b67f45b57a683f...
...commit http://git.netsurf-browser.org/netsurf.git/commit/9e3db46b67f45b57a683fe1...
...tree http://git.netsurf-browser.org/netsurf.git/tree/9e3db46b67f45b57a683fe1ff...
The branch, master has been updated
via 9e3db46b67f45b57a683fe1ff3350f89a6387354 (commit)
via 21ce8800b8b25ae2b5efefa2136c02387d390e8c (commit)
via de7361ca888881598a987972d8c76e58253423da (commit)
via 75cc4a06be412fa89fedfec13f524296aa106462 (commit)
from 4fd5d51765e9ec42626c961277062731942328a6 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/9e3db46b67f45b57a68...
commit 9e3db46b67f45b57a683fe1ff3350f89a6387354
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Handle CTRL modifier too. CTRL with cursor left/right is same as SHIFT. CTRL+U clears writable.
diff --git a/framebuffer/fbtk/text.c b/framebuffer/fbtk/text.c
index e2f0fa3..15c3f7a 100644
--- a/framebuffer/fbtk/text.c
+++ b/framebuffer/fbtk/text.c
@@ -306,6 +306,14 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
modifier &= ~(1<<1);
break;
+ case NSFB_KEY_RCTRL:
+ modifier &= ~(1<<2);
+ break;
+
+ case NSFB_KEY_LCTRL:
+ modifier &= ~(1<<3);
+ break;
+
default:
break;
}
@@ -371,7 +379,28 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
modifier |= 1<<1;
break;
+ case NSFB_KEY_RCTRL:
+ modifier |= 1<<2;
+ break;
+
+ case NSFB_KEY_LCTRL:
+ modifier |= 1<<3;
+ break;
+
default:
+ if (modifier & 1<<2 || modifier & 1<<3) {
+ /* CTRL pressed, don't enter any text */
+ if (value == NSFB_KEY_u) {
+ /* CTRL+U: clear writable */
+ widget->u.text.idx = 0;
+ widget->u.text.len = 0;
+ widget->u.text.text[widget->u.text.len] = '\0';
+ widget->u.text.width = 0;
+ caret_moved = true;
+ }
+ break;
+ }
+
/* allow for new character and null */
temp = realloc(widget->u.text.text, widget->u.text.len + 2);
if (temp == NULL) {
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/21ce8800b8b25ae2b5e...
commit 21ce8800b8b25ae2b5efefa2136c02387d390e8c
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Cursor left/right keys plus modifier move caret to extrems.
diff --git a/framebuffer/fbtk/text.c b/framebuffer/fbtk/text.c
index d71b162..e2f0fa3 100644
--- a/framebuffer/fbtk/text.c
+++ b/framebuffer/fbtk/text.c
@@ -334,16 +334,25 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
break;
case NSFB_KEY_RIGHT:
- if (widget->u.text.idx < widget->u.text.len)
- widget->u.text.idx++;
- caret_moved = true;
+ if (widget->u.text.idx < widget->u.text.len) {
+ if (modifier == 0)
+ widget->u.text.idx++;
+ else
+ widget->u.text.idx = widget->u.text.len;
+
+ caret_moved = true;
+ }
break;
case NSFB_KEY_LEFT:
- if (widget->u.text.idx > 0)
- widget->u.text.idx--;
+ if (widget->u.text.idx > 0) {
+ if (modifier == 0)
+ widget->u.text.idx--;
+ else
+ widget->u.text.idx = 0;
- caret_moved = true;
+ caret_moved = true;
+ }
break;
case NSFB_KEY_PAGEUP:
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/de7361ca888881598a9...
commit de7361ca888881598a987972d8c76e58253423da
Merge: 75cc4a0 4fd5d51
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Merge branch 'master' of git://git.netsurf-browser.org/netsurf
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/75cc4a06be412fa89fe...
commit 75cc4a06be412fa89fedfec13f524296aa106462
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Factor out some repeated code.
diff --git a/framebuffer/fbtk/text.c b/framebuffer/fbtk/text.c
index 879d888..d71b162 100644
--- a/framebuffer/fbtk/text.c
+++ b/framebuffer/fbtk/text.c
@@ -282,6 +282,7 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
plot_font_style_t font_style;
int fh;
int border;
+ bool caret_moved = false;
fb_text_font_style(widget, &fh, &border, &font_style);
@@ -324,13 +325,8 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
nsfont.font_width(&font_style, widget->u.text.text,
widget->u.text.len, &widget->u.text.width);
- nsfont.font_width(&font_style, widget->u.text.text,
- widget->u.text.idx, &widget->u.text.idx_offset);
- fbtk_set_caret(widget, true,
- widget->u.text.idx_offset + border,
- border,
- widget->height - border - border,
- fb_text_input_remove_caret_cb);
+
+ caret_moved = true;
break;
case NSFB_KEY_RETURN:
@@ -340,27 +336,14 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
case NSFB_KEY_RIGHT:
if (widget->u.text.idx < widget->u.text.len)
widget->u.text.idx++;
-
- nsfont.font_width(&font_style, widget->u.text.text,
- widget->u.text.idx, &widget->u.text.idx_offset);
- fbtk_set_caret(widget, true,
- widget->u.text.idx_offset + border,
- border,
- widget->height - border - border,
- fb_text_input_remove_caret_cb);
+ caret_moved = true;
break;
case NSFB_KEY_LEFT:
if (widget->u.text.idx > 0)
widget->u.text.idx--;
- nsfont.font_width(&font_style, widget->u.text.text,
- widget->u.text.idx, &widget->u.text.idx_offset);
- fbtk_set_caret(widget, true,
- widget->u.text.idx_offset + border,
- border,
- widget->height - border - border,
- fb_text_input_remove_caret_cb);
+ caret_moved = true;
break;
case NSFB_KEY_PAGEUP:
@@ -398,6 +381,11 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
nsfont.font_width(&font_style, widget->u.text.text,
widget->u.text.len, &widget->u.text.width);
+ caret_moved = true;
+ break;
+ }
+
+ if (caret_moved) {
nsfont.font_width(&font_style, widget->u.text.text,
widget->u.text.idx, &widget->u.text.idx_offset);
fbtk_set_caret(widget, true,
@@ -405,7 +393,6 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
border,
widget->height - border - border,
fb_text_input_remove_caret_cb);
- break;
}
fbtk_request_redraw(widget);
-----------------------------------------------------------------------
Summary of changes:
framebuffer/fbtk/text.c | 77 +++++++++++++++++++++++++++++++----------------
1 files changed, 51 insertions(+), 26 deletions(-)
diff --git a/framebuffer/fbtk/text.c b/framebuffer/fbtk/text.c
index 879d888..15c3f7a 100644
--- a/framebuffer/fbtk/text.c
+++ b/framebuffer/fbtk/text.c
@@ -282,6 +282,7 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
plot_font_style_t font_style;
int fh;
int border;
+ bool caret_moved = false;
fb_text_font_style(widget, &fh, &border, &font_style);
@@ -305,6 +306,14 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
modifier &= ~(1<<1);
break;
+ case NSFB_KEY_RCTRL:
+ modifier &= ~(1<<2);
+ break;
+
+ case NSFB_KEY_LCTRL:
+ modifier &= ~(1<<3);
+ break;
+
default:
break;
}
@@ -324,13 +333,8 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
nsfont.font_width(&font_style, widget->u.text.text,
widget->u.text.len, &widget->u.text.width);
- nsfont.font_width(&font_style, widget->u.text.text,
- widget->u.text.idx, &widget->u.text.idx_offset);
- fbtk_set_caret(widget, true,
- widget->u.text.idx_offset + border,
- border,
- widget->height - border - border,
- fb_text_input_remove_caret_cb);
+
+ caret_moved = true;
break;
case NSFB_KEY_RETURN:
@@ -338,29 +342,25 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
break;
case NSFB_KEY_RIGHT:
- if (widget->u.text.idx < widget->u.text.len)
- widget->u.text.idx++;
+ if (widget->u.text.idx < widget->u.text.len) {
+ if (modifier == 0)
+ widget->u.text.idx++;
+ else
+ widget->u.text.idx = widget->u.text.len;
- nsfont.font_width(&font_style, widget->u.text.text,
- widget->u.text.idx, &widget->u.text.idx_offset);
- fbtk_set_caret(widget, true,
- widget->u.text.idx_offset + border,
- border,
- widget->height - border - border,
- fb_text_input_remove_caret_cb);
+ caret_moved = true;
+ }
break;
case NSFB_KEY_LEFT:
- if (widget->u.text.idx > 0)
- widget->u.text.idx--;
+ if (widget->u.text.idx > 0) {
+ if (modifier == 0)
+ widget->u.text.idx--;
+ else
+ widget->u.text.idx = 0;
- nsfont.font_width(&font_style, widget->u.text.text,
- widget->u.text.idx, &widget->u.text.idx_offset);
- fbtk_set_caret(widget, true,
- widget->u.text.idx_offset + border,
- border,
- widget->height - border - border,
- fb_text_input_remove_caret_cb);
+ caret_moved = true;
+ }
break;
case NSFB_KEY_PAGEUP:
@@ -379,7 +379,28 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
modifier |= 1<<1;
break;
+ case NSFB_KEY_RCTRL:
+ modifier |= 1<<2;
+ break;
+
+ case NSFB_KEY_LCTRL:
+ modifier |= 1<<3;
+ break;
+
default:
+ if (modifier & 1<<2 || modifier & 1<<3) {
+ /* CTRL pressed, don't enter any text */
+ if (value == NSFB_KEY_u) {
+ /* CTRL+U: clear writable */
+ widget->u.text.idx = 0;
+ widget->u.text.len = 0;
+ widget->u.text.text[widget->u.text.len] = '\0';
+ widget->u.text.width = 0;
+ caret_moved = true;
+ }
+ break;
+ }
+
/* allow for new character and null */
temp = realloc(widget->u.text.text, widget->u.text.len + 2);
if (temp == NULL) {
@@ -398,6 +419,11 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
nsfont.font_width(&font_style, widget->u.text.text,
widget->u.text.len, &widget->u.text.width);
+ caret_moved = true;
+ break;
+ }
+
+ if (caret_moved) {
nsfont.font_width(&font_style, widget->u.text.text,
widget->u.text.idx, &widget->u.text.idx_offset);
fbtk_set_caret(widget, true,
@@ -405,7 +431,6 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
border,
widget->height - border - border,
fb_text_input_remove_caret_cb);
- break;
}
fbtk_request_redraw(widget);
--
NetSurf Browser
11 years, 1 month
netsurf: branch master updated. 4fd5d51765e9ec42626c961277062731942328a6
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/4fd5d51765e9ec42626c9...
...commit http://git.netsurf-browser.org/netsurf.git/commit/4fd5d51765e9ec42626c961...
...tree http://git.netsurf-browser.org/netsurf.git/tree/4fd5d51765e9ec42626c96127...
The branch, master has been updated
via 4fd5d51765e9ec42626c961277062731942328a6 (commit)
via 5c25b8255a9c3e62bf7ac1264cc5443ea3f14abc (commit)
from 53183b2411f10dbaf1a0b85ded1d2bd8b6df5ea9 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/4fd5d51765e9ec42626...
commit 4fd5d51765e9ec42626c961277062731942328a6
Merge: 5c25b82 53183b2
Author: Vincent Sanders <vince(a)netsurf-browser.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
Merge branch 'master' of git://git.netsurf-browser.org/netsurf
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/5c25b8255a9c3e62bf7...
commit 5c25b8255a9c3e62bf7ac1264cc5443ea3f14abc
Author: Vincent Sanders <vince(a)netsurf-browser.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
add post parse script execution
diff --git a/render/html.c b/render/html.c
index 4263a06..069f290 100644
--- a/render/html.c
+++ b/render/html.c
@@ -1972,6 +1972,9 @@ html_begin_conversion(html_content *htmlc)
return false;
}
+ /* complete script execution */
+ html_scripts_exec(htmlc);
+
htmlc->document = dom_hubbub_parser_get_document(htmlc->parser);
if (htmlc->document == NULL) {
diff --git a/render/html_internal.h b/render/html_internal.h
index 0f20cc1..b4e6d2c 100644
--- a/render/html_internal.h
+++ b/render/html_internal.h
@@ -158,6 +158,7 @@ void html_overflow_scroll_callback(void *client_data,
/* in render/html_script.c */
dom_hubbub_error html_process_script(void *ctx, dom_node *node);
void html_free_scripts(html_content *html);
+bool html_scripts_exec(html_content *c);
/* in render/html_forms.c */
struct form *html_forms_get_forms(const char *docenc, dom_html_document *doc);
diff --git a/render/html_script.c b/render/html_script.c
index f4d80ab..b27abf7 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -49,13 +49,13 @@ static script_handler_t *select_script_handler(content_type ctype)
}
-/* attempt to progress script execution
+/* attempt defer and async script execution
*
* execute scripts using algorithm found in:
* http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.h...
*
*/
-static bool html_scripts_exec(html_content *c)
+bool html_scripts_exec(html_content *c)
{
unsigned int i;
struct html_script *s;
@@ -69,10 +69,8 @@ static bool html_scripts_exec(html_content *c)
continue;
}
- assert((s->type == HTML_SCRIPT_SYNC) ||
- (s->type == HTML_SCRIPT_INLINE));
-
- if (s->type == HTML_SCRIPT_SYNC) {
+ if ((s->type == HTML_SCRIPT_ASYNC) ||
+ (s->type == HTML_SCRIPT_DEFER)) {
/* ensure script content is present */
if (s->data.handle == NULL)
continue;
@@ -99,14 +97,7 @@ static bool html_scripts_exec(html_content *c)
s->already_started = true;
- } else {
- /* script not yet available */
-
- /* check if deferable or asynchronous */
- if (!s->defer && !s->async) {
- break;
- }
- }
+ }
}
}
-----------------------------------------------------------------------
Summary of changes:
render/html.c | 3 +++
render/html_internal.h | 1 +
render/html_script.c | 19 +++++--------------
3 files changed, 9 insertions(+), 14 deletions(-)
diff --git a/render/html.c b/render/html.c
index 4263a06..069f290 100644
--- a/render/html.c
+++ b/render/html.c
@@ -1972,6 +1972,9 @@ html_begin_conversion(html_content *htmlc)
return false;
}
+ /* complete script execution */
+ html_scripts_exec(htmlc);
+
htmlc->document = dom_hubbub_parser_get_document(htmlc->parser);
if (htmlc->document == NULL) {
diff --git a/render/html_internal.h b/render/html_internal.h
index 0f20cc1..b4e6d2c 100644
--- a/render/html_internal.h
+++ b/render/html_internal.h
@@ -158,6 +158,7 @@ void html_overflow_scroll_callback(void *client_data,
/* in render/html_script.c */
dom_hubbub_error html_process_script(void *ctx, dom_node *node);
void html_free_scripts(html_content *html);
+bool html_scripts_exec(html_content *c);
/* in render/html_forms.c */
struct form *html_forms_get_forms(const char *docenc, dom_html_document *doc);
diff --git a/render/html_script.c b/render/html_script.c
index f4d80ab..b27abf7 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -49,13 +49,13 @@ static script_handler_t *select_script_handler(content_type ctype)
}
-/* attempt to progress script execution
+/* attempt defer and async script execution
*
* execute scripts using algorithm found in:
* http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.h...
*
*/
-static bool html_scripts_exec(html_content *c)
+bool html_scripts_exec(html_content *c)
{
unsigned int i;
struct html_script *s;
@@ -69,10 +69,8 @@ static bool html_scripts_exec(html_content *c)
continue;
}
- assert((s->type == HTML_SCRIPT_SYNC) ||
- (s->type == HTML_SCRIPT_INLINE));
-
- if (s->type == HTML_SCRIPT_SYNC) {
+ if ((s->type == HTML_SCRIPT_ASYNC) ||
+ (s->type == HTML_SCRIPT_DEFER)) {
/* ensure script content is present */
if (s->data.handle == NULL)
continue;
@@ -99,14 +97,7 @@ static bool html_scripts_exec(html_content *c)
s->already_started = true;
- } else {
- /* script not yet available */
-
- /* check if deferable or asynchronous */
- if (!s->defer && !s->async) {
- break;
- }
- }
+ }
}
}
--
NetSurf Browser
11 years, 1 month
netsurf: branch master updated. 53183b2411f10dbaf1a0b85ded1d2bd8b6df5ea9
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/53183b2411f10dbaf1a0b...
...commit http://git.netsurf-browser.org/netsurf.git/commit/53183b2411f10dbaf1a0b85...
...tree http://git.netsurf-browser.org/netsurf.git/tree/53183b2411f10dbaf1a0b85de...
The branch, master has been updated
via 53183b2411f10dbaf1a0b85ded1d2bd8b6df5ea9 (commit)
via 9505fdcf849433d4cb08b4e9a340c3ab73f53e6a (commit)
via 72cb5b6ea47986acab5ec2bc0463db31b9330237 (commit)
via daa47fce528aa2dc5eb2c089ac106c744c91a8bb (commit)
from 84152cd72b5971250ba37b7654856a15c03ba42b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/53183b2411f10dbaf1a...
commit 53183b2411f10dbaf1a0b85ded1d2bd8b6df5ea9
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Make text input widget remove caret on "strip focus" event.
diff --git a/framebuffer/fbtk/text.c b/framebuffer/fbtk/text.c
index 69e8215..879d888 100644
--- a/framebuffer/fbtk/text.c
+++ b/framebuffer/fbtk/text.c
@@ -413,9 +413,9 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
return 0;
}
-/** Routine called when text events occour in writeable widget.
+/** Routine called when click events occour in writeable widget.
*
- * @param widget The widget reciving input events.
+ * @param widget The widget reciving click events.
* @param cbi The callback parameters.
* @return The callback result.
*/
@@ -447,6 +447,20 @@ text_input_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
return 0;
}
+/** Routine called when "stripped of focus" event occours for writeable widget.
+ *
+ * @param widget The widget reciving "stripped of focus" event.
+ * @param cbi The callback parameters.
+ * @return The callback result.
+ */
+static int
+text_input_strip_focus(fbtk_widget_t *widget, fbtk_callback_info *cbi)
+{
+ fbtk_set_caret(widget, false, 0, 0, 0, NULL);
+
+ return 0;
+}
+
/* exported function documented in fbtk.h */
void
fbtk_writable_text(fbtk_widget_t *widget, fbtk_enter_t enter, void *pw)
@@ -546,6 +560,7 @@ fbtk_create_writable_text(fbtk_widget_t *parent,
fbtk_set_handler(neww, FBTK_CBT_REDRAW, fb_redraw_text, NULL);
fbtk_set_handler(neww, FBTK_CBT_CLICK, text_input_click, pw);
+ fbtk_set_handler(neww, FBTK_CBT_STRIP_FOCUS, text_input_strip_focus, NULL);
fbtk_set_handler(neww, FBTK_CBT_INPUT, text_input, neww);
return neww;
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/9505fdcf849433d4cb0...
commit 9505fdcf849433d4cb08b4e9a340c3ab73f53e6a
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Make browser window widget remove caret on "strip focus" event.
diff --git a/framebuffer/gui.c b/framebuffer/gui.c
index 52d2f25..286f263 100644
--- a/framebuffer/gui.c
+++ b/framebuffer/gui.c
@@ -1153,6 +1153,20 @@ create_toolbar(struct gui_window *gw,
return toolbar;
}
+/** Routine called when "stripped of focus" event occours for browser widget.
+ *
+ * @param widget The widget reciving "stripped of focus" event.
+ * @param cbi The callback parameters.
+ * @return The callback result.
+ */
+static int
+fb_browser_window_strip_focus(fbtk_widget_t *widget, fbtk_callback_info *cbi)
+{
+ fbtk_set_caret(widget, false, 0, 0, 0, NULL);
+
+ return 0;
+}
+
static void
create_browser_widget(struct gui_window *gw, int toolbar_height, int furniture_width)
{
@@ -1169,6 +1183,7 @@ create_browser_widget(struct gui_window *gw, int toolbar_height, int furniture_w
fbtk_set_handler(gw->browser, FBTK_CBT_REDRAW, fb_browser_window_redraw, gw);
fbtk_set_handler(gw->browser, FBTK_CBT_INPUT, fb_browser_window_input, gw);
fbtk_set_handler(gw->browser, FBTK_CBT_CLICK, fb_browser_window_click, gw);
+ fbtk_set_handler(gw->browser, FBTK_CBT_STRIP_FOCUS, fb_browser_window_strip_focus, gw);
fbtk_set_handler(gw->browser, FBTK_CBT_POINTERMOVE, fb_browser_window_move, gw);
}
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/72cb5b6ea47986acab5...
commit 72cb5b6ea47986acab5ec2bc0463db31b9330237
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add widget callback for getting stripped of focus. Call it in the input setter, on previous input holder.
diff --git a/framebuffer/fbtk.h b/framebuffer/fbtk.h
index a3f0155..f2b09e5 100644
--- a/framebuffer/fbtk.h
+++ b/framebuffer/fbtk.h
@@ -48,6 +48,7 @@ typedef enum fbtk_callback_type {
FBTK_CBT_REDRAW,
FBTK_CBT_DESTROY,
FBTK_CBT_USER,
+ FBTK_CBT_STRIP_FOCUS,
FBTK_CBT_END,
} fbtk_callback_type;
diff --git a/framebuffer/fbtk/fbtk.c b/framebuffer/fbtk/fbtk.c
index d333d20..b29fe9f 100644
--- a/framebuffer/fbtk/fbtk.c
+++ b/framebuffer/fbtk/fbtk.c
@@ -729,6 +729,9 @@ fbtk_post_callback(fbtk_widget_t *widget, fbtk_callback_type cbt, ...)
case FBTK_CBT_USER:
break;
+ case FBTK_CBT_STRIP_FOCUS:
+ break;
+
default:
break;
}
@@ -749,6 +752,13 @@ fbtk_set_focus(fbtk_widget_t *widget)
/* ensure we have the root widget */
root = fbtk_get_root_widget(widget);
+ if (root->u.root.input != NULL &&
+ root->u.root.input != widget) {
+ /* inform previous holder of focus that it's being stripped
+ * of focus */
+ fbtk_post_callback(root->u.root.input, FBTK_CBT_STRIP_FOCUS);
+ }
+
root->u.root.input = widget;
}
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/daa47fce528aa2dc5eb...
commit daa47fce528aa2dc5eb2c089ac106c744c91a8bb
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Use setter when giving clicked input focus.
diff --git a/framebuffer/fbtk/event.c b/framebuffer/fbtk/event.c
index 0c68912..570c829 100644
--- a/framebuffer/fbtk/event.c
+++ b/framebuffer/fbtk/event.c
@@ -79,7 +79,7 @@ fbtk_click(fbtk_widget_t *widget, nsfb_event_t *event)
return;
if (fbtk_get_handler(clicked, FBTK_CBT_INPUT) != NULL) {
- root->u.root.input = clicked;
+ fbtk_set_focus(clicked);
}
x = fbtk_get_absx(clicked);
-----------------------------------------------------------------------
Summary of changes:
framebuffer/fbtk.h | 1 +
framebuffer/fbtk/event.c | 2 +-
framebuffer/fbtk/fbtk.c | 10 ++++++++++
framebuffer/fbtk/text.c | 19 +++++++++++++++++--
framebuffer/gui.c | 15 +++++++++++++++
5 files changed, 44 insertions(+), 3 deletions(-)
diff --git a/framebuffer/fbtk.h b/framebuffer/fbtk.h
index a3f0155..f2b09e5 100644
--- a/framebuffer/fbtk.h
+++ b/framebuffer/fbtk.h
@@ -48,6 +48,7 @@ typedef enum fbtk_callback_type {
FBTK_CBT_REDRAW,
FBTK_CBT_DESTROY,
FBTK_CBT_USER,
+ FBTK_CBT_STRIP_FOCUS,
FBTK_CBT_END,
} fbtk_callback_type;
diff --git a/framebuffer/fbtk/event.c b/framebuffer/fbtk/event.c
index 0c68912..570c829 100644
--- a/framebuffer/fbtk/event.c
+++ b/framebuffer/fbtk/event.c
@@ -79,7 +79,7 @@ fbtk_click(fbtk_widget_t *widget, nsfb_event_t *event)
return;
if (fbtk_get_handler(clicked, FBTK_CBT_INPUT) != NULL) {
- root->u.root.input = clicked;
+ fbtk_set_focus(clicked);
}
x = fbtk_get_absx(clicked);
diff --git a/framebuffer/fbtk/fbtk.c b/framebuffer/fbtk/fbtk.c
index d333d20..b29fe9f 100644
--- a/framebuffer/fbtk/fbtk.c
+++ b/framebuffer/fbtk/fbtk.c
@@ -729,6 +729,9 @@ fbtk_post_callback(fbtk_widget_t *widget, fbtk_callback_type cbt, ...)
case FBTK_CBT_USER:
break;
+ case FBTK_CBT_STRIP_FOCUS:
+ break;
+
default:
break;
}
@@ -749,6 +752,13 @@ fbtk_set_focus(fbtk_widget_t *widget)
/* ensure we have the root widget */
root = fbtk_get_root_widget(widget);
+ if (root->u.root.input != NULL &&
+ root->u.root.input != widget) {
+ /* inform previous holder of focus that it's being stripped
+ * of focus */
+ fbtk_post_callback(root->u.root.input, FBTK_CBT_STRIP_FOCUS);
+ }
+
root->u.root.input = widget;
}
diff --git a/framebuffer/fbtk/text.c b/framebuffer/fbtk/text.c
index 69e8215..879d888 100644
--- a/framebuffer/fbtk/text.c
+++ b/framebuffer/fbtk/text.c
@@ -413,9 +413,9 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
return 0;
}
-/** Routine called when text events occour in writeable widget.
+/** Routine called when click events occour in writeable widget.
*
- * @param widget The widget reciving input events.
+ * @param widget The widget reciving click events.
* @param cbi The callback parameters.
* @return The callback result.
*/
@@ -447,6 +447,20 @@ text_input_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
return 0;
}
+/** Routine called when "stripped of focus" event occours for writeable widget.
+ *
+ * @param widget The widget reciving "stripped of focus" event.
+ * @param cbi The callback parameters.
+ * @return The callback result.
+ */
+static int
+text_input_strip_focus(fbtk_widget_t *widget, fbtk_callback_info *cbi)
+{
+ fbtk_set_caret(widget, false, 0, 0, 0, NULL);
+
+ return 0;
+}
+
/* exported function documented in fbtk.h */
void
fbtk_writable_text(fbtk_widget_t *widget, fbtk_enter_t enter, void *pw)
@@ -546,6 +560,7 @@ fbtk_create_writable_text(fbtk_widget_t *parent,
fbtk_set_handler(neww, FBTK_CBT_REDRAW, fb_redraw_text, NULL);
fbtk_set_handler(neww, FBTK_CBT_CLICK, text_input_click, pw);
+ fbtk_set_handler(neww, FBTK_CBT_STRIP_FOCUS, text_input_strip_focus, NULL);
fbtk_set_handler(neww, FBTK_CBT_INPUT, text_input, neww);
return neww;
diff --git a/framebuffer/gui.c b/framebuffer/gui.c
index 52d2f25..286f263 100644
--- a/framebuffer/gui.c
+++ b/framebuffer/gui.c
@@ -1153,6 +1153,20 @@ create_toolbar(struct gui_window *gw,
return toolbar;
}
+/** Routine called when "stripped of focus" event occours for browser widget.
+ *
+ * @param widget The widget reciving "stripped of focus" event.
+ * @param cbi The callback parameters.
+ * @return The callback result.
+ */
+static int
+fb_browser_window_strip_focus(fbtk_widget_t *widget, fbtk_callback_info *cbi)
+{
+ fbtk_set_caret(widget, false, 0, 0, 0, NULL);
+
+ return 0;
+}
+
static void
create_browser_widget(struct gui_window *gw, int toolbar_height, int furniture_width)
{
@@ -1169,6 +1183,7 @@ create_browser_widget(struct gui_window *gw, int toolbar_height, int furniture_w
fbtk_set_handler(gw->browser, FBTK_CBT_REDRAW, fb_browser_window_redraw, gw);
fbtk_set_handler(gw->browser, FBTK_CBT_INPUT, fb_browser_window_input, gw);
fbtk_set_handler(gw->browser, FBTK_CBT_CLICK, fb_browser_window_click, gw);
+ fbtk_set_handler(gw->browser, FBTK_CBT_STRIP_FOCUS, fb_browser_window_strip_focus, gw);
fbtk_set_handler(gw->browser, FBTK_CBT_POINTERMOVE, fb_browser_window_move, gw);
}
--
NetSurf Browser
11 years, 1 month
netsurf: branch master updated. 84152cd72b5971250ba37b7654856a15c03ba42b
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/84152cd72b5971250ba37...
...commit http://git.netsurf-browser.org/netsurf.git/commit/84152cd72b5971250ba37b7...
...tree http://git.netsurf-browser.org/netsurf.git/tree/84152cd72b5971250ba37b765...
The branch, master has been updated
via 84152cd72b5971250ba37b7654856a15c03ba42b (commit)
from 2999410af69bff5e27e1203d2288a938bcee8604 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/84152cd72b5971250ba...
commit 84152cd72b5971250ba37b7654856a15c03ba42b
Author: Vincent Sanders <vince(a)netsurf-browser.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
add another script test
diff --git a/test/js/index.html b/test/js/index.html
index 22f602e..f7ce2f3 100644
--- a/test/js/index.html
+++ b/test/js/index.html
@@ -9,7 +9,8 @@
<li><a href="assorted.html">Assorted</a></li>
<li><a href="inline-doc-write-simple.html">Simple docuemnt write</a></li>
<li><a href="inline-doc-write.html">Script within inline script</a></li>
-<li><a href="sync-script.html">External syncronous script (with css)</a></li>
+<li><a href="sync-script.html">External syncronous script</a></li>
+<li><a href="sync-script-css.html">External syncronous script (with css)</a></li>
</ul>
diff --git a/test/js/sync-script-css.html b/test/js/sync-script-css.html
new file mode 100644
index 0000000..55840f2
--- /dev/null
+++ b/test/js/sync-script-css.html
@@ -0,0 +1,12 @@
+<html>
+<head>
+<title>Sync script Test (css)</title>
+<link rel="stylesheet" type="text/css" href="tst.css">
+</head>
+<body>
+<h1>Sync script Test (css0</h1>
+<p>Before</p>
+<script src="tst.js"></script>
+<p>Afterwards</p>
+</body>
+</html>
diff --git a/test/js/sync-script.html b/test/js/sync-script.html
index e234fb4..9692631 100644
--- a/test/js/sync-script.html
+++ b/test/js/sync-script.html
@@ -1,7 +1,6 @@
<html>
<head>
<title>Sync script Test</title>
-<link rel="stylesheet" type="text/css" href="tst.css">
</head>
<body>
<h1>Sync script Test</h1>
-----------------------------------------------------------------------
Summary of changes:
test/js/index.html | 3 ++-
test/js/{sync-script.html => sync-script-css.html} | 4 ++--
test/js/sync-script.html | 1 -
3 files changed, 4 insertions(+), 4 deletions(-)
copy test/js/{sync-script.html => sync-script-css.html} (69%)
diff --git a/test/js/index.html b/test/js/index.html
index 22f602e..f7ce2f3 100644
--- a/test/js/index.html
+++ b/test/js/index.html
@@ -9,7 +9,8 @@
<li><a href="assorted.html">Assorted</a></li>
<li><a href="inline-doc-write-simple.html">Simple docuemnt write</a></li>
<li><a href="inline-doc-write.html">Script within inline script</a></li>
-<li><a href="sync-script.html">External syncronous script (with css)</a></li>
+<li><a href="sync-script.html">External syncronous script</a></li>
+<li><a href="sync-script-css.html">External syncronous script (with css)</a></li>
</ul>
diff --git a/test/js/sync-script.html b/test/js/sync-script-css.html
similarity index 69%
copy from test/js/sync-script.html
copy to test/js/sync-script-css.html
index e234fb4..55840f2 100644
--- a/test/js/sync-script.html
+++ b/test/js/sync-script-css.html
@@ -1,10 +1,10 @@
<html>
<head>
-<title>Sync script Test</title>
+<title>Sync script Test (css)</title>
<link rel="stylesheet" type="text/css" href="tst.css">
</head>
<body>
-<h1>Sync script Test</h1>
+<h1>Sync script Test (css0</h1>
<p>Before</p>
<script src="tst.js"></script>
<p>Afterwards</p>
diff --git a/test/js/sync-script.html b/test/js/sync-script.html
index e234fb4..9692631 100644
--- a/test/js/sync-script.html
+++ b/test/js/sync-script.html
@@ -1,7 +1,6 @@
<html>
<head>
<title>Sync script Test</title>
-<link rel="stylesheet" type="text/css" href="tst.css">
</head>
<body>
<h1>Sync script Test</h1>
--
NetSurf Browser
11 years, 1 month
netsurf: branch master updated. 2999410af69bff5e27e1203d2288a938bcee8604
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/2999410af69bff5e27e12...
...commit http://git.netsurf-browser.org/netsurf.git/commit/2999410af69bff5e27e1203...
...tree http://git.netsurf-browser.org/netsurf.git/tree/2999410af69bff5e27e1203d2...
The branch, master has been updated
via 2999410af69bff5e27e1203d2288a938bcee8604 (commit)
via 9a92e7bdebb9886bff3f0fbdf7e5c9416588e010 (commit)
via 140795500c6186d588b180d60b168ba10caed1cf (commit)
via 2e4bb2d020a1de1b0c8c8a3d80264243b11b29bc (commit)
via 941a48dabd93323f11ac2b18803289d30e8b3a78 (commit)
from 4125a8afdfcbc18fb5e0e60b49d6d5cdd44d008c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/2999410af69bff5e27e...
commit 2999410af69bff5e27e1203d2288a938bcee8604
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
When a text input widget has its text set, and it has the caret, move the caret to the end.
diff --git a/framebuffer/fbtk/text.c b/framebuffer/fbtk/text.c
index 34cb1f9..69e8215 100644
--- a/framebuffer/fbtk/text.c
+++ b/framebuffer/fbtk/text.c
@@ -461,6 +461,11 @@ fbtk_writable_text(fbtk_widget_t *widget, fbtk_enter_t enter, void *pw)
void
fbtk_set_text(fbtk_widget_t *widget, const char *text)
{
+ plot_font_style_t font_style;
+ int c_x, c_y, c_h;
+ int fh;
+ int border;
+
if ((widget == NULL) || (widget->type != FB_WIDGET_TYPE_TEXT))
return;
if (widget->u.text.text != NULL) {
@@ -472,6 +477,22 @@ fbtk_set_text(fbtk_widget_t *widget, const char *text)
widget->u.text.len = strlen(text);
widget->u.text.idx = widget->u.text.len;
+
+ fb_text_font_style(widget, &fh, &border, &font_style);
+ nsfont.font_width(&font_style, widget->u.text.text,
+ widget->u.text.len, &widget->u.text.width);
+ nsfont.font_width(&font_style, widget->u.text.text,
+ widget->u.text.idx, &widget->u.text.idx_offset);
+
+ if (fbtk_get_caret(widget, &c_x, &c_y, &c_h)) {
+ /* Widget has caret; move it to end of new string */
+ fbtk_set_caret(widget, true,
+ widget->u.text.idx_offset + border,
+ border,
+ widget->height - border - border,
+ fb_text_input_remove_caret_cb);
+ }
+
fbtk_request_redraw(widget);
}
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/9a92e7bdebb9886bff3...
commit 9a92e7bdebb9886bff3f0fbdf7e5c9416588e010
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Core's gui_window_remove_caret should only remove caret if the bw in question owns the caret.
diff --git a/framebuffer/gui.c b/framebuffer/gui.c
index cae17c5..52d2f25 100644
--- a/framebuffer/gui.c
+++ b/framebuffer/gui.c
@@ -1536,8 +1536,12 @@ gui_window_place_caret(struct gui_window *g, int x, int y, int height)
void
gui_window_remove_caret(struct gui_window *g)
{
- /* remove caret */
- fbtk_set_caret(g->browser, false, 0, 0, 0, NULL);
+ int c_x, c_y, c_h;
+
+ if (fbtk_get_caret(g->browser, &c_x, &c_y, &c_h)) {
+ /* browser window owns the caret, so can remove it */
+ fbtk_set_caret(g->browser, false, 0, 0, 0, NULL);
+ }
}
void
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/140795500c6186d588b...
commit 140795500c6186d588b180d60b168ba10caed1cf
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Claim, position, and render caret in text input widget. Currently does not remove caret when input widget is stripped of focus (because widget doesn't know).
diff --git a/framebuffer/fbtk/text.c b/framebuffer/fbtk/text.c
index 505515c..34cb1f9 100644
--- a/framebuffer/fbtk/text.c
+++ b/framebuffer/fbtk/text.c
@@ -29,9 +29,11 @@
#include "utils/log.h"
#include "desktop/browser.h"
+#include "render/font.h"
#include "framebuffer/gui.h"
#include "framebuffer/fbtk.h"
+#include "framebuffer/font.h"
#include "framebuffer/framebuffer.h"
#include "framebuffer/image_data.h"
@@ -52,11 +54,24 @@
/* Get a font style for a text input */
static inline void
-fb_text_font_style(fbtk_widget_t *widget, int font_height,
+fb_text_font_style(fbtk_widget_t *widget, int *font_height, int *padding,
plot_font_style_t *font_style)
{
+ if (widget->u.text.outline)
+ *padding = 1;
+ else
+ *padding = 0;
+
+#ifdef FB_USE_FREETYPE
+ *padding += widget->height / 6;
+ *font_height = widget->height - *padding - *padding;
+#else
+ *font_height = font_regular.height;
+ *padding = (widget->height - *padding - *font_height) / 2;
+#endif
+
font_style->family = PLOT_FONT_FAMILY_SANS_SERIF;
- font_style->size = px_to_pt(font_height) * FONT_SIZE_SCALE;
+ font_style->size = px_to_pt(*font_height) * FONT_SIZE_SCALE;
font_style->weight = 400;
font_style->flags = FONTF_NONE;
font_style->background = widget->bg;
@@ -78,10 +93,11 @@ fb_redraw_text(fbtk_widget_t *widget, fbtk_callback_info *cbi )
nsfb_bbox_t rect;
fbtk_widget_t *root;
plot_font_style_t font_style;
+ int caret_x, caret_y, caret_h;
int fh;
int padding;
- padding = (widget->height * FBTK_WIDGET_PADDING) / 200;
+ fb_text_font_style(widget, &fh, &padding, &font_style);
root = fbtk_get_root_widget(widget);
@@ -101,26 +117,39 @@ fb_redraw_text(fbtk_widget_t *widget, fbtk_callback_info *cbi )
if (widget->u.text.outline) {
rect.x1--;
rect.y1--;
- nsfb_plot_rectangle(root->u.root.fb, &rect, 1, 0x00000000, false, false);
- padding++;
+ nsfb_plot_rectangle(root->u.root.fb, &rect, 1,
+ 0x00000000, false, false);
}
if (widget->u.text.text != NULL) {
- fh = widget->height - padding - padding;
- fb_text_font_style(widget, fh, &font_style);
- FBTK_LOG(("plotting %p at %d,%d %d,%d w/h %d,%d font h %d padding %d",
+ FBTK_LOG(("plotting %p at %d,%d %d,%d w/h %d,%d "
+ "font h %d padding %d",
widget, bbox.x0, bbox.y0, bbox.x1, bbox.y1,
widget->width, widget->height, fh, padding));
- /* Call the fb text plotting, baseline is 3/4 down the
- * font, somewhere along the way the co-ordinate
- * system for the baseline is to the "higher value
- * pixel co-ordinate" due to this the + 1 is neccessary.
- */
+ /* Call the fb text plotting, baseline is 3/4 down the font */
fb_plotters.text(bbox.x0 + padding,
- bbox.y0 + (((fh * 3) + 3)/4) + padding + 1,
- widget->u.text.text,
- widget->u.text.len,
- &font_style);
+ bbox.y0 + ((fh * 3) / 4) + padding,
+ widget->u.text.text,
+ widget->u.text.len,
+ &font_style);
+ }
+
+ if (fbtk_get_caret(widget, &caret_x, &caret_y, &caret_h)) {
+ /* This widget has caret, so render it */
+ nsfb_t *nsfb = fbtk_get_nsfb(widget);
+ nsfb_bbox_t line;
+ nsfb_plot_pen_t pen;
+
+ line.x0 = bbox.x0 + caret_x;
+ line.y0 = bbox.y0 + caret_y;
+ line.x1 = bbox.x0 + caret_x;
+ line.y1 = bbox.y0 + caret_y + caret_h;
+
+ pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
+ pen.stroke_width = 1;
+ pen.stroke_colour = 0xFF0000FF;
+
+ nsfb_plot_line(nsfb, &line, &pen);
}
nsfb_update(root->u.root.fb, &bbox);
@@ -144,15 +173,12 @@ fb_redraw_text_button(fbtk_widget_t *widget, fbtk_callback_info *cbi )
nsfb_bbox_t line;
nsfb_plot_pen_t pen;
plot_font_style_t font_style;
+ int caret_x, caret_y, caret_h;
int fh;
int border;
fbtk_widget_t *root = fbtk_get_root_widget(widget);
- if (widget->height < 20) {
- border = 0;
- } else {
- border = (widget->height * 10) / 90;
- }
+ fb_text_font_style(widget, &fh, &border, &font_style);
pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
pen.stroke_width = 1;
@@ -194,26 +220,36 @@ fb_redraw_text_button(fbtk_widget_t *widget, fbtk_callback_info *cbi )
line.x1 = rect.x1;
line.y1 = rect.y1;
nsfb_plot_line(root->u.root.fb, &line, &pen);
- border++;
}
if (widget->u.text.text != NULL) {
- fh = widget->height - border - border;
- fb_text_font_style(widget, fh, &font_style);
-
LOG(("plotting %p at %d,%d %d,%d w/h %d,%d font h %d border %d",
widget, bbox.x0, bbox.y0, bbox.x1, bbox.y1,
widget->width, widget->height, fh, border));
- /* Call the fb text plotting, baseline is 3/4 down the
- * font, somewhere along the way the co-ordinate
- * system for the baseline is to the "higher value
- * pixel co-ordinate" due to this the + 1 is neccessary.
- */
+ /* Call the fb text plotting, baseline is 3/4 down the font */
fb_plotters.text(bbox.x0 + border,
- bbox.y0 + (((fh * 3) + 3)/4) + border + 1,
- widget->u.text.text,
- widget->u.text.len,
- &font_style);
+ bbox.y0 + ((fh * 3) / 4) + border,
+ widget->u.text.text,
+ widget->u.text.len,
+ &font_style);
+ }
+
+ if (fbtk_get_caret(widget, &caret_x, &caret_y, &caret_h)) {
+ /* This widget has caret, so render it */
+ nsfb_t *nsfb = fbtk_get_nsfb(widget);
+ nsfb_bbox_t line;
+ nsfb_plot_pen_t pen;
+
+ line.x0 = bbox.x0 + caret_x;
+ line.y0 = bbox.y0 + caret_y;
+ line.x1 = bbox.x0 + caret_x;
+ line.y1 = bbox.y0 + caret_y + caret_h;
+
+ pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
+ pen.stroke_width = 1;
+ pen.stroke_colour = 0xFF0000FF;
+
+ nsfb_plot_line(nsfb, &line, &pen);
}
nsfb_update(root->u.root.fb, &bbox);
@@ -221,6 +257,16 @@ fb_redraw_text_button(fbtk_widget_t *widget, fbtk_callback_info *cbi )
return 0;
}
+static void
+fb_text_input_remove_caret_cb(fbtk_widget_t *widget)
+{
+ int c_x, c_y, c_h;
+
+ if (fbtk_get_caret(widget, &c_x, &c_y, &c_h)) {
+ fbtk_request_redraw(widget);
+ }
+}
+
/** Routine called when text events occour in writeable widget.
*
* @param widget The widget reciving input events.
@@ -233,14 +279,16 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
int value;
static uint8_t modifier = 0;
char *temp;
+ plot_font_style_t font_style;
+ int fh;
+ int border;
+
+ fb_text_font_style(widget, &fh, &border, &font_style);
if (cbi->event == NULL) {
/* gain focus */
if (widget->u.text.text == NULL)
widget->u.text.text = calloc(1,1);
- widget->u.text.idx = widget->u.text.len;
-
- fbtk_request_redraw(widget);
return 0;
}
@@ -273,6 +321,16 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
widget->u.text.idx--;
widget->u.text.len--;
widget->u.text.text[widget->u.text.len] = 0;
+
+ nsfont.font_width(&font_style, widget->u.text.text,
+ widget->u.text.len, &widget->u.text.width);
+ nsfont.font_width(&font_style, widget->u.text.text,
+ widget->u.text.idx, &widget->u.text.idx_offset);
+ fbtk_set_caret(widget, true,
+ widget->u.text.idx_offset + border,
+ border,
+ widget->height - border - border,
+ fb_text_input_remove_caret_cb);
break;
case NSFB_KEY_RETURN:
@@ -282,11 +340,27 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
case NSFB_KEY_RIGHT:
if (widget->u.text.idx < widget->u.text.len)
widget->u.text.idx++;
+
+ nsfont.font_width(&font_style, widget->u.text.text,
+ widget->u.text.idx, &widget->u.text.idx_offset);
+ fbtk_set_caret(widget, true,
+ widget->u.text.idx_offset + border,
+ border,
+ widget->height - border - border,
+ fb_text_input_remove_caret_cb);
break;
case NSFB_KEY_LEFT:
if (widget->u.text.idx > 0)
widget->u.text.idx--;
+
+ nsfont.font_width(&font_style, widget->u.text.text,
+ widget->u.text.idx, &widget->u.text.idx_offset);
+ fbtk_set_caret(widget, true,
+ widget->u.text.idx_offset + border,
+ border,
+ widget->height - border - border,
+ fb_text_input_remove_caret_cb);
break;
case NSFB_KEY_PAGEUP:
@@ -322,6 +396,15 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
widget->u.text.len++;
widget->u.text.text[widget->u.text.len] = '\0';
+ nsfont.font_width(&font_style, widget->u.text.text,
+ widget->u.text.len, &widget->u.text.width);
+ nsfont.font_width(&font_style, widget->u.text.text,
+ widget->u.text.idx, &widget->u.text.idx_offset);
+ fbtk_set_caret(widget, true,
+ widget->u.text.idx_offset + border,
+ border,
+ widget->height - border - border,
+ fb_text_input_remove_caret_cb);
break;
}
@@ -330,6 +413,40 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
return 0;
}
+/** Routine called when text events occour in writeable widget.
+ *
+ * @param widget The widget reciving input events.
+ * @param cbi The callback parameters.
+ * @return The callback result.
+ */
+static int
+text_input_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
+{
+ plot_font_style_t font_style;
+ int fh;
+ int border;
+ size_t idx;
+
+ fb_text_font_style(widget, &fh, &border, &font_style);
+
+ widget->u.text.idx = widget->u.text.len;
+
+ nsfont.font_position_in_string(&font_style, widget->u.text.text,
+ widget->u.text.len, cbi->x - border,
+ &idx,
+ &widget->u.text.idx_offset);
+ widget->u.text.idx = idx;
+ fbtk_set_caret(widget, true,
+ widget->u.text.idx_offset + border,
+ border,
+ widget->height - border - border,
+ fb_text_input_remove_caret_cb);
+
+ fbtk_request_redraw(widget);
+
+ return 0;
+}
+
/* exported function documented in fbtk.h */
void
fbtk_writable_text(fbtk_widget_t *widget, fbtk_enter_t enter, void *pw)
@@ -407,6 +524,7 @@ fbtk_create_writable_text(fbtk_widget_t *parent,
neww->u.text.pw = pw;
fbtk_set_handler(neww, FBTK_CBT_REDRAW, fb_redraw_text, NULL);
+ fbtk_set_handler(neww, FBTK_CBT_CLICK, text_input_click, pw);
fbtk_set_handler(neww, FBTK_CBT_INPUT, text_input, neww);
return neww;
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/2e4bb2d020a1de1b0c8...
commit 2e4bb2d020a1de1b0c8c8a3d80264243b11b29bc
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Round to nearest point between chars in nsfont_position_in_string, instead of rounding down.
diff --git a/framebuffer/font_internal.c b/framebuffer/font_internal.c
index 6ef13d5..6535ac4 100644
--- a/framebuffer/font_internal.c
+++ b/framebuffer/font_internal.c
@@ -18,6 +18,7 @@
*/
#include <inttypes.h>
+#include <string.h>
#include <assert.h>
#include "css/css.h"
@@ -112,7 +113,7 @@ static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
int x, size_t *char_offset, int *actual_x)
{
const struct fb_font_desc* fb_font = fb_get_font(fstyle);
- *char_offset = x / fb_font->width;
+ *char_offset = (x + fb_font->width / 2) / fb_font->width;
if (*char_offset > length)
*char_offset = length;
*actual_x = *char_offset * fb_font->width;
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/941a48dabd93323f11a...
commit 941a48dabd93323f11ac2b18803289d30e8b3a78
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
When setting fbtk caret, register callback for redrawing caret removal.
diff --git a/framebuffer/fbtk.h b/framebuffer/fbtk.h
index 131ae65..a3f0155 100644
--- a/framebuffer/fbtk.h
+++ b/framebuffer/fbtk.h
@@ -273,7 +273,8 @@ bool fbtk_set_pos_and_size(fbtk_widget_t *widget, int x, int y, int width, int h
* @param y y-coordinate of caret top
* @param height height of caret
*/
-void fbtk_set_caret(fbtk_widget_t *widget, bool set, int x, int y, int height);
+void fbtk_set_caret(fbtk_widget_t *widget, bool set, int x, int y, int height,
+ void (*remove_caret)(fbtk_widget_t *widget));
/** Map a widget and request it is redrawn.
*/
diff --git a/framebuffer/fbtk/fbtk.c b/framebuffer/fbtk/fbtk.c
index 8e8bc11..d333d20 100644
--- a/framebuffer/fbtk/fbtk.c
+++ b/framebuffer/fbtk/fbtk.c
@@ -224,21 +224,30 @@ fbtk_set_pos_and_size(fbtk_widget_t *widget,
/* exported function docuemnted in fbtk.h */
void
fbtk_set_caret(fbtk_widget_t *widget, bool set,
- int x, int y, int height)
+ int x, int y, int height,
+ void (*remove_caret)(fbtk_widget_t *widget))
{
fbtk_widget_t *root;
assert(widget != NULL);
root = fbtk_get_root_widget(widget);
+ if (root->u.root.caret.owner != NULL &&
+ root->u.root.caret.remove_cb != NULL)
+ root->u.root.caret.remove_cb(widget);
+
if (set) {
+ assert(remove_caret != NULL);
+
root->u.root.caret.owner = widget;
root->u.root.caret.x = x;
root->u.root.caret.y = y;
root->u.root.caret.height = height;
+ root->u.root.caret.remove_cb = remove_caret;
} else {
root->u.root.caret.owner = NULL;
+ root->u.root.caret.remove_cb = NULL;
}
}
diff --git a/framebuffer/fbtk/widget.h b/framebuffer/fbtk/widget.h
index 3521cc3..5622723 100644
--- a/framebuffer/fbtk/widget.h
+++ b/framebuffer/fbtk/widget.h
@@ -168,6 +168,7 @@ struct fbtk_widget_s {
int x; /* relative to owner */
int y; /* relative to owner */
int height;
+ void (*remove_cb)(fbtk_widget_t *widget);
} caret;
} root;
@@ -182,9 +183,10 @@ struct fbtk_widget_s {
bool outline;
fbtk_enter_t enter;
void *pw;
- int idx;
- int len;
- int width;
+ int idx; /* caret pos in text */
+ int len; /* text length */
+ int width; /* text width in px */
+ int idx_offset; /* caret pos in pixels */
} text;
/* application driven widget */
diff --git a/framebuffer/gui.c b/framebuffer/gui.c
index 216791d..cae17c5 100644
--- a/framebuffer/gui.c
+++ b/framebuffer/gui.c
@@ -1499,24 +1499,31 @@ gui_window_stop_throbber(struct gui_window *gw)
}
-void
-gui_window_place_caret(struct gui_window *g, int x, int y, int height)
+static void
+gui_window_remove_caret_cb(fbtk_widget_t *widget)
{
- struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser);
+ struct browser_widget_s *bwidget = fbtk_get_userpw(widget);
int c_x, c_y, c_h;
- if (fbtk_get_caret(g->browser, &c_x, &c_y, &c_h)) {
+ if (fbtk_get_caret(widget, &c_x, &c_y, &c_h)) {
/* browser window already had caret:
* redraw its area to remove it first */
- fb_queue_redraw(g->browser,
+ fb_queue_redraw(widget,
c_x - bwidget->scrollx,
c_y - bwidget->scrolly,
c_x + 1 - bwidget->scrollx,
c_y + c_h - bwidget->scrolly);
}
+}
+
+void
+gui_window_place_caret(struct gui_window *g, int x, int y, int height)
+{
+ struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser);
/* set new pos */
- fbtk_set_caret(g->browser, true, x, y, height);
+ fbtk_set_caret(g->browser, true, x, y, height,
+ gui_window_remove_caret_cb);
/* redraw new caret pos */
fb_queue_redraw(g->browser,
@@ -1529,21 +1536,8 @@ gui_window_place_caret(struct gui_window *g, int x, int y, int height)
void
gui_window_remove_caret(struct gui_window *g)
{
- struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser);
- int c_x, c_y, c_h;
-
- if (fbtk_get_caret(g->browser, &c_x, &c_y, &c_h)) {
- /* browser window already had caret:
- * redraw its area to remove it first */
- fb_queue_redraw(g->browser,
- c_x - bwidget->scrollx,
- c_y - bwidget->scrolly,
- c_x + 1 - bwidget->scrollx,
- c_y + c_h - bwidget->scrolly);
- }
-
/* remove caret */
- fbtk_set_caret(g->browser, false, 0, 0, 0);
+ fbtk_set_caret(g->browser, false, 0, 0, 0, NULL);
}
void
-----------------------------------------------------------------------
Summary of changes:
framebuffer/fbtk.h | 3 +-
framebuffer/fbtk/fbtk.c | 11 ++-
framebuffer/fbtk/text.c | 215 +++++++++++++++++++++++++++++++++++--------
framebuffer/fbtk/widget.h | 8 +-
framebuffer/font_internal.c | 3 +-
framebuffer/gui.c | 32 +++----
6 files changed, 211 insertions(+), 61 deletions(-)
diff --git a/framebuffer/fbtk.h b/framebuffer/fbtk.h
index 131ae65..a3f0155 100644
--- a/framebuffer/fbtk.h
+++ b/framebuffer/fbtk.h
@@ -273,7 +273,8 @@ bool fbtk_set_pos_and_size(fbtk_widget_t *widget, int x, int y, int width, int h
* @param y y-coordinate of caret top
* @param height height of caret
*/
-void fbtk_set_caret(fbtk_widget_t *widget, bool set, int x, int y, int height);
+void fbtk_set_caret(fbtk_widget_t *widget, bool set, int x, int y, int height,
+ void (*remove_caret)(fbtk_widget_t *widget));
/** Map a widget and request it is redrawn.
*/
diff --git a/framebuffer/fbtk/fbtk.c b/framebuffer/fbtk/fbtk.c
index 8e8bc11..d333d20 100644
--- a/framebuffer/fbtk/fbtk.c
+++ b/framebuffer/fbtk/fbtk.c
@@ -224,21 +224,30 @@ fbtk_set_pos_and_size(fbtk_widget_t *widget,
/* exported function docuemnted in fbtk.h */
void
fbtk_set_caret(fbtk_widget_t *widget, bool set,
- int x, int y, int height)
+ int x, int y, int height,
+ void (*remove_caret)(fbtk_widget_t *widget))
{
fbtk_widget_t *root;
assert(widget != NULL);
root = fbtk_get_root_widget(widget);
+ if (root->u.root.caret.owner != NULL &&
+ root->u.root.caret.remove_cb != NULL)
+ root->u.root.caret.remove_cb(widget);
+
if (set) {
+ assert(remove_caret != NULL);
+
root->u.root.caret.owner = widget;
root->u.root.caret.x = x;
root->u.root.caret.y = y;
root->u.root.caret.height = height;
+ root->u.root.caret.remove_cb = remove_caret;
} else {
root->u.root.caret.owner = NULL;
+ root->u.root.caret.remove_cb = NULL;
}
}
diff --git a/framebuffer/fbtk/text.c b/framebuffer/fbtk/text.c
index 505515c..69e8215 100644
--- a/framebuffer/fbtk/text.c
+++ b/framebuffer/fbtk/text.c
@@ -29,9 +29,11 @@
#include "utils/log.h"
#include "desktop/browser.h"
+#include "render/font.h"
#include "framebuffer/gui.h"
#include "framebuffer/fbtk.h"
+#include "framebuffer/font.h"
#include "framebuffer/framebuffer.h"
#include "framebuffer/image_data.h"
@@ -52,11 +54,24 @@
/* Get a font style for a text input */
static inline void
-fb_text_font_style(fbtk_widget_t *widget, int font_height,
+fb_text_font_style(fbtk_widget_t *widget, int *font_height, int *padding,
plot_font_style_t *font_style)
{
+ if (widget->u.text.outline)
+ *padding = 1;
+ else
+ *padding = 0;
+
+#ifdef FB_USE_FREETYPE
+ *padding += widget->height / 6;
+ *font_height = widget->height - *padding - *padding;
+#else
+ *font_height = font_regular.height;
+ *padding = (widget->height - *padding - *font_height) / 2;
+#endif
+
font_style->family = PLOT_FONT_FAMILY_SANS_SERIF;
- font_style->size = px_to_pt(font_height) * FONT_SIZE_SCALE;
+ font_style->size = px_to_pt(*font_height) * FONT_SIZE_SCALE;
font_style->weight = 400;
font_style->flags = FONTF_NONE;
font_style->background = widget->bg;
@@ -78,10 +93,11 @@ fb_redraw_text(fbtk_widget_t *widget, fbtk_callback_info *cbi )
nsfb_bbox_t rect;
fbtk_widget_t *root;
plot_font_style_t font_style;
+ int caret_x, caret_y, caret_h;
int fh;
int padding;
- padding = (widget->height * FBTK_WIDGET_PADDING) / 200;
+ fb_text_font_style(widget, &fh, &padding, &font_style);
root = fbtk_get_root_widget(widget);
@@ -101,26 +117,39 @@ fb_redraw_text(fbtk_widget_t *widget, fbtk_callback_info *cbi )
if (widget->u.text.outline) {
rect.x1--;
rect.y1--;
- nsfb_plot_rectangle(root->u.root.fb, &rect, 1, 0x00000000, false, false);
- padding++;
+ nsfb_plot_rectangle(root->u.root.fb, &rect, 1,
+ 0x00000000, false, false);
}
if (widget->u.text.text != NULL) {
- fh = widget->height - padding - padding;
- fb_text_font_style(widget, fh, &font_style);
- FBTK_LOG(("plotting %p at %d,%d %d,%d w/h %d,%d font h %d padding %d",
+ FBTK_LOG(("plotting %p at %d,%d %d,%d w/h %d,%d "
+ "font h %d padding %d",
widget, bbox.x0, bbox.y0, bbox.x1, bbox.y1,
widget->width, widget->height, fh, padding));
- /* Call the fb text plotting, baseline is 3/4 down the
- * font, somewhere along the way the co-ordinate
- * system for the baseline is to the "higher value
- * pixel co-ordinate" due to this the + 1 is neccessary.
- */
+ /* Call the fb text plotting, baseline is 3/4 down the font */
fb_plotters.text(bbox.x0 + padding,
- bbox.y0 + (((fh * 3) + 3)/4) + padding + 1,
- widget->u.text.text,
- widget->u.text.len,
- &font_style);
+ bbox.y0 + ((fh * 3) / 4) + padding,
+ widget->u.text.text,
+ widget->u.text.len,
+ &font_style);
+ }
+
+ if (fbtk_get_caret(widget, &caret_x, &caret_y, &caret_h)) {
+ /* This widget has caret, so render it */
+ nsfb_t *nsfb = fbtk_get_nsfb(widget);
+ nsfb_bbox_t line;
+ nsfb_plot_pen_t pen;
+
+ line.x0 = bbox.x0 + caret_x;
+ line.y0 = bbox.y0 + caret_y;
+ line.x1 = bbox.x0 + caret_x;
+ line.y1 = bbox.y0 + caret_y + caret_h;
+
+ pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
+ pen.stroke_width = 1;
+ pen.stroke_colour = 0xFF0000FF;
+
+ nsfb_plot_line(nsfb, &line, &pen);
}
nsfb_update(root->u.root.fb, &bbox);
@@ -144,15 +173,12 @@ fb_redraw_text_button(fbtk_widget_t *widget, fbtk_callback_info *cbi )
nsfb_bbox_t line;
nsfb_plot_pen_t pen;
plot_font_style_t font_style;
+ int caret_x, caret_y, caret_h;
int fh;
int border;
fbtk_widget_t *root = fbtk_get_root_widget(widget);
- if (widget->height < 20) {
- border = 0;
- } else {
- border = (widget->height * 10) / 90;
- }
+ fb_text_font_style(widget, &fh, &border, &font_style);
pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
pen.stroke_width = 1;
@@ -194,26 +220,36 @@ fb_redraw_text_button(fbtk_widget_t *widget, fbtk_callback_info *cbi )
line.x1 = rect.x1;
line.y1 = rect.y1;
nsfb_plot_line(root->u.root.fb, &line, &pen);
- border++;
}
if (widget->u.text.text != NULL) {
- fh = widget->height - border - border;
- fb_text_font_style(widget, fh, &font_style);
-
LOG(("plotting %p at %d,%d %d,%d w/h %d,%d font h %d border %d",
widget, bbox.x0, bbox.y0, bbox.x1, bbox.y1,
widget->width, widget->height, fh, border));
- /* Call the fb text plotting, baseline is 3/4 down the
- * font, somewhere along the way the co-ordinate
- * system for the baseline is to the "higher value
- * pixel co-ordinate" due to this the + 1 is neccessary.
- */
+ /* Call the fb text plotting, baseline is 3/4 down the font */
fb_plotters.text(bbox.x0 + border,
- bbox.y0 + (((fh * 3) + 3)/4) + border + 1,
- widget->u.text.text,
- widget->u.text.len,
- &font_style);
+ bbox.y0 + ((fh * 3) / 4) + border,
+ widget->u.text.text,
+ widget->u.text.len,
+ &font_style);
+ }
+
+ if (fbtk_get_caret(widget, &caret_x, &caret_y, &caret_h)) {
+ /* This widget has caret, so render it */
+ nsfb_t *nsfb = fbtk_get_nsfb(widget);
+ nsfb_bbox_t line;
+ nsfb_plot_pen_t pen;
+
+ line.x0 = bbox.x0 + caret_x;
+ line.y0 = bbox.y0 + caret_y;
+ line.x1 = bbox.x0 + caret_x;
+ line.y1 = bbox.y0 + caret_y + caret_h;
+
+ pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
+ pen.stroke_width = 1;
+ pen.stroke_colour = 0xFF0000FF;
+
+ nsfb_plot_line(nsfb, &line, &pen);
}
nsfb_update(root->u.root.fb, &bbox);
@@ -221,6 +257,16 @@ fb_redraw_text_button(fbtk_widget_t *widget, fbtk_callback_info *cbi )
return 0;
}
+static void
+fb_text_input_remove_caret_cb(fbtk_widget_t *widget)
+{
+ int c_x, c_y, c_h;
+
+ if (fbtk_get_caret(widget, &c_x, &c_y, &c_h)) {
+ fbtk_request_redraw(widget);
+ }
+}
+
/** Routine called when text events occour in writeable widget.
*
* @param widget The widget reciving input events.
@@ -233,14 +279,16 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
int value;
static uint8_t modifier = 0;
char *temp;
+ plot_font_style_t font_style;
+ int fh;
+ int border;
+
+ fb_text_font_style(widget, &fh, &border, &font_style);
if (cbi->event == NULL) {
/* gain focus */
if (widget->u.text.text == NULL)
widget->u.text.text = calloc(1,1);
- widget->u.text.idx = widget->u.text.len;
-
- fbtk_request_redraw(widget);
return 0;
}
@@ -273,6 +321,16 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
widget->u.text.idx--;
widget->u.text.len--;
widget->u.text.text[widget->u.text.len] = 0;
+
+ nsfont.font_width(&font_style, widget->u.text.text,
+ widget->u.text.len, &widget->u.text.width);
+ nsfont.font_width(&font_style, widget->u.text.text,
+ widget->u.text.idx, &widget->u.text.idx_offset);
+ fbtk_set_caret(widget, true,
+ widget->u.text.idx_offset + border,
+ border,
+ widget->height - border - border,
+ fb_text_input_remove_caret_cb);
break;
case NSFB_KEY_RETURN:
@@ -282,11 +340,27 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
case NSFB_KEY_RIGHT:
if (widget->u.text.idx < widget->u.text.len)
widget->u.text.idx++;
+
+ nsfont.font_width(&font_style, widget->u.text.text,
+ widget->u.text.idx, &widget->u.text.idx_offset);
+ fbtk_set_caret(widget, true,
+ widget->u.text.idx_offset + border,
+ border,
+ widget->height - border - border,
+ fb_text_input_remove_caret_cb);
break;
case NSFB_KEY_LEFT:
if (widget->u.text.idx > 0)
widget->u.text.idx--;
+
+ nsfont.font_width(&font_style, widget->u.text.text,
+ widget->u.text.idx, &widget->u.text.idx_offset);
+ fbtk_set_caret(widget, true,
+ widget->u.text.idx_offset + border,
+ border,
+ widget->height - border - border,
+ fb_text_input_remove_caret_cb);
break;
case NSFB_KEY_PAGEUP:
@@ -322,6 +396,15 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
widget->u.text.len++;
widget->u.text.text[widget->u.text.len] = '\0';
+ nsfont.font_width(&font_style, widget->u.text.text,
+ widget->u.text.len, &widget->u.text.width);
+ nsfont.font_width(&font_style, widget->u.text.text,
+ widget->u.text.idx, &widget->u.text.idx_offset);
+ fbtk_set_caret(widget, true,
+ widget->u.text.idx_offset + border,
+ border,
+ widget->height - border - border,
+ fb_text_input_remove_caret_cb);
break;
}
@@ -330,6 +413,40 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
return 0;
}
+/** Routine called when text events occour in writeable widget.
+ *
+ * @param widget The widget reciving input events.
+ * @param cbi The callback parameters.
+ * @return The callback result.
+ */
+static int
+text_input_click(fbtk_widget_t *widget, fbtk_callback_info *cbi)
+{
+ plot_font_style_t font_style;
+ int fh;
+ int border;
+ size_t idx;
+
+ fb_text_font_style(widget, &fh, &border, &font_style);
+
+ widget->u.text.idx = widget->u.text.len;
+
+ nsfont.font_position_in_string(&font_style, widget->u.text.text,
+ widget->u.text.len, cbi->x - border,
+ &idx,
+ &widget->u.text.idx_offset);
+ widget->u.text.idx = idx;
+ fbtk_set_caret(widget, true,
+ widget->u.text.idx_offset + border,
+ border,
+ widget->height - border - border,
+ fb_text_input_remove_caret_cb);
+
+ fbtk_request_redraw(widget);
+
+ return 0;
+}
+
/* exported function documented in fbtk.h */
void
fbtk_writable_text(fbtk_widget_t *widget, fbtk_enter_t enter, void *pw)
@@ -344,6 +461,11 @@ fbtk_writable_text(fbtk_widget_t *widget, fbtk_enter_t enter, void *pw)
void
fbtk_set_text(fbtk_widget_t *widget, const char *text)
{
+ plot_font_style_t font_style;
+ int c_x, c_y, c_h;
+ int fh;
+ int border;
+
if ((widget == NULL) || (widget->type != FB_WIDGET_TYPE_TEXT))
return;
if (widget->u.text.text != NULL) {
@@ -355,6 +477,22 @@ fbtk_set_text(fbtk_widget_t *widget, const char *text)
widget->u.text.len = strlen(text);
widget->u.text.idx = widget->u.text.len;
+
+ fb_text_font_style(widget, &fh, &border, &font_style);
+ nsfont.font_width(&font_style, widget->u.text.text,
+ widget->u.text.len, &widget->u.text.width);
+ nsfont.font_width(&font_style, widget->u.text.text,
+ widget->u.text.idx, &widget->u.text.idx_offset);
+
+ if (fbtk_get_caret(widget, &c_x, &c_y, &c_h)) {
+ /* Widget has caret; move it to end of new string */
+ fbtk_set_caret(widget, true,
+ widget->u.text.idx_offset + border,
+ border,
+ widget->height - border - border,
+ fb_text_input_remove_caret_cb);
+ }
+
fbtk_request_redraw(widget);
}
@@ -407,6 +545,7 @@ fbtk_create_writable_text(fbtk_widget_t *parent,
neww->u.text.pw = pw;
fbtk_set_handler(neww, FBTK_CBT_REDRAW, fb_redraw_text, NULL);
+ fbtk_set_handler(neww, FBTK_CBT_CLICK, text_input_click, pw);
fbtk_set_handler(neww, FBTK_CBT_INPUT, text_input, neww);
return neww;
diff --git a/framebuffer/fbtk/widget.h b/framebuffer/fbtk/widget.h
index 3521cc3..5622723 100644
--- a/framebuffer/fbtk/widget.h
+++ b/framebuffer/fbtk/widget.h
@@ -168,6 +168,7 @@ struct fbtk_widget_s {
int x; /* relative to owner */
int y; /* relative to owner */
int height;
+ void (*remove_cb)(fbtk_widget_t *widget);
} caret;
} root;
@@ -182,9 +183,10 @@ struct fbtk_widget_s {
bool outline;
fbtk_enter_t enter;
void *pw;
- int idx;
- int len;
- int width;
+ int idx; /* caret pos in text */
+ int len; /* text length */
+ int width; /* text width in px */
+ int idx_offset; /* caret pos in pixels */
} text;
/* application driven widget */
diff --git a/framebuffer/font_internal.c b/framebuffer/font_internal.c
index 6ef13d5..6535ac4 100644
--- a/framebuffer/font_internal.c
+++ b/framebuffer/font_internal.c
@@ -18,6 +18,7 @@
*/
#include <inttypes.h>
+#include <string.h>
#include <assert.h>
#include "css/css.h"
@@ -112,7 +113,7 @@ static bool nsfont_position_in_string(const plot_font_style_t *fstyle,
int x, size_t *char_offset, int *actual_x)
{
const struct fb_font_desc* fb_font = fb_get_font(fstyle);
- *char_offset = x / fb_font->width;
+ *char_offset = (x + fb_font->width / 2) / fb_font->width;
if (*char_offset > length)
*char_offset = length;
*actual_x = *char_offset * fb_font->width;
diff --git a/framebuffer/gui.c b/framebuffer/gui.c
index 216791d..52d2f25 100644
--- a/framebuffer/gui.c
+++ b/framebuffer/gui.c
@@ -1499,24 +1499,31 @@ gui_window_stop_throbber(struct gui_window *gw)
}
-void
-gui_window_place_caret(struct gui_window *g, int x, int y, int height)
+static void
+gui_window_remove_caret_cb(fbtk_widget_t *widget)
{
- struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser);
+ struct browser_widget_s *bwidget = fbtk_get_userpw(widget);
int c_x, c_y, c_h;
- if (fbtk_get_caret(g->browser, &c_x, &c_y, &c_h)) {
+ if (fbtk_get_caret(widget, &c_x, &c_y, &c_h)) {
/* browser window already had caret:
* redraw its area to remove it first */
- fb_queue_redraw(g->browser,
+ fb_queue_redraw(widget,
c_x - bwidget->scrollx,
c_y - bwidget->scrolly,
c_x + 1 - bwidget->scrollx,
c_y + c_h - bwidget->scrolly);
}
+}
+
+void
+gui_window_place_caret(struct gui_window *g, int x, int y, int height)
+{
+ struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser);
/* set new pos */
- fbtk_set_caret(g->browser, true, x, y, height);
+ fbtk_set_caret(g->browser, true, x, y, height,
+ gui_window_remove_caret_cb);
/* redraw new caret pos */
fb_queue_redraw(g->browser,
@@ -1529,21 +1536,12 @@ gui_window_place_caret(struct gui_window *g, int x, int y, int height)
void
gui_window_remove_caret(struct gui_window *g)
{
- struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser);
int c_x, c_y, c_h;
if (fbtk_get_caret(g->browser, &c_x, &c_y, &c_h)) {
- /* browser window already had caret:
- * redraw its area to remove it first */
- fb_queue_redraw(g->browser,
- c_x - bwidget->scrollx,
- c_y - bwidget->scrolly,
- c_x + 1 - bwidget->scrollx,
- c_y + c_h - bwidget->scrolly);
+ /* browser window owns the caret, so can remove it */
+ fbtk_set_caret(g->browser, false, 0, 0, 0, NULL);
}
-
- /* remove caret */
- fbtk_set_caret(g->browser, false, 0, 0, 0);
}
void
--
NetSurf Browser
11 years, 1 month
netsurf: branch master updated. 4125a8afdfcbc18fb5e0e60b49d6d5cdd44d008c
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/4125a8afdfcbc18fb5e0e...
...commit http://git.netsurf-browser.org/netsurf.git/commit/4125a8afdfcbc18fb5e0e60...
...tree http://git.netsurf-browser.org/netsurf.git/tree/4125a8afdfcbc18fb5e0e60b4...
The branch, master has been updated
via 4125a8afdfcbc18fb5e0e60b49d6d5cdd44d008c (commit)
via 45b9d9667885a9a15c228f508a705c97948f4eea (commit)
from cbfd887311935675112aa7a79f367d03324536e2 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/4125a8afdfcbc18fb5e...
commit 4125a8afdfcbc18fb5e0e60b49d6d5cdd44d008c
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Remove strlen from redraw functions.
diff --git a/framebuffer/fbtk/text.c b/framebuffer/fbtk/text.c
index f262546..505515c 100644
--- a/framebuffer/fbtk/text.c
+++ b/framebuffer/fbtk/text.c
@@ -119,7 +119,7 @@ fb_redraw_text(fbtk_widget_t *widget, fbtk_callback_info *cbi )
fb_plotters.text(bbox.x0 + padding,
bbox.y0 + (((fh * 3) + 3)/4) + padding + 1,
widget->u.text.text,
- strlen(widget->u.text.text),
+ widget->u.text.len,
&font_style);
}
@@ -212,7 +212,7 @@ fb_redraw_text_button(fbtk_widget_t *widget, fbtk_callback_info *cbi )
fb_plotters.text(bbox.x0 + border,
bbox.y0 + (((fh * 3) + 3)/4) + border + 1,
widget->u.text.text,
- strlen(widget->u.text.text),
+ widget->u.text.len,
&font_style);
}
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/45b9d9667885a9a15c2...
commit 45b9d9667885a9a15c228f508a705c97948f4eea
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add support for editing text input widget contents from arbitrary position in string (instead of just end).
diff --git a/framebuffer/fbtk/text.c b/framebuffer/fbtk/text.c
index 2796814..f262546 100644
--- a/framebuffer/fbtk/text.c
+++ b/framebuffer/fbtk/text.c
@@ -238,7 +238,7 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
/* gain focus */
if (widget->u.text.text == NULL)
widget->u.text.text = calloc(1,1);
- widget->u.text.idx = strlen(widget->u.text.text);
+ widget->u.text.idx = widget->u.text.len;
fbtk_request_redraw(widget);
@@ -267,18 +267,30 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
case NSFB_KEY_BACKSPACE:
if (widget->u.text.idx <= 0)
break;
+ memmove(widget->u.text.text + widget->u.text.idx - 1,
+ widget->u.text.text + widget->u.text.idx,
+ widget->u.text.len - widget->u.text.idx);
widget->u.text.idx--;
- widget->u.text.text[widget->u.text.idx] = 0;
+ widget->u.text.len--;
+ widget->u.text.text[widget->u.text.len] = 0;
break;
case NSFB_KEY_RETURN:
widget->u.text.enter(widget->u.text.pw, widget->u.text.text);
break;
- case NSFB_KEY_PAGEUP:
- case NSFB_KEY_PAGEDOWN:
case NSFB_KEY_RIGHT:
+ if (widget->u.text.idx < widget->u.text.len)
+ widget->u.text.idx++;
+ break;
+
case NSFB_KEY_LEFT:
+ if (widget->u.text.idx > 0)
+ widget->u.text.idx--;
+ break;
+
+ case NSFB_KEY_PAGEUP:
+ case NSFB_KEY_PAGEDOWN:
case NSFB_KEY_UP:
case NSFB_KEY_DOWN:
/* Not handling any of these correctly yet, but avoid putting
@@ -295,14 +307,21 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
default:
/* allow for new character and null */
- temp = realloc(widget->u.text.text, widget->u.text.idx + 2);
- if (temp != NULL) {
- widget->u.text.text = temp;
- widget->u.text.text[widget->u.text.idx] = fbtk_keycode_to_ucs4(value, modifier);
- widget->u.text.text[widget->u.text.idx + 1] = '\0';
- widget->u.text.idx++;
+ temp = realloc(widget->u.text.text, widget->u.text.len + 2);
+ if (temp == NULL) {
+ break;
}
+ widget->u.text.text = temp;
+ memmove(widget->u.text.text + widget->u.text.idx + 1,
+ widget->u.text.text + widget->u.text.idx,
+ widget->u.text.len - widget->u.text.idx);
+ widget->u.text.text[widget->u.text.idx] =
+ fbtk_keycode_to_ucs4(value, modifier);
+ widget->u.text.idx++;
+ widget->u.text.len++;
+ widget->u.text.text[widget->u.text.len] = '\0';
+
break;
}
@@ -333,7 +352,8 @@ fbtk_set_text(fbtk_widget_t *widget, const char *text)
free(widget->u.text.text);
}
widget->u.text.text = strdup(text);
- widget->u.text.idx = strlen(text);
+ widget->u.text.len = strlen(text);
+ widget->u.text.idx = widget->u.text.len;
fbtk_request_redraw(widget);
}
diff --git a/framebuffer/fbtk/widget.h b/framebuffer/fbtk/widget.h
index e31fa11..3521cc3 100644
--- a/framebuffer/fbtk/widget.h
+++ b/framebuffer/fbtk/widget.h
@@ -183,6 +183,8 @@ struct fbtk_widget_s {
fbtk_enter_t enter;
void *pw;
int idx;
+ int len;
+ int width;
} text;
/* application driven widget */
-----------------------------------------------------------------------
Summary of changes:
framebuffer/fbtk/text.c | 46 ++++++++++++++++++++++++++++++++------------
framebuffer/fbtk/widget.h | 2 +
2 files changed, 35 insertions(+), 13 deletions(-)
diff --git a/framebuffer/fbtk/text.c b/framebuffer/fbtk/text.c
index 2796814..505515c 100644
--- a/framebuffer/fbtk/text.c
+++ b/framebuffer/fbtk/text.c
@@ -119,7 +119,7 @@ fb_redraw_text(fbtk_widget_t *widget, fbtk_callback_info *cbi )
fb_plotters.text(bbox.x0 + padding,
bbox.y0 + (((fh * 3) + 3)/4) + padding + 1,
widget->u.text.text,
- strlen(widget->u.text.text),
+ widget->u.text.len,
&font_style);
}
@@ -212,7 +212,7 @@ fb_redraw_text_button(fbtk_widget_t *widget, fbtk_callback_info *cbi )
fb_plotters.text(bbox.x0 + border,
bbox.y0 + (((fh * 3) + 3)/4) + border + 1,
widget->u.text.text,
- strlen(widget->u.text.text),
+ widget->u.text.len,
&font_style);
}
@@ -238,7 +238,7 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
/* gain focus */
if (widget->u.text.text == NULL)
widget->u.text.text = calloc(1,1);
- widget->u.text.idx = strlen(widget->u.text.text);
+ widget->u.text.idx = widget->u.text.len;
fbtk_request_redraw(widget);
@@ -267,18 +267,30 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
case NSFB_KEY_BACKSPACE:
if (widget->u.text.idx <= 0)
break;
+ memmove(widget->u.text.text + widget->u.text.idx - 1,
+ widget->u.text.text + widget->u.text.idx,
+ widget->u.text.len - widget->u.text.idx);
widget->u.text.idx--;
- widget->u.text.text[widget->u.text.idx] = 0;
+ widget->u.text.len--;
+ widget->u.text.text[widget->u.text.len] = 0;
break;
case NSFB_KEY_RETURN:
widget->u.text.enter(widget->u.text.pw, widget->u.text.text);
break;
- case NSFB_KEY_PAGEUP:
- case NSFB_KEY_PAGEDOWN:
case NSFB_KEY_RIGHT:
+ if (widget->u.text.idx < widget->u.text.len)
+ widget->u.text.idx++;
+ break;
+
case NSFB_KEY_LEFT:
+ if (widget->u.text.idx > 0)
+ widget->u.text.idx--;
+ break;
+
+ case NSFB_KEY_PAGEUP:
+ case NSFB_KEY_PAGEDOWN:
case NSFB_KEY_UP:
case NSFB_KEY_DOWN:
/* Not handling any of these correctly yet, but avoid putting
@@ -295,14 +307,21 @@ text_input(fbtk_widget_t *widget, fbtk_callback_info *cbi)
default:
/* allow for new character and null */
- temp = realloc(widget->u.text.text, widget->u.text.idx + 2);
- if (temp != NULL) {
- widget->u.text.text = temp;
- widget->u.text.text[widget->u.text.idx] = fbtk_keycode_to_ucs4(value, modifier);
- widget->u.text.text[widget->u.text.idx + 1] = '\0';
- widget->u.text.idx++;
+ temp = realloc(widget->u.text.text, widget->u.text.len + 2);
+ if (temp == NULL) {
+ break;
}
+ widget->u.text.text = temp;
+ memmove(widget->u.text.text + widget->u.text.idx + 1,
+ widget->u.text.text + widget->u.text.idx,
+ widget->u.text.len - widget->u.text.idx);
+ widget->u.text.text[widget->u.text.idx] =
+ fbtk_keycode_to_ucs4(value, modifier);
+ widget->u.text.idx++;
+ widget->u.text.len++;
+ widget->u.text.text[widget->u.text.len] = '\0';
+
break;
}
@@ -333,7 +352,8 @@ fbtk_set_text(fbtk_widget_t *widget, const char *text)
free(widget->u.text.text);
}
widget->u.text.text = strdup(text);
- widget->u.text.idx = strlen(text);
+ widget->u.text.len = strlen(text);
+ widget->u.text.idx = widget->u.text.len;
fbtk_request_redraw(widget);
}
diff --git a/framebuffer/fbtk/widget.h b/framebuffer/fbtk/widget.h
index e31fa11..3521cc3 100644
--- a/framebuffer/fbtk/widget.h
+++ b/framebuffer/fbtk/widget.h
@@ -183,6 +183,8 @@ struct fbtk_widget_s {
fbtk_enter_t enter;
void *pw;
int idx;
+ int len;
+ int width;
} text;
/* application driven widget */
--
NetSurf Browser
11 years, 1 month
netsurf: branch master updated. cbfd887311935675112aa7a79f367d03324536e2
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/cbfd887311935675112aa...
...commit http://git.netsurf-browser.org/netsurf.git/commit/cbfd887311935675112aa7a...
...tree http://git.netsurf-browser.org/netsurf.git/tree/cbfd887311935675112aa7a79...
The branch, master has been updated
via cbfd887311935675112aa7a79f367d03324536e2 (commit)
via c0aaf31f5a9a65808d8b7af92434608135ccc752 (commit)
via d763e57d30dc8c68309c5b35f556531cb8346da5 (commit)
via 4182685d1e90e082407a8e40a0b1db76cf9fbea2 (commit)
via b0a41606ffe3b2cff04c68e0ae0aec96816cb857 (commit)
via db76dd3b1abd32950971c38b3a8fb915471fb3d2 (commit)
via 06608c1bf0b1046520e184fdc063c83ead2184af (commit)
via 4f0e70b50d2446ed3ba14bd51d61c80088226d91 (commit)
via f207f14be1e95d0c1fa1866decf2c07a119ba8fe (commit)
from 90b0c48bb216cef4f3aafbc14565f203a3f6861c (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/cbfd887311935675112...
commit cbfd887311935675112aa7a79f367d03324536e2
Merge: 90b0c48 c0aaf31
Author: Vincent Sanders <vince(a)netsurf-browser.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
Merge branch 'vince/script-async'
-----------------------------------------------------------------------
Summary of changes:
javascript/jsapi.h | 1 -
javascript/jsapi/document.c | 4 +-
javascript/jsapi/window.c | 12 +-
render/html.c | 159 +++++++-----
render/html.h | 13 +-
render/html_internal.h | 13 +-
render/html_script.c | 479 ++++++++++++++++++++++++++--------
test/js/assorted.html | 34 +++
test/js/index.html | 17 ++
test/js/inline-doc-write-simple.html | 11 +
test/js/inline-doc-write.html | 13 +
test/js/sync-script.html | 12 +
test/js/tst.css | 1 +
test/js/tst.js | 1 +
utils/corestrings.c | 6 +
utils/corestrings.h | 2 +
16 files changed, 599 insertions(+), 179 deletions(-)
create mode 100644 test/js/assorted.html
create mode 100644 test/js/index.html
create mode 100644 test/js/inline-doc-write-simple.html
create mode 100644 test/js/inline-doc-write.html
create mode 100644 test/js/sync-script.html
create mode 100644 test/js/tst.css
create mode 100644 test/js/tst.js
diff --git a/javascript/jsapi.h b/javascript/jsapi.h
index cf099cc..a44323f 100644
--- a/javascript/jsapi.h
+++ b/javascript/jsapi.h
@@ -79,7 +79,6 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx,
if (global == NULL) {
return NULL;
}
- JS_SetGlobalObject(cx, global);
return global;
}
diff --git a/javascript/jsapi/document.c b/javascript/jsapi/document.c
index dfad551..bb5019c 100644
--- a/javascript/jsapi/document.c
+++ b/javascript/jsapi/document.c
@@ -92,8 +92,10 @@ JSObject *jsapi_new_document(JSContext *cx, JSObject *parent, void *doc_priv)
LOG(("setting content to %p",doc_priv));
/* private pointer to browsing context */
- if (!JS_SetPrivate(cx, doc, doc_priv))
+ if (JS_SetPrivate(cx, doc, doc_priv) != JS_TRUE) {
+ LOG(("failed to set content"));
return NULL;
+ }
return doc;
}
diff --git a/javascript/jsapi/window.c b/javascript/jsapi/window.c
index 06e6cdf..0b7673b 100644
--- a/javascript/jsapi/window.c
+++ b/javascript/jsapi/window.c
@@ -299,8 +299,18 @@ JSObject * jsapi_new_window(JSContext *cx, JSObject *parent, void *win_priv)
return NULL;
}
+ /** @todo reconsider global object handling. future
+ * editions of spidermonkey appear to be removing the
+ * idea of a global so we probably need to handle
+ * global object references internally
+ */
+
+ /* set the contexts global */
+ JS_SetGlobalObject(cx, window);
+
/* Populate the global object with the standard globals, like
- Object and Array. */
+ * Object and Array.
+ */
if (!JS_InitStandardClasses(cx, window)) {
return NULL;
}
diff --git a/render/html.c b/render/html.c
index 759c244..4263a06 100644
--- a/render/html.c
+++ b/render/html.c
@@ -301,6 +301,8 @@ html_create_html_data(html_content *c, const http_parameter *params)
c->scripts = NULL;
c->jscontext = NULL;
+ c->base.active = 1; /* The html content itself is active */
+
if (lwc_intern_string("*", SLEN("*"), &c->universal) != lwc_error_ok) {
msg_data.error = messages_get("NoMemory");
content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
@@ -412,12 +414,10 @@ html_create(const content_handler *handler,
-/**
- * Process data for CONTENT_HTML.
- */
-
static bool
-html_process_data(struct content *c, const char *data, unsigned int size)
+html_process_encoding_change(struct content *c,
+ const char *data,
+ unsigned int size)
{
html_content *html = (html_content *) c;
dom_hubbub_error error;
@@ -425,23 +425,6 @@ html_process_data(struct content *c, const char *data, unsigned int size)
const char *source_data;
unsigned long source_size;
- error = dom_hubbub_parser_parse_chunk(html->parser, (const uint8_t *) data, size);
-
- if (error == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_ENCODINGCHANGE)) {
- goto encoding_change;
- } else if (error != DOM_HUBBUB_OK) {
- union content_msg_data msg_data;
-
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
-
- return false;
- }
-
- return true;
-
-encoding_change:
-
/* Retrieve new encoding */
encoding = dom_hubbub_parser_get_encoding(html->parser,
&html->encoding_source);
@@ -464,11 +447,11 @@ encoding_change:
/* Create new binding, using the new encoding */
html->parser = dom_hubbub_parser_create(html->encoding,
- true,
- nsoption_bool(enable_javascript),
- NULL,
- html_process_script,
- html);
+ true,
+ nsoption_bool(enable_javascript),
+ NULL,
+ html_process_script,
+ html);
if (html->parser == NULL) {
/* Ok, we don't support the declared encoding. Bailing out
* isn't exactly user-friendly, so fall back to Windows-1252 */
@@ -506,10 +489,50 @@ encoding_change:
source_data = content__get_source_data(c, &source_size);
- /* Recurse to reprocess all the data. This is safe because
+ /* Reprocess all the data. This is safe because
* the encoding is now specified at parser start which means
* it cannot be changed again. */
- return html_process_data(c, source_data, source_size);
+ error = dom_hubbub_parser_parse_chunk(html->parser, (const uint8_t *)source_data, source_size);
+
+ if ((error == DOM_HUBBUB_OK) ||
+ (error == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED))) {
+ return true;
+ }
+
+ union content_msg_data msg_data;
+
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+
+ return false;
+
+}
+
+/**
+ * Process data for CONTENT_HTML.
+ */
+
+static bool
+html_process_data(struct content *c, const char *data, unsigned int size)
+{
+ html_content *html = (html_content *) c;
+ dom_hubbub_error error;
+ union content_msg_data msg_data;
+
+ error = dom_hubbub_parser_parse_chunk(html->parser, (const uint8_t *) data, size);
+
+ if ((error == DOM_HUBBUB_OK) ||
+ (error == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED))) {
+ return true;
+ } else if (error == (DOM_HUBBUB_HUBBUB_ERR | HUBBUB_ENCODINGCHANGE)) {
+ return html_process_encoding_change(c, data, size);
+ }
+
+ /** @todo better error handling and reporting */
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+
+ return false;
}
@@ -1912,24 +1935,39 @@ html_find_stylesheets_no_memory:
static bool html_convert(struct content *c)
{
html_content *htmlc = (html_content *) c;
- dom_hubbub_error err;
+
+ htmlc->base.active--; /* the html fetch is no longer active */
+ LOG(("%d fetches active", htmlc->base.active));
+
+
+ /* if there are no active fetches in progress no scripts are
+ * being fetched or they completed already.
+ */
+ if (htmlc->base.active == 0) {
+ return html_begin_conversion(htmlc);
+ }
+ return true;
+
+}
+
+bool
+html_begin_conversion(html_content *htmlc)
+{
dom_node *html, *head;
union content_msg_data msg_data;
- unsigned long size;
struct form *f;
dom_exception exc; /* returned by libdom functions */
dom_string *node_name = NULL;
+ dom_hubbub_error error;
- /* finish parsing */
- content__get_source_data(c, &size);
-
- err = dom_hubbub_parser_completed(htmlc->parser);
- if (err != DOM_HUBBUB_OK) {
+ /* complete parsing */
+ error = dom_hubbub_parser_completed(htmlc->parser);
+ if (error != DOM_HUBBUB_OK) {
union content_msg_data msg_data;
- /** @todo Improve precessing of errors */
+ /** @todo Improve processing of errors */
msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
return false;
}
@@ -1939,7 +1977,7 @@ static bool html_convert(struct content *c)
if (htmlc->document == NULL) {
LOG(("Parsing failed"));
msg_data.error = messages_get("ParsingFail");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
return false;
}
@@ -1956,10 +1994,10 @@ static bool html_convert(struct content *c)
encoding = dom_hubbub_parser_get_encoding(htmlc->parser,
&htmlc->encoding_source);
- htmlc->encoding = talloc_strdup(c, encoding);
+ htmlc->encoding = talloc_strdup(&htmlc->base, encoding);
if (htmlc->encoding == NULL) {
msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
return false;
}
}
@@ -1967,7 +2005,7 @@ static bool html_convert(struct content *c)
/* Give up processing if we've been aborted */
if (htmlc->aborted) {
msg_data.error = messages_get("Stopped");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
return false;
}
@@ -1976,7 +2014,7 @@ static bool html_convert(struct content *c)
if ((exc != DOM_NO_ERR) || (html == NULL)) {
LOG(("error retrieving html element from dom"));
msg_data.error = messages_get("ParsingFail");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
return false;
}
@@ -1987,7 +2025,7 @@ static bool html_convert(struct content *c)
corestring_lwc_html))) {
LOG(("root element not html"));
msg_data.error = messages_get("ParsingFail");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
dom_node_unref(html);
return false;
}
@@ -2036,7 +2074,7 @@ static bool html_convert(struct content *c)
if (head != NULL) {
if (html_head(htmlc, head) == false) {
msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
dom_node_unref(html);
dom_node_unref(head);
return false;
@@ -2060,7 +2098,7 @@ static bool html_convert(struct content *c)
/* Make all actions absolute */
if (f->action == NULL || f->action[0] == '\0') {
/* HTML5 4.10.22.3 step 11 */
- res = url_join(nsurl_access(content_get_url(c)),
+ res = url_join(nsurl_access(content_get_url(&htmlc->base)),
nsurl_access(htmlc->base_url), &action);
} else {
res = url_join(f->action, nsurl_access(htmlc->base_url),
@@ -2069,7 +2107,7 @@ static bool html_convert(struct content *c)
if (res != URL_FUNC_OK) {
msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
+ content_broadcast(&htmlc->base, CONTENT_MSG_ERROR, msg_data);
dom_node_unref(html);
dom_node_unref(head);
return false;
@@ -2083,8 +2121,9 @@ static bool html_convert(struct content *c)
f->document_charset = strdup(htmlc->encoding);
if (f->document_charset == NULL) {
msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR,
- msg_data);
+ content_broadcast(&htmlc->base,
+ CONTENT_MSG_ERROR,
+ msg_data);
dom_node_unref(html);
dom_node_unref(head);
return false;
@@ -2093,6 +2132,7 @@ static bool html_convert(struct content *c)
}
dom_node_unref(head);
+
/* get stylesheets */
if (html_find_stylesheets(htmlc, html) == false) {
dom_node_unref(html);
@@ -2100,6 +2140,11 @@ static bool html_convert(struct content *c)
}
dom_node_unref(html);
+
+ if (htmlc->base.active == 0) {
+ html_finish_conversion(htmlc);
+ }
+
return true;
}
@@ -2433,21 +2478,7 @@ static void html_destroy(struct content *c)
}
/* Free scripts */
- for (i = 0; i != html->scripts_count; i++) {
- if (html->scripts[i].mimetype != NULL) {
- dom_string_unref(html->scripts[i].mimetype);
- }
- if (html->scripts[i].type == HTML_SCRIPT_EXTERNAL &&
- html->scripts[i].data.external != NULL) {
- hlcache_handle_release(
- html->scripts[i].data.external);
- } else if (html->scripts[i].type ==
- HTML_SCRIPT_INTERNAL &&
- html->scripts[i].data.internal != NULL) {
- dom_string_unref(html->scripts[i].data.internal);
- }
- }
- free(html->scripts);
+ html_free_scripts(html);
/* Free objects */
html_destroy_objects(html);
diff --git a/render/html.h b/render/html.h
index 64548f8..dcbc1a3 100644
--- a/render/html.h
+++ b/render/html.h
@@ -66,10 +66,13 @@ struct html_stylesheet {
*/
struct html_script {
/** Type of script */
- enum html_script_type { HTML_SCRIPT_EXTERNAL, HTML_SCRIPT_INTERNAL } type;
+ enum html_script_type { HTML_SCRIPT_INLINE,
+ HTML_SCRIPT_SYNC,
+ HTML_SCRIPT_DEFER,
+ HTML_SCRIPT_ASYNC } type;
union {
- struct hlcache_handle *external;
- struct dom_string *internal;
+ struct hlcache_handle *handle;
+ struct dom_string *string;
} data; /**< Script data */
struct dom_string *mimetype;
struct dom_string *encoding;
@@ -175,9 +178,9 @@ struct content_html_frames *html_get_frameset(struct hlcache_handle *h);
struct content_html_iframe *html_get_iframe(struct hlcache_handle *h);
nsurl *html_get_base_url(struct hlcache_handle *h);
const char *html_get_base_target(struct hlcache_handle *h);
-struct html_stylesheet *html_get_stylesheets(struct hlcache_handle *h,
+struct html_stylesheet *html_get_stylesheets(struct hlcache_handle *h,
unsigned int *n);
-struct content_html_object *html_get_objects(struct hlcache_handle *h,
+struct content_html_object *html_get_objects(struct hlcache_handle *h,
unsigned int *n);
bool html_get_id_offset(struct hlcache_handle *h, lwc_string *frag_id,
int *x, int *y);
diff --git a/render/html_internal.h b/render/html_internal.h
index ad032f7..0f20cc1 100644
--- a/render/html_internal.h
+++ b/render/html_internal.h
@@ -127,12 +127,20 @@ void html__redraw_a_box(struct content *c, struct box *box);
struct browser_window *html_get_browser_window(struct content *c);
struct search_context *html_get_search(struct content *c);
void html_set_search(struct content *c, struct search_context *s);
+
/**
* Complete conversion of an HTML document
*
- * \param c Content to convert
+ * \param htmlc Content to convert
+ */
+void html_finish_conversion(html_content *htmlc);
+
+/**
+ * Begin conversion of an HTML document
+ *
+ * \param htmlc Content to convert
*/
-void html_finish_conversion(html_content *c);
+bool html_begin_conversion(html_content *htmlc);
/* in render/html_redraw.c */
bool html_redraw(struct content *c, struct content_redraw_data *data,
@@ -149,6 +157,7 @@ void html_overflow_scroll_callback(void *client_data,
/* in render/html_script.c */
dom_hubbub_error html_process_script(void *ctx, dom_node *node);
+void html_free_scripts(html_content *html);
/* in render/html_forms.c */
struct form *html_forms_get_forms(const char *docenc, dom_html_document *doc);
diff --git a/render/html_script.c b/render/html_script.c
index 5fd8c8a..f4d80ab 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -69,32 +69,32 @@ static bool html_scripts_exec(html_content *c)
continue;
}
- assert((s->type == HTML_SCRIPT_EXTERNAL) ||
- (s->type == HTML_SCRIPT_INTERNAL));
+ assert((s->type == HTML_SCRIPT_SYNC) ||
+ (s->type == HTML_SCRIPT_INLINE));
- if (s->type == HTML_SCRIPT_EXTERNAL) {
+ if (s->type == HTML_SCRIPT_SYNC) {
/* ensure script content is present */
- if (s->data.external == NULL)
+ if (s->data.handle == NULL)
continue;
/* ensure script content fetch status is not an error */
- if (content_get_status(s->data.external) ==
+ if (content_get_status(s->data.handle) ==
CONTENT_STATUS_ERROR)
continue;
/* ensure script handler for content type */
script_handler = select_script_handler(
- content_get_type(s->data.external));
+ content_get_type(s->data.handle));
if (script_handler == NULL)
continue; /* unsupported type */
- if (content_get_status(s->data.external) ==
+ if (content_get_status(s->data.handle) ==
CONTENT_STATUS_DONE) {
/* external script is now available */
const char *data;
unsigned long size;
data = content_get_source_data(
- s->data.external, &size );
+ s->data.handle, &size );
script_handler(c->jscontext, data, size);
s->already_started = true;
@@ -115,7 +115,9 @@ static bool html_scripts_exec(html_content *c)
/* create new html script entry */
static struct html_script *
-html_process_new_script(html_content *c, enum html_script_type type)
+html_process_new_script(html_content *c,
+ dom_string *mimetype,
+ enum html_script_type type)
{
struct html_script *nscript;
/* add space for new script entry */
@@ -140,15 +142,78 @@ html_process_new_script(html_content *c, enum html_script_type type)
nscript->type = type;
+ nscript->mimetype = dom_string_ref(mimetype); /* reference mimetype */
+
return nscript;
}
/**
- * Callback for fetchcache() for linked stylesheets.
+ * Callback for asyncronous scripts
*/
+static nserror
+convert_script_async_cb(hlcache_handle *script,
+ const hlcache_event *event,
+ void *pw)
+{
+ html_content *parent = pw;
+ unsigned int i;
+ struct html_script *s;
+
+ /* Find script */
+ for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) {
+ if (s->type == HTML_SCRIPT_ASYNC && s->data.handle == script)
+ break;
+ }
+
+ assert(i != parent->scripts_count);
+
+ switch (event->type) {
+ case CONTENT_MSG_LOADING:
+ break;
+
+ case CONTENT_MSG_READY:
+ break;
+
+ case CONTENT_MSG_DONE:
+ LOG(("script %d done '%s'", i,
+ nsurl_access(hlcache_handle_get_url(script))));
+ parent->base.active--;
+ LOG(("%d fetches active", parent->base.active));
+
+
+
+ break;
+
+ case CONTENT_MSG_ERROR:
+ LOG(("script %s failed: %s",
+ nsurl_access(hlcache_handle_get_url(script)),
+ event->data.error));
+ hlcache_handle_release(script);
+ s->data.handle = NULL;
+ parent->base.active--;
+ LOG(("%d fetches active", parent->base.active));
+ content_add_error(&parent->base, "?", 0);
+
+ break;
+
+ case CONTENT_MSG_STATUS:
+ html_set_status(parent, content_get_status_message(script));
+ content_broadcast(&parent->base, CONTENT_MSG_STATUS,
+ event->data);
+ break;
+
+ default:
+ assert(0);
+ }
+ return NSERROR_OK;
+}
+
+/**
+ * Callback for defer scripts
+ */
static nserror
-html_convert_script_callback(hlcache_handle *script,
+convert_script_defer_cb(hlcache_handle *script,
const hlcache_event *event,
void *pw)
{
@@ -158,8 +223,7 @@ html_convert_script_callback(hlcache_handle *script,
/* Find script */
for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) {
- if (s->type == HTML_SCRIPT_EXTERNAL &&
- s->data.external == script)
+ if (s->type == HTML_SCRIPT_ASYNC && s->data.handle == script)
break;
}
@@ -178,8 +242,6 @@ html_convert_script_callback(hlcache_handle *script,
parent->base.active--;
LOG(("%d fetches active", parent->base.active));
- /* script finished loading so try and continue execution */
- html_scripts_exec(parent);
break;
case CONTENT_MSG_ERROR:
@@ -187,13 +249,101 @@ html_convert_script_callback(hlcache_handle *script,
nsurl_access(hlcache_handle_get_url(script)),
event->data.error));
hlcache_handle_release(script);
- s->data.external = NULL;
+ s->data.handle = NULL;
parent->base.active--;
LOG(("%d fetches active", parent->base.active));
content_add_error(&parent->base, "?", 0);
- /* script failed loading so try and continue execution */
- html_scripts_exec(parent);
+ break;
+
+ case CONTENT_MSG_STATUS:
+ html_set_status(parent, content_get_status_message(script));
+ content_broadcast(&parent->base, CONTENT_MSG_STATUS,
+ event->data);
+ break;
+
+ default:
+ assert(0);
+ }
+
+ /* if there are no active fetches remaining begin post parse
+ * conversion
+ */
+ if (parent->base.active == 0) {
+ html_begin_conversion(parent);
+ }
+
+ return NSERROR_OK;
+}
+
+/**
+ * Callback for syncronous scripts
+ */
+static nserror
+convert_script_sync_cb(hlcache_handle *script,
+ const hlcache_event *event,
+ void *pw)
+{
+ html_content *parent = pw;
+ unsigned int i;
+ struct html_script *s;
+ script_handler_t *script_handler;
+ dom_hubbub_error err;
+
+ /* Find script */
+ for (i = 0, s = parent->scripts; i != parent->scripts_count; i++, s++) {
+ if (s->type == HTML_SCRIPT_SYNC && s->data.handle == script)
+ break;
+ }
+
+ assert(i != parent->scripts_count);
+
+ switch (event->type) {
+ case CONTENT_MSG_LOADING:
+ break;
+
+ case CONTENT_MSG_READY:
+ break;
+
+ case CONTENT_MSG_DONE:
+ LOG(("script %d done '%s'", i,
+ nsurl_access(hlcache_handle_get_url(script))));
+ parent->base.active--;
+ LOG(("%d fetches active", parent->base.active));
+
+ s->already_started = true;
+
+ /* attempt to execute script */
+ script_handler = select_script_handler(content_get_type(s->data.handle));
+ if (script_handler != NULL) {
+ /* script has a handler */
+ const char *data;
+ unsigned long size;
+ data = content_get_source_data(s->data.handle, &size );
+ script_handler(parent->jscontext, data, size);
+ }
+
+ /* continue parse */
+ err = dom_hubbub_parser_pause(parent->parser, false);
+ if (err != DOM_HUBBUB_OK) {
+ LOG(("unpause returned 0x%x", err));
+ }
+
+ break;
+
+ case CONTENT_MSG_ERROR:
+ LOG(("script %s failed: %s",
+ nsurl_access(hlcache_handle_get_url(script)),
+ event->data.error));
+
+ hlcache_handle_release(script);
+ s->data.handle = NULL;
+ parent->base.active--;
+
+ LOG(("%d fetches active", parent->base.active));
+ content_add_error(&parent->base, "?", 0);
+
+ s->already_started = true;
break;
@@ -207,13 +357,193 @@ html_convert_script_callback(hlcache_handle *script,
assert(0);
}
- if (parent->base.active == 0)
- html_finish_conversion(parent);
+ /* if there are no active fetches remaining begin post parse
+ * conversion
+ */
+ if (parent->base.active == 0) {
+ html_begin_conversion(parent);
+ }
return NSERROR_OK;
}
-/** process script node
+/**
+ * process a script with a src tag
+ */
+static dom_hubbub_error
+exec_src_script(html_content *c,
+ dom_node *node,
+ dom_string *mimetype,
+ dom_string *src)
+{
+ nserror ns_error;
+ nsurl *joined;
+ hlcache_child_context child;
+ struct html_script *nscript;
+ union content_msg_data msg_data;
+ bool async;
+ bool defer;
+ enum html_script_type script_type;
+ hlcache_handle_callback script_cb;
+ dom_hubbub_error ret = DOM_HUBBUB_OK;
+ dom_exception exc; /* returned by libdom functions */
+
+ /* src url */
+ ns_error = nsurl_join(c->base_url, dom_string_data(src), &joined);
+ if (ns_error != NSERROR_OK) {
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ return DOM_HUBBUB_NOMEM;
+ }
+
+ LOG(("script %i '%s'", c->scripts_count, nsurl_access(joined)));
+
+ /* there are three ways to process the script tag at this point:
+ *
+ * Syncronously pause the parent parse and continue after
+ * the script has downloaded and executed. (default)
+ * Async Start the script downloading and execute it when it
+ * becomes available.
+ * Defered Start the script downloading and execute it when
+ * the page has completed parsing, may be set along
+ * with async where it is ignored.
+ */
+
+ /* we interpret the presence of the async and defer attribute
+ * as true and ignore its value, technically only the empty
+ * value or the attribute name itself are valid. However
+ * various browsers interpret this in various ways the most
+ * compatible approach is to be liberal and accept any
+ * value. Note setting the values to "false" still makes them true!
+ */
+ exc = dom_element_has_attribute(node, corestring_dom_async, &async);
+ if (exc != DOM_NO_ERR) {
+ return DOM_HUBBUB_OK; /* dom error */
+ }
+
+ if (async) {
+ /* asyncronous script */
+ script_type = HTML_SCRIPT_ASYNC;
+ script_cb = convert_script_async_cb;
+
+ } else {
+ exc = dom_element_has_attribute(node,
+ corestring_dom_defer, &defer);
+ if (exc != DOM_NO_ERR) {
+ return DOM_HUBBUB_OK; /* dom error */
+ }
+
+ if (defer) {
+ /* defered script */
+ script_type = HTML_SCRIPT_DEFER;
+ script_cb = convert_script_defer_cb;
+ } else {
+ /* syncronous script */
+ script_type = HTML_SCRIPT_SYNC;
+ script_cb = convert_script_sync_cb;
+ }
+ }
+
+ nscript = html_process_new_script(c, mimetype, script_type);
+ if (nscript == NULL) {
+ nsurl_unref(joined);
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ return DOM_HUBBUB_NOMEM;
+ }
+
+ /* set up child fetch encoding and quirks */
+ child.charset = c->encoding;
+ child.quirks = c->base.quirks;
+
+ ns_error = hlcache_handle_retrieve(joined,
+ 0,
+ content_get_url(&c->base),
+ NULL,
+ script_cb,
+ c,
+ &child,
+ CONTENT_SCRIPT,
+ &nscript->data.handle);
+
+
+ nsurl_unref(joined);
+
+ if (ns_error != NSERROR_OK) {
+ /* @todo Deal with fetch error better. currently assume
+ * fetch never became active
+ */
+ /* mark duff script fetch as already started */
+ nscript->already_started = true;
+ LOG(("Fetch failed with error %d",ns_error));
+ } else {
+ /* update base content active fetch count */
+ c->base.active++;
+ LOG(("%d fetches active", c->base.active));
+
+ switch (script_type) {
+ case HTML_SCRIPT_SYNC:
+ ret = DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED;
+
+ case HTML_SCRIPT_ASYNC:
+ break;
+
+ case HTML_SCRIPT_DEFER:
+ break;
+
+ default:
+ assert(0);
+ }
+ }
+
+ return ret;
+}
+
+static dom_hubbub_error
+exec_inline_script(html_content *c, dom_node *node, dom_string *mimetype)
+{
+ union content_msg_data msg_data;
+ dom_string *script;
+ dom_exception exc; /* returned by libdom functions */
+ struct lwc_string_s *lwcmimetype;
+ script_handler_t *script_handler;
+ struct html_script *nscript;
+
+ /* does not appear to be a src so script is inline content */
+ exc = dom_node_get_text_content(node, &script);
+ if ((exc != DOM_NO_ERR) || (script == NULL)) {
+ return DOM_HUBBUB_OK; /* no contents, skip */
+ }
+
+ nscript = html_process_new_script(c, mimetype, HTML_SCRIPT_INLINE);
+ if (nscript == NULL) {
+ dom_string_unref(script);
+
+ msg_data.error = messages_get("NoMemory");
+ content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
+ return DOM_HUBBUB_NOMEM;
+
+ }
+
+ nscript->data.string = script;
+ nscript->already_started = true;
+
+ /* ensure script handler for content type */
+ dom_string_intern(mimetype, &lwcmimetype);
+ script_handler = select_script_handler(content_factory_type_from_mime_type(lwcmimetype));
+ lwc_string_unref(lwcmimetype);
+
+ if (script_handler != NULL) {
+ script_handler(c->jscontext,
+ dom_string_data(script),
+ dom_string_byte_length(script));
+ }
+ return DOM_HUBBUB_OK;
+}
+
+
+/**
+ * process script node parser callback
*
*
*/
@@ -222,9 +552,8 @@ html_process_script(void *ctx, dom_node *node)
{
html_content *c = (html_content *)ctx;
dom_exception exc; /* returned by libdom functions */
- dom_string *src, *script, *mimetype;
- struct html_script *nscript;
- union content_msg_data msg_data;
+ dom_string *src, *mimetype;
+ dom_hubbub_error err = DOM_HUBBUB_OK;
/* ensure javascript context is available */
if (c->jscontext == NULL) {
@@ -239,7 +568,7 @@ html_process_script(void *ctx, dom_node *node)
}
}
- LOG(("content %p parser %p node %p",c,c->parser, node));
+ LOG(("content %p parser %p node %p", c, c->parser, node));
exc = dom_element_get_attribute(node, corestring_dom_type, &mimetype);
if (exc != DOM_NO_ERR || mimetype == NULL) {
@@ -248,97 +577,37 @@ html_process_script(void *ctx, dom_node *node)
exc = dom_element_get_attribute(node, corestring_dom_src, &src);
if (exc != DOM_NO_ERR || src == NULL) {
- struct lwc_string_s *lwcmimetype;
- script_handler_t *script_handler;
-
- /* does not appear to be a src so script is inline content */
- exc = dom_node_get_text_content(node, &script);
- if ((exc != DOM_NO_ERR) || (script == NULL)) {
- dom_string_unref(mimetype);
- return DOM_HUBBUB_OK; /* no contents, skip */
- }
-
- nscript = html_process_new_script(c, HTML_STYLESHEET_INTERNAL);
- if (nscript == NULL) {
- dom_string_unref(mimetype);
- dom_string_unref(script);
- goto html_process_script_no_memory;
- }
-
- nscript->data.internal = script;
- nscript->mimetype = mimetype;
- nscript->already_started = true;
-
- /* charset (encoding) */
-
- /* ensure script handler for content type */
- dom_string_intern(mimetype, &lwcmimetype);
- script_handler = select_script_handler(content_factory_type_from_mime_type(lwcmimetype));
- lwc_string_unref(lwcmimetype);
-
- if (script_handler != NULL) {
- script_handler(c->jscontext,
- dom_string_data(script),
- dom_string_byte_length(script));
- }
-
-
+ err = exec_inline_script(c, node, mimetype);
} else {
- /* script with a src tag */
- nserror ns_error;
- nsurl *joined;
- hlcache_child_context child;
+ err = exec_src_script(c, node, mimetype, src);
+ dom_string_unref(src);
+ }
+ dom_string_unref(mimetype);
- nscript = html_process_new_script(c, HTML_STYLESHEET_EXTERNAL);
- if (nscript == NULL) {
- dom_string_unref(src);
- dom_string_unref(mimetype);
- goto html_process_script_no_memory;
- }
+ return err;
+}
- /* charset (encoding) */
+void html_free_scripts(html_content *html)
+{
+ unsigned int i;
- ns_error = nsurl_join(c->base_url, dom_string_data(src), &joined);
- dom_string_unref(src);
- if (ns_error != NSERROR_OK) {
- dom_string_unref(mimetype);
- goto html_process_script_no_memory;
+ for (i = 0; i != html->scripts_count; i++) {
+ if (html->scripts[i].mimetype != NULL) {
+ dom_string_unref(html->scripts[i].mimetype);
}
- nscript->mimetype = mimetype; /* keep reference to mimetype */
-
- LOG(("script %i '%s'", c->scripts_count, nsurl_access(joined)));
+ if ((html->scripts[i].type == HTML_SCRIPT_INLINE) &&
+ (html->scripts[i].data.string != NULL)) {
- child.charset = c->encoding;
- child.quirks = c->base.quirks;
+ dom_string_unref(html->scripts[i].data.string);
- ns_error = hlcache_handle_retrieve(joined,
- 0,
- content_get_url(&c->base),
- NULL,
- html_convert_script_callback,
- c,
- &child,
- CONTENT_SCRIPT,
- &nscript->data.external);
+ } else if ((html->scripts[i].type == HTML_SCRIPT_SYNC) &&
+ (html->scripts[i].data.handle != NULL)) {
- nsurl_unref(joined);
+ hlcache_handle_release(html->scripts[i].data.handle);
- if (ns_error != NSERROR_OK) {
- goto html_process_script_no_memory;
}
-
- c->base.active++; /* ensure base content knows the fetch is active */
- LOG(("%d fetches active", c->base.active));
-
}
- html_scripts_exec(c);
-
- return DOM_HUBBUB_OK;
-
-html_process_script_no_memory:
- msg_data.error = messages_get("NoMemory");
- content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
- return DOM_HUBBUB_NOMEM;
+ free(html->scripts);
}
diff --git a/test/js/assorted.html b/test/js/assorted.html
new file mode 100644
index 0000000..bb3d477
--- /dev/null
+++ b/test/js/assorted.html
@@ -0,0 +1,34 @@
+<html>
+<head><title>moo</title></head>
+<body>
+<script>
+var tree = (this ===window)
+console.log(tree);
+var string = "50";
+
+console.log(string + 100); // 50100
+console.log(+string + 100); // 150
+
+string = parseInt(string, 10);
+console.log(string + 100); // 150
+var binary = parseInt("110010", 2);
+console.log(binary); // 50
+
+function doSomething(param) {
+ param = param.toUpperCase(); // param is now a local variable
+ console.log(param);
+}
+var string = "test";
+
+/* note that string will be passed in by reference */
+doSomething(string); // TEST
+console.log(string); // test
+
+document.write("<p>Hello World!<p>");
+</script>
+<p>one</p>
+<script>document.write("<scr" +"ipt>document.write(\"Goodbye Cruel World\");</scri" + "pt>");</script>
+</script>
+<p>hi</p>
+</body>
+</html>
diff --git a/test/js/index.html b/test/js/index.html
new file mode 100644
index 0000000..22f602e
--- /dev/null
+++ b/test/js/index.html
@@ -0,0 +1,17 @@
+<html>
+<head>
+<title>Script Tests</title>
+<link rel="stylesheet" type="text/css" href="tst.css">
+</head>
+<body>
+<h1>Script Tests</h1>
+<ul>
+<li><a href="assorted.html">Assorted</a></li>
+<li><a href="inline-doc-write-simple.html">Simple docuemnt write</a></li>
+<li><a href="inline-doc-write.html">Script within inline script</a></li>
+<li><a href="sync-script.html">External syncronous script (with css)</a></li>
+
+
+</ul>
+</body>
+</html>
diff --git a/test/js/inline-doc-write-simple.html b/test/js/inline-doc-write-simple.html
new file mode 100644
index 0000000..17ad8ee
--- /dev/null
+++ b/test/js/inline-doc-write-simple.html
@@ -0,0 +1,11 @@
+<html>
+<head><title>Inline Script Simple Document Write</title></head>
+<body>
+<h1>Inline Script Simple Document Write</h1>
+<p>Before</p>
+<script>
+document.write("<p>Hello World!<p>");
+</script>
+<p>Afterwards</p>
+</body>
+</html>
diff --git a/test/js/inline-doc-write.html b/test/js/inline-doc-write.html
new file mode 100644
index 0000000..290256d
--- /dev/null
+++ b/test/js/inline-doc-write.html
@@ -0,0 +1,13 @@
+<html>
+<head>
+<title>Inline Docuemnt Write Test</title>
+<link rel="stylesheet" type="text/css" href="tst.css">
+</head>
+<body>
+<h1>Inline Document Write Test</h1>
+<p>Before</p>
+<script>document.write("<scr" +"ipt>document.write(\"Goodbye Cruel World\");</scri" + "pt>");</script>
+</script>
+<p>Afterwards</p>
+</body>
+</html>
diff --git a/test/js/sync-script.html b/test/js/sync-script.html
new file mode 100644
index 0000000..e234fb4
--- /dev/null
+++ b/test/js/sync-script.html
@@ -0,0 +1,12 @@
+<html>
+<head>
+<title>Sync script Test</title>
+<link rel="stylesheet" type="text/css" href="tst.css">
+</head>
+<body>
+<h1>Sync script Test</h1>
+<p>Before</p>
+<script src="tst.js"></script>
+<p>Afterwards</p>
+</body>
+</html>
diff --git a/test/js/tst.css b/test/js/tst.css
new file mode 100644
index 0000000..6069f24
--- /dev/null
+++ b/test/js/tst.css
@@ -0,0 +1 @@
+h1 { color:red; }
diff --git a/test/js/tst.js b/test/js/tst.js
new file mode 100644
index 0000000..10e3b9c
--- /dev/null
+++ b/test/js/tst.js
@@ -0,0 +1 @@
+document.write("<script>document.write(\"Hello World\");</script>");
diff --git a/utils/corestrings.c b/utils/corestrings.c
index 396e86e..af87ce2 100644
--- a/utils/corestrings.c
+++ b/utils/corestrings.c
@@ -112,6 +112,7 @@ lwc_string *corestring_lwc__top;
dom_string *corestring_dom_a;
dom_string *corestring_dom_align;
dom_string *corestring_dom_area;
+dom_string *corestring_dom_async;
dom_string *corestring_dom_background;
dom_string *corestring_dom_bgcolor;
dom_string *corestring_dom_border;
@@ -122,6 +123,7 @@ dom_string *corestring_dom_color;
dom_string *corestring_dom_cols;
dom_string *corestring_dom_content;
dom_string *corestring_dom_coords;
+dom_string *corestring_dom_defer;
dom_string *corestring_dom_height;
dom_string *corestring_dom_href;
dom_string *corestring_dom_hreflang;
@@ -258,6 +260,7 @@ void corestrings_fini(void)
CSS_DOM_STRING_UNREF(a);
CSS_DOM_STRING_UNREF(align);
CSS_DOM_STRING_UNREF(area);
+ CSS_DOM_STRING_UNREF(async);
CSS_DOM_STRING_UNREF(background);
CSS_DOM_STRING_UNREF(bgcolor);
CSS_DOM_STRING_UNREF(border);
@@ -268,6 +271,7 @@ void corestrings_fini(void)
CSS_DOM_STRING_UNREF(cols);
CSS_DOM_STRING_UNREF(content);
CSS_DOM_STRING_UNREF(coords);
+ CSS_DOM_STRING_UNREF(defer);
CSS_DOM_STRING_UNREF(height);
CSS_DOM_STRING_UNREF(href);
CSS_DOM_STRING_UNREF(hreflang);
@@ -431,6 +435,7 @@ nserror corestrings_init(void)
CSS_DOM_STRING_INTERN(a);
CSS_DOM_STRING_INTERN(align);
CSS_DOM_STRING_INTERN(area);
+ CSS_DOM_STRING_INTERN(async);
CSS_DOM_STRING_INTERN(background);
CSS_DOM_STRING_INTERN(bgcolor);
CSS_DOM_STRING_INTERN(border);
@@ -441,6 +446,7 @@ nserror corestrings_init(void)
CSS_DOM_STRING_INTERN(cols);
CSS_DOM_STRING_INTERN(content);
CSS_DOM_STRING_INTERN(coords);
+ CSS_DOM_STRING_INTERN(defer);
CSS_DOM_STRING_INTERN(height);
CSS_DOM_STRING_INTERN(href);
CSS_DOM_STRING_INTERN(hreflang);
diff --git a/utils/corestrings.h b/utils/corestrings.h
index a3bda16..1bcf8ae 100644
--- a/utils/corestrings.h
+++ b/utils/corestrings.h
@@ -118,6 +118,7 @@ struct dom_string;
extern struct dom_string *corestring_dom_a;
extern struct dom_string *corestring_dom_align;
extern struct dom_string *corestring_dom_area;
+extern struct dom_string *corestring_dom_async;
extern struct dom_string *corestring_dom_background;
extern struct dom_string *corestring_dom_bgcolor;
extern struct dom_string *corestring_dom_border;
@@ -128,6 +129,7 @@ extern struct dom_string *corestring_dom_color;
extern struct dom_string *corestring_dom_cols;
extern struct dom_string *corestring_dom_content;
extern struct dom_string *corestring_dom_coords;
+extern struct dom_string *corestring_dom_defer;
extern struct dom_string *corestring_dom_height;
extern struct dom_string *corestring_dom_href;
extern struct dom_string *corestring_dom_hreflang;
--
NetSurf Browser
11 years, 1 month
netsurf: branch vince/script-async updated. c0aaf31f5a9a65808d8b7af92434608135ccc752
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/c0aaf31f5a9a65808d8b7...
...commit http://git.netsurf-browser.org/netsurf.git/commit/c0aaf31f5a9a65808d8b7af...
...tree http://git.netsurf-browser.org/netsurf.git/tree/c0aaf31f5a9a65808d8b7af92...
The branch, vince/script-async has been updated
via c0aaf31f5a9a65808d8b7af92434608135ccc752 (commit)
via d763e57d30dc8c68309c5b35f556531cb8346da5 (commit)
from 4182685d1e90e082407a8e40a0b1db76cf9fbea2 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/c0aaf31f5a9a65808d8...
commit c0aaf31f5a9a65808d8b7af92434608135ccc752
Author: Vincent Sanders <vince(a)netsurf-browser.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
fix global handling
diff --git a/javascript/jsapi.h b/javascript/jsapi.h
index cf099cc..a44323f 100644
--- a/javascript/jsapi.h
+++ b/javascript/jsapi.h
@@ -79,7 +79,6 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx,
if (global == NULL) {
return NULL;
}
- JS_SetGlobalObject(cx, global);
return global;
}
diff --git a/javascript/jsapi/document.c b/javascript/jsapi/document.c
index dfad551..bb5019c 100644
--- a/javascript/jsapi/document.c
+++ b/javascript/jsapi/document.c
@@ -92,8 +92,10 @@ JSObject *jsapi_new_document(JSContext *cx, JSObject *parent, void *doc_priv)
LOG(("setting content to %p",doc_priv));
/* private pointer to browsing context */
- if (!JS_SetPrivate(cx, doc, doc_priv))
+ if (JS_SetPrivate(cx, doc, doc_priv) != JS_TRUE) {
+ LOG(("failed to set content"));
return NULL;
+ }
return doc;
}
diff --git a/javascript/jsapi/window.c b/javascript/jsapi/window.c
index 06e6cdf..0b7673b 100644
--- a/javascript/jsapi/window.c
+++ b/javascript/jsapi/window.c
@@ -299,8 +299,18 @@ JSObject * jsapi_new_window(JSContext *cx, JSObject *parent, void *win_priv)
return NULL;
}
+ /** @todo reconsider global object handling. future
+ * editions of spidermonkey appear to be removing the
+ * idea of a global so we probably need to handle
+ * global object references internally
+ */
+
+ /* set the contexts global */
+ JS_SetGlobalObject(cx, window);
+
/* Populate the global object with the standard globals, like
- Object and Array. */
+ * Object and Array.
+ */
if (!JS_InitStandardClasses(cx, window)) {
return NULL;
}
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/d763e57d30dc8c68309...
commit d763e57d30dc8c68309c5b35f556531cb8346da5
Author: Vincent Sanders <vince(a)netsurf-browser.org>
Commit: Vincent Sanders <vince(a)netsurf-browser.org>
fix dom parser error return check
diff --git a/render/html_script.c b/render/html_script.c
index 7222f80..f4d80ab 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -483,7 +483,7 @@ exec_src_script(html_content *c,
switch (script_type) {
case HTML_SCRIPT_SYNC:
- ret = DOM_HUBBUB_PAUSED;
+ ret = DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED;
case HTML_SCRIPT_ASYNC:
break;
-----------------------------------------------------------------------
Summary of changes:
javascript/jsapi.h | 1 -
javascript/jsapi/document.c | 4 +++-
javascript/jsapi/window.c | 12 +++++++++++-
render/html_script.c | 2 +-
4 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/javascript/jsapi.h b/javascript/jsapi.h
index cf099cc..a44323f 100644
--- a/javascript/jsapi.h
+++ b/javascript/jsapi.h
@@ -79,7 +79,6 @@ JS_NewCompartmentAndGlobalObject(JSContext *cx,
if (global == NULL) {
return NULL;
}
- JS_SetGlobalObject(cx, global);
return global;
}
diff --git a/javascript/jsapi/document.c b/javascript/jsapi/document.c
index dfad551..bb5019c 100644
--- a/javascript/jsapi/document.c
+++ b/javascript/jsapi/document.c
@@ -92,8 +92,10 @@ JSObject *jsapi_new_document(JSContext *cx, JSObject *parent, void *doc_priv)
LOG(("setting content to %p",doc_priv));
/* private pointer to browsing context */
- if (!JS_SetPrivate(cx, doc, doc_priv))
+ if (JS_SetPrivate(cx, doc, doc_priv) != JS_TRUE) {
+ LOG(("failed to set content"));
return NULL;
+ }
return doc;
}
diff --git a/javascript/jsapi/window.c b/javascript/jsapi/window.c
index 06e6cdf..0b7673b 100644
--- a/javascript/jsapi/window.c
+++ b/javascript/jsapi/window.c
@@ -299,8 +299,18 @@ JSObject * jsapi_new_window(JSContext *cx, JSObject *parent, void *win_priv)
return NULL;
}
+ /** @todo reconsider global object handling. future
+ * editions of spidermonkey appear to be removing the
+ * idea of a global so we probably need to handle
+ * global object references internally
+ */
+
+ /* set the contexts global */
+ JS_SetGlobalObject(cx, window);
+
/* Populate the global object with the standard globals, like
- Object and Array. */
+ * Object and Array.
+ */
if (!JS_InitStandardClasses(cx, window)) {
return NULL;
}
diff --git a/render/html_script.c b/render/html_script.c
index 7222f80..f4d80ab 100644
--- a/render/html_script.c
+++ b/render/html_script.c
@@ -483,7 +483,7 @@ exec_src_script(html_content *c,
switch (script_type) {
case HTML_SCRIPT_SYNC:
- ret = DOM_HUBBUB_PAUSED;
+ ret = DOM_HUBBUB_HUBBUB_ERR | HUBBUB_PAUSED;
case HTML_SCRIPT_ASYNC:
break;
--
NetSurf Browser
11 years, 1 month
netsurf: branch master updated. 90b0c48bb216cef4f3aafbc14565f203a3f6861c
by NetSurf Browser Project
Gitweb links:
...log http://git.netsurf-browser.org/netsurf.git/shortlog/90b0c48bb216cef4f3aaf...
...commit http://git.netsurf-browser.org/netsurf.git/commit/90b0c48bb216cef4f3aafbc...
...tree http://git.netsurf-browser.org/netsurf.git/tree/90b0c48bb216cef4f3aafbc14...
The branch, master has been updated
via 90b0c48bb216cef4f3aafbc14565f203a3f6861c (commit)
via f6436d54c8aa367828433a59ba16ffbeac8444c3 (commit)
via 8db6d74bcb2c04285378e9eaa863dc4de5d5e4ba (commit)
from c48d7fa2da7331c482fe5e2298d2a08aa41de7d9 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/90b0c48bb216cef4f3a...
commit 90b0c48bb216cef4f3aafbc14565f203a3f6861c
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Split out common code to generate a font style for text input widget.
diff --git a/framebuffer/fbtk/text.c b/framebuffer/fbtk/text.c
index f50a5ad..2796814 100644
--- a/framebuffer/fbtk/text.c
+++ b/framebuffer/fbtk/text.c
@@ -50,6 +50,19 @@
/* Convert pixels to points, assuming a DPI of 90 */
#define px_to_pt(x) (((x) * 72) / FBTK_DPI)
+/* Get a font style for a text input */
+static inline void
+fb_text_font_style(fbtk_widget_t *widget, int font_height,
+ plot_font_style_t *font_style)
+{
+ font_style->family = PLOT_FONT_FAMILY_SANS_SERIF;
+ font_style->size = px_to_pt(font_height) * FONT_SIZE_SCALE;
+ font_style->weight = 400;
+ font_style->flags = FONTF_NONE;
+ font_style->background = widget->bg;
+ font_style->foreground = widget->fg;
+}
+
/** Text redraw callback.
*
* Called when a text widget requires redrawing.
@@ -94,13 +107,7 @@ fb_redraw_text(fbtk_widget_t *widget, fbtk_callback_info *cbi )
if (widget->u.text.text != NULL) {
fh = widget->height - padding - padding;
- font_style.family = PLOT_FONT_FAMILY_SANS_SERIF;
- font_style.size = px_to_pt(fh) * FONT_SIZE_SCALE;
- font_style.weight = 400;
- font_style.flags = FONTF_NONE;
- font_style.background = widget->bg;
- font_style.foreground = widget->fg;
-
+ fb_text_font_style(widget, fh, &font_style);
FBTK_LOG(("plotting %p at %d,%d %d,%d w/h %d,%d font h %d padding %d",
widget, bbox.x0, bbox.y0, bbox.x1, bbox.y1,
widget->width, widget->height, fh, padding));
@@ -192,12 +199,7 @@ fb_redraw_text_button(fbtk_widget_t *widget, fbtk_callback_info *cbi )
if (widget->u.text.text != NULL) {
fh = widget->height - border - border;
- font_style.family = PLOT_FONT_FAMILY_SANS_SERIF;
- font_style.size = px_to_pt(fh) * FONT_SIZE_SCALE;
- font_style.weight = 400;
- font_style.flags = FONTF_NONE;
- font_style.background = widget->bg;
- font_style.foreground = widget->fg;
+ fb_text_font_style(widget, fh, &font_style);
LOG(("plotting %p at %d,%d %d,%d w/h %d,%d font h %d border %d",
widget, bbox.x0, bbox.y0, bbox.x1, bbox.y1,
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/f6436d54c8aa3678284...
commit f6436d54c8aa367828433a59ba16ffbeac8444c3
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add caret to browser window widgets. Caret now shows when editing forms.
diff --git a/framebuffer/gui.c b/framebuffer/gui.c
index 10c2e46..216791d 100644
--- a/framebuffer/gui.c
+++ b/framebuffer/gui.c
@@ -308,12 +308,14 @@ fb_redraw(fbtk_widget_t *widget,
{
int x;
int y;
+ int caret_x, caret_y, caret_h;
struct rect clip;
struct redraw_context ctx = {
.interactive = true,
.background_images = true,
.plot = &fb_plotters
};
+ nsfb_t *nsfb = fbtk_get_nsfb(widget);
LOG(("%d,%d to %d,%d",
bwidget->redraw_box.x0,
@@ -330,7 +332,7 @@ fb_redraw(fbtk_widget_t *widget,
bwidget->redraw_box.x0 += x;
bwidget->redraw_box.x1 += x;
- nsfb_claim(fbtk_get_nsfb(widget), &bwidget->redraw_box);
+ nsfb_claim(nsfb, &bwidget->redraw_box);
/* redraw bounding box is relative to window */
clip.x0 = bwidget->redraw_box.x0;
@@ -343,6 +345,23 @@ fb_redraw(fbtk_widget_t *widget,
(y - bwidget->scrolly) / bw->scale,
&clip, &ctx);
+ if (fbtk_get_caret(widget, &caret_x, &caret_y, &caret_h)) {
+ /* This widget has caret, so render it */
+ nsfb_bbox_t line;
+ nsfb_plot_pen_t pen;
+
+ line.x0 = x - bwidget->scrollx + caret_x;
+ line.y0 = y - bwidget->scrolly + caret_y;
+ line.x1 = x - bwidget->scrollx + caret_x;
+ line.y1 = y - bwidget->scrolly + caret_y + caret_h;
+
+ pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
+ pen.stroke_width = 1;
+ pen.stroke_colour = 0xFF0000FF;
+
+ nsfb_plot_line(nsfb, &line, &pen);
+ }
+
nsfb_update(fbtk_get_nsfb(widget), &bwidget->redraw_box);
bwidget->redraw_box.y0 = bwidget->redraw_box.x0 = INT_MAX;
@@ -1483,11 +1502,48 @@ gui_window_stop_throbber(struct gui_window *gw)
void
gui_window_place_caret(struct gui_window *g, int x, int y, int height)
{
+ struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser);
+ int c_x, c_y, c_h;
+
+ if (fbtk_get_caret(g->browser, &c_x, &c_y, &c_h)) {
+ /* browser window already had caret:
+ * redraw its area to remove it first */
+ fb_queue_redraw(g->browser,
+ c_x - bwidget->scrollx,
+ c_y - bwidget->scrolly,
+ c_x + 1 - bwidget->scrollx,
+ c_y + c_h - bwidget->scrolly);
+ }
+
+ /* set new pos */
+ fbtk_set_caret(g->browser, true, x, y, height);
+
+ /* redraw new caret pos */
+ fb_queue_redraw(g->browser,
+ x - bwidget->scrollx,
+ y - bwidget->scrolly,
+ x + 1 - bwidget->scrollx,
+ y + height - bwidget->scrolly);
}
void
gui_window_remove_caret(struct gui_window *g)
{
+ struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser);
+ int c_x, c_y, c_h;
+
+ if (fbtk_get_caret(g->browser, &c_x, &c_y, &c_h)) {
+ /* browser window already had caret:
+ * redraw its area to remove it first */
+ fb_queue_redraw(g->browser,
+ c_x - bwidget->scrollx,
+ c_y - bwidget->scrolly,
+ c_x + 1 - bwidget->scrollx,
+ c_y + c_h - bwidget->scrolly);
+ }
+
+ /* remove caret */
+ fbtk_set_caret(g->browser, false, 0, 0, 0);
}
void
commitdiff http://git.netsurf-browser.org/netsurf.git/commitdiff/8db6d74bcb2c0428537...
commit 8db6d74bcb2c04285378e9eaa863dc4de5d5e4ba
Author: Michael Drake <tlsa(a)netsurf-browser.org>
Commit: Michael Drake <tlsa(a)netsurf-browser.org>
Add basic awareness of text input caret to ftbk and functions to get/set caret pos.
diff --git a/framebuffer/fbtk.h b/framebuffer/fbtk.h
index e587957..131ae65 100644
--- a/framebuffer/fbtk.h
+++ b/framebuffer/fbtk.h
@@ -247,6 +247,16 @@ int fbtk_get_height(fbtk_widget_t *widget);
*/
bool fbtk_get_bbox(fbtk_widget_t *widget, struct nsfb_bbox_s *bbox);
+/** Get a widget caret pos, if it owns caret.
+ *
+ * @param widget The widget to inspect.
+ * @param x If widget has caret, returns x-coord of caret within widget
+ * @param y If widget has caret, returns y-coord of caret within widget
+ * @param height If widget has caret, returns caret height
+ * @return true iff widget has caret
+ */
+bool fbtk_get_caret(fbtk_widget_t *widget, int *x, int *y, int *height);
+
/******************* Widget Manipulation **********************/
@@ -255,6 +265,16 @@ bool fbtk_get_bbox(fbtk_widget_t *widget, struct nsfb_bbox_s *bbox);
*/
bool fbtk_set_pos_and_size(fbtk_widget_t *widget, int x, int y, int width, int height);
+/** Set caret owner and position
+ *
+ * @param widget widget to give caret to, or ensure caret is released from
+ * @param set true: caret to be set for widget, false: caret to be released
+ * @param x x-coordinate of caret top
+ * @param y y-coordinate of caret top
+ * @param height height of caret
+ */
+void fbtk_set_caret(fbtk_widget_t *widget, bool set, int x, int y, int height);
+
/** Map a widget and request it is redrawn.
*/
int fbtk_set_mapping(fbtk_widget_t *widget, bool mapped);
diff --git a/framebuffer/fbtk/fbtk.c b/framebuffer/fbtk/fbtk.c
index db298eb..8e8bc11 100644
--- a/framebuffer/fbtk/fbtk.c
+++ b/framebuffer/fbtk/fbtk.c
@@ -220,6 +220,28 @@ fbtk_set_pos_and_size(fbtk_widget_t *widget,
return false;
}
+
+/* exported function docuemnted in fbtk.h */
+void
+fbtk_set_caret(fbtk_widget_t *widget, bool set,
+ int x, int y, int height)
+{
+ fbtk_widget_t *root;
+
+ assert(widget != NULL);
+ root = fbtk_get_root_widget(widget);
+
+ if (set) {
+ root->u.root.caret.owner = widget;
+ root->u.root.caret.x = x;
+ root->u.root.caret.y = y;
+ root->u.root.caret.height = height;
+
+ } else {
+ root->u.root.caret.owner = NULL;
+ }
+}
+
/* exported function documented in fbtk.h */
int
fbtk_destroy_widget(fbtk_widget_t *widget)
@@ -429,6 +451,27 @@ fbtk_get_bbox(fbtk_widget_t *widget, nsfb_bbox_t *bbox)
return true;
}
+bool
+fbtk_get_caret(fbtk_widget_t *widget, int *x, int *y, int *height)
+{
+ fbtk_widget_t *root = fbtk_get_root_widget(widget);
+
+ if (root->u.root.caret.owner == widget) {
+ *x = root->u.root.caret.x;
+ *y = root->u.root.caret.y;
+ *height = root->u.root.caret.height;
+
+ return true;
+
+ } else {
+ *x = 0;
+ *y = 0;
+ *height = 0;
+
+ return false;
+ }
+}
+
/* exported function documented in fbtk.h */
fbtk_widget_t *
fbtk_get_widget_at(fbtk_widget_t *nwid, int x, int y)
@@ -727,6 +770,7 @@ fbtk_init(nsfb_t *fb)
root->type = FB_WIDGET_TYPE_ROOT;
root->u.root.fb = fb;
+ root->u.root.caret.owner = NULL;
nsfb_get_geometry(fb, &root->width, &root->height, NULL);
diff --git a/framebuffer/fbtk/widget.h b/framebuffer/fbtk/widget.h
index 060999b..e31fa11 100644
--- a/framebuffer/fbtk/widget.h
+++ b/framebuffer/fbtk/widget.h
@@ -161,6 +161,14 @@ struct fbtk_widget_s {
struct fbtk_widget_s *prev; /* previous widget pointer wasin */
struct fbtk_widget_s *grabbed; /* widget that has grabbed pointer movement. */
struct fbtk_widget_s *input;
+
+ /* caret */
+ struct {
+ struct fbtk_widget_s *owner; /* widget / NULL */
+ int x; /* relative to owner */
+ int y; /* relative to owner */
+ int height;
+ } caret;
} root;
/* bitmap */
-----------------------------------------------------------------------
Summary of changes:
framebuffer/fbtk.h | 20 +++++++++++++++
framebuffer/fbtk/fbtk.c | 44 ++++++++++++++++++++++++++++++++++
framebuffer/fbtk/text.c | 28 +++++++++++----------
framebuffer/fbtk/widget.h | 8 ++++++
framebuffer/gui.c | 58 ++++++++++++++++++++++++++++++++++++++++++++-
5 files changed, 144 insertions(+), 14 deletions(-)
diff --git a/framebuffer/fbtk.h b/framebuffer/fbtk.h
index e587957..131ae65 100644
--- a/framebuffer/fbtk.h
+++ b/framebuffer/fbtk.h
@@ -247,6 +247,16 @@ int fbtk_get_height(fbtk_widget_t *widget);
*/
bool fbtk_get_bbox(fbtk_widget_t *widget, struct nsfb_bbox_s *bbox);
+/** Get a widget caret pos, if it owns caret.
+ *
+ * @param widget The widget to inspect.
+ * @param x If widget has caret, returns x-coord of caret within widget
+ * @param y If widget has caret, returns y-coord of caret within widget
+ * @param height If widget has caret, returns caret height
+ * @return true iff widget has caret
+ */
+bool fbtk_get_caret(fbtk_widget_t *widget, int *x, int *y, int *height);
+
/******************* Widget Manipulation **********************/
@@ -255,6 +265,16 @@ bool fbtk_get_bbox(fbtk_widget_t *widget, struct nsfb_bbox_s *bbox);
*/
bool fbtk_set_pos_and_size(fbtk_widget_t *widget, int x, int y, int width, int height);
+/** Set caret owner and position
+ *
+ * @param widget widget to give caret to, or ensure caret is released from
+ * @param set true: caret to be set for widget, false: caret to be released
+ * @param x x-coordinate of caret top
+ * @param y y-coordinate of caret top
+ * @param height height of caret
+ */
+void fbtk_set_caret(fbtk_widget_t *widget, bool set, int x, int y, int height);
+
/** Map a widget and request it is redrawn.
*/
int fbtk_set_mapping(fbtk_widget_t *widget, bool mapped);
diff --git a/framebuffer/fbtk/fbtk.c b/framebuffer/fbtk/fbtk.c
index db298eb..8e8bc11 100644
--- a/framebuffer/fbtk/fbtk.c
+++ b/framebuffer/fbtk/fbtk.c
@@ -220,6 +220,28 @@ fbtk_set_pos_and_size(fbtk_widget_t *widget,
return false;
}
+
+/* exported function docuemnted in fbtk.h */
+void
+fbtk_set_caret(fbtk_widget_t *widget, bool set,
+ int x, int y, int height)
+{
+ fbtk_widget_t *root;
+
+ assert(widget != NULL);
+ root = fbtk_get_root_widget(widget);
+
+ if (set) {
+ root->u.root.caret.owner = widget;
+ root->u.root.caret.x = x;
+ root->u.root.caret.y = y;
+ root->u.root.caret.height = height;
+
+ } else {
+ root->u.root.caret.owner = NULL;
+ }
+}
+
/* exported function documented in fbtk.h */
int
fbtk_destroy_widget(fbtk_widget_t *widget)
@@ -429,6 +451,27 @@ fbtk_get_bbox(fbtk_widget_t *widget, nsfb_bbox_t *bbox)
return true;
}
+bool
+fbtk_get_caret(fbtk_widget_t *widget, int *x, int *y, int *height)
+{
+ fbtk_widget_t *root = fbtk_get_root_widget(widget);
+
+ if (root->u.root.caret.owner == widget) {
+ *x = root->u.root.caret.x;
+ *y = root->u.root.caret.y;
+ *height = root->u.root.caret.height;
+
+ return true;
+
+ } else {
+ *x = 0;
+ *y = 0;
+ *height = 0;
+
+ return false;
+ }
+}
+
/* exported function documented in fbtk.h */
fbtk_widget_t *
fbtk_get_widget_at(fbtk_widget_t *nwid, int x, int y)
@@ -727,6 +770,7 @@ fbtk_init(nsfb_t *fb)
root->type = FB_WIDGET_TYPE_ROOT;
root->u.root.fb = fb;
+ root->u.root.caret.owner = NULL;
nsfb_get_geometry(fb, &root->width, &root->height, NULL);
diff --git a/framebuffer/fbtk/text.c b/framebuffer/fbtk/text.c
index f50a5ad..2796814 100644
--- a/framebuffer/fbtk/text.c
+++ b/framebuffer/fbtk/text.c
@@ -50,6 +50,19 @@
/* Convert pixels to points, assuming a DPI of 90 */
#define px_to_pt(x) (((x) * 72) / FBTK_DPI)
+/* Get a font style for a text input */
+static inline void
+fb_text_font_style(fbtk_widget_t *widget, int font_height,
+ plot_font_style_t *font_style)
+{
+ font_style->family = PLOT_FONT_FAMILY_SANS_SERIF;
+ font_style->size = px_to_pt(font_height) * FONT_SIZE_SCALE;
+ font_style->weight = 400;
+ font_style->flags = FONTF_NONE;
+ font_style->background = widget->bg;
+ font_style->foreground = widget->fg;
+}
+
/** Text redraw callback.
*
* Called when a text widget requires redrawing.
@@ -94,13 +107,7 @@ fb_redraw_text(fbtk_widget_t *widget, fbtk_callback_info *cbi )
if (widget->u.text.text != NULL) {
fh = widget->height - padding - padding;
- font_style.family = PLOT_FONT_FAMILY_SANS_SERIF;
- font_style.size = px_to_pt(fh) * FONT_SIZE_SCALE;
- font_style.weight = 400;
- font_style.flags = FONTF_NONE;
- font_style.background = widget->bg;
- font_style.foreground = widget->fg;
-
+ fb_text_font_style(widget, fh, &font_style);
FBTK_LOG(("plotting %p at %d,%d %d,%d w/h %d,%d font h %d padding %d",
widget, bbox.x0, bbox.y0, bbox.x1, bbox.y1,
widget->width, widget->height, fh, padding));
@@ -192,12 +199,7 @@ fb_redraw_text_button(fbtk_widget_t *widget, fbtk_callback_info *cbi )
if (widget->u.text.text != NULL) {
fh = widget->height - border - border;
- font_style.family = PLOT_FONT_FAMILY_SANS_SERIF;
- font_style.size = px_to_pt(fh) * FONT_SIZE_SCALE;
- font_style.weight = 400;
- font_style.flags = FONTF_NONE;
- font_style.background = widget->bg;
- font_style.foreground = widget->fg;
+ fb_text_font_style(widget, fh, &font_style);
LOG(("plotting %p at %d,%d %d,%d w/h %d,%d font h %d border %d",
widget, bbox.x0, bbox.y0, bbox.x1, bbox.y1,
diff --git a/framebuffer/fbtk/widget.h b/framebuffer/fbtk/widget.h
index 060999b..e31fa11 100644
--- a/framebuffer/fbtk/widget.h
+++ b/framebuffer/fbtk/widget.h
@@ -161,6 +161,14 @@ struct fbtk_widget_s {
struct fbtk_widget_s *prev; /* previous widget pointer wasin */
struct fbtk_widget_s *grabbed; /* widget that has grabbed pointer movement. */
struct fbtk_widget_s *input;
+
+ /* caret */
+ struct {
+ struct fbtk_widget_s *owner; /* widget / NULL */
+ int x; /* relative to owner */
+ int y; /* relative to owner */
+ int height;
+ } caret;
} root;
/* bitmap */
diff --git a/framebuffer/gui.c b/framebuffer/gui.c
index 10c2e46..216791d 100644
--- a/framebuffer/gui.c
+++ b/framebuffer/gui.c
@@ -308,12 +308,14 @@ fb_redraw(fbtk_widget_t *widget,
{
int x;
int y;
+ int caret_x, caret_y, caret_h;
struct rect clip;
struct redraw_context ctx = {
.interactive = true,
.background_images = true,
.plot = &fb_plotters
};
+ nsfb_t *nsfb = fbtk_get_nsfb(widget);
LOG(("%d,%d to %d,%d",
bwidget->redraw_box.x0,
@@ -330,7 +332,7 @@ fb_redraw(fbtk_widget_t *widget,
bwidget->redraw_box.x0 += x;
bwidget->redraw_box.x1 += x;
- nsfb_claim(fbtk_get_nsfb(widget), &bwidget->redraw_box);
+ nsfb_claim(nsfb, &bwidget->redraw_box);
/* redraw bounding box is relative to window */
clip.x0 = bwidget->redraw_box.x0;
@@ -343,6 +345,23 @@ fb_redraw(fbtk_widget_t *widget,
(y - bwidget->scrolly) / bw->scale,
&clip, &ctx);
+ if (fbtk_get_caret(widget, &caret_x, &caret_y, &caret_h)) {
+ /* This widget has caret, so render it */
+ nsfb_bbox_t line;
+ nsfb_plot_pen_t pen;
+
+ line.x0 = x - bwidget->scrollx + caret_x;
+ line.y0 = y - bwidget->scrolly + caret_y;
+ line.x1 = x - bwidget->scrollx + caret_x;
+ line.y1 = y - bwidget->scrolly + caret_y + caret_h;
+
+ pen.stroke_type = NFSB_PLOT_OPTYPE_SOLID;
+ pen.stroke_width = 1;
+ pen.stroke_colour = 0xFF0000FF;
+
+ nsfb_plot_line(nsfb, &line, &pen);
+ }
+
nsfb_update(fbtk_get_nsfb(widget), &bwidget->redraw_box);
bwidget->redraw_box.y0 = bwidget->redraw_box.x0 = INT_MAX;
@@ -1483,11 +1502,48 @@ gui_window_stop_throbber(struct gui_window *gw)
void
gui_window_place_caret(struct gui_window *g, int x, int y, int height)
{
+ struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser);
+ int c_x, c_y, c_h;
+
+ if (fbtk_get_caret(g->browser, &c_x, &c_y, &c_h)) {
+ /* browser window already had caret:
+ * redraw its area to remove it first */
+ fb_queue_redraw(g->browser,
+ c_x - bwidget->scrollx,
+ c_y - bwidget->scrolly,
+ c_x + 1 - bwidget->scrollx,
+ c_y + c_h - bwidget->scrolly);
+ }
+
+ /* set new pos */
+ fbtk_set_caret(g->browser, true, x, y, height);
+
+ /* redraw new caret pos */
+ fb_queue_redraw(g->browser,
+ x - bwidget->scrollx,
+ y - bwidget->scrolly,
+ x + 1 - bwidget->scrollx,
+ y + height - bwidget->scrolly);
}
void
gui_window_remove_caret(struct gui_window *g)
{
+ struct browser_widget_s *bwidget = fbtk_get_userpw(g->browser);
+ int c_x, c_y, c_h;
+
+ if (fbtk_get_caret(g->browser, &c_x, &c_y, &c_h)) {
+ /* browser window already had caret:
+ * redraw its area to remove it first */
+ fb_queue_redraw(g->browser,
+ c_x - bwidget->scrollx,
+ c_y - bwidget->scrolly,
+ c_x + 1 - bwidget->scrollx,
+ c_y + c_h - bwidget->scrolly);
+ }
+
+ /* remove caret */
+ fbtk_set_caret(g->browser, false, 0, 0, 0);
}
void
--
NetSurf Browser
11 years, 1 month