NetSurf
Data Structures | Functions | Variables
box_construct.c File Reference

Implementation of conversion from DOM tree to box tree. More...

#include <string.h>
#include <dom/dom.h>
#include "utils/errors.h"
#include "utils/nsoption.h"
#include "utils/corestrings.h"
#include "utils/talloc.h"
#include "utils/ascii.h"
#include "utils/nsurl.h"
#include "netsurf/misc.h"
#include "css/select.h"
#include "desktop/gui_internal.h"
#include "html/private.h"
#include "html/object.h"
#include "html/box.h"
#include "html/box_manipulate.h"
#include "html/box_construct.h"
#include "html/box_special.h"
#include "html/box_normalise.h"
#include "html/form_internal.h"
Include dependency graph for box_construct.c:

Go to the source code of this file.

Data Structures

struct  box_construct_ctx
 Context for box tree construction. More...
 
struct  box_construct_props
 Transient properties for construction of current node. More...
 

Functions

static bool box_is_root (dom_node *n)
 determine if a box is the root node More...
 
static void box_extract_properties (dom_node *n, struct box_construct_props *props)
 Extract transient construction properties. More...
 
static css_select_results * box_get_style (html_content *c, const css_computed_style *parent_style, const css_computed_style *root_style, dom_node *n)
 Get the style for an element. More...
 
static void box_construct_generate (dom_node *n, html_content *content, struct box *box, const css_computed_style *style)
 Construct the box required for a generated element. More...
 
static bool box_construct_marker (struct box *box, const char *title, struct box_construct_ctx *ctx, struct box *parent)
 Construct a list marker box. More...
 
static bool box__style_is_float (const struct box *box)
 
static bool box__is_flex (const struct box *box)
 
static bool box__containing_block_is_flex (const struct box_construct_props *props)
 
static bool box_construct_element (struct box_construct_ctx *ctx, bool *convert_children)
 Construct the box tree for an XML element. More...
 
static void box_construct_element_after (dom_node *n, html_content *content)
 Complete construction of the box tree for an element. More...
 
static dom_node * next_node (dom_node *n, html_content *content, bool convert_children)
 Find the next node in the DOM tree, completing element construction where appropriate. More...
 
static void box_text_transform (char *s, unsigned int len, enum css_text_transform_e tt)
 Apply the CSS text-transform property to given text for its ASCII chars. More...
 
static bool box_construct_text (struct box_construct_ctx *ctx)
 Construct the box tree for an XML text node. More...
 
static void convert_xml_to_box (struct box_construct_ctx *ctx)
 Convert an ELEMENT node to a box tree fragment, then schedule conversion of the next ELEMENT node. More...
 
nserror dom_to_box (dom_node *n, html_content *c, box_construct_complete_cb cb, void **box_conversion_context)
 Construct a box tree from a dom and html content. More...
 
nserror cancel_dom_to_box (void *box_conversion_context)
 aborts any ongoing box construction More...
 
struct boxbox_for_node (dom_node *n)
 Retrieve the box for a dom node, if there is one. More...
 
bool box_extract_link (const html_content *content, const dom_string *dsrel, nsurl *base, nsurl **result)
 

Variables

static const content_type image_types = CONTENT_IMAGE
 
static const box_type box_map []
 

Detailed Description

Implementation of conversion from DOM tree to box tree.

Definition in file box_construct.c.

Function Documentation

◆ box__containing_block_is_flex()

static bool box__containing_block_is_flex ( const struct box_construct_props props)
inlinestatic

Definition at line 456 of file box_construct.c.

References box__is_flex(), and box_construct_props::containing_block.

Referenced by box_construct_element().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ box__is_flex()

static bool box__is_flex ( const struct box box)
inlinestatic

Definition at line 451 of file box_construct.c.

References BOX_FLEX, BOX_INLINE_FLEX, and box::type.

Referenced by box__containing_block_is_flex().

Here is the caller graph for this function:

◆ box__style_is_float()

static bool box__style_is_float ( const struct box box)
inlinestatic

Definition at line 445 of file box_construct.c.

References box::style.

Referenced by box_construct_element().

Here is the caller graph for this function:

◆ box_construct_element()

static bool box_construct_element ( struct box_construct_ctx ctx,
bool *  convert_children 
)
static

Construct the box tree for an XML element.

Parameters
ctxTree construction context
convert_childrenWhether to convert children
Returns
true on success, false on memory exhaustion

Definition at line 471 of file box_construct.c.

References box_construct_ctx::bctx, form_control::box, box__containing_block_is_flex(), box__style_is_float(), box_add_child(), BOX_BLOCK, BOX_BR, box_construct_generate(), box_construct_marker(), box_create(), box_extract_properties(), BOX_FLEX, BOX_FLOAT_LEFT, BOX_FLOAT_RIGHT, box_get_style(), BOX_INLINE, BOX_INLINE_BLOCK, BOX_INLINE_CONTAINER, BOX_INLINE_FLEX, box_map, BOX_NONE, box::columns, box_construct_props::containing_block, box_construct_ctx::content, CONVERT_CHILDREN, convert_special_elements(), box::flags, box::gadget, box_construct_props::href, html_fetch_object(), image_types, box_construct_props::inline_container, IS_REPLACED, box_construct_ctx::n, box::node, box_construct_props::node_is_root, ns_computed_display(), ns_computed_display_static(), NSERROR_OK, nsoption_bool, nsurl_create(), nsurl_unref(), box_construct_props::parent_style, box_construct_ctx::root_box, box::rows, squash_whitespace(), box::style, box::styles, talloc_strdup(), box_construct_props::target, box_construct_props::title, and box::type.

Referenced by convert_xml_to_box().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ box_construct_element_after()

static void box_construct_element_after ( dom_node *  n,
html_content content 
)
static

Complete construction of the box tree for an element.

Parameters
nDOM node to construct for
contentContaining document

This will be called after all children of an element have been processed

Definition at line 770 of file box_construct.c.

References box_add_child(), BOX_BR, box_construct_generate(), box_create(), box_extract_properties(), box_for_node(), BOX_INLINE, BOX_INLINE_CONTAINER, BOX_INLINE_END, box_construct_props::containing_block, CONVERT_CHILDREN, box::flags, box::href, box::id, box_construct_props::inline_container, box::inline_end, IS_REPLACED, box::style, box::styles, box::target, box::title, and box::type.

Referenced by next_node().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ box_construct_generate()

static void box_construct_generate ( dom_node *  n,
html_content content,
struct box box,
const css_computed_style *  style 
)
static

Construct the box required for a generated element.

Parameters
nXML node of type XML_ELEMENT_NODE
contentContent of type CONTENT_HTML that is being processed
boxBox which may have generated content
styleComplete computed style for pseudo element, or NULL
Todo:
This is currently incomplete. It just does enough to support the clearfix hack. (http://www.positioniseverything.net/easyclearing.html )
Todo:
Not wise to drop const from the computed style

Definition at line 312 of file box_construct.c.

References box_add_child(), BOX_BLOCK, box_create(), box_is_root(), box_map, ns_computed_display(), box::style, and box::type.

Referenced by box_construct_element(), and box_construct_element_after().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ box_construct_marker()

static bool box_construct_marker ( struct box box,
const char *  title,
struct box_construct_ctx ctx,
struct box parent 
)
static

Construct a list marker box.

Parameters
boxBox to attach marker to
titleCurrent title attribute
ctxBox construction context
parentCurrent block-level container
Returns
true on success, false on memory exhaustion
Todo:
marker content (list-style-type)

Definition at line 367 of file box_construct.c.

References box_construct_ctx::bctx, BOX_BLOCK, box_create(), box_construct_ctx::content, html_fetch_object(), image_types, box::length, box::list_marker, NSERROR_OK, nsoption_bool, nsurl_create(), nsurl_unref(), box::parent, box::style, box::text, box::title, and box::type.

Referenced by box_construct_element().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ box_construct_text()

static bool box_construct_text ( struct box_construct_ctx ctx)
static

Construct the box tree for an XML text node.

Parameters
ctxTree construction context
Returns
true on success, false on memory exhaustion
Todo:
Dropping const here is not clever
Todo:
Dropping const isn't clever

Definition at line 990 of file box_construct.c.

References box_construct_ctx::bctx, box_add_child(), box_create(), box_extract_properties(), BOX_INLINE_CONTAINER, BOX_TEXT, box_text_transform(), box_construct_props::containing_block, box::flags, box_construct_props::href, box_construct_props::inline_container, box::last, box::length, box_construct_ctx::n, box_construct_props::parent_style, PRE_STRIP, box::prev, box::space, squash_whitespace(), talloc_strdup(), box_construct_props::target, box::text, text(), box_construct_props::title, box::type, and UNKNOWN_WIDTH.

Referenced by convert_xml_to_box().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ box_extract_link()

bool box_extract_link ( const html_content content,
const dom_string *  dsrel,
nsurl base,
nsurl **  result 
)

Definition at line 1385 of file box_construct.c.

References ascii_is_space(), base, NSERROR_OK, nsurl_join(), and result.

Referenced by box_a(), box_create_frameset(), box_embed(), box_iframe(), box_image(), box_object(), and imagemap_addtolist().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ box_extract_properties()

static void box_extract_properties ( dom_node *  n,
struct box_construct_props props 
)
static

Extract transient construction properties.

Parameters
nCurrent DOM node to convert
propsProperty object to populate

Definition at line 154 of file box_construct.c.

References BOX_BR, box_for_node(), BOX_INLINE, BOX_INLINE_CONTAINER, box_is_root(), box_construct_props::containing_block, box::href, box_construct_props::href, box_construct_props::inline_container, box::last, box_construct_props::node_is_root, parent_node(), box_construct_props::parent_style, box::style, box::target, box_construct_props::target, box::title, box_construct_props::title, and box::type.

Referenced by box_construct_element(), box_construct_element_after(), and box_construct_text().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ box_for_node()

struct box * box_for_node ( struct dom_node *  node)

Retrieve the box for a dom node, if there is one.

Parameters
nodeThe DOM node
Returns
The box if there is one

Definition at line 1370 of file box_construct.c.

Referenced by box_construct_element_after(), box_extract_properties(), html_texty_element_update(), and next_node().

Here is the caller graph for this function:

◆ box_get_style()

static css_select_results * box_get_style ( html_content c,
const css_computed_style *  parent_style,
const css_computed_style *  root_style,
dom_node *  n 
)
static

Get the style for an element.

Parameters
ccontent of type CONTENT_HTML that is being processed
parent_stylestyle at this point in xml tree, or NULL for root
root_styleroot node's style, or NULL for root
nnode in xml tree
Returns
the new style, or NULL on memory exhaustion

Definition at line 247 of file box_construct.c.

References nscss_select_ctx::base_url, html_content::base_url, nscss_select_ctx::ctx, html_content::encoding, html_content::media, nscss_create_inline_style(), nscss_get_style(), nsoption_bool, nsurl_access(), nscss_select_ctx::parent_style, nscss_select_ctx::quirks, html_content::quirks, nscss_select_ctx::root_style, html_content::select_ctx, box::styles, html_content::unit_len_ctx, nscss_select_ctx::universal, and html_content::universal.

Referenced by box_construct_element().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ box_is_root()

static bool box_is_root ( dom_node *  n)
inlinestatic

determine if a box is the root node

Parameters
nnode to check
Returns
true if node is root else false.

Definition at line 122 of file box_construct.c.

References parent, and type.

Referenced by box_construct_generate(), box_extract_properties(), and next_node().

Here is the caller graph for this function:

◆ box_text_transform()

static void box_text_transform ( char *  s,
unsigned int  len,
enum css_text_transform_e  tt 
)
static

Apply the CSS text-transform property to given text for its ASCII chars.

Parameters
sstring to transform
lenlength of s
tttransform type

Definition at line 954 of file box_construct.c.

References ascii_is_space(), ascii_to_lower(), and ascii_to_upper().

Referenced by box_construct_text().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cancel_dom_to_box()

nserror cancel_dom_to_box ( void *  box_conversion_context)

aborts any ongoing box construction

Definition at line 1352 of file box_construct.c.

References convert_xml_to_box(), guit, netsurf_table::misc, box_construct_ctx::n, NSERROR_OK, and gui_misc_table::schedule.

Referenced by html_destroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ convert_xml_to_box()

static void convert_xml_to_box ( struct box_construct_ctx ctx)
static

Convert an ELEMENT node to a box tree fragment, then schedule conversion of the next ELEMENT node.

Todo:
Remove box_normalise_block

Definition at line 1231 of file box_construct.c.

References BOX_BLOCK, box_construct_element(), box_construct_text(), box_normalise_block(), box_construct_ctx::cb, box_construct_ctx::content, convert_xml_to_box(), guit, html_content::layout, netsurf_table::misc, box_construct_ctx::n, box::next, next_node(), box::parent, root, box_construct_ctx::root_box, gui_misc_table::schedule, and type.

Referenced by cancel_dom_to_box(), convert_xml_to_box(), and dom_to_box().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ dom_to_box()

nserror dom_to_box ( struct dom_node *  n,
struct html_content c,
box_construct_complete_cb  cb,
void **  box_conversion_context 
)

Construct a box tree from a dom and html content.

Parameters
ndom document
ccontent of type CONTENT_HTML to construct box tree in
cbcallback to report conversion completion
box_conversion_contextpointer that recives the conversion context
Returns
netsurf error code indicating status of call

Definition at line 1317 of file box_construct.c.

References box_construct_ctx::bctx, html_content::bctx, box_construct_ctx::cb, box_construct_ctx::content, convert_xml_to_box(), guit, netsurf_table::misc, box_construct_ctx::n, NSERROR_NOMEM, box_construct_ctx::root_box, gui_misc_table::schedule, and talloc_zero.

Referenced by html_finish_conversion().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ next_node()

static dom_node * next_node ( dom_node *  n,
html_content content,
bool  convert_children 
)
static

Find the next node in the DOM tree, completing element construction where appropriate.

Parameters
nCurrent node
contentContaining content
convert_childrenWhether to consider children of n
Returns
Next node to process, or NULL if complete
Note
n will be unreferenced

Definition at line 842 of file box_construct.c.

References box_construct_element_after(), box_for_node(), box_is_root(), box::next, and parent.

Referenced by convert_xml_to_box(), and libdom_find_first_element().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ box_map

const box_type box_map[]
static
Initial value:
= {
}
@ BOX_BLOCK
Definition: box.h:56
@ BOX_INLINE_BLOCK
Definition: box.h:65
@ BOX_TABLE_CELL
Definition: box.h:61
@ BOX_TABLE_ROW_GROUP
Definition: box.h:62
@ BOX_TABLE
Definition: box.h:59
@ BOX_INLINE
Definition: box.h:58
@ BOX_TABLE_ROW
Definition: box.h:60
@ BOX_INLINE_FLEX
Definition: box.h:71
@ BOX_FLEX
Definition: box.h:70
@ BOX_NONE
Definition: box.h:69

Definition at line 91 of file box_construct.c.

Referenced by box_construct_element(), and box_construct_generate().

◆ image_types

const content_type image_types = CONTENT_IMAGE
static