From a706c69bf416beedc71e386fe344761d5d417cd1 Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Sat, 2 May 2020 20:47:53 +0100 Subject: improve html content handler private headers --- content/handlers/html/box_construct.c | 2 +- content/handlers/html/box_inspect.c | 2 +- content/handlers/html/box_manipulate.c | 6 +- content/handlers/html/box_normalise.c | 4 +- content/handlers/html/box_special.c | 2 +- content/handlers/html/box_textarea.c | 3 +- content/handlers/html/css.c | 47 ++- content/handlers/html/css.h | 109 ++++++ content/handlers/html/css_fetcher.c | 2 +- content/handlers/html/form.c | 6 +- content/handlers/html/forms.c | 2 +- content/handlers/html/html.c | 13 +- content/handlers/html/html_internal.h | 413 ----------------------- content/handlers/html/imagemap.c | 2 +- content/handlers/html/interaction.c | 2 +- content/handlers/html/interaction.h | 46 +++ content/handlers/html/layout.c | 2 +- content/handlers/html/object.c | 3 +- content/handlers/html/private.h | 386 +++++++++++++++++++++ content/handlers/html/redraw.c | 2 +- content/handlers/html/redraw_border.c | 2 +- content/handlers/html/script.c | 2 +- content/handlers/html/search.c | 2 +- content/handlers/javascript/duktape/Document.bnd | 2 +- content/handlers/javascript/duktape/Window.bnd | 2 +- 25 files changed, 609 insertions(+), 455 deletions(-) create mode 100644 content/handlers/html/css.h delete mode 100644 content/handlers/html/html_internal.h create mode 100644 content/handlers/html/private.h (limited to 'content/handlers') diff --git a/content/handlers/html/box_construct.c b/content/handlers/html/box_construct.c index f1ea71d3b..3d100176a 100644 --- a/content/handlers/html/box_construct.c +++ b/content/handlers/html/box_construct.c @@ -37,7 +37,7 @@ #include "css/select.h" #include "desktop/gui_internal.h" -#include "html/html_internal.h" +#include "html/private.h" #include "html/object.h" #include "html/box.h" #include "html/box_manipulate.h" diff --git a/content/handlers/html/box_inspect.c b/content/handlers/html/box_inspect.c index 268ed3d95..df9a1b4e2 100644 --- a/content/handlers/html/box_inspect.c +++ b/content/handlers/html/box_inspect.c @@ -34,9 +34,9 @@ #include "css/dump.h" #include "desktop/scrollbar.h" +#include "html/private.h" #include "html/box.h" #include "html/box_inspect.h" -#include "html/html_internal.h" /** * Direction to move in a box-tree walk diff --git a/content/handlers/html/box_manipulate.c b/content/handlers/html/box_manipulate.c index 0bc1c9fea..d88e360a1 100644 --- a/content/handlers/html/box_manipulate.c +++ b/content/handlers/html/box_manipulate.c @@ -32,11 +32,11 @@ #include "netsurf/mouse.h" #include "desktop/scrollbar.h" -#include "html/box.h" -#include "html/box_manipulate.h" +#include "html/private.h" #include "html/form_internal.h" -#include "html/html_internal.h" #include "html/interaction.h" +#include "html/box.h" +#include "html/box_manipulate.h" /** diff --git a/content/handlers/html/box_normalise.c b/content/handlers/html/box_normalise.c index fbdb6cd05..b7032da55 100644 --- a/content/handlers/html/box_normalise.c +++ b/content/handlers/html/box_normalise.c @@ -32,11 +32,11 @@ #include "utils/errors.h" #include "css/select.h" +#include "html/private.h" +#include "html/table.h" #include "html/box.h" #include "html/box_manipulate.h" #include "html/box_normalise.h" -#include "html/html_internal.h" -#include "html/table.h" /* Define to enable box normalise debug */ #undef BOX_NORMALISE_DEBUG diff --git a/content/handlers/html/box_special.c b/content/handlers/html/box_special.c index 2d3bd054b..06f2f91d6 100644 --- a/content/handlers/html/box_special.c +++ b/content/handlers/html/box_special.c @@ -41,7 +41,7 @@ #include "desktop/frame_types.h" #include "html/html.h" -#include "html/html_internal.h" +#include "html/private.h" #include "html/object.h" #include "html/box.h" #include "html/box_manipulate.h" diff --git a/content/handlers/html/box_textarea.c b/content/handlers/html/box_textarea.c index 476773f29..1038be31a 100644 --- a/content/handlers/html/box_textarea.c +++ b/content/handlers/html/box_textarea.c @@ -31,7 +31,8 @@ #include "desktop/textarea.h" #include "desktop/gui_internal.h" -#include "html/html_internal.h" +#include "html/private.h" +#include "html/interaction.h" #include "html/box.h" #include "html/box_inspect.h" #include "html/box_textarea.h" diff --git a/content/handlers/html/css.c b/content/handlers/html/css.c index 23d51f1be..575898134 100644 --- a/content/handlers/html/css.c +++ b/content/handlers/html/css.c @@ -42,13 +42,17 @@ #include "desktop/gui_internal.h" #include "html/html.h" -#include "html/html_internal.h" +#include "html/private.h" +#include "html/css.h" static nsurl *html_default_stylesheet_url; static nsurl *html_adblock_stylesheet_url; static nsurl *html_quirks_stylesheet_url; static nsurl *html_user_stylesheet_url; +/** + * Convert css error to netsurf error. + */ static nserror css_error_to_nserror(css_error error) { switch (error) { @@ -82,10 +86,10 @@ static nserror css_error_to_nserror(css_error error) return NSERROR_CSS; } + /** * Callback for fetchcache() for stylesheets. */ - static nserror html_convert_css_callback(hlcache_handle *css, const hlcache_event *event, @@ -141,6 +145,7 @@ html_convert_css_callback(hlcache_handle *css, return NSERROR_OK; } + static nserror html_stylesheet_from_domnode(html_content *c, dom_node *node, @@ -195,6 +200,7 @@ html_stylesheet_from_domnode(html_content *c, return NSERROR_OK; } + /** * Process an inline stylesheet in the document. * @@ -202,7 +208,6 @@ html_stylesheet_from_domnode(html_content *c, * \param style xml node of style element * \return true on success, false if an error occurred */ - static struct html_stylesheet * html_create_style_element(html_content *c, dom_node *style) { @@ -254,8 +259,9 @@ html_create_style_element(html_content *c, dom_node *style) return c->stylesheets + (c->stylesheet_count - 1); } -static bool html_css_process_modified_style(html_content *c, - struct html_stylesheet *s) + +static bool +html_css_process_modified_style(html_content *c, struct html_stylesheet *s) { hlcache_handle *sheet = NULL; nserror error; @@ -291,6 +297,10 @@ static bool html_css_process_modified_style(html_content *c, return true; } + +/** + * process a stylesheet that has been modified. + */ static void html_css_process_modified_styles(void *pw) { html_content *c = pw; @@ -310,6 +320,8 @@ static void html_css_process_modified_styles(void *pw) } } + +/* exported function documented in html/css.h */ bool html_css_update_style(html_content *c, dom_node *style) { unsigned int i; @@ -337,6 +349,8 @@ bool html_css_update_style(html_content *c, dom_node *style) return true; } + +/* exported function documented in html/css.h */ bool html_css_process_style(html_content *c, dom_node *node) { unsigned int i; @@ -368,6 +382,8 @@ bool html_css_process_style(html_content *c, dom_node *node) return true; } + +/* exported function documented in html/css.h */ bool html_css_process_link(html_content *htmlc, dom_node *node) { dom_string *rel, *type_attr, *media, *href; @@ -475,6 +491,7 @@ no_memory: return false; } + /* exported interface documented in html/html.h */ struct html_stylesheet *html_get_stylesheets(hlcache_handle *h, unsigned int *n) { @@ -488,8 +505,9 @@ struct html_stylesheet *html_get_stylesheets(hlcache_handle *h, unsigned int *n) return c->stylesheets; } -/* exported interface documented in html/html_internal.h */ -bool html_saw_insecure_stylesheets(html_content *html) + +/* exported function documented in html/css.h */ +bool html_css_saw_insecure_stylesheets(html_content *html) { struct html_stylesheet *s; unsigned int i; @@ -506,7 +524,8 @@ bool html_saw_insecure_stylesheets(html_content *html) return false; } -/* exported interface documented in html/html_internal.h */ + +/* exported function documented in html/css.h */ nserror html_css_free_stylesheets(html_content *html) { unsigned int i; @@ -526,7 +545,8 @@ nserror html_css_free_stylesheets(html_content *html) return NSERROR_OK; } -/* exported interface documented in html/html_internal.h */ + +/* exported function documented in html/css.h */ nserror html_css_quirks_stylesheets(html_content *c) { nserror ns_error = NSERROR_OK; @@ -554,7 +574,8 @@ nserror html_css_quirks_stylesheets(html_content *c) return ns_error; } -/* exported interface documented in html/html_internal.h */ + +/* exported function documented in html/css.h */ nserror html_css_new_stylesheets(html_content *c) { nserror ns_error; @@ -624,6 +645,8 @@ nserror html_css_new_stylesheets(html_content *c) return ns_error; } + +/* exported function documented in html/css.h */ nserror html_css_new_selection_context(html_content *c, css_select_ctx **ret_select_ctx) { @@ -686,6 +709,8 @@ html_css_new_selection_context(html_content *c, css_select_ctx **ret_select_ctx) return NSERROR_OK; } + +/* exported function documented in html/css.h */ nserror html_css_init(void) { nserror error; @@ -715,6 +740,8 @@ nserror html_css_init(void) return error; } + +/* exported function documented in html/css.h */ void html_css_fini(void) { if (html_user_stylesheet_url != NULL) { diff --git a/content/handlers/html/css.h b/content/handlers/html/css.h new file mode 100644 index 000000000..35f6a61e9 --- /dev/null +++ b/content/handlers/html/css.h @@ -0,0 +1,109 @@ +/* + * Copyright 2020 Vincent Sanders + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file + * HTML content handler CSS interface. + */ + +#ifndef NETSURF_HTML_CSS_H +#define NETSURF_HTML_CSS_H + +/** + * Initialise html content css handling. + * + * \return NSERROR_OK on success else error code + */ +nserror html_css_init(void); + +/** + * Finalise html content css handling. + */ +void html_css_fini(void); + +/** + * create a new css selection context for an html content. + * + * \param c The html content to create css selction on. + * \param select_ctx A pointer to receive the new context. + * \return NSERROR_OK on success and \a select_ctx updated else error code + */ +nserror html_css_new_selection_context(struct html_content *c, css_select_ctx **select_ctx); + +/** + * Initialise core stylesheets for a content + * + * \param c content structure to update + * \return NSERROR_OK on success or error code + */ +nserror html_css_new_stylesheets(struct html_content *c); + +/** + * Initialise quirk stylesheets for a content + * + * \param c content structure to update + * \return NSERROR_OK on success or error code + */ +nserror html_css_quirks_stylesheets(struct html_content *c); + +/** + * Free all css stylesheets associated with an HTML content. + * + * \param html The HTML content to free stylesheets from. + * \return NSERROR_OK on success or error code. + */ +nserror html_css_free_stylesheets(struct html_content *html); + +/** + * determine if any of the stylesheets were loaded insecurely + * + * \param htmlc The HTML content to check. + * \return true if there were insecurely loadd stylesheets else false. + */ +bool html_css_saw_insecure_stylesheets(struct html_content *htmlc); + +/** + * process a css stylesheet dom LINK node + * + * \param htmlc The HTML content. + * \param node the DOM link node to process. + * \return true on success else false. + */ +bool html_css_process_link(struct html_content *htmlc, dom_node *node); + +/** + * process a css style dom node + * + * \param htmlc The HTML content. + * \param node the DOM node to process. + * \return true on success else false. + */ +bool html_css_process_style(struct html_content *htmlc, dom_node *node); + +/** + * process a css style dom node update + * + * \param htmlc The HTML content. + * \param node the DOM node to process. + * \return true on success else false. + */ +bool html_css_update_style(struct html_content *htmlc, dom_node *node); + + + +#endif diff --git a/content/handlers/html/css_fetcher.c b/content/handlers/html/css_fetcher.c index ae208797d..4e0f672e9 100644 --- a/content/handlers/html/css_fetcher.c +++ b/content/handlers/html/css_fetcher.c @@ -39,7 +39,7 @@ #include "content/fetch.h" #include "content/fetchers.h" -#include "html/html_internal.h" +#include "html/private.h" typedef struct html_css_fetcher_item { uint32_t key; diff --git a/content/handlers/html/form.c b/content/handlers/html/form.c index 86c4196ed..93297e8a2 100644 --- a/content/handlers/html/form.c +++ b/content/handlers/html/form.c @@ -52,13 +52,13 @@ #include "desktop/textarea.h" #include "desktop/gui_internal.h" +#include "html/html.h" +#include "html/private.h" +#include "html/layout.h" #include "html/box.h" #include "html/box_inspect.h" #include "html/font.h" #include "html/form_internal.h" -#include "html/html.h" -#include "html/html_internal.h" -#include "html/layout.h" #define MAX_SELECT_HEIGHT 210 #define SELECT_LINE_SPACING 0.2 diff --git a/content/handlers/html/forms.c b/content/handlers/html/forms.c index 896263dd0..b8b9cb565 100644 --- a/content/handlers/html/forms.c +++ b/content/handlers/html/forms.c @@ -26,7 +26,7 @@ #include "utils/log.h" #include "html/form_internal.h" -#include "html/html_internal.h" +#include "html/private.h" /** * process form element from dom diff --git a/content/handlers/html/html.c b/content/handlers/html/html.c index 2f6377f80..b4cda4a11 100644 --- a/content/handlers/html/html.c +++ b/content/handlers/html/html.c @@ -56,7 +56,8 @@ #include "desktop/gui_internal.h" #include "html/html.h" -#include "html/html_internal.h" +#include "html/private.h" +#include "html/css.h" #include "html/object.h" #include "html/html_save.h" #include "html/interaction.h" @@ -2816,7 +2817,7 @@ html_saw_insecure_objects(struct content *c) } /* Now check stylesheets */ - if (html_saw_insecure_stylesheets(htmlc)) { + if (html_css_saw_insecure_stylesheets(htmlc)) { return true; } @@ -2894,12 +2895,8 @@ error: return error; } -/** - * Get the browser window containing an HTML content - * - * \param c HTML content - * \return the browser window - */ + +/* exported function documented in html/private.h */ struct browser_window *html_get_browser_window(struct content *c) { html_content *html = (html_content *) c; diff --git a/content/handlers/html/html_internal.h b/content/handlers/html/html_internal.h deleted file mode 100644 index ae3182a07..000000000 --- a/content/handlers/html/html_internal.h +++ /dev/null @@ -1,413 +0,0 @@ -/* - * Copyright 2004 James Bursa - * - * This file is part of NetSurf, http://www.netsurf-browser.org/ - * - * NetSurf is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; version 2 of the License. - * - * NetSurf is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file - * Private data for text/html content. - */ - -#ifndef NETSURF_HTML_HTML_INTERNAL_H -#define NETSURF_HTML_HTML_INTERNAL_H - -#include -#include - -#include "netsurf/types.h" -#include "content/content_protected.h" -#include "desktop/selection.h" - - -struct gui_layout_table; -struct scrollbar_msg_data; -struct content_redraw_data; - -typedef enum { - HTML_DRAG_NONE, /** No drag */ - HTML_DRAG_SELECTION, /** Own; Text selection */ - HTML_DRAG_SCROLLBAR, /** Not own; drag in scrollbar widget */ - HTML_DRAG_TEXTAREA_SELECTION, /** Not own; drag in textarea widget */ - HTML_DRAG_TEXTAREA_SCROLLBAR, /** Not own; drag in textarea widget */ - HTML_DRAG_CONTENT_SELECTION, /** Not own; drag in child content */ - HTML_DRAG_CONTENT_SCROLL /** Not own; drag in child content */ -} html_drag_type; - -/** - * For drags we don't own - */ -union html_drag_owner { - bool no_owner; - struct box *content; - struct scrollbar *scrollbar; - struct box *textarea; -}; - -typedef enum { - HTML_SELECTION_NONE, /** No selection */ - HTML_SELECTION_TEXTAREA, /** Selection in one of our textareas */ - HTML_SELECTION_SELF, /** Selection in this html content */ - HTML_SELECTION_CONTENT /** Selection in child content */ -} html_selection_type; - -/** - * For getting at selections in this content or things in this content - */ -union html_selection_owner { - bool none; - struct box *textarea; - struct box *content; -}; - -typedef enum { - HTML_FOCUS_SELF, /**< Focus is our own */ - HTML_FOCUS_CONTENT, /**< Focus belongs to child content */ - HTML_FOCUS_TEXTAREA /**< Focus belongs to textarea */ -} html_focus_type; - -/** - * For directing input - */ -union html_focus_owner { - bool self; - struct box *textarea; - struct box *content; -}; - -/** - * Data specific to CONTENT_HTML. - */ -typedef struct html_content { - struct content base; - - dom_hubbub_parser *parser; /**< Parser object handle */ - bool parse_completed; /**< Whether the parse has been completed */ - bool conversion_begun; /**< Whether or not the conversion has begun */ - - /** Document tree */ - dom_document *document; - /** Quirkyness of document */ - dom_document_quirks_mode quirks; - - /** Encoding of source, NULL if unknown. */ - char *encoding; - /** Source of encoding information. */ - dom_hubbub_encoding_source encoding_source; - - /** Base URL (may be a copy of content->url). */ - nsurl *base_url; - /** Base target */ - char *base_target; - - /** CSS length conversion context for document. */ - nscss_len_ctx len_ctx; - - /** Content has been aborted in the LOADING state */ - bool aborted; - - /** Whether a meta refresh has been handled */ - bool refresh; - - /** Whether a layout (reflow) is in progress */ - bool reflowing; - - /** Whether an initial layout has been done */ - bool had_initial_layout; - - /** Whether scripts are enabled for this content */ - bool enable_scripting; - - /* Title element node */ - dom_node *title; - - /** A talloc context purely for the render box tree */ - int *bctx; - /** A context pointer for the box conversion, NULL if no conversion - * is in progress. - */ - void *box_conversion_context; - /** Box tree, or NULL. */ - struct box *layout; - /** Document background colour. */ - colour background_colour; - - /** Font callback table */ - const struct gui_layout_table *font_func; - - /** Number of entries in scripts */ - unsigned int scripts_count; - /** Scripts */ - struct html_script *scripts; - /** javascript thread in use */ - struct jsthread *jsthread; - - /** Number of entries in stylesheet_content. */ - unsigned int stylesheet_count; - /** Stylesheets. Each may be NULL. */ - struct html_stylesheet *stylesheets; - /**< Style selection context */ - css_select_ctx *select_ctx; - /**< Style selection media specification */ - css_media media; - /**< Universal selector */ - lwc_string *universal; - - /** Number of entries in object_list. */ - unsigned int num_objects; - /** List of objects. */ - struct content_html_object *object_list; - /** Forms, in reverse order to document. */ - struct form *forms; - /** Hash table of imagemaps. */ - struct imagemap **imagemaps; - - /** Browser window containing this document, or NULL if not open. */ - struct browser_window *bw; - - /** Frameset information */ - struct content_html_frames *frameset; - - /** Inline frame information */ - struct content_html_iframe *iframe; - - /** Content of type CONTENT_HTML containing this, or NULL if not an - * object within a page. */ - struct html_content *page; - - /** Current drag type */ - html_drag_type drag_type; - /** Widget capturing all mouse events */ - union html_drag_owner drag_owner; - - /** Current selection state */ - html_selection_type selection_type; - /** Current selection owner */ - union html_selection_owner selection_owner; - - /** Current input focus target type */ - html_focus_type focus_type; - /** Current input focus target */ - union html_focus_owner focus_owner; - - /** HTML content's own text selection object */ - struct selection sel; - - /** Open core-handled form SELECT menu, - * or NULL if none currently open. */ - struct form_control *visible_select_menu; - - /** Context for free text search, or NULL if none */ - struct search_context *search; - /** Search string or NULL */ - char *search_string; - -} html_content; - -/** Render padding and margin box outlines in html_redraw(). */ -extern bool html_redraw_debug; - -void html__redraw_a_box(html_content *html, struct box *box); - -/** - * Set our drag status, and inform whatever owns the content - * - * \param html HTML content - * \param drag_type Type of drag - * \param drag_owner What owns the drag - * \param rect Pointer movement bounds - */ -void html_set_drag_type(html_content *html, html_drag_type drag_type, - union html_drag_owner drag_owner, const struct rect *rect); - -/** - * Set our selection status, and inform whatever owns the content - * - * \param html HTML content - * \param selection_type Type of selection - * \param selection_owner What owns the selection - * \param read_only True iff selection is read only - */ -void html_set_selection(html_content *html, html_selection_type selection_type, - union html_selection_owner selection_owner, bool read_only); - -/** - * Set our input focus, and inform whatever owns the content - * - * \param html HTML content - * \param focus_type Type of input focus - * \param focus_owner What owns the focus - * \param hide_caret True iff caret to be hidden - * \param x Carret x-coord rel to owner - * \param y Carret y-coord rel to owner - * \param height Carret height - * \param clip Carret clip rect - */ -void html_set_focus(html_content *html, html_focus_type focus_type, - union html_focus_owner focus_owner, bool hide_caret, - int x, int y, int height, const struct rect *clip); - - -struct browser_window *html_get_browser_window(struct content *c); - -/** - * Complete conversion of an HTML document - * - * \param htmlc Content to convert - */ -void html_finish_conversion(html_content *htmlc); - -/** - * Test if an HTML content conversion can begin - * - * \param htmlc html content to test - * \return true iff the html content conversion can begin - */ -bool html_can_begin_conversion(html_content *htmlc); - -/** - * Begin conversion of an HTML document - * - * \param htmlc Content to convert - */ -bool html_begin_conversion(html_content *htmlc); - -/* in html/html_redraw.c */ -bool html_redraw(struct content *c, struct content_redraw_data *data, - const struct rect *clip, const struct redraw_context *ctx); - -/* in html/html_redraw_border.c */ -bool html_redraw_borders(struct box *box, int x_parent, int y_parent, - int p_width, int p_height, const struct rect *clip, float scale, - const struct redraw_context *ctx); - -bool html_redraw_inline_borders(struct box *box, struct rect b, - const struct rect *clip, float scale, bool first, bool last, - const struct redraw_context *ctx); - -/* in html/html_script.c */ -dom_hubbub_error html_process_script(void *ctx, dom_node *node); - -/* in html/html.c */ -bool html_exec(struct content *c, const char *src, size_t srclen); - -/** - * Attempt script execution for defer and async scripts - * - * execute scripts using algorithm found in: - * http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#the-script-element - * - * \param htmlc html content. - * \param allow_defer allow deferred execution, if not, only async scripts. - * \return NSERROR_OK error code. - */ -nserror html_script_exec(html_content *htmlc, bool allow_defer); - -/** - * Free all script resources and references for a html content. - * - * \param htmlc html content. - * \return NSERROR_OK or error code. - */ -nserror html_script_free(html_content *htmlc); - -/** - * Check if any of the scripts loaded were insecure - */ -bool html_saw_insecure_scripts(html_content *htmlc); - -/* in html/html_forms.c */ -struct form *html_forms_get_forms(const char *docenc, dom_html_document *doc); -struct form_control *html_forms_get_control_for_node(struct form *forms, - dom_node *node); - -/* in html/html_css.c */ -nserror html_css_init(void); -void html_css_fini(void); - -/** - * Initialise core stylesheets for a content - * - * \param c content structure to update - * \return nserror - */ -nserror html_css_new_stylesheets(html_content *c); -nserror html_css_quirks_stylesheets(html_content *c); -nserror html_css_free_stylesheets(html_content *html); - -/** Return if any of the stylesheets were loaded insecurely */ -bool html_saw_insecure_stylesheets(html_content *html); - -bool html_css_process_link(html_content *htmlc, dom_node *node); -bool html_css_process_style(html_content *htmlc, dom_node *node); -bool html_css_update_style(html_content *c, dom_node *style); - -nserror html_css_new_selection_context(html_content *c, - css_select_ctx **ret_select_ctx); - -/* in html/html_css_fetcher.c */ -/** - * Register the fetcher for the pseudo x-ns-css scheme. - * - * \return NSERROR_OK on successful registration or error code on failure. - */ -nserror html_css_fetcher_register(void); -nserror html_css_fetcher_add_item(dom_string *data, nsurl *base_url, - uint32_t *key); - -/** - * Complete the HTML content state machine *iff* all scripts are finished - */ -nserror html_proceed_to_done(html_content *html); - - -/* Events */ -/** - * Construct an event and fire it at the DOM - * - */ -bool fire_generic_dom_event(dom_string *type, dom_node *target, - bool bubbles, bool cancelable); - -/** - * Construct a keyboard event and fire it at the DOM - */ -bool fire_dom_keyboard_event(dom_string *type, dom_node *target, - bool bubbles, bool cancelable, uint32_t key); - -/* Useful dom_string pointers */ -struct dom_string; - -extern struct dom_string *html_dom_string_map; -extern struct dom_string *html_dom_string_id; -extern struct dom_string *html_dom_string_name; -extern struct dom_string *html_dom_string_area; -extern struct dom_string *html_dom_string_a; -extern struct dom_string *html_dom_string_nohref; -extern struct dom_string *html_dom_string_href; -extern struct dom_string *html_dom_string_target; -extern struct dom_string *html_dom_string_shape; -extern struct dom_string *html_dom_string_default; -extern struct dom_string *html_dom_string_rect; -extern struct dom_string *html_dom_string_rectangle; -extern struct dom_string *html_dom_string_coords; -extern struct dom_string *html_dom_string_circle; -extern struct dom_string *html_dom_string_poly; -extern struct dom_string *html_dom_string_polygon; -extern struct dom_string *html_dom_string_text_javascript; -extern struct dom_string *html_dom_string_type; -extern struct dom_string *html_dom_string_src; - -#endif diff --git a/content/handlers/html/imagemap.c b/content/handlers/html/imagemap.c index 37095e21d..f23be2353 100644 --- a/content/handlers/html/imagemap.c +++ b/content/handlers/html/imagemap.c @@ -37,7 +37,7 @@ #include "html/box.h" #include "html/box_construct.h" -#include "html/html_internal.h" +#include "html/private.h" #include "html/imagemap.h" #define HASH_SIZE 31 /* fixed size hash table */ diff --git a/content/handlers/html/interaction.c b/content/handlers/html/interaction.c index e4ef2f123..3f401bd11 100644 --- a/content/handlers/html/interaction.c +++ b/content/handlers/html/interaction.c @@ -53,7 +53,7 @@ #include "html/box_inspect.h" #include "html/font.h" #include "html/form_internal.h" -#include "html/html_internal.h" +#include "html/private.h" #include "html/imagemap.h" #include "html/search.h" #include "html/interaction.h" diff --git a/content/handlers/html/interaction.h b/content/handlers/html/interaction.h index c1339c01e..fe8beada0 100644 --- a/content/handlers/html/interaction.h +++ b/content/handlers/html/interaction.h @@ -64,14 +64,60 @@ nserror html_mouse_track(struct content *c, struct browser_window *bw, nserror html_mouse_action(struct content *c, struct browser_window *bw, browser_mouse_state mouse, int x, int y); + bool html_keypress(struct content *c, uint32_t key); + void html_overflow_scroll_callback(void *client_data, struct scrollbar_msg_data *scrollbar_data); + void html_search(struct content *c, void *context, search_flags_t flags, const char *string); + void html_search_clear(struct content *c); + +/** + * Set our drag status, and inform whatever owns the content + * + * \param html HTML content + * \param drag_type Type of drag + * \param drag_owner What owns the drag + * \param rect Pointer movement bounds + */ +void html_set_drag_type(html_content *html, html_drag_type drag_type, + union html_drag_owner drag_owner, const struct rect *rect); + + +/** + * Set our selection status, and inform whatever owns the content + * + * \param html HTML content + * \param selection_type Type of selection + * \param selection_owner What owns the selection + * \param read_only True iff selection is read only + */ +void html_set_selection(html_content *html, html_selection_type selection_type, + union html_selection_owner selection_owner, bool read_only); + + +/** + * Set our input focus, and inform whatever owns the content + * + * \param html HTML content + * \param focus_type Type of input focus + * \param focus_owner What owns the focus + * \param hide_caret True iff caret to be hidden + * \param x Carret x-coord rel to owner + * \param y Carret y-coord rel to owner + * \param height Carret height + * \param clip Carret clip rect + */ +void html_set_focus(html_content *html, html_focus_type focus_type, + union html_focus_owner focus_owner, bool hide_caret, + int x, int y, int height, const struct rect *clip); + + #endif diff --git a/content/handlers/html/layout.c b/content/handlers/html/layout.c index 128b12c0b..3d022ab76 100644 --- a/content/handlers/html/layout.c +++ b/content/handlers/html/layout.c @@ -58,7 +58,7 @@ #include "html/html.h" #include "html/html_save.h" -#include "html/html_internal.h" +#include "html/private.h" #include "html/box.h" #include "html/box_inspect.h" #include "html/font.h" diff --git a/content/handlers/html/object.c b/content/handlers/html/object.c index e8cdc7db9..ba1470bd0 100644 --- a/content/handlers/html/object.c +++ b/content/handlers/html/object.c @@ -41,9 +41,10 @@ #include "desktop/gui_internal.h" #include "html/html.h" +#include "html/private.h" +#include "html/interaction.h" #include "html/box.h" #include "html/box_inspect.h" -#include "html/html_internal.h" #include "html/object.h" /* break reference loop */ diff --git a/content/handlers/html/private.h b/content/handlers/html/private.h new file mode 100644 index 000000000..134acff6d --- /dev/null +++ b/content/handlers/html/private.h @@ -0,0 +1,386 @@ +/* + * Copyright 2004 James Bursa + * + * This file is part of NetSurf, http://www.netsurf-browser.org/ + * + * NetSurf is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; version 2 of the License. + * + * NetSurf is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file + * Private data for text/html content. + */ + +#ifndef NETSURF_HTML_PRIVATE_H +#define NETSURF_HTML_PRIVATE_H + +#include +#include + +#include "netsurf/types.h" +#include "content/content_protected.h" +#include "desktop/selection.h" + + +struct gui_layout_table; +struct scrollbar_msg_data; +struct content_redraw_data; + +typedef enum { + HTML_DRAG_NONE, /** No drag */ + HTML_DRAG_SELECTION, /** Own; Text selection */ + HTML_DRAG_SCROLLBAR, /** Not own; drag in scrollbar widget */ + HTML_DRAG_TEXTAREA_SELECTION, /** Not own; drag in textarea widget */ + HTML_DRAG_TEXTAREA_SCROLLBAR, /** Not own; drag in textarea widget */ + HTML_DRAG_CONTENT_SELECTION, /** Not own; drag in child content */ + HTML_DRAG_CONTENT_SCROLL /** Not own; drag in child content */ +} html_drag_type; + +/** + * For drags we don't own + */ +union html_drag_owner { + bool no_owner; + struct box *content; + struct scrollbar *scrollbar; + struct box *textarea; +}; + +typedef enum { + HTML_SELECTION_NONE, /** No selection */ + HTML_SELECTION_TEXTAREA, /** Selection in one of our textareas */ + HTML_SELECTION_SELF, /** Selection in this html content */ + HTML_SELECTION_CONTENT /** Selection in child content */ +} html_selection_type; + +/** + * For getting at selections in this content or things in this content + */ +union html_selection_owner { + bool none; + struct box *textarea; + struct box *content; +}; + +typedef enum { + HTML_FOCUS_SELF, /**< Focus is our own */ + HTML_FOCUS_CONTENT, /**< Focus belongs to child content */ + HTML_FOCUS_TEXTAREA /**< Focus belongs to textarea */ +} html_focus_type; + +/** + * For directing input + */ +union html_focus_owner { + bool self; + struct box *textarea; + struct box *content; +}; + +/** + * Data specific to CONTENT_HTML. + */ +typedef struct html_content { + struct content base; + + dom_hubbub_parser *parser; /**< Parser object handle */ + bool parse_completed; /**< Whether the parse has been completed */ + bool conversion_begun; /**< Whether or not the conversion has begun */ + + /** Document tree */ + dom_document *document; + /** Quirkyness of document */ + dom_document_quirks_mode quirks; + + /** Encoding of source, NULL if unknown. */ + char *encoding; + /** Source of encoding information. */ + dom_hubbub_encoding_source encoding_source; + + /** Base URL (may be a copy of content->url). */ + nsurl *base_url; + /** Base target */ + char *base_target; + + /** CSS length conversion context for document. */ + nscss_len_ctx len_ctx; + + /** Content has been aborted in the LOADING state */ + bool aborted; + + /** Whether a meta refresh has been handled */ + bool refresh; + + /** Whether a layout (reflow) is in progress */ + bool reflowing; + + /** Whether an initial layout has been done */ + bool had_initial_layout; + + /** Whether scripts are enabled for this content */ + bool enable_scripting; + + /* Title element node */ + dom_node *title; + + /** A talloc context purely for the render box tree */ + int *bctx; + /** A context pointer for the box conversion, NULL if no conversion + * is in progress. + */ + void *box_conversion_context; + /** Box tree, or NULL. */ + struct box *layout; + /** Document background colour. */ + colour background_colour; + + /** Font callback table */ + const struct gui_layout_table *font_func; + + /** Number of entries in scripts */ + unsigned int scripts_count; + /** Scripts */ + struct html_script *scripts; + /** javascript thread in use */ + struct jsthread *jsthread; + + /** Number of entries in stylesheet_content. */ + unsigned int stylesheet_count; + /** Stylesheets. Each may be NULL. */ + struct html_stylesheet *stylesheets; + /**< Style selection context */ + css_select_ctx *select_ctx; + /**< Style selection media specification */ + css_media media; + /**< Universal selector */ + lwc_string *universal; + + /** Number of entries in object_list. */ + unsigned int num_objects; + /** List of objects. */ + struct content_html_object *object_list; + /** Forms, in reverse order to document. */ + struct form *forms; + /** Hash table of imagemaps. */ + struct imagemap **imagemaps; + + /** Browser window containing this document, or NULL if not open. */ + struct browser_window *bw; + + /** Frameset information */ + struct content_html_frames *frameset; + + /** Inline frame information */ + struct content_html_iframe *iframe; + + /** Content of type CONTENT_HTML containing this, or NULL if not an + * object within a page. */ + struct html_content *page; + + /** Current drag type */ + html_drag_type drag_type; + /** Widget capturing all mouse events */ + union html_drag_owner drag_owner; + + /** Current selection state */ + html_selection_type selection_type; + /** Current selection owner */ + union html_selection_owner selection_owner; + + /** Current input focus target type */ + html_focus_type focus_type; + /** Current input focus target */ + union html_focus_owner focus_owner; + + /** HTML content's own text selection object */ + struct selection sel; + + /** + * Open core-handled form SELECT menu, or NULL if none + * currently open. + */ + struct form_control *visible_select_menu; + + /** Context for free text search, or NULL if none */ + struct search_context *search; + /** Search string or NULL */ + char *search_string; + +} html_content; + +/** + * Render padding and margin box outlines in html_redraw(). + */ +extern bool html_redraw_debug; + + +/* in html/html.c */ + +/** + * redraw a box + * + * \param htmlc HTML content + * \param box The box to redraw. + */ +void html__redraw_a_box(html_content *htmlc, struct box *box); + + +/** + * Get the browser window containing an HTML content + * + * \param c HTML content + * \return the browser window + */ +struct browser_window *html_get_browser_window(struct content *c); + + +/** + * Complete conversion of an HTML document + * + * \param htmlc Content to convert + */ +void html_finish_conversion(html_content *htmlc); + + +/** + * Test if an HTML content conversion can begin + * + * \param htmlc html content to test + * \return true iff the html content conversion can begin + */ +bool html_can_begin_conversion(html_content *htmlc); + + +/** + * Begin conversion of an HTML document + * + * \param htmlc Content to convert + */ +bool html_begin_conversion(html_content *htmlc); + + +/** + * execute some text as a script element + */ +bool html_exec(struct content *c, const char *src, size_t srclen); + + +/** + * Attempt script execution for defer and async scripts + * + * execute scripts using algorithm found in: + * http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#the-script-element + * + * \param htmlc html content. + * \param allow_defer allow deferred execution, if not, only async scripts. + * \return NSERROR_OK error code. + */ +nserror html_script_exec(html_content *htmlc, bool allow_defer); + + +/** + * Free all script resources and references for a html content. + * + * \param htmlc html content. + * \return NSERROR_OK or error code. + */ +nserror html_script_free(html_content *htmlc); + + +/** + * Check if any of the scripts loaded were insecure + */ +bool html_saw_insecure_scripts(html_content *htmlc); + + +/** + * Complete the HTML content state machine *iff* all scripts are finished + */ +nserror html_proceed_to_done(html_content *html); + + +/* in html/redraw.c */ +bool html_redraw(struct content *c, struct content_redraw_data *data, + const struct rect *clip, const struct redraw_context *ctx); + + +/* in html/redraw_border.c */ +bool html_redraw_borders(struct box *box, int x_parent, int y_parent, + int p_width, int p_height, const struct rect *clip, float scale, + const struct redraw_context *ctx); + + +bool html_redraw_inline_borders(struct box *box, struct rect b, + const struct rect *clip, float scale, bool first, bool last, + const struct redraw_context *ctx); + + +/* in html/script.c */ +dom_hubbub_error html_process_script(void *ctx, dom_node *node); + + +/* in html/forms.c */ +struct form *html_forms_get_forms(const char *docenc, dom_html_document *doc); +struct form_control *html_forms_get_control_for_node(struct form *forms, + dom_node *node); + + +/* in html/css_fetcher.c */ +/** + * Register the fetcher for the pseudo x-ns-css scheme. + * + * \return NSERROR_OK on successful registration or error code on failure. + */ +nserror html_css_fetcher_register(void); +nserror html_css_fetcher_add_item(dom_string *data, nsurl *base_url, + uint32_t *key); + + +/* Events */ +/** + * Construct an event and fire it at the DOM + * + */ +bool fire_generic_dom_event(dom_string *type, dom_node *target, + bool bubbles, bool cancelable); + +/** + * Construct a keyboard event and fire it at the DOM + */ +bool fire_dom_keyboard_event(dom_string *type, dom_node *target, + bool bubbles, bool cancelable, uint32_t key); + +/* Useful dom_string pointers */ +struct dom_string; + +extern struct dom_string *html_dom_string_map; +extern struct dom_string *html_dom_string_id; +extern struct dom_string *html_dom_string_name; +extern struct dom_string *html_dom_string_area; +extern struct dom_string *html_dom_string_a; +extern struct dom_string *html_dom_string_nohref; +extern struct dom_string *html_dom_string_href; +extern struct dom_string *html_dom_string_target; +extern struct dom_string *html_dom_string_shape; +extern struct dom_string *html_dom_string_default; +extern struct dom_string *html_dom_string_rect; +extern struct dom_string *html_dom_string_rectangle; +extern struct dom_string *html_dom_string_coords; +extern struct dom_string *html_dom_string_circle; +extern struct dom_string *html_dom_string_poly; +extern struct dom_string *html_dom_string_polygon; +extern struct dom_string *html_dom_string_text_javascript; +extern struct dom_string *html_dom_string_type; +extern struct dom_string *html_dom_string_src; + +#endif diff --git a/content/handlers/html/redraw.c b/content/handlers/html/redraw.c index ee6fab275..fa4cd954d 100644 --- a/content/handlers/html/redraw.c +++ b/content/handlers/html/redraw.c @@ -58,7 +58,7 @@ #include "html/box_manipulate.h" #include "html/font.h" #include "html/form_internal.h" -#include "html/html_internal.h" +#include "html/private.h" #include "html/layout.h" #include "html/search.h" diff --git a/content/handlers/html/redraw_border.c b/content/handlers/html/redraw_border.c index 0b3d858e6..39ed432cd 100644 --- a/content/handlers/html/redraw_border.c +++ b/content/handlers/html/redraw_border.c @@ -30,7 +30,7 @@ #include "netsurf/css.h" #include "html/box.h" -#include "html/html_internal.h" +#include "html/private.h" static plot_style_t plot_style_bdr = { diff --git a/content/handlers/html/script.c b/content/handlers/html/script.c index 81bdccda9..99275c0e9 100644 --- a/content/handlers/html/script.c +++ b/content/handlers/html/script.c @@ -40,7 +40,7 @@ #include "content/hlcache.h" #include "html/html.h" -#include "html/html_internal.h" +#include "html/private.h" typedef bool (script_handler_t)(struct jsthread *jsthread, const uint8_t *data, size_t size, const char *name); diff --git a/content/handlers/html/search.c b/content/handlers/html/search.c index 864fac6dd..8ccb6920c 100644 --- a/content/handlers/html/search.c +++ b/content/handlers/html/search.c @@ -42,7 +42,7 @@ #include "html/box.h" #include "html/box_inspect.h" #include "html/html.h" -#include "html/html_internal.h" +#include "html/private.h" #include "html/search.h" #ifndef NOF_ELEMENTS diff --git a/content/handlers/javascript/duktape/Document.bnd b/content/handlers/javascript/duktape/Document.bnd index de96cd864..2f9adc380 100644 --- a/content/handlers/javascript/duktape/Document.bnd +++ b/content/handlers/javascript/duktape/Document.bnd @@ -14,7 +14,7 @@ prologue Document() #include "utils/libdom.h" #include "utils/utils.h" #include "content/hlcache.h" -#include "html/html_internal.h" +#include "html/private.h" #include "content/urldb.h" #define HANDLER_MAGIC MAGIC(HANDLER_MAP) diff --git a/content/handlers/javascript/duktape/Window.bnd b/content/handlers/javascript/duktape/Window.bnd index 2c26f1d70..f7d143f6c 100644 --- a/content/handlers/javascript/duktape/Window.bnd +++ b/content/handlers/javascript/duktape/Window.bnd @@ -19,7 +19,7 @@ class Window { #include "netsurf/browser_window.h" #include "content/hlcache.h" #include "html/html.h" -#include "html/html_internal.h" +#include "html/private.h" #include "desktop/gui_internal.h" #include "netsurf/misc.h" #include "utils/ring.h" -- cgit v1.2.3