From f815ca9e7f27a8fc4a8230413ecac8ad2b2e0621 Mon Sep 17 00:00:00 2001 From: Sebastian Geerken Date: Fri, 20 Sep 2013 09:40:14 +0200 Subject: Added BrowserWindow and DilloURL (base URL) to StyleEngine::apply and related. --- src/html_common.hh | 14 ++++++++------ src/plain.cc | 7 ++++--- src/styleengine.cc | 32 +++++++++++++++++--------------- src/styleengine.hh | 25 ++++++++++++++----------- src/web.cc | 4 ++-- 5 files changed, 45 insertions(+), 37 deletions(-) diff --git a/src/html_common.hh b/src/html_common.hh index a2d13bf1..a43d91b7 100644 --- a/src/html_common.hh +++ b/src/html_common.hh @@ -220,17 +220,19 @@ public: void addCssUrl(const DilloUrl *url); // useful shortcuts - inline void startElement (int tag) { styleEngine->startElement (tag); } + inline void startElement (int tag) + { styleEngine->startElement (tag, bw, base_url); } inline void startElement (const char *tagname) - { styleEngine->startElement (tagname); } + { styleEngine->startElement (tagname, bw, base_url); } inline dw::core::style::Style *backgroundStyle () - { return styleEngine->backgroundStyle (); } - inline dw::core::style::Style *style () { return styleEngine->style (); } + { return styleEngine->backgroundStyle (bw, base_url); } + inline dw::core::style::Style *style () + { return styleEngine->style (bw, base_url); } inline dw::core::style::Style *wordStyle () - { return styleEngine->wordStyle (); } + { return styleEngine->wordStyle (bw, base_url); } - inline void restyle () { styleEngine->restyle (); } + inline void restyle () { styleEngine->restyle (bw, base_url); } }; diff --git a/src/plain.cc b/src/plain.cc index d63ce6cf..d09f6d79 100644 --- a/src/plain.cc +++ b/src/plain.cc @@ -97,9 +97,10 @@ DilloPlain::DilloPlain(BrowserWindow *p_bw) Layout *layout = (Layout*) bw->render_layout; StyleEngine styleEngine (layout); - styleEngine.startElement ("body"); - styleEngine.startElement ("pre"); - widgetStyle = styleEngine.wordStyle (); + // TODO (3x) No URL? + styleEngine.startElement ("body", bw, NULL); + styleEngine.startElement ("pre", bw, NULL); + widgetStyle = styleEngine.wordStyle (bw, NULL); widgetStyle->ref (); /* The context menu */ diff --git a/src/styleengine.cc b/src/styleengine.cc index 47bf6240..af5623c2 100644 --- a/src/styleengine.cc +++ b/src/styleengine.cc @@ -92,8 +92,8 @@ void StyleEngine::stackPop () { /** * \brief tell the styleEngine that a new html element has started. */ -void StyleEngine::startElement (int element) { - style (); // ensure that style of current node is computed +void StyleEngine::startElement (int element, BrowserWindow *bw, DilloUrl *url) { + style (bw, url); // ensure that style of current node is computed stackPush (); Node *n = stack->getLastRef (); @@ -103,8 +103,9 @@ void StyleEngine::startElement (int element) { n->doctreeNode = dn; } -void StyleEngine::startElement (const char *tagname) { - startElement (a_Html_tag_index (tagname)); +void StyleEngine::startElement (const char *tagname, BrowserWindow *bw, + DilloUrl *url) { + startElement (a_Html_tag_index (tagname), bw, url); } void StyleEngine::setId (const char *id) { @@ -281,7 +282,8 @@ void StyleEngine::postprocessAttrs (dw::core::style::StyleAttrs *attrs) { /** * \brief Make changes to StyleAttrs attrs according to CssPropertyList props. */ -void StyleEngine::apply (int i, StyleAttrs *attrs, CssPropertyList *props) { +void StyleEngine::apply (int i, StyleAttrs *attrs, CssPropertyList *props, + BrowserWindow *bw, DilloUrl *url) { FontAttrs fontAttrs = *attrs->font; Font *parentFont = stack->get (i - 1).style->font; char *c, *fontName; @@ -706,9 +708,9 @@ void StyleEngine::computeBorderWidth (int *dest, CssProperty *p, * A normal style might have backgroundColor == NULL to indicate a transparent * background. This method ensures that backgroundColor is set. */ -Style * StyleEngine::backgroundStyle () { +Style * StyleEngine::backgroundStyle (BrowserWindow *bw, DilloUrl *url) { if (!stack->getRef (stack->size () - 1)->backgroundStyle) { - StyleAttrs attrs = *style (); + StyleAttrs attrs = *style (bw, url); for (int i = stack->size () - 1; i >= 0 && ! attrs.backgroundColor; i--) attrs.backgroundColor = stack->getRef (i)->style->backgroundColor; @@ -725,7 +727,7 @@ Style * StyleEngine::backgroundStyle () { * HTML elements and the nonCssProperties that have been set. * This method is private. Call style() to get a current style object. */ -Style * StyleEngine::style0 (int i) { +Style * StyleEngine::style0 (int i, BrowserWindow *bw, DilloUrl *url) { CssPropertyList props, *styleAttrProperties, *styleAttrPropertiesImportant; CssPropertyList *nonCssProperties; // get previous style from the stack @@ -753,7 +755,7 @@ Style * StyleEngine::style0 (int i) { nonCssProperties); // apply style - apply (i, &attrs, &props); + apply (i, &attrs, &props, bw, url); postprocessAttrs (&attrs); @@ -762,14 +764,14 @@ Style * StyleEngine::style0 (int i) { return stack->getRef (i)->style; } -Style * StyleEngine::wordStyle0 () { - StyleAttrs attrs = *style (); +Style * StyleEngine::wordStyle0 (BrowserWindow *bw, DilloUrl *url) { + StyleAttrs attrs = *style (bw, url); attrs.resetValues (); if (stack->getRef (stack->size() - 1)->inheritBackgroundColor) - attrs.backgroundColor = style ()->backgroundColor; + attrs.backgroundColor = style (bw, url)->backgroundColor; - attrs.valign = style ()->valign; + attrs.valign = style (bw, url)->valign; stack->getRef(stack->size() - 1)->wordStyle = Style::create(&attrs); return stack->getRef (stack->size () - 1)->wordStyle; @@ -782,7 +784,7 @@ Style * StyleEngine::wordStyle0 () { * and thereby after the HTML-element has been opened. * Note that restyle() does not change any styles in the widget tree. */ -void StyleEngine::restyle () { +void StyleEngine::restyle (BrowserWindow *bw, DilloUrl *url) { for (int i = 1; i < stack->size (); i++) { Node *n = stack->getRef (i); if (n->style) { @@ -798,7 +800,7 @@ void StyleEngine::restyle () { n->backgroundStyle = NULL; } - style0 (i); + style0 (i, bw, url); } } diff --git a/src/styleengine.hh b/src/styleengine.hh index 237008a6..14222f35 100644 --- a/src/styleengine.hh +++ b/src/styleengine.hh @@ -40,8 +40,8 @@ class StyleEngine { void stackPop (); void buildUserAgentStyle (); void buildUserStyle (); - dw::core::style::Style *style0 (int i); - dw::core::style::Style *wordStyle0 (); + dw::core::style::Style *style0 (int i, BrowserWindow *bw, DilloUrl *url); + dw::core::style::Style *wordStyle0 (BrowserWindow *bw, DilloUrl *url); inline void setNonCssHint(CssPropertyName name, CssValueType type, CssPropertyValue value) { Node *n = stack->getRef (stack->size () - 1); @@ -52,7 +52,8 @@ class StyleEngine { } 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); + void apply (int i, dw::core::style::StyleAttrs *attrs, + CssPropertyList *props, BrowserWindow *bw, DilloUrl *url); bool computeValue (int *dest, CssLength value, dw::core::style::Font *font); bool computeValue (int *dest, CssLength value, @@ -68,8 +69,8 @@ class StyleEngine { void parse (DilloHtml *html, DilloUrl *url, const char *buf, int buflen, CssOrigin origin); - void startElement (int tag); - void startElement (const char *tagname); + void startElement (int tag, BrowserWindow *bw, DilloUrl *url); + void startElement (const char *tagname, BrowserWindow *bw, DilloUrl *url); void setId (const char *id); const char * getId () { return doctree->top ()->id; }; void setClass (const char *klass); @@ -91,25 +92,27 @@ class StyleEngine { } void inheritNonCssHints (); void clearNonCssHints (); - void restyle (); + void restyle (BrowserWindow *bw, DilloUrl *url); void inheritBackgroundColor (); /* \todo get rid of this somehow */ - dw::core::style::Style *backgroundStyle (); + dw::core::style::Style *backgroundStyle (BrowserWindow *bw, + DilloUrl *url); dw::core::style::Color *backgroundColor (); - inline dw::core::style::Style *style () { + inline dw::core::style::Style *style (BrowserWindow *bw, DilloUrl *url) { dw::core::style::Style *s = stack->getRef (stack->size () - 1)->style; if (s) return s; else - return style0 (stack->size () - 1); + return style0 (stack->size () - 1, bw, url); }; - inline dw::core::style::Style *wordStyle () { + inline dw::core::style::Style *wordStyle (BrowserWindow *bw, + DilloUrl *url) { dw::core::style::Style *s = stack->getRef(stack->size()-1)->wordStyle; if (s) return s; else - return wordStyle0 (); + return wordStyle0 (bw, url); }; }; diff --git a/src/web.cc b/src/web.cc index fcc65af8..a469ccb2 100644 --- a/src/web.cc +++ b/src/web.cc @@ -70,13 +70,13 @@ int a_Web_dispatch_by_type (const char *Type, DilloWeb *Web, /* Set a style for the widget */ StyleEngine styleEngine (layout); - styleEngine.startElement ("body"); + styleEngine.startElement ("body", Web->bw, Web->url); dw = (Widget*) viewer(Type, Web, Call, Data); if (dw == NULL) return -1; - dw->setStyle (styleEngine.style ()); + dw->setStyle (styleEngine.style (Web->bw, Web->url)); /* This method frees the old dw if any */ layout->setWidget(dw); -- cgit v1.2.3