Web Inspector: Support smart-pasting in the Rules sidebar panel
[WebKit-https.git] / Source / WebInspectorUI / UserInterface / Models / DOMNodeStyles.js
index 45f722f..ed5b9ff 100644 (file)
@@ -322,6 +322,52 @@ WebInspector.DOMNodeStyles = class DOMNodeStyles extends WebInspector.Object
         this._markAsNeedsRefresh();
     }
 
+    changeRule(rule, selector, text)
+    {
+        if (!rule)
+            return;
+
+        selector = selector || "";
+
+        function changeCompleted()
+        {
+            DOMAgent.markUndoableState();
+            this.refresh();
+        }
+
+        function styleChanged(error, stylePayload)
+        {
+            if (error)
+                return;
+
+            changeCompleted.call(this);
+        }
+
+        function changeText(styleId)
+        {
+            // COMPATIBILITY (iOS 6): CSSAgent.setStyleText was not available in iOS 6.
+            if (!text || !text.length || !CSSAgent.setStyleText) {
+                changeCompleted.call(this);
+                return;
+            }
+
+            CSSAgent.setStyleText(styleId, text, styleChanged.bind(this));
+        }
+
+        function ruleSelectorChanged(error, rulePayload)
+        {
+            if (error)
+                return;
+
+            changeText.call(this, rulePayload.style.styleId);
+        }
+
+        this._needsRefresh = true;
+        this._ignoreNextContentDidChangeForStyleSheet = rule.ownerStyleSheet;
+
+        CSSAgent.setRuleSelector(rule.id, selector, ruleSelectorChanged.bind(this));
+    }
+
     changeRuleSelector(rule, selector)
     {
         selector = selector || "";