OLD | NEW |
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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 }, | 559 }, |
560 | 560 |
561 /** | 561 /** |
562 * @param {!Event} event | 562 * @param {!Event} event |
563 */ | 563 */ |
564 _mouseMovedOverElement: function(event) | 564 _mouseMovedOverElement: function(event) |
565 { | 565 { |
566 if (this._elementUnderMouse && event.target !== this._elementUnderMouse) | 566 if (this._elementUnderMouse && event.target !== this._elementUnderMouse) |
567 this._discardElementUnderMouse(); | 567 this._discardElementUnderMouse(); |
568 this._elementUnderMouse = event.target; | 568 this._elementUnderMouse = event.target; |
569 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(/** @type {!MouseEv
ent} */(event))) | 569 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(/** @type {!MouseEv
ent} */(event))) { |
570 this._elementUnderMouse.classList.add("styles-panel-hovered"); | 570 this._elementUnderMouse.classList.add("styles-panel-hovered"); |
| 571 var selectorElement = this._elementUnderMouse.enclosingNodeOrSelfWit
hClass("selector"); |
| 572 var sectionElement = selectorElement ? selectorElement.enclosingNode
OrSelfWithClass("styles-section") : null; |
| 573 if (sectionElement) |
| 574 sectionElement._section.makeHoverableSelectorsMode(); |
| 575 } |
571 }, | 576 }, |
572 | 577 |
573 /** | 578 /** |
574 * @param {!Event} event | 579 * @param {!Event} event |
575 */ | 580 */ |
576 _keyDown: function(event) | 581 _keyDown: function(event) |
577 { | 582 { |
578 if ((!WebInspector.isMac() && event.keyCode === WebInspector.KeyboardSho
rtcut.Keys.Ctrl.code) || | 583 if ((!WebInspector.isMac() && event.keyCode === WebInspector.KeyboardSho
rtcut.Keys.Ctrl.code) || |
579 (WebInspector.isMac() && event.keyCode === WebInspector.KeyboardShor
tcut.Keys.Meta.code)) { | 584 (WebInspector.isMac() && event.keyCode === WebInspector.KeyboardShor
tcut.Keys.Meta.code)) { |
580 if (this._elementUnderMouse) | 585 if (this._elementUnderMouse) |
(...skipping 597 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1178 hasMatchingChild |= child._updateFilter(); | 1183 hasMatchingChild |= child._updateFilter(); |
1179 | 1184 |
1180 var regex = this._parentPane.filterRegex(); | 1185 var regex = this._parentPane.filterRegex(); |
1181 var hideRule = !hasMatchingChild && !!regex && !regex.test(this.element.
textContent); | 1186 var hideRule = !hasMatchingChild && !!regex && !regex.test(this.element.
textContent); |
1182 this.element.classList.toggle("hidden", hideRule); | 1187 this.element.classList.toggle("hidden", hideRule); |
1183 if (!hideRule && this._style.parentRule) | 1188 if (!hideRule && this._style.parentRule) |
1184 this._markSelectorHighlights(); | 1189 this._markSelectorHighlights(); |
1185 return !hideRule; | 1190 return !hideRule; |
1186 }, | 1191 }, |
1187 | 1192 |
| 1193 makeHoverableSelectorsMode: function() |
| 1194 { |
| 1195 if (this._hoverableSelectorsMode) |
| 1196 return; |
| 1197 this._hoverableSelectorsMode = true; |
| 1198 this._markSelectorMatches(); |
| 1199 }, |
| 1200 |
1188 _markSelectorMatches: function() | 1201 _markSelectorMatches: function() |
1189 { | 1202 { |
1190 var rule = this._style.parentRule; | 1203 var rule = this._style.parentRule; |
1191 if (!rule) | 1204 if (!rule) |
1192 return; | 1205 return; |
1193 | 1206 |
1194 this._mediaListElement.classList.toggle("media-matches", this._matchedSt
yles.mediaMatches(this._style)); | 1207 this._mediaListElement.classList.toggle("media-matches", this._matchedSt
yles.mediaMatches(this._style)); |
1195 | 1208 |
1196 if (!this._matchedStyles.hasMatchingSelectors(/** @type {!WebInspector.C
SSStyleRule} */(rule))) | 1209 if (!this._matchedStyles.hasMatchingSelectors(/** @type {!WebInspector.C
SSStyleRule} */(rule))) |
1197 return; | 1210 return; |
1198 | 1211 |
1199 var selectors = rule.selectors; | 1212 var selectorTexts = rule.selectors.map(selector => selector.text); |
1200 var fragment = createDocumentFragment(); | |
1201 var currentMatch = 0; | |
1202 var matchingSelectors = this._matchedStyles.matchingSelectors(/** @type
{!WebInspector.CSSStyleRule} */(rule)); | |
1203 for (var i = 0; i < selectors.length ; ++i) { | |
1204 if (i) | |
1205 fragment.createTextChild(", "); | |
1206 var isSelectorMatching = matchingSelectors[currentMatch] === i; | |
1207 if (isSelectorMatching) | |
1208 ++currentMatch; | |
1209 var matchingSelectorClass = isSelectorMatching ? " selector-matches"
: ""; | |
1210 var selectorElement = createElement("span"); | |
1211 selectorElement.className = "simple-selector" + matchingSelectorClas
s; | |
1212 if (rule.styleSheetId) | |
1213 selectorElement._selectorIndex = i; | |
1214 selectorElement.textContent = selectors[i].text; | |
1215 | 1213 |
1216 fragment.appendChild(selectorElement); | 1214 var matchingSelectorIndexes = this._matchedStyles.matchingSelectors(/**
@type {!WebInspector.CSSStyleRule} */(rule)); |
1217 } | 1215 var matchingSelectors = new Array(selectorTexts.length).fill(false); |
| 1216 for (var matchingIndex of matchingSelectorIndexes) |
| 1217 matchingSelectors[matchingIndex] = true; |
1218 | 1218 |
| 1219 var fragment = this._hoverableSelectorsMode ? this._renderHoverableSelec
tors(selectorTexts, matchingSelectors) : this._renderSimplifiedSelectors(selecto
rTexts, matchingSelectors); |
1219 this._selectorElement.removeChildren(); | 1220 this._selectorElement.removeChildren(); |
1220 this._selectorElement.appendChild(fragment); | 1221 this._selectorElement.appendChild(fragment); |
1221 this._markSelectorHighlights(); | 1222 this._markSelectorHighlights(); |
1222 }, | 1223 }, |
1223 | 1224 |
| 1225 /** |
| 1226 * @param {!Array<string>} selectors |
| 1227 * @param {!Array<boolean>} matchingSelectors |
| 1228 * @return {!DocumentFragment} |
| 1229 */ |
| 1230 _renderHoverableSelectors: function(selectors, matchingSelectors) |
| 1231 { |
| 1232 var fragment = createDocumentFragment(); |
| 1233 for (var i = 0; i < selectors.length ; ++i) { |
| 1234 if (i) |
| 1235 fragment.createTextChild(", "); |
| 1236 fragment.appendChild(this._createSelectorElement(selectors[i], match
ingSelectors[i], i)); |
| 1237 } |
| 1238 return fragment; |
| 1239 }, |
| 1240 |
| 1241 /** |
| 1242 * @param {string} text |
| 1243 * @param {boolean} isMatching |
| 1244 * @param {number=} navigationIndex |
| 1245 * @return {!Element} |
| 1246 */ |
| 1247 _createSelectorElement: function(text, isMatching, navigationIndex) |
| 1248 { |
| 1249 var element = createElementWithClass("span", "simple-selector"); |
| 1250 element.classList.toggle("selector-matches", isMatching); |
| 1251 if (typeof navigationIndex === "number") |
| 1252 element._selectorIndex = navigationIndex; |
| 1253 element.textContent = text; |
| 1254 return element; |
| 1255 }, |
| 1256 |
| 1257 /** |
| 1258 * @param {!Array<string>} selectors |
| 1259 * @param {!Array<boolean>} matchingSelectors |
| 1260 * @return {!DocumentFragment} |
| 1261 */ |
| 1262 _renderSimplifiedSelectors: function(selectors, matchingSelectors) |
| 1263 { |
| 1264 var fragment = createDocumentFragment(); |
| 1265 var currentMatching = false; |
| 1266 var text = ""; |
| 1267 for (var i = 0; i < selectors.length; ++i) { |
| 1268 if (currentMatching !== matchingSelectors[i] && text) { |
| 1269 fragment.appendChild(this._createSelectorElement(text, currentMa
tching)); |
| 1270 text = ""; |
| 1271 } |
| 1272 currentMatching = matchingSelectors[i]; |
| 1273 text += selectors[i] + (i === selectors.length - 1 ? "" : ", "); |
| 1274 } |
| 1275 if (text) |
| 1276 fragment.appendChild(this._createSelectorElement(text, currentMatchi
ng)); |
| 1277 return fragment; |
| 1278 }, |
| 1279 |
1224 _markSelectorHighlights: function() | 1280 _markSelectorHighlights: function() |
1225 { | 1281 { |
1226 var selectors = this._selectorElement.getElementsByClassName("simple-sel
ector"); | 1282 var selectors = this._selectorElement.getElementsByClassName("simple-sel
ector"); |
1227 var regex = this._parentPane.filterRegex(); | 1283 var regex = this._parentPane.filterRegex(); |
1228 for (var i = 0; i < selectors.length; ++i) { | 1284 for (var i = 0; i < selectors.length; ++i) { |
1229 var selectorMatchesFilter = !!regex && regex.test(selectors[i].textC
ontent); | 1285 var selectorMatchesFilter = !!regex && regex.test(selectors[i].textC
ontent); |
1230 selectors[i].classList.toggle("filter-match", selectorMatchesFilter)
; | 1286 selectors[i].classList.toggle("filter-match", selectorMatchesFilter)
; |
1231 } | 1287 } |
1232 }, | 1288 }, |
1233 | 1289 |
(...skipping 1903 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3137 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, onNodeCha
nged); | 3193 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, onNodeCha
nged); |
3138 onNodeChanged(); | 3194 onNodeChanged(); |
3139 return button; | 3195 return button; |
3140 | 3196 |
3141 function onNodeChanged() | 3197 function onNodeChanged() |
3142 { | 3198 { |
3143 var node = WebInspector.context.flavor(WebInspector.DOMNode); | 3199 var node = WebInspector.context.flavor(WebInspector.DOMNode); |
3144 button.setEnabled(!!node); | 3200 button.setEnabled(!!node); |
3145 } | 3201 } |
3146 } | 3202 } |
OLD | NEW |