| 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({ |
| 768 lineNumbers: false, |
| 769 lineWrapping: Common.moduleSetting('domWordWrap').get(), |
| 770 mimeType: 'text/html', |
| 771 autoHeight: false, |
| 772 padBottom: false |
| 773 }); |
| 774 this._editing = |
| 775 {commit: commit.bind(this), cancel: dispose.bind(this), editor: editor
, resize: resize.bind(this)}; |
| 776 resize.call(this); |
| 777 |
| 778 editor.widget().show(this._htmlEditElement); |
| 779 editor.setText(initialValue); |
| 780 editor.widget().focus(); |
| 781 editor.widget().element.addEventListener('blur', this._editing.commit, tru
e); |
| 782 editor.widget().element.addEventListener('keydown', keydown.bind(this), tr
ue); |
| 783 |
| 784 this.treeOutline.setMultilineEditing(this._editing); |
| 785 } |
| 786 |
| 787 /** |
| 788 * @this {Elements.ElementsTreeElement} |
| 789 */ |
| 790 function resize() { |
| 791 this._htmlEditElement.style.width = this.treeOutline.visibleWidth() - this
._computeLeftIndent() - 30 + 'px'; |
| 792 this._editing.editor.onResize(); |
| 793 } |
| 794 |
| 795 /** |
| 796 * @this {Elements.ElementsTreeElement} |
| 797 */ |
| 798 function commit() { |
| 799 commitCallback(initialValue, this._editing.editor.text()); |
| 767 dispose.call(this); | 800 dispose.call(this); |
| 768 } | 801 } |
| 769 | 802 |
| 770 /** | 803 /** |
| 771 * @this {Elements.ElementsTreeElement} | 804 * @this {Elements.ElementsTreeElement} |
| 772 */ | 805 */ |
| 773 function dispose() { | 806 function dispose() { |
| 774 disposeCallback(); | 807 this._editing.editor.widget().element.removeEventListener('blur', this._ed
iting.commit, true); |
| 808 this._editing.editor.widget().detach(); |
| 775 delete this._editing; | 809 delete this._editing; |
| 776 this.treeOutline.setMultilineEditing(null); | |
| 777 | 810 |
| 778 this.listItemElement.classList.remove('editing-as-html'); | 811 this.listItemElement.classList.remove('editing-as-html'); |
| 779 // Remove editor. | 812 // Remove editor. |
| 780 this.listItemElement.removeChild(this._htmlEditElement); | 813 this.listItemElement.removeChild(this._htmlEditElement); |
| 781 delete this._htmlEditElement; | 814 delete this._htmlEditElement; |
| 782 // Unhide children item. | 815 // Unhide children item. |
| 783 if (this.childrenListElement) | 816 if (this.childrenListElement) |
| 784 this.childrenListElement.style.removeProperty('display'); | 817 this.childrenListElement.style.removeProperty('display'); |
| 785 // Unhide header items. | 818 // Unhide header items. |
| 786 var child = this.listItemElement.firstChild; | 819 var child = this.listItemElement.firstChild; |
| 787 while (child) { | 820 while (child) { |
| 788 child.style.removeProperty('display'); | 821 child.style.removeProperty('display'); |
| 789 child = child.nextSibling; | 822 child = child.nextSibling; |
| 790 } | 823 } |
| 791 | 824 |
| 792 this.treeOutline.element.removeEventListener('mousedown', consume, false); | 825 if (this.treeOutline) { |
| 793 this.treeOutline.focus(); | 826 this.treeOutline.setMultilineEditing(null); |
| 827 this.treeOutline.element.removeEventListener('mousedown', consume, false
); |
| 828 this.treeOutline.focus(); |
| 829 } |
| 830 |
| 831 disposeCallback(); |
| 794 } | 832 } |
| 795 | 833 |
| 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 /** | 834 /** |
| 803 * @param {!Object} controller | 835 * @param {!Event} event |
| 804 * @this {Elements.ElementsTreeElement} | 836 * @this {!Elements.ElementsTreeElement} |
| 805 */ | 837 */ |
| 806 function markAsBeingEdited(controller) { | 838 function keydown(event) { |
| 807 this._editing = /** @type {!UI.InplaceEditor.Controller} */ (controller); | 839 var isMetaOrCtrl = UI.KeyboardShortcut.eventHasCtrlOrMeta(/** @type {!Keyb
oardEvent} */ (event)) && |
| 808 this._editing.setWidth(this.treeOutline.visibleWidth() - this._computeLeft
Indent()); | 840 !event.altKey && !event.shiftKey; |
| 809 this.treeOutline.setMultilineEditing(this._editing); | 841 if (isEnterKey(event) && (isMetaOrCtrl || event.isMetaOrCtrlForTest)) { |
| 842 event.consume(true); |
| 843 this._editing.commit(); |
| 844 } else if (event.keyCode === UI.KeyboardShortcut.Keys.Esc.code || event.ke
y === 'Escape') { |
| 845 event.consume(true); |
| 846 this._editing.cancel(); |
| 847 } |
| 810 } | 848 } |
| 811 } | 849 } |
| 812 | 850 |
| 813 _attributeEditingCommitted(element, newText, oldText, attributeName, moveDirec
tion) { | 851 _attributeEditingCommitted(element, newText, oldText, attributeName, moveDirec
tion) { |
| 814 delete this._editing; | 852 delete this._editing; |
| 815 | 853 |
| 816 var treeOutline = this.treeOutline; | 854 var treeOutline = this.treeOutline; |
| 817 | 855 |
| 818 /** | 856 /** |
| 819 * @param {?Protocol.Error=} error | 857 * @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) | 1503 if (!this._node.parentNode || this._node.parentNode.nodeType() === Node.DOCU
MENT_NODE) |
| 1466 return; | 1504 return; |
| 1467 this._node.removeNode(); | 1505 this._node.removeNode(); |
| 1468 } | 1506 } |
| 1469 | 1507 |
| 1470 /** | 1508 /** |
| 1471 * @param {function(boolean)=} callback | 1509 * @param {function(boolean)=} callback |
| 1472 * @param {boolean=} startEditing | 1510 * @param {boolean=} startEditing |
| 1473 */ | 1511 */ |
| 1474 toggleEditAsHTML(callback, startEditing) { | 1512 toggleEditAsHTML(callback, startEditing) { |
| 1475 if (this._editing && this._htmlEditElement && UI.isBeingEdited(this._htmlEdi
tElement)) { | 1513 if (this._editing && this._htmlEditElement) { |
| 1476 this._editing.commit(); | 1514 this._editing.commit(); |
| 1477 return; | 1515 return; |
| 1478 } | 1516 } |
| 1479 | 1517 |
| 1480 if (startEditing === false) | 1518 if (startEditing === false) |
| 1481 return; | 1519 return; |
| 1482 | 1520 |
| 1483 /** | 1521 /** |
| 1484 * @param {?Protocol.Error} error | 1522 * @param {?Protocol.Error} error |
| 1485 */ | 1523 */ |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1566 | 1604 |
| 1567 // A union of HTML4 and HTML5-Draft elements that explicitly | 1605 // A union of HTML4 and HTML5-Draft elements that explicitly |
| 1568 // or implicitly (for HTML5) forbid the closing tag. | 1606 // or implicitly (for HTML5) forbid the closing tag. |
| 1569 Elements.ElementsTreeElement.ForbiddenClosingTagElements = new Set([ | 1607 Elements.ElementsTreeElement.ForbiddenClosingTagElements = new Set([ |
| 1570 'area', 'base', 'basefont', 'br', 'canvas', 'col', 'command', 'embed',
'frame', 'hr', | 1608 'area', 'base', 'basefont', 'br', 'canvas', 'col', 'command', 'embed',
'frame', 'hr', |
| 1571 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source',
'track', 'wbr' | 1609 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source',
'track', 'wbr' |
| 1572 ]); | 1610 ]); |
| 1573 | 1611 |
| 1574 // These tags we do not allow editing their tag name. | 1612 // These tags we do not allow editing their tag name. |
| 1575 Elements.ElementsTreeElement.EditTagBlacklist = new Set(['html', 'head', 'body']
); | 1613 Elements.ElementsTreeElement.EditTagBlacklist = new Set(['html', 'head', 'body']
); |
| 1614 |
| 1615 /** @typedef {{cancel: function(), commit: function(), resize: function(), edito
r:!UI.TextEditor}} */ |
| 1616 Elements.MultilineEditorController; |
| OLD | NEW |