Mercurial > dillo_port1.3
annotate src/styleengine.hh @ 1733:f39cfc38ea10
rework nonCssHints API of StyleEngine
* Instead of passing the nonCssHints as a CssPropertyList, set the hints
separately and create the list in StyleEngine.
* The CssPropertyList holding the nonCssHints is now completely managed
by StyleEngine and kept on the stack.
* Replace the table_cell_props mechanic in html.cc/table.cc with a
new method inheritNonCssHints() in StyleEngine.
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> |
---|---|
date | Mon, 11 Oct 2010 21:35:53 +0200 |
parents | 3e3630a58627 |
children | 90feb0de4310 |
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 | 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 | 6 #include "dw/core.hh" |
501 | 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 | 10 |
1049 | 11 /** |
12 * \brief This class provides the glue between HTML parser and CSS subsystem. | |
13 * | |
1083 | 14 * It maintains a document tree and creates and caches style objects for use |
1049 | 15 * by the HTML parser. |
16 * The HTML parser in turn informs StyleEngine about opened or closed | |
17 * HTML elements and their attributes via the startElement() / endElement() | |
18 * methods. | |
19 */ | |
1494
9225a90ad7dd
make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1472
diff
changeset
|
20 class StyleEngine { |
493 | 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; |
3e3630a58627
store style attribute as CssPropertyList instead of a string
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1731
diff
changeset
|
24 CssPropertyList *nonCssProperties; |
1731
92b899247f72
make StyleEngine::Node a struct - it's just that anyway
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1711
diff
changeset
|
25 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
|
26 dw::core::style::Style *wordStyle; |
92b899247f72
make StyleEngine::Node a struct - it's just that anyway
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1711
diff
changeset
|
27 bool inheritBackgroundColor; |
503
00b31843839b
implement various apply() methods
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
501
diff
changeset
|
28 }; |
00b31843839b
implement various apply() methods
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
501
diff
changeset
|
29 |
509
fd2454cd0120
pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
506
diff
changeset
|
30 dw::core::Layout *layout; |
503
00b31843839b
implement various apply() methods
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
501
diff
changeset
|
31 lout::misc::SimpleVector <Node> *stack; |
509
fd2454cd0120
pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
506
diff
changeset
|
32 CssContext *cssContext; |
1494
9225a90ad7dd
make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1472
diff
changeset
|
33 Doctree *doctree; |
1035
474b9814a8fa
support CSS @import directive
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
990
diff
changeset
|
34 int importDepth; |
493 | 35 |
1733
f39cfc38ea10
rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1732
diff
changeset
|
36 dw::core::style::Style *style0 (); |
f39cfc38ea10
rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1732
diff
changeset
|
37 dw::core::style::Style *wordStyle0 (); |
f39cfc38ea10
rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1732
diff
changeset
|
38 void setNonCssHint(CssPropertyName name, CssValueType type, |
f39cfc38ea10
rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1732
diff
changeset
|
39 CssPropertyValue value); |
1711
b27cf7eb15b6
fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1494
diff
changeset
|
40 void preprocessAttrs (dw::core::style::StyleAttrs *attrs); |
b27cf7eb15b6
fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1494
diff
changeset
|
41 void postprocessAttrs (dw::core::style::StyleAttrs *attrs); |
509
fd2454cd0120
pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
506
diff
changeset
|
42 void apply (dw::core::style::StyleAttrs *attrs, CssPropertyList *props); |
1039
4ed33b76809c
wrap long lines in src/ css code
corvid <corvid@lavabit.com>
parents:
1035
diff
changeset
|
43 bool computeValue (int *dest, CssLength value, |
4ed33b76809c
wrap long lines in src/ css code
corvid <corvid@lavabit.com>
parents:
1035
diff
changeset
|
44 dw::core::style::Font *font); |
4ed33b76809c
wrap long lines in src/ css code
corvid <corvid@lavabit.com>
parents:
1035
diff
changeset
|
45 bool computeValue (int *dest, CssLength value, |
4ed33b76809c
wrap long lines in src/ css code
corvid <corvid@lavabit.com>
parents:
1035
diff
changeset
|
46 dw::core::style::Font *font, int percentageBase); |
990 | 47 bool computeLength (dw::core::style::Length *dest, CssLength value, |
48 dw::core::style::Font *font); | |
1472
6ed936726b50
support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1083
diff
changeset
|
49 void computeBorderWidth (int *dest, CssProperty *p, |
6ed936726b50
support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1083
diff
changeset
|
50 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
|
51 |
493 | 52 public: |
509
fd2454cd0120
pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
506
diff
changeset
|
53 StyleEngine (dw::core::Layout *layout); |
493 | 54 ~StyleEngine (); |
930
b277eed3119c
whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents:
901
diff
changeset
|
55 |
1039
4ed33b76809c
wrap long lines in src/ css code
corvid <corvid@lavabit.com>
parents:
1035
diff
changeset
|
56 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
|
57 CssOrigin origin); |
598
4ff90b6242f9
fix id, class, style attribute handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
590
diff
changeset
|
58 void startElement (int tag); |
982
d04d960da3f4
remove bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
956
diff
changeset
|
59 void startElement (const char *tagname); |
598
4ff90b6242f9
fix id, class, style attribute handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
590
diff
changeset
|
60 void setId (const char *id); |
1494
9225a90ad7dd
make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1472
diff
changeset
|
61 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
|
62 void setClass (const char *klass); |
4ff90b6242f9
fix id, class, style attribute handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
590
diff
changeset
|
63 void setStyle (const char *style); |
495 | 64 void endElement (int tag); |
679
14ce954d98c0
inherit pseudo classes "link" and "visited"
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
664
diff
changeset
|
65 void setPseudoLink (); |
14ce954d98c0
inherit pseudo classes "link" and "visited"
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
664
diff
changeset
|
66 void setPseudoVisited (); |
1733
f39cfc38ea10
rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1732
diff
changeset
|
67 void setNonCssHint(CssPropertyName name, CssValueType type, |
f39cfc38ea10
rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1732
diff
changeset
|
68 int value) { |
f39cfc38ea10
rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1732
diff
changeset
|
69 CssPropertyValue v; |
f39cfc38ea10
rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1732
diff
changeset
|
70 v.intVal = value; |
f39cfc38ea10
rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1732
diff
changeset
|
71 setNonCssHint (name, type, v); |
f39cfc38ea10
rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1732
diff
changeset
|
72 } |
f39cfc38ea10
rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1732
diff
changeset
|
73 void setNonCssHint(CssPropertyName name, CssValueType type, |
f39cfc38ea10
rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1732
diff
changeset
|
74 const char *value) { |
f39cfc38ea10
rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1732
diff
changeset
|
75 CssPropertyValue v; |
f39cfc38ea10
rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1732
diff
changeset
|
76 v.strVal = dStrdup(value); |
f39cfc38ea10
rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1732
diff
changeset
|
77 setNonCssHint (name, type, v); |
f39cfc38ea10
rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1732
diff
changeset
|
78 } |
f39cfc38ea10
rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1732
diff
changeset
|
79 void inheritNonCssHints (); |
f39cfc38ea10
rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
1732
diff
changeset
|
80 void clearNonCssHints (); |
664
109eaf60aea2
add comment about inheritBackgroundColor()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
659
diff
changeset
|
81 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
|
82 dw::core::style::Style *backgroundStyle (); |
503
00b31843839b
implement various apply() methods
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
501
diff
changeset
|
83 |
00b31843839b
implement various apply() methods
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
501
diff
changeset
|
84 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
|
85 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
|
86 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
|
87 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
|
88 else |
03de2284bfa6
switch to original enum names from dillo-0.8.0-css-3
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
503
diff
changeset
|
89 return style0 (); |
503
00b31843839b
implement various apply() methods
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
501
diff
changeset
|
90 }; |
990 | 91 |
644
9e4ad941cbdc
add wordStyle() method to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
643
diff
changeset
|
92 inline dw::core::style::Style *wordStyle () { |
1039
4ed33b76809c
wrap long lines in src/ css code
corvid <corvid@lavabit.com>
parents:
1035
diff
changeset
|
93 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
|
94 if (s) |
9e4ad941cbdc
add wordStyle() method to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
643
diff
changeset
|
95 return s; |
9e4ad941cbdc
add wordStyle() method to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
643
diff
changeset
|
96 else |
9e4ad941cbdc
add wordStyle() method to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
643
diff
changeset
|
97 return wordStyle0 (); |
9e4ad941cbdc
add wordStyle() method to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
643
diff
changeset
|
98 }; |
493 | 99 }; |
100 | |
101 #endif |