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 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
630 return this._cssModel; | 630 return this._cssModel; |
631 }, | 631 }, |
632 | 632 |
633 __proto__: WebInspector.SDKObject.prototype | 633 __proto__: WebInspector.SDKObject.prototype |
634 } | 634 } |
635 | 635 |
636 /** | 636 /** |
637 * @constructor | 637 * @constructor |
638 * @param {!WebInspector.CSSStyleModel} cssModel | 638 * @param {!WebInspector.CSSStyleModel} cssModel |
639 * @param {!CSSAgent.CSSStyle} payload | 639 * @param {!CSSAgent.CSSStyle} payload |
640 * @param {boolean=} isComputedStyle | |
640 */ | 641 */ |
641 WebInspector.CSSStyleDeclaration = function(cssModel, payload) | 642 WebInspector.CSSStyleDeclaration = function(cssModel, payload, isComputedStyle) |
642 { | 643 { |
643 this._cssModel = cssModel; | 644 this._cssModel = cssModel; |
644 this.styleSheetId = payload.styleSheetId; | 645 this.styleSheetId = payload.styleSheetId; |
645 this.range = payload.range ? WebInspector.TextRange.fromObject(payload.range ) : null; | 646 this.range = payload.range ? WebInspector.TextRange.fromObject(payload.range ) : null; |
646 | 647 |
647 var shorthandEntries = payload.shorthandEntries; | 648 var shorthandEntries = payload.shorthandEntries; |
648 /** @type {!Map.<string, string>} */ | 649 /** @type {!Map.<string, string>} */ |
649 this._shorthandValues = new Map(); | 650 this._shorthandValues = new Map(); |
650 /** @type {!Set.<string>} */ | 651 /** @type {!Set.<string>} */ |
651 this._shorthandIsImportant = new Set(); | 652 this._shorthandIsImportant = new Set(); |
652 for (var i = 0; i < shorthandEntries.length; ++i) { | 653 for (var i = 0; i < shorthandEntries.length; ++i) { |
653 this._shorthandValues.set(shorthandEntries[i].name, shorthandEntries[i]. value); | 654 this._shorthandValues.set(shorthandEntries[i].name, shorthandEntries[i]. value); |
654 if (shorthandEntries[i].important) | 655 if (shorthandEntries[i].important) |
655 this._shorthandIsImportant.add(shorthandEntries[i].name); | 656 this._shorthandIsImportant.add(shorthandEntries[i].name); |
656 } | 657 } |
657 | 658 |
658 this._livePropertyMap = {}; // LIVE properties (source-based or style-based) : { name -> CSSProperty } | 659 this._allProperties = []; |
659 this._allProperties = []; // ALL properties: [ CSSProperty ] | 660 for (var i = 0; i < payload.cssProperties.length; ++i) { |
660 this.__disabledProperties = {}; // DISABLED properties: { index -> CSSProper ty } | |
661 var payloadPropertyCount = payload.cssProperties.length; | |
662 | |
663 for (var i = 0; i < payloadPropertyCount; ++i) { | |
664 var property = WebInspector.CSSProperty.parsePayload(this, i, payload.cs sProperties[i]); | 661 var property = WebInspector.CSSProperty.parsePayload(this, i, payload.cs sProperties[i]); |
665 this._allProperties.push(property); | 662 this._allProperties.push(property); |
666 } | 663 } |
667 | 664 |
668 this._computeActiveProperties(); | 665 if (!isComputedStyle) { |
666 this._generateSyntheticPropertiesIfNeeded(); | |
667 this._computeInactiveProperties(); | |
668 } | |
669 | 669 |
670 var propertyIndex = 0; | 670 this._activePropertyMap = new Map(); |
671 for (var i = 0; i < this._allProperties.length; ++i) { | 671 for (var property of this._allProperties) { |
672 var property = this._allProperties[i]; | 672 if (!property.activeInStyle()) |
673 if (property.disabled) | |
674 this.__disabledProperties[i] = property; | |
675 if (!property.active && !property.styleBased) | |
676 continue; | 673 continue; |
677 var name = property.name; | 674 this._activePropertyMap.set(property.name, property); |
678 this[propertyIndex] = name; | |
679 this._livePropertyMap[name] = property; | |
680 ++propertyIndex; | |
681 } | 675 } |
682 this.length = propertyIndex; | 676 |
683 if ("cssText" in payload) | 677 if ("cssText" in payload) |
684 this.cssText = payload.cssText; | 678 this.cssText = payload.cssText; |
685 } | 679 } |
686 | 680 |
687 /** | 681 /** |
688 * @param {!WebInspector.CSSStyleModel} cssModel | 682 * @param {!WebInspector.CSSStyleModel} cssModel |
689 * @return {!WebInspector.CSSStyleDeclaration} | 683 * @return {!WebInspector.CSSStyleDeclaration} |
690 */ | 684 */ |
691 WebInspector.CSSStyleDeclaration.createDummyStyle = function(cssModel) | 685 WebInspector.CSSStyleDeclaration.createDummyStyle = function(cssModel) |
692 { | 686 { |
(...skipping 18 matching lines...) Expand all Loading... | |
711 * @param {!WebInspector.CSSStyleModel} cssModel | 705 * @param {!WebInspector.CSSStyleModel} cssModel |
712 * @param {!Array.<!CSSAgent.CSSComputedStyleProperty>} payload | 706 * @param {!Array.<!CSSAgent.CSSComputedStyleProperty>} payload |
713 * @return {!WebInspector.CSSStyleDeclaration} | 707 * @return {!WebInspector.CSSStyleDeclaration} |
714 */ | 708 */ |
715 WebInspector.CSSStyleDeclaration.parseComputedStylePayload = function(cssModel, payload) | 709 WebInspector.CSSStyleDeclaration.parseComputedStylePayload = function(cssModel, payload) |
716 { | 710 { |
717 var newPayload = /** @type {!CSSAgent.CSSStyle} */ ({ cssProperties: [], sho rthandEntries: [], width: "", height: "" }); | 711 var newPayload = /** @type {!CSSAgent.CSSStyle} */ ({ cssProperties: [], sho rthandEntries: [], width: "", height: "" }); |
718 if (payload) | 712 if (payload) |
719 newPayload.cssProperties = /** @type {!Array.<!CSSAgent.CSSProperty>} */ (payload); | 713 newPayload.cssProperties = /** @type {!Array.<!CSSAgent.CSSProperty>} */ (payload); |
720 | 714 |
721 return new WebInspector.CSSStyleDeclaration(cssModel, newPayload); | 715 return new WebInspector.CSSStyleDeclaration(cssModel, newPayload, true); |
722 } | 716 } |
723 | 717 |
724 WebInspector.CSSStyleDeclaration.prototype = { | 718 WebInspector.CSSStyleDeclaration.prototype = { |
719 _generateSyntheticPropertiesIfNeeded: function() | |
720 { | |
721 if (this.range) | |
722 return; | |
723 | |
724 if (!this._shorthandValues.size) | |
725 return; | |
726 | |
727 var propertiesSet = new Set(); | |
728 for (var property of this._allProperties) | |
729 propertiesSet.add(property.name); | |
730 | |
731 var generatedProperties = []; | |
732 // For style-based properties, generate shorthands with values when poss ible. | |
733 for (var property of this._allProperties) { | |
734 // For style-based properties, try generating shorthands. | |
735 var shorthands = WebInspector.CSSMetadata.cssPropertiesMetainfo.shor thands(property.name) || []; | |
736 for (var shorthand of shorthands) { | |
737 if (propertiesSet.has(shorthand)) | |
738 continue; // There already is a shorthand this longhands fa lls under. | |
739 var shorthandValue = this._shorthandValues.get(shorthand); | |
740 if (!shorthandValue) | |
741 continue; // Never generate synthetic shorthands when no va lue is available. | |
742 | |
743 // Generate synthetic shorthand we have a value for. | |
744 var shorthandImportance = !!this._shorthandIsImportant.has(short hand); | |
745 var shorthandProperty = new WebInspector.CSSProperty(this, this. allProperties.length, shorthand, shorthandValue, shorthandImportance, false, tru e, false); | |
746 generatedProperties.push(shorthandProperty); | |
747 propertiesSet.add(shorthand); | |
748 } | |
749 } | |
750 this._allProperties = this._allProperties.concat(generatedProperties); | |
751 }, | |
752 | |
753 /** | |
754 * @return {!Array.<!WebInspector.CSSProperty>} | |
755 */ | |
756 leadingProperties: function() | |
757 { | |
758 /** | |
759 * @param {!WebInspector.CSSProperty} property | |
760 * @return {boolean} | |
761 */ | |
762 function propertyHasRange(property) | |
763 { | |
764 return !!property.range; | |
765 } | |
766 | |
767 if (this.range) | |
768 return this._allProperties.filter(propertyHasRange); | |
769 | |
770 var leadingProperties = []; | |
771 for (var property of this._allProperties) { | |
772 var shorthands = WebInspector.CSSMetadata.cssPropertiesMetainfo.shor thands(property.name) || []; | |
773 var belongToAnyShorthand = false; | |
774 for (var shorthand of shorthands) { | |
775 if (this._shorthandValues.get(shorthand)) { | |
776 belongToAnyShorthand = true; | |
777 break; | |
778 } | |
779 } | |
780 if (!belongToAnyShorthand) | |
781 leadingProperties.push(property); | |
782 } | |
783 | |
784 return leadingProperties; | |
785 }, | |
786 | |
725 /** | 787 /** |
726 * @return {!WebInspector.Target} | 788 * @return {!WebInspector.Target} |
727 */ | 789 */ |
728 target: function() | 790 target: function() |
729 { | 791 { |
730 return this._cssModel.target(); | 792 return this._cssModel.target(); |
731 }, | 793 }, |
732 | 794 |
733 /** | 795 /** |
734 * @return {!WebInspector.CSSStyleModel} | 796 * @return {!WebInspector.CSSStyleModel} |
(...skipping 11 matching lines...) Expand all Loading... | |
746 sourceStyleSheetEdited: function(styleSheetId, oldRange, newRange) | 808 sourceStyleSheetEdited: function(styleSheetId, oldRange, newRange) |
747 { | 809 { |
748 if (this.styleSheetId !== styleSheetId) | 810 if (this.styleSheetId !== styleSheetId) |
749 return; | 811 return; |
750 if (this.range) | 812 if (this.range) |
751 this.range = this.range.rebaseAfterTextEdit(oldRange, newRange); | 813 this.range = this.range.rebaseAfterTextEdit(oldRange, newRange); |
752 for (var i = 0; i < this._allProperties.length; ++i) | 814 for (var i = 0; i < this._allProperties.length; ++i) |
753 this._allProperties[i].sourceStyleSheetEdited(styleSheetId, oldRange , newRange); | 815 this._allProperties[i].sourceStyleSheetEdited(styleSheetId, oldRange , newRange); |
754 }, | 816 }, |
755 | 817 |
756 _computeActiveProperties: function() | 818 _computeInactiveProperties: function() |
757 { | 819 { |
758 var activeProperties = {}; | 820 var activeProperties = {}; |
759 for (var i = this._allProperties.length - 1; i >= 0; --i) { | 821 for (var i = 0; i < this._allProperties.length; ++i) { |
760 var property = this._allProperties[i]; | 822 var property = this._allProperties[i]; |
761 if (property.styleBased || property.disabled) | 823 if (property.disabled || !property.parsedOk) { |
824 property._setActive(false); | |
762 continue; | 825 continue; |
763 property._setActive(false); | 826 } |
764 if (!property.parsedOk) | |
765 continue; | |
766 var canonicalName = WebInspector.CSSMetadata.canonicalPropertyName(p roperty.name); | 827 var canonicalName = WebInspector.CSSMetadata.canonicalPropertyName(p roperty.name); |
767 var activeProperty = activeProperties[canonicalName]; | 828 var activeProperty = activeProperties[canonicalName]; |
768 if (!activeProperty || (!activeProperty.important && property.import ant)) | 829 if (!activeProperty) { |
769 activeProperties[canonicalName] = property; | 830 activeProperties[canonicalName] = property; |
770 } | 831 } else if (!activeProperty.important || property.important) { |
771 for (var propertyName in activeProperties) { | 832 activeProperty._setActive(false); |
772 var property = activeProperties[propertyName]; | 833 activeProperties[canonicalName] = property; |
773 property._setActive(true); | 834 } else { |
835 property._setActive(false); | |
836 } | |
774 } | 837 } |
775 }, | 838 }, |
776 | 839 |
777 get allProperties() | 840 get allProperties() |
778 { | 841 { |
779 return this._allProperties; | 842 return this._allProperties; |
780 }, | 843 }, |
781 | 844 |
782 /** | 845 /** |
783 * @param {string} name | 846 * @param {string} name |
784 * @return {?WebInspector.CSSProperty} | |
785 */ | |
786 getLiveProperty: function(name) | |
787 { | |
788 return this._livePropertyMap[name] || null; | |
789 }, | |
790 | |
791 /** | |
792 * @param {string} name | |
793 * @return {string} | 847 * @return {string} |
794 */ | 848 */ |
795 getPropertyValue: function(name) | 849 getPropertyValue: function(name) |
796 { | 850 { |
797 var property = this._livePropertyMap[name]; | 851 var property = this._activePropertyMap.get(name); |
798 return property ? property.value : ""; | 852 return property ? property.value : ""; |
799 }, | 853 }, |
800 | 854 |
801 /** | 855 /** |
802 * @param {string} name | 856 * @param {string} name |
803 * @return {boolean} | 857 * @return {boolean} |
804 */ | 858 */ |
805 isPropertyImplicit: function(name) | 859 isPropertyImplicit: function(name) |
806 { | 860 { |
807 var property = this._livePropertyMap[name]; | 861 var property = this._activePropertyMap.get(name); |
808 return property ? property.implicit : ""; | 862 return property ? property.implicit : ""; |
809 }, | 863 }, |
810 | 864 |
811 /** | 865 /** |
812 * @param {string} name | 866 * @param {string} name |
813 * @return {!Array.<!WebInspector.CSSProperty>} | 867 * @return {!Array.<!WebInspector.CSSProperty>} |
814 */ | 868 */ |
815 longhandProperties: function(name) | 869 longhandProperties: function(name) |
816 { | 870 { |
817 var longhands = WebInspector.CSSMetadata.cssPropertiesMetainfo.longhands (name); | 871 var longhands = WebInspector.CSSMetadata.cssPropertiesMetainfo.longhands (name); |
818 var result = []; | 872 var result = []; |
819 for (var i = 0; longhands && i < longhands.length; ++i) { | 873 for (var i = 0; longhands && i < longhands.length; ++i) { |
820 var property = this._livePropertyMap[longhands[i]]; | 874 var property = this._activePropertyMap.get(longhands[i]); |
821 if (property) | 875 if (property) |
822 result.push(property); | 876 result.push(property); |
823 } | 877 } |
824 return result; | 878 return result; |
825 }, | 879 }, |
826 | 880 |
827 /** | 881 /** |
828 * @param {string} shorthandProperty | |
829 * @return {string} | |
830 */ | |
831 shorthandValue: function(shorthandProperty) | |
832 { | |
833 return this._shorthandValues.get(shorthandProperty) || ""; | |
834 }, | |
835 | |
836 /** | |
837 * @param {string} shorthandProperty | |
838 * @return {boolean} | |
839 */ | |
840 shorthandIsImportant: function(shorthandProperty) | |
841 { | |
842 return this._shorthandIsImportant.has(shorthandProperty); | |
843 }, | |
844 | |
845 /** | |
846 * @param {number} index | 882 * @param {number} index |
847 * @return {?WebInspector.CSSProperty} | 883 * @return {?WebInspector.CSSProperty} |
848 */ | 884 */ |
849 propertyAt: function(index) | 885 propertyAt: function(index) |
850 { | 886 { |
851 return (index < this.allProperties.length) ? this.allProperties[index] : null; | 887 return (index < this.allProperties.length) ? this.allProperties[index] : null; |
852 }, | 888 }, |
853 | 889 |
854 /** | 890 /** |
855 * @return {number} | 891 * @return {number} |
(...skipping 18 matching lines...) Expand all Loading... | |
874 }, | 910 }, |
875 | 911 |
876 /** | 912 /** |
877 * @param {number=} index | 913 * @param {number=} index |
878 * @return {!WebInspector.CSSProperty} | 914 * @return {!WebInspector.CSSProperty} |
879 */ | 915 */ |
880 newBlankProperty: function(index) | 916 newBlankProperty: function(index) |
881 { | 917 { |
882 index = (typeof index === "undefined") ? this.pastLastSourcePropertyInde x() : index; | 918 index = (typeof index === "undefined") ? this.pastLastSourcePropertyInde x() : index; |
883 var property = new WebInspector.CSSProperty(this, index, "", "", false, false, true, false, "", this._insertionRange(index)); | 919 var property = new WebInspector.CSSProperty(this, index, "", "", false, false, true, false, "", this._insertionRange(index)); |
884 property._setActive(true); | |
885 return property; | 920 return property; |
886 }, | 921 }, |
887 | 922 |
888 /** | 923 /** |
889 * @param {string} text | 924 * @param {string} text |
890 * @param {boolean} majorChange | 925 * @param {boolean} majorChange |
891 * @return {!Promise.<?WebInspector.CSSStyleDeclaration>} | 926 * @return {!Promise.<?WebInspector.CSSStyleDeclaration>} |
892 */ | 927 */ |
893 setText: function(text, majorChange) | 928 setText: function(text, majorChange) |
894 { | 929 { |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1149 */ | 1184 */ |
1150 WebInspector.CSSProperty = function(ownerStyle, index, name, value, important, d isabled, parsedOk, implicit, text, range) | 1185 WebInspector.CSSProperty = function(ownerStyle, index, name, value, important, d isabled, parsedOk, implicit, text, range) |
1151 { | 1186 { |
1152 this.ownerStyle = ownerStyle; | 1187 this.ownerStyle = ownerStyle; |
1153 this.index = index; | 1188 this.index = index; |
1154 this.name = name; | 1189 this.name = name; |
1155 this.value = value; | 1190 this.value = value; |
1156 this.important = important; | 1191 this.important = important; |
1157 this.disabled = disabled; | 1192 this.disabled = disabled; |
1158 this.parsedOk = parsedOk; | 1193 this.parsedOk = parsedOk; |
1159 this.implicit = implicit; | 1194 this.implicit = implicit; // A longhand, implicitly set by missing values of shorthand. |
1160 this.text = text; | 1195 this.text = text; |
1161 this.range = range ? WebInspector.TextRange.fromObject(range) : null; | 1196 this.range = range ? WebInspector.TextRange.fromObject(range) : null; |
1197 this._active = true; | |
pfeldman
2015/08/21 17:40:42
Why is active default?
lushnikov
2015/08/21 21:25:03
We set all properties active by default, and then
| |
1162 } | 1198 } |
1163 | 1199 |
1164 /** | 1200 /** |
1165 * @param {?WebInspector.CSSStyleDeclaration} ownerStyle | 1201 * @param {?WebInspector.CSSStyleDeclaration} ownerStyle |
1166 * @param {number} index | 1202 * @param {number} index |
1167 * @param {!CSSAgent.CSSProperty} payload | 1203 * @param {!CSSAgent.CSSProperty} payload |
1168 * @return {!WebInspector.CSSProperty} | 1204 * @return {!WebInspector.CSSProperty} |
1169 */ | 1205 */ |
1170 WebInspector.CSSProperty.parsePayload = function(ownerStyle, index, payload) | 1206 WebInspector.CSSProperty.parsePayload = function(ownerStyle, index, payload) |
1171 { | 1207 { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1204 get propertyText() | 1240 get propertyText() |
1205 { | 1241 { |
1206 if (this.text !== undefined) | 1242 if (this.text !== undefined) |
1207 return this.text; | 1243 return this.text; |
1208 | 1244 |
1209 if (this.name === "") | 1245 if (this.name === "") |
1210 return ""; | 1246 return ""; |
1211 return this.name + ": " + this.value + (this.important ? " !important" : "") + ";"; | 1247 return this.name + ": " + this.value + (this.important ? " !important" : "") + ";"; |
1212 }, | 1248 }, |
1213 | 1249 |
1214 get isLive() | 1250 /** |
1251 * @return {boolean} | |
1252 */ | |
1253 activeInStyle: function() | |
1215 { | 1254 { |
1216 return this.active || this.styleBased; | 1255 return this._active; |
1217 }, | |
1218 | |
1219 get active() | |
1220 { | |
1221 return typeof this._active === "boolean" && this._active; | |
1222 }, | |
1223 | |
1224 get styleBased() | |
1225 { | |
1226 return !this.range; | |
1227 }, | |
1228 | |
1229 get inactive() | |
1230 { | |
1231 return typeof this._active === "boolean" && !this._active; | |
1232 }, | 1256 }, |
1233 | 1257 |
1234 /** | 1258 /** |
1235 * @param {string} propertyText | 1259 * @param {string} propertyText |
1236 * @param {boolean} majorChange | 1260 * @param {boolean} majorChange |
1237 * @param {boolean} overwrite | 1261 * @param {boolean} overwrite |
1238 * @return {!Promise.<?WebInspector.CSSStyleDeclaration>} | 1262 * @return {!Promise.<?WebInspector.CSSStyleDeclaration>} |
1239 */ | 1263 */ |
1240 setText: function(propertyText, majorChange, overwrite) | 1264 setText: function(propertyText, majorChange, overwrite) |
1241 { | 1265 { |
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1964 * @constructor | 1988 * @constructor |
1965 * @param {?WebInspector.CSSStyleDeclaration} inlineStyle | 1989 * @param {?WebInspector.CSSStyleDeclaration} inlineStyle |
1966 * @param {?WebInspector.CSSStyleDeclaration} attributesStyle | 1990 * @param {?WebInspector.CSSStyleDeclaration} attributesStyle |
1967 */ | 1991 */ |
1968 WebInspector.CSSStyleModel.InlineStyleResult = function(inlineStyle, attributesS tyle) | 1992 WebInspector.CSSStyleModel.InlineStyleResult = function(inlineStyle, attributesS tyle) |
1969 { | 1993 { |
1970 this.inlineStyle = inlineStyle; | 1994 this.inlineStyle = inlineStyle; |
1971 this.attributesStyle = attributesStyle; | 1995 this.attributesStyle = attributesStyle; |
1972 } | 1996 } |
1973 | 1997 |
OLD | NEW |