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 790 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 801 child = child.nextSibling; | 801 child = child.nextSibling; |
| 802 } | 802 } |
| 803 // Hide children item. | 803 // Hide children item. |
| 804 if (this._childrenListNode) | 804 if (this._childrenListNode) |
| 805 this._childrenListNode.style.display = "none"; | 805 this._childrenListNode.style.display = "none"; |
| 806 // Append editor. | 806 // Append editor. |
| 807 this.listItemElement.appendChild(this._htmlEditElement); | 807 this.listItemElement.appendChild(this._htmlEditElement); |
| 808 this.listItemElement.classList.add("editing-as-html"); | 808 this.listItemElement.classList.add("editing-as-html"); |
| 809 this.treeOutline.element.addEventListener("mousedown", consume, false); | 809 this.treeOutline.element.addEventListener("mousedown", consume, false); |
| 810 | 810 |
| 811 self.runtime.extension(WebInspector.TextEditorFactory).instance().then(g otFactory.bind(this)); | |
| 812 | |
| 811 /** | 813 /** |
| 812 * @param {!Element} element | 814 * @param {!WebInspector.TextEditorFactory} factory |
| 813 * @param {string} newValue | |
| 814 * @this {WebInspector.ElementsTreeElement} | 815 * @this {WebInspector.ElementsTreeElement} |
| 815 */ | 816 */ |
| 816 function commit(element, newValue) | 817 function gotFactory(factory) |
| 817 { | 818 { |
| 818 commitCallback(initialValue, newValue); | 819 var editor = factory.createEditor({ |
| 819 dispose.call(this); | 820 lineNumbers: false, |
| 821 lineWrapping: WebInspector.moduleSetting("domWordWrap").get(), | |
| 822 mimeType: "text/html", | |
| 823 autoHeight: false | |
| 824 }); | |
| 825 editor.widget().show(this._htmlEditElement); | |
| 826 editor.setText(initialValue); | |
| 827 editor.widget().focus(); | |
| 828 var cancelled = false; | |
| 829 this._editing = { | |
| 830 commit: commit.bind(this), | |
| 831 cancel: cancel.bind(this), | |
| 832 editorForTest: editor | |
| 833 } | |
| 834 this.treeOutline.setMultilineEditing(this._editing); | |
| 835 // editor.widget().element.addEventListener("blur", this._editing.co mmit, true); | |
|
lushnikov
2016/09/29 21:16:26
drop
| |
| 836 editor.widget().element.addEventListener("keydown", keydown.bind(thi s), true); | |
| 837 | |
| 838 /** | |
| 839 * @this {WebInspector.ElementsTreeElement} | |
| 840 */ | |
| 841 function cancel() | |
| 842 { | |
| 843 editor.widget().element.removeEventListener("blur", this._editin g.commit); | |
| 844 editor.widget().detach(); | |
| 845 delete this._editing; | |
| 846 | |
| 847 this.listItemElement.classList.remove("editing-as-html"); | |
| 848 // Remove editor. | |
| 849 this.listItemElement.removeChild(this._htmlEditElement); | |
| 850 delete this._htmlEditElement; | |
| 851 // Unhide children item. | |
| 852 if (this._childrenListNode) | |
| 853 this._childrenListNode.style.removeProperty("display"); | |
| 854 // Unhide header items. | |
| 855 var child = this.listItemElement.firstChild; | |
| 856 while (child) { | |
| 857 child.style.removeProperty("display"); | |
| 858 child = child.nextSibling; | |
| 859 } | |
| 860 | |
| 861 disposeCallback(); | |
| 862 | |
| 863 if (!this.treeOutline) | |
| 864 return; | |
| 865 this.treeOutline.element.removeEventListener("mousedown", consum e, false); | |
| 866 this.treeOutline.focus(); | |
| 867 } | |
| 868 | |
| 869 /** | |
| 870 * @this {WebInspector.ElementsTreeElement} | |
| 871 */ | |
| 872 function commit() | |
| 873 { | |
| 874 if (cancelled) | |
| 875 return; | |
| 876 commitCallback(initialValue, editor.text()); | |
| 877 this._editing.cancel.call(this); | |
| 878 } | |
| 879 | |
| 880 /** | |
| 881 * @param {!Event} event | |
| 882 * @this {WebInspector.ElementsTreeElement} | |
| 883 */ | |
| 884 function keydown(event) | |
| 885 { | |
| 886 var isMetaOrCtrl = WebInspector.isMac() ? | |
| 887 event.metaKey && !event.shiftKey && !event.ctrlKey && !event .altKey : | |
| 888 event.ctrlKey && !event.shiftKey && !event.metaKey && !event .altKey; | |
| 889 | |
| 890 if (isEnterKey(event) && (isMetaOrCtrl || event.isMetaOrCtrlForT est)) | |
| 891 this._editing.commit(); | |
| 892 else if (event.key === "Escape") | |
| 893 this._editing.cancel(); | |
| 894 } | |
| 820 } | 895 } |
| 821 | 896 |
| 822 /** | |
| 823 * @this {WebInspector.ElementsTreeElement} | |
| 824 */ | |
| 825 function dispose() | |
| 826 { | |
| 827 disposeCallback(); | |
| 828 delete this._editing; | |
| 829 this.treeOutline.setMultilineEditing(null); | |
| 830 | |
| 831 this.listItemElement.classList.remove("editing-as-html"); | |
| 832 // Remove editor. | |
| 833 this.listItemElement.removeChild(this._htmlEditElement); | |
| 834 delete this._htmlEditElement; | |
| 835 // Unhide children item. | |
| 836 if (this._childrenListNode) | |
| 837 this._childrenListNode.style.removeProperty("display"); | |
| 838 // Unhide header items. | |
| 839 var child = this.listItemElement.firstChild; | |
| 840 while (child) { | |
| 841 child.style.removeProperty("display"); | |
| 842 child = child.nextSibling; | |
| 843 } | |
| 844 | |
| 845 this.treeOutline.element.removeEventListener("mousedown", consume, f alse); | |
| 846 this.treeOutline.focus(); | |
| 847 } | |
| 848 | |
| 849 var config = new WebInspector.InplaceEditor.Config(commit.bind(this), di spose.bind(this)); | |
| 850 config.setMultilineOptions(initialValue, { name: "xml", htmlMode: true } , "web-inspector-html", WebInspector.moduleSetting("domWordWrap").get(), true); | |
| 851 WebInspector.InplaceEditor.startMultilineEditing(this._htmlEditElement, config).then(markAsBeingEdited.bind(this)); | |
| 852 | |
| 853 /** | |
| 854 * @param {!Object} controller | |
| 855 * @this {WebInspector.ElementsTreeElement} | |
| 856 */ | |
| 857 function markAsBeingEdited(controller) | |
| 858 { | |
| 859 this._editing = /** @type {!WebInspector.InplaceEditor.Controller} * / (controller); | |
| 860 this._editing.setWidth(this.treeOutline.visibleWidth()); | |
| 861 this.treeOutline.setMultilineEditing(this._editing); | |
| 862 } | |
| 863 }, | 897 }, |
| 864 | 898 |
| 865 _attributeEditingCommitted: function(element, newText, oldText, attributeNam e, moveDirection) | 899 _attributeEditingCommitted: function(element, newText, oldText, attributeNam e, moveDirection) |
| 866 { | 900 { |
| 867 delete this._editing; | 901 delete this._editing; |
| 868 | 902 |
| 869 var treeOutline = this.treeOutline; | 903 var treeOutline = this.treeOutline; |
| 870 | 904 |
| 871 /** | 905 /** |
| 872 * @param {?Protocol.Error=} error | 906 * @param {?Protocol.Error=} error |
| (...skipping 654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1527 return; | 1561 return; |
| 1528 this._node.removeNode(); | 1562 this._node.removeNode(); |
| 1529 }, | 1563 }, |
| 1530 | 1564 |
| 1531 /** | 1565 /** |
| 1532 * @param {function(boolean)=} callback | 1566 * @param {function(boolean)=} callback |
| 1533 * @param {boolean=} startEditing | 1567 * @param {boolean=} startEditing |
| 1534 */ | 1568 */ |
| 1535 toggleEditAsHTML: function(callback, startEditing) | 1569 toggleEditAsHTML: function(callback, startEditing) |
| 1536 { | 1570 { |
| 1537 if (this._editing && this._htmlEditElement && WebInspector.isBeingEdited (this._htmlEditElement)) { | 1571 if (this._editing && this._htmlEditElement) { |
| 1538 this._editing.commit(); | 1572 this._editing.commit(); |
| 1539 return; | 1573 return; |
| 1540 } | 1574 } |
| 1541 | 1575 |
| 1542 if (startEditing === false) | 1576 if (startEditing === false) |
| 1543 return; | 1577 return; |
| 1544 | 1578 |
| 1545 /** | 1579 /** |
| 1546 * @param {?Protocol.Error} error | 1580 * @param {?Protocol.Error} error |
| 1547 */ | 1581 */ |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1626 }, | 1660 }, |
| 1627 | 1661 |
| 1628 _editAsHTML: function() | 1662 _editAsHTML: function() |
| 1629 { | 1663 { |
| 1630 var promise = WebInspector.Revealer.revealPromise(this.node()); | 1664 var promise = WebInspector.Revealer.revealPromise(this.node()); |
| 1631 promise.then(() => WebInspector.actionRegistry.action("elements.edit-as- html").execute()); | 1665 promise.then(() => WebInspector.actionRegistry.action("elements.edit-as- html").execute()); |
| 1632 }, | 1666 }, |
| 1633 | 1667 |
| 1634 __proto__: TreeElement.prototype | 1668 __proto__: TreeElement.prototype |
| 1635 } | 1669 } |
| OLD | NEW |