Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> | 3 * Copyright (C) 2008 Matt Lilek <webkit@mattlilek.com> |
| 4 * Copyright (C) 2009 Joseph Pecoraro | 4 * Copyright (C) 2009 Joseph Pecoraro |
| 5 * | 5 * |
| 6 * Redistribution and use in source and binary forms, with or without | 6 * Redistribution and use in source and binary forms, with or without |
| 7 * modification, are permitted provided that the following conditions | 7 * modification, are permitted provided that the following conditions |
| 8 * are met: | 8 * are met: |
| 9 * | 9 * |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 739 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 750 child = child.nextSibling; | 750 child = child.nextSibling; |
| 751 } | 751 } |
| 752 // Hide children item. | 752 // Hide children item. |
| 753 if (this.childrenListElement) | 753 if (this.childrenListElement) |
| 754 this.childrenListElement.style.display = 'none'; | 754 this.childrenListElement.style.display = 'none'; |
| 755 // Append editor. | 755 // Append editor. |
| 756 this.listItemElement.appendChild(this._htmlEditElement); | 756 this.listItemElement.appendChild(this._htmlEditElement); |
| 757 this.listItemElement.classList.add('editing-as-html'); | 757 this.listItemElement.classList.add('editing-as-html'); |
| 758 this.treeOutline.element.addEventListener('mousedown', consume, false); | 758 this.treeOutline.element.addEventListener('mousedown', consume, false); |
| 759 | 759 |
| 760 self.runtime.extension(UI.TextEditorFactory).instance().then(gotFactory.bind (this)); | |
| 761 | |
| 760 /** | 762 /** |
| 761 * @param {!Element} element | 763 * @param {!UI.TextEditorFactory} factory |
| 762 * @param {string} newValue | |
| 763 * @this {Elements.ElementsTreeElement} | 764 * @this {Elements.ElementsTreeElement} |
| 764 */ | 765 */ |
| 765 function commit(element, newValue) { | 766 function gotFactory(factory) { |
| 766 commitCallback(initialValue, newValue); | 767 var editor = factory.createEditor({ |
| 767 dispose.call(this); | 768 lineNumbers: false, |
| 769 lineWrapping: Common.moduleSetting('domWordWrap').get(), | |
| 770 mimeType: 'text/html', | |
| 771 autoHeight: false, | |
| 772 padBottom: false | |
| 773 }); | |
| 774 this._htmlEditElement.style.width = this.treeOutline.visibleWidth() - this ._computeLeftIndent() - 30 + 'px'; | |
| 775 editor.widget().show(this._htmlEditElement); | |
| 776 editor.setText(initialValue); | |
| 777 editor.widget().focus(); | |
| 778 this._editing = {commit: commit.bind(this), cancel: cancel.bind(this), edi tor: editor}; | |
| 779 this.treeOutline.setMultilineEditing(this._editing); | |
| 780 editor.widget().element.addEventListener('blur', this._editing.commit, tru e); | |
| 781 editor.widget().element.addEventListener('keydown', keydown.bind(this), tr ue); | |
| 768 } | 782 } |
| 769 | 783 |
| 770 /** | 784 /** |
| 771 * @this {Elements.ElementsTreeElement} | 785 * @this {Elements.ElementsTreeElement} |
| 772 */ | 786 */ |
| 773 function dispose() { | 787 function commit() { |
| 774 disposeCallback(); | 788 commitCallback(initialValue, this._editing.editor.text()); |
| 789 this._editing.cancel(); | |
| 790 } | |
| 791 | |
| 792 /** | |
| 793 * @this {Elements.ElementsTreeElement} | |
| 794 */ | |
| 795 function cancel() { | |
|
lushnikov
2017/03/01 23:52:48
let's name this dispose (and call dispose.all(this
einbinder
2017/03/02 00:25:09
Done.
| |
| 796 this._editing.editor.widget().element.removeEventListener('blur', this._ed iting.commit, true); | |
| 797 this._editing.editor.widget().detach(); | |
| 775 delete this._editing; | 798 delete this._editing; |
| 776 this.treeOutline.setMultilineEditing(null); | |
| 777 | 799 |
| 778 this.listItemElement.classList.remove('editing-as-html'); | 800 this.listItemElement.classList.remove('editing-as-html'); |
| 779 // Remove editor. | 801 // Remove editor. |
| 780 this.listItemElement.removeChild(this._htmlEditElement); | 802 this.listItemElement.removeChild(this._htmlEditElement); |
| 781 delete this._htmlEditElement; | 803 delete this._htmlEditElement; |
| 782 // Unhide children item. | 804 // Unhide children item. |
| 783 if (this.childrenListElement) | 805 if (this.childrenListElement) |
| 784 this.childrenListElement.style.removeProperty('display'); | 806 this.childrenListElement.style.removeProperty('display'); |
| 785 // Unhide header items. | 807 // Unhide header items. |
| 786 var child = this.listItemElement.firstChild; | 808 var child = this.listItemElement.firstChild; |
| 787 while (child) { | 809 while (child) { |
| 788 child.style.removeProperty('display'); | 810 child.style.removeProperty('display'); |
| 789 child = child.nextSibling; | 811 child = child.nextSibling; |
| 790 } | 812 } |
| 791 | 813 |
| 814 disposeCallback(); | |
|
lushnikov
2017/03/01 23:52:47
let's call this as the very-last line of the metho
einbinder
2017/03/02 00:25:09
Done.
| |
| 815 if (!this.treeOutline) | |
| 816 return; | |
| 817 | |
| 792 this.treeOutline.element.removeEventListener('mousedown', consume, false); | 818 this.treeOutline.element.removeEventListener('mousedown', consume, false); |
| 793 this.treeOutline.focus(); | 819 this.treeOutline.focus(); |
| 794 } | 820 } |
| 795 | 821 |
| 796 var config = new UI.InplaceEditor.Config(commit.bind(this), dispose.bind(thi s)); | |
| 797 config.setMultilineOptions( | |
| 798 initialValue, {name: 'xml', htmlMode: true}, 'web-inspector-html', Commo n.moduleSetting('domWordWrap').get(), | |
| 799 true); | |
| 800 UI.InplaceEditor.startMultilineEditing(this._htmlEditElement, config).then(m arkAsBeingEdited.bind(this)); | |
| 801 | |
| 802 /** | 822 /** |
| 803 * @param {!Object} controller | 823 * @param {!Event} event |
| 804 * @this {Elements.ElementsTreeElement} | 824 * @this {!Elements.ElementsTreeElement} |
| 805 */ | 825 */ |
| 806 function markAsBeingEdited(controller) { | 826 function keydown(event) { |
| 807 this._editing = /** @type {!UI.InplaceEditor.Controller} */ (controller); | 827 var isMetaOrCtrl = Host.isMac() ? event.metaKey && !event.shiftKey && !eve nt.ctrlKey && !event.altKey : |
|
lushnikov
2017/03/01 23:52:47
KeyboardShortcuts.eventHasCtrlOrMeta
einbinder
2017/03/02 00:25:09
Done.
| |
| 808 this._editing.setWidth(this.treeOutline.visibleWidth() - this._computeLeft Indent()); | 828 event.ctrlKey && !event.shiftKey && !eve nt.metaKey && !event.altKey; |
| 809 this.treeOutline.setMultilineEditing(this._editing); | 829 if (isEnterKey(event) && (isMetaOrCtrl || event.isMetaOrCtrlForTest)) { |
|
lushnikov
2017/03/01 23:52:48
Occassionally i hit this exception:
ElementsTreeE
einbinder
2017/03/02 00:25:09
Done.
| |
| 830 event.consume(true); | |
| 831 this._editing.commit(); | |
| 832 } else if (event.keyCode === UI.KeyboardShortcut.Keys.Esc.code || event.ke y === 'Escape') { | |
| 833 event.consume(true); | |
| 834 this._editing.cancel(); | |
| 835 } | |
| 810 } | 836 } |
| 811 } | 837 } |
| 812 | 838 |
| 813 _attributeEditingCommitted(element, newText, oldText, attributeName, moveDirec tion) { | 839 _attributeEditingCommitted(element, newText, oldText, attributeName, moveDirec tion) { |
| 814 delete this._editing; | 840 delete this._editing; |
| 815 | 841 |
| 816 var treeOutline = this.treeOutline; | 842 var treeOutline = this.treeOutline; |
| 817 | 843 |
| 818 /** | 844 /** |
| 819 * @param {?Protocol.Error=} error | 845 * @param {?Protocol.Error=} error |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1465 if (!this._node.parentNode || this._node.parentNode.nodeType() === Node.DOCU MENT_NODE) | 1491 if (!this._node.parentNode || this._node.parentNode.nodeType() === Node.DOCU MENT_NODE) |
| 1466 return; | 1492 return; |
| 1467 this._node.removeNode(); | 1493 this._node.removeNode(); |
| 1468 } | 1494 } |
| 1469 | 1495 |
| 1470 /** | 1496 /** |
| 1471 * @param {function(boolean)=} callback | 1497 * @param {function(boolean)=} callback |
| 1472 * @param {boolean=} startEditing | 1498 * @param {boolean=} startEditing |
| 1473 */ | 1499 */ |
| 1474 toggleEditAsHTML(callback, startEditing) { | 1500 toggleEditAsHTML(callback, startEditing) { |
| 1475 if (this._editing && this._htmlEditElement && UI.isBeingEdited(this._htmlEdi tElement)) { | 1501 if (this._editing && this._htmlEditElement) { |
| 1476 this._editing.commit(); | 1502 this._editing.commit(); |
| 1477 return; | 1503 return; |
| 1478 } | 1504 } |
| 1479 | 1505 |
| 1480 if (startEditing === false) | 1506 if (startEditing === false) |
| 1481 return; | 1507 return; |
| 1482 | 1508 |
| 1483 /** | 1509 /** |
| 1484 * @param {?Protocol.Error} error | 1510 * @param {?Protocol.Error} error |
| 1485 */ | 1511 */ |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1566 | 1592 |
| 1567 // A union of HTML4 and HTML5-Draft elements that explicitly | 1593 // A union of HTML4 and HTML5-Draft elements that explicitly |
| 1568 // or implicitly (for HTML5) forbid the closing tag. | 1594 // or implicitly (for HTML5) forbid the closing tag. |
| 1569 Elements.ElementsTreeElement.ForbiddenClosingTagElements = new Set([ | 1595 Elements.ElementsTreeElement.ForbiddenClosingTagElements = new Set([ |
| 1570 'area', 'base', 'basefont', 'br', 'canvas', 'col', 'command', 'embed', 'frame', 'hr', | 1596 'area', 'base', 'basefont', 'br', 'canvas', 'col', 'command', 'embed', 'frame', 'hr', |
| 1571 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr' | 1597 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr' |
| 1572 ]); | 1598 ]); |
| 1573 | 1599 |
| 1574 // These tags we do not allow editing their tag name. | 1600 // These tags we do not allow editing their tag name. |
| 1575 Elements.ElementsTreeElement.EditTagBlacklist = new Set(['html', 'head', 'body'] ); | 1601 Elements.ElementsTreeElement.EditTagBlacklist = new Set(['html', 'head', 'body'] ); |
| OLD | NEW |