aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/css.cc16
-rw-r--r--src/css.hh1
2 files changed, 13 insertions, 4 deletions
diff --git a/src/css.cc b/src/css.cc
index 6fe0e8fb..abc08231 100644
--- a/src/css.cc
+++ b/src/css.cc
@@ -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,
diff --git a/src/css.hh b/src/css.hh
index b299adab..805f2c5c 100644
--- a/src/css.hh
+++ b/src/css.hh
@@ -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; };
};