diff options
author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2009-01-30 21:03:14 +0100 |
---|---|---|
committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2009-01-30 21:03:14 +0100 |
commit | 728e69c56a0fd440af3ae0e2c3d18ab263ad248a (patch) | |
tree | fac5b50f2db77e6b218c3846e088a7305bf03a8c | |
parent | 05581a769d934cf6231cd112c917ddde949354b4 (diff) |
insert rules in correct order
-rw-r--r-- | src/css.cc | 16 | ||||
-rw-r--r-- | src/css.hh | 1 |
2 files changed, 13 insertions, 4 deletions
@@ -237,6 +237,16 @@ void CssRule::print () { props->print (); } +void CssStyleSheet::RuleList::insert (CssRule *rule) { + increase (); + int i = size () - 1; + + while (i > 0 && rule->specificity () < get (i - 1)->specificity ()) + *getRef (i) = get (i - 1); + + *getRef (i) = rule; +} + CssStyleSheet::CssStyleSheet () { for (int i = 0; i < ntags; i++) elementTable[i] = new RuleList (); @@ -283,10 +293,8 @@ void CssStyleSheet::addRule (CssRule *rule) { ruleList = anyTable; } - if (ruleList) { - ruleList->increase (); - *ruleList->getRef (ruleList->size() - 1) = rule; - } + if (ruleList) + ruleList->insert (rule); } void CssStyleSheet::apply (CssPropertyList *props, @@ -300,6 +300,7 @@ class CssStyleSheet { delete get (i); }; + void insert (CssRule *rule); inline bool equals (lout::object::Object *other) { return this == other; }; inline int hashValue () { return (intptr_t) this; }; }; |