OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 userCallback(null); | 115 userCallback(null); |
116 else | 116 else |
117 userCallback(WebInspector.CSSStyleDeclaration.parsePayload(style
Payload)); | 117 userCallback(WebInspector.CSSStyleDeclaration.parsePayload(style
Payload)); |
118 } | 118 } |
119 | 119 |
120 CSSAgent.getInlineStyleForNode(nodeId, callback.bind(null, userCallback)
); | 120 CSSAgent.getInlineStyleForNode(nodeId, callback.bind(null, userCallback)
); |
121 }, | 121 }, |
122 | 122 |
123 setRuleSelector: function(ruleId, nodeId, newSelector, successCallback, fail
ureCallback) | 123 setRuleSelector: function(ruleId, nodeId, newSelector, successCallback, fail
ureCallback) |
124 { | 124 { |
125 function checkAffectsCallback(nodeId, successCallback, rulePayload, erro
r, selectedNodeIds) | 125 function checkAffectsCallback(nodeId, successCallback, rulePayload, sele
ctedNodeIds) |
126 { | 126 { |
127 if (error) | 127 if (!selectedNodeIds) |
128 return; | 128 return; |
129 var doesAffectSelectedNode = (selectedNodeIds.indexOf(nodeId) >= 0); | 129 var doesAffectSelectedNode = (selectedNodeIds.indexOf(nodeId) >= 0); |
130 var rule = WebInspector.CSSRule.parsePayload(rulePayload); | 130 var rule = WebInspector.CSSRule.parsePayload(rulePayload); |
131 successCallback(rule, doesAffectSelectedNode); | 131 successCallback(rule, doesAffectSelectedNode); |
132 this._fireStyleSheetChanged(rule.id.styleSheetId, true); | 132 this._fireStyleSheetChanged(rule.id.styleSheetId, true); |
133 } | 133 } |
134 | 134 |
135 function callback(nodeId, successCallback, failureCallback, error, newSe
lector, rulePayload) | 135 function callback(nodeId, successCallback, failureCallback, error, newSe
lector, rulePayload) |
136 { | 136 { |
137 // FIXME: looks like rulePayload is always null. | 137 // FIXME: looks like rulePayload is always null. |
138 if (error) | 138 if (error) |
139 failureCallback(); | 139 failureCallback(); |
140 else | 140 else { |
141 WebInspector.domAgent.querySelectorAll(nodeId, newSelector, chec
kAffectsCallback.bind(this, nodeId, successCallback, rulePayload)); | 141 var documentElementId = this._documentElementId(nodeId); |
| 142 if (documentElementId) |
| 143 WebInspector.domAgent.querySelectorAll(documentElementId, ne
wSelector, checkAffectsCallback.bind(this, nodeId, successCallback, rulePayload)
); |
| 144 else |
| 145 failureCallback(); |
| 146 } |
142 } | 147 } |
143 | 148 |
144 CSSAgent.setRuleSelector(ruleId, newSelector, callback.bind(this, nodeId
, successCallback, failureCallback, newSelector)); | 149 CSSAgent.setRuleSelector(ruleId, newSelector, callback.bind(this, nodeId
, successCallback, failureCallback, newSelector)); |
145 }, | 150 }, |
146 | 151 |
147 addRule: function(nodeId, selector, successCallback, failureCallback) | 152 addRule: function(nodeId, selector, successCallback, failureCallback) |
148 { | 153 { |
149 function checkAffectsCallback(nodeId, successCallback, rulePayload, erro
r, selectedNodeIds) | 154 function checkAffectsCallback(nodeId, successCallback, rulePayload, sele
ctedNodeIds) |
150 { | 155 { |
| 156 if (!selectedNodeIds) |
| 157 return; |
151 var doesAffectSelectedNode = (selectedNodeIds.indexOf(nodeId) >= 0); | 158 var doesAffectSelectedNode = (selectedNodeIds.indexOf(nodeId) >= 0); |
152 var rule = WebInspector.CSSRule.parsePayload(rulePayload); | 159 var rule = WebInspector.CSSRule.parsePayload(rulePayload); |
153 successCallback(rule, doesAffectSelectedNode); | 160 successCallback(rule, doesAffectSelectedNode); |
154 this._fireStyleSheetChanged(rule.id.styleSheetId, true); | 161 this._fireStyleSheetChanged(rule.id.styleSheetId, true); |
155 } | 162 } |
156 | 163 |
157 function callback(successCallback, failureCallback, selector, error, rul
ePayload) | 164 function callback(successCallback, failureCallback, selector, error, rul
ePayload) |
158 { | 165 { |
159 if (error) { | 166 if (error) { |
160 // Invalid syntax for a selector | 167 // Invalid syntax for a selector |
161 failureCallback(); | 168 failureCallback(); |
162 } else | 169 } else { |
163 WebInspector.domAgent.querySelectorAll(nodeId, selector, checkAf
fectsCallback.bind(this, nodeId, successCallback, rulePayload)); | 170 var documentElementId = this._documentElementId(nodeId); |
| 171 if (documentElementId) |
| 172 WebInspector.domAgent.querySelectorAll(documentElementId, se
lector, checkAffectsCallback.bind(this, nodeId, successCallback, rulePayload)); |
| 173 else |
| 174 failureCallback(); |
| 175 } |
164 } | 176 } |
165 | 177 |
166 CSSAgent.addRule(nodeId, selector, callback.bind(this, successCallback,
failureCallback, selector)); | 178 CSSAgent.addRule(nodeId, selector, callback.bind(this, successCallback,
failureCallback, selector)); |
167 }, | 179 }, |
168 | 180 |
| 181 _documentElementId: function(nodeId) |
| 182 { |
| 183 var node = WebInspector.domAgent.nodeForId(nodeId); |
| 184 if (!node) |
| 185 return null; |
| 186 return node.ownerDocumentElement().id; |
| 187 }, |
| 188 |
169 _fireStyleSheetChanged: function(styleSheetId, majorChange, callback) | 189 _fireStyleSheetChanged: function(styleSheetId, majorChange, callback) |
170 { | 190 { |
171 callback = callback || function() {}; | 191 callback = callback || function() {}; |
172 | 192 |
173 if (!majorChange || !styleSheetId || !this.hasEventListeners(WebInspecto
r.CSSStyleModel.Events.StyleSheetChanged)) { | 193 if (!majorChange || !styleSheetId || !this.hasEventListeners(WebInspecto
r.CSSStyleModel.Events.StyleSheetChanged)) { |
174 callback(); | 194 callback(); |
175 return; | 195 return; |
176 } | 196 } |
177 | 197 |
178 function mycallback(error, content) | 198 function mycallback(error, content) |
(...skipping 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
686 | 706 |
687 if (!this._styleSheetIdToURL[styleSheetId]) { | 707 if (!this._styleSheetIdToURL[styleSheetId]) { |
688 this._loadStyleSheetHeaders(setContent.bind(this)); | 708 this._loadStyleSheetHeaders(setContent.bind(this)); |
689 return; | 709 return; |
690 } | 710 } |
691 setContent.call(this); | 711 setContent.call(this); |
692 } | 712 } |
693 } | 713 } |
694 | 714 |
695 WebInspector.CSSStyleModelResourceBinding.prototype.__proto__ = WebInspector.Res
ourceDomainModelBinding.prototype; | 715 WebInspector.CSSStyleModelResourceBinding.prototype.__proto__ = WebInspector.Res
ourceDomainModelBinding.prototype; |
OLD | NEW |