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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 function selectorQueried(index, nodeId, matchingSelectors, matchingNodeI
ds) | 274 function selectorQueried(index, nodeId, matchingSelectors, matchingNodeI
ds) |
275 { | 275 { |
276 if (!matchingNodeIds) | 276 if (!matchingNodeIds) |
277 return; | 277 return; |
278 if (matchingNodeIds.indexOf(nodeId) !== -1) | 278 if (matchingNodeIds.indexOf(nodeId) !== -1) |
279 matchingSelectors.push(index); | 279 matchingSelectors.push(index); |
280 } | 280 } |
281 }, | 281 }, |
282 | 282 |
283 /** | 283 /** |
284 * @param {!DOMAgent.NodeId} nodeId | 284 * @param {!CSSAgent.StyleSheetId} styleSheetId |
| 285 * @param {!WebInspector.DOMNode} node |
285 * @param {string} selector | 286 * @param {string} selector |
286 * @param {function(!WebInspector.CSSRule)} successCallback | 287 * @param {function(!WebInspector.CSSRule)} successCallback |
287 * @param {function()} failureCallback | 288 * @param {function()} failureCallback |
288 */ | 289 */ |
289 addRule: function(nodeId, selector, successCallback, failureCallback) | 290 addRule: function(styleSheetId, node, selector, successCallback, failureCall
back) |
290 { | 291 { |
| 292 this._pendingCommandsMajorState.push(true); |
| 293 CSSAgent.addRule(styleSheetId, selector, callback.bind(this)); |
| 294 |
291 /** | 295 /** |
292 * @param {?Protocol.Error} error | 296 * @param {?Protocol.Error} error |
293 * @param {!CSSAgent.CSSRule} rulePayload | 297 * @param {!CSSAgent.CSSRule} rulePayload |
294 * @this {WebInspector.CSSStyleModel} | 298 * @this {WebInspector.CSSStyleModel} |
295 */ | 299 */ |
296 function callback(error, rulePayload) | 300 function callback(error, rulePayload) |
297 { | 301 { |
298 this._pendingCommandsMajorState.pop(); | 302 this._pendingCommandsMajorState.pop(); |
299 if (error) { | 303 if (error) { |
300 // Invalid syntax for a selector | 304 // Invalid syntax for a selector |
301 failureCallback(); | 305 failureCallback(); |
302 } else { | 306 } else { |
303 WebInspector.domAgent.markUndoableState(); | 307 WebInspector.domAgent.markUndoableState(); |
304 this._computeMatchingSelectors(rulePayload, nodeId, successCallb
ack, failureCallback); | 308 this._computeMatchingSelectors(rulePayload, node.id, successCall
back, failureCallback); |
| 309 } |
| 310 } |
| 311 }, |
| 312 |
| 313 /** |
| 314 * @param {!WebInspector.DOMNode} node |
| 315 * @param {function(?WebInspector.CSSStyleSheetHeader)} callback |
| 316 */ |
| 317 requestViaInspectorStylesheet: function(node, callback) |
| 318 { |
| 319 var frameId = node.frameId() || WebInspector.resourceTreeModel.mainFrame
.id; |
| 320 for (var styleSheetId in this._styleSheetIdToHeader) { |
| 321 var styleSheetHeader = this._styleSheetIdToHeader[styleSheetId]; |
| 322 if (styleSheetHeader.frameId === frameId && styleSheetHeader.isViaIn
spector()) { |
| 323 callback(styleSheetHeader); |
| 324 return; |
305 } | 325 } |
306 } | 326 } |
307 | 327 |
308 this._pendingCommandsMajorState.push(true); | 328 /** |
309 CSSAgent.addRule(nodeId, selector, callback.bind(this)); | 329 * @this {WebInspector.CSSStyleModel} |
| 330 * @param {?Protocol.Error} error |
| 331 * @param {!CSSAgent.StyleSheetId} styleSheetId |
| 332 */ |
| 333 function innerCallback(error, styleSheetId) |
| 334 { |
| 335 if (error) { |
| 336 console.error(error); |
| 337 callback(null); |
| 338 } |
| 339 |
| 340 callback(this._styleSheetIdToHeader[styleSheetId]); |
| 341 } |
| 342 |
| 343 CSSAgent.createStyleSheet(frameId, innerCallback.bind(this)); |
310 }, | 344 }, |
311 | 345 |
312 mediaQueryResultChanged: function() | 346 mediaQueryResultChanged: function() |
313 { | 347 { |
314 this._styleLoader.reset(); | 348 this._styleLoader.reset(); |
315 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.MediaQue
ryResultChanged); | 349 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.MediaQue
ryResultChanged); |
316 }, | 350 }, |
317 | 351 |
318 /** | 352 /** |
319 * @param {!CSSAgent.StyleSheetId} id | 353 * @param {!CSSAgent.StyleSheetId} id |
(...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1258 /** @type {!Array.<!WebInspector.SourceMapping>} */ | 1292 /** @type {!Array.<!WebInspector.SourceMapping>} */ |
1259 this._sourceMappings = []; | 1293 this._sourceMappings = []; |
1260 } | 1294 } |
1261 | 1295 |
1262 WebInspector.CSSStyleSheetHeader.prototype = { | 1296 WebInspector.CSSStyleSheetHeader.prototype = { |
1263 /** | 1297 /** |
1264 * @return {string} | 1298 * @return {string} |
1265 */ | 1299 */ |
1266 resourceURL: function() | 1300 resourceURL: function() |
1267 { | 1301 { |
1268 return this.origin === "inspector" ? this._viaInspectorResourceURL() : t
his.sourceURL; | 1302 return this.isViaInspector() ? this._viaInspectorResourceURL() : this.so
urceURL; |
1269 }, | 1303 }, |
1270 | 1304 |
1271 /** | 1305 /** |
1272 * @param {!WebInspector.CSSStyleModel.LiveLocation} location | 1306 * @param {!WebInspector.CSSStyleModel.LiveLocation} location |
1273 */ | 1307 */ |
1274 addLiveLocation: function(location) | 1308 addLiveLocation: function(location) |
1275 { | 1309 { |
1276 this._locations.add(location); | 1310 this._locations.add(location); |
1277 location.update(); | 1311 location.update(); |
1278 }, | 1312 }, |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1418 * @param {string} newText | 1452 * @param {string} newText |
1419 * @param {function(?Protocol.Error)} callback | 1453 * @param {function(?Protocol.Error)} callback |
1420 */ | 1454 */ |
1421 setContent: function(newText, callback) | 1455 setContent: function(newText, callback) |
1422 { | 1456 { |
1423 newText = this._trimSourceURL(newText); | 1457 newText = this._trimSourceURL(newText); |
1424 if (this.hasSourceURL) | 1458 if (this.hasSourceURL) |
1425 newText += "\n/*# sourceURL=" + this.sourceURL + " */"; | 1459 newText += "\n/*# sourceURL=" + this.sourceURL + " */"; |
1426 CSSAgent.setStyleSheetText(this.id, newText, callback); | 1460 CSSAgent.setStyleSheetText(this.id, newText, callback); |
1427 }, | 1461 }, |
| 1462 |
| 1463 /** |
| 1464 * @return {boolean} |
| 1465 */ |
| 1466 isViaInspector: function() |
| 1467 { |
| 1468 return this.origin === "inspector"; |
| 1469 }, |
| 1470 |
1428 } | 1471 } |
1429 | 1472 |
1430 /** | 1473 /** |
1431 * @constructor | 1474 * @constructor |
1432 * @implements {CSSAgent.Dispatcher} | 1475 * @implements {CSSAgent.Dispatcher} |
1433 * @param {!WebInspector.CSSStyleModel} cssModel | 1476 * @param {!WebInspector.CSSStyleModel} cssModel |
1434 */ | 1477 */ |
1435 WebInspector.CSSDispatcher = function(cssModel) | 1478 WebInspector.CSSDispatcher = function(cssModel) |
1436 { | 1479 { |
1437 this._cssModel = cssModel; | 1480 this._cssModel = cssModel; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1524 for (var i = 0; i < callbacks.length; ++i) | 1567 for (var i = 0; i < callbacks.length; ++i) |
1525 callbacks[i](computedStyle); | 1568 callbacks[i](computedStyle); |
1526 } | 1569 } |
1527 } | 1570 } |
1528 } | 1571 } |
1529 | 1572 |
1530 /** | 1573 /** |
1531 * @type {!WebInspector.CSSStyleModel} | 1574 * @type {!WebInspector.CSSStyleModel} |
1532 */ | 1575 */ |
1533 WebInspector.cssModel; | 1576 WebInspector.cssModel; |
OLD | NEW |