changeset 509:fd2454cd0120

pass Layout to StyleEngine
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Wed, 29 Oct 2008 19:03:43 +0100
parents 61d1a4c74690
children 2bc3d207f5ad
files src/css.cc src/css.hh src/doctree.hh src/html.cc src/styleengine.cc src/styleengine.hh
diffstat 6 files changed, 74 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/css.cc	Wed Oct 29 18:24:05 2008 +0100
+++ b/src/css.cc	Wed Oct 29 19:03:43 2008 +0100
@@ -13,7 +13,7 @@
 #include "css.hh"
 
 /** \todo dummy only */
-CssPropertyList *CssPropertyList::parse (const char *buf, int buflen) {
+CssPropertyList *CssPropertyList::parse (const char *buf) {
    return NULL;
 }
 
@@ -35,13 +35,13 @@
 }
 
 /** \todo dummy only */
-CssSelector *CssSelector::parse (const char *buf, int buflen) {
+CssSelector *CssSelector::parse (const char *buf) {
    return NULL;
 }
 
 /** \todo dummy only */
 bool CssSelector::match (Doctree *docTree) {
-   return tagIndex < 0 || tagIndex == docTree->top ()->tagIndex;
+   return tag < 0 || tag == docTree->top ()->tag;
 }
 
 void CssRule::apply (CssPropertyList *props, Doctree *docTree) {
--- a/src/css.hh	Wed Oct 29 18:24:05 2008 +0100
+++ b/src/css.hh	Wed Oct 29 19:03:43 2008 +0100
@@ -116,7 +116,7 @@
    public:
       CssPropertyList() : lout::misc::SimpleVector <CssProperty> (1) {};
 
-      static CssPropertyList *parse (const char *buf, int buflen);
+      static CssPropertyList *parse (const char *buf);
       void set (CssProperty::Name name, CssProperty::Value value);
       void apply (CssPropertyList *props);
 };
@@ -124,17 +124,17 @@
 /** \todo proper implementation */
 class CssSelector {
    private:
-      int tagIndex;
+      int tag;
       const char *klass, *id;
 
    public:
-      CssSelector (int tagIndex, const char *klass, const char *id) {
-         this->tagIndex = tagIndex;
+      CssSelector (int tag, const char *klass, const char *id) {
+         this->tag = tag;
          this->klass = klass;
          this->id = id;
       };
 
-      static CssSelector *parse (const char *buf, int buflen);
+      static CssSelector *parse (const char *buf);
 
       bool match (Doctree *dt);
 };
--- a/src/doctree.hh	Wed Oct 29 18:24:05 2008 +0100
+++ b/src/doctree.hh	Wed Oct 29 19:03:43 2008 +0100
@@ -4,7 +4,7 @@
 class DoctreeNode {
    public:
       int depth;
-      int tagIndex;
+      int tag;
       const char *klass;
       const char *id;
 };
--- a/src/html.cc	Wed Oct 29 18:24:05 2008 +0100
+++ b/src/html.cc	Wed Oct 29 19:03:43 2008 +0100
@@ -481,7 +481,7 @@
    stack->getRef(0)->current_bg_color = prefs.bg_color;
    stack->getRef(0)->hand_over_break = false;
 
-   styleEngine = new StyleEngine ();
+   styleEngine = new StyleEngine (HT2LT (this));
 
    InFlags = IN_NONE;
 
--- a/src/styleengine.cc	Wed Oct 29 18:24:05 2008 +0100
+++ b/src/styleengine.cc	Wed Oct 29 19:03:43 2008 +0100
@@ -12,8 +12,10 @@
 #include <stdio.h>
 #include "styleengine.hh"
 
-StyleEngine::StyleEngine () {
+StyleEngine::StyleEngine (dw::core::Layout *layout) {
    stack = new lout::misc::SimpleVector <Node> (1);
+   cssContext = new CssContext ();
+   this->layout = layout;
 }
 
 StyleEngine::~StyleEngine () {
@@ -21,11 +23,65 @@
 }
 
 void
-StyleEngine::startElement (int tag, const char *id, const char *klass, const char *style) {
+StyleEngine::startElement (int tag, const char *id, const char *klass,
+   const char *style) {
    fprintf(stderr, "===> START %d %s %s %s\n", tag, id, klass, style);
+
+   if (stack->getRef (stack->size () - 1)->style == NULL)
+      stack->getRef (stack->size () - 1)->style = style0 ();
+
+   stack->increase ();
+   Node *n =  stack->getRef (stack->size () - 1);
+   n->style = NULL;
+   n->nonCssProperties = NULL;
+   n->depth = stack->size ();
+   n->tag = tag;
+   n->id = id;
+   n->klass = klass;
+   n->styleAttribute = style;
+}
+
+void
+StyleEngine::setNonCssProperties (CssPropertyList *props) {
+   stack->getRef (stack->size () - 1)->nonCssProperties = props;
 }
 
 void
 StyleEngine::endElement (int tag) {
    fprintf(stderr, "===> END %d\n", tag);
+   stack->setSize (stack->size () - 1);
 }
+
+void StyleEngine::apply (dw::core::style::StyleAttrs *attr,
+   CssPropertyList *props) {
+
+   for (int i = 0; i < props->size (); i++) {
+      CssProperty *p = props->getRef (i);
+      
+      switch (p->name) {
+
+
+         default:
+            break;
+      }
+   }
+}
+
+dw::core::style::Style * StyleEngine::style0 () {
+   CssPropertyList props;
+   CssPropertyList *tagStyleProps = CssPropertyList::parse (
+      stack->getRef (stack->size () - 1)->styleAttribute);
+
+   dw::core::style::StyleAttrs attrs =
+      *stack->getRef (stack->size () - 1)->style;
+
+   cssContext->apply (&props, this, tagStyleProps,
+      stack->getRef (stack->size () - 1)->nonCssProperties);
+
+   apply (&attrs, &props);
+
+   stack->getRef (stack->size () - 1)->style =
+      dw::core::style::Style::create (layout, &attrs);
+   
+   return NULL;
+}
--- a/src/styleengine.hh	Wed Oct 29 18:24:05 2008 +0100
+++ b/src/styleengine.hh	Wed Oct 29 19:03:43 2008 +0100
@@ -10,14 +10,19 @@
       class Node : public DoctreeNode {
          public:
             dw::core::style::Style *style;
+            CssPropertyList *nonCssProperties;
+            const char *styleAttribute;
       };
 
+      dw::core::Layout *layout;
       lout::misc::SimpleVector <Node> *stack;
+      CssContext *cssContext;
 
       dw::core::style::Style *style0 ();
+      void apply (dw::core::style::StyleAttrs *attrs, CssPropertyList *props);
 
    public:
-      StyleEngine ();
+      StyleEngine (dw::core::Layout *layout);
       ~StyleEngine ();
    
       /* Doctree interface */