Mercurial > dillo_port1.3
changeset 514:18e895f547c5
fill userAgentStyle with test values
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> |
---|---|
date | Thu, 30 Oct 2008 16:07:53 +0100 |
parents | c82c5fd9b043 |
children | 7b3bbc2af326 |
files | src/css.cc src/css.hh |
diffstat | 2 files changed, 58 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/css.cc Wed Oct 29 19:34:46 2008 +0100 +++ b/src/css.cc Thu Oct 30 16:07:53 2008 +0100 @@ -10,6 +10,7 @@ */ #include <stdio.h> +#include "html_common.hh" #include "css.hh" /** \todo dummy only */ @@ -49,24 +50,63 @@ this->props->apply (props); } +void CssStyleSheet::addRule (CssSelector *selector, CssPropertyList *props) { + CssRule *rule = new CssRule (selector, props); + increase (); + set (size () - 1, rule); +} + void CssStyleSheet::apply (CssPropertyList *props, Doctree *docTree) { for (int i = 0; i < size (); i++) get (i)->apply (props, docTree); } -void CssContext::addRule (CssRule *rule, PrimaryOrder order) { - sheet[order].increase (); - sheet[order].set (sheet[order].size () - 1, rule); -}; +CssStyleSheet *CssContext::userAgentStyle; +CssStyleSheet *CssContext::userStyle; +CssStyleSheet *CssContext::userImportantStyle; + +CssContext::CssContext () { + for (int o = CSS_PRIMARY_USER_AGENT; o <= CSS_PRIMARY_USER_IMPORTANT; o++) + sheet[o] = NULL; + + if (userAgentStyle == NULL) { + userAgentStyle = buildUserAgentStyle (); + userStyle = buildUserStyle (false); + userImportantStyle = buildUserStyle (true); + } + + sheet[CSS_PRIMARY_USER_AGENT] = userAgentStyle; + sheet[CSS_PRIMARY_USER] = userStyle; + sheet[CSS_PRIMARY_USER_IMPORTANT] = userImportantStyle; +} void CssContext::apply (CssPropertyList *props, Doctree *docTree, CssPropertyList *tagStyle, CssPropertyList *nonCss) { - sheet[CSS_PRIMARY_USER_AGENT].apply (props, docTree); + sheet[CSS_PRIMARY_USER_AGENT]->apply (props, docTree); if (nonCss) nonCss->apply (props); for (int o = CSS_PRIMARY_USER; o <= CSS_PRIMARY_USER_IMPORTANT; o++) - sheet[o].apply (props, docTree); + if (sheet[o]) + sheet[o]->apply (props, docTree); if (tagStyle) nonCss->apply (props); } + +CssStyleSheet * CssContext::buildUserAgentStyle () { + CssStyleSheet *s = new CssStyleSheet (); + CssPropertyList *props; + CssProperty::Value v; + + props = new CssPropertyList (); + v.color = 13; + props->set (CssProperty::CSS_PROPERTY_BACKGROUND_COLOR, v); + v.size = 20; + props->set (CssProperty::CSS_PROPERTY_FONT_SIZE, v); + s->addRule (new CssSelector(a_Html_tag_index("a"), NULL, NULL), props); + return s; +} + +CssStyleSheet * CssContext::buildUserStyle (bool important) { + return NULL; +}
--- a/src/css.hh Wed Oct 29 19:34:46 2008 +0100 +++ b/src/css.hh Thu Oct 30 16:07:53 2008 +0100 @@ -155,9 +155,10 @@ void apply (CssPropertyList *props, Doctree *docTree); }; -class CssStyleSheet : public lout::misc::SimpleVector <CssRule*> { +class CssStyleSheet : lout::misc::SimpleVector <CssRule*> { public: CssStyleSheet() : lout::misc::SimpleVector <CssRule*> (1) {}; + void addRule (CssSelector *selector, CssPropertyList *props); void apply (CssPropertyList *props, Doctree *docTree); }; @@ -172,9 +173,18 @@ } PrimaryOrder; private: - CssStyleSheet sheet[CSS_PRIMARY_USER_IMPORTANT + 1]; + static CssStyleSheet *userAgentStyle; + static CssStyleSheet *userStyle; + static CssStyleSheet *userImportantStyle; + CssStyleSheet *sheet[CSS_PRIMARY_USER_IMPORTANT + 1]; + + CssStyleSheet *buildUserAgentStyle (); + CssStyleSheet *buildUserStyle (bool important); public: + CssContext (); + ~CssContext (); + void addRule (CssRule *rule, PrimaryOrder order); void apply (CssPropertyList *props, Doctree *docTree,