mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-11-21 22:11:22 +03:00
split html box processing code
reduce the module size of the html box handling code by splitting into smaller sections. No functional code change.
This commit is contained in:
parent
a64261c3bd
commit
e8d0ba15ad
@ -1,7 +1,23 @@
|
||||
# HTML content handler sources
|
||||
|
||||
S_HTML := box.c box_construct.c box_normalise.c box_textarea.c \
|
||||
font.c form.c imagemap.c layout.c search.c table.c \
|
||||
html.c html_css.c html_css_fetcher.c html_script.c \
|
||||
interaction.c html_redraw.c html_redraw_border.c \
|
||||
html_forms.c html_object.c
|
||||
S_HTML := box_construct.c \
|
||||
box_inspect.c \
|
||||
box_manipulate.c \
|
||||
box_normalise.c \
|
||||
box_special.c \
|
||||
box_textarea.c \
|
||||
font.c \
|
||||
form.c \
|
||||
imagemap.c \
|
||||
layout.c \
|
||||
search.c \
|
||||
table.c \
|
||||
html.c \
|
||||
html_css.c \
|
||||
html_css_fetcher.c \
|
||||
html_script.c \
|
||||
interaction.c \
|
||||
html_redraw.c \
|
||||
html_redraw_border.c \
|
||||
html_forms.c \
|
||||
html_object.c
|
||||
|
@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Copyright 2005 James Bursa <bursa@users.sourceforge.net>
|
||||
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
||||
* Copyright 2020 Vincent Sanders <vince@netsurf-browser.org>
|
||||
*
|
||||
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
||||
*
|
||||
@ -19,69 +20,8 @@
|
||||
|
||||
/**
|
||||
* \file
|
||||
* Box tree construction and manipulation interface.
|
||||
* Box interface.
|
||||
*
|
||||
* This stage of rendering converts a tree of dom_nodes (produced by libdom)
|
||||
* to a tree of struct box. The box tree represents the structure of the
|
||||
* document as given by the CSS display and float properties.
|
||||
*
|
||||
* For example, consider the following HTML:
|
||||
* \code
|
||||
* <h1>Example Heading</h1>
|
||||
* <p>Example paragraph <em>with emphasised text</em> etc.</p> \endcode
|
||||
*
|
||||
* This would produce approximately the following box tree with default CSS
|
||||
* rules:
|
||||
* \code
|
||||
* BOX_BLOCK (corresponds to h1)
|
||||
* BOX_INLINE_CONTAINER
|
||||
* BOX_INLINE "Example Heading"
|
||||
* BOX_BLOCK (p)
|
||||
* BOX_INLINE_CONTAINER
|
||||
* BOX_INLINE "Example paragraph "
|
||||
* BOX_INLINE "with emphasised text" (em)
|
||||
* BOX_INLINE "etc." \endcode
|
||||
*
|
||||
* Note that the em has been collapsed into the INLINE_CONTAINER.
|
||||
*
|
||||
* If these CSS rules were applied:
|
||||
* \code
|
||||
* h1 { display: table-cell }
|
||||
* p { display: table-cell }
|
||||
* em { float: left; width: 5em } \endcode
|
||||
*
|
||||
* then the box tree would instead look like this:
|
||||
* \code
|
||||
* BOX_TABLE
|
||||
* BOX_TABLE_ROW_GROUP
|
||||
* BOX_TABLE_ROW
|
||||
* BOX_TABLE_CELL (h1)
|
||||
* BOX_INLINE_CONTAINER
|
||||
* BOX_INLINE "Example Heading"
|
||||
* BOX_TABLE_CELL (p)
|
||||
* BOX_INLINE_CONTAINER
|
||||
* BOX_INLINE "Example paragraph "
|
||||
* BOX_FLOAT_LEFT (em)
|
||||
* BOX_BLOCK
|
||||
* BOX_INLINE_CONTAINER
|
||||
* BOX_INLINE "with emphasised text"
|
||||
* BOX_INLINE "etc." \endcode
|
||||
*
|
||||
* Here implied boxes have been added and a float is present.
|
||||
*
|
||||
* A box tree is "normalized" if the following is satisfied:
|
||||
* \code
|
||||
* parent permitted child nodes
|
||||
* BLOCK, INLINE_BLOCK BLOCK, INLINE_CONTAINER, TABLE
|
||||
* INLINE_CONTAINER INLINE, INLINE_BLOCK, FLOAT_LEFT, FLOAT_RIGHT, BR, TEXT,
|
||||
* INLINE_END
|
||||
* INLINE none
|
||||
* TABLE at least 1 TABLE_ROW_GROUP
|
||||
* TABLE_ROW_GROUP at least 1 TABLE_ROW
|
||||
* TABLE_ROW at least 1 TABLE_CELL
|
||||
* TABLE_CELL BLOCK, INLINE_CONTAINER, TABLE (same as BLOCK)
|
||||
* FLOAT_(LEFT|RIGHT) exactly 1 BLOCK or TABLE
|
||||
* \endcode
|
||||
*/
|
||||
|
||||
#ifndef NETSURF_HTML_BOX_H
|
||||
@ -89,7 +29,6 @@
|
||||
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <libcss/libcss.h>
|
||||
|
||||
#include "content/handlers/css/utils.h"
|
||||
@ -517,197 +456,4 @@ extern const char *TARGET_TOP;
|
||||
extern const char *TARGET_BLANK;
|
||||
|
||||
|
||||
/**
|
||||
* Create a box tree node.
|
||||
*
|
||||
* \param styles selection results for the box, or NULL
|
||||
* \param style computed style for the box (not copied), or 0
|
||||
* \param style_owned whether style is owned by this box
|
||||
* \param href href for the box (copied), or 0
|
||||
* \param target target for the box (not copied), or 0
|
||||
* \param title title for the box (not copied), or 0
|
||||
* \param id id for the box (not copied), or 0
|
||||
* \param context context for allocations
|
||||
* \return allocated and initialised box, or 0 on memory exhaustion
|
||||
*
|
||||
* styles is always owned by the box, if it is set.
|
||||
* style is only owned by the box in the case of implied boxes.
|
||||
*/
|
||||
struct box * box_create(css_select_results *styles, css_computed_style *style, bool style_owned, struct nsurl *href, const char *target, const char *title, lwc_string *id, void *context);
|
||||
|
||||
|
||||
/**
|
||||
* Add a child to a box tree node.
|
||||
*
|
||||
* \param parent box giving birth
|
||||
* \param child box to link as last child of parent
|
||||
*/
|
||||
void box_add_child(struct box *parent, struct box *child);
|
||||
|
||||
|
||||
/**
|
||||
* Insert a new box as a sibling to a box in a tree.
|
||||
*
|
||||
* \param box box already in tree
|
||||
* \param new_box box to link into tree as next sibling
|
||||
*/
|
||||
void box_insert_sibling(struct box *box, struct box *new_box);
|
||||
|
||||
|
||||
/**
|
||||
* Unlink a box from the box tree and then free it recursively.
|
||||
*
|
||||
* \param box box to unlink and free recursively.
|
||||
*/
|
||||
void box_unlink_and_free(struct box *box);
|
||||
|
||||
|
||||
/**
|
||||
* Free a box tree recursively.
|
||||
*
|
||||
* \param box box to free recursively
|
||||
*
|
||||
* The box and all its children is freed.
|
||||
*/
|
||||
void box_free(struct box *box);
|
||||
|
||||
|
||||
/**
|
||||
* Free the data in a single box structure.
|
||||
*
|
||||
* \param box box to free
|
||||
*/
|
||||
void box_free_box(struct box *box);
|
||||
|
||||
|
||||
/**
|
||||
* Find the absolute coordinates of a box.
|
||||
*
|
||||
* \param box the box to calculate coordinates of
|
||||
* \param x updated to x coordinate
|
||||
* \param y updated to y coordinate
|
||||
*/
|
||||
void box_coords(struct box *box, int *x, int *y);
|
||||
|
||||
|
||||
/**
|
||||
* Find the bounds of a box.
|
||||
*
|
||||
* \param box the box to calculate bounds of
|
||||
* \param r receives bounds
|
||||
*/
|
||||
void box_bounds(struct box *box, struct rect *r);
|
||||
|
||||
|
||||
/**
|
||||
* Find the boxes at a point.
|
||||
*
|
||||
* \param len_ctx CSS length conversion context for document.
|
||||
* \param box box to search children of
|
||||
* \param x point to find, in global document coordinates
|
||||
* \param y point to find, in global document coordinates
|
||||
* \param box_x position of box, in global document coordinates, updated
|
||||
* to position of returned box, if any
|
||||
* \param box_y position of box, in global document coordinates, updated
|
||||
* to position of returned box, if any
|
||||
* \return box at given point, or 0 if none found
|
||||
*
|
||||
* To find all the boxes in the hierarchy at a certain point, use code like
|
||||
* this:
|
||||
* \code
|
||||
* struct box *box = top_of_document_to_search;
|
||||
* int box_x = 0, box_y = 0;
|
||||
*
|
||||
* while ((box = box_at_point(len_ctx, box, x, y, &box_x, &box_y))) {
|
||||
* // process box
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
struct box *box_at_point(const nscss_len_ctx *len_ctx, struct box *box, const int x, const int y, int *box_x, int *box_y);
|
||||
|
||||
|
||||
/**
|
||||
* Peform pick text on browser window contents to locate the box under
|
||||
* the mouse pointer, or nearest in the given direction if the pointer is
|
||||
* not over a text box.
|
||||
*
|
||||
* \param html an HTML content
|
||||
* \param x coordinate of mouse
|
||||
* \param y coordinate of mouse
|
||||
* \param dir direction to search (-1 = above-left, +1 = below-right)
|
||||
* \param dx receives x ordinate of mouse relative to text box
|
||||
* \param dy receives y ordinate of mouse relative to text box
|
||||
*/
|
||||
struct box *box_pick_text_box(struct html_content *html, int x, int y, int dir, int *dx, int *dy);
|
||||
|
||||
|
||||
/**
|
||||
* Find a box based upon its id attribute.
|
||||
*
|
||||
* \param box box tree to search
|
||||
* \param id id to look for
|
||||
* \return the box or 0 if not found
|
||||
*/
|
||||
struct box *box_find_by_id(struct box *box, lwc_string *id);
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a box is visible when the tree is rendered.
|
||||
*
|
||||
* \param box box to check
|
||||
* \return true iff the box is rendered
|
||||
*/
|
||||
bool box_visible(struct box *box);
|
||||
|
||||
|
||||
/**
|
||||
* Print a box tree to a file.
|
||||
*/
|
||||
void box_dump(FILE *stream, struct box *box, unsigned int depth, bool style);
|
||||
|
||||
|
||||
/**
|
||||
* Applies the given scroll setup to a box. This includes scroll
|
||||
* creation/deletion as well as scroll dimension updates.
|
||||
*
|
||||
* \param c content in which the box is located
|
||||
* \param box the box to handle the scrolls for
|
||||
* \param bottom whether the horizontal scrollbar should be present
|
||||
* \param right whether the vertical scrollbar should be present
|
||||
* \return true on success false otherwise
|
||||
*/
|
||||
nserror box_handle_scrollbars(struct content *c, struct box *box,
|
||||
bool bottom, bool right);
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a box has a vertical scrollbar.
|
||||
*
|
||||
* \param box scrolling box
|
||||
* \return the box has a vertical scrollbar
|
||||
*/
|
||||
bool box_vscrollbar_present(const struct box *box);
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a box has a horizontal scrollbar.
|
||||
*
|
||||
* \param box scrolling box
|
||||
* \return the box has a horizontal scrollbar
|
||||
*/
|
||||
bool box_hscrollbar_present(const struct box *box);
|
||||
|
||||
|
||||
/**
|
||||
* Check if layout box is a first child.
|
||||
*
|
||||
* \param[in] b Box to check.
|
||||
* \return true iff box is first child.
|
||||
*/
|
||||
static inline bool box_is_first_child(struct box *b)
|
||||
{
|
||||
return (b->parent == NULL || b == b->parent->children);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -19,6 +19,54 @@
|
||||
/**
|
||||
* \file
|
||||
* HTML Box tree construction interface.
|
||||
*
|
||||
* This stage of rendering converts a tree of dom_nodes (produced by libdom)
|
||||
* to a tree of struct box. The box tree represents the structure of the
|
||||
* document as given by the CSS display and float properties.
|
||||
*
|
||||
* For example, consider the following HTML:
|
||||
* \code
|
||||
* <h1>Example Heading</h1>
|
||||
* <p>Example paragraph <em>with emphasised text</em> etc.</p> \endcode
|
||||
*
|
||||
* This would produce approximately the following box tree with default CSS
|
||||
* rules:
|
||||
* \code
|
||||
* BOX_BLOCK (corresponds to h1)
|
||||
* BOX_INLINE_CONTAINER
|
||||
* BOX_INLINE "Example Heading"
|
||||
* BOX_BLOCK (p)
|
||||
* BOX_INLINE_CONTAINER
|
||||
* BOX_INLINE "Example paragraph "
|
||||
* BOX_INLINE "with emphasised text" (em)
|
||||
* BOX_INLINE "etc." \endcode
|
||||
*
|
||||
* Note that the em has been collapsed into the INLINE_CONTAINER.
|
||||
*
|
||||
* If these CSS rules were applied:
|
||||
* \code
|
||||
* h1 { display: table-cell }
|
||||
* p { display: table-cell }
|
||||
* em { float: left; width: 5em } \endcode
|
||||
*
|
||||
* then the box tree would instead look like this:
|
||||
* \code
|
||||
* BOX_TABLE
|
||||
* BOX_TABLE_ROW_GROUP
|
||||
* BOX_TABLE_ROW
|
||||
* BOX_TABLE_CELL (h1)
|
||||
* BOX_INLINE_CONTAINER
|
||||
* BOX_INLINE "Example Heading"
|
||||
* BOX_TABLE_CELL (p)
|
||||
* BOX_INLINE_CONTAINER
|
||||
* BOX_INLINE "Example paragraph "
|
||||
* BOX_FLOAT_LEFT (em)
|
||||
* BOX_BLOCK
|
||||
* BOX_INLINE_CONTAINER
|
||||
* BOX_INLINE "with emphasised text"
|
||||
* BOX_INLINE "etc." \endcode
|
||||
*
|
||||
* Here implied boxes have been added and a float is present.
|
||||
*/
|
||||
|
||||
#ifndef NETSURF_HTML_BOX_CONSTRUCT_H
|
||||
|
File diff suppressed because it is too large
Load Diff
143
content/handlers/html/box_inspect.h
Normal file
143
content/handlers/html/box_inspect.h
Normal file
@ -0,0 +1,143 @@
|
||||
/*
|
||||
* 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 Box tree inspection interface.
|
||||
*/
|
||||
|
||||
#ifndef NETSURF_HTML_BOX_INSPECT_H
|
||||
#define NETSURF_HTML_BOX_INSPECT_H
|
||||
|
||||
/**
|
||||
* Find the absolute coordinates of a box.
|
||||
*
|
||||
* \param box the box to calculate coordinates of
|
||||
* \param x updated to x coordinate
|
||||
* \param y updated to y coordinate
|
||||
*/
|
||||
void box_coords(struct box *box, int *x, int *y);
|
||||
|
||||
|
||||
/**
|
||||
* Find the bounds of a box.
|
||||
*
|
||||
* \param box the box to calculate bounds of
|
||||
* \param r receives bounds
|
||||
*/
|
||||
void box_bounds(struct box *box, struct rect *r);
|
||||
|
||||
|
||||
/**
|
||||
* Find the boxes at a point.
|
||||
*
|
||||
* \param len_ctx CSS length conversion context for document.
|
||||
* \param box box to search children of
|
||||
* \param x point to find, in global document coordinates
|
||||
* \param y point to find, in global document coordinates
|
||||
* \param box_x position of box, in global document coordinates, updated
|
||||
* to position of returned box, if any
|
||||
* \param box_y position of box, in global document coordinates, updated
|
||||
* to position of returned box, if any
|
||||
* \return box at given point, or 0 if none found
|
||||
*
|
||||
* To find all the boxes in the hierarchy at a certain point, use code like
|
||||
* this:
|
||||
* \code
|
||||
* struct box *box = top_of_document_to_search;
|
||||
* int box_x = 0, box_y = 0;
|
||||
*
|
||||
* while ((box = box_at_point(len_ctx, box, x, y, &box_x, &box_y))) {
|
||||
* // process box
|
||||
* }
|
||||
* \endcode
|
||||
*/
|
||||
struct box *box_at_point(const nscss_len_ctx *len_ctx, struct box *box, const int x, const int y, int *box_x, int *box_y);
|
||||
|
||||
|
||||
/**
|
||||
* Find a box based upon its id attribute.
|
||||
*
|
||||
* \param box box tree to search
|
||||
* \param id id to look for
|
||||
* \return the box or 0 if not found
|
||||
*/
|
||||
struct box *box_find_by_id(struct box *box, lwc_string *id);
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a box is visible when the tree is rendered.
|
||||
*
|
||||
* \param box box to check
|
||||
* \return true iff the box is rendered
|
||||
*/
|
||||
bool box_visible(struct box *box);
|
||||
|
||||
|
||||
/**
|
||||
* Print a box tree to a file.
|
||||
*/
|
||||
void box_dump(FILE *stream, struct box *box, unsigned int depth, bool style);
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a box has a vertical scrollbar.
|
||||
*
|
||||
* \param box scrolling box
|
||||
* \return the box has a vertical scrollbar
|
||||
*/
|
||||
bool box_vscrollbar_present(const struct box *box);
|
||||
|
||||
|
||||
/**
|
||||
* Determine if a box has a horizontal scrollbar.
|
||||
*
|
||||
* \param box scrolling box
|
||||
* \return the box has a horizontal scrollbar
|
||||
*/
|
||||
bool box_hscrollbar_present(const struct box *box);
|
||||
|
||||
|
||||
/**
|
||||
* Peform pick text on browser window contents to locate the box under
|
||||
* the mouse pointer, or nearest in the given direction if the pointer is
|
||||
* not over a text box.
|
||||
*
|
||||
* \param html an HTML content
|
||||
* \param x coordinate of mouse
|
||||
* \param y coordinate of mouse
|
||||
* \param dir direction to search (-1 = above-left, +1 = below-right)
|
||||
* \param dx receives x ordinate of mouse relative to text box
|
||||
* \param dy receives y ordinate of mouse relative to text box
|
||||
*/
|
||||
struct box *box_pick_text_box(struct html_content *html, int x, int y, int dir, int *dx, int *dy);
|
||||
|
||||
|
||||
/**
|
||||
* Check if layout box is a first child.
|
||||
*
|
||||
* \param[in] b Box to check.
|
||||
* \return true iff box is first child.
|
||||
*/
|
||||
static inline bool box_is_first_child(struct box *b)
|
||||
{
|
||||
return (b->parent == NULL || b == b->parent->children);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
350
content/handlers/html/box_manipulate.c
Normal file
350
content/handlers/html/box_manipulate.c
Normal file
@ -0,0 +1,350 @@
|
||||
/*
|
||||
* Copyright 2005-2007 James Bursa <bursa@users.sourceforge.net>
|
||||
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
||||
* Copyright 2005 John M Bell <jmb202@ecs.soton.ac.uk>
|
||||
* Copyright 2008 Michael Drake <tlsa@netsurf-browser.org>
|
||||
* 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
|
||||
* implementation of box tree manipulation.
|
||||
*/
|
||||
|
||||
|
||||
#include "utils/errors.h"
|
||||
#include "utils/talloc.h"
|
||||
#include "netsurf/types.h"
|
||||
#include "netsurf/mouse.h"
|
||||
#include "desktop/scrollbar.h"
|
||||
|
||||
#include "html/box.h"
|
||||
#include "html/box_manipulate.h"
|
||||
#include "html/form_internal.h"
|
||||
#include "html/html_internal.h"
|
||||
#include "html/interaction.h"
|
||||
|
||||
|
||||
/**
|
||||
* Destructor for box nodes which own styles
|
||||
*
|
||||
* \param b The box being destroyed.
|
||||
* \return 0 to allow talloc to continue destroying the tree.
|
||||
*/
|
||||
static int box_talloc_destructor(struct box *b)
|
||||
{
|
||||
struct html_scrollbar_data *data;
|
||||
|
||||
if ((b->flags & STYLE_OWNED) && b->style != NULL) {
|
||||
css_computed_style_destroy(b->style);
|
||||
b->style = NULL;
|
||||
}
|
||||
|
||||
if (b->styles != NULL) {
|
||||
css_select_results_destroy(b->styles);
|
||||
b->styles = NULL;
|
||||
}
|
||||
|
||||
if (b->href != NULL)
|
||||
nsurl_unref(b->href);
|
||||
|
||||
if (b->id != NULL) {
|
||||
lwc_string_unref(b->id);
|
||||
}
|
||||
|
||||
if (b->node != NULL) {
|
||||
dom_node_unref(b->node);
|
||||
}
|
||||
|
||||
if (b->scroll_x != NULL) {
|
||||
data = scrollbar_get_data(b->scroll_x);
|
||||
scrollbar_destroy(b->scroll_x);
|
||||
free(data);
|
||||
}
|
||||
|
||||
if (b->scroll_y != NULL) {
|
||||
data = scrollbar_get_data(b->scroll_y);
|
||||
scrollbar_destroy(b->scroll_y);
|
||||
free(data);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* Exported function documented in html/box.h */
|
||||
struct box *
|
||||
box_create(css_select_results *styles,
|
||||
css_computed_style *style,
|
||||
bool style_owned,
|
||||
nsurl *href,
|
||||
const char *target,
|
||||
const char *title,
|
||||
lwc_string *id,
|
||||
void *context)
|
||||
{
|
||||
unsigned int i;
|
||||
struct box *box;
|
||||
|
||||
box = talloc(context, struct box);
|
||||
if (!box) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
talloc_set_destructor(box, box_talloc_destructor);
|
||||
|
||||
box->type = BOX_INLINE;
|
||||
box->flags = 0;
|
||||
box->flags = style_owned ? (box->flags | STYLE_OWNED) : box->flags;
|
||||
box->styles = styles;
|
||||
box->style = style;
|
||||
box->x = box->y = 0;
|
||||
box->width = UNKNOWN_WIDTH;
|
||||
box->height = 0;
|
||||
box->descendant_x0 = box->descendant_y0 = 0;
|
||||
box->descendant_x1 = box->descendant_y1 = 0;
|
||||
for (i = 0; i != 4; i++)
|
||||
box->margin[i] = box->padding[i] = box->border[i].width = 0;
|
||||
box->scroll_x = box->scroll_y = NULL;
|
||||
box->min_width = 0;
|
||||
box->max_width = UNKNOWN_MAX_WIDTH;
|
||||
box->byte_offset = 0;
|
||||
box->text = NULL;
|
||||
box->length = 0;
|
||||
box->space = 0;
|
||||
box->href = (href == NULL) ? NULL : nsurl_ref(href);
|
||||
box->target = target;
|
||||
box->title = title;
|
||||
box->columns = 1;
|
||||
box->rows = 1;
|
||||
box->start_column = 0;
|
||||
box->next = NULL;
|
||||
box->prev = NULL;
|
||||
box->children = NULL;
|
||||
box->last = NULL;
|
||||
box->parent = NULL;
|
||||
box->inline_end = NULL;
|
||||
box->float_children = NULL;
|
||||
box->float_container = NULL;
|
||||
box->next_float = NULL;
|
||||
box->cached_place_below_level = 0;
|
||||
box->list_marker = NULL;
|
||||
box->col = NULL;
|
||||
box->gadget = NULL;
|
||||
box->usemap = NULL;
|
||||
box->id = id;
|
||||
box->background = NULL;
|
||||
box->object = NULL;
|
||||
box->object_params = NULL;
|
||||
box->iframe = NULL;
|
||||
box->node = NULL;
|
||||
|
||||
return box;
|
||||
}
|
||||
|
||||
|
||||
/* Exported function documented in html/box.h */
|
||||
void box_add_child(struct box *parent, struct box *child)
|
||||
{
|
||||
assert(parent);
|
||||
assert(child);
|
||||
|
||||
if (parent->children != 0) { /* has children already */
|
||||
parent->last->next = child;
|
||||
child->prev = parent->last;
|
||||
} else { /* this is the first child */
|
||||
parent->children = child;
|
||||
child->prev = 0;
|
||||
}
|
||||
|
||||
parent->last = child;
|
||||
child->parent = parent;
|
||||
}
|
||||
|
||||
|
||||
/* Exported function documented in html/box.h */
|
||||
void box_insert_sibling(struct box *box, struct box *new_box)
|
||||
{
|
||||
new_box->parent = box->parent;
|
||||
new_box->prev = box;
|
||||
new_box->next = box->next;
|
||||
box->next = new_box;
|
||||
if (new_box->next)
|
||||
new_box->next->prev = new_box;
|
||||
else if (new_box->parent)
|
||||
new_box->parent->last = new_box;
|
||||
}
|
||||
|
||||
|
||||
/* Exported function documented in html/box.h */
|
||||
void box_unlink_and_free(struct box *box)
|
||||
{
|
||||
struct box *parent = box->parent;
|
||||
struct box *next = box->next;
|
||||
struct box *prev = box->prev;
|
||||
|
||||
if (parent) {
|
||||
if (parent->children == box)
|
||||
parent->children = next;
|
||||
if (parent->last == box)
|
||||
parent->last = next ? next : prev;
|
||||
}
|
||||
|
||||
if (prev)
|
||||
prev->next = next;
|
||||
if (next)
|
||||
next->prev = prev;
|
||||
|
||||
box_free(box);
|
||||
}
|
||||
|
||||
|
||||
/* Exported function documented in html/box.h */
|
||||
void box_free(struct box *box)
|
||||
{
|
||||
struct box *child, *next;
|
||||
|
||||
/* free children first */
|
||||
for (child = box->children; child; child = next) {
|
||||
next = child->next;
|
||||
box_free(child);
|
||||
}
|
||||
|
||||
/* last this box */
|
||||
box_free_box(box);
|
||||
}
|
||||
|
||||
|
||||
/* Exported function documented in html/box.h */
|
||||
void box_free_box(struct box *box)
|
||||
{
|
||||
if (!(box->flags & CLONE)) {
|
||||
if (box->gadget)
|
||||
form_free_control(box->gadget);
|
||||
if (box->scroll_x != NULL)
|
||||
scrollbar_destroy(box->scroll_x);
|
||||
if (box->scroll_y != NULL)
|
||||
scrollbar_destroy(box->scroll_y);
|
||||
if (box->styles != NULL)
|
||||
css_select_results_destroy(box->styles);
|
||||
}
|
||||
|
||||
talloc_free(box);
|
||||
}
|
||||
|
||||
|
||||
/* exported interface documented in html/box.h */
|
||||
nserror
|
||||
box_handle_scrollbars(struct content *c,
|
||||
struct box *box,
|
||||
bool bottom,
|
||||
bool right)
|
||||
{
|
||||
struct html_scrollbar_data *data;
|
||||
int visible_width, visible_height;
|
||||
int full_width, full_height;
|
||||
nserror res;
|
||||
|
||||
if (!bottom && box->scroll_x != NULL) {
|
||||
data = scrollbar_get_data(box->scroll_x);
|
||||
scrollbar_destroy(box->scroll_x);
|
||||
free(data);
|
||||
box->scroll_x = NULL;
|
||||
}
|
||||
|
||||
if (!right && box->scroll_y != NULL) {
|
||||
data = scrollbar_get_data(box->scroll_y);
|
||||
scrollbar_destroy(box->scroll_y);
|
||||
free(data);
|
||||
box->scroll_y = NULL;
|
||||
}
|
||||
|
||||
if (!bottom && !right) {
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
visible_width = box->width + box->padding[RIGHT] + box->padding[LEFT];
|
||||
visible_height = box->height + box->padding[TOP] + box->padding[BOTTOM];
|
||||
|
||||
full_width = ((box->descendant_x1 - box->border[RIGHT].width) >
|
||||
visible_width) ?
|
||||
box->descendant_x1 + box->padding[RIGHT] :
|
||||
visible_width;
|
||||
full_height = ((box->descendant_y1 - box->border[BOTTOM].width) >
|
||||
visible_height) ?
|
||||
box->descendant_y1 + box->padding[BOTTOM] :
|
||||
visible_height;
|
||||
|
||||
if (right) {
|
||||
if (box->scroll_y == NULL) {
|
||||
data = malloc(sizeof(struct html_scrollbar_data));
|
||||
if (data == NULL) {
|
||||
return NSERROR_NOMEM;
|
||||
}
|
||||
data->c = c;
|
||||
data->box = box;
|
||||
res = scrollbar_create(false,
|
||||
visible_height,
|
||||
full_height,
|
||||
visible_height,
|
||||
data,
|
||||
html_overflow_scroll_callback,
|
||||
&(box->scroll_y));
|
||||
if (res != NSERROR_OK) {
|
||||
return res;
|
||||
}
|
||||
} else {
|
||||
scrollbar_set_extents(box->scroll_y,
|
||||
visible_height,
|
||||
visible_height,
|
||||
full_height);
|
||||
}
|
||||
}
|
||||
if (bottom) {
|
||||
if (box->scroll_x == NULL) {
|
||||
data = malloc(sizeof(struct html_scrollbar_data));
|
||||
if (data == NULL) {
|
||||
return NSERROR_OK;
|
||||
}
|
||||
data->c = c;
|
||||
data->box = box;
|
||||
res = scrollbar_create(true,
|
||||
visible_width - (right ? SCROLLBAR_WIDTH : 0),
|
||||
full_width,
|
||||
visible_width,
|
||||
data,
|
||||
html_overflow_scroll_callback,
|
||||
&box->scroll_x);
|
||||
if (res != NSERROR_OK) {
|
||||
return res;
|
||||
}
|
||||
} else {
|
||||
scrollbar_set_extents(box->scroll_x,
|
||||
visible_width -
|
||||
(right ? SCROLLBAR_WIDTH : 0),
|
||||
visible_width, full_width);
|
||||
}
|
||||
}
|
||||
|
||||
if (right && bottom) {
|
||||
scrollbar_make_pair(box->scroll_x, box->scroll_y);
|
||||
}
|
||||
|
||||
return NSERROR_OK;
|
||||
}
|
||||
|
||||
|
106
content/handlers/html/box_manipulate.h
Normal file
106
content/handlers/html/box_manipulate.h
Normal file
@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Copyright 2005 James Bursa <bursa@users.sourceforge.net>
|
||||
* Copyright 2003 Phil Mellor <monkeyson@users.sourceforge.net>
|
||||
*
|
||||
* 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
|
||||
* Box tree manipulation interface.
|
||||
*/
|
||||
|
||||
#ifndef NETSURF_HTML_BOX_MANIPULATE_H
|
||||
#define NETSURF_HTML_BOX_MANIPULATE_H
|
||||
|
||||
|
||||
/**
|
||||
* Create a box tree node.
|
||||
*
|
||||
* \param styles selection results for the box, or NULL
|
||||
* \param style computed style for the box (not copied), or 0
|
||||
* \param style_owned whether style is owned by this box
|
||||
* \param href href for the box (copied), or 0
|
||||
* \param target target for the box (not copied), or 0
|
||||
* \param title title for the box (not copied), or 0
|
||||
* \param id id for the box (not copied), or 0
|
||||
* \param context context for allocations
|
||||
* \return allocated and initialised box, or 0 on memory exhaustion
|
||||
*
|
||||
* styles is always owned by the box, if it is set.
|
||||
* style is only owned by the box in the case of implied boxes.
|
||||
*/
|
||||
struct box * box_create(css_select_results *styles, css_computed_style *style, bool style_owned, struct nsurl *href, const char *target, const char *title, lwc_string *id, void *context);
|
||||
|
||||
|
||||
/**
|
||||
* Add a child to a box tree node.
|
||||
*
|
||||
* \param parent box giving birth
|
||||
* \param child box to link as last child of parent
|
||||
*/
|
||||
void box_add_child(struct box *parent, struct box *child);
|
||||
|
||||
|
||||
/**
|
||||
* Insert a new box as a sibling to a box in a tree.
|
||||
*
|
||||
* \param box box already in tree
|
||||
* \param new_box box to link into tree as next sibling
|
||||
*/
|
||||
void box_insert_sibling(struct box *box, struct box *new_box);
|
||||
|
||||
|
||||
/**
|
||||
* Unlink a box from the box tree and then free it recursively.
|
||||
*
|
||||
* \param box box to unlink and free recursively.
|
||||
*/
|
||||
void box_unlink_and_free(struct box *box);
|
||||
|
||||
|
||||
/**
|
||||
* Free a box tree recursively.
|
||||
*
|
||||
* \param box box to free recursively
|
||||
*
|
||||
* The box and all its children is freed.
|
||||
*/
|
||||
void box_free(struct box *box);
|
||||
|
||||
|
||||
/**
|
||||
* Free the data in a single box structure.
|
||||
*
|
||||
* \param box box to free
|
||||
*/
|
||||
void box_free_box(struct box *box);
|
||||
|
||||
|
||||
/**
|
||||
* Applies the given scroll setup to a box. This includes scroll
|
||||
* creation/deletion as well as scroll dimension updates.
|
||||
*
|
||||
* \param c content in which the box is located
|
||||
* \param box the box to handle the scrolls for
|
||||
* \param bottom whether the horizontal scrollbar should be present
|
||||
* \param right whether the vertical scrollbar should be present
|
||||
* \return true on success false otherwise
|
||||
*/
|
||||
nserror box_handle_scrollbars(struct content *c, struct box *box,
|
||||
bool bottom, bool right);
|
||||
|
||||
|
||||
#endif
|
@ -33,6 +33,7 @@
|
||||
#include "css/select.h"
|
||||
|
||||
#include "html/box.h"
|
||||
#include "html/box_manipulate.h"
|
||||
#include "html/box_normalise.h"
|
||||
#include "html/html_internal.h"
|
||||
#include "html/table.h"
|
||||
|
@ -19,6 +19,21 @@
|
||||
/**
|
||||
* \file
|
||||
* HTML Box tree normalise interface.
|
||||
*
|
||||
* A box tree is "normalized" if the following is satisfied:
|
||||
* \code
|
||||
* parent permitted child nodes
|
||||
* BLOCK, INLINE_BLOCK BLOCK, INLINE_CONTAINER, TABLE
|
||||
* INLINE_CONTAINER INLINE, INLINE_BLOCK, FLOAT_LEFT, FLOAT_RIGHT, BR, TEXT,
|
||||
* INLINE_END
|
||||
* INLINE none
|
||||
* TABLE at least 1 TABLE_ROW_GROUP
|
||||
* TABLE_ROW_GROUP at least 1 TABLE_ROW
|
||||
* TABLE_ROW at least 1 TABLE_CELL
|
||||
* TABLE_CELL BLOCK, INLINE_CONTAINER, TABLE (same as BLOCK)
|
||||
* FLOAT_(LEFT|RIGHT) exactly 1 BLOCK or TABLE
|
||||
* \endcode
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef NETSURF_HTML_BOX_NORMALISE_H
|
||||
|
1916
content/handlers/html/box_special.c
Normal file
1916
content/handlers/html/box_special.c
Normal file
File diff suppressed because it is too large
Load Diff
35
content/handlers/html/box_special.h
Normal file
35
content/handlers/html/box_special.h
Normal file
@ -0,0 +1,35 @@
|
||||
/*
|
||||
* 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 Box tree construction special element conversion interface.
|
||||
*/
|
||||
|
||||
#ifndef NETSURF_HTML_BOX_SPECIAL_H
|
||||
#define NETSURF_HTML_BOX_SPECIAL_H
|
||||
|
||||
|
||||
/**
|
||||
* call an elements special conversion handler
|
||||
*
|
||||
* \return true if box construction should continue else false on error.
|
||||
*/
|
||||
bool convert_special_elements(dom_node *node, html_content *content, struct box *box, bool *convert_children);
|
||||
|
||||
#endif
|
@ -33,6 +33,7 @@
|
||||
|
||||
#include "html/html_internal.h"
|
||||
#include "html/box.h"
|
||||
#include "html/box_inspect.h"
|
||||
#include "html/box_textarea.h"
|
||||
#include "html/font.h"
|
||||
#include "html/form_internal.h"
|
||||
|
@ -53,6 +53,7 @@
|
||||
#include "desktop/gui_internal.h"
|
||||
|
||||
#include "html/box.h"
|
||||
#include "html/box_inspect.h"
|
||||
#include "html/font.h"
|
||||
#include "html/form_internal.h"
|
||||
#include "html/html.h"
|
||||
|
@ -61,6 +61,7 @@
|
||||
#include "html/interaction.h"
|
||||
#include "html/box.h"
|
||||
#include "html/box_construct.h"
|
||||
#include "html/box_inspect.h"
|
||||
#include "html/form_internal.h"
|
||||
#include "html/imagemap.h"
|
||||
#include "html/layout.h"
|
||||
|
@ -42,6 +42,7 @@
|
||||
|
||||
#include "html/html.h"
|
||||
#include "html/box.h"
|
||||
#include "html/box_inspect.h"
|
||||
#include "html/html_internal.h"
|
||||
|
||||
/* break reference loop */
|
||||
|
@ -54,6 +54,8 @@
|
||||
#include "desktop/gui_internal.h"
|
||||
|
||||
#include "html/box.h"
|
||||
#include "html/box_inspect.h"
|
||||
#include "html/box_manipulate.h"
|
||||
#include "html/font.h"
|
||||
#include "html/form_internal.h"
|
||||
#include "html/html_internal.h"
|
||||
|
@ -50,6 +50,7 @@
|
||||
|
||||
#include "html/box.h"
|
||||
#include "html/box_textarea.h"
|
||||
#include "html/box_inspect.h"
|
||||
#include "html/font.h"
|
||||
#include "html/form_internal.h"
|
||||
#include "html/html_internal.h"
|
||||
|
@ -60,6 +60,7 @@
|
||||
#include "html/html_save.h"
|
||||
#include "html/html_internal.h"
|
||||
#include "html/box.h"
|
||||
#include "html/box_inspect.h"
|
||||
#include "html/font.h"
|
||||
#include "html/form_internal.h"
|
||||
#include "html/layout.h"
|
||||
|
@ -40,6 +40,7 @@
|
||||
|
||||
#include "text/textplain.h"
|
||||
#include "html/box.h"
|
||||
#include "html/box_inspect.h"
|
||||
#include "html/html.h"
|
||||
#include "html/html_internal.h"
|
||||
#include "html/search.h"
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "content/hlcache.h"
|
||||
#include "html/html.h"
|
||||
#include "html/box.h"
|
||||
#include "html/box_inspect.h"
|
||||
|
||||
#include "desktop/browser_private.h"
|
||||
#include "desktop/frames.h"
|
||||
|
@ -38,6 +38,7 @@
|
||||
#define SCROLL_BOTTOM INT_MAX
|
||||
|
||||
struct scrollbar;
|
||||
struct redraw_context;
|
||||
|
||||
/**
|
||||
* scrollbar message types
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include "utils/utils.h"
|
||||
#include "netsurf/form.h"
|
||||
#include "html/box.h"
|
||||
#include "html/box_inspect.h"
|
||||
#include "html/html_internal.h"
|
||||
#include "html/font.h"
|
||||
#include "text/textplain.h"
|
||||
|
Loading…
Reference in New Issue
Block a user