annotate src/styleengine.cc @ 2048:5060d415a85a

clickable menu items (even those introducing submenus) MUST have callbacks I clicked on the "Panel size" item itself instead of any of the options in its submenu, and: Segfault!
author corvid <corvid@lavabit.com>
date Thu, 26 May 2011 02:51:18 +0000
parents 586c7a6f61aa
children 5e0654968e3c
rev   line source
493
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
1 /*
497
96713a0f5d8b css.[ch][ch] -> styleengine.[ch][ch]
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 496
diff changeset
2 * File: styleengine.cc
493
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
3 *
777
841158582d34 update copyright
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 770
diff changeset
4 * Copyright 2008-2009 Johannes Hofmann <Johannes.Hofmann@gmx.de>
493
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
5 *
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
8 * the Free Software Foundation; either version 3 of the License, or
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
9 * (at your option) any later version.
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
10 */
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
11
598
4ff90b6242f9 fix id, class, style attribute handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 595
diff changeset
12 #include "../dlib/dlib.h"
1035
474b9814a8fa support CSS @import directive
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1018
diff changeset
13 #include "msg.h"
770
e62191e6da9a use prefs.font_factor to scale base font
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 767
diff changeset
14 #include "prefs.h"
982
d04d960da3f4 remove bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 980
diff changeset
15 #include "html_common.hh"
497
96713a0f5d8b css.[ch][ch] -> styleengine.[ch][ch]
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 496
diff changeset
16 #include "styleengine.hh"
493
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
17
1693
a9a11a23d707 add lout::misc::roundInt() for double -> int conversion
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1650
diff changeset
18 using namespace lout::misc;
510
2bc3d207f5ad start implementing StyleEngine::apply
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 509
diff changeset
19 using namespace dw::core::style;
2bc3d207f5ad start implementing StyleEngine::apply
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 509
diff changeset
20
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
21 StyleEngine::StyleEngine (dw::core::Layout *layout) {
515
7b3bbc2af326 hook up styleengine in html.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 512
diff changeset
22 StyleAttrs style_attrs;
7b3bbc2af326 hook up styleengine in html.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 512
diff changeset
23 FontAttrs font_attrs;
7b3bbc2af326 hook up styleengine in html.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 512
diff changeset
24
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
25 doctree = new Doctree ();
503
00b31843839b implement various apply() methods
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 499
diff changeset
26 stack = new lout::misc::SimpleVector <Node> (1);
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
27 cssContext = new CssContext ();
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
28 this->layout = layout;
1035
474b9814a8fa support CSS @import directive
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1018
diff changeset
29 importDepth = 0;
515
7b3bbc2af326 hook up styleengine in html.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 512
diff changeset
30
7b3bbc2af326 hook up styleengine in html.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 512
diff changeset
31 stack->increase ();
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
32 Node *n = stack->getRef (stack->size () - 1);
515
7b3bbc2af326 hook up styleengine in html.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 512
diff changeset
33
7b3bbc2af326 hook up styleengine in html.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 512
diff changeset
34 /* Create a dummy font, attribute, and tag for the bottom of the stack. */
824
556b5972dd18 adapt font-family preferences to match CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 805
diff changeset
35 font_attrs.name = prefs.font_sans_serif;
1693
a9a11a23d707 add lout::misc::roundInt() for double -> int conversion
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1650
diff changeset
36 font_attrs.size = roundInt(14 * prefs.font_factor);
954
270e94174519 check base font against font_min_size
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 947
diff changeset
37 if (font_attrs.size < prefs.font_min_size)
270e94174519 check base font against font_min_size
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 947
diff changeset
38 font_attrs.size = prefs.font_min_size;
955
b84781690627 add font_max_size dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 954
diff changeset
39 if (font_attrs.size > prefs.font_max_size)
b84781690627 add font_max_size dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 954
diff changeset
40 font_attrs.size = prefs.font_max_size;
914
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
41 font_attrs.weight = 400;
515
7b3bbc2af326 hook up styleengine in html.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 512
diff changeset
42 font_attrs.style = FONT_STYLE_NORMAL;
1350
0fb1bd0e94a9 add letter-spacing support to CSS subsystem
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1340
diff changeset
43 font_attrs.letterSpacing = 0;
1712
9a71c8d886ef CSS part for font-variant: small-caps support
Jorge Arellano Cid <jcid@dillo.org>
parents: 1711
diff changeset
44 font_attrs.fontVariant = FONT_VARIANT_NORMAL;
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 921
diff changeset
45
515
7b3bbc2af326 hook up styleengine in html.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 512
diff changeset
46 style_attrs.initValues ();
7b3bbc2af326 hook up styleengine in html.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 512
diff changeset
47 style_attrs.font = Font::create (layout, &font_attrs);
677
b6ef23efdac7 always use shaded colors
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 672
diff changeset
48 style_attrs.color = Color::create (layout, 0);
b6ef23efdac7 always use shaded colors
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 672
diff changeset
49 style_attrs.backgroundColor = Color::create (layout, 0xffffff);
763
df8153796f48 initial implementation of a CSS selector matching optimization
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 739
diff changeset
50
515
7b3bbc2af326 hook up styleengine in html.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 512
diff changeset
51 n->style = Style::create (layout, &style_attrs);
682
7f134e04fe6a initialize wordStyle
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 679
diff changeset
52 n->wordStyle = NULL;
1746
ef983c0fe908 fix Style leaks in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1743
diff changeset
53 n->backgroundStyle = NULL;
1732
3e3630a58627 store style attribute as CssPropertyList instead of a string
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
54 n->styleAttrProperties = NULL;
3e3630a58627 store style attribute as CssPropertyList instead of a string
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
55 n->nonCssProperties = NULL;
739
cb5fc438936b initialize styleAttribute and inheritBackgroundColor (by Jorge)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 733
diff changeset
56 n->inheritBackgroundColor = false;
493
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
57 }
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
58
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
59 StyleEngine::~StyleEngine () {
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
60 while (doctree->top ())
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
61 endElement (doctree->top ()->element);
1749
1a3af54d6003 fix another Style leak in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1748
diff changeset
62 assert (stack->size () == 1); // dummy node on the bottom of the stack
1a3af54d6003 fix another Style leak in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1748
diff changeset
63 Node *n = stack->getRef (stack->size () - 1);
1a3af54d6003 fix another Style leak in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1748
diff changeset
64 if (n->style)
1a3af54d6003 fix another Style leak in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1748
diff changeset
65 n->style->unref ();
1a3af54d6003 fix another Style leak in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1748
diff changeset
66 if (n->wordStyle)
1a3af54d6003 fix another Style leak in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1748
diff changeset
67 n->wordStyle->unref ();
1a3af54d6003 fix another Style leak in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1748
diff changeset
68 if (n->backgroundStyle)
1a3af54d6003 fix another Style leak in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1748
diff changeset
69 n->backgroundStyle->unref ();
503
00b31843839b implement various apply() methods
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 499
diff changeset
70 delete stack;
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
71 delete doctree;
584
60fd513750ad merge with cvs
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 580
diff changeset
72 delete cssContext;
493
03e0cacbb994 add css.hh css.cc
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents:
diff changeset
73 }
496
8f420eb7c20d strdup() id and style strings
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 495
diff changeset
74
532
a41fe7c781cb add some comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 530
diff changeset
75 /**
a41fe7c781cb add some comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 530
diff changeset
76 * \brief tell the styleEngine that a new html element has started.
a41fe7c781cb add some comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 530
diff changeset
77 */
598
4ff90b6242f9 fix id, class, style attribute handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 595
diff changeset
78 void StyleEngine::startElement (int element) {
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
79 if (stack->getRef (stack->size () - 1)->style == NULL)
1734
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
80 style0 (stack->size () - 1);
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
81
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
82 stack->increase ();
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
83 Node *n = stack->getRef (stack->size () - 1);
1732
3e3630a58627 store style attribute as CssPropertyList instead of a string
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
84 n->styleAttrProperties = NULL;
3e3630a58627 store style attribute as CssPropertyList instead of a string
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
85 n->nonCssProperties = NULL;
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
86 n->style = NULL;
646
35c1cb888c4a use styleEngine->wordStyle() for adding text or parbreaks
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 644
diff changeset
87 n->wordStyle = NULL;
1746
ef983c0fe908 fix Style leaks in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1743
diff changeset
88 n->backgroundStyle = NULL;
615
d0694361ecd0 add workaround for table row coloring
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 603
diff changeset
89 n->inheritBackgroundColor = false;
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
90
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
91 DoctreeNode *dn = doctree->push ();
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
92 dn->element = element;
1738
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1736
diff changeset
93 n->doctreeNode = dn;
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
94 }
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
95
982
d04d960da3f4 remove bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 980
diff changeset
96 void StyleEngine::startElement (const char *tagname) {
d04d960da3f4 remove bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 980
diff changeset
97 startElement (a_Html_tag_index (tagname));
d04d960da3f4 remove bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 980
diff changeset
98 }
d04d960da3f4 remove bg_color dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 980
diff changeset
99
598
4ff90b6242f9 fix id, class, style attribute handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 595
diff changeset
100 void StyleEngine::setId (const char *id) {
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
101 DoctreeNode *dn = doctree->top ();
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
102 assert (dn->id == NULL);
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
103 dn->id = dStrdup (id);
598
4ff90b6242f9 fix id, class, style attribute handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 595
diff changeset
104 };
4ff90b6242f9 fix id, class, style attribute handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 595
diff changeset
105
1215
47e96b92122c split class attributes at whitespace
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
106 /**
1216
3b3fb6a206ac optimize splitStr()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1215
diff changeset
107 * \brief split a string at sep chars and return a SimpleVector of strings
1215
47e96b92122c split class attributes at whitespace
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
108 */
1216
3b3fb6a206ac optimize splitStr()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1215
diff changeset
109 static lout::misc::SimpleVector<char *> *splitStr (const char *str, char sep) {
3b3fb6a206ac optimize splitStr()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1215
diff changeset
110 const char *p1 = NULL;
1215
47e96b92122c split class attributes at whitespace
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
111 lout::misc::SimpleVector<char *> *list =
1216
3b3fb6a206ac optimize splitStr()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1215
diff changeset
112 new lout::misc::SimpleVector<char *> (1);
1215
47e96b92122c split class attributes at whitespace
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
113
1216
3b3fb6a206ac optimize splitStr()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1215
diff changeset
114 for (;; str++) {
3b3fb6a206ac optimize splitStr()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1215
diff changeset
115 if (*str != '\0' && *str != sep) {
3b3fb6a206ac optimize splitStr()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1215
diff changeset
116 if (!p1)
3b3fb6a206ac optimize splitStr()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1215
diff changeset
117 p1 = str;
3b3fb6a206ac optimize splitStr()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1215
diff changeset
118 } else if (p1) {
3b3fb6a206ac optimize splitStr()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1215
diff changeset
119 list->increase ();
3b3fb6a206ac optimize splitStr()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1215
diff changeset
120 list->set (list->size () - 1, dStrndup (p1, str - p1));
3b3fb6a206ac optimize splitStr()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1215
diff changeset
121 p1 = NULL;
3b3fb6a206ac optimize splitStr()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1215
diff changeset
122 }
3b3fb6a206ac optimize splitStr()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1215
diff changeset
123
3b3fb6a206ac optimize splitStr()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1215
diff changeset
124 if (*str == '\0')
3b3fb6a206ac optimize splitStr()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1215
diff changeset
125 break;
1215
47e96b92122c split class attributes at whitespace
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
126 }
47e96b92122c split class attributes at whitespace
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
127
1216
3b3fb6a206ac optimize splitStr()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1215
diff changeset
128 return list;
1215
47e96b92122c split class attributes at whitespace
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
129 }
47e96b92122c split class attributes at whitespace
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1214
diff changeset
130
598
4ff90b6242f9 fix id, class, style attribute handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 595
diff changeset
131 void StyleEngine::setClass (const char *klass) {
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
132 DoctreeNode *dn = doctree->top ();
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
133 assert (dn->klass == NULL);
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
134 dn->klass = splitStr (klass, ' ');
598
4ff90b6242f9 fix id, class, style attribute handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 595
diff changeset
135 };
4ff90b6242f9 fix id, class, style attribute handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 595
diff changeset
136
1732
3e3630a58627 store style attribute as CssPropertyList instead of a string
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
137 void StyleEngine::setStyle (const char *styleAttr) {
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
138 Node *n = stack->getRef (stack->size () - 1);
1732
3e3630a58627 store style attribute as CssPropertyList instead of a string
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
139 assert (n->styleAttrProperties == NULL);
3e3630a58627 store style attribute as CssPropertyList instead of a string
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
140 // parse style information from style="" attribute, if it exists
3e3630a58627 store style attribute as CssPropertyList instead of a string
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
141 if (styleAttr && prefs.parse_embedded_css)
3e3630a58627 store style attribute as CssPropertyList instead of a string
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
142 n->styleAttrProperties =
3e3630a58627 store style attribute as CssPropertyList instead of a string
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
143 CssParser::parseDeclarationBlock (styleAttr,
3e3630a58627 store style attribute as CssPropertyList instead of a string
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
144 strlen (styleAttr));
598
4ff90b6242f9 fix id, class, style attribute handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 595
diff changeset
145 };
4ff90b6242f9 fix id, class, style attribute handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 595
diff changeset
146
532
a41fe7c781cb add some comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 530
diff changeset
147 /**
1741
b35adbe0366c comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1739
diff changeset
148 * \brief Instruct StyleEngine to use the nonCssHints from parent element
b35adbe0366c comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1739
diff changeset
149 * This is only used for tables where nonCssHints on the TABLE-element
b35adbe0366c comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1739
diff changeset
150 * (e.g. border=1) also affect child elements like TD.
532
a41fe7c781cb add some comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 530
diff changeset
151 */
1733
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
152 void StyleEngine::inheritNonCssHints () {
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
153 Node *pn = stack->getRef (stack->size () - 2);
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
154 Node *n = stack->getRef (stack->size () - 1);
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
155
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
156 if (pn->nonCssProperties)
1739
7188140a1c0a implement optional deep copy for CssPropertyList
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1738
diff changeset
157 n->nonCssProperties = new CssPropertyList (*pn->nonCssProperties, true);
1733
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
158 }
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
159
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
160 void StyleEngine::clearNonCssHints () {
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
161 Node *n = stack->getRef (stack->size () - 1);
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
162
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
163 if (n->nonCssProperties) {
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
164 delete n->nonCssProperties;
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
165 n->nonCssProperties = NULL;
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
166 }
496
8f420eb7c20d strdup() id and style strings
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 495
diff changeset
167 }
8f420eb7c20d strdup() id and style strings
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 495
diff changeset
168
532
a41fe7c781cb add some comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 530
diff changeset
169 /**
615
d0694361ecd0 add workaround for table row coloring
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 603
diff changeset
170 * \brief Use of the background color of the parent style as default.
d0694361ecd0 add workaround for table row coloring
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 603
diff changeset
171 * This is only used in table code to allow for colors specified for
d0694361ecd0 add workaround for table row coloring
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 603
diff changeset
172 * table rows as table rows are currently no widgets and therefore
d0694361ecd0 add workaround for table row coloring
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 603
diff changeset
173 * don't draw any background.
d0694361ecd0 add workaround for table row coloring
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 603
diff changeset
174 */
d0694361ecd0 add workaround for table row coloring
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 603
diff changeset
175 void StyleEngine::inheritBackgroundColor () {
d0694361ecd0 add workaround for table row coloring
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 603
diff changeset
176 stack->getRef (stack->size () - 1)->inheritBackgroundColor = true;
d0694361ecd0 add workaround for table row coloring
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 603
diff changeset
177 }
d0694361ecd0 add workaround for table row coloring
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 603
diff changeset
178
1738
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1736
diff changeset
179 dw::core::style::Color *StyleEngine::backgroundColor () {
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1736
diff changeset
180 for (int i = 1; i < stack->size (); i++) {
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1736
diff changeset
181 Node *n = stack->getRef (i);
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1736
diff changeset
182
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1736
diff changeset
183 if (n->style && n->style->backgroundColor)
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1736
diff changeset
184 return n->style->backgroundColor;
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1736
diff changeset
185 }
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1736
diff changeset
186
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1736
diff changeset
187 return NULL;
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1736
diff changeset
188 }
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1736
diff changeset
189
615
d0694361ecd0 add workaround for table row coloring
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 603
diff changeset
190 /**
679
14ce954d98c0 inherit pseudo classes "link" and "visited"
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 677
diff changeset
191 * \brief set the CSS pseudo class :link.
535
6428b62b5a24 minor cleanup
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 534
diff changeset
192 */
679
14ce954d98c0 inherit pseudo classes "link" and "visited"
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 677
diff changeset
193 void StyleEngine::setPseudoLink () {
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
194 DoctreeNode *dn = doctree->top ();
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
195 dn->pseudo = "link";
679
14ce954d98c0 inherit pseudo classes "link" and "visited"
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 677
diff changeset
196 }
14ce954d98c0 inherit pseudo classes "link" and "visited"
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 677
diff changeset
197
14ce954d98c0 inherit pseudo classes "link" and "visited"
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 677
diff changeset
198 /**
14ce954d98c0 inherit pseudo classes "link" and "visited"
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 677
diff changeset
199 * \brief set the CSS pseudo class :visited.
14ce954d98c0 inherit pseudo classes "link" and "visited"
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 677
diff changeset
200 */
14ce954d98c0 inherit pseudo classes "link" and "visited"
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 677
diff changeset
201 void StyleEngine::setPseudoVisited () {
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
202 DoctreeNode *dn = doctree->top ();
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
203 dn->pseudo = "visited";
535
6428b62b5a24 minor cleanup
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 534
diff changeset
204 }
6428b62b5a24 minor cleanup
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 534
diff changeset
205
6428b62b5a24 minor cleanup
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 534
diff changeset
206 /**
532
a41fe7c781cb add some comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 530
diff changeset
207 * \brief tell the styleEngine that a html element has ended.
a41fe7c781cb add some comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 530
diff changeset
208 */
563
b384452e32fb tag -> element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 558
diff changeset
209 void StyleEngine::endElement (int element) {
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
210 assert (element == doctree->top ()->element);
511
1d7a68d6ceb5 delete stuff in StyleEngine::endElement
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 510
diff changeset
211
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
212 Node *n = stack->getRef (stack->size () - 1);
598
4ff90b6242f9 fix id, class, style attribute handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 595
diff changeset
213
1732
3e3630a58627 store style attribute as CssPropertyList instead of a string
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
214 if (n->styleAttrProperties)
3e3630a58627 store style attribute as CssPropertyList instead of a string
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
215 delete n->styleAttrProperties;
3e3630a58627 store style attribute as CssPropertyList instead of a string
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
216 if (n->nonCssProperties)
3e3630a58627 store style attribute as CssPropertyList instead of a string
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
217 delete n->nonCssProperties;
511
1d7a68d6ceb5 delete stuff in StyleEngine::endElement
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 510
diff changeset
218 if (n->style)
1d7a68d6ceb5 delete stuff in StyleEngine::endElement
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 510
diff changeset
219 n->style->unref ();
644
9e4ad941cbdc add wordStyle() method to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 643
diff changeset
220 if (n->wordStyle)
9e4ad941cbdc add wordStyle() method to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 643
diff changeset
221 n->wordStyle->unref ();
1746
ef983c0fe908 fix Style leaks in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1743
diff changeset
222 if (n->backgroundStyle)
ef983c0fe908 fix Style leaks in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1743
diff changeset
223 n->backgroundStyle->unref ();
598
4ff90b6242f9 fix id, class, style attribute handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 595
diff changeset
224
1494
9225a90ad7dd make Doctree a non-virtual class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1472
diff changeset
225 doctree->pop ();
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
226 stack->setSize (stack->size () - 1);
496
8f420eb7c20d strdup() id and style strings
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 495
diff changeset
227 }
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
228
1711
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
229 void StyleEngine::preprocessAttrs (dw::core::style::StyleAttrs *attrs) {
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
230 /* workaround for styling of inline elements */
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
231 if (stack->getRef (stack->size () - 2)->inheritBackgroundColor) {
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
232 attrs->backgroundColor =
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
233 stack->getRef (stack->size () - 2)->style->backgroundColor;
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
234
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
235 attrs->valign = stack->getRef (stack->size () - 2)->style->valign;
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
236 }
1779
7822a753c004 border-color: transparent
corvid <corvid@lavabit.com>
parents: 1770
diff changeset
237 attrs->borderColor.top = (Color *) -1;
7822a753c004 border-color: transparent
corvid <corvid@lavabit.com>
parents: 1770
diff changeset
238 attrs->borderColor.bottom = (Color *) -1;
7822a753c004 border-color: transparent
corvid <corvid@lavabit.com>
parents: 1770
diff changeset
239 attrs->borderColor.left = (Color *) -1;
7822a753c004 border-color: transparent
corvid <corvid@lavabit.com>
parents: 1770
diff changeset
240 attrs->borderColor.right = (Color *) -1;
1711
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
241 /* initial value of border-width is 'medium' */
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
242 attrs->borderWidth.top = 2;
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
243 attrs->borderWidth.bottom = 2;
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
244 attrs->borderWidth.left = 2;
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
245 attrs->borderWidth.right = 2;
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
246 }
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
247
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
248 void StyleEngine::postprocessAttrs (dw::core::style::StyleAttrs *attrs) {
1779
7822a753c004 border-color: transparent
corvid <corvid@lavabit.com>
parents: 1770
diff changeset
249 /* if border-color is not specified, use color as computed value */
7822a753c004 border-color: transparent
corvid <corvid@lavabit.com>
parents: 1770
diff changeset
250 if (attrs->borderColor.top == (Color *) -1)
1711
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
251 attrs->borderColor.top = attrs->color;
1779
7822a753c004 border-color: transparent
corvid <corvid@lavabit.com>
parents: 1770
diff changeset
252 if (attrs->borderColor.bottom == (Color *) -1)
1711
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
253 attrs->borderColor.bottom = attrs->color;
1779
7822a753c004 border-color: transparent
corvid <corvid@lavabit.com>
parents: 1770
diff changeset
254 if (attrs->borderColor.left == (Color *) -1)
1711
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
255 attrs->borderColor.left = attrs->color;
1779
7822a753c004 border-color: transparent
corvid <corvid@lavabit.com>
parents: 1770
diff changeset
256 if (attrs->borderColor.right == (Color *) -1)
1711
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
257 attrs->borderColor.right = attrs->color;
1719
2bf8bf3a0277 set border-width to 0 if border-style is 'hidden'
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
258 /* computed value of border-width is 0 if border-style
2bf8bf3a0277 set border-width to 0 if border-style is 'hidden'
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
259 is 'none' or 'hidden' */
2bf8bf3a0277 set border-width to 0 if border-style is 'hidden'
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
260 if (attrs->borderStyle.top == BORDER_NONE ||
2bf8bf3a0277 set border-width to 0 if border-style is 'hidden'
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
261 attrs->borderStyle.top == BORDER_HIDDEN)
1711
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
262 attrs->borderWidth.top = 0;
1719
2bf8bf3a0277 set border-width to 0 if border-style is 'hidden'
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
263 if (attrs->borderStyle.bottom == BORDER_NONE ||
2bf8bf3a0277 set border-width to 0 if border-style is 'hidden'
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
264 attrs->borderStyle.bottom == BORDER_HIDDEN)
1711
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
265 attrs->borderWidth.bottom = 0;
1719
2bf8bf3a0277 set border-width to 0 if border-style is 'hidden'
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
266 if (attrs->borderStyle.left == BORDER_NONE ||
2bf8bf3a0277 set border-width to 0 if border-style is 'hidden'
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
267 attrs->borderStyle.left == BORDER_HIDDEN)
1711
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
268 attrs->borderWidth.left = 0;
1719
2bf8bf3a0277 set border-width to 0 if border-style is 'hidden'
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
269 if (attrs->borderStyle.right == BORDER_NONE ||
2bf8bf3a0277 set border-width to 0 if border-style is 'hidden'
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1712
diff changeset
270 attrs->borderStyle.right == BORDER_HIDDEN)
1711
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
271 attrs->borderWidth.right = 0;
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
272 }
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
273
543
74c07ade1edc convert table code to new style handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 535
diff changeset
274 /**
74c07ade1edc convert table code to new style handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 535
diff changeset
275 * \brief Make changes to StyleAttrs attrs according to CssPropertyList props.
74c07ade1edc convert table code to new style handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 535
diff changeset
276 */
1738
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1736
diff changeset
277 void StyleEngine::apply (int i, StyleAttrs *attrs, CssPropertyList *props) {
510
2bc3d207f5ad start implementing StyleEngine::apply
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 509
diff changeset
278 FontAttrs fontAttrs = *attrs->font;
1738
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1736
diff changeset
279 Font *parentFont = stack->get (i - 1).style->font;
1436
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
280 char *c, *fontName;
1642
a4eb350d3db2 line-height
corvid, Johannes Hofmann
parents: 1524
diff changeset
281 int lineHeight;
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
282
1712
9a71c8d886ef CSS part for font-variant: small-caps support
Jorge Arellano Cid <jcid@dillo.org>
parents: 1711
diff changeset
283 /* Determine font first so it can be used to resolve relative lengths. */
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
284 for (int i = 0; i < props->size (); i++) {
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
285 CssProperty *p = props->getRef (i);
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 921
diff changeset
286
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
287 switch (p->name) {
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
288 case CSS_PROPERTY_FONT_FAMILY:
1437
16602aa5aabc comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1436
diff changeset
289 // Check font names in comma separated list.
1436
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
290 // Note, that p->value.strVal is modified, so that in future calls
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
291 // the matching font name can be used directly.
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
292 fontName = NULL;
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
293 while (p->value.strVal) {
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
294 if ((c = strchr(p->value.strVal, ',')))
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
295 *c = '\0';
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
296 dStrstrip(p->value.strVal);
1431
f524c1c7e5ae use first font name in comma separated list in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1353
diff changeset
297
1436
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
298 if (strcmp (p->value.strVal, "serif") == 0)
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
299 fontName = prefs.font_serif;
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
300 else if (strcmp (p->value.strVal, "sans-serif") == 0)
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
301 fontName = prefs.font_sans_serif;
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
302 else if (strcmp (p->value.strVal, "cursive") == 0)
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
303 fontName = prefs.font_cursive;
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
304 else if (strcmp (p->value.strVal, "fantasy") == 0)
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
305 fontName = prefs.font_fantasy;
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
306 else if (strcmp (p->value.strVal, "monospace") == 0)
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
307 fontName = prefs.font_monospace;
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
308 else if (Font::exists(layout, p->value.strVal))
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
309 fontName = p->value.strVal;
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
310
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
311 if (fontName) { // font found
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
312 fontAttrs.name = fontName;
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
313 break;
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
314 } else if (c) { // try next from list
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
315 memmove(p->value.strVal, c + 1, strlen(c + 1) + 1);
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
316 } else { // no font found
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
317 break;
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
318 }
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
319 }
d5536dc7114a properly handle comma separated lists of font names in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1431
diff changeset
320
510
2bc3d207f5ad start implementing StyleEngine::apply
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 509
diff changeset
321 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
322 case CSS_PROPERTY_FONT_SIZE:
918
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
323 if (p->type == CSS_TYPE_ENUM) {
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
324 switch (p->value.intVal) {
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
325 case CSS_FONT_SIZE_XX_SMALL:
1693
a9a11a23d707 add lout::misc::roundInt() for double -> int conversion
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1650
diff changeset
326 fontAttrs.size = roundInt(11.0 * prefs.font_factor);
918
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
327 break;
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
328 case CSS_FONT_SIZE_X_SMALL:
1693
a9a11a23d707 add lout::misc::roundInt() for double -> int conversion
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1650
diff changeset
329 fontAttrs.size = roundInt(12.0 * prefs.font_factor);
918
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
330 break;
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
331 case CSS_FONT_SIZE_SMALL:
1693
a9a11a23d707 add lout::misc::roundInt() for double -> int conversion
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1650
diff changeset
332 fontAttrs.size = roundInt(13.0 * prefs.font_factor);
918
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
333 break;
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
334 case CSS_FONT_SIZE_MEDIUM:
1693
a9a11a23d707 add lout::misc::roundInt() for double -> int conversion
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1650
diff changeset
335 fontAttrs.size = roundInt(14.0 * prefs.font_factor);
918
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
336 break;
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
337 case CSS_FONT_SIZE_LARGE:
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
338 break;
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
339 case CSS_FONT_SIZE_X_LARGE:
1693
a9a11a23d707 add lout::misc::roundInt() for double -> int conversion
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1650
diff changeset
340 fontAttrs.size = roundInt(16.0 * prefs.font_factor);
918
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
341 break;
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
342 case CSS_FONT_SIZE_XX_LARGE:
1693
a9a11a23d707 add lout::misc::roundInt() for double -> int conversion
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1650
diff changeset
343 fontAttrs.size = roundInt(17.0 * prefs.font_factor);
918
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
344 break;
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
345 case CSS_FONT_SIZE_SMALLER:
1693
a9a11a23d707 add lout::misc::roundInt() for double -> int conversion
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1650
diff changeset
346 fontAttrs.size -= roundInt(1.0 * prefs.font_factor);
918
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
347 break;
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
348 case CSS_FONT_SIZE_LARGER:
1693
a9a11a23d707 add lout::misc::roundInt() for double -> int conversion
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1650
diff changeset
349 fontAttrs.size += roundInt(1.0 * prefs.font_factor);
918
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
350 break;
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
351 default:
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
352 assert(false); // invalid font-size enum
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
353 }
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
354 } else {
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
355 computeValue (&fontAttrs.size, p->value.intVal, parentFont,
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
356 parentFont->size);
fa79176adf1a support font-size enum values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 914
diff changeset
357 }
935
b43ce176d305 add "font_min_size" dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 930
diff changeset
358
b43ce176d305 add "font_min_size" dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 930
diff changeset
359 if (fontAttrs.size < prefs.font_min_size)
b43ce176d305 add "font_min_size" dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 930
diff changeset
360 fontAttrs.size = prefs.font_min_size;
955
b84781690627 add font_max_size dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 954
diff changeset
361 if (fontAttrs.size > prefs.font_max_size)
b84781690627 add font_max_size dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 954
diff changeset
362 fontAttrs.size = prefs.font_max_size;
935
b43ce176d305 add "font_min_size" dillorc option
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 930
diff changeset
363
510
2bc3d207f5ad start implementing StyleEngine::apply
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 509
diff changeset
364 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
365 case CSS_PROPERTY_FONT_STYLE:
533
0ae28670be00 make CssProperty::Value a union of int and char*
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 532
diff changeset
366 fontAttrs.style = (FontStyle) p->value.intVal;
521
5dedb43b39f2 add <b> and <i>
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 519
diff changeset
367 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
368 case CSS_PROPERTY_FONT_WEIGHT:
914
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
369
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
370 if (p->type == CSS_TYPE_ENUM) {
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
371 switch (p->value.intVal) {
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
372 case CSS_FONT_WEIGHT_BOLD:
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
373 fontAttrs.weight = 700;
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
374 break;
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
375 case CSS_FONT_WEIGHT_BOLDER:
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
376 fontAttrs.weight += 300;
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
377 break;
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
378 case CSS_FONT_WEIGHT_LIGHT:
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
379 fontAttrs.weight = 100;
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
380 break;
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
381 case CSS_FONT_WEIGHT_LIGHTER:
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
382 fontAttrs.weight -= 300;
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
383 break;
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
384 case CSS_FONT_WEIGHT_NORMAL:
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
385 fontAttrs.weight = 400;
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
386 break;
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
387 default:
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
388 assert(false); // invalid font weight value
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
389 break;
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
390 }
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
391 } else {
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
392 fontAttrs.weight = p->value.intVal;
534
7e141578b8c6 support CSS_FONT_WEIGHT_LIGHTER and CSS_FONT_WEIGHT_BOLDER
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 533
diff changeset
393 }
914
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
394
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
395 if (fontAttrs.weight < 100)
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
396 fontAttrs.weight = 100;
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
397 if (fontAttrs.weight > 900)
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
398 fontAttrs.weight = 900;
81370e1971df switch font-weight handling to new multi type system
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 910
diff changeset
399
521
5dedb43b39f2 add <b> and <i>
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 519
diff changeset
400 break;
1350
0fb1bd0e94a9 add letter-spacing support to CSS subsystem
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1340
diff changeset
401 case CSS_PROPERTY_LETTER_SPACING:
0fb1bd0e94a9 add letter-spacing support to CSS subsystem
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1340
diff changeset
402 if (p->type == CSS_TYPE_ENUM) {
0fb1bd0e94a9 add letter-spacing support to CSS subsystem
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1340
diff changeset
403 if (p->value.intVal == CSS_LETTER_SPACING_NORMAL) {
0fb1bd0e94a9 add letter-spacing support to CSS subsystem
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1340
diff changeset
404 fontAttrs.letterSpacing = 0;
0fb1bd0e94a9 add letter-spacing support to CSS subsystem
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1340
diff changeset
405 }
0fb1bd0e94a9 add letter-spacing support to CSS subsystem
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1340
diff changeset
406 } else {
0fb1bd0e94a9 add letter-spacing support to CSS subsystem
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1340
diff changeset
407 computeValue (&fontAttrs.letterSpacing, p->value.intVal,
0fb1bd0e94a9 add letter-spacing support to CSS subsystem
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1340
diff changeset
408 parentFont, parentFont->size);
0fb1bd0e94a9 add letter-spacing support to CSS subsystem
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1340
diff changeset
409 }
1353
e62ad3632a0e limit letter-spacing values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1350
diff changeset
410
e62ad3632a0e limit letter-spacing values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1350
diff changeset
411 /* Limit letterSpacing to reasonable values to avoid overflows e.g,
e62ad3632a0e limit letter-spacing values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1350
diff changeset
412 * when measuring word width.
e62ad3632a0e limit letter-spacing values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1350
diff changeset
413 */
e62ad3632a0e limit letter-spacing values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1350
diff changeset
414 if (fontAttrs.letterSpacing > 1000)
e62ad3632a0e limit letter-spacing values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1350
diff changeset
415 fontAttrs.letterSpacing = 1000;
e62ad3632a0e limit letter-spacing values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1350
diff changeset
416 else if (fontAttrs.letterSpacing < -1000)
e62ad3632a0e limit letter-spacing values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1350
diff changeset
417 fontAttrs.letterSpacing = -1000;
1350
0fb1bd0e94a9 add letter-spacing support to CSS subsystem
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1340
diff changeset
418 break;
1712
9a71c8d886ef CSS part for font-variant: small-caps support
Jorge Arellano Cid <jcid@dillo.org>
parents: 1711
diff changeset
419 case CSS_PROPERTY_FONT_VARIANT:
9a71c8d886ef CSS part for font-variant: small-caps support
Jorge Arellano Cid <jcid@dillo.org>
parents: 1711
diff changeset
420 fontAttrs.fontVariant = (FontVariant) p->value.intVal;
9a71c8d886ef CSS part for font-variant: small-caps support
Jorge Arellano Cid <jcid@dillo.org>
parents: 1711
diff changeset
421 break;
576
66153396f4ba start implementing resolution of relative CSS values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 575
diff changeset
422 default:
66153396f4ba start implementing resolution of relative CSS values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 575
diff changeset
423 break;
66153396f4ba start implementing resolution of relative CSS values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 575
diff changeset
424 }
66153396f4ba start implementing resolution of relative CSS values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 575
diff changeset
425 }
66153396f4ba start implementing resolution of relative CSS values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 575
diff changeset
426
66153396f4ba start implementing resolution of relative CSS values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 575
diff changeset
427 attrs->font = Font::create (layout, &fontAttrs);
66153396f4ba start implementing resolution of relative CSS values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 575
diff changeset
428
66153396f4ba start implementing resolution of relative CSS values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 575
diff changeset
429 for (int i = 0; i < props->size (); i++) {
66153396f4ba start implementing resolution of relative CSS values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 575
diff changeset
430 CssProperty *p = props->getRef (i);
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 921
diff changeset
431
576
66153396f4ba start implementing resolution of relative CSS values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 575
diff changeset
432 switch (p->name) {
510
2bc3d207f5ad start implementing StyleEngine::apply
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 509
diff changeset
433 /* \todo missing cases */
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
434 case CSS_PROPERTY_BACKGROUND_COLOR:
998
9e07ea8a694b whitespace
Jorge Arellano Cid <jcid@dillo.org>
parents: 997
diff changeset
435 if (prefs.allow_white_bg || p->value.intVal != 0xffffff)
9e07ea8a694b whitespace
Jorge Arellano Cid <jcid@dillo.org>
parents: 997
diff changeset
436 attrs->backgroundColor = Color::create(layout, p->value.intVal);
997
d633f4cc03e2 fix allow_white_bg=NO case
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 990
diff changeset
437 else
1523
bf5107c0f232 Changed the default background color when allow_white_bg=NO (part 2)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1472
diff changeset
438 //attrs->backgroundColor = Color::create(layout, 0xdcd1ba);
bf5107c0f232 Changed the default background color when allow_white_bg=NO (part 2)
Jorge Arellano Cid <jcid@dillo.org>
parents: 1472
diff changeset
439 attrs->backgroundColor = Color::create(layout, 0xe0e0a3);
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 921
diff changeset
440 break;
1756
cc7c9180ae95 imported patch border-collapse-parsing
Jorge Arellano Cid <jcid@dillo.org>
parents: 1749
diff changeset
441 case CSS_PROPERTY_BORDER_COLLAPSE:
cc7c9180ae95 imported patch border-collapse-parsing
Jorge Arellano Cid <jcid@dillo.org>
parents: 1749
diff changeset
442 attrs->borderCollapse = (BorderCollapse) p->value.intVal;
cc7c9180ae95 imported patch border-collapse-parsing
Jorge Arellano Cid <jcid@dillo.org>
parents: 1749
diff changeset
443 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
444 case CSS_PROPERTY_BORDER_TOP_COLOR:
1779
7822a753c004 border-color: transparent
corvid <corvid@lavabit.com>
parents: 1770
diff changeset
445 attrs->borderColor.top = (p->type == CSS_TYPE_ENUM) ? NULL :
7822a753c004 border-color: transparent
corvid <corvid@lavabit.com>
parents: 1770
diff changeset
446 Color::create (layout, p->value.intVal);
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 921
diff changeset
447 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
448 case CSS_PROPERTY_BORDER_BOTTOM_COLOR:
1779
7822a753c004 border-color: transparent
corvid <corvid@lavabit.com>
parents: 1770
diff changeset
449 attrs->borderColor.bottom = (p->type == CSS_TYPE_ENUM) ? NULL :
7822a753c004 border-color: transparent
corvid <corvid@lavabit.com>
parents: 1770
diff changeset
450 Color::create (layout, p->value.intVal);
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 921
diff changeset
451 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
452 case CSS_PROPERTY_BORDER_LEFT_COLOR:
1779
7822a753c004 border-color: transparent
corvid <corvid@lavabit.com>
parents: 1770
diff changeset
453 attrs->borderColor.left = (p->type == CSS_TYPE_ENUM) ? NULL :
7822a753c004 border-color: transparent
corvid <corvid@lavabit.com>
parents: 1770
diff changeset
454 Color::create (layout, p->value.intVal);
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 921
diff changeset
455 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
456 case CSS_PROPERTY_BORDER_RIGHT_COLOR:
1779
7822a753c004 border-color: transparent
corvid <corvid@lavabit.com>
parents: 1770
diff changeset
457 attrs->borderColor.right = (p->type == CSS_TYPE_ENUM) ? NULL :
7822a753c004 border-color: transparent
corvid <corvid@lavabit.com>
parents: 1770
diff changeset
458 Color::create (layout, p->value.intVal);
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 921
diff changeset
459 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
460 case CSS_PROPERTY_BORDER_BOTTOM_STYLE:
576
66153396f4ba start implementing resolution of relative CSS values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 575
diff changeset
461 attrs->borderStyle.bottom = (BorderStyle) p->value.intVal;
510
2bc3d207f5ad start implementing StyleEngine::apply
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 509
diff changeset
462 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
463 case CSS_PROPERTY_BORDER_LEFT_STYLE:
577
9f7a3aa4e1f6 support more border-style
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 576
diff changeset
464 attrs->borderStyle.left = (BorderStyle) p->value.intVal;
510
2bc3d207f5ad start implementing StyleEngine::apply
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 509
diff changeset
465 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
466 case CSS_PROPERTY_BORDER_RIGHT_STYLE:
577
9f7a3aa4e1f6 support more border-style
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 576
diff changeset
467 attrs->borderStyle.right = (BorderStyle) p->value.intVal;
9f7a3aa4e1f6 support more border-style
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 576
diff changeset
468 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
469 case CSS_PROPERTY_BORDER_TOP_STYLE:
577
9f7a3aa4e1f6 support more border-style
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 576
diff changeset
470 attrs->borderStyle.top = (BorderStyle) p->value.intVal;
576
66153396f4ba start implementing resolution of relative CSS values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 575
diff changeset
471 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
472 case CSS_PROPERTY_BORDER_BOTTOM_WIDTH:
1472
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
473 computeBorderWidth (&attrs->borderWidth.bottom, p, attrs->font);
579
a2c3ced33216 support more border-width
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 578
diff changeset
474 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
475 case CSS_PROPERTY_BORDER_LEFT_WIDTH:
1472
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
476 computeBorderWidth (&attrs->borderWidth.left, p, attrs->font);
579
a2c3ced33216 support more border-width
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 578
diff changeset
477 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
478 case CSS_PROPERTY_BORDER_RIGHT_WIDTH:
1472
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
479 computeBorderWidth (&attrs->borderWidth.right, p, attrs->font);
579
a2c3ced33216 support more border-width
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 578
diff changeset
480 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
481 case CSS_PROPERTY_BORDER_TOP_WIDTH:
1472
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
482 computeBorderWidth (&attrs->borderWidth.top, p, attrs->font);
579
a2c3ced33216 support more border-width
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 578
diff changeset
483 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
484 case CSS_PROPERTY_BORDER_SPACING:
998
9e07ea8a694b whitespace
Jorge Arellano Cid <jcid@dillo.org>
parents: 997
diff changeset
485 computeValue (&attrs->hBorderSpacing, p->value.intVal,attrs->font);
9e07ea8a694b whitespace
Jorge Arellano Cid <jcid@dillo.org>
parents: 997
diff changeset
486 computeValue (&attrs->vBorderSpacing, p->value.intVal,attrs->font);
576
66153396f4ba start implementing resolution of relative CSS values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 575
diff changeset
487 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
488 case CSS_PROPERTY_COLOR:
677
b6ef23efdac7 always use shaded colors
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 672
diff changeset
489 attrs->color = Color::create (layout, p->value.intVal);
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 921
diff changeset
490 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
491 case CSS_PROPERTY_CURSOR:
576
66153396f4ba start implementing resolution of relative CSS values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 575
diff changeset
492 attrs->cursor = (Cursor) p->value.intVal;
930
b277eed3119c whitespace cleanup: 's/ +$//g'
Jorge Arellano Cid <jcid@dillo.org>
parents: 921
diff changeset
493 break;
1460
a41372a38f02 set style.display in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1437
diff changeset
494 case CSS_PROPERTY_DISPLAY:
a41372a38f02 set style.display in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1437
diff changeset
495 attrs->display = (DisplayType) p->value.intVal;
a41372a38f02 set style.display in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1437
diff changeset
496 break;
1642
a4eb350d3db2 line-height
corvid, Johannes Hofmann
parents: 1524
diff changeset
497 case CSS_PROPERTY_LINE_HEIGHT:
a4eb350d3db2 line-height
corvid, Johannes Hofmann
parents: 1524
diff changeset
498 if (p->type == CSS_TYPE_ENUM) { //only valid enum value is "normal"
a4eb350d3db2 line-height
corvid, Johannes Hofmann
parents: 1524
diff changeset
499 attrs->lineHeight = dw::core::style::LENGTH_AUTO;
a4eb350d3db2 line-height
corvid, Johannes Hofmann
parents: 1524
diff changeset
500 } else if (p->type == CSS_TYPE_LENGTH_PERCENTAGE_NUMBER) {
a4eb350d3db2 line-height
corvid, Johannes Hofmann
parents: 1524
diff changeset
501 if (CSS_LENGTH_TYPE (p->value.intVal) == CSS_LENGTH_TYPE_NONE) {
a4eb350d3db2 line-height
corvid, Johannes Hofmann
parents: 1524
diff changeset
502 attrs->lineHeight =
a4eb350d3db2 line-height
corvid, Johannes Hofmann
parents: 1524
diff changeset
503 createPerLength(CSS_LENGTH_VALUE(p->value.intVal));
1720
d9765916771e don't try to set lineHeight if illegal value 'auto' is specified
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1719
diff changeset
504 } else if (computeValue (&lineHeight, p->value.intVal,
d9765916771e don't try to set lineHeight if illegal value 'auto' is specified
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1719
diff changeset
505 attrs->font, attrs->font->size)) {
1642
a4eb350d3db2 line-height
corvid, Johannes Hofmann
parents: 1524
diff changeset
506 attrs->lineHeight = createAbsLength(lineHeight);
a4eb350d3db2 line-height
corvid, Johannes Hofmann
parents: 1524
diff changeset
507 }
a4eb350d3db2 line-height
corvid, Johannes Hofmann
parents: 1524
diff changeset
508 }
a4eb350d3db2 line-height
corvid, Johannes Hofmann
parents: 1524
diff changeset
509 break;
1464
2ed2df2dfaad add support for CSS property list-style-position
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1460
diff changeset
510 case CSS_PROPERTY_LIST_STYLE_POSITION:
2ed2df2dfaad add support for CSS property list-style-position
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1460
diff changeset
511 attrs->listStylePosition = (ListStylePosition) p->value.intVal;
2ed2df2dfaad add support for CSS property list-style-position
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1460
diff changeset
512 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
513 case CSS_PROPERTY_LIST_STYLE_TYPE:
533
0ae28670be00 make CssProperty::Value a union of int and char*
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 532
diff changeset
514 attrs->listStyleType = (ListStyleType) p->value.intVal;
529
a88b4a31cb7a make ol work
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 526
diff changeset
515 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
516 case CSS_PROPERTY_MARGIN_BOTTOM:
659
920e6090d6d6 use output parameter in StyleEngine::computeValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 658
diff changeset
517 computeValue (&attrs->margin.bottom, p->value.intVal, attrs->font);
1039
4ed33b76809c wrap long lines in src/ css code
corvid <corvid@lavabit.com>
parents: 1035
diff changeset
518 if (attrs->margin.bottom < 0) // \todo fix negative margins in dw/*
1018
1949cc16378f disable negative margins for now
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1006
diff changeset
519 attrs->margin.bottom = 0;
568
532277951457 support more CSS_PROPERTY_MARGIN* props; fix primary order
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 566
diff changeset
520 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
521 case CSS_PROPERTY_MARGIN_LEFT:
659
920e6090d6d6 use output parameter in StyleEngine::computeValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 658
diff changeset
522 computeValue (&attrs->margin.left, p->value.intVal, attrs->font);
1018
1949cc16378f disable negative margins for now
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1006
diff changeset
523 if (attrs->margin.left < 0) // \todo fix negative margins in dw/*
1949cc16378f disable negative margins for now
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1006
diff changeset
524 attrs->margin.left = 0;
568
532277951457 support more CSS_PROPERTY_MARGIN* props; fix primary order
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 566
diff changeset
525 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
526 case CSS_PROPERTY_MARGIN_RIGHT:
659
920e6090d6d6 use output parameter in StyleEngine::computeValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 658
diff changeset
527 computeValue (&attrs->margin.right, p->value.intVal, attrs->font);
1018
1949cc16378f disable negative margins for now
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1006
diff changeset
528 if (attrs->margin.right < 0) // \todo fix negative margins in dw/*
1949cc16378f disable negative margins for now
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1006
diff changeset
529 attrs->margin.right = 0;
568
532277951457 support more CSS_PROPERTY_MARGIN* props; fix primary order
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 566
diff changeset
530 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
531 case CSS_PROPERTY_MARGIN_TOP:
659
920e6090d6d6 use output parameter in StyleEngine::computeValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 658
diff changeset
532 computeValue (&attrs->margin.top, p->value.intVal, attrs->font);
1018
1949cc16378f disable negative margins for now
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1006
diff changeset
533 if (attrs->margin.top < 0) // \todo fix negative margins in dw/*
1949cc16378f disable negative margins for now
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1006
diff changeset
534 attrs->margin.top = 0;
568
532277951457 support more CSS_PROPERTY_MARGIN* props; fix primary order
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 566
diff changeset
535 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
536 case CSS_PROPERTY_PADDING_TOP:
659
920e6090d6d6 use output parameter in StyleEngine::computeValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 658
diff changeset
537 computeValue (&attrs->padding.top, p->value.intVal, attrs->font);
595
69892f9e6d6c support padding-* and set it for <td>
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 591
diff changeset
538 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
539 case CSS_PROPERTY_PADDING_BOTTOM:
998
9e07ea8a694b whitespace
Jorge Arellano Cid <jcid@dillo.org>
parents: 997
diff changeset
540 computeValue (&attrs->padding.bottom, p->value.intVal,attrs->font);
595
69892f9e6d6c support padding-* and set it for <td>
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 591
diff changeset
541 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
542 case CSS_PROPERTY_PADDING_LEFT:
659
920e6090d6d6 use output parameter in StyleEngine::computeValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 658
diff changeset
543 computeValue (&attrs->padding.left, p->value.intVal, attrs->font);
595
69892f9e6d6c support padding-* and set it for <td>
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 591
diff changeset
544 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
545 case CSS_PROPERTY_PADDING_RIGHT:
659
920e6090d6d6 use output parameter in StyleEngine::computeValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 658
diff changeset
546 computeValue (&attrs->padding.right, p->value.intVal, attrs->font);
595
69892f9e6d6c support padding-* and set it for <td>
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 591
diff changeset
547 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
548 case CSS_PROPERTY_TEXT_ALIGN:
533
0ae28670be00 make CssProperty::Value a union of int and char*
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 532
diff changeset
549 attrs->textAlign = (TextAlignType) p->value.intVal;
530
b0e3156bfeec fix text alignment
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 529
diff changeset
550 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
551 case CSS_PROPERTY_TEXT_DECORATION:
533
0ae28670be00 make CssProperty::Value a union of int and char*
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 532
diff changeset
552 attrs->textDecoration |= p->value.intVal;
516
81b8543357b6 fix some bugs
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 515
diff changeset
553 break;
1755
71f7877a5d37 css text-indent property
corvid <corvid@lavabit.com>
parents: 1749
diff changeset
554 case CSS_PROPERTY_TEXT_INDENT:
71f7877a5d37 css text-indent property
corvid <corvid@lavabit.com>
parents: 1749
diff changeset
555 computeLength (&attrs->textIndent, p->value.intVal, attrs->font);
71f7877a5d37 css text-indent property
corvid <corvid@lavabit.com>
parents: 1749
diff changeset
556 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
557 case CSS_PROPERTY_VERTICAL_ALIGN:
543
74c07ade1edc convert table code to new style handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 535
diff changeset
558 attrs->valign = (VAlignType) p->value.intVal;
74c07ade1edc convert table code to new style handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 535
diff changeset
559 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
560 case CSS_PROPERTY_WHITE_SPACE:
663
fbeaa9990ff3 support white-space property
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 660
diff changeset
561 attrs->whiteSpace = (WhiteSpace) p->value.intVal;
fbeaa9990ff3 support white-space property
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 660
diff changeset
562 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
563 case CSS_PROPERTY_WIDTH:
659
920e6090d6d6 use output parameter in StyleEngine::computeValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 658
diff changeset
564 computeLength (&attrs->width, p->value.intVal, attrs->font);
576
66153396f4ba start implementing resolution of relative CSS values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 575
diff changeset
565 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
566 case CSS_PROPERTY_HEIGHT:
659
920e6090d6d6 use output parameter in StyleEngine::computeValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 658
diff changeset
567 computeLength (&attrs->height, p->value.intVal, attrs->font);
920e6090d6d6 use output parameter in StyleEngine::computeValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 658
diff changeset
568 break;
1650
ef996982334c css word-spacing property
corvid <corvid@lavabit.com>
parents: 1642
diff changeset
569 case CSS_PROPERTY_WORD_SPACING:
ef996982334c css word-spacing property
corvid <corvid@lavabit.com>
parents: 1642
diff changeset
570 if (p->type == CSS_TYPE_ENUM) {
ef996982334c css word-spacing property
corvid <corvid@lavabit.com>
parents: 1642
diff changeset
571 if (p->value.intVal == CSS_WORD_SPACING_NORMAL) {
ef996982334c css word-spacing property
corvid <corvid@lavabit.com>
parents: 1642
diff changeset
572 attrs->wordSpacing = 0;
ef996982334c css word-spacing property
corvid <corvid@lavabit.com>
parents: 1642
diff changeset
573 }
ef996982334c css word-spacing property
corvid <corvid@lavabit.com>
parents: 1642
diff changeset
574 } else {
ef996982334c css word-spacing property
corvid <corvid@lavabit.com>
parents: 1642
diff changeset
575 computeValue(&attrs->wordSpacing, p->value.intVal, attrs->font);
ef996982334c css word-spacing property
corvid <corvid@lavabit.com>
parents: 1642
diff changeset
576 }
ef996982334c css word-spacing property
corvid <corvid@lavabit.com>
parents: 1642
diff changeset
577
ef996982334c css word-spacing property
corvid <corvid@lavabit.com>
parents: 1642
diff changeset
578 /* Limit to reasonable values to avoid overflows */
ef996982334c css word-spacing property
corvid <corvid@lavabit.com>
parents: 1642
diff changeset
579 if (attrs->wordSpacing > 1000)
ef996982334c css word-spacing property
corvid <corvid@lavabit.com>
parents: 1642
diff changeset
580 attrs->wordSpacing = 1000;
ef996982334c css word-spacing property
corvid <corvid@lavabit.com>
parents: 1642
diff changeset
581 else if (attrs->wordSpacing < -1000)
ef996982334c css word-spacing property
corvid <corvid@lavabit.com>
parents: 1642
diff changeset
582 attrs->wordSpacing = -1000;
ef996982334c css word-spacing property
corvid <corvid@lavabit.com>
parents: 1642
diff changeset
583 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
584 case PROPERTY_X_LINK:
533
0ae28670be00 make CssProperty::Value a union of int and char*
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 532
diff changeset
585 attrs->x_link = p->value.intVal;
518
52394e6577ba add link support
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 516
diff changeset
586 break;
910
ca7c689d3873 move CssProperty::Name and CssProperty::Value out of CssProperty class
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
587 case PROPERTY_X_IMG:
533
0ae28670be00 make CssProperty::Value a union of int and char*
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 532
diff changeset
588 attrs->x_img = p->value.intVal;
510
2bc3d207f5ad start implementing StyleEngine::apply
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 509
diff changeset
589 break;
1340
37f26396a31b some tooltips
corvid <corvid@lavabit.com>
parents: 1326
diff changeset
590 case PROPERTY_X_TOOLTIP:
37f26396a31b some tooltips
corvid <corvid@lavabit.com>
parents: 1326
diff changeset
591 attrs->x_tooltip = Tooltip::create(layout, p->value.strVal);
37f26396a31b some tooltips
corvid <corvid@lavabit.com>
parents: 1326
diff changeset
592 break;
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
593 default:
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
594 break;
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
595 }
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
596 }
510
2bc3d207f5ad start implementing StyleEngine::apply
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 509
diff changeset
597
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
598 }
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
599
532
a41fe7c781cb add some comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 530
diff changeset
600 /**
573
79599d1a3fe9 compute relative values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 568
diff changeset
601 * \brief Resolve relative lengths to absolute values.
79599d1a3fe9 compute relative values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 568
diff changeset
602 */
693
478dfc078e12 make StyleEngine::computeValue() and computeLength() return bool
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 682
diff changeset
603 bool StyleEngine::computeValue (int *dest, CssLength value, Font *font) {
573
79599d1a3fe9 compute relative values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 568
diff changeset
604 static float dpmm;
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
605
573
79599d1a3fe9 compute relative values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 568
diff changeset
606 if (dpmm == 0.0)
580
a06315c852e5 fix mm -> px conversion
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 579
diff changeset
607 dpmm = layout->dpiX () / 25.4; /* assume dpiX == dpiY */
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
608
573
79599d1a3fe9 compute relative values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 568
diff changeset
609 switch (CSS_LENGTH_TYPE (value)) {
79599d1a3fe9 compute relative values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 568
diff changeset
610 case CSS_LENGTH_TYPE_PX:
659
920e6090d6d6 use output parameter in StyleEngine::computeValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 658
diff changeset
611 *dest = (int) CSS_LENGTH_VALUE (value);
693
478dfc078e12 make StyleEngine::computeValue() and computeLength() return bool
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 682
diff changeset
612 return true;
573
79599d1a3fe9 compute relative values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 568
diff changeset
613 case CSS_LENGTH_TYPE_MM:
1693
a9a11a23d707 add lout::misc::roundInt() for double -> int conversion
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1650
diff changeset
614 *dest = roundInt (CSS_LENGTH_VALUE (value) * dpmm);
693
478dfc078e12 make StyleEngine::computeValue() and computeLength() return bool
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 682
diff changeset
615 return true;
573
79599d1a3fe9 compute relative values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 568
diff changeset
616 case CSS_LENGTH_TYPE_EM:
1693
a9a11a23d707 add lout::misc::roundInt() for double -> int conversion
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1650
diff changeset
617 *dest = roundInt (CSS_LENGTH_VALUE (value) * font->size);
693
478dfc078e12 make StyleEngine::computeValue() and computeLength() return bool
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 682
diff changeset
618 return true;
573
79599d1a3fe9 compute relative values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 568
diff changeset
619 case CSS_LENGTH_TYPE_EX:
1693
a9a11a23d707 add lout::misc::roundInt() for double -> int conversion
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1650
diff changeset
620 *dest = roundInt (CSS_LENGTH_VALUE(value) * font->xHeight);
693
478dfc078e12 make StyleEngine::computeValue() and computeLength() return bool
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 682
diff changeset
621 return true;
1999
586c7a6f61aa fix handling of CSS length values of 0 without unit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1779
diff changeset
622 case CSS_LENGTH_TYPE_NONE:
586c7a6f61aa fix handling of CSS length values of 0 without unit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1779
diff changeset
623 // length values other than 0 without unit are only allowed
586c7a6f61aa fix handling of CSS length values of 0 without unit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1779
diff changeset
624 // in special cases (line-height) and have to be handled
586c7a6f61aa fix handling of CSS length values of 0 without unit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1779
diff changeset
625 // separately.
586c7a6f61aa fix handling of CSS length values of 0 without unit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1779
diff changeset
626 assert ((int) CSS_LENGTH_VALUE (value) == 0);
586c7a6f61aa fix handling of CSS length values of 0 without unit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1779
diff changeset
627 *dest = 0;
586c7a6f61aa fix handling of CSS length values of 0 without unit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1779
diff changeset
628 return true;
573
79599d1a3fe9 compute relative values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 568
diff changeset
629 default:
79599d1a3fe9 compute relative values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 568
diff changeset
630 break;
79599d1a3fe9 compute relative values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 568
diff changeset
631 }
693
478dfc078e12 make StyleEngine::computeValue() and computeLength() return bool
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 682
diff changeset
632
478dfc078e12 make StyleEngine::computeValue() and computeLength() return bool
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 682
diff changeset
633 return false;
573
79599d1a3fe9 compute relative values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 568
diff changeset
634 }
79599d1a3fe9 compute relative values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 568
diff changeset
635
693
478dfc078e12 make StyleEngine::computeValue() and computeLength() return bool
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 682
diff changeset
636 bool StyleEngine::computeValue (int *dest, CssLength value, Font *font,
659
920e6090d6d6 use output parameter in StyleEngine::computeValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 658
diff changeset
637 int percentageBase) {
693
478dfc078e12 make StyleEngine::computeValue() and computeLength() return bool
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 682
diff changeset
638 if (CSS_LENGTH_TYPE (value) == CSS_LENGTH_TYPE_PERCENTAGE) {
1693
a9a11a23d707 add lout::misc::roundInt() for double -> int conversion
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1650
diff changeset
639 *dest = roundInt (CSS_LENGTH_VALUE (value) * percentageBase);
693
478dfc078e12 make StyleEngine::computeValue() and computeLength() return bool
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 682
diff changeset
640 return true;
478dfc078e12 make StyleEngine::computeValue() and computeLength() return bool
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 682
diff changeset
641 } else
478dfc078e12 make StyleEngine::computeValue() and computeLength() return bool
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 682
diff changeset
642 return computeValue (dest, value, font);
659
920e6090d6d6 use output parameter in StyleEngine::computeValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 658
diff changeset
643 }
920e6090d6d6 use output parameter in StyleEngine::computeValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 658
diff changeset
644
693
478dfc078e12 make StyleEngine::computeValue() and computeLength() return bool
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 682
diff changeset
645 bool StyleEngine::computeLength (dw::core::style::Length *dest,
659
920e6090d6d6 use output parameter in StyleEngine::computeValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 658
diff changeset
646 CssLength value, Font *font) {
920e6090d6d6 use output parameter in StyleEngine::computeValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 658
diff changeset
647 int v;
920e6090d6d6 use output parameter in StyleEngine::computeValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 658
diff changeset
648
693
478dfc078e12 make StyleEngine::computeValue() and computeLength() return bool
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 682
diff changeset
649 if (CSS_LENGTH_TYPE (value) == CSS_LENGTH_TYPE_PERCENTAGE) {
659
920e6090d6d6 use output parameter in StyleEngine::computeValue()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 658
diff changeset
650 *dest = createPerLength (CSS_LENGTH_VALUE (value));
693
478dfc078e12 make StyleEngine::computeValue() and computeLength() return bool
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 682
diff changeset
651 return true;
801
ec76f63c44db start supporting "auto" value in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 790
diff changeset
652 } else if (CSS_LENGTH_TYPE (value) == CSS_LENGTH_TYPE_AUTO) {
ec76f63c44db start supporting "auto" value in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 790
diff changeset
653 *dest = dw::core::style::LENGTH_AUTO;
ec76f63c44db start supporting "auto" value in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 790
diff changeset
654 return true;
ec76f63c44db start supporting "auto" value in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 790
diff changeset
655 } else if (computeValue (&v, value, font)) {
ec76f63c44db start supporting "auto" value in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 790
diff changeset
656 *dest = createAbsLength (v);
ec76f63c44db start supporting "auto" value in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 790
diff changeset
657 return true;
ec76f63c44db start supporting "auto" value in CSS
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 790
diff changeset
658 }
693
478dfc078e12 make StyleEngine::computeValue() and computeLength() return bool
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 682
diff changeset
659
478dfc078e12 make StyleEngine::computeValue() and computeLength() return bool
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 682
diff changeset
660 return false;
658
ea961706be66 use CssLength type
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 657
diff changeset
661 }
573
79599d1a3fe9 compute relative values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 568
diff changeset
662
1472
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
663 void StyleEngine::computeBorderWidth (int *dest, CssProperty *p,
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
664 dw::core::style::Font *font) {
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
665 if (p->type == CSS_TYPE_ENUM) {
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
666 switch (p->value.intVal) {
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
667 case CSS_BORDER_WIDTH_THIN:
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
668 *dest = 1;
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
669 break;
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
670 case CSS_BORDER_WIDTH_MEDIUM:
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
671 *dest = 2;
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
672 break;
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
673 case CSS_BORDER_WIDTH_THICK:
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
674 *dest = 3;
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
675 break;
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
676 default:
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
677 assert(false);
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
678 }
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
679 } else {
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
680 computeValue (dest, p->value.intVal, font);
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
681 }
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
682 }
6ed936726b50 support border-width: thin | medium | thick
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1464
diff changeset
683
573
79599d1a3fe9 compute relative values
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 568
diff changeset
684 /**
956
dd46fa6ceb94 fix missing background color for ComplexButton (noticed by corvid)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 955
diff changeset
685 * \brief Similar to StyleEngine::style(), but with backgroundColor set.
dd46fa6ceb94 fix missing background color for ComplexButton (noticed by corvid)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 955
diff changeset
686 * A normal style might have backgroundColor == NULL to indicate a transparent
dd46fa6ceb94 fix missing background color for ComplexButton (noticed by corvid)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 955
diff changeset
687 * background. This method ensures that backgroundColor is set.
1326
02ef25700865 trim some spaces
corvid <corvid@lavabit.com>
parents: 1216
diff changeset
688 */
956
dd46fa6ceb94 fix missing background color for ComplexButton (noticed by corvid)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 955
diff changeset
689 Style * StyleEngine::backgroundStyle () {
1746
ef983c0fe908 fix Style leaks in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1743
diff changeset
690 if (!stack->getRef (stack->size () - 1)->backgroundStyle) {
ef983c0fe908 fix Style leaks in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1743
diff changeset
691 StyleAttrs attrs = *style ();
1326
02ef25700865 trim some spaces
corvid <corvid@lavabit.com>
parents: 1216
diff changeset
692
1746
ef983c0fe908 fix Style leaks in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1743
diff changeset
693 for (int i = stack->size () - 1; i >= 0 && ! attrs.backgroundColor; i--)
ef983c0fe908 fix Style leaks in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1743
diff changeset
694 attrs.backgroundColor = stack->getRef (i)->style->backgroundColor;
956
dd46fa6ceb94 fix missing background color for ComplexButton (noticed by corvid)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 955
diff changeset
695
1746
ef983c0fe908 fix Style leaks in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1743
diff changeset
696 assert (attrs.backgroundColor);
ef983c0fe908 fix Style leaks in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1743
diff changeset
697 stack->getRef (stack->size () - 1)->backgroundStyle =
ef983c0fe908 fix Style leaks in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1743
diff changeset
698 Style::create (layout, &attrs);
ef983c0fe908 fix Style leaks in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1743
diff changeset
699 }
ef983c0fe908 fix Style leaks in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1743
diff changeset
700 return stack->getRef (stack->size () - 1)->backgroundStyle;
956
dd46fa6ceb94 fix missing background color for ComplexButton (noticed by corvid)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 955
diff changeset
701 }
dd46fa6ceb94 fix missing background color for ComplexButton (noticed by corvid)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 955
diff changeset
702
dd46fa6ceb94 fix missing background color for ComplexButton (noticed by corvid)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 955
diff changeset
703 /**
532
a41fe7c781cb add some comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 530
diff changeset
704 * \brief Create a new style object based on the previously opened / closed
1437
16602aa5aabc comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1436
diff changeset
705 * HTML elements and the nonCssProperties that have been set.
16602aa5aabc comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1436
diff changeset
706 * This method is private. Call style() to get a current style object.
532
a41fe7c781cb add some comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 530
diff changeset
707 */
1734
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
708 Style * StyleEngine::style0 (int i) {
1733
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
709 CssPropertyList props, *styleAttrProperties, *nonCssProperties;
532
a41fe7c781cb add some comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 530
diff changeset
710 // get previous style from the stack
1734
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
711 StyleAttrs attrs = *stack->getRef (i - 1)->style;
980
11c6f887d649 reduce number of styleEngine::style0() calls
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 956
diff changeset
712
11c6f887d649 reduce number of styleEngine::style0() calls
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 956
diff changeset
713 // Ensure that StyleEngine::style0() has not been called before for
11c6f887d649 reduce number of styleEngine::style0() calls
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 956
diff changeset
714 // this element.
11c6f887d649 reduce number of styleEngine::style0() calls
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 956
diff changeset
715 // Style computation is expensive so limit it as much as possible.
1326
02ef25700865 trim some spaces
corvid <corvid@lavabit.com>
parents: 1216
diff changeset
716 // If this assertion is hit, you need to rearrange the code that is
1733
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
717 // doing styleEngine calls to call setNonCssHint() before calling
980
11c6f887d649 reduce number of styleEngine::style0() calls
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 956
diff changeset
718 // style() or wordStyle() for each new element.
1734
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
719 assert (stack->getRef (i)->style == NULL);
980
11c6f887d649 reduce number of styleEngine::style0() calls
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 956
diff changeset
720
543
74c07ade1edc convert table code to new style handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 535
diff changeset
721 // reset values that are not inherited according to CSS
74c07ade1edc convert table code to new style handling
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 535
diff changeset
722 attrs.resetValues ();
1711
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
723 preprocessAttrs (&attrs);
906
e766286e0884 inherit valign when inheritBackgroundColor is set
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 895
diff changeset
724
1734
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
725 styleAttrProperties = stack->getRef (i)->styleAttrProperties;
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
726 nonCssProperties = stack->getRef (i)->nonCssProperties;
780
3bea75694f07 implement parsing of CSS data from style attribute
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 777
diff changeset
727
3bea75694f07 implement parsing of CSS data from style attribute
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 777
diff changeset
728 // merge style information
1738
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1736
diff changeset
729 cssContext->apply (&props, doctree, stack->getRef(i)->doctreeNode,
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1736
diff changeset
730 styleAttrProperties, nonCssProperties);
780
3bea75694f07 implement parsing of CSS data from style attribute
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 777
diff changeset
731
3bea75694f07 implement parsing of CSS data from style attribute
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 777
diff changeset
732 // apply style
1738
7974b38cc036 use background-color on <html>-element
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1736
diff changeset
733 apply (i, &attrs, &props);
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
734
1711
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
735 postprocessAttrs (&attrs);
b27cf7eb15b6 fix last commit
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1710
diff changeset
736
1734
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
737 stack->getRef (i)->style = Style::create (layout, &attrs);
845
f325ea7239fa free font names from style="" attributes (found by Jeremy)
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 824
diff changeset
738
1734
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
739 return stack->getRef (i)->style;
509
fd2454cd0120 pass Layout to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 503
diff changeset
740 }
643
eb0279297fde hook up <style>...</style> parsing
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 638
diff changeset
741
1733
f39cfc38ea10 rework nonCssHints API of StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1732
diff changeset
742 Style * StyleEngine::wordStyle0 () {
644
9e4ad941cbdc add wordStyle() method to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 643
diff changeset
743 StyleAttrs attrs = *style ();
9e4ad941cbdc add wordStyle() method to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 643
diff changeset
744 attrs.resetValues ();
647
ed5ea857edc6 adjust inheritBackgroundColor() handling to new wordStyle() stuff
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 646
diff changeset
745
1734
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
746 if (stack->getRef (stack->size() - 1)->inheritBackgroundColor)
647
ed5ea857edc6 adjust inheritBackgroundColor() handling to new wordStyle() stuff
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 646
diff changeset
747 attrs.backgroundColor = style ()->backgroundColor;
ed5ea857edc6 adjust inheritBackgroundColor() handling to new wordStyle() stuff
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 646
diff changeset
748
755
bad0f47c6758 pass valign property from base style into wordStyle
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 739
diff changeset
749 attrs.valign = style ()->valign;
bad0f47c6758 pass valign property from base style into wordStyle
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 739
diff changeset
750
998
9e07ea8a694b whitespace
Jorge Arellano Cid <jcid@dillo.org>
parents: 997
diff changeset
751 stack->getRef(stack->size() - 1)->wordStyle = Style::create(layout, &attrs);
644
9e4ad941cbdc add wordStyle() method to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 643
diff changeset
752 return stack->getRef (stack->size () - 1)->wordStyle;
9e4ad941cbdc add wordStyle() method to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 643
diff changeset
753 }
9e4ad941cbdc add wordStyle() method to StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 643
diff changeset
754
1741
b35adbe0366c comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1739
diff changeset
755 /**
b35adbe0366c comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1739
diff changeset
756 * \brief Recompute all style information from scratch
1770
4779a3d891a1 trim some spaces
corvid <corvid@lavabit.com>
parents: 1759
diff changeset
757 * This is used to take into account CSS styles for the HTML-element.
1741
b35adbe0366c comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1739
diff changeset
758 * The CSS data is only completely available after parsing the HEAD-section
b35adbe0366c comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1739
diff changeset
759 * and thereby after the HTML-element has been opened.
b35adbe0366c comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1739
diff changeset
760 * Note that restyle() does not change any styles in the widget tree.
b35adbe0366c comments
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1739
diff changeset
761 */
1734
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
762 void StyleEngine::restyle () {
1736
6b1ecbfe96b5 start restyling at 1
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1734
diff changeset
763 for (int i = 1; i < stack->size (); i++) {
1734
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
764 Node *n = stack->getRef (i);
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
765 if (n->style) {
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
766 n->style->unref ();
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
767 n->style = NULL;
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
768 }
1746
ef983c0fe908 fix Style leaks in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1743
diff changeset
769 if (n->wordStyle) {
ef983c0fe908 fix Style leaks in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1743
diff changeset
770 n->wordStyle->unref ();
ef983c0fe908 fix Style leaks in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1743
diff changeset
771 n->wordStyle = NULL;
ef983c0fe908 fix Style leaks in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1743
diff changeset
772 }
1747
4e57bc05b69d also recompute backgroundStyle in StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1746
diff changeset
773 if (n->backgroundStyle) {
4e57bc05b69d also recompute backgroundStyle in StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1746
diff changeset
774 n->backgroundStyle->unref ();
4e57bc05b69d also recompute backgroundStyle in StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1746
diff changeset
775 n->backgroundStyle = NULL;
4e57bc05b69d also recompute backgroundStyle in StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1746
diff changeset
776 }
1746
ef983c0fe908 fix Style leaks in StyleEngine
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1743
diff changeset
777
1734
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
778 style0 (i);
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
779 }
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
780 }
90feb0de4310 add StyleEngine::restyle()
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1733
diff changeset
781
1039
4ed33b76809c wrap long lines in src/ css code
corvid <corvid@lavabit.com>
parents: 1035
diff changeset
782 void StyleEngine::parse (DilloHtml *html, DilloUrl *url, const char *buf,
4ed33b76809c wrap long lines in src/ css code
corvid <corvid@lavabit.com>
parents: 1035
diff changeset
783 int buflen, CssOrigin origin) {
1035
474b9814a8fa support CSS @import directive
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1018
diff changeset
784 if (importDepth > 10) { // avoid looping with recursive @import directives
1039
4ed33b76809c wrap long lines in src/ css code
corvid <corvid@lavabit.com>
parents: 1035
diff changeset
785 MSG_WARN("Maximum depth of CSS @import reached--ignoring stylesheet.\n");
1035
474b9814a8fa support CSS @import directive
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1018
diff changeset
786 return;
474b9814a8fa support CSS @import directive
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1018
diff changeset
787 }
474b9814a8fa support CSS @import directive
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1018
diff changeset
788
474b9814a8fa support CSS @import directive
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1018
diff changeset
789 importDepth++;
474b9814a8fa support CSS @import directive
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1018
diff changeset
790 CssParser::parse (html, url, cssContext, buf, buflen, origin);
474b9814a8fa support CSS @import directive
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 1018
diff changeset
791 importDepth--;
643
eb0279297fde hook up <style>...</style> parsing
Johannes Hofmann <Johannes.Hofmann@gmx.de>
parents: 638
diff changeset
792 }