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 714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 725 * @constructor | 725 * @constructor |
| 726 * @param {!WebInspector.CSSStyleModel} cssModel | 726 * @param {!WebInspector.CSSStyleModel} cssModel |
| 727 * @param {!CSSAgent.CSSStyle} payload | 727 * @param {!CSSAgent.CSSStyle} payload |
| 728 */ | 728 */ |
| 729 WebInspector.CSSStyleDeclaration = function(cssModel, payload) | 729 WebInspector.CSSStyleDeclaration = function(cssModel, payload) |
| 730 { | 730 { |
| 731 this._cssModel = cssModel; | 731 this._cssModel = cssModel; |
| 732 this.id = payload.styleId; | 732 this.id = payload.styleId; |
| 733 this.width = payload.width; | 733 this.width = payload.width; |
| 734 this.height = payload.height; | 734 this.height = payload.height; |
| 735 this.range = payload.range; | 735 this.range = payload.range ? WebInspector.TextRange.fromObject(payload.range ) : null; |
| 736 this._shorthandValues = WebInspector.CSSStyleDeclaration.buildShorthandValue Map(payload.shorthandEntries); | 736 this._shorthandValues = WebInspector.CSSStyleDeclaration.buildShorthandValue Map(payload.shorthandEntries); |
| 737 this._livePropertyMap = {}; // LIVE properties (source-based or style-based) : { name -> CSSProperty } | 737 this._livePropertyMap = {}; // LIVE properties (source-based or style-based) : { name -> CSSProperty } |
| 738 this._allProperties = []; // ALL properties: [ CSSProperty ] | 738 this._allProperties = []; // ALL properties: [ CSSProperty ] |
| 739 this.__disabledProperties = {}; // DISABLED properties: { index -> CSSProper ty } | 739 this.__disabledProperties = {}; // DISABLED properties: { index -> CSSProper ty } |
| 740 var payloadPropertyCount = payload.cssProperties.length; | 740 var payloadPropertyCount = payload.cssProperties.length; |
| 741 | 741 |
| 742 | 742 |
| 743 for (var i = 0; i < payloadPropertyCount; ++i) { | 743 for (var i = 0; i < payloadPropertyCount; ++i) { |
| 744 var property = WebInspector.CSSProperty.parsePayload(this, i, payload.cs sProperties[i]); | 744 var property = WebInspector.CSSProperty.parsePayload(this, i, payload.cs sProperties[i]); |
| 745 this._allProperties.push(property); | 745 this._allProperties.push(property); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 794 WebInspector.CSSStyleDeclaration.parseComputedStylePayload = function(cssModel, payload) | 794 WebInspector.CSSStyleDeclaration.parseComputedStylePayload = function(cssModel, payload) |
| 795 { | 795 { |
| 796 var newPayload = /** @type {!CSSAgent.CSSStyle} */ ({ cssProperties: [], sho rthandEntries: [], width: "", height: "" }); | 796 var newPayload = /** @type {!CSSAgent.CSSStyle} */ ({ cssProperties: [], sho rthandEntries: [], width: "", height: "" }); |
| 797 if (payload) | 797 if (payload) |
| 798 newPayload.cssProperties = /** @type {!Array.<!CSSAgent.CSSProperty>} */ (payload); | 798 newPayload.cssProperties = /** @type {!Array.<!CSSAgent.CSSProperty>} */ (payload); |
| 799 | 799 |
| 800 return new WebInspector.CSSStyleDeclaration(cssModel, newPayload); | 800 return new WebInspector.CSSStyleDeclaration(cssModel, newPayload); |
| 801 } | 801 } |
| 802 | 802 |
| 803 WebInspector.CSSStyleDeclaration.prototype = { | 803 WebInspector.CSSStyleDeclaration.prototype = { |
| 804 /** | |
| 805 * @param {string} styleSheetId | |
| 806 * @param {!WebInspector.TextRange} oldRange | |
| 807 * @param {!WebInspector.TextRange} newRange | |
| 808 */ | |
| 809 sourceStyleSheetEdited: function(styleSheetId, oldRange, newRange) | |
| 810 { | |
| 811 if (!this.id || this.id.styleSheetId !== styleSheetId) | |
| 812 return; | |
| 813 if (this.range) | |
| 814 this.range = this.range.rebaseAfterTextEdit(oldRange, newRange); | |
| 815 for (var i = 0; i < this._allProperties.length; ++i) | |
| 816 this._allProperties[i].sourceStyleSheetEdited(styleSheetId, oldRange , newRange); | |
| 817 }, | |
| 818 | |
| 804 _computeActiveProperties: function() | 819 _computeActiveProperties: function() |
| 805 { | 820 { |
| 806 var activeProperties = {}; | 821 var activeProperties = {}; |
| 807 for (var i = this._allProperties.length - 1; i >= 0; --i) { | 822 for (var i = this._allProperties.length - 1; i >= 0; --i) { |
| 808 var property = this._allProperties[i]; | 823 var property = this._allProperties[i]; |
| 809 if (property.styleBased || property.disabled) | 824 if (property.styleBased || property.disabled) |
| 810 continue; | 825 continue; |
| 811 property._setActive(false); | 826 property._setActive(false); |
| 812 if (!property.parsedOk) | 827 if (!property.parsedOk) |
| 813 continue; | 828 continue; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 963 * @param {!WebInspector.CSSStyleModel} cssModel | 978 * @param {!WebInspector.CSSStyleModel} cssModel |
| 964 * @param {!CSSAgent.CSSRule} payload | 979 * @param {!CSSAgent.CSSRule} payload |
| 965 * @param {!Array.<number>=} matchingSelectors | 980 * @param {!Array.<number>=} matchingSelectors |
| 966 */ | 981 */ |
| 967 WebInspector.CSSRule = function(cssModel, payload, matchingSelectors) | 982 WebInspector.CSSRule = function(cssModel, payload, matchingSelectors) |
| 968 { | 983 { |
| 969 this._cssModel = cssModel; | 984 this._cssModel = cssModel; |
| 970 this.id = payload.ruleId; | 985 this.id = payload.ruleId; |
| 971 if (matchingSelectors) | 986 if (matchingSelectors) |
| 972 this.matchingSelectors = matchingSelectors; | 987 this.matchingSelectors = matchingSelectors; |
| 973 this.selectors = payload.selectorList.selectors; | 988 this.selectors = payload.selectorList.selectors || []; |
|
apavlov
2014/04/02 15:23:57
Being on too safe a side?
lushnikov
2014/04/02 15:35:04
Done.
| |
| 989 for (var i = 0; i < this.selectors.length; ++i) { | |
| 990 var selector = this.selectors[i]; | |
| 991 if (selector.range) | |
| 992 selector.range = WebInspector.TextRange.fromObject(selector.range); | |
| 993 } | |
| 974 this.selectorText = this.selectors.select("value").join(", "); | 994 this.selectorText = this.selectors.select("value").join(", "); |
| 975 | 995 |
| 976 var firstRange = this.selectors[0].range; | 996 var firstRange = this.selectors[0].range; |
| 977 if (firstRange) { | 997 if (firstRange) { |
| 978 var lastRange = this.selectors.peekLast().range; | 998 var lastRange = this.selectors.peekLast().range; |
| 979 this.selectorRange = new WebInspector.TextRange(firstRange.startLine, fi rstRange.startColumn, lastRange.endLine, lastRange.endColumn); | 999 this.selectorRange = new WebInspector.TextRange(firstRange.startLine, fi rstRange.startColumn, lastRange.endLine, lastRange.endColumn); |
| 980 } | 1000 } |
| 981 this.sourceURL = payload.sourceURL; | 1001 this.sourceURL = payload.sourceURL; |
| 982 this.origin = payload.origin; | 1002 this.origin = payload.origin; |
| 983 this.style = WebInspector.CSSStyleDeclaration.parsePayload(this._cssModel, p ayload.style); | 1003 this.style = WebInspector.CSSStyleDeclaration.parsePayload(this._cssModel, p ayload.style); |
| 984 this.style.parentRule = this; | 1004 this.style.parentRule = this; |
| 985 if (payload.media) | 1005 if (payload.media) |
| 986 this.media = WebInspector.CSSMedia.parseMediaArrayPayload(cssModel, payl oad.media); | 1006 this.media = WebInspector.CSSMedia.parseMediaArrayPayload(cssModel, payl oad.media); |
| 987 this._setRawLocationAndFrameId(); | 1007 this._setRawLocationAndFrameId(); |
| 988 } | 1008 } |
| 989 | 1009 |
| 990 /** | 1010 /** |
| 991 * @param {!WebInspector.CSSStyleModel} cssModel | 1011 * @param {!WebInspector.CSSStyleModel} cssModel |
| 992 * @param {!CSSAgent.CSSRule} payload | 1012 * @param {!CSSAgent.CSSRule} payload |
| 993 * @param {!Array.<number>=} matchingIndices | 1013 * @param {!Array.<number>=} matchingIndices |
| 994 * @return {!WebInspector.CSSRule} | 1014 * @return {!WebInspector.CSSRule} |
| 995 */ | 1015 */ |
| 996 WebInspector.CSSRule.parsePayload = function(cssModel, payload, matchingIndices) | 1016 WebInspector.CSSRule.parsePayload = function(cssModel, payload, matchingIndices) |
| 997 { | 1017 { |
| 998 return new WebInspector.CSSRule(cssModel, payload, matchingIndices); | 1018 return new WebInspector.CSSRule(cssModel, payload, matchingIndices); |
| 999 } | 1019 } |
| 1000 | 1020 |
| 1001 WebInspector.CSSRule.prototype = { | 1021 WebInspector.CSSRule.prototype = { |
| 1022 /** | |
| 1023 * @param {string} styleSheetId | |
| 1024 * @param {!WebInspector.TextRange} oldRange | |
| 1025 * @param {!WebInspector.TextRange} newRange | |
| 1026 */ | |
| 1027 sourceStyleSheetEdited: function(styleSheetId, oldRange, newRange) | |
| 1028 { | |
| 1029 if (this.id && this.id.styleSheetId === styleSheetId) { | |
| 1030 if (this.selectorRange) | |
| 1031 this.selectorRange = this.selectorRange.rebaseAfterTextEdit(oldR ange, newRange); | |
| 1032 for (var i = 0; i < this.selectors.length; ++i) { | |
| 1033 var selector = this.selectors[i]; | |
| 1034 if (selector.range) | |
| 1035 selector.range = selector.range.rebaseAfterTextEdit(oldRange , newRange); | |
| 1036 } | |
| 1037 } | |
| 1038 if (this.media) { | |
| 1039 for (var i = 0; i < this.media.length; ++i) | |
| 1040 this.media[i].sourceStyleSheetEdited(styleSheetId, oldRange, new Range); | |
| 1041 } | |
| 1042 this.style.sourceStyleSheetEdited(styleSheetId, oldRange, newRange); | |
| 1043 }, | |
| 1044 | |
| 1002 _setRawLocationAndFrameId: function() | 1045 _setRawLocationAndFrameId: function() |
| 1003 { | 1046 { |
| 1004 if (!this.id) | 1047 if (!this.id) |
| 1005 return; | 1048 return; |
| 1006 var styleSheetHeader = this._cssModel.styleSheetHeaderForId(this.id.styl eSheetId); | 1049 var styleSheetHeader = this._cssModel.styleSheetHeaderForId(this.id.styl eSheetId); |
| 1007 this.frameId = styleSheetHeader.frameId; | 1050 this.frameId = styleSheetHeader.frameId; |
| 1008 var url = styleSheetHeader.resourceURL(); | 1051 var url = styleSheetHeader.resourceURL(); |
| 1009 if (!url) | 1052 if (!url) |
| 1010 return; | 1053 return; |
| 1011 this.rawLocation = new WebInspector.CSSLocation(this._cssModel.target(), url, this.lineNumberInSource(0), this.columnNumberInSource(0)); | 1054 this.rawLocation = new WebInspector.CSSLocation(this._cssModel.target(), url, this.lineNumberInSource(0), this.columnNumberInSource(0)); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1087 { | 1130 { |
| 1088 this.ownerStyle = ownerStyle; | 1131 this.ownerStyle = ownerStyle; |
| 1089 this.index = index; | 1132 this.index = index; |
| 1090 this.name = name; | 1133 this.name = name; |
| 1091 this.value = value; | 1134 this.value = value; |
| 1092 this.important = important; | 1135 this.important = important; |
| 1093 this.disabled = disabled; | 1136 this.disabled = disabled; |
| 1094 this.parsedOk = parsedOk; | 1137 this.parsedOk = parsedOk; |
| 1095 this.implicit = implicit; | 1138 this.implicit = implicit; |
| 1096 this.text = text; | 1139 this.text = text; |
| 1097 this.range = range; | 1140 this.range = range ? WebInspector.TextRange.fromObject(range) : null; |
| 1098 } | 1141 } |
| 1099 | 1142 |
| 1100 /** | 1143 /** |
| 1101 * @param {?WebInspector.CSSStyleDeclaration} ownerStyle | 1144 * @param {?WebInspector.CSSStyleDeclaration} ownerStyle |
| 1102 * @param {number} index | 1145 * @param {number} index |
| 1103 * @param {!CSSAgent.CSSProperty} payload | 1146 * @param {!CSSAgent.CSSProperty} payload |
| 1104 * @return {!WebInspector.CSSProperty} | 1147 * @return {!WebInspector.CSSProperty} |
| 1105 */ | 1148 */ |
| 1106 WebInspector.CSSProperty.parsePayload = function(ownerStyle, index, payload) | 1149 WebInspector.CSSProperty.parsePayload = function(ownerStyle, index, payload) |
| 1107 { | 1150 { |
| 1108 // The following default field values are used in the payload: | 1151 // The following default field values are used in the payload: |
| 1109 // important: false | 1152 // important: false |
| 1110 // parsedOk: true | 1153 // parsedOk: true |
| 1111 // implicit: false | 1154 // implicit: false |
| 1112 // disabled: false | 1155 // disabled: false |
| 1113 var result = new WebInspector.CSSProperty( | 1156 var result = new WebInspector.CSSProperty( |
| 1114 ownerStyle, index, payload.name, payload.value, payload.important || fal se, payload.disabled || false, ("parsedOk" in payload) ? !!payload.parsedOk : tr ue, !!payload.implicit, payload.text, payload.range); | 1157 ownerStyle, index, payload.name, payload.value, payload.important || fal se, payload.disabled || false, ("parsedOk" in payload) ? !!payload.parsedOk : tr ue, !!payload.implicit, payload.text, payload.range); |
| 1115 return result; | 1158 return result; |
| 1116 } | 1159 } |
| 1117 | 1160 |
| 1118 WebInspector.CSSProperty.prototype = { | 1161 WebInspector.CSSProperty.prototype = { |
| 1119 /** | 1162 /** |
| 1163 * @param {string} styleSheetId | |
| 1164 * @param {!WebInspector.TextRange} oldRange | |
| 1165 * @param {!WebInspector.TextRange} newRange | |
| 1166 */ | |
| 1167 sourceStyleSheetEdited: function(styleSheetId, oldRange, newRange) | |
| 1168 { | |
| 1169 if (!this.ownerStyle.id || this.ownerStyle.id.styleSheetId !== styleShee tId) | |
| 1170 return; | |
| 1171 if (this.range) | |
| 1172 this.range = this.range.rebaseAfterTextEdit(oldRange, newRange); | |
| 1173 }, | |
| 1174 | |
| 1175 /** | |
| 1120 * @param {boolean} active | 1176 * @param {boolean} active |
| 1121 */ | 1177 */ |
| 1122 _setActive: function(active) | 1178 _setActive: function(active) |
| 1123 { | 1179 { |
| 1124 this._active = active; | 1180 this._active = active; |
| 1125 }, | 1181 }, |
| 1126 | 1182 |
| 1127 get propertyText() | 1183 get propertyText() |
| 1128 { | 1184 { |
| 1129 if (this.text !== undefined) | 1185 if (this.text !== undefined) |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1302 WebInspector.CSSMedia.parseMediaArrayPayload = function(cssModel, payload) | 1358 WebInspector.CSSMedia.parseMediaArrayPayload = function(cssModel, payload) |
| 1303 { | 1359 { |
| 1304 var result = []; | 1360 var result = []; |
| 1305 for (var i = 0; i < payload.length; ++i) | 1361 for (var i = 0; i < payload.length; ++i) |
| 1306 result.push(WebInspector.CSSMedia.parsePayload(cssModel, payload[i])); | 1362 result.push(WebInspector.CSSMedia.parsePayload(cssModel, payload[i])); |
| 1307 return result; | 1363 return result; |
| 1308 } | 1364 } |
| 1309 | 1365 |
| 1310 WebInspector.CSSMedia.prototype = { | 1366 WebInspector.CSSMedia.prototype = { |
| 1311 /** | 1367 /** |
| 1368 * @param {string} styleSheetId | |
| 1369 * @param {!WebInspector.TextRange} oldRange | |
| 1370 * @param {!WebInspector.TextRange} newRange | |
| 1371 */ | |
| 1372 sourceStyleSheetEdited: function(styleSheetId, oldRange, newRange) | |
| 1373 { | |
| 1374 if (this.parentStyleSheetId !== styleSheetId) | |
| 1375 return; | |
| 1376 if (this.range) | |
| 1377 this.range = this.range.rebaseAfterTextEdit(oldRange, newRange); | |
| 1378 }, | |
| 1379 | |
| 1380 /** | |
| 1312 * @return {number|undefined} | 1381 * @return {number|undefined} |
| 1313 */ | 1382 */ |
| 1314 lineNumberInSource: function() | 1383 lineNumberInSource: function() |
| 1315 { | 1384 { |
| 1316 if (!this.range) | 1385 if (!this.range) |
| 1317 return undefined; | 1386 return undefined; |
| 1318 var header = this.header(); | 1387 var header = this.header(); |
| 1319 if (!header) | 1388 if (!header) |
| 1320 return undefined; | 1389 return undefined; |
| 1321 return header.lineNumberInSource(this.range.startLine); | 1390 return header.lineNumberInSource(this.range.startLine); |
| (...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1633 for (var i = 0; i < callbacks.length; ++i) | 1702 for (var i = 0; i < callbacks.length; ++i) |
| 1634 callbacks[i](computedStyle); | 1703 callbacks[i](computedStyle); |
| 1635 } | 1704 } |
| 1636 } | 1705 } |
| 1637 } | 1706 } |
| 1638 | 1707 |
| 1639 /** | 1708 /** |
| 1640 * @type {!WebInspector.CSSStyleModel} | 1709 * @type {!WebInspector.CSSStyleModel} |
| 1641 */ | 1710 */ |
| 1642 WebInspector.cssModel; | 1711 WebInspector.cssModel; |
| OLD | NEW |