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

Side by Side Diff: Source/devtools/front_end/StylesSidebarPane.js

Issue 220403005: DevTools: synchronize links in StylesSidebarPane on edits. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: extract common parts into _applyNewStyle method Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/devtools/front_end/CSSStyleModel.js ('k') | Source/devtools/front_end/TextRange.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 if (value.endsWith("\9")) 155 if (value.endsWith("\9"))
156 return true; 156 return true;
157 if (hasUnknownVendorPrefix(value)) 157 if (hasUnknownVendorPrefix(value))
158 return true; 158 return true;
159 159
160 return false; 160 return false;
161 } 161 }
162 162
163 WebInspector.StylesSidebarPane.prototype = { 163 WebInspector.StylesSidebarPane.prototype = {
164 /** 164 /**
165 * @param {!WebInspector.CSSRule} editedRule
166 * @param {!WebInspector.TextRange} oldRange
167 * @param {!WebInspector.TextRange} newRange
168 */
169 _styleSheetRuleEdited: function(editedRule, oldRange, newRange)
170 {
171 var styleRuleSections = this.sections[0];
172 for (var i = 1; i < styleRuleSections.length; ++i)
173 styleRuleSections[i]._styleSheetRuleEdited(editedRule, oldRange, new Range);
174 },
175
176 /**
165 * @param {?Event} event 177 * @param {?Event} event
166 */ 178 */
167 _contextMenuEventFired: function(event) 179 _contextMenuEventFired: function(event)
168 { 180 {
169 // We start editing upon click -> default navigation to resources panel is not available 181 // We start editing upon click -> default navigation to resources panel is not available
170 // Hence we add a soft context menu for hrefs. 182 // Hence we add a soft context menu for hrefs.
171 var contextMenu = new WebInspector.ContextMenu(event); 183 var contextMenu = new WebInspector.ContextMenu(event);
172 contextMenu.appendApplicableItems(/** @type {!Node} */ (event.target)); 184 contextMenu.appendApplicableItems(/** @type {!Node} */ (event.target));
173 contextMenu.show(); 185 contextMenu.show();
174 }, 186 },
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 this.styleRule = styleRule; 1085 this.styleRule = styleRule;
1074 this.rule = this.styleRule.rule; 1086 this.rule = this.styleRule.rule;
1075 this.editable = editable; 1087 this.editable = editable;
1076 this.isInherited = isInherited; 1088 this.isInherited = isInherited;
1077 1089
1078 var extraClasses = (this.rule && (this.rule.isUser || this.rule.isUserAgent) ? " user-rule" : ""); 1090 var extraClasses = (this.rule && (this.rule.isUser || this.rule.isUserAgent) ? " user-rule" : "");
1079 this.element.className = "styles-section matched-styles monospace" + extraCl asses; 1091 this.element.className = "styles-section matched-styles monospace" + extraCl asses;
1080 // We don't really use properties' disclosure. 1092 // We don't really use properties' disclosure.
1081 this.propertiesElement.classList.remove("properties-tree"); 1093 this.propertiesElement.classList.remove("properties-tree");
1082 1094
1083 if (styleRule.media) {
1084 for (var i = styleRule.media.length - 1; i >= 0; --i) {
1085 var media = styleRule.media[i];
1086 var mediaDataElement = this.titleElement.createChild("div", "media") ;
1087 var mediaText;
1088 switch (media.source) {
1089 case WebInspector.CSSMedia.Source.LINKED_SHEET:
1090 case WebInspector.CSSMedia.Source.INLINE_SHEET:
1091 mediaText = "media=\"" + media.text + "\"";
1092 break;
1093 case WebInspector.CSSMedia.Source.MEDIA_RULE:
1094 mediaText = "@media " + media.text;
1095 break;
1096 case WebInspector.CSSMedia.Source.IMPORT_RULE:
1097 mediaText = "@import " + media.text;
1098 break;
1099 }
1100
1101 if (media.sourceURL) {
1102 var refElement = mediaDataElement.createChild("div", "subtitle") ;
1103 var rawLocation;
1104 var mediaHeader;
1105 if (media.range) {
1106 mediaHeader = media.header();
1107 if (mediaHeader) {
1108 var lineNumber = media.lineNumberInSource();
1109 var columnNumber = media.columnNumberInSource();
1110 console.assert(typeof lineNumber !== "undefined" && type of columnNumber !== "undefined");
1111 rawLocation = new WebInspector.CSSLocation(this._parentP ane._target, media.sourceURL, lineNumber, columnNumber);
1112 }
1113 }
1114
1115 var anchor;
1116 if (rawLocation)
1117 anchor = this._parentPane._linkifier.linkifyCSSLocation(medi aHeader.id, rawLocation);
1118 else {
1119 // The "linkedStylesheet" case.
1120 anchor = WebInspector.linkifyResourceAsNode(media.sourceURL, undefined, "subtitle", media.sourceURL);
1121 }
1122 anchor.style.float = "right";
1123 refElement.appendChild(anchor);
1124 }
1125
1126 var mediaTextElement = mediaDataElement.createChild("span");
1127 mediaTextElement.textContent = mediaText;
1128 mediaTextElement.title = media.text;
1129 }
1130 }
1131
1132 var selectorContainer = document.createElement("div"); 1095 var selectorContainer = document.createElement("div");
1133 this._selectorElement = document.createElement("span"); 1096 this._selectorElement = document.createElement("span");
1134 this._selectorElement.textContent = styleRule.selectorText; 1097 this._selectorElement.textContent = styleRule.selectorText;
1135 selectorContainer.appendChild(this._selectorElement); 1098 selectorContainer.appendChild(this._selectorElement);
1136 1099
1137 var openBrace = document.createElement("span"); 1100 var openBrace = document.createElement("span");
1138 openBrace.textContent = " {"; 1101 openBrace.textContent = " {";
1139 selectorContainer.appendChild(openBrace); 1102 selectorContainer.appendChild(openBrace);
1140 selectorContainer.addEventListener("mousedown", this._handleEmptySpaceMouseD own.bind(this), false); 1103 selectorContainer.addEventListener("mousedown", this._handleEmptySpaceMouseD own.bind(this), false);
1141 selectorContainer.addEventListener("click", this._handleSelectorContainerCli ck.bind(this), false); 1104 selectorContainer.addEventListener("click", this._handleSelectorContainerCli ck.bind(this), false);
(...skipping 15 matching lines...) Expand all
1157 if (this.rule.id) 1120 if (this.rule.id)
1158 this.navigable = !!this.rule.resourceURL(); 1121 this.navigable = !!this.rule.resourceURL();
1159 } 1122 }
1160 this.titleElement.classList.add("styles-selector"); 1123 this.titleElement.classList.add("styles-selector");
1161 } 1124 }
1162 1125
1163 this._usedProperties = styleRule.usedProperties; 1126 this._usedProperties = styleRule.usedProperties;
1164 1127
1165 this._selectorRefElement = document.createElement("div"); 1128 this._selectorRefElement = document.createElement("div");
1166 this._selectorRefElement.className = "subtitle"; 1129 this._selectorRefElement.className = "subtitle";
1130 this._mediaListElement = this.titleElement.createChild("div", "media-list");
1131 this._updateMediaList();
1167 this._updateRuleOrigin(); 1132 this._updateRuleOrigin();
1168 selectorContainer.insertBefore(this._selectorRefElement, selectorContainer.f irstChild); 1133 selectorContainer.insertBefore(this._selectorRefElement, selectorContainer.f irstChild);
1169 this.titleElement.appendChild(selectorContainer); 1134 this.titleElement.appendChild(selectorContainer);
1170 this._selectorContainer = selectorContainer; 1135 this._selectorContainer = selectorContainer;
1171 1136
1172 if (isInherited) 1137 if (isInherited)
1173 this.element.classList.add("styles-show-inherited"); // This one is rela ted to inherited rules, not computed style. 1138 this.element.classList.add("styles-show-inherited"); // This one is rela ted to inherited rules, not computed style.
1174 1139
1175 if (this.navigable) 1140 if (this.navigable)
1176 this.element.classList.add("navigable"); 1141 this.element.classList.add("navigable");
1177 1142
1178 if (!this.editable) 1143 if (!this.editable)
1179 this.element.classList.add("read-only"); 1144 this.element.classList.add("read-only");
1180 } 1145 }
1181 1146
1182 WebInspector.StylePropertiesSection.prototype = { 1147 WebInspector.StylePropertiesSection.prototype = {
1148 /**
1149 * @param {!WebInspector.CSSRule} editedRule
1150 * @param {!WebInspector.TextRange} oldRange
1151 * @param {!WebInspector.TextRange} newRange
1152 */
1153 _styleSheetRuleEdited: function(editedRule, oldRange, newRange)
1154 {
1155 if (!this.rule || !this.rule.id)
1156 return;
1157 if (this.rule !== editedRule)
1158 this.rule.sourceStyleSheetEdited(this.rule.id.styleSheetId, oldRange , newRange);
1159 this._updateMediaList();
1160 this._updateRuleOrigin();
1161 },
1162
1163 /**
1164 * @param {!Object} styleRule
1165 */
1166 _createMediaList: function(styleRule)
1167 {
1168 if (!styleRule.media)
1169 return;
1170 for (var i = styleRule.media.length - 1; i >= 0; --i) {
1171 var media = styleRule.media[i];
1172 var mediaDataElement = this._mediaListElement.createChild("div", "me dia");
1173 var mediaText;
1174 switch (media.source) {
1175 case WebInspector.CSSMedia.Source.LINKED_SHEET:
1176 case WebInspector.CSSMedia.Source.INLINE_SHEET:
1177 mediaText = "media=\"" + media.text + "\"";
1178 break;
1179 case WebInspector.CSSMedia.Source.MEDIA_RULE:
1180 mediaText = "@media " + media.text;
1181 break;
1182 case WebInspector.CSSMedia.Source.IMPORT_RULE:
1183 mediaText = "@import " + media.text;
1184 break;
1185 }
1186
1187 if (media.sourceURL) {
1188 var refElement = mediaDataElement.createChild("div", "subtitle") ;
1189 var rawLocation;
1190 var mediaHeader;
1191 if (media.range) {
1192 mediaHeader = media.header();
1193 if (mediaHeader) {
1194 var lineNumber = media.lineNumberInSource();
1195 var columnNumber = media.columnNumberInSource();
1196 console.assert(typeof lineNumber !== "undefined" && type of columnNumber !== "undefined");
1197 rawLocation = new WebInspector.CSSLocation(this._parentP ane._target, media.sourceURL, lineNumber, columnNumber);
1198 }
1199 }
1200
1201 var anchor;
1202 if (rawLocation)
1203 anchor = this._parentPane._linkifier.linkifyCSSLocation(medi aHeader.id, rawLocation);
1204 else {
1205 // The "linkedStylesheet" case.
1206 anchor = WebInspector.linkifyResourceAsNode(media.sourceURL, undefined, "subtitle", media.sourceURL);
1207 }
1208 anchor.style.float = "right";
1209 refElement.appendChild(anchor);
1210 }
1211
1212 var mediaTextElement = mediaDataElement.createChild("span");
1213 mediaTextElement.textContent = mediaText;
1214 mediaTextElement.title = media.text;
1215 }
1216 },
1217
1218 _updateMediaList: function()
1219 {
1220 this._mediaListElement.removeChildren();
1221 this._createMediaList(this.styleRule);
1222 },
1223
1183 collapse: function() 1224 collapse: function()
1184 { 1225 {
1185 // Overriding with empty body. 1226 // Overriding with empty body.
1186 }, 1227 },
1187 1228
1188 handleClick: function() 1229 handleClick: function()
1189 { 1230 {
1190 // Avoid consuming events. 1231 // Avoid consuming events.
1191 }, 1232 },
1192 1233
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
1615 { 1656 {
1616 var doesAffectSelectedNode = newRule.matchingSelectors.length > 0; 1657 var doesAffectSelectedNode = newRule.matchingSelectors.length > 0;
1617 if (!doesAffectSelectedNode) { 1658 if (!doesAffectSelectedNode) {
1618 this.noAffect = true; 1659 this.noAffect = true;
1619 this.element.classList.add("no-affect"); 1660 this.element.classList.add("no-affect");
1620 } else { 1661 } else {
1621 delete this.noAffect; 1662 delete this.noAffect;
1622 this.element.classList.remove("no-affect"); 1663 this.element.classList.remove("no-affect");
1623 } 1664 }
1624 1665
1666 var oldSelectorRange = this.rule.selectorRange;
1625 this.rule = newRule; 1667 this.rule = newRule;
1626 this.styleRule = { section: this, style: newRule.style, selectorText : newRule.selectorText, media: newRule.media, sourceURL: newRule.resourceURL(), rule: newRule }; 1668 this.styleRule = { section: this, style: newRule.style, selectorText : newRule.selectorText, media: newRule.media, sourceURL: newRule.resourceURL(), rule: newRule };
1627 1669
1628 this._parentPane.update(selectedNode); 1670 this._parentPane.update(selectedNode);
1629 this._updateRuleOrigin(); 1671 this._parentPane._styleSheetRuleEdited(this.rule, oldSelectorRange, this.rule.selectorRange);
1630 1672
1631 finishOperationAndMoveEditor.call(this, moveDirection); 1673 finishOperationAndMoveEditor.call(this, moveDirection);
1632 } 1674 }
1633 1675
1634 /** 1676 /**
1635 * @this {WebInspector.StylePropertiesSection} 1677 * @this {WebInspector.StylePropertiesSection}
1636 */ 1678 */
1637 function finishOperationAndMoveEditor(direction) 1679 function finishOperationAndMoveEditor(direction)
1638 { 1680 {
1639 delete this._parentPane._userOperation; 1681 delete this._parentPane._userOperation;
(...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after
2468 var section = this.section(); 2510 var section = this.section();
2469 if (section && section._parentPane) 2511 if (section && section._parentPane)
2470 section._parentPane._refreshUpdate(section, false, userCallback); 2512 section._parentPane._refreshUpdate(section, false, userCallback);
2471 else { 2513 else {
2472 if (userCallback) 2514 if (userCallback)
2473 userCallback(); 2515 userCallback();
2474 } 2516 }
2475 }, 2517 },
2476 2518
2477 /** 2519 /**
2520 * @param {!WebInspector.CSSStyleDeclaration} newStyle
2521 */
2522 _applyNewStyle: function(newStyle)
2523 {
2524 newStyle.parentRule = this.style.parentRule;
2525 var oldStyleRange = /** @type {!WebInspector.TextRange} */ (this.style.r ange);
2526 var newStyleRange = /** @type {!WebInspector.TextRange} */ (newStyle.ran ge);
2527 this.style = newStyle;
2528 this._styleRule.style = newStyle;
2529 if (this.style.parentRule) {
2530 this.style.parentRule.style = this.style;
2531 this._parentPane._styleSheetRuleEdited(this.style.parentRule, oldSty leRange, newStyleRange);
2532 }
2533 },
2534
2535 /**
2478 * @param {?Event} event 2536 * @param {?Event} event
2479 */ 2537 */
2480 toggleEnabled: function(event) 2538 toggleEnabled: function(event)
2481 { 2539 {
2482 var disabled = !event.target.checked; 2540 var disabled = !event.target.checked;
2483 2541
2484 /** 2542 /**
2485 * @param {?WebInspector.CSSStyleDeclaration} newStyle 2543 * @param {?WebInspector.CSSStyleDeclaration} newStyle
2486 * @this {WebInspector.StylePropertyTreeElement} 2544 * @this {WebInspector.StylePropertyTreeElement}
2487 */ 2545 */
2488 function callback(newStyle) 2546 function callback(newStyle)
2489 { 2547 {
2490 delete this._parentPane._userOperation; 2548 delete this._parentPane._userOperation;
2491 2549
2492 if (!newStyle) 2550 if (!newStyle)
2493 return; 2551 return;
2494 2552 this._applyNewStyle(newStyle);
2495 newStyle.parentRule = this.style.parentRule;
2496 this.style = newStyle;
2497 this._styleRule.style = newStyle;
2498 2553
2499 var section = this.section(); 2554 var section = this.section();
2500 if (section && section._parentPane) 2555 if (section && section._parentPane)
2501 section._parentPane.dispatchEventToListeners("style property tog gled"); 2556 section._parentPane.dispatchEventToListeners("style property tog gled");
2502 2557
2503 this._updatePane(); 2558 this._updatePane();
2504 } 2559 }
2505 2560
2506 this._parentPane._userOperation = true; 2561 this._parentPane._userOperation = true;
2507 this.property.setDisabled(disabled, callback.bind(this)); 2562 this.property.setDisabled(disabled, callback.bind(this));
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
3082 function callback(userCallback, originalPropertyText, newStyle) 3137 function callback(userCallback, originalPropertyText, newStyle)
3083 { 3138 {
3084 if (!newStyle) { 3139 if (!newStyle) {
3085 if (updateInterface) { 3140 if (updateInterface) {
3086 // It did not apply, cancel editing. 3141 // It did not apply, cancel editing.
3087 this._revertStyleUponEditingCanceled(originalPropertyText); 3142 this._revertStyleUponEditingCanceled(originalPropertyText);
3088 } 3143 }
3089 userCallback(); 3144 userCallback();
3090 return; 3145 return;
3091 } 3146 }
3147 this._applyNewStyle(newStyle);
3092 3148
3093 if (this._newProperty) 3149 if (this._newProperty)
3094 this._newPropertyInStyle = true; 3150 this._newPropertyInStyle = true;
3095 newStyle.parentRule = this.style.parentRule; 3151
3096 this.style = newStyle;
3097 this.property = newStyle.propertyAt(this.property.index); 3152 this.property = newStyle.propertyAt(this.property.index);
3098 this._styleRule.style = this.style;
3099
3100 if (section && section._parentPane) 3153 if (section && section._parentPane)
3101 section._parentPane.dispatchEventToListeners("style edited"); 3154 section._parentPane.dispatchEventToListeners("style edited");
3102 3155
3103 if (updateInterface && currentNode === this.node()) { 3156 if (updateInterface && currentNode === this.node()) {
3104 this._updatePane(userCallback); 3157 this._updatePane(userCallback);
3105 return; 3158 return;
3106 } 3159 }
3107 3160
3108 userCallback(); 3161 userCallback();
3109 } 3162 }
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
3255 return; 3308 return;
3256 } 3309 }
3257 3310
3258 var results = this._cssCompletions.startsWith(prefix); 3311 var results = this._cssCompletions.startsWith(prefix);
3259 var selectedIndex = this._cssCompletions.mostUsedOf(results); 3312 var selectedIndex = this._cssCompletions.mostUsedOf(results);
3260 completionsReadyCallback(results, selectedIndex); 3313 completionsReadyCallback(results, selectedIndex);
3261 }, 3314 },
3262 3315
3263 __proto__: WebInspector.TextPrompt.prototype 3316 __proto__: WebInspector.TextPrompt.prototype
3264 } 3317 }
OLDNEW
« no previous file with comments | « Source/devtools/front_end/CSSStyleModel.js ('k') | Source/devtools/front_end/TextRange.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698