changeset 1739:7188140a1c0a

implement optional deep copy for CssPropertyList
author Johannes Hofmann <Johannes.Hofmann@gmx.de>
date Tue, 12 Oct 2010 09:58:07 +0200
parents 7974b38cc036
children a7af9ba1c073
files src/css.hh src/styleengine.cc
diffstat 2 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/css.hh	Mon Oct 11 23:36:36 2010 +0200
+++ b/src/css.hh	Tue Oct 12 09:58:07 2010 +0200
@@ -304,10 +304,25 @@
          refCount = 0;
          this->ownerOfStrings = ownerOfStrings;
       };
-      inline CssPropertyList(const CssPropertyList &p) :
+      inline CssPropertyList(const CssPropertyList &p, bool deep = false) :
          lout::misc::SimpleVector <CssProperty> (p) {
          refCount = 0;
-         ownerOfStrings = false;
+         if (deep) {
+            for (int i = 0; i < size (); i++) {
+               CssProperty *p = getRef(i);
+               switch (p->type) {
+                  case CSS_TYPE_STRING:
+                  case CSS_TYPE_SYMBOL:
+                     p->value.strVal = dStrdup (p->value.strVal);
+                     break;
+                  default:
+                     break;
+               }
+            }
+            ownerOfStrings = true;
+         } else {
+            ownerOfStrings = false;
+         }
       };
       ~CssPropertyList ();
 
--- a/src/styleengine.cc	Mon Oct 11 23:36:36 2010 +0200
+++ b/src/styleengine.cc	Tue Oct 12 09:58:07 2010 +0200
@@ -153,7 +153,7 @@
    Node *n = stack->getRef (stack->size () - 1);
 
    if (pn->nonCssProperties)
-      n->nonCssProperties = new CssPropertyList (*pn->nonCssProperties);
+      n->nonCssProperties = new CssPropertyList (*pn->nonCssProperties, true);
 }
 
 void StyleEngine::clearNonCssHints () {