Dillo v3.1.1-91-g6d5b3ee3
Loading...
Searching...
No Matches
StyleEngine Class Reference

This class provides the glue between HTML parser and CSS subsystem. More...

#include <styleengine.hh>

Classes

struct  Node
 

Public Member Functions

 StyleEngine (dw::core::Layout *layout, const DilloUrl *pageUrl, const DilloUrl *baseUrl, float zoom)
 
 ~StyleEngine ()
 
void parse (DilloHtml *html, DilloUrl *url, const char *buf, int buflen, CssOrigin origin)
 
void startElement (int tag, BrowserWindow *bw)
 tell the styleEngine that a new html element has started.
 
void startElement (const char *tagname, BrowserWindow *bw)
 
void setId (const char *id)
 
const char * getId ()
 
void setClass (const char *klass)
 
void setStyle (const char *style)
 
void endElement (int tag)
 tell the styleEngine that a html element has ended.
 
void setPseudoLink ()
 set the CSS pseudo class :link.
 
void setPseudoVisited ()
 set the CSS pseudo class :visited.
 
void setNonCssHint (CssPropertyName name, CssValueType type, int value)
 
void setNonCssHint (CssPropertyName name, CssValueType type, const char *value)
 
void setNonCssHint (CssPropertyName name, CssValueType type, CssLength value)
 
void inheritNonCssHints ()
 Instruct StyleEngine to use the nonCssHints from parent element This is only used for tables where nonCssHints on the TABLE-element (e.g.
 
void clearNonCssHints ()
 
void restyle (BrowserWindow *bw)
 Recompute all style information from scratch This is used to take into account CSS styles for the HTML-element.
 
void inheritBackgroundColor ()
 Use of the background color of the parent style as default.
 
dw::core::style::StylebackgroundStyle (BrowserWindow *bw)
 Similar to StyleEngine::style(), but with backgroundColor set.
 
dw::core::style::ColorbackgroundColor ()
 
dw::core::style::StyleImagebackgroundImage (dw::core::style::BackgroundRepeat *bgRepeat, dw::core::style::BackgroundAttachment *bgAttachment, dw::core::style::Length *bgPositionX, dw::core::style::Length *bgPositionY)
 
dw::core::style::Stylestyle (BrowserWindow *bw)
 
dw::core::style::StylewordStyle (BrowserWindow *bw)
 

Static Public Member Functions

static void init ()
 Create the user agent style.
 

Private Member Functions

void stackPush ()
 
void stackPop ()
 
void buildUserStyle ()
 
dw::core::style::Stylestyle0 (int i, BrowserWindow *bw)
 Create a new style object based on the previously opened / closed HTML elements and the nonCssProperties that have been set.
 
dw::core::style::StylewordStyle0 (BrowserWindow *bw)
 
void setNonCssHint (CssPropertyName name, CssValueType type, CssPropertyValue value)
 
void preprocessAttrs (dw::core::style::StyleAttrs *attrs)
 
void postprocessAttrs (dw::core::style::StyleAttrs *attrs)
 
void apply (int i, dw::core::style::StyleAttrs *attrs, CssPropertyList *props, BrowserWindow *bw)
 Make changes to StyleAttrs attrs according to CssPropertyList props.
 
bool computeValue (int *dest, CssLength value, dw::core::style::Font *font)
 Resolve relative lengths to absolute values.
 
bool computeValue (int *dest, CssLength value, dw::core::style::Font *font, int percentageBase)
 
bool computeLength (dw::core::style::Length *dest, CssLength value, dw::core::style::Font *font)
 
void computeBorderWidth (int *dest, CssProperty *p, dw::core::style::Font *font)
 

Private Attributes

dw::core::Layoutlayout
 
lout::misc::SimpleVector< Node > * stack
 
CssContextcssContext
 
Doctreedoctree
 
int importDepth
 
float dpmm
 
float zoom
 
DilloUrlpageUrl
 
DilloUrlbaseUrl
 

Detailed Description

This class provides the glue between HTML parser and CSS subsystem.

It maintains a document tree and creates and caches style objects for use by the HTML parser. The HTML parser in turn informs StyleEngine about opened or closed HTML elements and their attributes via the startElement() / endElement() methods.

Definition at line 32 of file styleengine.hh.

Constructor & Destructor Documentation

◆ StyleEngine()

◆ ~StyleEngine()

StyleEngine::~StyleEngine ( )

Member Function Documentation

◆ apply()

void StyleEngine::apply ( int  i,
dw::core::style::StyleAttrs attrs,
CssPropertyList props,
BrowserWindow bw 
)
private

Make changes to StyleAttrs attrs according to CssPropertyList props.

Definition at line 364 of file styleengine.cc.

References a_Bw_add_client(), a_Bw_add_url(), a_Capi_open_url(), a_Image_new(), a_Image_ref(), a_Url_free(), a_Url_new(), a_Web_new(), DilloPrefs::allow_white_bg, dw::core::style::StyleAttrs::backgroundAttachment, dw::core::style::StyleAttrs::backgroundColor, dw::core::style::StyleAttrs::backgroundImage, dw::core::style::StyleAttrs::backgroundPositionX, dw::core::style::StyleAttrs::backgroundPositionY, dw::core::style::StyleAttrs::backgroundRepeat, dw::core::style::StyleAttrs::borderCollapse, dw::core::style::StyleAttrs::borderColor, dw::core::style::StyleAttrs::borderStyle, dw::core::style::StyleAttrs::borderWidth, dw::core::style::Box::bottom, dw::core::style::StyleAttrs::bottom, dw::core::style::StyleAttrs::clear, dw::core::style::StyleAttrs::color, computeBorderWidth(), computeLength(), computeValue(), lout::signal::ObservedObject::connectDeletion(), dw::core::style::StyleImage::create(), dw::core::style::Tooltip::create(), dw::core::style::Font::create(), dw::core::style::Color::create(), dw::core::style::createAbsLength(), dw::core::style::createPerLength(), CSS_FONT_SIZE_LARGE, CSS_FONT_SIZE_LARGER, CSS_FONT_SIZE_MEDIUM, CSS_FONT_SIZE_SMALL, CSS_FONT_SIZE_SMALLER, CSS_FONT_SIZE_X_LARGE, CSS_FONT_SIZE_X_SMALL, CSS_FONT_SIZE_XX_LARGE, CSS_FONT_SIZE_XX_SMALL, CSS_FONT_WEIGHT_BOLD, CSS_FONT_WEIGHT_BOLDER, CSS_FONT_WEIGHT_LIGHT, CSS_FONT_WEIGHT_LIGHTER, CSS_FONT_WEIGHT_NORMAL, CSS_LENGTH_TYPE(), CSS_LENGTH_TYPE_AUTO, CSS_LENGTH_TYPE_NONE, CSS_LENGTH_VALUE(), CSS_LETTER_SPACING_NORMAL, CSS_PROPERTY_BACKGROUND_ATTACHMENT, CSS_PROPERTY_BACKGROUND_COLOR, CSS_PROPERTY_BACKGROUND_IMAGE, CSS_PROPERTY_BACKGROUND_POSITION, CSS_PROPERTY_BACKGROUND_REPEAT, CSS_PROPERTY_BORDER_BOTTOM_COLOR, CSS_PROPERTY_BORDER_BOTTOM_STYLE, CSS_PROPERTY_BORDER_BOTTOM_WIDTH, CSS_PROPERTY_BORDER_COLLAPSE, CSS_PROPERTY_BORDER_LEFT_COLOR, CSS_PROPERTY_BORDER_LEFT_STYLE, CSS_PROPERTY_BORDER_LEFT_WIDTH, CSS_PROPERTY_BORDER_RIGHT_COLOR, CSS_PROPERTY_BORDER_RIGHT_STYLE, CSS_PROPERTY_BORDER_RIGHT_WIDTH, CSS_PROPERTY_BORDER_SPACING, CSS_PROPERTY_BORDER_TOP_COLOR, CSS_PROPERTY_BORDER_TOP_STYLE, CSS_PROPERTY_BORDER_TOP_WIDTH, CSS_PROPERTY_BOTTOM, CSS_PROPERTY_CLEAR, CSS_PROPERTY_COLOR, CSS_PROPERTY_CURSOR, CSS_PROPERTY_DISPLAY, CSS_PROPERTY_FLOAT, CSS_PROPERTY_FONT_FAMILY, CSS_PROPERTY_FONT_SIZE, CSS_PROPERTY_FONT_STYLE, CSS_PROPERTY_FONT_VARIANT, CSS_PROPERTY_FONT_WEIGHT, CSS_PROPERTY_HEIGHT, CSS_PROPERTY_LEFT, CSS_PROPERTY_LETTER_SPACING, CSS_PROPERTY_LINE_HEIGHT, CSS_PROPERTY_LIST_STYLE_POSITION, CSS_PROPERTY_LIST_STYLE_TYPE, CSS_PROPERTY_MARGIN_BOTTOM, CSS_PROPERTY_MARGIN_LEFT, CSS_PROPERTY_MARGIN_RIGHT, CSS_PROPERTY_MARGIN_TOP, CSS_PROPERTY_MAX_HEIGHT, CSS_PROPERTY_MAX_WIDTH, CSS_PROPERTY_MIN_HEIGHT, CSS_PROPERTY_MIN_WIDTH, CSS_PROPERTY_OVERFLOW, CSS_PROPERTY_PADDING_BOTTOM, CSS_PROPERTY_PADDING_LEFT, CSS_PROPERTY_PADDING_RIGHT, CSS_PROPERTY_PADDING_TOP, CSS_PROPERTY_POSITION, CSS_PROPERTY_RIGHT, CSS_PROPERTY_TEXT_ALIGN, CSS_PROPERTY_TEXT_DECORATION, CSS_PROPERTY_TEXT_INDENT, CSS_PROPERTY_TEXT_TRANSFORM, CSS_PROPERTY_TOP, CSS_PROPERTY_VERTICAL_ALIGN, CSS_PROPERTY_WHITE_SPACE, CSS_PROPERTY_WIDTH, CSS_PROPERTY_WORD_SPACING, CSS_PROPERTY_Z_INDEX, CSS_TYPE_ENUM, CSS_TYPE_LENGTH_PERCENTAGE_NUMBER, CSS_WORD_SPACING_NORMAL, dw::core::style::StyleAttrs::cursor, D_ASCII_TOLOWER, dw::core::style::StyleAttrs::display, dw::core::style::DISPLAY_NONE, dStrAsciiCasecmp(), dStrstrip(), dw::core::style::Font::exists(), _DilloWeb::flags, dw::core::style::StyleAttrs::font, DilloPrefs::font_cursive, DilloPrefs::font_factor, DilloPrefs::font_fantasy, DilloPrefs::font_max_size, DilloPrefs::font_min_size, DilloPrefs::font_monospace, DilloPrefs::font_sans_serif, DilloPrefs::font_serif, dw::core::style::FontAttrs::fontVariant, dw::core::style::StyleImage::getMainImgRenderer(), lout::misc::SimpleVector< T >::getRef(), dw::core::style::StyleAttrs::hBorderSpacing, dw::core::style::StyleAttrs::height, _DilloWeb::Image, image, CssPropertyValue::intVal, layout, dw::core::style::Box::left, dw::core::style::StyleAttrs::left, dw::core::style::LENGTH_AUTO, CssPropertyValue::lenVal, dw::core::style::FontAttrs::letterSpacing, dw::core::style::StyleAttrs::lineHeight, dw::core::style::StyleAttrs::listStylePosition, dw::core::style::StyleAttrs::listStyleType, DilloPrefs::load_background_images, dw::core::style::StyleAttrs::margin, dw::core::style::StyleAttrs::maxHeight, dw::core::style::StyleAttrs::maxWidth, dw::core::style::StyleAttrs::minHeight, dw::core::style::StyleAttrs::minWidth, dw::core::style::FontAttrs::name, CssProperty::name, dw::core::style::StyleAttrs::overflow, dw::core::style::StyleAttrs::padding, pageUrl, dw::core::style::StyleAttrs::position, CssPropertyValue::posVal, CssBackgroundPosition::posX, CssBackgroundPosition::posY, prefs, PROPERTY_X_IMG, PROPERTY_X_LANG, PROPERTY_X_LINK, PROPERTY_X_TOOLTIP, dw::core::style::Box::right, dw::core::style::StyleAttrs::right, lout::misc::roundInt(), dw::core::style::FontAttrs::size, lout::misc::SimpleVector< T >::size(), stack, CssPropertyValue::strVal, dw::core::style::FontAttrs::style, dw::core::style::StyleAttrs::textAlign, dw::core::style::StyleAttrs::textDecoration, dw::core::style::StyleAttrs::textIndent, dw::core::style::StyleAttrs::textTransform, dw::core::style::Box::top, dw::core::style::StyleAttrs::top, CssProperty::type, URL_FLAGS, URL_SpamSafe, dw::core::style::StyleAttrs::valign, CssProperty::value, dw::core::style::StyleAttrs::vBorderSpacing, dw::core::style::StyleAttrs::vloat, WEB_Image, dw::core::style::FontAttrs::weight, DilloPrefs::white_bg_replacement, dw::core::style::StyleAttrs::whiteSpace, dw::core::style::StyleAttrs::width, dw::core::style::StyleAttrs::wordSpacing, dw::core::style::StyleAttrs::x_img, dw::core::style::StyleAttrs::x_lang, dw::core::style::StyleAttrs::x_link, dw::core::style::StyleAttrs::x_tooltip, dw::core::style::Z_INDEX_AUTO, dw::core::style::StyleAttrs::zIndex, and zoom.

Referenced by style0().

◆ backgroundColor()

dw::core::style::Color * StyleEngine::backgroundColor ( )

◆ backgroundImage()

◆ backgroundStyle()

Style * StyleEngine::backgroundStyle ( BrowserWindow bw)

Similar to StyleEngine::style(), but with backgroundColor set.

A normal style might have backgroundColor == NULL to indicate a transparent background. This method ensures that backgroundColor is set.

Definition at line 900 of file styleengine.cc.

References dw::core::style::StyleAttrs::backgroundColor, dw::core::style::Style::create(), stack, and style().

Referenced by DilloHtml::backgroundStyle().

◆ buildUserStyle()

void StyleEngine::buildUserStyle ( )
private

◆ clearNonCssHints()

void StyleEngine::clearNonCssHints ( )

Definition at line 232 of file styleengine.cc.

References StyleEngine::Node::nonCssProperties, and stack.

Referenced by Html_tag_open_table().

◆ computeBorderWidth()

void StyleEngine::computeBorderWidth ( int *  dest,
CssProperty p,
dw::core::style::Font font 
)
private

◆ computeLength()

◆ computeValue() [1/2]

◆ computeValue() [2/2]

bool StyleEngine::computeValue ( int *  dest,
CssLength  value,
dw::core::style::Font font,
int  percentageBase 
)
private

◆ endElement()

void StyleEngine::endElement ( int  tag)

tell the styleEngine that a html element has ended.

Definition at line 299 of file styleengine.cc.

References doctree, DoctreeNode::element, Doctree::pop(), stackPop(), and Doctree::top().

Referenced by Html_real_pop_tag(), Html_tag_open_body(), and ~StyleEngine().

◆ getId()

const char * StyleEngine::getId ( )
inline

Definition at line 93 of file styleengine.hh.

References doctree, DoctreeNode::id, and Doctree::top().

Referenced by Html_process_tag(), and Html_tag_open_a().

◆ inheritBackgroundColor()

void StyleEngine::inheritBackgroundColor ( )

Use of the background color of the parent style as default.

This is only used in table code to allow for colors specified for table rows as table rows are currently no widgets and therefore don't draw any background.

Definition at line 245 of file styleengine.cc.

References lout::misc::SimpleVector< T >::getRef(), and stack.

Referenced by Html_tag_open_a(), Html_tag_open_abbr(), Html_tag_open_default(), Html_tag_open_dir(), Html_tag_open_dl(), Html_tag_open_dt(), Html_tag_open_pre(), Html_tag_open_q(), Html_tag_open_span(), and Html_tag_open_tr().

◆ inheritNonCssHints()

void StyleEngine::inheritNonCssHints ( )

Instruct StyleEngine to use the nonCssHints from parent element This is only used for tables where nonCssHints on the TABLE-element (e.g.

border=1) also affect child elements like TD.

Definition at line 216 of file styleengine.cc.

References CssPropertyList::apply(), StyleEngine::Node::nonCssProperties, and stack.

Referenced by Html_tag_open_table_cell(), and Html_tag_open_tr().

◆ init()

void StyleEngine::init ( )
static

Create the user agent style.

The user agent style defines how dillo renders HTML in the absence of author or user styles.

Definition at line 1020 of file styleengine.cc.

References CSS_ORIGIN_USER_AGENT, and CssParser::parse().

Referenced by main().

◆ parse()

void StyleEngine::parse ( DilloHtml html,
DilloUrl url,
const char *  buf,
int  buflen,
CssOrigin  origin 
)

Definition at line 1002 of file styleengine.cc.

References cssContext, importDepth, MSG_WARN, and CssParser::parse().

Referenced by a_Html_load_stylesheet(), and Html_tag_close_style().

◆ postprocessAttrs()

◆ preprocessAttrs()

◆ restyle()

void StyleEngine::restyle ( BrowserWindow bw)

Recompute all style information from scratch This is used to take into account CSS styles for the HTML-element.

The CSS data is only completely available after parsing the HEAD-section and thereby after the HTML-element has been opened. Note that restyle() does not change any styles in the widget tree.

Definition at line 982 of file styleengine.cc.

References StyleEngine::Node::backgroundStyle, stack, StyleEngine::Node::style, style0(), dw::core::style::Style::unref(), and StyleEngine::Node::wordStyle.

Referenced by DilloHtml::restyle().

◆ setClass()

void StyleEngine::setClass ( const char *  klass)

Definition at line 191 of file styleengine.cc.

References doctree, DoctreeNode::klass, splitStr(), and Doctree::top().

Referenced by Html_parse_common_attrs().

◆ setId()

void StyleEngine::setId ( const char *  id)

Definition at line 160 of file styleengine.cc.

References doctree, dStrdup(), DoctreeNode::id, and Doctree::top().

Referenced by Html_parse_common_attrs().

◆ setNonCssHint() [1/4]

void StyleEngine::setNonCssHint ( CssPropertyName  name,
CssValueType  type,
const char *  value 
)
inline

Definition at line 105 of file styleengine.hh.

References dStrdup(), setNonCssHint(), and CssPropertyValue::strVal.

◆ setNonCssHint() [2/4]

void StyleEngine::setNonCssHint ( CssPropertyName  name,
CssValueType  type,
CssLength  value 
)
inline

Definition at line 111 of file styleengine.hh.

References CssPropertyValue::lenVal, and setNonCssHint().

◆ setNonCssHint() [3/4]

◆ setNonCssHint() [4/4]

void StyleEngine::setNonCssHint ( CssPropertyName  name,
CssValueType  type,
int  value 
)
inline

Definition at line 99 of file styleengine.hh.

References CssPropertyValue::intVal, and setNonCssHint().

◆ setPseudoLink()

void StyleEngine::setPseudoLink ( )

◆ setPseudoVisited()

void StyleEngine::setPseudoVisited ( )

◆ setStyle()

◆ stackPop()

◆ stackPush()

void StyleEngine::stackPush ( )
private

Definition at line 117 of file styleengine.cc.

References stack.

Referenced by startElement(), and StyleEngine().

◆ startElement() [1/2]

void StyleEngine::startElement ( const char *  tagname,
BrowserWindow bw 
)

Definition at line 156 of file styleengine.cc.

References a_Html_tag_index(), and startElement().

◆ startElement() [2/2]

void StyleEngine::startElement ( int  tag,
BrowserWindow bw 
)

◆ style()

dw::core::style::Style * StyleEngine::style ( BrowserWindow bw)
inline

◆ style0()

Style * StyleEngine::style0 ( int  i,
BrowserWindow bw 
)
private

Create a new style object based on the previously opened / closed HTML elements and the nonCssProperties that have been set.

This method is private. Call style() to get a current style object.

Definition at line 919 of file styleengine.cc.

References CssContext::apply(), apply(), dw::core::style::Style::create(), cssContext, doctree, lout::misc::SimpleVector< T >::getRef(), postprocessAttrs(), preprocessAttrs(), dw::core::style::StyleAttrs::resetValues(), and stack.

Referenced by restyle(), and style().

◆ wordStyle()

dw::core::style::Style * StyleEngine::wordStyle ( BrowserWindow bw)
inline

Definition at line 137 of file styleengine.hh.

References stack, and wordStyle0().

Referenced by DilloHtml::wordStyle().

◆ wordStyle0()

Member Data Documentation

◆ baseUrl

DilloUrl * StyleEngine::baseUrl
private

Definition at line 53 of file styleengine.hh.

Referenced by setStyle(), StyleEngine(), and ~StyleEngine().

◆ cssContext

CssContext* StyleEngine::cssContext
private

Definition at line 48 of file styleengine.hh.

Referenced by buildUserStyle(), parse(), style0(), StyleEngine(), and ~StyleEngine().

◆ doctree

Doctree* StyleEngine::doctree
private

◆ dpmm

float StyleEngine::dpmm
private

Definition at line 51 of file styleengine.hh.

Referenced by computeValue(), and StyleEngine().

◆ importDepth

int StyleEngine::importDepth
private

Definition at line 50 of file styleengine.hh.

Referenced by parse(), and StyleEngine().

◆ layout

dw::core::Layout* StyleEngine::layout
private

Definition at line 46 of file styleengine.hh.

Referenced by apply(), computeValue(), and StyleEngine().

◆ pageUrl

DilloUrl* StyleEngine::pageUrl
private

Definition at line 53 of file styleengine.hh.

Referenced by apply(), StyleEngine(), and ~StyleEngine().

◆ stack

◆ zoom

float StyleEngine::zoom
private

Definition at line 52 of file styleengine.hh.

Referenced by apply(), computeValue(), and StyleEngine().


The documentation for this class was generated from the following files: