Chromium Code Reviews| 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) | |
|
lushnikov
2014/02/28 11:55:59
ensureViaInspectorStyleSheet?
vsevik
2014/02/28 14:35:28
I prefer requestViaInspectorStyleSheet.
| |
| 318 { | |
| 319 var frameId = node.frameId() || WebInspector.resourceTreeModel.mainFrame .id; | |
| 320 var viaInspectorStyleSheetHeader; | |
| 321 for (var styleSheetId in this._styleSheetIdToHeader) { | |
| 322 var styleSheetHeader = this._styleSheetIdToHeader[styleSheetId]; | |
| 323 if (styleSheetHeader.frameId === frameId && styleSheetHeader.isViaIn spector()) { | |
| 324 viaInspectorStyleSheetHeader = styleSheetHeader; | |
|
lushnikov
2014/02/28 11:55:59
we don't need viaInspectorStyleSheetHeader var - l
vsevik
2014/02/28 14:35:28
Done.
| |
| 325 break; | |
| 305 } | 326 } |
| 306 } | 327 } |
| 307 | 328 |
| 308 this._pendingCommandsMajorState.push(true); | 329 if (viaInspectorStyleSheetHeader) { |
| 309 CSSAgent.addRule(nodeId, selector, callback.bind(this)); | 330 callback(viaInspectorStyleSheetHeader); |
| 331 return; | |
| 332 } | |
| 333 | |
| 334 /** | |
| 335 * @this {WebInspector.CSSStyleModel} | |
| 336 * @param {?Protocol.Error} error | |
| 337 * @param {!CSSAgent.StyleSheetId} styleSheetId | |
| 338 */ | |
| 339 function innerCallback(error, styleSheetId) | |
| 340 { | |
| 341 if (error) { | |
| 342 console.error(error); | |
| 343 callback(null); | |
| 344 } | |
| 345 | |
| 346 callback(this._styleSheetIdToHeader[styleSheetId]); | |
| 347 } | |
| 348 | |
| 349 CSSAgent.createViaInspectorStyleSheet(frameId, innerCallback.bind(this)) ; | |
| 310 }, | 350 }, |
| 311 | 351 |
| 312 mediaQueryResultChanged: function() | 352 mediaQueryResultChanged: function() |
| 313 { | 353 { |
| 314 this._styleLoader.reset(); | 354 this._styleLoader.reset(); |
| 315 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.MediaQue ryResultChanged); | 355 this.dispatchEventToListeners(WebInspector.CSSStyleModel.Events.MediaQue ryResultChanged); |
| 316 }, | 356 }, |
| 317 | 357 |
| 318 /** | 358 /** |
| 319 * @param {!CSSAgent.StyleSheetId} id | 359 * @param {!CSSAgent.StyleSheetId} id |
| (...skipping 938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1258 /** @type {!Array.<!WebInspector.SourceMapping>} */ | 1298 /** @type {!Array.<!WebInspector.SourceMapping>} */ |
| 1259 this._sourceMappings = []; | 1299 this._sourceMappings = []; |
| 1260 } | 1300 } |
| 1261 | 1301 |
| 1262 WebInspector.CSSStyleSheetHeader.prototype = { | 1302 WebInspector.CSSStyleSheetHeader.prototype = { |
| 1263 /** | 1303 /** |
| 1264 * @return {string} | 1304 * @return {string} |
| 1265 */ | 1305 */ |
| 1266 resourceURL: function() | 1306 resourceURL: function() |
| 1267 { | 1307 { |
| 1268 return this.origin === "inspector" ? this._viaInspectorResourceURL() : t his.sourceURL; | 1308 return this.isViaInspector() ? this._viaInspectorResourceURL() : this.so urceURL; |
| 1269 }, | 1309 }, |
| 1270 | 1310 |
| 1271 /** | 1311 /** |
| 1272 * @param {!WebInspector.CSSStyleModel.LiveLocation} location | 1312 * @param {!WebInspector.CSSStyleModel.LiveLocation} location |
| 1273 */ | 1313 */ |
| 1274 addLiveLocation: function(location) | 1314 addLiveLocation: function(location) |
| 1275 { | 1315 { |
| 1276 this._locations.add(location); | 1316 this._locations.add(location); |
| 1277 location.update(); | 1317 location.update(); |
| 1278 }, | 1318 }, |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1418 * @param {string} newText | 1458 * @param {string} newText |
| 1419 * @param {function(?Protocol.Error)} callback | 1459 * @param {function(?Protocol.Error)} callback |
| 1420 */ | 1460 */ |
| 1421 setContent: function(newText, callback) | 1461 setContent: function(newText, callback) |
| 1422 { | 1462 { |
| 1423 newText = this._trimSourceURL(newText); | 1463 newText = this._trimSourceURL(newText); |
| 1424 if (this.hasSourceURL) | 1464 if (this.hasSourceURL) |
| 1425 newText += "\n/*# sourceURL=" + this.sourceURL + " */"; | 1465 newText += "\n/*# sourceURL=" + this.sourceURL + " */"; |
| 1426 CSSAgent.setStyleSheetText(this.id, newText, callback); | 1466 CSSAgent.setStyleSheetText(this.id, newText, callback); |
| 1427 }, | 1467 }, |
| 1468 | |
| 1469 /** | |
| 1470 * @return {boolean} | |
| 1471 */ | |
| 1472 isViaInspector: function() | |
| 1473 { | |
| 1474 return this.origin === "inspector"; | |
| 1475 }, | |
| 1476 | |
| 1428 } | 1477 } |
| 1429 | 1478 |
| 1430 /** | 1479 /** |
| 1431 * @constructor | 1480 * @constructor |
| 1432 * @implements {CSSAgent.Dispatcher} | 1481 * @implements {CSSAgent.Dispatcher} |
| 1433 * @param {!WebInspector.CSSStyleModel} cssModel | 1482 * @param {!WebInspector.CSSStyleModel} cssModel |
| 1434 */ | 1483 */ |
| 1435 WebInspector.CSSDispatcher = function(cssModel) | 1484 WebInspector.CSSDispatcher = function(cssModel) |
| 1436 { | 1485 { |
| 1437 this._cssModel = cssModel; | 1486 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) | 1573 for (var i = 0; i < callbacks.length; ++i) |
| 1525 callbacks[i](computedStyle); | 1574 callbacks[i](computedStyle); |
| 1526 } | 1575 } |
| 1527 } | 1576 } |
| 1528 } | 1577 } |
| 1529 | 1578 |
| 1530 /** | 1579 /** |
| 1531 * @type {!WebInspector.CSSStyleModel} | 1580 * @type {!WebInspector.CSSStyleModel} |
| 1532 */ | 1581 */ |
| 1533 WebInspector.cssModel; | 1582 WebInspector.cssModel; |
| OLD | NEW |