comparison src/styleengine.hh @ 1494:9225a90ad7dd

make Doctree a non-virtual class Doctree now is a proper class with it's own implementation. StyleEngine no longer needs to provide the Doctree interface itself. This hopefully make the code easier to understand and should also be a bit faster as no virtual methods are involved.
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Thu, 07 Jan 2010 16:23:05 +0100
parents 6ed936726b50
children b27cf7eb15b6
comparison
equal deleted inserted replaced
1493:a26f03ea99a8 1494:9225a90ad7dd
15 * by the HTML parser. 15 * by the HTML parser.
16 * The HTML parser in turn informs StyleEngine about opened or closed 16 * The HTML parser in turn informs StyleEngine about opened or closed
17 * HTML elements and their attributes via the startElement() / endElement() 17 * HTML elements and their attributes via the startElement() / endElement()
18 * methods. 18 * methods.
19 */ 19 */
20 class StyleEngine : public Doctree { 20 class StyleEngine {
21 private: 21 private:
22 class Node : public DoctreeNode { 22 class Node {
23 public: 23 public:
24 dw::core::style::Style *style; 24 dw::core::style::Style *style;
25 dw::core::style::Style *wordStyle; 25 dw::core::style::Style *wordStyle;
26 const char *styleAttribute; 26 const char *styleAttribute;
27 bool inheritBackgroundColor; 27 bool inheritBackgroundColor;
28 }; 28 };
29 29
30 dw::core::Layout *layout; 30 dw::core::Layout *layout;
31 lout::misc::SimpleVector <Node> *stack; 31 lout::misc::SimpleVector <Node> *stack;
32 CssContext *cssContext; 32 CssContext *cssContext;
33 int num; 33 Doctree *doctree;
34 int importDepth; 34 int importDepth;
35 35
36 dw::core::style::Style *style0 (CssPropertyList *nonCssHints = NULL); 36 dw::core::style::Style *style0 (CssPropertyList *nonCssHints = NULL);
37 dw::core::style::Style *wordStyle0 (CssPropertyList *nonCssHints = NULL); 37 dw::core::style::Style *wordStyle0 (CssPropertyList *nonCssHints = NULL);
38 void apply (dw::core::style::StyleAttrs *attrs, CssPropertyList *props); 38 void apply (dw::core::style::StyleAttrs *attrs, CssPropertyList *props);
47 47
48 public: 48 public:
49 StyleEngine (dw::core::Layout *layout); 49 StyleEngine (dw::core::Layout *layout);
50 ~StyleEngine (); 50 ~StyleEngine ();
51 51
52 /* Doctree interface */
53 inline const DoctreeNode *top () {
54 return stack->getRef (stack->size () - 1);
55 };
56
57 inline const DoctreeNode *parent (const DoctreeNode *n) {
58 if (n->depth > 1)
59 return stack->getRef (n->depth - 1);
60 else
61 return NULL;
62 };
63
64 void parse (DilloHtml *html, DilloUrl *url, const char *buf, int buflen, 52 void parse (DilloHtml *html, DilloUrl *url, const char *buf, int buflen,
65 CssOrigin origin); 53 CssOrigin origin);
66 void startElement (int tag); 54 void startElement (int tag);
67 void startElement (const char *tagname); 55 void startElement (const char *tagname);
68 void setId (const char *id); 56 void setId (const char *id);
69 const char * getId () { return top ()->id; }; 57 const char * getId () { return doctree->top ()->id; };
70 void setClass (const char *klass); 58 void setClass (const char *klass);
71 void setStyle (const char *style); 59 void setStyle (const char *style);
72 void endElement (int tag); 60 void endElement (int tag);
73 void setPseudoLink (); 61 void setPseudoLink ();
74 void setPseudoVisited (); 62 void setPseudoVisited ();