From 399b0fa3b970ec1ff6969902639d5058c3e732a9 Mon Sep 17 00:00:00 2001 From: corvid Date: Mon, 16 May 2011 19:13:04 +0000 Subject: rm spaces --- src/cssparser.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/cssparser.cc') diff --git a/src/cssparser.cc b/src/cssparser.cc index aa4cea56..1075ef63 100644 --- a/src/cssparser.cc +++ b/src/cssparser.cc @@ -1522,7 +1522,7 @@ const char * CssParser::propertyNameString(CssPropertyName name) { return Css_property_info[name].symbol; } - + void CssParser::ignoreBlock() { int depth = 0; -- cgit v1.2.3 From d9d884f2437dcfaf9bb576194767247616e5efdb Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Tue, 7 Jun 2011 12:06:52 +0200 Subject: support !important in style attributes --- ChangeLog | 1 + config.h.in | 5 +---- src/css.cc | 6 +++++- src/css.hh | 3 ++- src/cssparser.cc | 14 ++++---------- src/cssparser.hh | 5 +++-- src/styleengine.cc | 23 +++++++++++++++++------ src/styleengine.hh | 1 + 8 files changed, 34 insertions(+), 24 deletions(-) (limited to 'src/cssparser.cc') diff --git a/ChangeLog b/ChangeLog index febfd507..9a1f04b7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -27,6 +27,7 @@ dillo-2.2.1 [not released yet] +- Reintroduce bg_color dillorc option. - Make Dillo compile with Clang. - Fix Textblock flushing. + - Support !important in style attributes. Patches: Johannes Hofmann +- Implement line-height. - Draw image maps when image not loaded. diff --git a/config.h.in b/config.h.in index 371d658f..fcffdf8f 100644 --- a/config.h.in +++ b/config.h.in @@ -78,9 +78,6 @@ /* Define to the one symbol short name of this package. */ #undef PACKAGE_TARNAME -/* Define to the home page for this package. */ -#undef PACKAGE_URL - /* Define to the version of this package. */ #undef PACKAGE_VERSION @@ -106,7 +103,7 @@ #undef VERSION /* Define for Solaris 2.5.1 so the uint32_t typedef from , - , or is not used. If the typedef were allowed, the + , or is not used. If the typedef was allowed, the #define below would cause a syntax error. */ #undef _UINT32_T diff --git a/src/css.cc b/src/css.cc index cb0864fd..d8f086db 100644 --- a/src/css.cc +++ b/src/css.cc @@ -535,7 +535,8 @@ CssContext::~CssContext () { */ void CssContext::apply (CssPropertyList *props, Doctree *docTree, DoctreeNode *node, - CssPropertyList *tagStyle, CssPropertyList *nonCssHints) { + CssPropertyList *tagStyle, CssPropertyList *tagStyleImportant, + CssPropertyList *nonCssHints) { if (sheet[CSS_PRIMARY_USER_AGENT]) sheet[CSS_PRIMARY_USER_AGENT]->apply (props, docTree, node); @@ -554,6 +555,9 @@ void CssContext::apply (CssPropertyList *props, Doctree *docTree, if (sheet[CSS_PRIMARY_AUTHOR_IMPORTANT]) sheet[CSS_PRIMARY_AUTHOR_IMPORTANT]->apply (props, docTree, node); + if (tagStyleImportant) + tagStyleImportant->apply (props); + if (sheet[CSS_PRIMARY_USER_IMPORTANT]) sheet[CSS_PRIMARY_USER_IMPORTANT]->apply (props, docTree, node); } diff --git a/src/css.hh b/src/css.hh index bf7d3c1d..61c1d12f 100644 --- a/src/css.hh +++ b/src/css.hh @@ -475,7 +475,8 @@ class CssContext { CssPrimaryOrder order); void apply (CssPropertyList *props, Doctree *docTree, DoctreeNode *node, - CssPropertyList *tagStyle, CssPropertyList *nonCssHints); + CssPropertyList *tagStyle, CssPropertyList *tagStyleImportant, + CssPropertyList *nonCssHints); }; #endif diff --git a/src/cssparser.cc b/src/cssparser.cc index aa4cea56..4838f607 100644 --- a/src/cssparser.cc +++ b/src/cssparser.cc @@ -1590,22 +1590,16 @@ void CssParser::parse(DilloHtml *html, DilloUrl *url, CssContext * context, } } -CssPropertyList *CssParser::parseDeclarationBlock(const char *buf, int buflen) +void CssParser::parseDeclarationBlock(const char *buf, int buflen, + CssPropertyList *props, + CssPropertyList *propsImortant) { - CssPropertyList *props = new CssPropertyList (true); CssParser parser (NULL, CSS_ORIGIN_AUTHOR, buf, buflen); parser.withinBlock = true; do - parser.parseDeclaration(props, NULL); + parser.parseDeclaration(props, propsImortant); while (!(parser.ttype == CSS_TK_END || (parser.ttype == CSS_TK_CHAR && parser.tval[0] == '}'))); - - if (props->size () == 0) { - delete props; - props = NULL; - } - - return props; } diff --git a/src/cssparser.hh b/src/cssparser.hh index 1542405d..8609877b 100644 --- a/src/cssparser.hh +++ b/src/cssparser.hh @@ -47,8 +47,9 @@ class CssParser { void ignoreStatement(); public: - static CssPropertyList *parseDeclarationBlock(const char *buf, - int buflen); + static void parseDeclarationBlock(const char *buf, int buflen, + CssPropertyList *props, + CssPropertyList *propsImortant); static void parse(DilloHtml *html, DilloUrl *url, CssContext *context, const char *buf, int buflen, CssOrigin origin); static const char *propertyNameString(CssPropertyName name); diff --git a/src/styleengine.cc b/src/styleengine.cc index d763146e..9a8a1738 100644 --- a/src/styleengine.cc +++ b/src/styleengine.cc @@ -52,6 +52,7 @@ StyleEngine::StyleEngine (dw::core::Layout *layout) { n->wordStyle = NULL; n->backgroundStyle = NULL; n->styleAttrProperties = NULL; + n->styleAttrPropertiesImportant = NULL; n->nonCssProperties = NULL; n->inheritBackgroundColor = false; } @@ -82,6 +83,7 @@ void StyleEngine::startElement (int element) { stack->increase (); Node *n = stack->getRef (stack->size () - 1); n->styleAttrProperties = NULL; + n->styleAttrPropertiesImportant = NULL; n->nonCssProperties = NULL; n->style = NULL; n->wordStyle = NULL; @@ -138,10 +140,14 @@ void StyleEngine::setStyle (const char *styleAttr) { Node *n = stack->getRef (stack->size () - 1); assert (n->styleAttrProperties == NULL); // parse style information from style="" attribute, if it exists - if (styleAttr && prefs.parse_embedded_css) - n->styleAttrProperties = - CssParser::parseDeclarationBlock (styleAttr, - strlen (styleAttr)); + if (styleAttr && prefs.parse_embedded_css) { + n->styleAttrProperties = new CssPropertyList (true); + n->styleAttrPropertiesImportant = new CssPropertyList (true); + + CssParser::parseDeclarationBlock (styleAttr, strlen (styleAttr), + n->styleAttrProperties, + n->styleAttrPropertiesImportant); + } }; /** @@ -213,6 +219,8 @@ void StyleEngine::endElement (int element) { if (n->styleAttrProperties) delete n->styleAttrProperties; + if (n->styleAttrPropertiesImportant) + delete n->styleAttrPropertiesImportant; if (n->nonCssProperties) delete n->nonCssProperties; if (n->style) @@ -706,7 +714,8 @@ Style * StyleEngine::backgroundStyle () { * This method is private. Call style() to get a current style object. */ Style * StyleEngine::style0 (int i) { - CssPropertyList props, *styleAttrProperties, *nonCssProperties; + CssPropertyList props, *styleAttrProperties, *styleAttrPropertiesImportant; + CssPropertyList *nonCssProperties; // get previous style from the stack StyleAttrs attrs = *stack->getRef (i - 1)->style; @@ -723,11 +732,13 @@ Style * StyleEngine::style0 (int i) { preprocessAttrs (&attrs); styleAttrProperties = stack->getRef (i)->styleAttrProperties; + styleAttrPropertiesImportant = stack->getRef(i)->styleAttrPropertiesImportant; nonCssProperties = stack->getRef (i)->nonCssProperties; // merge style information cssContext->apply (&props, doctree, stack->getRef(i)->doctreeNode, - styleAttrProperties, nonCssProperties); + styleAttrProperties, styleAttrPropertiesImportant, + nonCssProperties); // apply style apply (i, &attrs, &props); diff --git a/src/styleengine.hh b/src/styleengine.hh index e37aeed1..b73a8b5f 100644 --- a/src/styleengine.hh +++ b/src/styleengine.hh @@ -21,6 +21,7 @@ class StyleEngine { private: struct Node { CssPropertyList *styleAttrProperties; + CssPropertyList *styleAttrPropertiesImportant; CssPropertyList *nonCssProperties; dw::core::style::Style *style; dw::core::style::Style *wordStyle; -- cgit v1.2.3 From 86ad9513a8d090501dd602b00b70fecc31eeaaa4 Mon Sep 17 00:00:00 2001 From: Jorge Arellano Cid Date: Tue, 21 Jun 2011 21:06:38 -0400 Subject: Eliminated a pack of 22 compiler warnings (gcc-4.6.1 amd64) --- dpi/downloads.cc | 3 --- dpid/misc_new.c | 6 ++---- dpip/dpip.c | 15 ++++++++------- dw/fltkui.cc | 2 +- dw/style.cc | 23 ++++++++++++----------- src/cssparser.cc | 3 +-- src/html.cc | 12 ++---------- src/nav.c | 3 +-- src/table.cc | 9 ++------- src/ui.cc | 2 +- test/dw_anchors_test.cc | 2 +- 11 files changed, 31 insertions(+), 49 deletions(-) (limited to 'src/cssparser.cc') diff --git a/dpi/downloads.cc b/dpi/downloads.cc index 47ef4e0d..46e847ff 100644 --- a/dpi/downloads.cc +++ b/dpi/downloads.cc @@ -599,13 +599,11 @@ static void read_log_cb(int fd_in, void *data) const int BufLen = 4096; char Buf[BufLen]; ssize_t st; - int ret = -1; do { st = read(fd_in, Buf, BufLen); if (st < 0) { if (errno == EAGAIN) { - ret = 1; break; } perror("read, "); @@ -614,7 +612,6 @@ static void read_log_cb(int fd_in, void *data) close(fd_in); Fl::remove_fd(fd_in, 1); dl_item->log_done(1); - ret = 0; break; } else { dl_item->log_text_add(Buf, st); diff --git a/dpid/misc_new.c b/dpid/misc_new.c index 7f963aed..8c07a4eb 100644 --- a/dpid/misc_new.c +++ b/dpid/misc_new.c @@ -71,14 +71,12 @@ Dstr *a_Misc_rdtag(int socket) */ char *a_Misc_readtag(int sock) { - char *tag, c, buf[10]; - size_t buflen, i; + char *tag, c; + size_t i; size_t taglen = 0, tagmem = 10; ssize_t rdln = 1; tag = NULL; - buf[0] = '\0'; - buflen = sizeof(buf) / sizeof(buf[0]); // new start tag = (char *) dMalloc(tagmem + 1); for (i = 0; (rdln = read(sock, &c, 1)) != 0; i++) { diff --git a/dpip/dpip.c b/dpip/dpip.c index a5517784..170e4a88 100644 --- a/dpip/dpip.c +++ b/dpip/dpip.c @@ -214,11 +214,13 @@ int a_Dpip_check_auth(const char *auth_tag) MSG_ERR("[a_Dpip_check_auth] empty file: %s\n", fname); } else { port = strtol(rcline, &tail, 10); - for (i = 0; *tail && isxdigit(tail[i+1]); ++i) - SharedSecret[i] = tail[i+1]; - SharedSecret[i] = 0; - if (strcmp(msg, SharedSecret) == 0) - ret = 1; + if (tail && port != 0) { + for (i = 0; *tail && isxdigit(tail[i+1]); ++i) + SharedSecret[i] = tail[i+1]; + SharedSecret[i] = 0; + if (strcmp(msg, SharedSecret) == 0) + ret = 1; + } } if (In) fclose(In); @@ -376,7 +378,7 @@ int a_Dpip_dsh_write_str(Dsh *dsh, int flush, const char *str) static void Dpip_dsh_read(Dsh *dsh, int blocking) { char buf[RBUF_SZ]; - int req_mode, old_flags = 0, st, ret = -3, nb = !blocking; + int req_mode, old_flags = 0, st, nb = !blocking; dReturn_if (dsh->status == DPIP_ERROR || dsh->status == DPIP_EOF); @@ -395,7 +397,6 @@ static void Dpip_dsh_read(Dsh *dsh, int blocking) continue; } else if (errno == EAGAIN) { dsh->status = DPIP_EAGAIN; - ret = -1; break; } else { MSG_ERR("[Dpip_dsh_read] %s\n", dStrerror(errno)); diff --git a/dw/fltkui.cc b/dw/fltkui.cc index 1f0422b2..43a0d869 100644 --- a/dw/fltkui.cc +++ b/dw/fltkui.cc @@ -1126,7 +1126,7 @@ void *FltkListResource::newItem (const char *str, bool enabled, bool selected) enabled &= parent->is_active(); item->activate(enabled); - item->user_data((void *)index); + item->user_data((void*)(long)index); itemsSelected.increase (); itemsSelected.set (itemsSelected.size() - 1, selected); diff --git a/dw/style.cc b/dw/style.cc index 7020503e..c8cab24f 100644 --- a/dw/style.cc +++ b/dw/style.cc @@ -815,8 +815,7 @@ void drawBorder (View *view, Rectangle *area, Style *style, bool inverse) { /** \todo a lot! */ - Color::Shading dark, light, normal; - int xb1, yb1, xb2, yb2, xp1, yp1, xp2, yp2; + int xb1, yb1, xb2, yb2; // top left and bottom right point of outer border boundary xb1 = x + style->margin.left; @@ -824,15 +823,17 @@ void drawBorder (View *view, Rectangle *area, xb2 = x + (width > 0 ? width - 1 : 0) - style->margin.right; yb2 = y + (height > 0 ? height - 1 : 0) - style->margin.bottom; - // top left and bottom right point of inner border boundary - xp1 = xb1 + style->borderWidth.left; - yp1 = yb1 + style->borderWidth.top; - xp2 = xb2 - style->borderWidth.right; - yp2 = yb2 - style->borderWidth.bottom; - - light = inverse ? Color::SHADING_DARK : Color::SHADING_LIGHT; - dark = inverse ? Color::SHADING_LIGHT : Color::SHADING_DARK; - normal = inverse ? Color::SHADING_INVERSE : Color::SHADING_NORMAL; + /* + // top left and bottom right point of inner border boundary + xp1 = xb1 + style->borderWidth.left; + yp1 = yb1 + style->borderWidth.top; + xp2 = xb2 - style->borderWidth.right; + yp2 = yb2 - style->borderWidth.bottom; + + light = inverse ? Color::SHADING_DARK : Color::SHADING_LIGHT; + dark = inverse ? Color::SHADING_LIGHT : Color::SHADING_DARK; + normal = inverse ? Color::SHADING_INVERSE : Color::SHADING_NORMAL; + */ drawBorderRight(view, style, xb2, yb1, xb2, yb2); drawBorderLeft(view, style, xb1, yb1, xb1, yb2); diff --git a/src/cssparser.cc b/src/cssparser.cc index f173f403..3d62b31d 100644 --- a/src/cssparser.cc +++ b/src/cssparser.cc @@ -1049,7 +1049,7 @@ void CssParser::parseDeclaration(CssPropertyList * props, CssPropertyList * importantProps) { CssPropertyInfo pi = {NULL, {CSS_TYPE_UNUSED}, NULL}, *pip; - CssShorthandInfo si, *sip; + CssShorthandInfo *sip; CssValueType type = CSS_TYPE_UNUSED; CssPropertyName prop; @@ -1087,7 +1087,6 @@ void CssParser::parseDeclaration(CssPropertyList * props, } } else { /* Try shorthands. */ - si.symbol = tval; sip = (CssShorthandInfo *) bsearch(&pi, Css_shorthand_info, CSS_SHORTHAND_NUM, diff --git a/src/html.cc b/src/html.cc index 264e0041..1bdbd8fb 100644 --- a/src/html.cc +++ b/src/html.cc @@ -1718,7 +1718,6 @@ static void Html_tag_close_style(DilloHtml *html, int TagIdx) static void Html_tag_open_body(DilloHtml *html, const char *tag, int tagsize) { const char *attrbuf; - Textblock *textblock; int32_t color; int tag_index_a = a_Html_tag_index ("a"); style::Color *bgColor; @@ -1736,8 +1735,6 @@ static void Html_tag_open_body(DilloHtml *html, const char *tag, int tagsize) BUG_MSG("unclosed HEAD element\n"); } - textblock = HT2TB(html); - if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) { color = a_Html_color_parse(html, attrbuf, -1); if (color != -1) @@ -2165,7 +2162,6 @@ static void Html_tag_open_img(DilloHtml *html, const char *tag, int tagsize) { DilloImage *Image; DilloUrl *url, *usemap_url; - Textblock *textblock; const char *attrbuf; /* This avoids loading images. Useful for viewing suspicious HTML email. */ @@ -2176,8 +2172,6 @@ static void Html_tag_open_img(DilloHtml *html, const char *tag, int tagsize) !(url = a_Html_url_new(html, attrbuf, NULL, 0))) return; - textblock = HT2TB(html); - usemap_url = NULL; if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "usemap"))) /* TODO: usemap URLs outside of the document are not used. */ @@ -2254,12 +2248,11 @@ static void Html_tag_close_map(DilloHtml *html, int TagIdx) static misc::SimpleVector *Html_read_coords(DilloHtml *html, const char *str) { - int i, coord; + int coord; const char *tail = str; char *newtail = NULL; misc::SimpleVector *coords = new misc::SimpleVector (4); - i = 0; while (1) { coord = strtol(tail, &newtail, 10); if (coord == 0 && newtail == tail) @@ -2959,14 +2952,13 @@ void a_Html_load_stylesheet(DilloHtml *html, DilloUrl *url) if (endq && (endq - data <= 51)) { /* IANA limits charset names to 40 characters */ - const char *ignored; char *content_type; *endq = '\0'; content_type = dStrconcat("text/css; charset=", data+10, NULL); *endq = '"'; a_Capi_unref_buf(url); - ignored = a_Capi_set_content_type(url, content_type, "meta"); + a_Capi_set_content_type(url, content_type, "meta"); dFree(content_type); a_Capi_get_buf(url, &data, &len); } diff --git a/src/nav.c b/src/nav.c index 7f9d03db..f7aa26c9 100644 --- a/src/nav.c +++ b/src/nav.c @@ -195,13 +195,12 @@ static void Nav_open_url(BrowserWindow *bw, const DilloUrl *url, const DilloUrl *requester, int offset) { const DilloUrl *old_url; - bool_t MustLoad, ForceReload, Repush, IgnoreScroll; + bool_t MustLoad, ForceReload, IgnoreScroll; int x, y, idx, ClientKey; DilloWeb *Web; MSG("Nav_open_url: new url='%s'\n", URL_STR_(url)); - Repush = (URL_FLAGS(url) & URL_ReloadFromCache) != 0; ForceReload = (URL_FLAGS(url) & (URL_E2EQuery + URL_ReloadFromCache)) != 0; IgnoreScroll = (URL_FLAGS(url) & URL_IgnoreScroll) != 0; diff --git a/src/table.cc b/src/table.cc index 58cdf22e..d48a0c45 100644 --- a/src/table.cc +++ b/src/table.cc @@ -151,7 +151,6 @@ void Html_tag_open_tr(DilloHtml *html, const char *tag, int tagsize) { const char *attrbuf; int32_t bgcolor = -1; - bool new_style = false; html->styleEngine->inheritNonCssHints (); @@ -183,10 +182,8 @@ void Html_tag_open_tr(DilloHtml *html, const char *tag, int tagsize) if (bgcolor != -1) { html->styleEngine->setNonCssHint(CSS_PROPERTY_BACKGROUND_COLOR, CSS_TYPE_COLOR, bgcolor); - new_style = true; } - if (a_Html_tag_set_valign_attr (html, tag, tagsize)) - new_style = true; + a_Html_tag_set_valign_attr (html, tag, tagsize); break; default: break; @@ -318,7 +315,6 @@ static void Html_tag_open_table_cell(DilloHtml *html, int colspan = 1, rowspan = 1; const char *attrbuf; int32_t bgcolor; - bool_t new_style; html->styleEngine->inheritNonCssHints (); @@ -363,8 +359,7 @@ static void Html_tag_open_table_cell(DilloHtml *html, a_Html_parse_length (html, attrbuf)); } - if (a_Html_tag_set_valign_attr (html, tag, tagsize)) - new_style = TRUE; + a_Html_tag_set_valign_attr (html, tag, tagsize); if ((attrbuf = a_Html_get_attr(html, tag, tagsize, "bgcolor"))) { bgcolor = a_Html_color_parse(html, attrbuf, -1); diff --git a/src/ui.cc b/src/ui.cc index 1731f469..c50282d3 100644 --- a/src/ui.cc +++ b/src/ui.cc @@ -425,7 +425,7 @@ Fl_Button *UI::make_button(const char *label, Fl_Image *img, Fl_Image *deimg, b->image(img); if (deimg) b->deimage(deimg); - b->callback(b1_cb, (void *)b_n); + b->callback(b1_cb, INT2VOIDP(b_n)); b->clear_visible_focus(); b->labelsize(12); b->box(FL_FLAT_BOX); diff --git a/test/dw_anchors_test.cc b/test/dw_anchors_test.cc index e5fcdbf2..10525f1a 100644 --- a/test/dw_anchors_test.cc +++ b/test/dw_anchors_test.cc @@ -112,7 +112,7 @@ int main(int argc, char **argv) buf[0] = toupper (buf[0]); buttonLabel[i] = strdup(buf); Fl_Button *button = new Fl_Button(0, 20 * i, 50, 20, buttonLabel[i]); - button->callback (anchorCallback, (void*)i); + button->callback (anchorCallback, (void*)(long)i); button->when (FL_WHEN_RELEASE); } -- cgit v1.2.3 From 7ef21cbd8de03848230ca6d75f349bd586926aaa Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Wed, 24 Aug 2011 23:13:40 +0200 Subject: add support for CSS adjacent sibling selectors --- src/css.cc | 13 +++++++++++-- src/cssparser.cc | 3 +++ src/doctree.hh | 54 ++++++++++++++++++++++++++++++++++++------------------ 3 files changed, 50 insertions(+), 20 deletions(-) (limited to 'src/cssparser.cc') diff --git a/src/css.cc b/src/css.cc index 8b3e5371..aa799002 100644 --- a/src/css.cc +++ b/src/css.cc @@ -104,6 +104,7 @@ CssSelector::CssSelector () { cs = selectorList->getRef (selectorList->size () - 1); cs->notMatchingBefore = -1; + cs->combinator = CHILD; cs->selector = new CssSimpleSelector (); }; @@ -133,6 +134,7 @@ bool CssSelector::match (Doctree *docTree, const DoctreeNode *node) { switch (comb) { case CHILD: + case ADJACENT_SIBLING: if (!sel->match (node)) return false; break; @@ -148,7 +150,7 @@ bool CssSelector::match (Doctree *docTree, const DoctreeNode *node) { if (sel->match (node)) break; - node = docTree->parent (node); + node = node->parent; } break; default: @@ -156,7 +158,11 @@ bool CssSelector::match (Doctree *docTree, const DoctreeNode *node) { } comb = cs->combinator; - node = docTree->parent (node); + + if (comb == ADJACENT_SIBLING) + node = node->sibling; + else + node = node->parent; } return true; @@ -200,6 +206,9 @@ void CssSelector::print () { case DESCENDANT: fprintf (stderr, "\" \" "); break; + case ADJACENT_SIBLING: + fprintf (stderr, "+ "); + break; default: fprintf (stderr, "? "); break; diff --git a/src/cssparser.cc b/src/cssparser.cc index 3d62b31d..73b4331a 100644 --- a/src/cssparser.cc +++ b/src/cssparser.cc @@ -1289,6 +1289,9 @@ CssSelector *CssParser::parseSelector() } else if (ttype == CSS_TK_CHAR && tval[0] == '>') { selector->addSimpleSelector (CssSelector::CHILD); nextToken(); + } else if (ttype == CSS_TK_CHAR && tval[0] == '+') { + selector->addSimpleSelector (CssSelector::ADJACENT_SIBLING); + nextToken(); } else if (ttype != CSS_TK_END && spaceSeparated) { selector->addSimpleSelector (CssSelector::DESCENDANT); } else { diff --git a/src/doctree.hh b/src/doctree.hh index ef7faa7c..c46a5a10 100644 --- a/src/doctree.hh +++ b/src/doctree.hh @@ -6,6 +6,8 @@ class DoctreeNode { public: DoctreeNode *parent; + DoctreeNode *sibling; + DoctreeNode *lastChild; int num; // unique ascending id int element; lout::misc::SimpleVector *klass; @@ -14,11 +16,27 @@ class DoctreeNode { DoctreeNode () { parent = NULL; + sibling = NULL; + lastChild = NULL; klass = NULL; pseudo = NULL; id = NULL; element = 0; }; + + ~DoctreeNode () { + dFree ((void*) id); + while (lastChild) { + DoctreeNode *n = lastChild; + lastChild = lastChild->sibling; + delete n; + } + if (klass) { + for (int i = 0; i < klass->size (); i++) + dFree (klass->get(i)); + delete klass; + } + } }; /** @@ -26,47 +44,47 @@ class DoctreeNode { * * The Doctree class defines the interface to the parsed HTML document tree * as it is used for CSS selector matching. - * Currently the Doctree can be represented as stack, however to support - * CSS adjacent siblings or for future JavaScript support it may have to - * be extended to a real tree. */ class Doctree { private: DoctreeNode *topNode; + DoctreeNode *rootNode; int num; public: Doctree () { topNode = NULL; + rootNode = NULL; num = 0; }; - ~Doctree () { while (top ()) pop (); }; + + ~Doctree () { + if (rootNode) + delete rootNode; + }; + DoctreeNode *push () { DoctreeNode *dn = new DoctreeNode (); dn->parent = topNode; + if (dn->parent) { + dn->sibling = dn->parent->lastChild; + dn->parent->lastChild = dn; + } dn->num = num++; + if (!rootNode) + rootNode = dn; topNode = dn; return dn; }; + void pop () { - DoctreeNode *dn = topNode; - if (dn) { - dFree ((void*) dn->id); - if (dn->klass) { - for (int i = 0; i < dn->klass->size (); i++) - dFree (dn->klass->get(i)); - delete dn->klass; - } - topNode = dn->parent; - delete dn; - } + if (topNode) + topNode = topNode->parent; }; + inline DoctreeNode *top () { return topNode; }; - inline DoctreeNode *parent (const DoctreeNode *node) { - return node->parent; - }; }; #endif -- cgit v1.2.3