Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: Source/devtools/front_end/sdk/CSSStyleModel.js

Issue 404763002: DevTools: Inject styleSheetId in WebInspector.CSSLocation constructor (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Address comments Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 }, 725 },
726 726
727 __proto__: WebInspector.LiveLocation.prototype 727 __proto__: WebInspector.LiveLocation.prototype
728 } 728 }
729 729
730 /** 730 /**
731 * @constructor 731 * @constructor
732 * @implements {WebInspector.RawLocation} 732 * @implements {WebInspector.RawLocation}
733 * @extends {WebInspector.SDKObject} 733 * @extends {WebInspector.SDKObject}
734 * @param {!WebInspector.Target} target 734 * @param {!WebInspector.Target} target
735 * @param {?CSSAgent.StyleSheetId} styleSheetId
735 * @param {string} url 736 * @param {string} url
736 * @param {number} lineNumber 737 * @param {number} lineNumber
737 * @param {number=} columnNumber 738 * @param {number=} columnNumber
738 */ 739 */
739 WebInspector.CSSLocation = function(target, url, lineNumber, columnNumber) 740 WebInspector.CSSLocation = function(target, styleSheetId, url, lineNumber, colum nNumber)
740 { 741 {
741 WebInspector.SDKObject.call(this, target); 742 WebInspector.SDKObject.call(this, target);
742 this._cssModel = target.cssModel; 743 this._cssModel = target.cssModel;
744 this._styleSheetId = styleSheetId;
743 this.url = url; 745 this.url = url;
744 this.lineNumber = lineNumber; 746 this.lineNumber = lineNumber;
745 this.columnNumber = columnNumber || 0; 747 this.columnNumber = columnNumber || 0;
746 } 748 }
747 749
748 WebInspector.CSSLocation.prototype = { 750 WebInspector.CSSLocation.prototype = {
749 /** 751 /**
750 * @param {?CSSAgent.StyleSheetId} styleSheetId
751 * @param {function(!WebInspector.UILocation):(boolean|undefined)} updateDel egate 752 * @param {function(!WebInspector.UILocation):(boolean|undefined)} updateDel egate
752 * @return {?WebInspector.LiveLocation} 753 * @return {?WebInspector.LiveLocation}
753 */ 754 */
754 createLiveLocation: function(styleSheetId, updateDelegate) 755 createLiveLocation: function(updateDelegate)
755 { 756 {
756 var header = styleSheetId ? this._cssModel.styleSheetHeaderForId(styleSh eetId) : null; 757 var header = this._styleSheetId ? this._cssModel.styleSheetHeaderForId(t his._styleSheetId) : null;
757 return new WebInspector.CSSStyleModel.LiveLocation(this._cssModel, heade r, this, updateDelegate); 758 return new WebInspector.CSSStyleModel.LiveLocation(this._cssModel, heade r, this, updateDelegate);
758 }, 759 },
759 760
760 /** 761 /**
761 * @return {?WebInspector.UILocation} 762 * @return {?WebInspector.UILocation}
762 */ 763 */
763 toUILocation: function() 764 toUILocation: function()
764 { 765 {
765 return this._cssModel.rawLocationToUILocation(this); 766 return this._cssModel.rawLocationToUILocation(this);
766 }, 767 },
(...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 1103
1103 _setRawLocationAndFrameId: function() 1104 _setRawLocationAndFrameId: function()
1104 { 1105 {
1105 if (!this.styleSheetId) 1106 if (!this.styleSheetId)
1106 return; 1107 return;
1107 var styleSheetHeader = this._cssModel.styleSheetHeaderForId(this.styleSh eetId); 1108 var styleSheetHeader = this._cssModel.styleSheetHeaderForId(this.styleSh eetId);
1108 this.frameId = styleSheetHeader.frameId; 1109 this.frameId = styleSheetHeader.frameId;
1109 var url = styleSheetHeader.resourceURL(); 1110 var url = styleSheetHeader.resourceURL();
1110 if (!url) 1111 if (!url)
1111 return; 1112 return;
1112 this.rawLocation = new WebInspector.CSSLocation(this._cssModel.target(), url, this.lineNumberInSource(0), this.columnNumberInSource(0)); 1113 this.rawLocation = new WebInspector.CSSLocation(this._cssModel.target(), this.styleSheetId, url, this.lineNumberInSource(0), this.columnNumberInSource(0 ));
1113 }, 1114 },
1114 1115
1115 /** 1116 /**
1116 * @return {string} 1117 * @return {string}
1117 */ 1118 */
1118 resourceURL: function() 1119 resourceURL: function()
1119 { 1120 {
1120 if (!this.styleSheetId) 1121 if (!this.styleSheetId)
1121 return ""; 1122 return "";
1122 var styleSheetHeader = this._cssModel.styleSheetHeaderForId(this.styleSh eetId); 1123 var styleSheetHeader = this._cssModel.styleSheetHeaderForId(this.styleSh eetId);
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 else 1355 else
1355 this.setText(this.text.substring(2, this.text.length - 2).trim(), tr ue, true, userCallback); 1356 this.setText(this.text.substring(2, this.text.length - 2).trim(), tr ue, true, userCallback);
1356 }, 1357 },
1357 1358
1358 /** 1359 /**
1359 * @param {boolean} forName 1360 * @param {boolean} forName
1360 * @return {?WebInspector.UILocation} 1361 * @return {?WebInspector.UILocation}
1361 */ 1362 */
1362 uiLocation: function(forName) 1363 uiLocation: function(forName)
1363 { 1364 {
1364 if (!this.range || !this.ownerStyle || !this.ownerStyle.parentRule) 1365 if (!this.range || !this.ownerStyle || !this.ownerStyle.parentRule || !t his.ownerStyle.styleSheetId)
1365 return null; 1366 return null;
1366 1367
1367 var url = this.ownerStyle.parentRule.resourceURL(); 1368 var url = this.ownerStyle.parentRule.resourceURL();
1368 if (!url) 1369 if (!url)
1369 return null; 1370 return null;
1370 1371
1371 var range = this.range; 1372 var range = this.range;
1372 var line = forName ? range.startLine : range.endLine; 1373 var line = forName ? range.startLine : range.endLine;
1373 // End of range is exclusive, so subtract 1 from the end offset. 1374 // End of range is exclusive, so subtract 1 from the end offset.
1374 var column = forName ? range.startColumn : range.endColumn - (this.text && this.text.endsWith(";") ? 2 : 1); 1375 var column = forName ? range.startColumn : range.endColumn - (this.text && this.text.endsWith(";") ? 2 : 1);
1375 var rawLocation = new WebInspector.CSSLocation(this.ownerStyle._cssModel .target(), url, line, column); 1376 var rawLocation = new WebInspector.CSSLocation(this.ownerStyle._cssModel .target(), this.ownerStyle.styleSheetId, url, line, column);
1376 return rawLocation.toUILocation(); 1377 return rawLocation.toUILocation();
1377 } 1378 }
1378 } 1379 }
1379 1380
1380 /** 1381 /**
1381 * @constructor 1382 * @constructor
1382 * @param {!CSSAgent.MediaQueryExpression} payload 1383 * @param {!CSSAgent.MediaQueryExpression} payload
1383 */ 1384 */
1384 WebInspector.CSSMediaQueryExpression = function(payload) 1385 WebInspector.CSSMediaQueryExpression = function(payload)
1385 { 1386 {
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
1530 1531
1531 /** 1532 /**
1532 * @return {?WebInspector.CSSStyleSheetHeader} 1533 * @return {?WebInspector.CSSStyleSheetHeader}
1533 */ 1534 */
1534 header: function() 1535 header: function()
1535 { 1536 {
1536 return this.parentStyleSheetId ? this._cssModel.styleSheetHeaderForId(th is.parentStyleSheetId) : null; 1537 return this.parentStyleSheetId ? this._cssModel.styleSheetHeaderForId(th is.parentStyleSheetId) : null;
1537 }, 1538 },
1538 1539
1539 /** 1540 /**
1541 * @return {?WebInspector.CSSLocation}
1542 */
1543 rawLocation: function()
1544 {
1545 if (!this.header() || typeof this.lineNumberInSource() === "undefined")
1546 return null;
1547
1548 var lineNumber = Number(this.lineNumberInSource());
1549 return new WebInspector.CSSLocation(this._cssModel.target(), this.header ().id, this.sourceURL, lineNumber, this.columnNumberInSource());
1550 },
1551
1552 /**
1540 * @return {?WebInspector.UILocation} 1553 * @return {?WebInspector.UILocation}
1541 */ 1554 */
1542 uiLocation: function() 1555 uiLocation: function()
1543 { 1556 {
1544 var styleSheetHeader = this.header(); 1557 var styleSheetHeader = this.header();
1545 var lineNumber = this.lineNumberInSource(); 1558 var lineNumber = this.lineNumberInSource();
1546 var columnNumber = this.columnNumberInSource(); 1559 var columnNumber = this.columnNumberInSource();
1547 if (!styleSheetHeader || typeof lineNumber !== "number") 1560 if (typeof lineNumber !== "number")
1548 return null; 1561 return null;
1549 return styleSheetHeader.rawLocationToUILocation(/** @type {number} */(li neNumber), columnNumber); 1562 if (styleSheetHeader)
1563 return styleSheetHeader.rawLocationToUILocation(lineNumber, columnNu mber);
1564 var uiSourceCode = WebInspector.workspace.uiSourceCodeForURL(this.source URL);
1565 if (!uiSourceCode)
1566 return null;
1567 return uiSourceCode.uiLocation(lineNumber, columnNumber);
1550 } 1568 }
1551 } 1569 }
1552 1570
1553 /** 1571 /**
1554 * @constructor 1572 * @constructor
1555 * @implements {WebInspector.ContentProvider} 1573 * @implements {WebInspector.ContentProvider}
1556 * @param {!WebInspector.CSSStyleModel} cssModel 1574 * @param {!WebInspector.CSSStyleModel} cssModel
1557 * @param {!CSSAgent.CSSStyleSheetHeader} payload 1575 * @param {!CSSAgent.CSSStyleSheetHeader} payload
1558 */ 1576 */
1559 WebInspector.CSSStyleSheetHeader = function(cssModel, payload) 1577 WebInspector.CSSStyleSheetHeader = function(cssModel, payload)
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1610 }, 1628 },
1611 1629
1612 /** 1630 /**
1613 * @param {number} lineNumber 1631 * @param {number} lineNumber
1614 * @param {number=} columnNumber 1632 * @param {number=} columnNumber
1615 * @return {?WebInspector.UILocation} 1633 * @return {?WebInspector.UILocation}
1616 */ 1634 */
1617 rawLocationToUILocation: function(lineNumber, columnNumber) 1635 rawLocationToUILocation: function(lineNumber, columnNumber)
1618 { 1636 {
1619 var uiLocation = null; 1637 var uiLocation = null;
1620 var rawLocation = new WebInspector.CSSLocation(this._cssModel.target(), this.resourceURL(), lineNumber, columnNumber); 1638 var rawLocation = new WebInspector.CSSLocation(this._cssModel.target(), this.id, this.resourceURL(), lineNumber, columnNumber);
1621 for (var i = this._sourceMappings.length - 1; !uiLocation && i >= 0; --i ) 1639 for (var i = this._sourceMappings.length - 1; !uiLocation && i >= 0; --i )
1622 uiLocation = this._sourceMappings[i].rawLocationToUILocation(rawLoca tion); 1640 uiLocation = this._sourceMappings[i].rawLocationToUILocation(rawLoca tion);
1623 return uiLocation; 1641 return uiLocation;
1624 }, 1642 },
1625 1643
1626 /** 1644 /**
1627 * @param {!WebInspector.SourceMapping} sourceMapping 1645 * @param {!WebInspector.SourceMapping} sourceMapping
1628 */ 1646 */
1629 pushSourceMapping: function(sourceMapping) 1647 pushSourceMapping: function(sourceMapping)
1630 { 1648 {
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1840 for (var i = 0; i < callbacks.length; ++i) 1858 for (var i = 0; i < callbacks.length; ++i)
1841 callbacks[i](computedStyle); 1859 callbacks[i](computedStyle);
1842 } 1860 }
1843 } 1861 }
1844 } 1862 }
1845 1863
1846 /** 1864 /**
1847 * @type {!WebInspector.CSSStyleModel} 1865 * @type {!WebInspector.CSSStyleModel}
1848 */ 1866 */
1849 WebInspector.cssModel; 1867 WebInspector.cssModel;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698