diff options
Diffstat (limited to 'src/styleengine.cc')
-rw-r--r-- | src/styleengine.cc | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/styleengine.cc b/src/styleengine.cc index 3f674dec..7ca398a9 100644 --- a/src/styleengine.cc +++ b/src/styleengine.cc @@ -12,6 +12,7 @@ #include "../dlib/dlib.h" #include "msg.h" #include "prefs.h" +#include "misc.h" #include "html_common.hh" #include "styleengine.hh" @@ -25,6 +26,8 @@ StyleEngine::StyleEngine (dw::core::Layout *layout) { doctree = new Doctree (); stack = new lout::misc::SimpleVector <Node> (1); cssContext = new CssContext (); + buildUserAgentStyle (); + buildUserStyle (); this->layout = layout; importDepth = 0; @@ -807,3 +810,68 @@ void StyleEngine::parse (DilloHtml *html, DilloUrl *url, const char *buf, CssParser::parse (html, url, cssContext, buf, buflen, origin); importDepth--; } + +/** + * \brief Create the user agent style. + * + * The user agent style defines how dillo renders HTML in the absence of + * author or user styles. + */ +void StyleEngine::buildUserAgentStyle () { + const char *cssBuf = + "body {margin: 5px}" + "big {font-size: 1.17em}" + "blockquote, dd {margin-left: 40px; margin-right: 40px}" + "center {text-align: center}" + "dt {font-weight: bolder}" + ":link {color: blue; text-decoration: underline; cursor: pointer}" + ":visited {color: #800080; text-decoration: underline; cursor: pointer}" + "h1, h2, h3, h4, h5, h6, b, strong {font-weight: bolder}" + "i, em, cite, address, var {font-style: italic}" + ":link img, :visited img {border: 1px solid}" + "frameset, ul, ol, dir {margin-left: 40px}" + "h1 {font-size: 2em; margin-top: .67em; margin-bottom: 0}" + "h2 {font-size: 1.5em; margin-top: .75em; margin-bottom: 0}" + "h3 {font-size: 1.17em; margin-top: .83em; margin-bottom: 0}" + "h4 {margin-top: 1.12em; margin-bottom: 0}" + "h5 {font-size: 0.83em; margin-top: 1.5em; margin-bottom: 0}" + "h6 {font-size: 0.75em; margin-top: 1.67em; margin-bottom: 0}" + "hr {width: 100%; border: 1px inset}" + "li {margin-top: 0.1em}" + "pre {white-space: pre}" + "ol {list-style-type: decimal}" + "ul {list-style-type: disc}" + "ul ul {list-style-type: circle}" + "ul ul ul {list-style-type: square}" + "ul ul ul ul {list-style-type: disc}" + "u {text-decoration: underline}" + "small, sub, sup {font-size: 0.83em}" + "sub {vertical-align: sub}" + "sup {vertical-align: super}" + "s, strike, del {text-decoration: line-through}" + "table {border-spacing: 2px}" + "td, th {padding: 2px}" + "thead, tbody, tfoot {vertical-align: middle}" + "th {font-weight: bolder; text-align: center}" + "code, tt, pre, samp, kbd {font-family: monospace}" + /* WORKAROUND: Reset font properties in tables as some + * pages rely on it (e.g. gmail). + * http://developer.mozilla.org/En/Fixing_Table_Inheritance_in_Quirks_Mode + * has a detailed description of the issue. + */ + "table, caption {font-size: medium; font-weight: normal}"; + + CssParser::parse (NULL, NULL, cssContext, cssBuf, strlen (cssBuf), + CSS_ORIGIN_USER_AGENT); +} + +void StyleEngine::buildUserStyle () { + Dstr *style; + char *filename = dStrconcat(dGethomedir(), "/.dillo/style.css", NULL); + + if ((style = a_Misc_file2dstr(filename))) { + CssParser::parse (NULL,NULL,cssContext,style->str, style->len,CSS_ORIGIN_USER); + dStr_free (style, 1); + } + dFree (filename); +} |