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

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

Issue 2146233003: DevTools: [SSP] render selectors effectively (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 5 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
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/elements/styles-3/styles-add-new-rule-tab-expected.txt ('k') | no next file » | 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 548 matching lines...) Expand 10 before | Expand all | Expand 10 after
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");
pfeldman 2016/07/15 21:13:01 Both are ugly. please fetch section object instead
lushnikov 2016/07/15 21:26:04 As per offline discussion, I'll simplify this code
572 var sectionElement = selectorElement ? selectorElement.enclosingNode OrSelfWithClass("styles-section") : null;
573 if (sectionElement)
574 sectionElement._section.setHoverableSelectorsMode(true);
pfeldman 2016/07/15 21:13:01 makeHoverableSelectorsMode()
lushnikov 2016/07/15 21:26:04 Done.
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
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 /**
1194 * @param {boolean} value
1195 */
1196 setHoverableSelectorsMode: function(value)
1197 {
1198 if (this._hoverableSelectorsMode === value)
1199 return;
1200 this._hoverableSelectorsMode = value;
1201 this._markSelectorMatches();
1202 },
1203
1188 _markSelectorMatches: function() 1204 _markSelectorMatches: function()
1189 { 1205 {
1190 var rule = this._style.parentRule; 1206 var rule = this._style.parentRule;
1191 if (!rule) 1207 if (!rule)
1192 return; 1208 return;
1193 1209
1194 this._mediaListElement.classList.toggle("media-matches", this._matchedSt yles.mediaMatches(this._style)); 1210 this._mediaListElement.classList.toggle("media-matches", this._matchedSt yles.mediaMatches(this._style));
1195 1211
1196 if (!this._matchedStyles.hasMatchingSelectors(/** @type {!WebInspector.C SSStyleRule} */(rule))) 1212 if (!this._matchedStyles.hasMatchingSelectors(/** @type {!WebInspector.C SSStyleRule} */(rule)))
1197 return; 1213 return;
1198 1214
1199 var selectors = rule.selectors; 1215 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 1216
1216 fragment.appendChild(selectorElement); 1217 var matchingSelectorIndexes = this._matchedStyles.matchingSelectors(/** @type {!WebInspector.CSSStyleRule} */(rule));
1217 } 1218 var matchingSelectors = new Array(selectorTexts.length).fill(false);
1219 for (var matchingIndex of matchingSelectorIndexes)
1220 matchingSelectors[matchingIndex] = true;
1218 1221
1222 var fragment = this._hoverableSelectorsMode ? this._renderHoverableSelec tors(selectorTexts, matchingSelectors) : this._renderSimplifiedSelectors(selecto rTexts, matchingSelectors);
1219 this._selectorElement.removeChildren(); 1223 this._selectorElement.removeChildren();
1220 this._selectorElement.appendChild(fragment); 1224 this._selectorElement.appendChild(fragment);
1221 this._markSelectorHighlights(); 1225 this._markSelectorHighlights();
1222 }, 1226 },
1223 1227
1228 /**
1229 * @param {!Array<string>} selectors
1230 * @param {!Array<boolean>} matchingSelectors
1231 * @return {!DocumentFragment}
1232 */
1233 _renderHoverableSelectors: function(selectors, matchingSelectors)
1234 {
1235 var fragment = createDocumentFragment();
1236 for (var i = 0; i < selectors.length ; ++i) {
1237 if (i)
1238 fragment.createTextChild(", ");
1239 fragment.appendChild(this._createSelectorElement(selectors[i], match ingSelectors[i], i));
1240 }
1241 return fragment;
1242 },
1243
1244 /**
1245 * @param {string} text
1246 * @param {boolean} isMatching
1247 * @param {number=} navigationIndex
1248 * @return {!Element}
1249 */
1250 _createSelectorElement: function(text, isMatching, navigationIndex)
1251 {
1252 var element = createElementWithClass("span", "simple-selector");
1253 element.classList.toggle("selector-matches", isMatching);
1254 if (typeof navigationIndex === "number")
1255 element._selectorIndex = navigationIndex;
1256 element.textContent = text;
1257 return element;
1258 },
1259
1260 /**
1261 * @param {!Array<string>} selectors
1262 * @param {!Array<boolean>} matchingSelectors
1263 * @return {!DocumentFragment}
1264 */
1265 _renderSimplifiedSelectors: function(selectors, matchingSelectors)
1266 {
1267 var fragment = createDocumentFragment();
1268 var currentMatching = false;
1269 var text = "";
1270 for (var i = 0; i < selectors.length; ++i) {
1271 if (currentMatching !== matchingSelectors[i] && text) {
1272 fragment.appendChild(this._createSelectorElement(text, currentMa tching));
1273 text = "";
1274 }
1275 currentMatching = matchingSelectors[i];
1276 text += selectors[i] + (i === selectors.length - 1 ? "" : ", ");
1277 }
1278 if (text)
1279 fragment.appendChild(this._createSelectorElement(text, currentMatchi ng));
1280 return fragment;
1281 },
1282
1224 _markSelectorHighlights: function() 1283 _markSelectorHighlights: function()
1225 { 1284 {
1226 var selectors = this._selectorElement.getElementsByClassName("simple-sel ector"); 1285 var selectors = this._selectorElement.getElementsByClassName("simple-sel ector");
1227 var regex = this._parentPane.filterRegex(); 1286 var regex = this._parentPane.filterRegex();
1228 for (var i = 0; i < selectors.length; ++i) { 1287 for (var i = 0; i < selectors.length; ++i) {
1229 var selectorMatchesFilter = !!regex && regex.test(selectors[i].textC ontent); 1288 var selectorMatchesFilter = !!regex && regex.test(selectors[i].textC ontent);
1230 selectors[i].classList.toggle("filter-match", selectorMatchesFilter) ; 1289 selectors[i].classList.toggle("filter-match", selectorMatchesFilter) ;
1231 } 1290 }
1232 }, 1291 },
1233 1292
(...skipping 1903 matching lines...) Expand 10 before | Expand all | Expand 10 after
3137 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, onNodeCha nged); 3196 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, onNodeCha nged);
3138 onNodeChanged(); 3197 onNodeChanged();
3139 return button; 3198 return button;
3140 3199
3141 function onNodeChanged() 3200 function onNodeChanged()
3142 { 3201 {
3143 var node = WebInspector.context.flavor(WebInspector.DOMNode); 3202 var node = WebInspector.context.flavor(WebInspector.DOMNode);
3144 button.setEnabled(!!node); 3203 button.setEnabled(!!node);
3145 } 3204 }
3146 } 3205 }
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/inspector/elements/styles-3/styles-add-new-rule-tab-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698