annotate src/styleengine.hh @ 2084:5b8e5855ab8e

support !important in style attributes
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Tue, 07 Jun 2011 12:06:52 +0200
parents 4779a3d891a1
children
rev   line source
497
96713a0f5d8b css.[ch][ch] -> styleengine.[ch][ch]
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 495
diff changeset
1 #ifndef __STYLEENGINE_HH__
96713a0f5d8b css.[ch][ch] -> styleengine.[ch][ch]
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 495
diff changeset
2 #define __STYLEENGINE_HH__
493
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
3
1035
474b9814a8fa support CSS @import directive
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 990
diff changeset
4 class StyleEngine;
474b9814a8fa support CSS @import directive
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 990
diff changeset
5
493
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
6 #include "dw/core.hh"
501
424e4f409636 add doctree.hh
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 499
diff changeset
7 #include "doctree.hh"
506
03de2284bfa6 switch to original enum names from dillo-0.8.0-css-3
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
8 #include "css.hh"
643
eb0279297fde hook up <style>...</style> parsing
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 631
diff changeset
9 #include "cssparser.hh"
493
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
10
1049
a913df1621ac comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1039
diff changeset
11 /**
a913df1621ac comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1039
diff changeset
12 * \brief This class provides the glue between HTML parser and CSS subsystem.
a913df1621ac comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1039
diff changeset
13 *
1083
a7f1763fd21e spelling
corvid <corvid@lavabit.com>
parents: 1049
diff changeset
14 * It maintains a document tree and creates and caches style objects for use
1049
a913df1621ac comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1039
diff changeset
15 * by the HTML parser.
a913df1621ac comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1039
diff changeset
16 * The HTML parser in turn informs StyleEngine about opened or closed
a913df1621ac comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1039
diff changeset
17 * HTML elements and their attributes via the startElement() / endElement()
a913df1621ac comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1039
diff changeset
18 * methods.
a913df1621ac comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1039
diff changeset
19 */
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
20 class StyleEngine {
493
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
21 private:
1731
92b899247f72 make StyleEngine::Node a struct - it's just that anyway
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1711
diff changeset
22 struct Node {
1732
3e3630a58627 store style attribute as CssPropertyList instead of a string
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1731
diff changeset
23 CssPropertyList *styleAttrProperties;
2084
5b8e5855ab8e support !important in style attributes
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1770
diff changeset
24 CssPropertyList *styleAttrPropertiesImportant;
1732
3e3630a58627 store style attribute as CssPropertyList instead of a string
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1731
diff changeset
25 CssPropertyList *nonCssProperties;
1731
92b899247f72 make StyleEngine::Node a struct - it's just that anyway
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1711
diff changeset
26 dw::core::style::Style *style;
92b899247f72 make StyleEngine::Node a struct - it's just that anyway
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1711
diff changeset
27 dw::core::style::Style *wordStyle;
1746
ef983c0fe908 fix Style leaks in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1742
diff changeset
28 dw::core::style::Style *backgroundStyle;
1731
92b899247f72 make StyleEngine::Node a struct - it's just that anyway
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1711
diff changeset
29 bool inheritBackgroundColor;
1738
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1734
diff changeset
30 DoctreeNode *doctreeNode;
503
00b31843839b implement various apply() methods
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 501
diff changeset
31 };
00b31843839b implement various apply() methods
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 501
diff changeset
32
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 506
diff changeset
33 dw::core::Layout *layout;
503
00b31843839b implement various apply() methods
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 501
diff changeset
34 lout::misc::SimpleVector <Node> *stack;
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 506
diff changeset
35 CssContext *cssContext;
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
36 Doctree *doctree;
1035
474b9814a8fa support CSS @import directive
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 990
diff changeset
37 int importDepth;
493
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
38
1734
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
39 dw::core::style::Style *style0 (int i);
1733
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
40 dw::core::style::Style *wordStyle0 ();
1742
6ff5d5aeb9a5 inline setNonCssHint()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1738
diff changeset
41 inline void setNonCssHint(CssPropertyName name, CssValueType type,
6ff5d5aeb9a5 inline setNonCssHint()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1738
diff changeset
42 CssPropertyValue value) {
6ff5d5aeb9a5 inline setNonCssHint()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1738
diff changeset
43 Node *n = stack->getRef (stack->size () - 1);
6ff5d5aeb9a5 inline setNonCssHint()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1738
diff changeset
44
6ff5d5aeb9a5 inline setNonCssHint()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1738
diff changeset
45 if (!n->nonCssProperties)
6ff5d5aeb9a5 inline setNonCssHint()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1738
diff changeset
46 n->nonCssProperties = new CssPropertyList (true);
1770
4779a3d891a1 trim some spaces
corvid <corvid@lavabit.com>
parents: 1746
diff changeset
47 n->nonCssProperties->set(name, type, value);
1742
6ff5d5aeb9a5 inline setNonCssHint()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1738
diff changeset
48 }
1711
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1494
diff changeset
49 void preprocessAttrs (dw::core::style::StyleAttrs *attrs);
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1494
diff changeset
50 void postprocessAttrs (dw::core::style::StyleAttrs *attrs);
1738
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1734
diff changeset
51 void apply (int i, dw::core::style::StyleAttrs *attrs, CssPropertyList *props);
1039
4ed33b76809c wrap long lines in src/ css code
corvid <corvid@lavabit.com>
parents: 1035
diff changeset
52 bool computeValue (int *dest, CssLength value,
4ed33b76809c wrap long lines in src/ css code
corvid <corvid@lavabit.com>
parents: 1035
diff changeset
53 dw::core::style::Font *font);
4ed33b76809c wrap long lines in src/ css code
corvid <corvid@lavabit.com>
parents: 1035
diff changeset
54 bool computeValue (int *dest, CssLength value,
4ed33b76809c wrap long lines in src/ css code
corvid <corvid@lavabit.com>
parents: 1035
diff changeset
55 dw::core::style::Font *font, int percentageBase);
990
36d9fee90159 whitespace
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 982
diff changeset
56 bool computeLength (dw::core::style::Length *dest, CssLength value,
36d9fee90159 whitespace
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 982
diff changeset
57 dw::core::style::Font *font);
1472
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1083
diff changeset
58 void computeBorderWidth (int *dest, CssProperty *p,
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1083
diff changeset
59 dw::core::style::Font *font);
506
03de2284bfa6 switch to original enum names from dillo-0.8.0-css-3
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
60
493
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
61 public:
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 506
diff changeset
62 StyleEngine (dw::core::Layout *layout);
493
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
63 ~StyleEngine ();
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 901
diff changeset
64
1039
4ed33b76809c wrap long lines in src/ css code
corvid <corvid@lavabit.com>
parents: 1035
diff changeset
65 void parse (DilloHtml *html, DilloUrl *url, const char *buf, int buflen,
4ed33b76809c wrap long lines in src/ css code
corvid <corvid@lavabit.com>
parents: 1035
diff changeset
66 CssOrigin origin);
598
4ff90b6242f9 fix id, class, style attribute handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 590
diff changeset
67 void startElement (int tag);
982
d04d960da3f4 remove bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 956
diff changeset
68 void startElement (const char *tagname);
598
4ff90b6242f9 fix id, class, style attribute handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 590
diff changeset
69 void setId (const char *id);
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
70 const char * getId () { return doctree->top ()->id; };
598
4ff90b6242f9 fix id, class, style attribute handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 590
diff changeset
71 void setClass (const char *klass);
4ff90b6242f9 fix id, class, style attribute handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 590
diff changeset
72 void setStyle (const char *style);
495
7224de9c34b7 add StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 493
diff changeset
73 void endElement (int tag);
679
14ce954d98c0 inherit pseudo classes "link" and "visited"
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 664
diff changeset
74 void setPseudoLink ();
14ce954d98c0 inherit pseudo classes "link" and "visited"
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 664
diff changeset
75 void setPseudoVisited ();
1742
6ff5d5aeb9a5 inline setNonCssHint()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1738
diff changeset
76 inline void setNonCssHint(CssPropertyName name, CssValueType type,
6ff5d5aeb9a5 inline setNonCssHint()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1738
diff changeset
77 int value) {
1733
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
78 CssPropertyValue v;
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
79 v.intVal = value;
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
80 setNonCssHint (name, type, v);
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
81 }
1742
6ff5d5aeb9a5 inline setNonCssHint()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1738
diff changeset
82 inline void setNonCssHint(CssPropertyName name, CssValueType type,
6ff5d5aeb9a5 inline setNonCssHint()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1738
diff changeset
83 const char *value) {
1733
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
84 CssPropertyValue v;
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
85 v.strVal = dStrdup(value);
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
86 setNonCssHint (name, type, v);
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
87 }
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
88 void inheritNonCssHints ();
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
89 void clearNonCssHints ();
1734
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
90 void restyle ();
664
109eaf60aea2 add comment about inheritBackgroundColor()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 659
diff changeset
91 void inheritBackgroundColor (); /* \todo get rid of this somehow */
956
dd46fa6ceb94 fix missing background color for ComplexButton (noticed by corvid)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 930
diff changeset
92 dw::core::style::Style *backgroundStyle ();
1738
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1734
diff changeset
93 dw::core::style::Color *backgroundColor ();
503
00b31843839b implement various apply() methods
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 501
diff changeset
94
00b31843839b implement various apply() methods
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 501
diff changeset
95 inline dw::core::style::Style *style () {
506
03de2284bfa6 switch to original enum names from dillo-0.8.0-css-3
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
96 dw::core::style::Style *s = stack->getRef (stack->size () - 1)->style;
03de2284bfa6 switch to original enum names from dillo-0.8.0-css-3
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
97 if (s)
03de2284bfa6 switch to original enum names from dillo-0.8.0-css-3
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
98 return s;
03de2284bfa6 switch to original enum names from dillo-0.8.0-css-3
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
99 else
1734
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
100 return style0 (stack->size () - 1);
503
00b31843839b implement various apply() methods
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 501
diff changeset
101 };
990
36d9fee90159 whitespace
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 982
diff changeset
102
644
9e4ad941cbdc add wordStyle() method to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 643
diff changeset
103 inline dw::core::style::Style *wordStyle () {
1039
4ed33b76809c wrap long lines in src/ css code
corvid <corvid@lavabit.com>
parents: 1035
diff changeset
104 dw::core::style::Style *s = stack->getRef(stack->size()-1)->wordStyle;
644
9e4ad941cbdc add wordStyle() method to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 643
diff changeset
105 if (s)
9e4ad941cbdc add wordStyle() method to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 643
diff changeset
106 return s;
9e4ad941cbdc add wordStyle() method to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 643
diff changeset
107 else
9e4ad941cbdc add wordStyle() method to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 643
diff changeset
108 return wordStyle0 ();
9e4ad941cbdc add wordStyle() method to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 643
diff changeset
109 };
493
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
110 };
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
111
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
112 #endif