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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/elements/StylesSidebarPane.js

Issue 1434613002: DevTools: kill WebInspector.StylesSectionModel class (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 5 years, 1 month 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2009 Joseph Pecoraro 3 * Copyright (C) 2009 Joseph Pecoraro
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 * @param {!WebInspector.DOMNode} node 327 * @param {!WebInspector.DOMNode} node
328 * @param {?WebInspector.CSSStyleModel.MatchedStyleResult} matchedStyles 328 * @param {?WebInspector.CSSStyleModel.MatchedStyleResult} matchedStyles
329 * @return {?{matched: !WebInspector.SectionCascade, pseudo: !Map.<numbe r, !WebInspector.SectionCascade>}} 329 * @return {?{matched: !WebInspector.SectionCascade, pseudo: !Map.<numbe r, !WebInspector.SectionCascade>}}
330 * @this {WebInspector.StylesSidebarPane} 330 * @this {WebInspector.StylesSidebarPane}
331 */ 331 */
332 function buildMatchedCascades(node, matchedStyles) 332 function buildMatchedCascades(node, matchedStyles)
333 { 333 {
334 if (!matchedStyles || node !== this.node()) 334 if (!matchedStyles || node !== this.node())
335 return null; 335 return null;
336 336
337 return { 337 return WebInspector.SectionCascade.fromMatchedStyles(matchedStyles);
338 matched: this._buildMatchedRulesSectionCascade(matchedStyles),
339 pseudo: this._buildPseudoCascades(matchedStyles)
340 };
341 } 338 }
342 }, 339 },
343 340
344 /** 341 /**
345 * @param {!WebInspector.DOMNode} node 342 * @param {!WebInspector.DOMNode} node
346 * @return {!Promise.<?WebInspector.CSSStyleModel.MatchedStyleResult>} 343 * @return {!Promise.<?WebInspector.CSSStyleModel.MatchedStyleResult>}
347 */ 344 */
348 _matchedStylesForNode: function(node) 345 _matchedStylesForNode: function(node)
349 { 346 {
350 var cssModel = this.cssModel(); 347 var cssModel = this.cssModel();
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 423
427 this._sectionBlocks = this._rebuildSectionsForMatchedStyleRules(cascades .matched); 424 this._sectionBlocks = this._rebuildSectionsForMatchedStyleRules(cascades .matched);
428 var pseudoTypes = []; 425 var pseudoTypes = [];
429 var keys = new Set(cascades.pseudo.keys()); 426 var keys = new Set(cascades.pseudo.keys());
430 if (keys.delete(DOMAgent.PseudoType.Before)) 427 if (keys.delete(DOMAgent.PseudoType.Before))
431 pseudoTypes.push(DOMAgent.PseudoType.Before); 428 pseudoTypes.push(DOMAgent.PseudoType.Before);
432 pseudoTypes = pseudoTypes.concat(keys.valuesArray().sort()); 429 pseudoTypes = pseudoTypes.concat(keys.valuesArray().sort());
433 for (var pseudoType of pseudoTypes) { 430 for (var pseudoType of pseudoTypes) {
434 var block = WebInspector.SectionBlock.createPseudoTypeBlock(pseudoTy pe); 431 var block = WebInspector.SectionBlock.createPseudoTypeBlock(pseudoTy pe);
435 var cascade = cascades.pseudo.get(pseudoType); 432 var cascade = cascades.pseudo.get(pseudoType);
436 for (var sectionModel of cascade.sectionModels()) { 433 for (var style of cascade.styles()) {
437 var section = new WebInspector.StylePropertiesSection(this, sect ionModel); 434 var section = new WebInspector.StylePropertiesSection(this, casc ade, style);
438 block.sections.push(section); 435 block.sections.push(section);
439 } 436 }
440 this._sectionBlocks.push(block); 437 this._sectionBlocks.push(block);
441 } 438 }
442 439
443 for (var block of this._sectionBlocks) { 440 for (var block of this._sectionBlocks) {
444 var titleElement = block.titleElement(); 441 var titleElement = block.titleElement();
445 if (titleElement) 442 if (titleElement)
446 this._sectionsContainer.appendChild(titleElement); 443 this._sectionsContainer.appendChild(titleElement);
447 for (var section of block.sections) 444 for (var section of block.sections)
448 this._sectionsContainer.appendChild(section.element); 445 this._sectionsContainer.appendChild(section.element);
449 } 446 }
450 447
451 if (this._filterRegex) 448 if (this._filterRegex)
452 this._updateFilter(); 449 this._updateFilter();
453 450
454 this._nodeStylesUpdatedForTest(node, true); 451 this._nodeStylesUpdatedForTest(node, true);
455 }, 452 },
456 453
457 /** 454 /**
458 * @param {!WebInspector.CSSStyleModel.MatchedStyleResult} matchedResult
459 * @return {!Map<number, !WebInspector.SectionCascade>}
460 */
461 _buildPseudoCascades: function(matchedResult)
462 {
463 var pseudoCascades = new Map();
464 var pseudoStyles = matchedResult.pseudoStyles();
465 for (var pseudoType of pseudoStyles.keys()) {
466 var styles = pseudoStyles.get(pseudoType);
467 // Add rules in reverse order to match the cascade order.
468 var pseudoElementCascade = new WebInspector.SectionCascade();
469 for (var i = 0; i < styles.length; ++i)
470 pseudoElementCascade.appendModelFromStyle(styles[i], "");
471 pseudoCascades.set(pseudoType, pseudoElementCascade);
472 }
473 return pseudoCascades;
474 },
475
476 /**
477 * @param {!WebInspector.DOMNode} node 455 * @param {!WebInspector.DOMNode} node
478 * @param {boolean} rebuild 456 * @param {boolean} rebuild
479 */ 457 */
480 _nodeStylesUpdatedForTest: function(node, rebuild) 458 _nodeStylesUpdatedForTest: function(node, rebuild)
481 { 459 {
482 // For sniffing in tests. 460 // For sniffing in tests.
483 }, 461 },
484 462
485 /** 463 /**
486 * @param {!WebInspector.CSSStyleModel.MatchedStyleResult} matchedResult
487 * @return {!WebInspector.SectionCascade}
488 */
489 _buildMatchedRulesSectionCascade: function(matchedResult)
490 {
491 var cascade = new WebInspector.SectionCascade();
492
493 var nodeStyles = matchedResult.nodeStyles();
494 for (var i = 0; i < nodeStyles.length; ++i) {
495 var style = nodeStyles[i];
496 var node = matchedResult.nodeForStyle(style);
497 var inherited = matchedResult.isInherited(style);
498 var customSelectorText = "";
499 if (style.type === WebInspector.CSSStyleDeclaration.Type.Inline)
500 customSelectorText = inherited ? WebInspector.UIString("Style At tribute") : "element.style";
501 else if (style.type === WebInspector.CSSStyleDeclaration.Type.Attrib utes)
502 customSelectorText = node.nodeNameInCorrectCase() + "[" + WebIns pector.UIString("Attributes Style") + "]";
503 cascade.appendModelFromStyle(style, customSelectorText, inherited ? node : null);
504 }
505 return cascade;
506 },
507
508 /**
509 * @param {!WebInspector.SectionCascade} matchedCascade 464 * @param {!WebInspector.SectionCascade} matchedCascade
510 * @return {!Array.<!WebInspector.SectionBlock>} 465 * @return {!Array.<!WebInspector.SectionBlock>}
511 */ 466 */
512 _rebuildSectionsForMatchedStyleRules: function(matchedCascade) 467 _rebuildSectionsForMatchedStyleRules: function(matchedCascade)
513 { 468 {
514 var blocks = [new WebInspector.SectionBlock(null)]; 469 var blocks = [new WebInspector.SectionBlock(null)];
515 var lastParentNode = null; 470 var lastParentNode = null;
516 for (var sectionModel of matchedCascade.sectionModels()) { 471 for (var style of matchedCascade.styles()) {
517 var parentNode = sectionModel.parentNode(); 472 var parentNode = matchedCascade.isInherited(style) ? matchedCascade. nodeForStyle(style) : null;
518 if (parentNode && parentNode !== lastParentNode) { 473 if (parentNode && parentNode !== lastParentNode) {
519 lastParentNode = parentNode; 474 lastParentNode = parentNode;
520 var block = WebInspector.SectionBlock.createInheritedNodeBlock(l astParentNode); 475 var block = WebInspector.SectionBlock.createInheritedNodeBlock(l astParentNode);
521 blocks.push(block); 476 blocks.push(block);
522 } 477 }
523 478
524 var section = new WebInspector.StylePropertiesSection(this, sectionM odel); 479 var section = new WebInspector.StylePropertiesSection(this, matchedC ascade, style);
525 blocks.peekLast().sections.push(section); 480 blocks.peekLast().sections.push(section);
526 } 481 }
527 return blocks; 482 return blocks;
528 }, 483 },
529 484
530 _createNewRuleInViaInspectorStyleSheet: function() 485 _createNewRuleInViaInspectorStyleSheet: function()
531 { 486 {
532 var cssModel = this.cssModel(); 487 var cssModel = this.cssModel();
533 var node = this.node(); 488 var node = this.node();
534 if (!cssModel || !node) 489 if (!cssModel || !node)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 526
572 /** 527 /**
573 * @param {!WebInspector.StylePropertiesSection} insertAfterSection 528 * @param {!WebInspector.StylePropertiesSection} insertAfterSection
574 * @param {string} styleSheetId 529 * @param {string} styleSheetId
575 * @param {!WebInspector.TextRange} ruleLocation 530 * @param {!WebInspector.TextRange} ruleLocation
576 */ 531 */
577 _addBlankSection: function(insertAfterSection, styleSheetId, ruleLocation) 532 _addBlankSection: function(insertAfterSection, styleSheetId, ruleLocation)
578 { 533 {
579 this.expand(); 534 this.expand();
580 var node = this.node(); 535 var node = this.node();
581 var blankSection = new WebInspector.BlankStylePropertiesSection(this, no de ? WebInspector.DOMPresentationUtils.simpleSelector(node) : "", styleSheetId, ruleLocation, insertAfterSection.styleRule); 536 var blankSection = new WebInspector.BlankStylePropertiesSection(this, in sertAfterSection._cascade, node ? WebInspector.DOMPresentationUtils.simpleSelect or(node) : "", styleSheetId, ruleLocation, insertAfterSection._style);
582 537
583 this._sectionsContainer.insertBefore(blankSection.element, insertAfterSe ction.element.nextSibling); 538 this._sectionsContainer.insertBefore(blankSection.element, insertAfterSe ction.element.nextSibling);
584 539
585 for (var block of this._sectionBlocks) { 540 for (var block of this._sectionBlocks) {
586 var index = block.sections.indexOf(insertAfterSection); 541 var index = block.sections.indexOf(insertAfterSection);
587 if (index === -1) 542 if (index === -1)
588 continue; 543 continue;
589 block.sections.splice(index + 1, 0, blankSection); 544 block.sections.splice(index + 1, 0, blankSection);
590 blankSection.startEditingSelector(); 545 blankSection.startEditingSelector();
591 } 546 }
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
793 */ 748 */
794 titleElement: function() 749 titleElement: function()
795 { 750 {
796 return this._titleElement; 751 return this._titleElement;
797 } 752 }
798 } 753 }
799 754
800 /** 755 /**
801 * @constructor 756 * @constructor
802 * @param {!WebInspector.StylesSidebarPane} parentPane 757 * @param {!WebInspector.StylesSidebarPane} parentPane
803 * @param {!WebInspector.StylesSectionModel} styleRule 758 * @param {!WebInspector.SectionCascade} cascade
759 * @param {!WebInspector.CSSStyleDeclaration} style
804 */ 760 */
805 WebInspector.StylePropertiesSection = function(parentPane, styleRule) 761 WebInspector.StylePropertiesSection = function(parentPane, cascade, style)
806 { 762 {
807 this._parentPane = parentPane; 763 this._parentPane = parentPane;
808 this.styleRule = styleRule; 764 this._style = style;
809 this.editable = styleRule.editable(); 765 this._cascade = cascade;
766 this.editable = !!(style.styleSheetId && style.range);
810 767
811 var rule = styleRule.rule(); 768 var rule = style.parentRule;
812 this.element = createElementWithClass("div", "styles-section matched-styles monospace"); 769 this.element = createElementWithClass("div", "styles-section matched-styles monospace");
813 this.element._section = this; 770 this.element._section = this;
814 771
815 this._titleElement = this.element.createChild("div", "styles-section-title " + (rule ? "styles-selector" : "")); 772 this._titleElement = this.element.createChild("div", "styles-section-title " + (rule ? "styles-selector" : ""));
816 773
817 this.propertiesTreeOutline = new TreeOutline(); 774 this.propertiesTreeOutline = new TreeOutline();
818 this.propertiesTreeOutline.element.classList.add("style-properties", "monosp ace"); 775 this.propertiesTreeOutline.element.classList.add("style-properties", "monosp ace");
819 this.propertiesTreeOutline.section = this; 776 this.propertiesTreeOutline.section = this;
820 this.element.appendChild(this.propertiesTreeOutline.element); 777 this.element.appendChild(this.propertiesTreeOutline.element);
821 778
822 var selectorContainer = createElement("div"); 779 var selectorContainer = createElement("div");
823 this._selectorElement = createElementWithClass("span", "selector"); 780 this._selectorElement = createElementWithClass("span", "selector");
824 this._selectorElement.textContent = styleRule.selectorText(); 781 this._selectorElement.textContent = this._selectorText();
825 selectorContainer.appendChild(this._selectorElement); 782 selectorContainer.appendChild(this._selectorElement);
826 selectorContainer.addEventListener("mouseenter", this._onMouseEnterSelector. bind(this), false); 783 selectorContainer.addEventListener("mouseenter", this._onMouseEnterSelector. bind(this), false);
827 selectorContainer.addEventListener("mouseleave", this._onMouseOutSelector.bi nd(this), false); 784 selectorContainer.addEventListener("mouseleave", this._onMouseOutSelector.bi nd(this), false);
828 785
829 var openBrace = createElement("span"); 786 var openBrace = createElement("span");
830 openBrace.textContent = " {"; 787 openBrace.textContent = " {";
831 selectorContainer.appendChild(openBrace); 788 selectorContainer.appendChild(openBrace);
832 selectorContainer.addEventListener("mousedown", this._handleEmptySpaceMouseD own.bind(this), false); 789 selectorContainer.addEventListener("mousedown", this._handleEmptySpaceMouseD own.bind(this), false);
833 selectorContainer.addEventListener("click", this._handleSelectorContainerCli ck.bind(this), false); 790 selectorContainer.addEventListener("click", this._handleSelectorContainerCli ck.bind(this), false);
834 791
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 this.element.classList.add("navigable"); 862 this.element.classList.add("navigable");
906 863
907 if (!this.editable) 864 if (!this.editable)
908 this.element.classList.add("read-only"); 865 this.element.classList.add("read-only");
909 866
910 this._markSelectorMatches(); 867 this._markSelectorMatches();
911 this.onpopulate(); 868 this.onpopulate();
912 } 869 }
913 870
914 WebInspector.StylePropertiesSection.prototype = { 871 WebInspector.StylePropertiesSection.prototype = {
872 /**
873 * @return {!WebInspector.CSSStyleDeclaration}
874 */
875 style: function()
876 {
877 return this._style;
878 },
879
880 /**
881 * @return {string}
882 */
883 _selectorText: function()
884 {
885 var node = this._cascade.nodeForStyle(this._style);
886 if (this._style.type === WebInspector.CSSStyleDeclaration.Type.Inline)
887 return this._cascade.isInherited(this._style) ? WebInspector.UIStrin g("Style Attribute") : "element.style";
888 if (this._style.type === WebInspector.CSSStyleDeclaration.Type.Attribute s)
889 return node.nodeNameInCorrectCase() + "[" + WebInspector.UIString("A ttributes Style") + "]";
890 return this._style.parentRule.selectorText();
891 },
892
915 _onMouseOutSelector: function() 893 _onMouseOutSelector: function()
916 { 894 {
917 if (this._hoverTimer) 895 if (this._hoverTimer)
918 clearTimeout(this._hoverTimer); 896 clearTimeout(this._hoverTimer);
919 WebInspector.DOMModel.hideDOMNodeHighlight() 897 WebInspector.DOMModel.hideDOMNodeHighlight()
920 }, 898 },
921 899
922 _onMouseEnterSelector: function() 900 _onMouseEnterSelector: function()
923 { 901 {
924 if (this._hoverTimer) 902 if (this._hoverTimer)
925 clearTimeout(this._hoverTimer); 903 clearTimeout(this._hoverTimer);
926 this._hoverTimer = setTimeout(this._highlight.bind(this), 300); 904 this._hoverTimer = setTimeout(this._highlight.bind(this), 300);
927 }, 905 },
928 906
929 _highlight: function() 907 _highlight: function()
930 { 908 {
931 WebInspector.DOMModel.hideDOMNodeHighlight() 909 WebInspector.DOMModel.hideDOMNodeHighlight()
932 var node = this._parentPane.node(); 910 var node = this._parentPane.node();
933 var domModel = node.domModel(); 911 var domModel = node.domModel();
934 var selectors = this.styleRule.rule()? this.styleRule.rule().selectorTex t() : undefined; 912 var selectors = this._style.parentRule ? this._style.parentRule.selector Text() : undefined;
935 domModel.highlightDOMNodeWithConfig(node.id, { mode: "all", showInfo: un defined, selectors: selectors }); 913 domModel.highlightDOMNodeWithConfig(node.id, { mode: "all", showInfo: un defined, selectors: selectors });
936 this._activeHighlightDOMModel = domModel; 914 this._activeHighlightDOMModel = domModel;
937 }, 915 },
938 916
939 /** 917 /**
940 * @return {?WebInspector.StylePropertiesSection} 918 * @return {?WebInspector.StylePropertiesSection}
941 */ 919 */
942 firstSibling: function() 920 firstSibling: function()
943 { 921 {
944 var parent = this.element.parentElement; 922 var parent = this.element.parentElement;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
994 { 972 {
995 var curElement = this.element; 973 var curElement = this.element;
996 do { 974 do {
997 curElement = curElement.previousSibling; 975 curElement = curElement.previousSibling;
998 } while (curElement && !curElement._section); 976 } while (curElement && !curElement._section);
999 977
1000 return curElement ? curElement._section : null; 978 return curElement ? curElement._section : null;
1001 }, 979 },
1002 980
1003 /** 981 /**
1004 * @return {?WebInspector.CSSRule}
1005 */
1006 rule: function()
1007 {
1008 return this.styleRule.rule();
1009 },
1010
1011 /**
1012 * @param {!WebInspector.Event} event 982 * @param {!WebInspector.Event} event
1013 */ 983 */
1014 _onNewRuleClick: function(event) 984 _onNewRuleClick: function(event)
1015 { 985 {
1016 event.consume(); 986 event.consume();
1017 var rule = this.rule(); 987 var rule = this._style.parentRule;
1018 var range = WebInspector.TextRange.createFromLocation(rule.style.range.e ndLine, rule.style.range.endColumn + 1); 988 var range = WebInspector.TextRange.createFromLocation(rule.style.range.e ndLine, rule.style.range.endColumn + 1);
1019 this._parentPane._addBlankSection(this, /** @type {string} */(rule.style SheetId), range); 989 this._parentPane._addBlankSection(this, /** @type {string} */(rule.style SheetId), range);
1020 }, 990 },
1021 991
1022 /** 992 /**
1023 * @param {!WebInspector.Event} event 993 * @param {!WebInspector.Event} event
1024 */ 994 */
1025 _onInsertColorPropertyClick: function(event) 995 _onInsertColorPropertyClick: function(event)
1026 { 996 {
1027 event.consume(true); 997 event.consume(true);
(...skipping 21 matching lines...) Expand all
1049 colorSwatch.showPopover(); 1019 colorSwatch.showPopover();
1050 }, 1020 },
1051 1021
1052 /** 1022 /**
1053 * @param {!WebInspector.CSSRule} editedRule 1023 * @param {!WebInspector.CSSRule} editedRule
1054 * @param {!WebInspector.TextRange} oldRange 1024 * @param {!WebInspector.TextRange} oldRange
1055 * @param {!WebInspector.TextRange} newRange 1025 * @param {!WebInspector.TextRange} newRange
1056 */ 1026 */
1057 _styleSheetRuleEdited: function(editedRule, oldRange, newRange) 1027 _styleSheetRuleEdited: function(editedRule, oldRange, newRange)
1058 { 1028 {
1059 var rule = this.rule(); 1029 var rule = this._style.parentRule;
1060 if (!rule || !rule.styleSheetId) 1030 if (!rule || !rule.styleSheetId)
1061 return; 1031 return;
1062 if (rule !== editedRule) 1032 if (rule !== editedRule)
1063 rule.sourceStyleSheetEdited(/** @type {string} */(editedRule.styleSh eetId), oldRange, newRange); 1033 rule.sourceStyleSheetEdited(/** @type {string} */(editedRule.styleSh eetId), oldRange, newRange);
1064 this._updateMediaList(); 1034 this._updateMediaList();
1065 this._updateRuleOrigin(); 1035 this._updateRuleOrigin();
1066 }, 1036 },
1067 1037
1068 /** 1038 /**
1069 * @param {!WebInspector.CSSMedia} oldMedia 1039 * @param {!WebInspector.CSSMedia} oldMedia
1070 * @param {!WebInspector.CSSMedia} newMedia 1040 * @param {!WebInspector.CSSMedia} newMedia
1071 */ 1041 */
1072 _styleSheetMediaEdited: function(oldMedia, newMedia) 1042 _styleSheetMediaEdited: function(oldMedia, newMedia)
1073 { 1043 {
1074 var rule = this.rule(); 1044 var rule = this._style.parentRule;
1075 if (!rule || !rule.styleSheetId) 1045 if (!rule || !rule.styleSheetId)
1076 return; 1046 return;
1077 rule.mediaEdited(oldMedia, newMedia); 1047 rule.mediaEdited(oldMedia, newMedia);
1078 this._updateMediaList(); 1048 this._updateMediaList();
1079 }, 1049 },
1080 1050
1081 /** 1051 /**
1082 * @param {?Array.<!WebInspector.CSSMedia>} mediaRules 1052 * @param {?Array.<!WebInspector.CSSMedia>} mediaRules
1083 */ 1053 */
1084 _createMediaList: function(mediaRules) 1054 _createMediaList: function(mediaRules)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1116 case WebInspector.CSSMedia.Source.IMPORT_RULE: 1086 case WebInspector.CSSMedia.Source.IMPORT_RULE:
1117 mediaTextElement.textContent = "@import " + media.text; 1087 mediaTextElement.textContent = "@import " + media.text;
1118 break; 1088 break;
1119 } 1089 }
1120 } 1090 }
1121 }, 1091 },
1122 1092
1123 _updateMediaList: function() 1093 _updateMediaList: function()
1124 { 1094 {
1125 this._mediaListElement.removeChildren(); 1095 this._mediaListElement.removeChildren();
1126 this._createMediaList(this.styleRule.media()); 1096 this._createMediaList(this._style.parentRule ? this._style.parentRule.me dia : null);
1127 }, 1097 },
1128 1098
1129 /** 1099 /**
1130 * @param {string} propertyName 1100 * @param {string} propertyName
1131 * @return {boolean} 1101 * @return {boolean}
1132 */ 1102 */
1133 isPropertyInherited: function(propertyName) 1103 isPropertyInherited: function(propertyName)
1134 { 1104 {
1135 if (this.styleRule.inherited()) { 1105 if (this._cascade.isInherited(this._style)) {
1136 // While rendering inherited stylesheet, reverse meaning of this pro perty. 1106 // While rendering inherited stylesheet, reverse meaning of this pro perty.
1137 // Render truly inherited properties with black, i.e. return them as non-inherited. 1107 // Render truly inherited properties with black, i.e. return them as non-inherited.
1138 return !WebInspector.CSSMetadata.isPropertyInherited(propertyName); 1108 return !WebInspector.CSSMetadata.isPropertyInherited(propertyName);
1139 } 1109 }
1140 return false; 1110 return false;
1141 }, 1111 },
1142 1112
1143 /** 1113 /**
1144 * @return {?WebInspector.StylePropertiesSection} 1114 * @return {?WebInspector.StylePropertiesSection}
1145 */ 1115 */
(...skipping 30 matching lines...) Expand all
1176 } 1146 }
1177 1147
1178 return (curSection && curSection.editable) ? curSection : null; 1148 return (curSection && curSection.editable) ? curSection : null;
1179 }, 1149 },
1180 1150
1181 /** 1151 /**
1182 * @param {boolean} full 1152 * @param {boolean} full
1183 */ 1153 */
1184 update: function(full) 1154 update: function(full)
1185 { 1155 {
1186 if (this.styleRule.selectorText()) 1156 this._selectorElement.textContent = this._selectorText();
1187 this._selectorElement.textContent = this.styleRule.selectorText();
1188 this._markSelectorMatches(); 1157 this._markSelectorMatches();
1189 if (full) { 1158 if (full) {
1190 this.propertiesTreeOutline.removeChildren(); 1159 this.propertiesTreeOutline.removeChildren();
1191 this.onpopulate(); 1160 this.onpopulate();
1192 } else { 1161 } else {
1193 var child = this.propertiesTreeOutline.firstChild(); 1162 var child = this.propertiesTreeOutline.firstChild();
1194 while (child) { 1163 while (child) {
1195 var overloaded = this.styleRule.cascade().propertyState(child.pr operty) === WebInspector.SectionCascade.PropertyState.Overloaded; 1164 var overloaded = this._cascade.propertyState(child.property) === WebInspector.SectionCascade.PropertyState.Overloaded;
1196 child.setOverloaded(overloaded); 1165 child.setOverloaded(overloaded);
1197 child = child.traverseNextTreeElement(false, null, true); 1166 child = child.traverseNextTreeElement(false, null, true);
1198 } 1167 }
1199 } 1168 }
1200 this.afterUpdate(); 1169 this.afterUpdate();
1201 }, 1170 },
1202 1171
1203 afterUpdate: function() 1172 afterUpdate: function()
1204 { 1173 {
1205 if (this._afterUpdate) { 1174 if (this._afterUpdate) {
1206 this._afterUpdate(this); 1175 this._afterUpdate(this);
1207 delete this._afterUpdate; 1176 delete this._afterUpdate;
1208 this._afterUpdateFinishedForTest(); 1177 this._afterUpdateFinishedForTest();
1209 } 1178 }
1210 }, 1179 },
1211 1180
1212 _afterUpdateFinishedForTest: function() 1181 _afterUpdateFinishedForTest: function()
1213 { 1182 {
1214 }, 1183 },
1215 1184
1216 onpopulate: function() 1185 onpopulate: function()
1217 { 1186 {
1218 var style = this.styleRule.style(); 1187 var style = this._style;
1219 for (var property of style.leadingProperties()) { 1188 for (var property of style.leadingProperties()) {
1220 var isShorthand = !!WebInspector.CSSMetadata.cssPropertiesMetainfo.l onghands(property.name); 1189 var isShorthand = !!WebInspector.CSSMetadata.cssPropertiesMetainfo.l onghands(property.name);
1221 var inherited = this.isPropertyInherited(property.name); 1190 var inherited = this.isPropertyInherited(property.name);
1222 var overloaded = this.styleRule.cascade().propertyState(property) == = WebInspector.SectionCascade.PropertyState.Overloaded; 1191 var overloaded = this._cascade.propertyState(property) === WebInspec tor.SectionCascade.PropertyState.Overloaded;
1223 var item = new WebInspector.StylePropertyTreeElement(this._parentPan e, this.styleRule, property, isShorthand, inherited, overloaded); 1192 var item = new WebInspector.StylePropertyTreeElement(this._parentPan e, this._cascade, property, isShorthand, inherited, overloaded);
1224 this.propertiesTreeOutline.appendChild(item); 1193 this.propertiesTreeOutline.appendChild(item);
1225 } 1194 }
1226 }, 1195 },
1227 1196
1228 /** 1197 /**
1229 * @return {boolean} 1198 * @return {boolean}
1230 */ 1199 */
1231 _updateFilter: function() 1200 _updateFilter: function()
1232 { 1201 {
1233 var hasMatchingChild = false; 1202 var hasMatchingChild = false;
1234 for (var child of this.propertiesTreeOutline.rootElement().children()) 1203 for (var child of this.propertiesTreeOutline.rootElement().children())
1235 hasMatchingChild |= child._updateFilter(); 1204 hasMatchingChild |= child._updateFilter();
1236 1205
1237 var regex = this._parentPane.filterRegex(); 1206 var regex = this._parentPane.filterRegex();
1238 var hideRule = !hasMatchingChild && regex && !regex.test(this.element.te xtContent); 1207 var hideRule = !hasMatchingChild && regex && !regex.test(this.element.te xtContent);
1239 this.element.classList.toggle("hidden", hideRule); 1208 this.element.classList.toggle("hidden", hideRule);
1240 if (!hideRule && this.styleRule.rule()) 1209 if (!hideRule && this._style.parentRule)
1241 this._markSelectorHighlights(); 1210 this._markSelectorHighlights();
1242 return !hideRule; 1211 return !hideRule;
1243 }, 1212 },
1244 1213
1245 _markSelectorMatches: function() 1214 _markSelectorMatches: function()
1246 { 1215 {
1247 var rule = this.styleRule.rule(); 1216 var rule = this._style.parentRule;
1248 if (!rule) 1217 if (!rule)
1249 return; 1218 return;
1250 1219
1251 this._mediaListElement.classList.toggle("media-matches", this.styleRule. mediaMatches()); 1220 this._mediaListElement.classList.toggle("media-matches", this._cascade.m ediaMatches(this._style));
1252 1221
1253 if (!this.styleRule.hasMatchingSelectors()) 1222 if (!this._cascade.hasMatchingSelectors(this._style))
1254 return; 1223 return;
1255 1224
1256 var selectors = rule.selectors; 1225 var selectors = rule.selectors;
1257 var fragment = createDocumentFragment(); 1226 var fragment = createDocumentFragment();
1258 var currentMatch = 0; 1227 var currentMatch = 0;
1259 var matchingSelectors = rule.matchingSelectors; 1228 var matchingSelectors = rule.matchingSelectors;
1260 for (var i = 0; i < selectors.length ; ++i) { 1229 for (var i = 0; i < selectors.length ; ++i) {
1261 if (i) 1230 if (i)
1262 fragment.createTextChild(", "); 1231 fragment.createTextChild(", ");
1263 var isSelectorMatching = matchingSelectors[currentMatch] === i; 1232 var isSelectorMatching = matchingSelectors[currentMatch] === i;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1310 event.consume(true); 1279 event.consume(true);
1311 } 1280 }
1312 }, 1281 },
1313 1282
1314 /** 1283 /**
1315 * @param {number=} index 1284 * @param {number=} index
1316 * @return {!WebInspector.StylePropertyTreeElement} 1285 * @return {!WebInspector.StylePropertyTreeElement}
1317 */ 1286 */
1318 addNewBlankProperty: function(index) 1287 addNewBlankProperty: function(index)
1319 { 1288 {
1320 var property = this.styleRule.style().newBlankProperty(index); 1289 var property = this._style.newBlankProperty(index);
1321 var item = new WebInspector.StylePropertyTreeElement(this._parentPane, t his.styleRule, property, false, false, false); 1290 var item = new WebInspector.StylePropertyTreeElement(this._parentPane, t his._cascade, property, false, false, false);
1322 index = property.index; 1291 index = property.index;
1323 this.propertiesTreeOutline.insertChild(item, index); 1292 this.propertiesTreeOutline.insertChild(item, index);
1324 item.listItemElement.textContent = ""; 1293 item.listItemElement.textContent = "";
1325 item._newProperty = true; 1294 item._newProperty = true;
1326 item.updateTitle(); 1295 item.updateTitle();
1327 return item; 1296 return item;
1328 }, 1297 },
1329 1298
1330 _handleEmptySpaceMouseDown: function() 1299 _handleEmptySpaceMouseDown: function()
1331 { 1300 {
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
1448 _editingMediaTextCommittedForTest: function() { }, 1417 _editingMediaTextCommittedForTest: function() { },
1449 1418
1450 /** 1419 /**
1451 * @param {!Event} event 1420 * @param {!Event} event
1452 */ 1421 */
1453 _handleSelectorClick: function(event) 1422 _handleSelectorClick: function(event)
1454 { 1423 {
1455 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(/** @type {!MouseEv ent} */(event)) && this.navigable && event.target.classList.contains("simple-sel ector")) { 1424 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(/** @type {!MouseEv ent} */(event)) && this.navigable && event.target.classList.contains("simple-sel ector")) {
1456 var index = event.target._selectorIndex; 1425 var index = event.target._selectorIndex;
1457 var cssModel = this._parentPane._cssModel; 1426 var cssModel = this._parentPane._cssModel;
1458 var rule = this.rule(); 1427 var rule = this._style.parentRule;
1459 var rawLocation = new WebInspector.CSSLocation(cssModel, /** @type { string} */(rule.styleSheetId), rule.sourceURL, rule.lineNumberInSource(index), r ule.columnNumberInSource(index)); 1428 var rawLocation = new WebInspector.CSSLocation(cssModel, /** @type { string} */(rule.styleSheetId), rule.sourceURL, rule.lineNumberInSource(index), r ule.columnNumberInSource(index));
1460 var uiLocation = WebInspector.cssWorkspaceBinding.rawLocationToUILoc ation(rawLocation); 1429 var uiLocation = WebInspector.cssWorkspaceBinding.rawLocationToUILoc ation(rawLocation);
1461 if (uiLocation) 1430 if (uiLocation)
1462 WebInspector.Revealer.reveal(uiLocation); 1431 WebInspector.Revealer.reveal(uiLocation);
1463 event.consume(true); 1432 event.consume(true);
1464 return; 1433 return;
1465 } 1434 }
1466 this._startEditingOnMouseEvent(); 1435 this._startEditingOnMouseEvent();
1467 event.consume(true); 1436 event.consume(true);
1468 }, 1437 },
1469 1438
1470 _startEditingOnMouseEvent: function() 1439 _startEditingOnMouseEvent: function()
1471 { 1440 {
1472 if (!this.editable) 1441 if (!this.editable)
1473 return; 1442 return;
1474 1443
1475 if (!this.rule() && !this.propertiesTreeOutline.rootElement().childCount ()) { 1444 var rule = this._style.parentRule;
1445 if (!rule && !this.propertiesTreeOutline.rootElement().childCount()) {
1476 this.addNewBlankProperty().startEditing(); 1446 this.addNewBlankProperty().startEditing();
1477 return; 1447 return;
1478 } 1448 }
1479 1449
1480 if (!this.rule()) 1450 if (!rule)
1481 return; 1451 return;
1482 1452
1483 this.startEditingSelector(); 1453 this.startEditingSelector();
1484 }, 1454 },
1485 1455
1486 startEditingSelector: function() 1456 startEditingSelector: function()
1487 { 1457 {
1488 var element = this._selectorElement; 1458 var element = this._selectorElement;
1489 if (WebInspector.isBeingEdited(element)) 1459 if (WebInspector.isBeingEdited(element))
1490 return; 1460 return;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1563 { 1533 {
1564 this._editingSelectorEnded(); 1534 this._editingSelectorEnded();
1565 if (newContent) 1535 if (newContent)
1566 newContent = newContent.trim(); 1536 newContent = newContent.trim();
1567 if (newContent === oldContent) { 1537 if (newContent === oldContent) {
1568 // Revert to a trimmed version of the selector if need be. 1538 // Revert to a trimmed version of the selector if need be.
1569 this._selectorElement.textContent = newContent; 1539 this._selectorElement.textContent = newContent;
1570 this._moveEditorFromSelector(moveDirection); 1540 this._moveEditorFromSelector(moveDirection);
1571 return; 1541 return;
1572 } 1542 }
1573 var rule = this.rule(); 1543 var rule = this._style.parentRule;
1574 var oldSelectorRange = rule.selectorRange(); 1544 var oldSelectorRange = rule.selectorRange();
1575 if (!rule || !oldSelectorRange) 1545 if (!rule || !oldSelectorRange)
1576 return; 1546 return;
1577 1547
1578 /** 1548 /**
1579 * @param {!WebInspector.CSSRule} rule 1549 * @param {!WebInspector.CSSRule} rule
1580 * @param {!WebInspector.TextRange} oldSelectorRange 1550 * @param {!WebInspector.TextRange} oldSelectorRange
1581 * @param {boolean} success 1551 * @param {boolean} success
1582 * @this {WebInspector.StylePropertiesSection} 1552 * @this {WebInspector.StylePropertiesSection}
1583 */ 1553 */
1584 function finishCallback(rule, oldSelectorRange, success) 1554 function finishCallback(rule, oldSelectorRange, success)
1585 { 1555 {
1586 if (success) { 1556 if (success) {
1587 var doesAffectSelectedNode = rule.matchingSelectors.length > 0; 1557 var doesAffectSelectedNode = rule.matchingSelectors.length > 0;
1588 this.element.classList.toggle("no-affect", !doesAffectSelectedNo de); 1558 this.element.classList.toggle("no-affect", !doesAffectSelectedNo de);
1589 1559
1590 this.styleRule.resetCachedData(); 1560 this._cascade.resetActiveProperties();
1591 var newSelectorRange = /** @type {!WebInspector.TextRange} */(ru le.selectorRange()); 1561 var newSelectorRange = /** @type {!WebInspector.TextRange} */(ru le.selectorRange());
1592 rule.style.sourceStyleSheetEdited(/** @type {string} */(rule.sty leSheetId), oldSelectorRange, newSelectorRange); 1562 rule.style.sourceStyleSheetEdited(/** @type {string} */(rule.sty leSheetId), oldSelectorRange, newSelectorRange);
1593 this._parentPane._styleSheetRuleEdited(rule, oldSelectorRange, n ewSelectorRange); 1563 this._parentPane._styleSheetRuleEdited(rule, oldSelectorRange, n ewSelectorRange);
1594 this._parentPane._refreshUpdate(this); 1564 this._parentPane._refreshUpdate(this);
1595 } 1565 }
1596 1566
1597 delete this._parentPane._userOperation; 1567 delete this._parentPane._userOperation;
1598 this._moveEditorFromSelector(moveDirection); 1568 this._moveEditorFromSelector(moveDirection);
1599 this._editingSelectorCommittedForTest(); 1569 this._editingSelectorCommittedForTest();
1600 } 1570 }
1601 1571
1602 // This gets deleted in finishOperationAndMoveEditor(), which is called both on success and failure. 1572 // This gets deleted in finishOperationAndMoveEditor(), which is called both on success and failure.
1603 this._parentPane._userOperation = true; 1573 this._parentPane._userOperation = true;
1604 var selectedNode = this._parentPane.node(); 1574 var selectedNode = this._parentPane.node();
1605 rule.setSelectorText(selectedNode ? selectedNode.id : 0, newContent, fin ishCallback.bind(this, rule, oldSelectorRange)); 1575 rule.setSelectorText(selectedNode ? selectedNode.id : 0, newContent, fin ishCallback.bind(this, rule, oldSelectorRange));
1606 }, 1576 },
1607 1577
1608 _editingSelectorCommittedForTest: function() { }, 1578 _editingSelectorCommittedForTest: function() { },
1609 1579
1610 _updateRuleOrigin: function() 1580 _updateRuleOrigin: function()
1611 { 1581 {
1612 this._selectorRefElement.removeChildren(); 1582 this._selectorRefElement.removeChildren();
1613 this._selectorRefElement.appendChild(WebInspector.StylePropertiesSection .createRuleOriginNode(this._parentPane._cssModel, this._parentPane._linkifier, t his.rule())); 1583 this._selectorRefElement.appendChild(WebInspector.StylePropertiesSection .createRuleOriginNode(this._parentPane._cssModel, this._parentPane._linkifier, t his._style.parentRule));
1614 }, 1584 },
1615 1585
1616 _editingSelectorEnded: function() 1586 _editingSelectorEnded: function()
1617 { 1587 {
1618 this._parentPane.setEditingStyle(false); 1588 this._parentPane.setEditingStyle(false);
1619 this._parentPane._finishEditingSelector(); 1589 this._parentPane._finishEditingSelector();
1620 }, 1590 },
1621 1591
1622 editingSelectorCancelled: function() 1592 editingSelectorCancelled: function()
1623 { 1593 {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1677 var lineNumber = styleSheetHeader.lineNumberInSource(ruleLocation.startLine) ; 1647 var lineNumber = styleSheetHeader.lineNumberInSource(ruleLocation.startLine) ;
1678 var columnNumber = styleSheetHeader.columnNumberInSource(ruleLocation.startL ine, ruleLocation.startColumn); 1648 var columnNumber = styleSheetHeader.columnNumberInSource(ruleLocation.startL ine, ruleLocation.startColumn);
1679 var matchingSelectorLocation = new WebInspector.CSSLocation(cssModel, styleS heetId, sourceURL, lineNumber, columnNumber); 1649 var matchingSelectorLocation = new WebInspector.CSSLocation(cssModel, styleS heetId, sourceURL, lineNumber, columnNumber);
1680 return linkifier.linkifyCSSLocation(matchingSelectorLocation); 1650 return linkifier.linkifyCSSLocation(matchingSelectorLocation);
1681 } 1651 }
1682 1652
1683 /** 1653 /**
1684 * @constructor 1654 * @constructor
1685 * @extends {WebInspector.StylePropertiesSection} 1655 * @extends {WebInspector.StylePropertiesSection}
1686 * @param {!WebInspector.StylesSidebarPane} stylesPane 1656 * @param {!WebInspector.StylesSidebarPane} stylesPane
1657 * @param {!WebInspector.SectionCascade} cascade
1687 * @param {string} defaultSelectorText 1658 * @param {string} defaultSelectorText
1688 * @param {string} styleSheetId 1659 * @param {string} styleSheetId
1689 * @param {!WebInspector.TextRange} ruleLocation 1660 * @param {!WebInspector.TextRange} ruleLocation
1690 * @param {!WebInspector.StylesSectionModel} insertAfterStyleRule 1661 * @param {!WebInspector.CSSStyleDeclaration} insertAfterStyle
1691 */ 1662 */
1692 WebInspector.BlankStylePropertiesSection = function(stylesPane, defaultSelectorT ext, styleSheetId, ruleLocation, insertAfterStyleRule) 1663 WebInspector.BlankStylePropertiesSection = function(stylesPane, cascade, default SelectorText, styleSheetId, ruleLocation, insertAfterStyle)
1693 { 1664 {
1694 var dummyCascade = new WebInspector.SectionCascade(); 1665 var rule = WebInspector.CSSRule.createDummyRule(stylesPane._cssModel, defaul tSelectorText);
1695 var blankSectionModel = dummyCascade.appendModelFromStyle(WebInspector.CSSSt yleDeclaration.createDummyStyle(stylesPane._cssModel), defaultSelectorText); 1666 WebInspector.StylePropertiesSection.call(this, stylesPane, cascade, rule.sty le);
1696 blankSectionModel.setEditable(true);
1697 WebInspector.StylePropertiesSection.call(this, stylesPane, blankSectionModel );
1698 this._ruleLocation = ruleLocation; 1667 this._ruleLocation = ruleLocation;
1699 this._styleSheetId = styleSheetId; 1668 this._styleSheetId = styleSheetId;
1700 this._selectorRefElement.removeChildren(); 1669 this._selectorRefElement.removeChildren();
1701 this._selectorRefElement.appendChild(WebInspector.StylePropertiesSection._li nkifyRuleLocation(this._parentPane._cssModel, this._parentPane._linkifier, style SheetId, this._actualRuleLocation())); 1670 this._selectorRefElement.appendChild(WebInspector.StylePropertiesSection._li nkifyRuleLocation(this._parentPane._cssModel, this._parentPane._linkifier, style SheetId, this._actualRuleLocation()));
1702 if (insertAfterStyleRule) 1671 if (insertAfterStyle && insertAfterStyle.parentRule)
1703 this._createMediaList(insertAfterStyleRule.media()); 1672 this._createMediaList(insertAfterStyle.parentRule.media);
1704 this._insertAfterStyleRule = insertAfterStyleRule; 1673 this._insertAfterStyle = insertAfterStyle;
1705 this.element.classList.add("blank-section"); 1674 this.element.classList.add("blank-section");
1706 } 1675 }
1707 1676
1708 WebInspector.BlankStylePropertiesSection.prototype = { 1677 WebInspector.BlankStylePropertiesSection.prototype = {
1709 /** 1678 /**
1710 * @return {!WebInspector.TextRange} 1679 * @return {!WebInspector.TextRange}
1711 */ 1680 */
1712 _actualRuleLocation: function() 1681 _actualRuleLocation: function()
1713 { 1682 {
1714 var prefix = this._rulePrefix(); 1683 var prefix = this._rulePrefix();
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1802 this._editingSelectorEnded(); 1771 this._editingSelectorEnded();
1803 this._parentPane.removeSection(this); 1772 this._parentPane.removeSection(this);
1804 }, 1773 },
1805 1774
1806 /** 1775 /**
1807 * @param {!WebInspector.CSSRule} newRule 1776 * @param {!WebInspector.CSSRule} newRule
1808 */ 1777 */
1809 _makeNormal: function(newRule) 1778 _makeNormal: function(newRule)
1810 { 1779 {
1811 this.element.classList.remove("blank-section"); 1780 this.element.classList.remove("blank-section");
1812 var model = this._insertAfterStyleRule.cascade().insertModelFromRule(new Rule, this._insertAfterStyleRule); 1781 this._cascade.insertStyle(newRule.style, this._insertAfterStyle);
1813 this.styleRule = model; 1782 this._style = newRule.style;
1814 1783
1815 // FIXME: replace this instance by a normal WebInspector.StyleProperties Section. 1784 // FIXME: replace this instance by a normal WebInspector.StyleProperties Section.
1816 this._normal = true; 1785 this._normal = true;
1817 }, 1786 },
1818 1787
1819 __proto__: WebInspector.StylePropertiesSection.prototype 1788 __proto__: WebInspector.StylePropertiesSection.prototype
1820 } 1789 }
1821 1790
1822 /** 1791 /**
1823 * @constructor 1792 * @constructor
1824 * @extends {TreeElement} 1793 * @extends {TreeElement}
1825 * @param {!WebInspector.StylesSidebarPane} stylesPane 1794 * @param {!WebInspector.StylesSidebarPane} stylesPane
1826 * @param {!WebInspector.StylesSectionModel} styleRule 1795 * @param {!WebInspector.SectionCascade} cascade
1827 * @param {!WebInspector.CSSProperty} property 1796 * @param {!WebInspector.CSSProperty} property
1828 * @param {boolean} isShorthand 1797 * @param {boolean} isShorthand
1829 * @param {boolean} inherited 1798 * @param {boolean} inherited
1830 * @param {boolean} overloaded 1799 * @param {boolean} overloaded
1831 */ 1800 */
1832 WebInspector.StylePropertyTreeElement = function(stylesPane, styleRule, property , isShorthand, inherited, overloaded) 1801 WebInspector.StylePropertyTreeElement = function(stylesPane, cascade, property, isShorthand, inherited, overloaded)
1833 { 1802 {
1834 // Pass an empty title, the title gets made later in onattach. 1803 // Pass an empty title, the title gets made later in onattach.
1835 TreeElement.call(this, "", isShorthand); 1804 TreeElement.call(this, "", isShorthand);
1836 this._styleRule = styleRule; 1805 this._style = property.ownerStyle;
1806 this._cascade = cascade;
1837 this.property = property; 1807 this.property = property;
1838 this._inherited = inherited; 1808 this._inherited = inherited;
1839 this._overloaded = overloaded; 1809 this._overloaded = overloaded;
1840 this.selectable = false; 1810 this.selectable = false;
1841 this._parentPane = stylesPane; 1811 this._parentPane = stylesPane;
1842 this.isShorthand = isShorthand; 1812 this.isShorthand = isShorthand;
1843 this._applyStyleThrottler = new WebInspector.Throttler(0); 1813 this._applyStyleThrottler = new WebInspector.Throttler(0);
1844 } 1814 }
1845 1815
1846 /** @typedef {{expanded: boolean, hasChildren: boolean, isEditingName: boolean, previousContent: string}} */ 1816 /** @typedef {{expanded: boolean, hasChildren: boolean, isEditingName: boolean, previousContent: string}} */
1847 WebInspector.StylePropertyTreeElement.Context; 1817 WebInspector.StylePropertyTreeElement.Context;
1848 1818
1849 WebInspector.StylePropertyTreeElement.prototype = { 1819 WebInspector.StylePropertyTreeElement.prototype = {
1850 /** 1820 /**
1851 * @return {!WebInspector.CSSStyleDeclaration} 1821 * @return {boolean}
1852 */ 1822 */
1853 style: function() 1823 _editable: function()
1854 { 1824 {
1855 return this._styleRule.style(); 1825 return this._style.styleSheetId && this._style.range;
1856 }, 1826 },
1857 1827
1858 /** 1828 /**
1859 * @return {boolean} 1829 * @return {boolean}
1860 */ 1830 */
1861 inherited: function() 1831 inherited: function()
1862 { 1832 {
1863 return this._inherited; 1833 return this._inherited;
1864 }, 1834 },
1865 1835
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1924 * @param {string} text 1894 * @param {string} text
1925 * @return {!Node} 1895 * @return {!Node}
1926 */ 1896 */
1927 _processColor: function(text) 1897 _processColor: function(text)
1928 { 1898 {
1929 // We can be called with valid non-color values of |text| (like 'none' f rom border style) 1899 // We can be called with valid non-color values of |text| (like 'none' f rom border style)
1930 var color = WebInspector.Color.parse(text); 1900 var color = WebInspector.Color.parse(text);
1931 if (!color) 1901 if (!color)
1932 return createTextNode(text); 1902 return createTextNode(text);
1933 1903
1934 if (!this._styleRule.editable()) { 1904 if (!this._editable()) {
1935 var swatch = WebInspector.ColorSwatch.create(); 1905 var swatch = WebInspector.ColorSwatch.create();
1936 swatch.setColorText(text); 1906 swatch.setColorText(text);
1937 return swatch; 1907 return swatch;
1938 } 1908 }
1939 1909
1940 var stylesPopoverHelper = this._parentPane._stylesPopoverHelper; 1910 var stylesPopoverHelper = this._parentPane._stylesPopoverHelper;
1941 var swatchIcon = new WebInspector.ColorSwatchPopoverIcon(this, stylesPop overHelper, text); 1911 var swatchIcon = new WebInspector.ColorSwatchPopoverIcon(this, stylesPop overHelper, text);
1942 1912
1943 /** 1913 /**
1944 * @param {?Map.<string, string>} styles 1914 * @param {?Map.<string, string>} styles
(...skipping 26 matching lines...) Expand all
1971 return this.nameElement.textContent + ": " + this.valueElement.textConte nt; 1941 return this.nameElement.textContent + ": " + this.valueElement.textConte nt;
1972 }, 1942 },
1973 1943
1974 /** 1944 /**
1975 * @param {string} text 1945 * @param {string} text
1976 * @return {!Node} 1946 * @return {!Node}
1977 */ 1947 */
1978 _processBezier: function(text) 1948 _processBezier: function(text)
1979 { 1949 {
1980 var geometry = WebInspector.Geometry.CubicBezier.parse(text); 1950 var geometry = WebInspector.Geometry.CubicBezier.parse(text);
1981 if (!geometry || !this._styleRule.editable()) 1951 if (!geometry || !this._editable())
1982 return createTextNode(text); 1952 return createTextNode(text);
1983 var stylesPopoverHelper = this._parentPane._stylesPopoverHelper; 1953 var stylesPopoverHelper = this._parentPane._stylesPopoverHelper;
1984 return new WebInspector.BezierPopoverIcon(this, stylesPopoverHelper, tex t).element(); 1954 return new WebInspector.BezierPopoverIcon(this, stylesPopoverHelper, tex t).element();
1985 }, 1955 },
1986 1956
1987 _updateState: function() 1957 _updateState: function()
1988 { 1958 {
1989 if (!this.listItemElement) 1959 if (!this.listItemElement)
1990 return; 1960 return;
1991 1961
1992 if (this.style().isPropertyImplicit(this.name)) 1962 if (this._style.isPropertyImplicit(this.name))
1993 this.listItemElement.classList.add("implicit"); 1963 this.listItemElement.classList.add("implicit");
1994 else 1964 else
1995 this.listItemElement.classList.remove("implicit"); 1965 this.listItemElement.classList.remove("implicit");
1996 1966
1997 var hasIgnorableError = !this.property.parsedOk && WebInspector.StylesSi debarPane.ignoreErrorsForProperty(this.property); 1967 var hasIgnorableError = !this.property.parsedOk && WebInspector.StylesSi debarPane.ignoreErrorsForProperty(this.property);
1998 if (hasIgnorableError) 1968 if (hasIgnorableError)
1999 this.listItemElement.classList.add("has-ignorable-error"); 1969 this.listItemElement.classList.add("has-ignorable-error");
2000 else 1970 else
2001 this.listItemElement.classList.remove("has-ignorable-error"); 1971 this.listItemElement.classList.remove("has-ignorable-error");
2002 1972
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
2045 var section = this.section(); 2015 var section = this.section();
2046 if (section && section._parentPane) 2016 if (section && section._parentPane)
2047 section._parentPane._refreshUpdate(section); 2017 section._parentPane._refreshUpdate(section);
2048 }, 2018 },
2049 2019
2050 /** 2020 /**
2051 * @param {!WebInspector.TextRange} oldStyleRange 2021 * @param {!WebInspector.TextRange} oldStyleRange
2052 */ 2022 */
2053 _styleTextEdited: function(oldStyleRange) 2023 _styleTextEdited: function(oldStyleRange)
2054 { 2024 {
2055 var newStyleRange = /** @type {!WebInspector.TextRange} */ (this.style() .range); 2025 var newStyleRange = /** @type {!WebInspector.TextRange} */ (this._style. range);
2056 this._styleRule.resetCachedData(); 2026 this._cascade.resetActiveProperties();
2057 if (this._styleRule.rule()) 2027 if (this._style.parentRule)
2058 this._parentPane._styleSheetRuleEdited(/** @type {!WebInspector.CSSR ule} */(this._styleRule.rule()), oldStyleRange, newStyleRange); 2028 this._parentPane._styleSheetRuleEdited(this._style.parentRule, oldSt yleRange, newStyleRange);
2059 }, 2029 },
2060 2030
2061 /** 2031 /**
2062 * @param {!Event} event 2032 * @param {!Event} event
2063 */ 2033 */
2064 _toggleEnabled: function(event) 2034 _toggleEnabled: function(event)
2065 { 2035 {
2066 var disabled = !event.target.checked; 2036 var disabled = !event.target.checked;
2067 var oldStyleRange = this.style().range; 2037 var oldStyleRange = this._style.range;
2068 if (!oldStyleRange) 2038 if (!oldStyleRange)
2069 return; 2039 return;
2070 2040
2071 /** 2041 /**
2072 * @param {boolean} success 2042 * @param {boolean} success
2073 * @this {WebInspector.StylePropertyTreeElement} 2043 * @this {WebInspector.StylePropertyTreeElement}
2074 */ 2044 */
2075 function callback(success) 2045 function callback(success)
2076 { 2046 {
2077 delete this._parentPane._userOperation; 2047 delete this._parentPane._userOperation;
(...skipping 13 matching lines...) Expand all
2091 2061
2092 /** 2062 /**
2093 * @override 2063 * @override
2094 */ 2064 */
2095 onpopulate: function() 2065 onpopulate: function()
2096 { 2066 {
2097 // Only populate once and if this property is a shorthand. 2067 // Only populate once and if this property is a shorthand.
2098 if (this.childCount() || !this.isShorthand) 2068 if (this.childCount() || !this.isShorthand)
2099 return; 2069 return;
2100 2070
2101 var longhandProperties = this.style().longhandProperties(this.name); 2071 var longhandProperties = this._style.longhandProperties(this.name);
2102 for (var i = 0; i < longhandProperties.length; ++i) { 2072 for (var i = 0; i < longhandProperties.length; ++i) {
2103 var name = longhandProperties[i].name; 2073 var name = longhandProperties[i].name;
2104 var inherited = false; 2074 var inherited = false;
2105 var overloaded = false; 2075 var overloaded = false;
2106 2076
2107 var section = this.section(); 2077 var section = this.section();
2108 if (section) { 2078 if (section) {
2109 inherited = section.isPropertyInherited(name); 2079 inherited = section.isPropertyInherited(name);
2110 overloaded = section.styleRule.cascade().propertyState(longhandP roperties[i]) === WebInspector.SectionCascade.PropertyState.Overloaded; 2080 overloaded = this._cascade.propertyState(longhandProperties[i]) === WebInspector.SectionCascade.PropertyState.Overloaded;
2111 } 2081 }
2112 2082
2113 var item = new WebInspector.StylePropertyTreeElement(this._parentPan e, this._styleRule, longhandProperties[i], false, inherited, overloaded); 2083 var item = new WebInspector.StylePropertyTreeElement(this._parentPan e, this._cascade, longhandProperties[i], false, inherited, overloaded);
2114 this.appendChild(item); 2084 this.appendChild(item);
2115 } 2085 }
2116 }, 2086 },
2117 2087
2118 /** 2088 /**
2119 * @override 2089 * @override
2120 */ 2090 */
2121 onattach: function() 2091 onattach: function()
2122 { 2092 {
2123 this.updateTitle(); 2093 this.updateTitle();
(...skipping 23 matching lines...) Expand all
2147 delete this._parentPane._mouseDownTreeElementIsValue; 2117 delete this._parentPane._mouseDownTreeElementIsValue;
2148 } 2118 }
2149 }, 2119 },
2150 2120
2151 updateTitle: function() 2121 updateTitle: function()
2152 { 2122 {
2153 this._updateState(); 2123 this._updateState();
2154 this._expandElement = createElement("span"); 2124 this._expandElement = createElement("span");
2155 this._expandElement.className = "expand-element"; 2125 this._expandElement.className = "expand-element";
2156 2126
2157 var propertyRenderer = new WebInspector.StylesSidebarPropertyRenderer(th is._styleRule.rule(), this.node(), this.name, this.value); 2127 var propertyRenderer = new WebInspector.StylesSidebarPropertyRenderer(th is._style.parentRule, this.node(), this.name, this.value);
2158 if (this.property.parsedOk) { 2128 if (this.property.parsedOk) {
2159 propertyRenderer.setColorHandler(this._processColor.bind(this)); 2129 propertyRenderer.setColorHandler(this._processColor.bind(this));
2160 propertyRenderer.setBezierHandler(this._processBezier.bind(this)); 2130 propertyRenderer.setBezierHandler(this._processBezier.bind(this));
2161 } 2131 }
2162 2132
2163 this.listItemElement.removeChildren(); 2133 this.listItemElement.removeChildren();
2164 this.nameElement = propertyRenderer.renderName(); 2134 this.nameElement = propertyRenderer.renderName();
2165 this.valueElement = propertyRenderer.renderValue(); 2135 this.valueElement = propertyRenderer.renderValue();
2166 if (!this.treeOutline) 2136 if (!this.treeOutline)
2167 return; 2137 return;
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
2636 return; 2606 return;
2637 2607
2638 section.addNewBlankProperty().startEditing(); 2608 section.addNewBlankProperty().startEditing();
2639 return; 2609 return;
2640 } 2610 }
2641 2611
2642 if (abandonNewProperty) { 2612 if (abandonNewProperty) {
2643 moveTo = this._findSibling(moveDirection); 2613 moveTo = this._findSibling(moveDirection);
2644 var sectionToEdit = (moveTo || moveDirection === "backward") ? s ection : section.nextEditableSibling(); 2614 var sectionToEdit = (moveTo || moveDirection === "backward") ? s ection : section.nextEditableSibling();
2645 if (sectionToEdit) { 2615 if (sectionToEdit) {
2646 if (sectionToEdit.rule()) 2616 if (sectionToEdit.style().parentRule)
2647 sectionToEdit.startEditingSelector(); 2617 sectionToEdit.startEditingSelector();
2648 else 2618 else
2649 sectionToEdit._moveEditorFromSelector(moveDirection); 2619 sectionToEdit._moveEditorFromSelector(moveDirection);
2650 } 2620 }
2651 return; 2621 return;
2652 } 2622 }
2653 2623
2654 if (moveToSelector) { 2624 if (moveToSelector) {
2655 if (section.rule()) 2625 if (section.style().parentRule)
2656 section.startEditingSelector(); 2626 section.startEditingSelector();
2657 else 2627 else
2658 section._moveEditorFromSelector(moveDirection); 2628 section._moveEditorFromSelector(moveDirection);
2659 } 2629 }
2660 } 2630 }
2661 }, 2631 },
2662 2632
2663 _removePrompt: function() 2633 _removePrompt: function()
2664 { 2634 {
2665 // BUG 53242. This cannot go into editingEnded(), as it should always ha ppen first for any editing outcome. 2635 // BUG 53242. This cannot go into editingEnded(), as it should always ha ppen first for any editing outcome.
(...skipping 17 matching lines...) Expand all
2683 /** 2653 /**
2684 * @param {string} styleText 2654 * @param {string} styleText
2685 * @param {boolean} majorChange 2655 * @param {boolean} majorChange
2686 * @return {!Promise.<undefined>} 2656 * @return {!Promise.<undefined>}
2687 */ 2657 */
2688 _innerApplyStyleText: function(styleText, majorChange) 2658 _innerApplyStyleText: function(styleText, majorChange)
2689 { 2659 {
2690 if (!this.treeOutline) 2660 if (!this.treeOutline)
2691 return Promise.resolve(); 2661 return Promise.resolve();
2692 2662
2693 var oldStyleRange = this.style().range; 2663 var oldStyleRange = this._style.range;
2694 if (!oldStyleRange) 2664 if (!oldStyleRange)
2695 return Promise.resolve(); 2665 return Promise.resolve();
2696 2666
2697 styleText = styleText.replace(/\s/g, " ").trim(); // Replace &nbsp; with whitespace. 2667 styleText = styleText.replace(/\s/g, " ").trim(); // Replace &nbsp; with whitespace.
2698 if (!styleText.length && majorChange && this._newProperty && !this._prop ertyHasBeenEditedIncrementally) { 2668 if (!styleText.length && majorChange && this._newProperty && !this._prop ertyHasBeenEditedIncrementally) {
2699 // The user deleted everything and never applied a new property valu e via Up/Down scrolling/live editing, so remove the tree element and update. 2669 // The user deleted everything and never applied a new property valu e via Up/Down scrolling/live editing, so remove the tree element and update.
2700 var section = this.section(); 2670 var section = this.section();
2701 this.parent.removeChild(this); 2671 this.parent.removeChild(this);
2702 section.afterUpdate(); 2672 section.afterUpdate();
2703 return Promise.resolve(); 2673 return Promise.resolve();
(...skipping 14 matching lines...) Expand all
2718 if (majorChange) { 2688 if (majorChange) {
2719 // It did not apply, cancel editing. 2689 // It did not apply, cancel editing.
2720 this._revertStyleUponEditingCanceled(); 2690 this._revertStyleUponEditingCanceled();
2721 } 2691 }
2722 this.styleTextAppliedForTest(); 2692 this.styleTextAppliedForTest();
2723 return; 2693 return;
2724 } 2694 }
2725 this._styleTextEdited(oldStyleRange); 2695 this._styleTextEdited(oldStyleRange);
2726 2696
2727 this._propertyHasBeenEditedIncrementally = true; 2697 this._propertyHasBeenEditedIncrementally = true;
2728 this.property = this.style().propertyAt(this.property.index); 2698 this.property = this._style.propertyAt(this.property.index);
2729 2699
2730 // We are happy to update UI if user is not editing. 2700 // We are happy to update UI if user is not editing.
2731 if (!this._parentPane._isEditingStyle && currentNode === this.node() ) 2701 if (!this._parentPane._isEditingStyle && currentNode === this.node() )
2732 this._updatePane(); 2702 this._updatePane();
2733 2703
2734 this.styleTextAppliedForTest(); 2704 this.styleTextAppliedForTest();
2735 } 2705 }
2736 2706
2737 // Append a ";" if the new text does not end in ";". 2707 // Append a ";" if the new text does not end in ";".
2738 // FIXME: this does not handle trailing comments. 2708 // FIXME: this does not handle trailing comments.
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
3040 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, onNodeCha nged); 3010 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, onNodeCha nged);
3041 onNodeChanged(); 3011 onNodeChanged();
3042 return button; 3012 return button;
3043 3013
3044 function onNodeChanged() 3014 function onNodeChanged()
3045 { 3015 {
3046 var node = WebInspector.context.flavor(WebInspector.DOMNode); 3016 var node = WebInspector.context.flavor(WebInspector.DOMNode);
3047 button.setEnabled(!!node); 3017 button.setEnabled(!!node);
3048 } 3018 }
3049 } 3019 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698