From 216fb88f58227f94e87d9e9926b599161a8e65bb Mon Sep 17 00:00:00 2001 From: Vincent Sanders Date: Fri, 11 May 2018 13:15:17 +0100 Subject: clean up html content handler header use Improve header use in preperation for making browser window a corewindow --- content/handlers/html/box_construct.c | 1 + content/handlers/html/box_textarea.c | 2 + content/handlers/html/box_textarea.h | 10 ++--- content/handlers/html/html.c | 4 +- content/handlers/html/html.h | 66 +++++++++++++++++++++------- content/handlers/html/html_css.c | 1 + content/handlers/html/html_interaction.c | 74 +++++++++++++++++--------------- content/handlers/html/html_internal.h | 38 +++++++++++----- content/handlers/html/html_object.c | 1 + content/handlers/html/html_save.h | 46 ++++++++++++++++++++ content/handlers/html/html_script.c | 1 + content/handlers/html/layout.c | 4 +- desktop/save_complete.c | 1 + desktop/save_text.c | 2 +- 14 files changed, 182 insertions(+), 69 deletions(-) create mode 100644 content/handlers/html/html_save.h diff --git a/content/handlers/html/box_construct.c b/content/handlers/html/box_construct.c index 9c19391de..5650fbf55 100644 --- a/content/handlers/html/box_construct.c +++ b/content/handlers/html/box_construct.c @@ -49,6 +49,7 @@ #include "css/utils.h" #include "desktop/gui_internal.h" +#include "html/html.h" #include "html/box.h" #include "html/box_textarea.h" #include "html/form_internal.h" diff --git a/content/handlers/html/box_textarea.c b/content/handlers/html/box_textarea.c index abd28fb86..858de5039 100644 --- a/content/handlers/html/box_textarea.c +++ b/content/handlers/html/box_textarea.c @@ -28,6 +28,8 @@ #include "netsurf/keypress.h" #include "desktop/textarea.h" +#include "html/html_internal.h" +#include "html/box.h" #include "html/box_textarea.h" #include "html/font.h" #include "html/form_internal.h" diff --git a/content/handlers/html/box_textarea.h b/content/handlers/html/box_textarea.h index e2b02e811..822fc8b10 100644 --- a/content/handlers/html/box_textarea.h +++ b/content/handlers/html/box_textarea.h @@ -24,11 +24,9 @@ #ifndef NETSURF_HTML_BOX_TEXTAREA_H #define NETSURF_HTML_BOX_TEXTAREA_H - -#include "html/box.h" -#include "html/html_internal.h" - struct dom_node; +struct html_content; +struct box; /** * Create textarea widget for a form element @@ -37,7 +35,7 @@ struct dom_node; * \param box box with gadget to be given textarea widget * \param node DOM node for form element */ -bool box_textarea_create_textarea(html_content *html, +bool box_textarea_create_textarea(struct html_content *html, struct box *box, struct dom_node *node); @@ -49,6 +47,6 @@ bool box_textarea_create_textarea(html_content *html, * \param key keypress * \return true iff keypress handled */ -bool box_textarea_keypress(html_content *html, struct box *box, uint32_t key); +bool box_textarea_keypress(struct html_content *html, struct box *box, uint32_t key); #endif diff --git a/content/handlers/html/html.c b/content/handlers/html/html.c index 18c1a7afb..f721b98ab 100644 --- a/content/handlers/html/html.c +++ b/content/handlers/html/html.c @@ -54,9 +54,11 @@ #include "javascript/js.h" #include "desktop/gui_internal.h" +#include "html/html.h" +#include "html/html_save.h" +#include "html/html_internal.h" #include "html/box.h" #include "html/form_internal.h" -#include "html/html_internal.h" #include "html/imagemap.h" #include "html/layout.h" #include "html/search.h" diff --git a/content/handlers/html/html.h b/content/handlers/html/html.h index 691e969a5..8d1c77992 100644 --- a/content/handlers/html/html.h +++ b/content/handlers/html/html.h @@ -28,9 +28,6 @@ #include -#include -#include - #include "netsurf/types.h" #include "netsurf/content_type.h" #include "netsurf/browser_window.h" @@ -65,6 +62,7 @@ struct html_stylesheet { bool unused; }; + /** * Container for scripts used by an HTML document */ @@ -103,12 +101,10 @@ struct content_html_object { bool background; /**< This object is a background image. */ }; -struct html_scrollbar_data { - struct content *c; - struct box *box; -}; -/** Frame tree (frameset or frame tag) */ +/** + * Frame tree (frameset or frame tag) + */ struct content_html_frames { int cols; /** number of columns in frameset */ int rows; /** number of rows in frameset */ @@ -129,7 +125,9 @@ struct content_html_frames { struct content_html_frames *children; /** [cols * rows] children */ }; -/** Inline frame list (iframe tag) */ +/** + * Inline frame list (iframe tag) + */ struct content_html_iframe { struct box *box; @@ -153,19 +151,46 @@ struct content_html_iframe { #define STYLESHEET_USER 3 /* user stylesheet */ #define STYLESHEET_START 4 /* start of document stylesheets */ +/** + * initialise content handler + * + * \return NSERROR_OK on success otherwise appropriate error code + */ nserror html_init(void); +/** + * redraw a specific box + * + * used by core browser + */ void html_redraw_a_box(struct hlcache_handle *h, struct box *box); -void html_overflow_scroll_drag_end(struct scrollbar *scrollbar, - browser_mouse_state mouse, int x, int y); - -dom_document *html_get_document(struct hlcache_handle *h); -struct box *html_get_box_tree(struct hlcache_handle *h); +/** + * obtain html frame content from handle + * + * used by core browser + */ struct content_html_frames *html_get_frameset(struct hlcache_handle *h); + +/** + * obtain html iframe content from handle + * + * used by core browser + */ struct content_html_iframe *html_get_iframe(struct hlcache_handle *h); -struct nsurl *html_get_base_url(struct hlcache_handle *h); + +/** + * obtain html base target from handle + * + * used by core browser + */ const char *html_get_base_target(struct hlcache_handle *h); + +/** + * set filename on a file gadget + * + * used by core browser + */ void html_set_file_gadget_filename(struct hlcache_handle *hl, struct form_control *gadget, const char *fn); @@ -179,8 +204,19 @@ void html_set_file_gadget_filename(struct hlcache_handle *hl, struct html_stylesheet *html_get_stylesheets(struct hlcache_handle *h, unsigned int *n); +/** + * Retrieve objects used by HTML document + * + * \param h Content to retrieve objects from + * \param n Pointer to location to receive number of objects + * \return Pointer to array of objects + */ struct content_html_object *html_get_objects(struct hlcache_handle *h, unsigned int *n); + +/** + * get the offset within the docuemnt of a fragment id + */ bool html_get_id_offset(struct hlcache_handle *h, lwc_string *frag_id, int *x, int *y); diff --git a/content/handlers/html/html_css.c b/content/handlers/html/html_css.c index b67d19af6..7b2d469c4 100644 --- a/content/handlers/html/html_css.c +++ b/content/handlers/html/html_css.c @@ -38,6 +38,7 @@ #include "css/css.h" #include "desktop/gui_internal.h" +#include "html/html.h" #include "html/html_internal.h" static nsurl *html_default_stylesheet_url; diff --git a/content/handlers/html/html_interaction.c b/content/handlers/html/html_interaction.c index 898f55bc2..648d27467 100644 --- a/content/handlers/html/html_interaction.c +++ b/content/handlers/html/html_interaction.c @@ -294,6 +294,45 @@ html__image_coords_dom_user_data_handler(dom_node_operation operation, } } + +/** + * End overflow scroll scrollbar drags + * + * \param scrollbar scrollbar widget + * \param mouse state of mouse buttons and modifier keys + * \param x coordinate of mouse + * \param y coordinate of mouse + */ +static void +html_overflow_scroll_drag_end(struct scrollbar *scrollbar, + browser_mouse_state mouse, + int x, int y) +{ + int scroll_mouse_x, scroll_mouse_y, box_x, box_y; + struct html_scrollbar_data *data = scrollbar_get_data(scrollbar); + struct box *box; + + box = data->box; + box_coords(box, &box_x, &box_y); + + if (scrollbar_is_horizontal(scrollbar)) { + scroll_mouse_x = x - box_x; + scroll_mouse_y = y - (box_y + box->padding[TOP] + + box->height + box->padding[BOTTOM] - + SCROLLBAR_WIDTH); + scrollbar_mouse_drag_end(scrollbar, mouse, + scroll_mouse_x, scroll_mouse_y); + } else { + scroll_mouse_x = x - (box_x + box->padding[LEFT] + + box->width + box->padding[RIGHT] - + SCROLLBAR_WIDTH); + scroll_mouse_y = y - box_y; + scrollbar_mouse_drag_end(scrollbar, mouse, + scroll_mouse_x, scroll_mouse_y); + } +} + + /** * Handle mouse clicks and movements in an HTML content window. * @@ -1227,41 +1266,6 @@ void html_overflow_scroll_callback(void *client_data, } -/** - * End overflow scroll scrollbar drags - * - * \param scrollbar scrollbar widget - * \param mouse state of mouse buttons and modifier keys - * \param x coordinate of mouse - * \param y coordinate of mouse - */ -void html_overflow_scroll_drag_end(struct scrollbar *scrollbar, - browser_mouse_state mouse, int x, int y) -{ - int scroll_mouse_x, scroll_mouse_y, box_x, box_y; - struct html_scrollbar_data *data = scrollbar_get_data(scrollbar); - struct box *box; - - box = data->box; - box_coords(box, &box_x, &box_y); - - if (scrollbar_is_horizontal(scrollbar)) { - scroll_mouse_x = x - box_x; - scroll_mouse_y = y - (box_y + box->padding[TOP] + - box->height + box->padding[BOTTOM] - - SCROLLBAR_WIDTH); - scrollbar_mouse_drag_end(scrollbar, mouse, - scroll_mouse_x, scroll_mouse_y); - } else { - scroll_mouse_x = x - (box_x + box->padding[LEFT] + - box->width + box->padding[RIGHT] - - SCROLLBAR_WIDTH); - scroll_mouse_y = y - box_y; - scrollbar_mouse_drag_end(scrollbar, mouse, - scroll_mouse_x, scroll_mouse_y); - } -} - /* Documented in html_internal.h */ void html_set_drag_type(html_content *html, html_drag_type drag_type, union html_drag_owner drag_owner, const struct rect *rect) diff --git a/content/handlers/html/html_internal.h b/content/handlers/html/html_internal.h index b9eca663e..77354c369 100644 --- a/content/handlers/html/html_internal.h +++ b/content/handlers/html/html_internal.h @@ -25,14 +25,14 @@ #define NETSURF_HTML_HTML_INTERNAL_H #include +#include -#include "content/handlers/css/utils.h" +#include "netsurf/types.h" #include "content/content_protected.h" #include "desktop/selection.h" -#include "html/html.h" - struct gui_layout_table; +struct scrollbar_msg_data; typedef enum { HTML_DRAG_NONE, /** No drag */ @@ -44,12 +44,15 @@ typedef enum { 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; -}; /**< For drags we don't own */ +}; typedef enum { HTML_SELECTION_NONE, /** No selection */ @@ -57,24 +60,39 @@ typedef enum { 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; -}; /**< For getting at selections in this content or things in this 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_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; -}; /**< For directing input */ +}; -/** Data specific to CONTENT_HTML. */ +struct html_scrollbar_data { + struct content *c; + struct box *box; +}; + +/** + * Data specific to CONTENT_HTML. + */ typedef struct html_content { struct content base; diff --git a/content/handlers/html/html_object.c b/content/handlers/html/html_object.c index c8715e3fb..7eab46647 100644 --- a/content/handlers/html/html_object.c +++ b/content/handlers/html/html_object.c @@ -40,6 +40,7 @@ #include "desktop/scrollbar.h" #include "desktop/gui_internal.h" +#include "html/html.h" #include "html/box.h" #include "html/html_internal.h" diff --git a/content/handlers/html/html_save.h b/content/handlers/html/html_save.h new file mode 100644 index 000000000..c173922d5 --- /dev/null +++ b/content/handlers/html/html_save.h @@ -0,0 +1,46 @@ +/* + * Copyright 2018 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 + * Interface to HTML content handler to save documents. + * + * \todo Investigate altering this API as it is only used for + * exporting the html content to disc. + */ + +#ifndef NETSURF_HTML_HTML_SAVE_H +#define NETSURF_HTML_HTML_SAVE_H + +/** + * get the dom document of a html content from a handle + */ +dom_document *html_get_document(struct hlcache_handle *h); + + +/** + * get the render box tree of a html content from a handle + */ +struct box *html_get_box_tree(struct hlcache_handle *h); + +/** + * get the base url of an html content from a handle + */ +struct nsurl *html_get_base_url(struct hlcache_handle *h); + +#endif diff --git a/content/handlers/html/html_script.c b/content/handlers/html/html_script.c index e18a0caa0..80992b9dd 100644 --- a/content/handlers/html/html_script.c +++ b/content/handlers/html/html_script.c @@ -39,6 +39,7 @@ #include "content/fetch.h" #include "content/hlcache.h" +#include "html/html.h" #include "html/html_internal.h" typedef bool (script_handler_t)(struct jscontext *jscontext, const char *data, size_t size) ; diff --git a/content/handlers/html/layout.c b/content/handlers/html/layout.c index 6941d6759..2d2c42438 100644 --- a/content/handlers/html/layout.c +++ b/content/handlers/html/layout.c @@ -56,10 +56,12 @@ #include "desktop/scrollbar.h" #include "desktop/textarea.h" +#include "html/html.h" +#include "html/html_save.h" +#include "html/html_internal.h" #include "html/box.h" #include "html/font.h" #include "html/form_internal.h" -#include "html/html_internal.h" #include "html/layout.h" #include "html/table.h" diff --git a/desktop/save_complete.c b/desktop/save_complete.c index cd4ab30cf..ef794d4d7 100644 --- a/desktop/save_complete.c +++ b/desktop/save_complete.c @@ -44,6 +44,7 @@ #include "content/hlcache.h" #include "css/css.h" #include "html/box.h" +#include "html/html_save.h" #include "html/html.h" #include "netsurf/misc.h" diff --git a/desktop/save_text.c b/desktop/save_text.c index c4abb16f1..a86f173b0 100644 --- a/desktop/save_text.c +++ b/desktop/save_text.c @@ -33,7 +33,7 @@ #include "utils/utils.h" #include "netsurf/content.h" #include "html/box.h" -#include "html/html.h" +#include "html/html_save.h" #include "netsurf/utf8.h" #include "desktop/gui_internal.h" -- cgit v1.2.3