| 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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 { | 266 { |
| 267 this._pendingCommandsMajorState.pop(); | 267 this._pendingCommandsMajorState.pop(); |
| 268 if (error) { | 268 if (error) { |
| 269 failureCallback(); | 269 failureCallback(); |
| 270 return; | 270 return; |
| 271 } | 271 } |
| 272 this._domModel.markUndoableState(); | 272 this._domModel.markUndoableState(); |
| 273 this._computeMatchingSelectors(rulePayload, nodeId, successCallback,
failureCallback); | 273 this._computeMatchingSelectors(rulePayload, nodeId, successCallback,
failureCallback); |
| 274 } | 274 } |
| 275 | 275 |
| 276 if (!rule.styleSheetId) |
| 277 throw "No rule stylesheet id"; |
| 276 this._pendingCommandsMajorState.push(true); | 278 this._pendingCommandsMajorState.push(true); |
| 277 this._agent.setRuleSelector(rule.id.styleSheetId, rule.selectorRange, ne
wSelector, callback.bind(this, nodeId, successCallback, failureCallback, newSele
ctor)); | 279 this._agent.setRuleSelector(rule.styleSheetId, rule.selectorRange, newSe
lector, callback.bind(this, nodeId, successCallback, failureCallback, newSelecto
r)); |
| 278 }, | 280 }, |
| 279 | 281 |
| 280 /** | 282 /** |
| 281 * @param {!CSSAgent.CSSRule} rulePayload | 283 * @param {!CSSAgent.CSSRule} rulePayload |
| 282 * @param {!DOMAgent.NodeId} nodeId | 284 * @param {!DOMAgent.NodeId} nodeId |
| 283 * @param {function(!WebInspector.CSSRule)} successCallback | 285 * @param {function(!WebInspector.CSSRule)} successCallback |
| 284 * @param {function()} failureCallback | 286 * @param {function()} failureCallback |
| 285 */ | 287 */ |
| 286 _computeMatchingSelectors: function(rulePayload, nodeId, successCallback, fa
ilureCallback) | 288 _computeMatchingSelectors: function(rulePayload, nodeId, successCallback, fa
ilureCallback) |
| 287 { | 289 { |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 721 } | 723 } |
| 722 | 724 |
| 723 /** | 725 /** |
| 724 * @constructor | 726 * @constructor |
| 725 * @param {!WebInspector.CSSStyleModel} cssModel | 727 * @param {!WebInspector.CSSStyleModel} cssModel |
| 726 * @param {!CSSAgent.CSSStyle} payload | 728 * @param {!CSSAgent.CSSStyle} payload |
| 727 */ | 729 */ |
| 728 WebInspector.CSSStyleDeclaration = function(cssModel, payload) | 730 WebInspector.CSSStyleDeclaration = function(cssModel, payload) |
| 729 { | 731 { |
| 730 this._cssModel = cssModel; | 732 this._cssModel = cssModel; |
| 731 this.id = payload.styleId; | 733 this.styleSheetId = payload.styleSheetId; |
| 732 this.width = payload.width; | 734 this.width = payload.width; |
| 733 this.height = payload.height; | 735 this.height = payload.height; |
| 734 this.range = payload.range ? WebInspector.TextRange.fromObject(payload.range
) : null; | 736 this.range = payload.range ? WebInspector.TextRange.fromObject(payload.range
) : null; |
| 735 this._shorthandValues = WebInspector.CSSStyleDeclaration.buildShorthandValue
Map(payload.shorthandEntries); | 737 this._shorthandValues = WebInspector.CSSStyleDeclaration.buildShorthandValue
Map(payload.shorthandEntries); |
| 736 this._livePropertyMap = {}; // LIVE properties (source-based or style-based)
: { name -> CSSProperty } | 738 this._livePropertyMap = {}; // LIVE properties (source-based or style-based)
: { name -> CSSProperty } |
| 737 this._allProperties = []; // ALL properties: [ CSSProperty ] | 739 this._allProperties = []; // ALL properties: [ CSSProperty ] |
| 738 this.__disabledProperties = {}; // DISABLED properties: { index -> CSSProper
ty } | 740 this.__disabledProperties = {}; // DISABLED properties: { index -> CSSProper
ty } |
| 739 var payloadPropertyCount = payload.cssProperties.length; | 741 var payloadPropertyCount = payload.cssProperties.length; |
| 740 | 742 |
| 741 | 743 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 } | 802 } |
| 801 | 803 |
| 802 WebInspector.CSSStyleDeclaration.prototype = { | 804 WebInspector.CSSStyleDeclaration.prototype = { |
| 803 /** | 805 /** |
| 804 * @param {string} styleSheetId | 806 * @param {string} styleSheetId |
| 805 * @param {!WebInspector.TextRange} oldRange | 807 * @param {!WebInspector.TextRange} oldRange |
| 806 * @param {!WebInspector.TextRange} newRange | 808 * @param {!WebInspector.TextRange} newRange |
| 807 */ | 809 */ |
| 808 sourceStyleSheetEdited: function(styleSheetId, oldRange, newRange) | 810 sourceStyleSheetEdited: function(styleSheetId, oldRange, newRange) |
| 809 { | 811 { |
| 810 if (!this.id || this.id.styleSheetId !== styleSheetId) | 812 if (this.styleSheetId !== styleSheetId) |
| 811 return; | 813 return; |
| 812 if (this.range) | 814 if (this.range) |
| 813 this.range = this.range.rebaseAfterTextEdit(oldRange, newRange); | 815 this.range = this.range.rebaseAfterTextEdit(oldRange, newRange); |
| 814 for (var i = 0; i < this._allProperties.length; ++i) | 816 for (var i = 0; i < this._allProperties.length; ++i) |
| 815 this._allProperties[i].sourceStyleSheetEdited(styleSheetId, oldRange
, newRange); | 817 this._allProperties[i].sourceStyleSheetEdited(styleSheetId, oldRange
, newRange); |
| 816 }, | 818 }, |
| 817 | 819 |
| 818 _computeActiveProperties: function() | 820 _computeActiveProperties: function() |
| 819 { | 821 { |
| 820 var activeProperties = {}; | 822 var activeProperties = {}; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 957 if (!userCallback) | 959 if (!userCallback) |
| 958 return; | 960 return; |
| 959 | 961 |
| 960 if (error) { | 962 if (error) { |
| 961 console.error(error); | 963 console.error(error); |
| 962 userCallback(null); | 964 userCallback(null); |
| 963 } else | 965 } else |
| 964 userCallback(WebInspector.CSSStyleDeclaration.parsePayload(this.
_cssModel, payload)); | 966 userCallback(WebInspector.CSSStyleDeclaration.parsePayload(this.
_cssModel, payload)); |
| 965 } | 967 } |
| 966 | 968 |
| 967 if (!this.id) | 969 if (!this.styleSheetId) |
| 968 throw "No style id"; | 970 throw "No stylesheet id"; |
| 969 | 971 |
| 970 this._cssModel._pendingCommandsMajorState.push(true); | 972 this._cssModel._pendingCommandsMajorState.push(true); |
| 971 this._cssModel._agent.setPropertyText(this.id.styleSheetId, this._insert
ionRange(index), name + ": " + value + ";", callback.bind(this)); | 973 this._cssModel._agent.setPropertyText(this.styleSheetId, this._insertion
Range(index), name + ": " + value + ";", callback.bind(this)); |
| 972 }, | 974 }, |
| 973 | 975 |
| 974 /** | 976 /** |
| 975 * @param {string} name | 977 * @param {string} name |
| 976 * @param {string} value | 978 * @param {string} value |
| 977 * @param {function(?WebInspector.CSSStyleDeclaration)=} userCallback | 979 * @param {function(?WebInspector.CSSStyleDeclaration)=} userCallback |
| 978 */ | 980 */ |
| 979 appendProperty: function(name, value, userCallback) | 981 appendProperty: function(name, value, userCallback) |
| 980 { | 982 { |
| 981 this.insertPropertyAt(this.allProperties.length, name, value, userCallba
ck); | 983 this.insertPropertyAt(this.allProperties.length, name, value, userCallba
ck); |
| 982 } | 984 } |
| 983 } | 985 } |
| 984 | 986 |
| 985 /** | 987 /** |
| 986 * @constructor | 988 * @constructor |
| 987 * @param {!WebInspector.CSSStyleModel} cssModel | 989 * @param {!WebInspector.CSSStyleModel} cssModel |
| 988 * @param {!CSSAgent.CSSRule} payload | 990 * @param {!CSSAgent.CSSRule} payload |
| 989 * @param {!Array.<number>=} matchingSelectors | 991 * @param {!Array.<number>=} matchingSelectors |
| 990 */ | 992 */ |
| 991 WebInspector.CSSRule = function(cssModel, payload, matchingSelectors) | 993 WebInspector.CSSRule = function(cssModel, payload, matchingSelectors) |
| 992 { | 994 { |
| 993 this._cssModel = cssModel; | 995 this._cssModel = cssModel; |
| 994 this.id = payload.ruleId; | 996 this.styleSheetId = payload.styleSheetId; |
| 995 if (matchingSelectors) | 997 if (matchingSelectors) |
| 996 this.matchingSelectors = matchingSelectors; | 998 this.matchingSelectors = matchingSelectors; |
| 997 this.selectors = payload.selectorList.selectors; | 999 this.selectors = payload.selectorList.selectors; |
| 998 for (var i = 0; i < this.selectors.length; ++i) { | 1000 for (var i = 0; i < this.selectors.length; ++i) { |
| 999 var selector = this.selectors[i]; | 1001 var selector = this.selectors[i]; |
| 1000 if (selector.range) | 1002 if (selector.range) |
| 1001 selector.range = WebInspector.TextRange.fromObject(selector.range); | 1003 selector.range = WebInspector.TextRange.fromObject(selector.range); |
| 1002 } | 1004 } |
| 1003 this.selectorText = this.selectors.select("value").join(", "); | 1005 this.selectorText = this.selectors.select("value").join(", "); |
| 1004 | 1006 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1028 } | 1030 } |
| 1029 | 1031 |
| 1030 WebInspector.CSSRule.prototype = { | 1032 WebInspector.CSSRule.prototype = { |
| 1031 /** | 1033 /** |
| 1032 * @param {string} styleSheetId | 1034 * @param {string} styleSheetId |
| 1033 * @param {!WebInspector.TextRange} oldRange | 1035 * @param {!WebInspector.TextRange} oldRange |
| 1034 * @param {!WebInspector.TextRange} newRange | 1036 * @param {!WebInspector.TextRange} newRange |
| 1035 */ | 1037 */ |
| 1036 sourceStyleSheetEdited: function(styleSheetId, oldRange, newRange) | 1038 sourceStyleSheetEdited: function(styleSheetId, oldRange, newRange) |
| 1037 { | 1039 { |
| 1038 if (this.id && this.id.styleSheetId === styleSheetId) { | 1040 if (this.styleSheetId === styleSheetId) { |
| 1039 if (this.selectorRange) | 1041 if (this.selectorRange) |
| 1040 this.selectorRange = this.selectorRange.rebaseAfterTextEdit(oldR
ange, newRange); | 1042 this.selectorRange = this.selectorRange.rebaseAfterTextEdit(oldR
ange, newRange); |
| 1041 for (var i = 0; i < this.selectors.length; ++i) { | 1043 for (var i = 0; i < this.selectors.length; ++i) { |
| 1042 var selector = this.selectors[i]; | 1044 var selector = this.selectors[i]; |
| 1043 if (selector.range) | 1045 if (selector.range) |
| 1044 selector.range = selector.range.rebaseAfterTextEdit(oldRange
, newRange); | 1046 selector.range = selector.range.rebaseAfterTextEdit(oldRange
, newRange); |
| 1045 } | 1047 } |
| 1046 } | 1048 } |
| 1047 if (this.media) { | 1049 if (this.media) { |
| 1048 for (var i = 0; i < this.media.length; ++i) | 1050 for (var i = 0; i < this.media.length; ++i) |
| 1049 this.media[i].sourceStyleSheetEdited(styleSheetId, oldRange, new
Range); | 1051 this.media[i].sourceStyleSheetEdited(styleSheetId, oldRange, new
Range); |
| 1050 } | 1052 } |
| 1051 this.style.sourceStyleSheetEdited(styleSheetId, oldRange, newRange); | 1053 this.style.sourceStyleSheetEdited(styleSheetId, oldRange, newRange); |
| 1052 }, | 1054 }, |
| 1053 | 1055 |
| 1054 _setRawLocationAndFrameId: function() | 1056 _setRawLocationAndFrameId: function() |
| 1055 { | 1057 { |
| 1056 if (!this.id) | 1058 if (!this.styleSheetId) |
| 1057 return; | 1059 return; |
| 1058 var styleSheetHeader = this._cssModel.styleSheetHeaderForId(this.id.styl
eSheetId); | 1060 var styleSheetHeader = this._cssModel.styleSheetHeaderForId(this.styleSh
eetId); |
| 1059 this.frameId = styleSheetHeader.frameId; | 1061 this.frameId = styleSheetHeader.frameId; |
| 1060 var url = styleSheetHeader.resourceURL(); | 1062 var url = styleSheetHeader.resourceURL(); |
| 1061 if (!url) | 1063 if (!url) |
| 1062 return; | 1064 return; |
| 1063 this.rawLocation = new WebInspector.CSSLocation(this._cssModel.target(),
url, this.lineNumberInSource(0), this.columnNumberInSource(0)); | 1065 this.rawLocation = new WebInspector.CSSLocation(this._cssModel.target(),
url, this.lineNumberInSource(0), this.columnNumberInSource(0)); |
| 1064 }, | 1066 }, |
| 1065 | 1067 |
| 1066 /** | 1068 /** |
| 1067 * @return {string} | 1069 * @return {string} |
| 1068 */ | 1070 */ |
| 1069 resourceURL: function() | 1071 resourceURL: function() |
| 1070 { | 1072 { |
| 1071 if (!this.id) | 1073 if (!this.styleSheetId) |
| 1072 return ""; | 1074 return ""; |
| 1073 var styleSheetHeader = this._cssModel.styleSheetHeaderForId(this.id.styl
eSheetId); | 1075 var styleSheetHeader = this._cssModel.styleSheetHeaderForId(this.styleSh
eetId); |
| 1074 return styleSheetHeader.resourceURL(); | 1076 return styleSheetHeader.resourceURL(); |
| 1075 }, | 1077 }, |
| 1076 | 1078 |
| 1077 /** | 1079 /** |
| 1078 * @param {number} selectorIndex | 1080 * @param {number} selectorIndex |
| 1079 * @return {number} | 1081 * @return {number} |
| 1080 */ | 1082 */ |
| 1081 lineNumberInSource: function(selectorIndex) | 1083 lineNumberInSource: function(selectorIndex) |
| 1082 { | 1084 { |
| 1083 var selector = this.selectors[selectorIndex]; | 1085 var selector = this.selectors[selectorIndex]; |
| 1084 if (!selector || !selector.range) | 1086 if (!selector || !selector.range || !this.styleSheetId) |
| 1085 return 0; | 1087 return 0; |
| 1086 var styleSheetHeader = this._cssModel.styleSheetHeaderForId(this.id.styl
eSheetId); | 1088 var styleSheetHeader = this._cssModel.styleSheetHeaderForId(this.styleSh
eetId); |
| 1087 return styleSheetHeader.lineNumberInSource(selector.range.startLine); | 1089 return styleSheetHeader.lineNumberInSource(selector.range.startLine); |
| 1088 }, | 1090 }, |
| 1089 | 1091 |
| 1090 /** | 1092 /** |
| 1091 * @param {number} selectorIndex | 1093 * @param {number} selectorIndex |
| 1092 * @return {number|undefined} | 1094 * @return {number|undefined} |
| 1093 */ | 1095 */ |
| 1094 columnNumberInSource: function(selectorIndex) | 1096 columnNumberInSource: function(selectorIndex) |
| 1095 { | 1097 { |
| 1096 var selector = this.selectors[selectorIndex]; | 1098 var selector = this.selectors[selectorIndex]; |
| 1097 if (!selector || !selector.range) | 1099 if (!selector || !selector.range || !this.styleSheetId) |
| 1098 return undefined; | 1100 return undefined; |
| 1099 var styleSheetHeader = this._cssModel.styleSheetHeaderForId(this.id.styl
eSheetId); | 1101 var styleSheetHeader = this._cssModel.styleSheetHeaderForId(this.styleSh
eetId); |
| 1100 console.assert(styleSheetHeader); | 1102 console.assert(styleSheetHeader); |
| 1101 return styleSheetHeader.columnNumberInSource(selector.range.startLine, s
elector.range.startColumn); | 1103 return styleSheetHeader.columnNumberInSource(selector.range.startLine, s
elector.range.startColumn); |
| 1102 }, | 1104 }, |
| 1103 | 1105 |
| 1104 get isUserAgent() | 1106 get isUserAgent() |
| 1105 { | 1107 { |
| 1106 return this.origin === "user-agent"; | 1108 return this.origin === "user-agent"; |
| 1107 }, | 1109 }, |
| 1108 | 1110 |
| 1109 get isUser() | 1111 get isUser() |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1168 } | 1170 } |
| 1169 | 1171 |
| 1170 WebInspector.CSSProperty.prototype = { | 1172 WebInspector.CSSProperty.prototype = { |
| 1171 /** | 1173 /** |
| 1172 * @param {string} styleSheetId | 1174 * @param {string} styleSheetId |
| 1173 * @param {!WebInspector.TextRange} oldRange | 1175 * @param {!WebInspector.TextRange} oldRange |
| 1174 * @param {!WebInspector.TextRange} newRange | 1176 * @param {!WebInspector.TextRange} newRange |
| 1175 */ | 1177 */ |
| 1176 sourceStyleSheetEdited: function(styleSheetId, oldRange, newRange) | 1178 sourceStyleSheetEdited: function(styleSheetId, oldRange, newRange) |
| 1177 { | 1179 { |
| 1178 if (!this.ownerStyle.id || this.ownerStyle.id.styleSheetId !== styleShee
tId) | 1180 if (this.ownerStyle.styleSheetId !== styleSheetId) |
| 1179 return; | 1181 return; |
| 1180 if (this.range) | 1182 if (this.range) |
| 1181 this.range = this.range.rebaseAfterTextEdit(oldRange, newRange); | 1183 this.range = this.range.rebaseAfterTextEdit(oldRange, newRange); |
| 1182 }, | 1184 }, |
| 1183 | 1185 |
| 1184 /** | 1186 /** |
| 1185 * @param {boolean} active | 1187 * @param {boolean} active |
| 1186 */ | 1188 */ |
| 1187 _setActive: function(active) | 1189 _setActive: function(active) |
| 1188 { | 1190 { |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1258 userCallback(style); | 1260 userCallback(style); |
| 1259 } else { | 1261 } else { |
| 1260 if (userCallback) | 1262 if (userCallback) |
| 1261 userCallback(null); | 1263 userCallback(null); |
| 1262 } | 1264 } |
| 1263 } | 1265 } |
| 1264 | 1266 |
| 1265 if (!this.ownerStyle) | 1267 if (!this.ownerStyle) |
| 1266 throw "No ownerStyle for property"; | 1268 throw "No ownerStyle for property"; |
| 1267 | 1269 |
| 1268 if (!this.ownerStyle.id) | 1270 if (!this.ownerStyle.styleSheetId) |
| 1269 throw "No owner style id"; | 1271 throw "No owner style id"; |
| 1270 | 1272 |
| 1271 // An index past all the properties adds a new property to the style. | 1273 // An index past all the properties adds a new property to the style. |
| 1272 var cssModel = this.ownerStyle._cssModel; | 1274 var cssModel = this.ownerStyle._cssModel; |
| 1273 cssModel._pendingCommandsMajorState.push(majorChange); | 1275 cssModel._pendingCommandsMajorState.push(majorChange); |
| 1274 var range = /** @type {!WebInspector.TextRange} */ (this.range); | 1276 var range = /** @type {!WebInspector.TextRange} */ (this.range); |
| 1275 cssModel._agent.setPropertyText(this.ownerStyle.id.styleSheetId, overwri
te ? range : range.collapseToStart(), propertyText, callback.bind(this)); | 1277 cssModel._agent.setPropertyText(this.ownerStyle.styleSheetId, overwrite
? range : range.collapseToStart(), propertyText, callback.bind(this)); |
| 1276 }, | 1278 }, |
| 1277 | 1279 |
| 1278 /** | 1280 /** |
| 1279 * @param {string} newValue | 1281 * @param {string} newValue |
| 1280 * @param {boolean} majorChange | 1282 * @param {boolean} majorChange |
| 1281 * @param {boolean} overwrite | 1283 * @param {boolean} overwrite |
| 1282 * @param {function(?WebInspector.CSSStyleDeclaration)=} userCallback | 1284 * @param {function(?WebInspector.CSSStyleDeclaration)=} userCallback |
| 1283 */ | 1285 */ |
| 1284 setValue: function(newValue, majorChange, overwrite, userCallback) | 1286 setValue: function(newValue, majorChange, overwrite, userCallback) |
| 1285 { | 1287 { |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1712 for (var i = 0; i < callbacks.length; ++i) | 1714 for (var i = 0; i < callbacks.length; ++i) |
| 1713 callbacks[i](computedStyle); | 1715 callbacks[i](computedStyle); |
| 1714 } | 1716 } |
| 1715 } | 1717 } |
| 1716 } | 1718 } |
| 1717 | 1719 |
| 1718 /** | 1720 /** |
| 1719 * @type {!WebInspector.CSSStyleModel} | 1721 * @type {!WebInspector.CSSStyleModel} |
| 1720 */ | 1722 */ |
| 1721 WebInspector.cssModel; | 1723 WebInspector.cssModel; |
| OLD | NEW |