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

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

Issue 2830803002: DevTools: Fast resize styles sidebar (Closed)
Patch Set: removeProperty Created 3 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/elements/elementsPanel.css » ('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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 this._mouseDownTreeElementIsName = false; 50 this._mouseDownTreeElementIsName = false;
51 this._mouseDownTreeElementIsValue = false; 51 this._mouseDownTreeElementIsValue = false;
52 52
53 this.element.classList.add('styles-pane'); 53 this.element.classList.add('styles-pane');
54 54
55 /** @type {!Array<!Elements.SectionBlock>} */ 55 /** @type {!Array<!Elements.SectionBlock>} */
56 this._sectionBlocks = []; 56 this._sectionBlocks = [];
57 Elements.StylesSidebarPane._instance = this; 57 Elements.StylesSidebarPane._instance = this;
58 UI.context.addFlavorChangeListener(SDK.DOMNode, this.forceUpdate, this); 58 UI.context.addFlavorChangeListener(SDK.DOMNode, this.forceUpdate, this);
59 this.element.addEventListener('copy', this._clipboardCopy.bind(this)); 59 this.element.addEventListener('copy', this._clipboardCopy.bind(this));
60 this._resizeThrottler = new Common.Throttler(100);
60 } 61 }
61 62
62 /** 63 /**
63 * @param {!SDK.CSSProperty} property 64 * @param {!SDK.CSSProperty} property
64 * @return {!Element} 65 * @return {!Element}
65 */ 66 */
66 static createExclamationMark(property) { 67 static createExclamationMark(property) {
67 var exclamationElement = createElement('label', 'dt-icon-label'); 68 var exclamationElement = createElement('label', 'dt-icon-label');
68 exclamationElement.className = 'exclamation-mark'; 69 exclamationElement.className = 'exclamation-mark';
69 if (!Elements.StylesSidebarPane.ignoreErrorsForProperty(property)) 70 if (!Elements.StylesSidebarPane.ignoreErrorsForProperty(property))
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 } 248 }
248 249
249 /** 250 /**
250 * @override 251 * @override
251 * @return {!Promise.<?>} 252 * @return {!Promise.<?>}
252 */ 253 */
253 doUpdate() { 254 doUpdate() {
254 return this._fetchMatchedCascade().then(this._innerRebuildUpdate.bind(this)) ; 255 return this._fetchMatchedCascade().then(this._innerRebuildUpdate.bind(this)) ;
255 } 256 }
256 257
258 /**
259 * @override
260 */
261 onResize() {
262 this._resizeThrottler.schedule(this._innerResize.bind(this));
263 }
264
265 /**
266 * @return {!Promise}
267 */
268 _innerResize() {
269 var width = this.element.getBoundingClientRect().width + 'px';
270 this.allSections().forEach(section => section.propertiesTreeOutline.element. style.width = width);
271 return Promise.resolve();
272 }
273
257 _resetCache() { 274 _resetCache() {
258 if (this.cssModel()) 275 if (this.cssModel())
259 this.cssModel().discardCachedMatchedCascade(); 276 this.cssModel().discardCachedMatchedCascade();
260 } 277 }
261 278
262 /** 279 /**
263 * @return {!Promise.<?SDK.CSSMatchedStyles>} 280 * @return {!Promise.<?SDK.CSSMatchedStyles>}
264 */ 281 */
265 _fetchMatchedCascade() { 282 _fetchMatchedCascade() {
266 var node = this.node(); 283 var node = this.node();
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 this.editable = !!(style.styleSheetId && style.range); 595 this.editable = !!(style.styleSheetId && style.range);
579 /** @type {?number} */ 596 /** @type {?number} */
580 this._hoverTimer = null; 597 this._hoverTimer = null;
581 /** @type {?function(!Elements.StylePropertiesSection)} */ 598 /** @type {?function(!Elements.StylePropertiesSection)} */
582 this._afterUpdate = null; 599 this._afterUpdate = null;
583 this._willCauseCancelEditing = false; 600 this._willCauseCancelEditing = false;
584 601
585 var rule = style.parentRule; 602 var rule = style.parentRule;
586 this.element = createElementWithClass('div', 'styles-section matched-styles monospace'); 603 this.element = createElementWithClass('div', 'styles-section matched-styles monospace');
587 this.element._section = this; 604 this.element._section = this;
605 this._innerElement = this.element.createChild('div');
588 606
589 this._titleElement = this.element.createChild('div', 'styles-section-title ' + (rule ? 'styles-selector' : '')); 607 this._titleElement = this._innerElement.createChild('div', 'styles-section-t itle ' + (rule ? 'styles-selector' : ''));
590 608
591 this.propertiesTreeOutline = new UI.TreeOutlineInShadow(); 609 this.propertiesTreeOutline = new UI.TreeOutlineInShadow();
592 this.propertiesTreeOutline.registerRequiredCSS('elements/stylesSectionTree.c ss'); 610 this.propertiesTreeOutline.registerRequiredCSS('elements/stylesSectionTree.c ss');
593 this.propertiesTreeOutline.element.classList.add('style-properties', 'matche d-styles', 'monospace'); 611 this.propertiesTreeOutline.element.classList.add('style-properties', 'matche d-styles', 'monospace');
594 this.propertiesTreeOutline.section = this; 612 this.propertiesTreeOutline.section = this;
595 this.element.appendChild(this.propertiesTreeOutline.element); 613 this._innerElement.appendChild(this.propertiesTreeOutline.element);
596 614
597 var selectorContainer = createElement('div'); 615 var selectorContainer = createElement('div');
598 this._selectorElement = createElementWithClass('span', 'selector'); 616 this._selectorElement = createElementWithClass('span', 'selector');
599 this._selectorElement.textContent = this._headerText(); 617 this._selectorElement.textContent = this._headerText();
600 selectorContainer.appendChild(this._selectorElement); 618 selectorContainer.appendChild(this._selectorElement);
601 this._selectorElement.addEventListener('mouseenter', this._onMouseEnterSelec tor.bind(this), false); 619 this._selectorElement.addEventListener('mouseenter', this._onMouseEnterSelec tor.bind(this), false);
602 this._selectorElement.addEventListener('mouseleave', this._onMouseOutSelecto r.bind(this), false); 620 this._selectorElement.addEventListener('mouseleave', this._onMouseOutSelecto r.bind(this), false);
603 621
604 var openBrace = createElement('span'); 622 var openBrace = createElement('span');
605 openBrace.textContent = ' {'; 623 openBrace.textContent = ' {';
606 selectorContainer.appendChild(openBrace); 624 selectorContainer.appendChild(openBrace);
607 selectorContainer.addEventListener('mousedown', this._handleEmptySpaceMouseD own.bind(this), false); 625 selectorContainer.addEventListener('mousedown', this._handleEmptySpaceMouseD own.bind(this), false);
608 selectorContainer.addEventListener('click', this._handleSelectorContainerCli ck.bind(this), false); 626 selectorContainer.addEventListener('click', this._handleSelectorContainerCli ck.bind(this), false);
609 627
610 var closeBrace = this.element.createChild('div', 'sidebar-pane-closing-brace '); 628 var closeBrace = this._innerElement.createChild('div', 'sidebar-pane-closing -brace');
611 closeBrace.textContent = '}'; 629 closeBrace.textContent = '}';
612 630
613 this._createHoverMenuToolbar(closeBrace); 631 this._createHoverMenuToolbar(closeBrace);
614 632
615 this._selectorElement.addEventListener('click', this._handleSelectorClick.bi nd(this), false); 633 this._selectorElement.addEventListener('click', this._handleSelectorClick.bi nd(this), false);
616 this.element.addEventListener('mousedown', this._handleEmptySpaceMouseDown.b ind(this), false); 634 this.element.addEventListener('mousedown', this._handleEmptySpaceMouseDown.b ind(this), false);
617 this.element.addEventListener('click', this._handleEmptySpaceClick.bind(this ), false); 635 this.element.addEventListener('click', this._handleEmptySpaceClick.bind(this ), false);
618 this.element.addEventListener('mousemove', this._onMouseMove.bind(this), fal se); 636 this.element.addEventListener('mousemove', this._onMouseMove.bind(this), fal se);
619 this.element.addEventListener('mouseleave', this._setSectionHovered.bind(thi s, false), false); 637 this.element.addEventListener('mouseleave', this._setSectionHovered.bind(thi s, false), false);
620 638
(...skipping 18 matching lines...) Expand all
639 this._selectorContainer = selectorContainer; 657 this._selectorContainer = selectorContainer;
640 658
641 if (this.navigable) 659 if (this.navigable)
642 this.element.classList.add('navigable'); 660 this.element.classList.add('navigable');
643 661
644 if (!this.editable) { 662 if (!this.editable) {
645 this.element.classList.add('read-only'); 663 this.element.classList.add('read-only');
646 this.propertiesTreeOutline.element.classList.add('read-only'); 664 this.propertiesTreeOutline.element.classList.add('read-only');
647 } 665 }
648 666
667 var throttler = new Common.Throttler(100);
668 this._scheduleHeightUpdate = () => throttler.schedule(this._manuallySetHeigh t.bind(this));
669
649 this._hoverableSelectorsMode = false; 670 this._hoverableSelectorsMode = false;
650 this._markSelectorMatches(); 671 this._markSelectorMatches();
651 this.onpopulate(); 672 this.onpopulate();
652 } 673 }
653 674
654 /** 675 /**
655 * @param {!SDK.CSSMatchedStyles} matchedStyles 676 * @param {!SDK.CSSMatchedStyles} matchedStyles
656 * @param {!Components.Linkifier} linkifier 677 * @param {!Components.Linkifier} linkifier
657 * @param {?SDK.CSSRule} rule 678 * @param {?SDK.CSSRule} rule
658 * @return {!Node} 679 * @return {!Node}
(...skipping 633 matching lines...) Expand 10 before | Expand all | Expand 10 after
1292 return; 1313 return;
1293 } 1314 }
1294 1315
1295 if (!this.editable || this._isSASSStyle()) 1316 if (!this.editable || this._isSASSStyle())
1296 return; 1317 return;
1297 1318
1298 var config = new UI.InplaceEditor.Config( 1319 var config = new UI.InplaceEditor.Config(
1299 this._editingMediaCommitted.bind(this, media), this._editingMediaCancell ed.bind(this, element), undefined, 1320 this._editingMediaCommitted.bind(this, media), this._editingMediaCancell ed.bind(this, element), undefined,
1300 this._editingMediaBlurHandler.bind(this)); 1321 this._editingMediaBlurHandler.bind(this));
1301 UI.InplaceEditor.startEditing(element, config); 1322 UI.InplaceEditor.startEditing(element, config);
1323 this._startEditing();
1302 1324
1303 element.getComponentSelection().selectAllChildren(element); 1325 element.getComponentSelection().selectAllChildren(element);
1304 this._parentPane.setEditingStyle(true); 1326 this._parentPane.setEditingStyle(true);
1305 var parentMediaElement = element.enclosingNodeOrSelfWithClass('media'); 1327 var parentMediaElement = element.enclosingNodeOrSelfWithClass('media');
1306 parentMediaElement.classList.add('editing-media'); 1328 parentMediaElement.classList.add('editing-media');
1307 1329
1308 event.consume(true); 1330 event.consume(true);
1309 } 1331 }
1310 1332
1311 /** 1333 /**
1312 * @param {!Element} element 1334 * @param {!Element} element
1313 */ 1335 */
1314 _editingMediaFinished(element) { 1336 _editingMediaFinished(element) {
1315 this._parentPane.setEditingStyle(false); 1337 this._parentPane.setEditingStyle(false);
1316 var parentMediaElement = element.enclosingNodeOrSelfWithClass('media'); 1338 var parentMediaElement = element.enclosingNodeOrSelfWithClass('media');
1317 parentMediaElement.classList.remove('editing-media'); 1339 parentMediaElement.classList.remove('editing-media');
1340 this._stopEditing();
1318 } 1341 }
1319 1342
1320 /** 1343 /**
1321 * @param {!Element} element 1344 * @param {!Element} element
1322 */ 1345 */
1323 _editingMediaCancelled(element) { 1346 _editingMediaCancelled(element) {
1324 this._editingMediaFinished(element); 1347 this._editingMediaFinished(element);
1325 // Mark the selectors in group if necessary. 1348 // Mark the selectors in group if necessary.
1326 // This is overridden by BlankStylePropertiesSection. 1349 // This is overridden by BlankStylePropertiesSection.
1327 this._markSelectorMatches(); 1350 this._markSelectorMatches();
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1423 var element = this._selectorElement; 1446 var element = this._selectorElement;
1424 if (UI.isBeingEdited(element)) 1447 if (UI.isBeingEdited(element))
1425 return; 1448 return;
1426 1449
1427 element.scrollIntoViewIfNeeded(false); 1450 element.scrollIntoViewIfNeeded(false);
1428 element.textContent = element.textContent; // Reset selector marks in group . 1451 element.textContent = element.textContent; // Reset selector marks in group .
1429 1452
1430 var config = 1453 var config =
1431 new UI.InplaceEditor.Config(this.editingSelectorCommitted.bind(this), th is.editingSelectorCancelled.bind(this)); 1454 new UI.InplaceEditor.Config(this.editingSelectorCommitted.bind(this), th is.editingSelectorCancelled.bind(this));
1432 UI.InplaceEditor.startEditing(this._selectorElement, config); 1455 UI.InplaceEditor.startEditing(this._selectorElement, config);
1456 this._startEditing();
1433 1457
1434 element.getComponentSelection().selectAllChildren(element); 1458 element.getComponentSelection().selectAllChildren(element);
1435 this._parentPane.setEditingStyle(true); 1459 this._parentPane.setEditingStyle(true);
1436 if (element.classList.contains('simple-selector')) 1460 if (element.classList.contains('simple-selector'))
1437 this._navigateToSelectorSource(0, false); 1461 this._navigateToSelectorSource(0, false);
1438 } 1462 }
1439 1463
1440 /** 1464 /**
1441 * @param {string} moveDirection 1465 * @param {string} moveDirection
1442 */ 1466 */
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
1539 } 1563 }
1540 1564
1541 _updateRuleOrigin() { 1565 _updateRuleOrigin() {
1542 this._selectorRefElement.removeChildren(); 1566 this._selectorRefElement.removeChildren();
1543 this._selectorRefElement.appendChild(Elements.StylePropertiesSection.createR uleOriginNode( 1567 this._selectorRefElement.appendChild(Elements.StylePropertiesSection.createR uleOriginNode(
1544 this._matchedStyles, this._parentPane._linkifier, this._style.parentRule )); 1568 this._matchedStyles, this._parentPane._linkifier, this._style.parentRule ));
1545 } 1569 }
1546 1570
1547 _editingSelectorEnded() { 1571 _editingSelectorEnded() {
1548 this._parentPane.setEditingStyle(false); 1572 this._parentPane.setEditingStyle(false);
1573 this._stopEditing();
1549 } 1574 }
1550 1575
1551 editingSelectorCancelled() { 1576 editingSelectorCancelled() {
1552 this._editingSelectorEnded(); 1577 this._editingSelectorEnded();
1553 1578
1554 // Mark the selectors in group if necessary. 1579 // Mark the selectors in group if necessary.
1555 // This is overridden by BlankStylePropertiesSection. 1580 // This is overridden by BlankStylePropertiesSection.
1556 this._markSelectorMatches(); 1581 this._markSelectorMatches();
1557 } 1582 }
1583
1584 _startEditing() {
1585 this._manuallySetHeight();
1586 this.element.addEventListener('input', this._scheduleHeightUpdate, true);
1587 }
1588
1589 /**
1590 * @return {!Promise}
1591 */
1592 _manuallySetHeight() {
1593 this.element.style.height = this._innerElement.clientHeight + 'px';
1594 this.element.style.contain = 'strict';
1595 return Promise.resolve();
1596 }
1597
1598 _stopEditing() {
1599 this.element.style.removeProperty('height');
1600 this.element.style.removeProperty('contain');
1601 this.element.removeEventListener('input', this._scheduleHeightUpdate, true);
1602 }
1558 }; 1603 };
1559 1604
1560 Elements.BlankStylePropertiesSection = class extends Elements.StylePropertiesSec tion { 1605 Elements.BlankStylePropertiesSection = class extends Elements.StylePropertiesSec tion {
1561 /** 1606 /**
1562 * @param {!Elements.StylesSidebarPane} stylesPane 1607 * @param {!Elements.StylesSidebarPane} stylesPane
1563 * @param {!SDK.CSSMatchedStyles} matchedStyles 1608 * @param {!SDK.CSSMatchedStyles} matchedStyles
1564 * @param {string} defaultSelectorText 1609 * @param {string} defaultSelectorText
1565 * @param {string} styleSheetId 1610 * @param {string} styleSheetId
1566 * @param {!TextUtils.TextRange} ruleLocation 1611 * @param {!TextUtils.TextRange} ruleLocation
1567 * @param {!SDK.CSSStyleDeclaration} insertAfterStyle 1612 * @param {!SDK.CSSStyleDeclaration} insertAfterStyle
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after
2362 cssCompletions = SDK.cssMetadata().allProperties(); 2407 cssCompletions = SDK.cssMetadata().allProperties();
2363 cssCompletions = 2408 cssCompletions =
2364 cssCompletions.filter(property => SDK.cssMetadata().isSVGProperty(prop erty) === this.node().isSVGNode()); 2409 cssCompletions.filter(property => SDK.cssMetadata().isSVGProperty(prop erty) === this.node().isSVGNode());
2365 } else { 2410 } else {
2366 cssCompletions = SDK.cssMetadata().propertyValues(this.nameElement.textCon tent); 2411 cssCompletions = SDK.cssMetadata().propertyValues(this.nameElement.textCon tent);
2367 } 2412 }
2368 var cssVariables = this._matchedStyles.cssVariables().sort(String.naturalOrd erComparator); 2413 var cssVariables = this._matchedStyles.cssVariables().sort(String.naturalOrd erComparator);
2369 2414
2370 this._prompt = new Elements.StylesSidebarPane.CSSPropertyPrompt(cssCompletio ns, cssVariables, this, isEditingName); 2415 this._prompt = new Elements.StylesSidebarPane.CSSPropertyPrompt(cssCompletio ns, cssVariables, this, isEditingName);
2371 this._prompt.setAutocompletionTimeout(0); 2416 this._prompt.setAutocompletionTimeout(0);
2417 if (section)
2418 section._startEditing();
2372 2419
2373 // Do not live-edit "content" property of pseudo elements. crbug.com/433889 2420 // Do not live-edit "content" property of pseudo elements. crbug.com/433889
2374 if (!isEditingName && (!this._parentPane.node().pseudoType() || this.name != = 'content')) 2421 if (!isEditingName && (!this._parentPane.node().pseudoType() || this.name != = 'content'))
2375 this._prompt.addEventListener(UI.TextPrompt.Events.TextChanged, this._appl yFreeFlowStyleTextEdit.bind(this)); 2422 this._prompt.addEventListener(UI.TextPrompt.Events.TextChanged, this._appl yFreeFlowStyleTextEdit.bind(this));
2376 2423
2377 var proxyElement = this._prompt.attachAndStartEditing(selectElement, blurLis tener.bind(this, context)); 2424 var proxyElement = this._prompt.attachAndStartEditing(selectElement, blurLis tener.bind(this, context));
2378 this._navigateToSource(selectElement, true); 2425 this._navigateToSource(selectElement, true);
2379 2426
2380 proxyElement.addEventListener('keydown', this._editingNameValueKeyDown.bind( this, context), false); 2427 proxyElement.addEventListener('keydown', this._editingNameValueKeyDown.bind( this, context), false);
2381 proxyElement.addEventListener('keypress', this._editingNameValueKeyPress.bin d(this, context), false); 2428 proxyElement.addEventListener('keypress', this._editingNameValueKeyPress.bin d(this, context), false);
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
2656 } 2703 }
2657 } 2704 }
2658 } 2705 }
2659 2706
2660 _removePrompt() { 2707 _removePrompt() {
2661 // BUG 53242. This cannot go into editingEnded(), as it should always happen first for any editing outcome. 2708 // BUG 53242. This cannot go into editingEnded(), as it should always happen first for any editing outcome.
2662 if (this._prompt) { 2709 if (this._prompt) {
2663 this._prompt.detach(); 2710 this._prompt.detach();
2664 this._prompt = null; 2711 this._prompt = null;
2665 } 2712 }
2713 var section = this.section();
2714 if (section)
2715 section._stopEditing();
2666 } 2716 }
2667 2717
2668 styleTextAppliedForTest() { 2718 styleTextAppliedForTest() {
2669 } 2719 }
2670 2720
2671 /** 2721 /**
2672 * @param {string} styleText 2722 * @param {string} styleText
2673 * @param {boolean} majorChange 2723 * @param {boolean} majorChange
2674 */ 2724 */
2675 applyStyleText(styleText, majorChange) { 2725 applyStyleText(styleText, majorChange) {
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
3092 } 3142 }
3093 3143
3094 /** 3144 /**
3095 * @override 3145 * @override
3096 * @return {!UI.ToolbarItem} 3146 * @return {!UI.ToolbarItem}
3097 */ 3147 */
3098 item() { 3148 item() {
3099 return this._button; 3149 return this._button;
3100 } 3150 }
3101 }; 3151 };
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/devtools/front_end/elements/elementsPanel.css » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698