improve html content handler private headers

This commit is contained in:
Vincent Sanders 2020-05-02 20:47:53 +01:00
parent 19cd5cb3b3
commit a706c69bf4
26 changed files with 282 additions and 128 deletions

View File

@ -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"

View File

@ -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

View File

@ -32,11 +32,11 @@
#include "netsurf/mouse.h"
#include "desktop/scrollbar.h"
#include "html/private.h"
#include "html/form_internal.h"
#include "html/interaction.h"
#include "html/box.h"
#include "html/box_manipulate.h"
#include "html/form_internal.h"
#include "html/html_internal.h"
#include "html/interaction.h"
/**

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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) {

109
content/handlers/html/css.h Normal file
View File

@ -0,0 +1,109 @@
/*
* Copyright 2020 Vincent Sanders <vince@netsurf-browser.org>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \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

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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 */

View File

@ -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"

View File

@ -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

View File

@ -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"

View File

@ -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 */

View File

@ -21,8 +21,8 @@
* Private data for text/html content.
*/
#ifndef NETSURF_HTML_HTML_INTERNAL_H
#define NETSURF_HTML_HTML_INTERNAL_H
#ifndef NETSURF_HTML_PRIVATE_H
#define NETSURF_HTML_PRIVATE_H
#include <libcss/libcss.h>
#include <dom/bindings/hubbub/parser.h>
@ -205,8 +205,10 @@ typedef struct html_content {
/** HTML content's own text selection object */
struct selection sel;
/** Open core-handled form SELECT menu,
* or NULL if none currently open. */
/**
* 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 */
@ -216,52 +218,32 @@ typedef struct html_content {
} html_content;
/** Render padding and margin box outlines in html_redraw(). */
/**
* 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);
/* in html/html.c */
/**
* Set our drag status, and inform whatever owns the content
* redraw a box
*
* \param html HTML content
* \param drag_type Type of drag
* \param drag_owner What owns the drag
* \param rect Pointer movement bounds
* \param htmlc HTML content
* \param box The box to redraw.
*/
void html_set_drag_type(html_content *html, html_drag_type drag_type,
union html_drag_owner drag_owner, const struct rect *rect);
void html__redraw_a_box(html_content *htmlc, struct box *box);
/**
* Set our selection status, and inform whatever owns the content
* Get the browser window containing an HTML 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
* \param c HTML content
* \return the browser window
*/
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
*
@ -269,6 +251,7 @@ struct browser_window *html_get_browser_window(struct content *c);
*/
void html_finish_conversion(html_content *htmlc);
/**
* Test if an HTML content conversion can begin
*
@ -277,6 +260,7 @@ void html_finish_conversion(html_content *htmlc);
*/
bool html_can_begin_conversion(html_content *htmlc);
/**
* Begin conversion of an HTML document
*
@ -284,25 +268,13 @@ bool html_can_begin_conversion(html_content *htmlc);
*/
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 */
/**
* 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
*
@ -315,6 +287,7 @@ bool html_exec(struct content *c, const char *src, size_t srclen);
*/
nserror html_script_exec(html_content *htmlc, bool allow_defer);
/**
* Free all script resources and references for a html content.
*
@ -323,41 +296,46 @@ nserror html_script_exec(html_content *htmlc, bool allow_defer);
*/
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 */
/**
* 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/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 */
/* in html/css_fetcher.c */
/**
* Register the fetcher for the pseudo x-ns-css scheme.
*
@ -367,11 +345,6 @@ 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 */
/**

View File

@ -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"

View File

@ -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 = {

View File

@ -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);

View File

@ -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

View File

@ -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)

View File

@ -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"

View File

@ -34,7 +34,7 @@
#include "netsurf/form.h"
#include "html/box.h"
#include "html/box_inspect.h"
#include "html/html_internal.h"
#include "html/private.h"
#include "html/font.h"
#include "text/textplain.h"
#include "netsurf/browser_window.h"

View File

@ -39,7 +39,7 @@
#include "netsurf/browser_window.h"
#include "netsurf/keypress.h"
#include "html/box.h"
#include "html/html_internal.h"
#include "html/private.h"
#include "html/layout.h"
#include "desktop/browser_private.h"