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

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: 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 | « no previous file | 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 27 matching lines...) Expand all
38 38
39 WebInspector.moduleSetting("colorFormat").addChangeListener(this.update.bind (this)); 39 WebInspector.moduleSetting("colorFormat").addChangeListener(this.update.bind (this));
40 WebInspector.moduleSetting("textEditorIndent").addChangeListener(this.update .bind(this)); 40 WebInspector.moduleSetting("textEditorIndent").addChangeListener(this.update .bind(this));
41 41
42 this._sectionsContainer = this.element.createChild("div"); 42 this._sectionsContainer = this.element.createChild("div");
43 this._stylesPopoverHelper = new WebInspector.StylesPopoverHelper(); 43 this._stylesPopoverHelper = new WebInspector.StylesPopoverHelper();
44 this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.Defa ultCSSFormatter()); 44 this._linkifier = new WebInspector.Linkifier(new WebInspector.Linkifier.Defa ultCSSFormatter());
45 45
46 this.element.classList.add("styles-pane"); 46 this.element.classList.add("styles-pane");
47 this.element.addEventListener("mousemove", this._mouseMovedOverElement.bind( this), false); 47 this.element.addEventListener("mousemove", this._mouseMovedOverElement.bind( this), false);
48 this.element.addEventListener("mouseleave", this._discardElementUnderMouse.b ind(this), false);
48 this._keyDownBound = this._keyDown.bind(this); 49 this._keyDownBound = this._keyDown.bind(this);
49 this._keyUpBound = this._keyUp.bind(this); 50 this._keyUpBound = this._keyUp.bind(this);
50 51
51 /** @type {!Array<!WebInspector.SectionBlock>} */ 52 /** @type {!Array<!WebInspector.SectionBlock>} */
52 this._sectionBlocks = []; 53 this._sectionBlocks = [];
53 54
54 WebInspector.targetManager.addModelListener(WebInspector.CSSModel, WebInspec tor.CSSModel.Events.LayoutEditorChange, this._onLayoutEditorChange, this); 55 WebInspector.targetManager.addModelListener(WebInspector.CSSModel, WebInspec tor.CSSModel.Events.LayoutEditorChange, this._onLayoutEditorChange, this);
55 } 56 }
56 57
57 /** 58 /**
(...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after
546 { 547 {
547 this.element.ownerDocument.body.removeEventListener("keydown", this._key DownBound, false); 548 this.element.ownerDocument.body.removeEventListener("keydown", this._key DownBound, false);
548 this.element.ownerDocument.body.removeEventListener("keyup", this._keyUp Bound, false); 549 this.element.ownerDocument.body.removeEventListener("keyup", this._keyUp Bound, false);
549 this._stylesPopoverHelper.hide(); 550 this._stylesPopoverHelper.hide();
550 this._discardElementUnderMouse(); 551 this._discardElementUnderMouse();
551 WebInspector.ElementsSidebarPane.prototype.willHide.call(this); 552 WebInspector.ElementsSidebarPane.prototype.willHide.call(this);
552 }, 553 },
553 554
554 _discardElementUnderMouse: function() 555 _discardElementUnderMouse: function()
555 { 556 {
556 if (this._elementUnderMouse) 557 this._toggleCtrlHoverState(false);
557 this._elementUnderMouse.classList.remove("styles-panel-hovered"); 558 this._updateElementsUnderMouse(null, null);
558 delete this._elementUnderMouse;
559 }, 559 },
560 560
561 /** 561 /**
562 * @param {?Element} newElement
563 * @param {?WebInspector.StylePropertiesSection} newSection
564 */
565 _updateElementsUnderMouse: function(newElement, newSection)
566 {
567 if (newElement !== this._elementUnderMouse) {
568 if (this._elementUnderMouse)
569 this._elementUnderMouse.classList.remove("styles-panel-hovered") ;
570 this._elementUnderMouse = newElement;
571 }
572 if (this._sectionUnderMouse !== newSection) {
pfeldman 2016/07/14 23:14:41 I don't think you need sectionUnderMouse field.
lushnikov 2016/07/15 00:49:23 Done.
573 if (this._sectionUnderMouse)
574 this._sectionUnderMouse.setHoverableSelectorsMode(false);
575 this._sectionUnderMouse = newSection;
576 }
577 },
578
579 /**
580 * @param {boolean} value
581 */
582 _toggleCtrlHoverState: function(value)
583 {
584 if (this._elementUnderMouse)
585 this._elementUnderMouse.classList.toggle("styles-panel-hovered", val ue);
586 if (this._sectionUnderMouse)
587 this._sectionUnderMouse.setHoverableSelectorsMode(value);
588 },
589
590 /**
562 * @param {!Event} event 591 * @param {!Event} event
563 */ 592 */
564 _mouseMovedOverElement: function(event) 593 _mouseMovedOverElement: function(event)
565 { 594 {
566 if (this._elementUnderMouse && event.target !== this._elementUnderMouse) 595 var newElement = /** @type {!Element} */(event.target);
567 this._discardElementUnderMouse(); 596 var sectionElement = event.target.enclosingNodeOrSelfWithClass("styles-s ection");
568 this._elementUnderMouse = event.target; 597 var newSection = sectionElement ? sectionElement._section : null;
598 this._updateElementsUnderMouse(newElement, newSection);
599
569 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(/** @type {!MouseEv ent} */(event))) 600 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(/** @type {!MouseEv ent} */(event)))
570 this._elementUnderMouse.classList.add("styles-panel-hovered"); 601 this._toggleCtrlHoverState(true);
571 }, 602 },
572 603
573 /** 604 /**
574 * @param {!Event} event 605 * @param {!Event} event
575 */ 606 */
576 _keyDown: function(event) 607 _keyDown: function(event)
577 { 608 {
578 if ((!WebInspector.isMac() && event.keyCode === WebInspector.KeyboardSho rtcut.Keys.Ctrl.code) || 609 if (WebInspector.KeyboardShortcut.eventHasCtrlOrMeta(/** @type {!Keyboar dEvent} */(event)))
579 (WebInspector.isMac() && event.keyCode === WebInspector.KeyboardShor tcut.Keys.Meta.code)) { 610 this._toggleCtrlHoverState(true);
580 if (this._elementUnderMouse)
581 this._elementUnderMouse.classList.add("styles-panel-hovered");
582 }
583 }, 611 },
584 612
585 /** 613 /**
586 * @param {!Event} event 614 * @param {!Event} event
587 */ 615 */
588 _keyUp: function(event) 616 _keyUp: function(event)
589 { 617 {
590 if ((!WebInspector.isMac() && event.keyCode === WebInspector.KeyboardSho rtcut.Keys.Ctrl.code) || 618 if (WebInspector.KeyboardShortcut.Keys.CtrlOrMeta.code === event.keyCode )
591 (WebInspector.isMac() && event.keyCode === WebInspector.KeyboardShor tcut.Keys.Meta.code)) { 619 this._toggleCtrlHoverState(false);
592 this._discardElementUnderMouse();
593 }
594 }, 620 },
595 621
596 /** 622 /**
597 * @return {!Array<!WebInspector.StylePropertiesSection>} 623 * @return {!Array<!WebInspector.StylePropertiesSection>}
598 */ 624 */
599 allSections: function() 625 allSections: function()
600 { 626 {
601 var sections = []; 627 var sections = [];
602 for (var block of this._sectionBlocks) 628 for (var block of this._sectionBlocks)
603 sections = sections.concat(block.sections); 629 sections = sections.concat(block.sections);
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
784 this._updateRuleOrigin(); 810 this._updateRuleOrigin();
785 this._titleElement.appendChild(selectorContainer); 811 this._titleElement.appendChild(selectorContainer);
786 this._selectorContainer = selectorContainer; 812 this._selectorContainer = selectorContainer;
787 813
788 if (this.navigable) 814 if (this.navigable)
789 this.element.classList.add("navigable"); 815 this.element.classList.add("navigable");
790 816
791 if (!this.editable) 817 if (!this.editable)
792 this.element.classList.add("read-only"); 818 this.element.classList.add("read-only");
793 819
794 this._markSelectorMatches(); 820 this.setHoverableSelectorsMode(false);
795 this.onpopulate(); 821 this.onpopulate();
796 } 822 }
797 823
798 WebInspector.StylePropertiesSection.prototype = { 824 WebInspector.StylePropertiesSection.prototype = {
799 /** 825 /**
800 * @param {!Element} container 826 * @param {!Element} container
801 */ 827 */
802 _createHoverMenuToolbar: function(container) 828 _createHoverMenuToolbar: function(container)
803 { 829 {
804 if (!this.editable) 830 if (!this.editable)
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
1178 hasMatchingChild |= child._updateFilter(); 1204 hasMatchingChild |= child._updateFilter();
1179 1205
1180 var regex = this._parentPane.filterRegex(); 1206 var regex = this._parentPane.filterRegex();
1181 var hideRule = !hasMatchingChild && !!regex && !regex.test(this.element. textContent); 1207 var hideRule = !hasMatchingChild && !!regex && !regex.test(this.element. textContent);
1182 this.element.classList.toggle("hidden", hideRule); 1208 this.element.classList.toggle("hidden", hideRule);
1183 if (!hideRule && this._style.parentRule) 1209 if (!hideRule && this._style.parentRule)
1184 this._markSelectorHighlights(); 1210 this._markSelectorHighlights();
1185 return !hideRule; 1211 return !hideRule;
1186 }, 1212 },
1187 1213
1214 /**
1215 * @param {boolean} value
1216 */
1217 setHoverableSelectorsMode: function(value)
pfeldman 2016/07/14 23:14:41 Merge this with the method below and only trigger
lushnikov 2016/07/15 00:49:22 Couldn't get rid of this method, even though i now
1218 {
1219 if (this._hoverableSelectorsMode === value)
1220 return;
1221 this._hoverableSelectorsMode = value;
1222 if (!this._editingSelector)
1223 this._markSelectorMatches();
1224 },
1225
1188 _markSelectorMatches: function() 1226 _markSelectorMatches: function()
1189 { 1227 {
1190 var rule = this._style.parentRule; 1228 var rule = this._style.parentRule;
1191 if (!rule) 1229 if (!rule)
1192 return; 1230 return;
1193 1231
1194 this._mediaListElement.classList.toggle("media-matches", this._matchedSt yles.mediaMatches(this._style)); 1232 this._mediaListElement.classList.toggle("media-matches", this._matchedSt yles.mediaMatches(this._style));
1195 1233
1196 if (!this._matchedStyles.hasMatchingSelectors(/** @type {!WebInspector.C SSStyleRule} */(rule))) 1234 if (!this._matchedStyles.hasMatchingSelectors(/** @type {!WebInspector.C SSStyleRule} */(rule)))
1197 return; 1235 return;
1198 1236
1199 var selectors = rule.selectors;
1200 var fragment = createDocumentFragment();
1201 var currentMatch = 0;
1202 var matchingSelectors = this._matchedStyles.matchingSelectors(/** @type {!WebInspector.CSSStyleRule} */(rule)); 1237 var matchingSelectors = this._matchedStyles.matchingSelectors(/** @type {!WebInspector.CSSStyleRule} */(rule));
1203 for (var i = 0; i < selectors.length ; ++i) { 1238 var selectorTexts = rule.selectors.map(selector => selector.text);
1204 if (i) 1239 var fragment = this._hoverableSelectorsMode ? this._renderHoverableSelec tors(selectorTexts, matchingSelectors) : this._renderSimplifiedSelectors(selecto rTexts, matchingSelectors);
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 fragment.appendChild(selectorElement);
1217 }
1218
1219 this._selectorElement.removeChildren(); 1240 this._selectorElement.removeChildren();
1220 this._selectorElement.appendChild(fragment); 1241 this._selectorElement.appendChild(fragment);
1221 this._markSelectorHighlights(); 1242 this._markSelectorHighlights();
1222 }, 1243 },
1223 1244
1245 /**
1246 * @param {!Array<string>} selectors
1247 * @param {!Array<number>} matchingSelectorIndexes
1248 * @return {!DocumentFragment}
1249 */
1250 _renderHoverableSelectors: function(selectors, matchingSelectorIndexes)
1251 {
1252 var fragment = createDocumentFragment();
1253 var currentMatch = 0;
1254 for (var i = 0; i < selectors.length ; ++i) {
1255 if (i)
1256 fragment.createTextChild(", ");
1257 var isSelectorMatching = matchingSelectorIndexes[currentMatch] === i ;
1258 if (isSelectorMatching)
1259 ++currentMatch;
1260 fragment.appendChild(this._createSelectorElement(selectors[i], isSel ectorMatching, i));
1261 }
1262 return fragment;
1263 },
1264
1265 /**
1266 * @param {string} text
1267 * @param {boolean} isMatching
1268 * @param {number=} navigationIndex
1269 * @return {!Element}
1270 */
1271 _createSelectorElement: function(text, isMatching, navigationIndex)
1272 {
1273 var element = createElementWithClass("span", "simple-selector");
1274 element.classList.toggle("selector-matches", isMatching);
1275 if (typeof navigationIndex === "number")
1276 element._selectorIndex = navigationIndex;
1277 element.textContent = text;
1278 return element;
1279 },
1280
1281 /**
1282 * @param {!Array<string>} selectors
1283 * @param {!Array<number>} matchingSelectorIndexes
1284 * @return {!DocumentFragment}
1285 */
1286 _renderSimplifiedSelectors: function(selectors, matchingSelectorIndexes)
pfeldman 2016/07/14 23:14:41 Replace this with: function renderSimplifiedSelec
lushnikov 2016/07/15 00:49:23 Done.
1287 {
1288 var fragment = createDocumentFragment();
1289 var currentMatch = 0;
1290 var nonMatchingSelectors = null;
1291 for (var i = 0; i < selectors.length ; ++i) {
1292 if (i)
1293 renderNonMatchingText.call(this, ", ");
1294 var isSelectorMatching = matchingSelectorIndexes[currentMatch] === i ;
1295 if (isSelectorMatching) {
1296 ++currentMatch;
1297 renderMatchingText.call(this, selectors[i]);
1298 } else {
1299 renderNonMatchingText.call(this, selectors[i]);
1300 }
1301 }
1302 return fragment;
1303
1304 /**
1305 * @param {string} text
1306 * @this {WebInspector.StylePropertiesSection}
1307 */
1308 function renderNonMatchingText(text)
1309 {
1310 if (!nonMatchingSelectors) {
1311 nonMatchingSelectors = this._createSelectorElement(text, false);
1312 fragment.appendChild(nonMatchingSelectors);
1313 } else {
1314 nonMatchingSelectors.textContent += text;
1315 }
1316 }
1317
1318 /**
1319 * @param {string} text
1320 * @this {WebInspector.StylePropertiesSection}
1321 */
1322 function renderMatchingText(text)
1323 {
1324 fragment.appendChild(this._createSelectorElement(text, true));
1325 nonMatchingSelectors = null;
1326 }
1327 },
1328
1224 _markSelectorHighlights: function() 1329 _markSelectorHighlights: function()
1225 { 1330 {
1226 var selectors = this._selectorElement.getElementsByClassName("simple-sel ector"); 1331 var selectors = this._selectorElement.getElementsByClassName("simple-sel ector");
1227 var regex = this._parentPane.filterRegex(); 1332 var regex = this._parentPane.filterRegex();
1228 for (var i = 0; i < selectors.length; ++i) { 1333 for (var i = 0; i < selectors.length; ++i) {
1229 var selectorMatchesFilter = !!regex && regex.test(selectors[i].textC ontent); 1334 var selectorMatchesFilter = !!regex && regex.test(selectors[i].textC ontent);
1230 selectors[i].classList.toggle("filter-match", selectorMatchesFilter) ; 1335 selectors[i].classList.toggle("filter-match", selectorMatchesFilter) ;
1231 } 1336 }
1232 }, 1337 },
1233 1338
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 1559
1455 this.startEditingSelector(); 1560 this.startEditingSelector();
1456 }, 1561 },
1457 1562
1458 startEditingSelector: function() 1563 startEditingSelector: function()
1459 { 1564 {
1460 var element = this._selectorElement; 1565 var element = this._selectorElement;
1461 if (WebInspector.isBeingEdited(element)) 1566 if (WebInspector.isBeingEdited(element))
1462 return; 1567 return;
1463 1568
1569 this._editingSelector = true;
1464 element.scrollIntoViewIfNeeded(false); 1570 element.scrollIntoViewIfNeeded(false);
1465 element.textContent = element.textContent; // Reset selector marks in gr oup. 1571 element.textContent = element.textContent; // Reset selector marks in gr oup.
1466 1572
1467 var config = new WebInspector.InplaceEditor.Config(this.editingSelectorC ommitted.bind(this), this.editingSelectorCancelled.bind(this)); 1573 var config = new WebInspector.InplaceEditor.Config(this.editingSelectorC ommitted.bind(this), this.editingSelectorCancelled.bind(this));
1468 WebInspector.InplaceEditor.startEditing(this._selectorElement, config); 1574 WebInspector.InplaceEditor.startEditing(this._selectorElement, config);
1469 1575
1470 element.getComponentSelection().setBaseAndExtent(element, 0, element, 1) ; 1576 element.getComponentSelection().setBaseAndExtent(element, 0, element, 1) ;
1471 this._parentPane.setEditingStyle(true); 1577 this._parentPane.setEditingStyle(true);
1472 if (element.classList.contains("simple-selector")) 1578 if (element.classList.contains("simple-selector"))
1473 this._navigateToSelectorSource(0, false); 1579 this._navigateToSelectorSource(0, false);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
1582 _editingSelectorCommittedForTest: function() { }, 1688 _editingSelectorCommittedForTest: function() { },
1583 1689
1584 _updateRuleOrigin: function() 1690 _updateRuleOrigin: function()
1585 { 1691 {
1586 this._selectorRefElement.removeChildren(); 1692 this._selectorRefElement.removeChildren();
1587 this._selectorRefElement.appendChild(WebInspector.StylePropertiesSection .createRuleOriginNode(this._matchedStyles, this._parentPane._linkifier, this._st yle.parentRule)); 1693 this._selectorRefElement.appendChild(WebInspector.StylePropertiesSection .createRuleOriginNode(this._matchedStyles, this._parentPane._linkifier, this._st yle.parentRule));
1588 }, 1694 },
1589 1695
1590 _editingSelectorEnded: function() 1696 _editingSelectorEnded: function()
1591 { 1697 {
1698 this._editingSelector = false;
1592 this._parentPane.setEditingStyle(false); 1699 this._parentPane.setEditingStyle(false);
1593 }, 1700 },
1594 1701
1595 editingSelectorCancelled: function() 1702 editingSelectorCancelled: function()
1596 { 1703 {
1597 this._editingSelectorEnded(); 1704 this._editingSelectorEnded();
1598 1705
1599 // Mark the selectors in group if necessary. 1706 // Mark the selectors in group if necessary.
1600 // This is overridden by BlankStylePropertiesSection. 1707 // This is overridden by BlankStylePropertiesSection.
1601 this._markSelectorMatches(); 1708 this._markSelectorMatches();
(...skipping 1535 matching lines...) Expand 10 before | Expand all | Expand 10 after
3137 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, onNodeCha nged); 3244 WebInspector.context.addFlavorChangeListener(WebInspector.DOMNode, onNodeCha nged);
3138 onNodeChanged(); 3245 onNodeChanged();
3139 return button; 3246 return button;
3140 3247
3141 function onNodeChanged() 3248 function onNodeChanged()
3142 { 3249 {
3143 var node = WebInspector.context.flavor(WebInspector.DOMNode); 3250 var node = WebInspector.context.flavor(WebInspector.DOMNode);
3144 button.setEnabled(!!node); 3251 button.setEnabled(!!node);
3145 } 3252 }
3146 } 3253 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698