| 1514 | } |
| 1515 | |
| 1516 | void CssParser::parseRuleset() |
| 1517 | { |
| 1518 | lout::misc::SimpleVector < CssSelector * >*list; |
| 1519 | CssPropertyList *props, *importantProps; |
| 1520 | CssSelector *selector; |
| 1521 | |
| 1522 | list = new lout::misc::SimpleVector < CssSelector * >(1); |
| 1523 | |
| 1524 | while (true) { |
| 1525 | selector = parseSelector(); |
| 1526 | |
| 1527 | if (selector) { |
| 1528 | selector->ref(); |
| 1529 | list->increase(); |
| 1530 | list->set(list->size() - 1, selector); |
| 1531 | } |
| 1532 | |
| 1533 | // \todo dump whole ruleset in case of parse error as required by CSS 2.1 |
| 1534 | // however make sure we don't dump it if only dillo fails to parse |
| 1535 | // valid CSS. |
| 1536 | |
| 1537 | if (ttype == CSS_TK_CHAR && tval[0] == ',') |
| 1538 | /* To read the next token. */ |
| 1539 | nextToken(); |
| 1540 | else |
| 1541 | /* No more selectors. */ |
| 1542 | break; |
| 1543 | } |
| 1544 | |
| 1545 | DEBUG_MSG(DEBUG_PARSE_LEVEL, "end of %s\n", "selectors"); |
| 1546 | |
| 1547 | props = new CssPropertyList(true); |
| 1548 | props->ref(); |
| 1549 | importantProps = new CssPropertyList(true); |
| 1550 | importantProps->ref(); |
| 1551 | |
| 1552 | /* Read block. ('{' has already been read.) */ |
| 1553 | if (ttype != CSS_TK_END) { |
| 1554 | withinBlock = true; |
| 1555 | nextToken(); |
| 1556 | do |
| 1557 | parseDeclaration(props, importantProps); |
| 1558 | while (!(ttype == CSS_TK_END || |
| 1559 | (ttype == CSS_TK_CHAR && tval[0] == '}'))); |
| 1560 | withinBlock = false; |
| 1561 | } |
| 1562 | |
| 1563 | for (int i = 0; i < list->size(); i++) { |
| 1564 | CssSelector *s = list->get(i); |
| 1565 | |
| 1566 | if (origin == CSS_ORIGIN_USER_AGENT) { |
| 1567 | context->addRule(s, props, CSS_PRIMARY_USER_AGENT); |
| 1568 | } else if (origin == CSS_ORIGIN_USER) { |
| 1569 | context->addRule(s, props, CSS_PRIMARY_USER); |
| 1570 | context->addRule(s, importantProps, CSS_PRIMARY_USER_IMPORTANT); |
| 1571 | } else if (origin == CSS_ORIGIN_AUTHOR) { |
| 1572 | context->addRule(s, props, CSS_PRIMARY_AUTHOR); |
| 1573 | context->addRule(s, importantProps, CSS_PRIMARY_AUTHOR_IMPORTANT); |