| 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 13 matching lines...) Expand all Loading... |
| 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 24 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 /** | 31 /** |
| 32 * @unrestricted | 32 * @unrestricted |
| 33 */ | 33 */ |
| 34 WebInspector.ElementsTreeElement = class extends TreeElement { | 34 Elements.ElementsTreeElement = class extends TreeElement { |
| 35 /** | 35 /** |
| 36 * @param {!WebInspector.DOMNode} node | 36 * @param {!SDK.DOMNode} node |
| 37 * @param {boolean=} elementCloseTag | 37 * @param {boolean=} elementCloseTag |
| 38 */ | 38 */ |
| 39 constructor(node, elementCloseTag) { | 39 constructor(node, elementCloseTag) { |
| 40 // The title will be updated in onattach. | 40 // The title will be updated in onattach. |
| 41 super(); | 41 super(); |
| 42 this._node = node; | 42 this._node = node; |
| 43 | 43 |
| 44 this._gutterContainer = this.listItemElement.createChild('div', 'gutter-cont
ainer'); | 44 this._gutterContainer = this.listItemElement.createChild('div', 'gutter-cont
ainer'); |
| 45 this._gutterContainer.addEventListener('click', this._showContextMenu.bind(t
his)); | 45 this._gutterContainer.addEventListener('click', this._showContextMenu.bind(t
his)); |
| 46 this._decorationsElement = this._gutterContainer.createChild('div', 'hidden'
); | 46 this._decorationsElement = this._gutterContainer.createChild('div', 'hidden'
); |
| 47 | 47 |
| 48 this._elementCloseTag = elementCloseTag; | 48 this._elementCloseTag = elementCloseTag; |
| 49 | 49 |
| 50 if (this._node.nodeType() === Node.ELEMENT_NODE && !elementCloseTag) | 50 if (this._node.nodeType() === Node.ELEMENT_NODE && !elementCloseTag) |
| 51 this._canAddAttributes = true; | 51 this._canAddAttributes = true; |
| 52 this._searchQuery = null; | 52 this._searchQuery = null; |
| 53 this._expandedChildrenLimit = WebInspector.ElementsTreeElement.InitialChildr
enLimit; | 53 this._expandedChildrenLimit = Elements.ElementsTreeElement.InitialChildrenLi
mit; |
| 54 } | 54 } |
| 55 | 55 |
| 56 /** | 56 /** |
| 57 * @param {!WebInspector.ElementsTreeElement} treeElement | 57 * @param {!Elements.ElementsTreeElement} treeElement |
| 58 */ | 58 */ |
| 59 static animateOnDOMUpdate(treeElement) { | 59 static animateOnDOMUpdate(treeElement) { |
| 60 var tagName = treeElement.listItemElement.querySelector('.webkit-html-tag-na
me'); | 60 var tagName = treeElement.listItemElement.querySelector('.webkit-html-tag-na
me'); |
| 61 WebInspector.runCSSAnimationOnce(tagName || treeElement.listItemElement, 'do
m-update-highlight'); | 61 UI.runCSSAnimationOnce(tagName || treeElement.listItemElement, 'dom-update-h
ighlight'); |
| 62 } | 62 } |
| 63 | 63 |
| 64 /** | 64 /** |
| 65 * @param {!WebInspector.DOMNode} node | 65 * @param {!SDK.DOMNode} node |
| 66 * @return {!Array<!WebInspector.DOMNode>} | 66 * @return {!Array<!SDK.DOMNode>} |
| 67 */ | 67 */ |
| 68 static visibleShadowRoots(node) { | 68 static visibleShadowRoots(node) { |
| 69 var roots = node.shadowRoots(); | 69 var roots = node.shadowRoots(); |
| 70 if (roots.length && !WebInspector.moduleSetting('showUAShadowDOM').get()) | 70 if (roots.length && !Common.moduleSetting('showUAShadowDOM').get()) |
| 71 roots = roots.filter(filter); | 71 roots = roots.filter(filter); |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * @param {!WebInspector.DOMNode} root | 74 * @param {!SDK.DOMNode} root |
| 75 */ | 75 */ |
| 76 function filter(root) { | 76 function filter(root) { |
| 77 return root.shadowRootType() !== WebInspector.DOMNode.ShadowRootTypes.User
Agent; | 77 return root.shadowRootType() !== SDK.DOMNode.ShadowRootTypes.UserAgent; |
| 78 } | 78 } |
| 79 return roots; | 79 return roots; |
| 80 } | 80 } |
| 81 | 81 |
| 82 /** | 82 /** |
| 83 * @param {!WebInspector.DOMNode} node | 83 * @param {!SDK.DOMNode} node |
| 84 * @return {boolean} | 84 * @return {boolean} |
| 85 */ | 85 */ |
| 86 static canShowInlineText(node) { | 86 static canShowInlineText(node) { |
| 87 if (node.importedDocument() || node.templateContent() || | 87 if (node.importedDocument() || node.templateContent() || |
| 88 WebInspector.ElementsTreeElement.visibleShadowRoots(node).length || node
.hasPseudoElements()) | 88 Elements.ElementsTreeElement.visibleShadowRoots(node).length || node.has
PseudoElements()) |
| 89 return false; | 89 return false; |
| 90 if (node.nodeType() !== Node.ELEMENT_NODE) | 90 if (node.nodeType() !== Node.ELEMENT_NODE) |
| 91 return false; | 91 return false; |
| 92 if (!node.firstChild || node.firstChild !== node.lastChild || node.firstChil
d.nodeType() !== Node.TEXT_NODE) | 92 if (!node.firstChild || node.firstChild !== node.lastChild || node.firstChil
d.nodeType() !== Node.TEXT_NODE) |
| 93 return false; | 93 return false; |
| 94 var textChild = node.firstChild; | 94 var textChild = node.firstChild; |
| 95 var maxInlineTextChildLength = 80; | 95 var maxInlineTextChildLength = 80; |
| 96 if (textChild.nodeValue().length < maxInlineTextChildLength) | 96 if (textChild.nodeValue().length < maxInlineTextChildLength) |
| 97 return true; | 97 return true; |
| 98 return false; | 98 return false; |
| 99 } | 99 } |
| 100 | 100 |
| 101 /** | 101 /** |
| 102 * @param {!WebInspector.ContextSubMenuItem} subMenu | 102 * @param {!UI.ContextSubMenuItem} subMenu |
| 103 * @param {!WebInspector.DOMNode} node | 103 * @param {!SDK.DOMNode} node |
| 104 */ | 104 */ |
| 105 static populateForcedPseudoStateItems(subMenu, node) { | 105 static populateForcedPseudoStateItems(subMenu, node) { |
| 106 const pseudoClasses = ['active', 'hover', 'focus', 'visited']; | 106 const pseudoClasses = ['active', 'hover', 'focus', 'visited']; |
| 107 var forcedPseudoState = WebInspector.CSSModel.fromNode(node).pseudoState(nod
e); | 107 var forcedPseudoState = SDK.CSSModel.fromNode(node).pseudoState(node); |
| 108 for (var i = 0; i < pseudoClasses.length; ++i) { | 108 for (var i = 0; i < pseudoClasses.length; ++i) { |
| 109 var pseudoClassForced = forcedPseudoState.indexOf(pseudoClasses[i]) >= 0; | 109 var pseudoClassForced = forcedPseudoState.indexOf(pseudoClasses[i]) >= 0; |
| 110 subMenu.appendCheckboxItem( | 110 subMenu.appendCheckboxItem( |
| 111 ':' + pseudoClasses[i], setPseudoStateCallback.bind(null, pseudoClasse
s[i], !pseudoClassForced), | 111 ':' + pseudoClasses[i], setPseudoStateCallback.bind(null, pseudoClasse
s[i], !pseudoClassForced), |
| 112 pseudoClassForced, false); | 112 pseudoClassForced, false); |
| 113 } | 113 } |
| 114 | 114 |
| 115 /** | 115 /** |
| 116 * @param {string} pseudoState | 116 * @param {string} pseudoState |
| 117 * @param {boolean} enabled | 117 * @param {boolean} enabled |
| 118 */ | 118 */ |
| 119 function setPseudoStateCallback(pseudoState, enabled) { | 119 function setPseudoStateCallback(pseudoState, enabled) { |
| 120 WebInspector.CSSModel.fromNode(node).forcePseudoState(node, pseudoState, e
nabled); | 120 SDK.CSSModel.fromNode(node).forcePseudoState(node, pseudoState, enabled); |
| 121 } | 121 } |
| 122 } | 122 } |
| 123 | 123 |
| 124 /** | 124 /** |
| 125 * @return {boolean} | 125 * @return {boolean} |
| 126 */ | 126 */ |
| 127 isClosingTag() { | 127 isClosingTag() { |
| 128 return !!this._elementCloseTag; | 128 return !!this._elementCloseTag; |
| 129 } | 129 } |
| 130 | 130 |
| 131 /** | 131 /** |
| 132 * @return {!WebInspector.DOMNode} | 132 * @return {!SDK.DOMNode} |
| 133 */ | 133 */ |
| 134 node() { | 134 node() { |
| 135 return this._node; | 135 return this._node; |
| 136 } | 136 } |
| 137 | 137 |
| 138 /** | 138 /** |
| 139 * @return {boolean} | 139 * @return {boolean} |
| 140 */ | 140 */ |
| 141 isEditing() { | 141 isEditing() { |
| 142 return !!this._editing; | 142 return !!this._editing; |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 445 } | 445 } |
| 446 | 446 |
| 447 /** | 447 /** |
| 448 * @param {!Event} event | 448 * @param {!Event} event |
| 449 */ | 449 */ |
| 450 _showContextMenu(event) { | 450 _showContextMenu(event) { |
| 451 this.treeOutline.showContextMenu(this, event); | 451 this.treeOutline.showContextMenu(this, event); |
| 452 } | 452 } |
| 453 | 453 |
| 454 /** | 454 /** |
| 455 * @param {!WebInspector.ContextMenu} contextMenu | 455 * @param {!UI.ContextMenu} contextMenu |
| 456 * @param {!Event} event | 456 * @param {!Event} event |
| 457 */ | 457 */ |
| 458 populateTagContextMenu(contextMenu, event) { | 458 populateTagContextMenu(contextMenu, event) { |
| 459 // Add attribute-related actions. | 459 // Add attribute-related actions. |
| 460 var treeElement = this._elementCloseTag ? this.treeOutline.findTreeElement(t
his._node) : this; | 460 var treeElement = this._elementCloseTag ? this.treeOutline.findTreeElement(t
his._node) : this; |
| 461 contextMenu.appendItem( | 461 contextMenu.appendItem( |
| 462 WebInspector.UIString.capitalize('Add ^attribute'), treeElement._addNewA
ttribute.bind(treeElement)); | 462 Common.UIString.capitalize('Add ^attribute'), treeElement._addNewAttribu
te.bind(treeElement)); |
| 463 | 463 |
| 464 var attribute = event.target.enclosingNodeOrSelfWithClass('webkit-html-attri
bute'); | 464 var attribute = event.target.enclosingNodeOrSelfWithClass('webkit-html-attri
bute'); |
| 465 var newAttribute = event.target.enclosingNodeOrSelfWithClass('add-attribute'
); | 465 var newAttribute = event.target.enclosingNodeOrSelfWithClass('add-attribute'
); |
| 466 if (attribute && !newAttribute) | 466 if (attribute && !newAttribute) |
| 467 contextMenu.appendItem( | 467 contextMenu.appendItem( |
| 468 WebInspector.UIString.capitalize('Edit ^attribute'), | 468 Common.UIString.capitalize('Edit ^attribute'), |
| 469 this._startEditingAttribute.bind(this, attribute, event.target)); | 469 this._startEditingAttribute.bind(this, attribute, event.target)); |
| 470 this.populateNodeContextMenu(contextMenu); | 470 this.populateNodeContextMenu(contextMenu); |
| 471 WebInspector.ElementsTreeElement.populateForcedPseudoStateItems(contextMenu,
treeElement.node()); | 471 Elements.ElementsTreeElement.populateForcedPseudoStateItems(contextMenu, tre
eElement.node()); |
| 472 contextMenu.appendSeparator(); | 472 contextMenu.appendSeparator(); |
| 473 this.populateScrollIntoView(contextMenu); | 473 this.populateScrollIntoView(contextMenu); |
| 474 } | 474 } |
| 475 | 475 |
| 476 /** | 476 /** |
| 477 * @param {!WebInspector.ContextMenu} contextMenu | 477 * @param {!UI.ContextMenu} contextMenu |
| 478 */ | 478 */ |
| 479 populateScrollIntoView(contextMenu) { | 479 populateScrollIntoView(contextMenu) { |
| 480 contextMenu.appendItem(WebInspector.UIString.capitalize('Scroll into ^view')
, this._scrollIntoView.bind(this)); | 480 contextMenu.appendItem(Common.UIString.capitalize('Scroll into ^view'), this
._scrollIntoView.bind(this)); |
| 481 } | 481 } |
| 482 | 482 |
| 483 populateTextContextMenu(contextMenu, textNode) { | 483 populateTextContextMenu(contextMenu, textNode) { |
| 484 if (!this._editing) | 484 if (!this._editing) |
| 485 contextMenu.appendItem( | 485 contextMenu.appendItem( |
| 486 WebInspector.UIString.capitalize('Edit ^text'), this._startEditingText
Node.bind(this, textNode)); | 486 Common.UIString.capitalize('Edit ^text'), this._startEditingTextNode.b
ind(this, textNode)); |
| 487 this.populateNodeContextMenu(contextMenu); | 487 this.populateNodeContextMenu(contextMenu); |
| 488 } | 488 } |
| 489 | 489 |
| 490 populateNodeContextMenu(contextMenu) { | 490 populateNodeContextMenu(contextMenu) { |
| 491 // Add free-form node-related actions. | 491 // Add free-form node-related actions. |
| 492 var openTagElement = this._node[this.treeOutline.treeElementSymbol()] || thi
s; | 492 var openTagElement = this._node[this.treeOutline.treeElementSymbol()] || thi
s; |
| 493 var isEditable = this.hasEditableNode(); | 493 var isEditable = this.hasEditableNode(); |
| 494 if (isEditable && !this._editing) | 494 if (isEditable && !this._editing) |
| 495 contextMenu.appendItem(WebInspector.UIString('Edit as HTML'), this._editAs
HTML.bind(this)); | 495 contextMenu.appendItem(Common.UIString('Edit as HTML'), this._editAsHTML.b
ind(this)); |
| 496 var isShadowRoot = this._node.isShadowRoot(); | 496 var isShadowRoot = this._node.isShadowRoot(); |
| 497 | 497 |
| 498 // Place it here so that all "Copy"-ing items stick together. | 498 // Place it here so that all "Copy"-ing items stick together. |
| 499 var copyMenu = contextMenu.appendSubMenuItem(WebInspector.UIString('Copy')); | 499 var copyMenu = contextMenu.appendSubMenuItem(Common.UIString('Copy')); |
| 500 var createShortcut = WebInspector.KeyboardShortcut.shortcutToString; | 500 var createShortcut = UI.KeyboardShortcut.shortcutToString; |
| 501 var modifier = WebInspector.KeyboardShortcut.Modifiers.CtrlOrMeta; | 501 var modifier = UI.KeyboardShortcut.Modifiers.CtrlOrMeta; |
| 502 var treeOutline = this.treeOutline; | 502 var treeOutline = this.treeOutline; |
| 503 var menuItem; | 503 var menuItem; |
| 504 if (!isShadowRoot) { | 504 if (!isShadowRoot) { |
| 505 menuItem = copyMenu.appendItem( | 505 menuItem = copyMenu.appendItem( |
| 506 WebInspector.UIString('Copy outerHTML'), treeOutline.performCopyOrCut.
bind(treeOutline, false, this._node)); | 506 Common.UIString('Copy outerHTML'), treeOutline.performCopyOrCut.bind(t
reeOutline, false, this._node)); |
| 507 menuItem.setShortcut(createShortcut('V', modifier)); | 507 menuItem.setShortcut(createShortcut('V', modifier)); |
| 508 } | 508 } |
| 509 if (this._node.nodeType() === Node.ELEMENT_NODE) | 509 if (this._node.nodeType() === Node.ELEMENT_NODE) |
| 510 copyMenu.appendItem(WebInspector.UIString.capitalize('Copy selector'), thi
s._copyCSSPath.bind(this)); | 510 copyMenu.appendItem(Common.UIString.capitalize('Copy selector'), this._cop
yCSSPath.bind(this)); |
| 511 if (!isShadowRoot) | 511 if (!isShadowRoot) |
| 512 copyMenu.appendItem(WebInspector.UIString('Copy XPath'), this._copyXPath.b
ind(this)); | 512 copyMenu.appendItem(Common.UIString('Copy XPath'), this._copyXPath.bind(th
is)); |
| 513 if (!isShadowRoot) { | 513 if (!isShadowRoot) { |
| 514 menuItem = copyMenu.appendItem( | 514 menuItem = copyMenu.appendItem( |
| 515 WebInspector.UIString('Cut element'), treeOutline.performCopyOrCut.bin
d(treeOutline, true, this._node), | 515 Common.UIString('Cut element'), treeOutline.performCopyOrCut.bind(tree
Outline, true, this._node), |
| 516 !this.hasEditableNode()); | 516 !this.hasEditableNode()); |
| 517 menuItem.setShortcut(createShortcut('X', modifier)); | 517 menuItem.setShortcut(createShortcut('X', modifier)); |
| 518 menuItem = copyMenu.appendItem( | 518 menuItem = copyMenu.appendItem( |
| 519 WebInspector.UIString('Copy element'), treeOutline.performCopyOrCut.bi
nd(treeOutline, false, this._node)); | 519 Common.UIString('Copy element'), treeOutline.performCopyOrCut.bind(tre
eOutline, false, this._node)); |
| 520 menuItem.setShortcut(createShortcut('C', modifier)); | 520 menuItem.setShortcut(createShortcut('C', modifier)); |
| 521 menuItem = copyMenu.appendItem( | 521 menuItem = copyMenu.appendItem( |
| 522 WebInspector.UIString('Paste element'), treeOutline.pasteNode.bind(tre
eOutline, this._node), | 522 Common.UIString('Paste element'), treeOutline.pasteNode.bind(treeOutli
ne, this._node), |
| 523 !treeOutline.canPaste(this._node)); | 523 !treeOutline.canPaste(this._node)); |
| 524 menuItem.setShortcut(createShortcut('V', modifier)); | 524 menuItem.setShortcut(createShortcut('V', modifier)); |
| 525 } | 525 } |
| 526 | 526 |
| 527 contextMenu.appendSeparator(); | 527 contextMenu.appendSeparator(); |
| 528 menuItem = contextMenu.appendCheckboxItem( | 528 menuItem = contextMenu.appendCheckboxItem( |
| 529 WebInspector.UIString('Hide element'), treeOutline.toggleHideElement.bin
d(treeOutline, this._node), | 529 Common.UIString('Hide element'), treeOutline.toggleHideElement.bind(tree
Outline, this._node), |
| 530 treeOutline.isToggledToHidden(this._node)); | 530 treeOutline.isToggledToHidden(this._node)); |
| 531 menuItem.setShortcut(WebInspector.shortcutRegistry.shortcutTitleForAction('e
lements.hide-element')); | 531 menuItem.setShortcut(UI.shortcutRegistry.shortcutTitleForAction('elements.hi
de-element')); |
| 532 | 532 |
| 533 if (isEditable) | 533 if (isEditable) |
| 534 contextMenu.appendItem(WebInspector.UIString('Delete element'), this.remov
e.bind(this)); | 534 contextMenu.appendItem(Common.UIString('Delete element'), this.remove.bind
(this)); |
| 535 contextMenu.appendSeparator(); | 535 contextMenu.appendSeparator(); |
| 536 | 536 |
| 537 contextMenu.appendItem(WebInspector.UIString('Expand all'), this.expandRecur
sively.bind(this)); | 537 contextMenu.appendItem(Common.UIString('Expand all'), this.expandRecursively
.bind(this)); |
| 538 contextMenu.appendItem(WebInspector.UIString('Collapse all'), this.collapseR
ecursively.bind(this)); | 538 contextMenu.appendItem(Common.UIString('Collapse all'), this.collapseRecursi
vely.bind(this)); |
| 539 contextMenu.appendSeparator(); | 539 contextMenu.appendSeparator(); |
| 540 } | 540 } |
| 541 | 541 |
| 542 _startEditing() { | 542 _startEditing() { |
| 543 if (this.treeOutline.selectedDOMNode() !== this._node) | 543 if (this.treeOutline.selectedDOMNode() !== this._node) |
| 544 return; | 544 return; |
| 545 | 545 |
| 546 var listItem = this._listItemNode; | 546 var listItem = this._listItemNode; |
| 547 | 547 |
| 548 if (this._canAddAttributes) { | 548 if (this._canAddAttributes) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 588 if (elem.classList.contains('webkit-html-attribute-value')) | 588 if (elem.classList.contains('webkit-html-attribute-value')) |
| 589 return this._startEditingAttribute(elem.parentNode, elem); | 589 return this._startEditingAttribute(elem.parentNode, elem); |
| 590 } | 590 } |
| 591 } | 591 } |
| 592 } | 592 } |
| 593 } | 593 } |
| 594 | 594 |
| 595 _startEditingAttribute(attribute, elementForSelection) { | 595 _startEditingAttribute(attribute, elementForSelection) { |
| 596 console.assert(this.listItemElement.isAncestor(attribute)); | 596 console.assert(this.listItemElement.isAncestor(attribute)); |
| 597 | 597 |
| 598 if (WebInspector.isBeingEdited(attribute)) | 598 if (UI.isBeingEdited(attribute)) |
| 599 return true; | 599 return true; |
| 600 | 600 |
| 601 var attributeNameElement = attribute.getElementsByClassName('webkit-html-att
ribute-name')[0]; | 601 var attributeNameElement = attribute.getElementsByClassName('webkit-html-att
ribute-name')[0]; |
| 602 if (!attributeNameElement) | 602 if (!attributeNameElement) |
| 603 return false; | 603 return false; |
| 604 | 604 |
| 605 var attributeName = attributeNameElement.textContent; | 605 var attributeName = attributeNameElement.textContent; |
| 606 var attributeValueElement = attribute.getElementsByClassName('webkit-html-at
tribute-value')[0]; | 606 var attributeValueElement = attribute.getElementsByClassName('webkit-html-at
tribute-value')[0]; |
| 607 | 607 |
| 608 // Make sure elementForSelection is not a child of attributeValueElement. | 608 // Make sure elementForSelection is not a child of attributeValueElement. |
| 609 elementForSelection = | 609 elementForSelection = |
| 610 attributeValueElement.isAncestor(elementForSelection) ? attributeValueEl
ement : elementForSelection; | 610 attributeValueElement.isAncestor(elementForSelection) ? attributeValueEl
ement : elementForSelection; |
| 611 | 611 |
| 612 function removeZeroWidthSpaceRecursive(node) { | 612 function removeZeroWidthSpaceRecursive(node) { |
| 613 if (node.nodeType === Node.TEXT_NODE) { | 613 if (node.nodeType === Node.TEXT_NODE) { |
| 614 node.nodeValue = node.nodeValue.replace(/\u200B/g, ''); | 614 node.nodeValue = node.nodeValue.replace(/\u200B/g, ''); |
| 615 return; | 615 return; |
| 616 } | 616 } |
| 617 | 617 |
| 618 if (node.nodeType !== Node.ELEMENT_NODE) | 618 if (node.nodeType !== Node.ELEMENT_NODE) |
| 619 return; | 619 return; |
| 620 | 620 |
| 621 for (var child = node.firstChild; child; child = child.nextSibling) | 621 for (var child = node.firstChild; child; child = child.nextSibling) |
| 622 removeZeroWidthSpaceRecursive(child); | 622 removeZeroWidthSpaceRecursive(child); |
| 623 } | 623 } |
| 624 | 624 |
| 625 var attributeValue = attributeName && attributeValueElement ? this._node.get
Attribute(attributeName) : undefined; | 625 var attributeValue = attributeName && attributeValueElement ? this._node.get
Attribute(attributeName) : undefined; |
| 626 if (attributeValue !== undefined) | 626 if (attributeValue !== undefined) |
| 627 attributeValueElement.setTextContentTruncatedIfNeeded( | 627 attributeValueElement.setTextContentTruncatedIfNeeded( |
| 628 attributeValue, WebInspector.UIString('<value is too large to edit>'))
; | 628 attributeValue, Common.UIString('<value is too large to edit>')); |
| 629 | 629 |
| 630 // Remove zero-width spaces that were added by nodeTitleInfo. | 630 // Remove zero-width spaces that were added by nodeTitleInfo. |
| 631 removeZeroWidthSpaceRecursive(attribute); | 631 removeZeroWidthSpaceRecursive(attribute); |
| 632 | 632 |
| 633 var config = new WebInspector.InplaceEditor.Config( | 633 var config = new UI.InplaceEditor.Config( |
| 634 this._attributeEditingCommitted.bind(this), this._editingCancelled.bind(
this), attributeName); | 634 this._attributeEditingCommitted.bind(this), this._editingCancelled.bind(
this), attributeName); |
| 635 | 635 |
| 636 /** | 636 /** |
| 637 * @param {!Event} event | 637 * @param {!Event} event |
| 638 * @return {string} | 638 * @return {string} |
| 639 */ | 639 */ |
| 640 function postKeyDownFinishHandler(event) { | 640 function postKeyDownFinishHandler(event) { |
| 641 WebInspector.handleElementValueModifications(event, attribute); | 641 UI.handleElementValueModifications(event, attribute); |
| 642 return ''; | 642 return ''; |
| 643 } | 643 } |
| 644 | 644 |
| 645 if (!attributeValueElement.textContent.asParsedURL()) | 645 if (!attributeValueElement.textContent.asParsedURL()) |
| 646 config.setPostKeydownFinishHandler(postKeyDownFinishHandler); | 646 config.setPostKeydownFinishHandler(postKeyDownFinishHandler); |
| 647 | 647 |
| 648 this._editing = WebInspector.InplaceEditor.startEditing(attribute, config); | 648 this._editing = UI.InplaceEditor.startEditing(attribute, config); |
| 649 | 649 |
| 650 this.listItemElement.getComponentSelection().setBaseAndExtent(elementForSele
ction, 0, elementForSelection, 1); | 650 this.listItemElement.getComponentSelection().setBaseAndExtent(elementForSele
ction, 0, elementForSelection, 1); |
| 651 | 651 |
| 652 return true; | 652 return true; |
| 653 } | 653 } |
| 654 | 654 |
| 655 /** | 655 /** |
| 656 * @param {!Element} textNodeElement | 656 * @param {!Element} textNodeElement |
| 657 */ | 657 */ |
| 658 _startEditingTextNode(textNodeElement) { | 658 _startEditingTextNode(textNodeElement) { |
| 659 if (WebInspector.isBeingEdited(textNodeElement)) | 659 if (UI.isBeingEdited(textNodeElement)) |
| 660 return true; | 660 return true; |
| 661 | 661 |
| 662 var textNode = this._node; | 662 var textNode = this._node; |
| 663 // We only show text nodes inline in elements if the element only | 663 // We only show text nodes inline in elements if the element only |
| 664 // has a single child, and that child is a text node. | 664 // has a single child, and that child is a text node. |
| 665 if (textNode.nodeType() === Node.ELEMENT_NODE && textNode.firstChild) | 665 if (textNode.nodeType() === Node.ELEMENT_NODE && textNode.firstChild) |
| 666 textNode = textNode.firstChild; | 666 textNode = textNode.firstChild; |
| 667 | 667 |
| 668 var container = textNodeElement.enclosingNodeOrSelfWithClass('webkit-html-te
xt-node'); | 668 var container = textNodeElement.enclosingNodeOrSelfWithClass('webkit-html-te
xt-node'); |
| 669 if (container) | 669 if (container) |
| 670 container.textContent = textNode.nodeValue(); // Strip the CSS or JS high
lighting if present. | 670 container.textContent = textNode.nodeValue(); // Strip the CSS or JS high
lighting if present. |
| 671 var config = new WebInspector.InplaceEditor.Config( | 671 var config = new UI.InplaceEditor.Config( |
| 672 this._textNodeEditingCommitted.bind(this, textNode), this._editingCancel
led.bind(this)); | 672 this._textNodeEditingCommitted.bind(this, textNode), this._editingCancel
led.bind(this)); |
| 673 this._editing = WebInspector.InplaceEditor.startEditing(textNodeElement, con
fig); | 673 this._editing = UI.InplaceEditor.startEditing(textNodeElement, config); |
| 674 this.listItemElement.getComponentSelection().setBaseAndExtent(textNodeElemen
t, 0, textNodeElement, 1); | 674 this.listItemElement.getComponentSelection().setBaseAndExtent(textNodeElemen
t, 0, textNodeElement, 1); |
| 675 | 675 |
| 676 return true; | 676 return true; |
| 677 } | 677 } |
| 678 | 678 |
| 679 /** | 679 /** |
| 680 * @param {!Element=} tagNameElement | 680 * @param {!Element=} tagNameElement |
| 681 */ | 681 */ |
| 682 _startEditingTagName(tagNameElement) { | 682 _startEditingTagName(tagNameElement) { |
| 683 if (!tagNameElement) { | 683 if (!tagNameElement) { |
| 684 tagNameElement = this.listItemElement.getElementsByClassName('webkit-html-
tag-name')[0]; | 684 tagNameElement = this.listItemElement.getElementsByClassName('webkit-html-
tag-name')[0]; |
| 685 if (!tagNameElement) | 685 if (!tagNameElement) |
| 686 return false; | 686 return false; |
| 687 } | 687 } |
| 688 | 688 |
| 689 var tagName = tagNameElement.textContent; | 689 var tagName = tagNameElement.textContent; |
| 690 if (WebInspector.ElementsTreeElement.EditTagBlacklist.has(tagName.toLowerCas
e())) | 690 if (Elements.ElementsTreeElement.EditTagBlacklist.has(tagName.toLowerCase())
) |
| 691 return false; | 691 return false; |
| 692 | 692 |
| 693 if (WebInspector.isBeingEdited(tagNameElement)) | 693 if (UI.isBeingEdited(tagNameElement)) |
| 694 return true; | 694 return true; |
| 695 | 695 |
| 696 var closingTagElement = this._distinctClosingTagElement(); | 696 var closingTagElement = this._distinctClosingTagElement(); |
| 697 | 697 |
| 698 /** | 698 /** |
| 699 * @param {!Event} event | 699 * @param {!Event} event |
| 700 */ | 700 */ |
| 701 function keyupListener(event) { | 701 function keyupListener(event) { |
| 702 if (closingTagElement) | 702 if (closingTagElement) |
| 703 closingTagElement.textContent = '</' + tagNameElement.textContent + '>'; | 703 closingTagElement.textContent = '</' + tagNameElement.textContent + '>'; |
| 704 } | 704 } |
| 705 | 705 |
| 706 /** | 706 /** |
| 707 * @param {!Element} element | 707 * @param {!Element} element |
| 708 * @param {string} newTagName | 708 * @param {string} newTagName |
| 709 * @this {WebInspector.ElementsTreeElement} | 709 * @this {Elements.ElementsTreeElement} |
| 710 */ | 710 */ |
| 711 function editingComitted(element, newTagName) { | 711 function editingComitted(element, newTagName) { |
| 712 tagNameElement.removeEventListener('keyup', keyupListener, false); | 712 tagNameElement.removeEventListener('keyup', keyupListener, false); |
| 713 this._tagNameEditingCommitted.apply(this, arguments); | 713 this._tagNameEditingCommitted.apply(this, arguments); |
| 714 } | 714 } |
| 715 | 715 |
| 716 /** | 716 /** |
| 717 * @this {WebInspector.ElementsTreeElement} | 717 * @this {Elements.ElementsTreeElement} |
| 718 */ | 718 */ |
| 719 function editingCancelled() { | 719 function editingCancelled() { |
| 720 tagNameElement.removeEventListener('keyup', keyupListener, false); | 720 tagNameElement.removeEventListener('keyup', keyupListener, false); |
| 721 this._editingCancelled.apply(this, arguments); | 721 this._editingCancelled.apply(this, arguments); |
| 722 } | 722 } |
| 723 | 723 |
| 724 tagNameElement.addEventListener('keyup', keyupListener, false); | 724 tagNameElement.addEventListener('keyup', keyupListener, false); |
| 725 | 725 |
| 726 var config = | 726 var config = |
| 727 new WebInspector.InplaceEditor.Config(editingComitted.bind(this), editin
gCancelled.bind(this), tagName); | 727 new UI.InplaceEditor.Config(editingComitted.bind(this), editingCancelled
.bind(this), tagName); |
| 728 this._editing = WebInspector.InplaceEditor.startEditing(tagNameElement, conf
ig); | 728 this._editing = UI.InplaceEditor.startEditing(tagNameElement, config); |
| 729 this.listItemElement.getComponentSelection().setBaseAndExtent(tagNameElement
, 0, tagNameElement, 1); | 729 this.listItemElement.getComponentSelection().setBaseAndExtent(tagNameElement
, 0, tagNameElement, 1); |
| 730 return true; | 730 return true; |
| 731 } | 731 } |
| 732 | 732 |
| 733 /** | 733 /** |
| 734 * @param {function(string, string)} commitCallback | 734 * @param {function(string, string)} commitCallback |
| 735 * @param {function()} disposeCallback | 735 * @param {function()} disposeCallback |
| 736 * @param {?Protocol.Error} error | 736 * @param {?Protocol.Error} error |
| 737 * @param {string} initialValue | 737 * @param {string} initialValue |
| 738 */ | 738 */ |
| (...skipping 23 matching lines...) Expand all Loading... |
| 762 if (this._childrenListNode) | 762 if (this._childrenListNode) |
| 763 this._childrenListNode.style.display = 'none'; | 763 this._childrenListNode.style.display = 'none'; |
| 764 // Append editor. | 764 // Append editor. |
| 765 this.listItemElement.appendChild(this._htmlEditElement); | 765 this.listItemElement.appendChild(this._htmlEditElement); |
| 766 this.listItemElement.classList.add('editing-as-html'); | 766 this.listItemElement.classList.add('editing-as-html'); |
| 767 this.treeOutline.element.addEventListener('mousedown', consume, false); | 767 this.treeOutline.element.addEventListener('mousedown', consume, false); |
| 768 | 768 |
| 769 /** | 769 /** |
| 770 * @param {!Element} element | 770 * @param {!Element} element |
| 771 * @param {string} newValue | 771 * @param {string} newValue |
| 772 * @this {WebInspector.ElementsTreeElement} | 772 * @this {Elements.ElementsTreeElement} |
| 773 */ | 773 */ |
| 774 function commit(element, newValue) { | 774 function commit(element, newValue) { |
| 775 commitCallback(initialValue, newValue); | 775 commitCallback(initialValue, newValue); |
| 776 dispose.call(this); | 776 dispose.call(this); |
| 777 } | 777 } |
| 778 | 778 |
| 779 /** | 779 /** |
| 780 * @this {WebInspector.ElementsTreeElement} | 780 * @this {Elements.ElementsTreeElement} |
| 781 */ | 781 */ |
| 782 function dispose() { | 782 function dispose() { |
| 783 disposeCallback(); | 783 disposeCallback(); |
| 784 delete this._editing; | 784 delete this._editing; |
| 785 this.treeOutline.setMultilineEditing(null); | 785 this.treeOutline.setMultilineEditing(null); |
| 786 | 786 |
| 787 this.listItemElement.classList.remove('editing-as-html'); | 787 this.listItemElement.classList.remove('editing-as-html'); |
| 788 // Remove editor. | 788 // Remove editor. |
| 789 this.listItemElement.removeChild(this._htmlEditElement); | 789 this.listItemElement.removeChild(this._htmlEditElement); |
| 790 delete this._htmlEditElement; | 790 delete this._htmlEditElement; |
| 791 // Unhide children item. | 791 // Unhide children item. |
| 792 if (this._childrenListNode) | 792 if (this._childrenListNode) |
| 793 this._childrenListNode.style.removeProperty('display'); | 793 this._childrenListNode.style.removeProperty('display'); |
| 794 // Unhide header items. | 794 // Unhide header items. |
| 795 var child = this.listItemElement.firstChild; | 795 var child = this.listItemElement.firstChild; |
| 796 while (child) { | 796 while (child) { |
| 797 child.style.removeProperty('display'); | 797 child.style.removeProperty('display'); |
| 798 child = child.nextSibling; | 798 child = child.nextSibling; |
| 799 } | 799 } |
| 800 | 800 |
| 801 this.treeOutline.element.removeEventListener('mousedown', consume, false); | 801 this.treeOutline.element.removeEventListener('mousedown', consume, false); |
| 802 this.treeOutline.focus(); | 802 this.treeOutline.focus(); |
| 803 } | 803 } |
| 804 | 804 |
| 805 var config = new WebInspector.InplaceEditor.Config(commit.bind(this), dispos
e.bind(this)); | 805 var config = new UI.InplaceEditor.Config(commit.bind(this), dispose.bind(thi
s)); |
| 806 config.setMultilineOptions( | 806 config.setMultilineOptions( |
| 807 initialValue, {name: 'xml', htmlMode: true}, 'web-inspector-html', | 807 initialValue, {name: 'xml', htmlMode: true}, 'web-inspector-html', |
| 808 WebInspector.moduleSetting('domWordWrap').get(), true); | 808 Common.moduleSetting('domWordWrap').get(), true); |
| 809 WebInspector.InplaceEditor.startMultilineEditing(this._htmlEditElement, conf
ig).then(markAsBeingEdited.bind(this)); | 809 UI.InplaceEditor.startMultilineEditing(this._htmlEditElement, config).then(m
arkAsBeingEdited.bind(this)); |
| 810 | 810 |
| 811 /** | 811 /** |
| 812 * @param {!Object} controller | 812 * @param {!Object} controller |
| 813 * @this {WebInspector.ElementsTreeElement} | 813 * @this {Elements.ElementsTreeElement} |
| 814 */ | 814 */ |
| 815 function markAsBeingEdited(controller) { | 815 function markAsBeingEdited(controller) { |
| 816 this._editing = /** @type {!WebInspector.InplaceEditor.Controller} */ (con
troller); | 816 this._editing = /** @type {!UI.InplaceEditor.Controller} */ (controller); |
| 817 this._editing.setWidth(this.treeOutline.visibleWidth() - this._computeLeft
Indent()); | 817 this._editing.setWidth(this.treeOutline.visibleWidth() - this._computeLeft
Indent()); |
| 818 this.treeOutline.setMultilineEditing(this._editing); | 818 this.treeOutline.setMultilineEditing(this._editing); |
| 819 } | 819 } |
| 820 } | 820 } |
| 821 | 821 |
| 822 _attributeEditingCommitted(element, newText, oldText, attributeName, moveDirec
tion) { | 822 _attributeEditingCommitted(element, newText, oldText, attributeName, moveDirec
tion) { |
| 823 delete this._editing; | 823 delete this._editing; |
| 824 | 824 |
| 825 var treeOutline = this.treeOutline; | 825 var treeOutline = this.treeOutline; |
| 826 | 826 |
| 827 /** | 827 /** |
| 828 * @param {?Protocol.Error=} error | 828 * @param {?Protocol.Error=} error |
| 829 * @this {WebInspector.ElementsTreeElement} | 829 * @this {Elements.ElementsTreeElement} |
| 830 */ | 830 */ |
| 831 function moveToNextAttributeIfNeeded(error) { | 831 function moveToNextAttributeIfNeeded(error) { |
| 832 if (error) | 832 if (error) |
| 833 this._editingCancelled(element, attributeName); | 833 this._editingCancelled(element, attributeName); |
| 834 | 834 |
| 835 if (!moveDirection) | 835 if (!moveDirection) |
| 836 return; | 836 return; |
| 837 | 837 |
| 838 treeOutline.runPendingUpdates(); | 838 treeOutline.runPendingUpdates(); |
| 839 | 839 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 function cancel() { | 892 function cancel() { |
| 893 var closingTagElement = self._distinctClosingTagElement(); | 893 var closingTagElement = self._distinctClosingTagElement(); |
| 894 if (closingTagElement) | 894 if (closingTagElement) |
| 895 closingTagElement.textContent = '</' + tagName + '>'; | 895 closingTagElement.textContent = '</' + tagName + '>'; |
| 896 | 896 |
| 897 self._editingCancelled(element, tagName); | 897 self._editingCancelled(element, tagName); |
| 898 moveToNextAttributeIfNeeded.call(self); | 898 moveToNextAttributeIfNeeded.call(self); |
| 899 } | 899 } |
| 900 | 900 |
| 901 /** | 901 /** |
| 902 * @this {WebInspector.ElementsTreeElement} | 902 * @this {Elements.ElementsTreeElement} |
| 903 */ | 903 */ |
| 904 function moveToNextAttributeIfNeeded() { | 904 function moveToNextAttributeIfNeeded() { |
| 905 if (moveDirection !== 'forward') { | 905 if (moveDirection !== 'forward') { |
| 906 this._addNewAttribute(); | 906 this._addNewAttribute(); |
| 907 return; | 907 return; |
| 908 } | 908 } |
| 909 | 909 |
| 910 var attributes = this._node.attributes(); | 910 var attributes = this._node.attributes(); |
| 911 if (attributes.length > 0) | 911 if (attributes.length > 0) |
| 912 this._triggerEditAttribute(attributes[0].name); | 912 this._triggerEditAttribute(attributes[0].name); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 928 cancel(); | 928 cancel(); |
| 929 return; | 929 return; |
| 930 } | 930 } |
| 931 var newTreeItem = treeOutline.selectNodeAfterEdit(wasExpanded, error, node
Id); | 931 var newTreeItem = treeOutline.selectNodeAfterEdit(wasExpanded, error, node
Id); |
| 932 moveToNextAttributeIfNeeded.call(newTreeItem); | 932 moveToNextAttributeIfNeeded.call(newTreeItem); |
| 933 } | 933 } |
| 934 this._node.setNodeName(newText, changeTagNameCallback); | 934 this._node.setNodeName(newText, changeTagNameCallback); |
| 935 } | 935 } |
| 936 | 936 |
| 937 /** | 937 /** |
| 938 * @param {!WebInspector.DOMNode} textNode | 938 * @param {!SDK.DOMNode} textNode |
| 939 * @param {!Element} element | 939 * @param {!Element} element |
| 940 * @param {string} newText | 940 * @param {string} newText |
| 941 */ | 941 */ |
| 942 _textNodeEditingCommitted(textNode, element, newText) { | 942 _textNodeEditingCommitted(textNode, element, newText) { |
| 943 delete this._editing; | 943 delete this._editing; |
| 944 | 944 |
| 945 /** | 945 /** |
| 946 * @this {WebInspector.ElementsTreeElement} | 946 * @this {Elements.ElementsTreeElement} |
| 947 */ | 947 */ |
| 948 function callback() { | 948 function callback() { |
| 949 this.updateTitle(); | 949 this.updateTitle(); |
| 950 } | 950 } |
| 951 textNode.setNodeValue(newText, callback.bind(this)); | 951 textNode.setNodeValue(newText, callback.bind(this)); |
| 952 } | 952 } |
| 953 | 953 |
| 954 /** | 954 /** |
| 955 * @param {!Element} element | 955 * @param {!Element} element |
| 956 * @param {*} context | 956 * @param {*} context |
| (...skipping 19 matching lines...) Expand all Loading... |
| 976 } | 976 } |
| 977 | 977 |
| 978 // Remaining cases are single line non-expanded elements with a closing | 978 // Remaining cases are single line non-expanded elements with a closing |
| 979 // tag, or HTML elements without a closing tag (such as <br>). Return | 979 // tag, or HTML elements without a closing tag (such as <br>). Return |
| 980 // null in the case where there isn't a closing tag. | 980 // null in the case where there isn't a closing tag. |
| 981 var tags = this.listItemElement.getElementsByClassName('webkit-html-tag'); | 981 var tags = this.listItemElement.getElementsByClassName('webkit-html-tag'); |
| 982 return (tags.length === 1 ? null : tags[tags.length - 1]); | 982 return (tags.length === 1 ? null : tags[tags.length - 1]); |
| 983 } | 983 } |
| 984 | 984 |
| 985 /** | 985 /** |
| 986 * @param {?WebInspector.ElementsTreeOutline.UpdateRecord=} updateRecord | 986 * @param {?Elements.ElementsTreeOutline.UpdateRecord=} updateRecord |
| 987 * @param {boolean=} onlySearchQueryChanged | 987 * @param {boolean=} onlySearchQueryChanged |
| 988 */ | 988 */ |
| 989 updateTitle(updateRecord, onlySearchQueryChanged) { | 989 updateTitle(updateRecord, onlySearchQueryChanged) { |
| 990 // If we are editing, return early to prevent canceling the edit. | 990 // If we are editing, return early to prevent canceling the edit. |
| 991 // After editing is committed updateTitle will be called. | 991 // After editing is committed updateTitle will be called. |
| 992 if (this._editing) | 992 if (this._editing) |
| 993 return; | 993 return; |
| 994 | 994 |
| 995 if (onlySearchQueryChanged) { | 995 if (onlySearchQueryChanged) { |
| 996 this._hideSearchHighlight(); | 996 this._hideSearchHighlight(); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 | 1045 |
| 1046 if (this.isClosingTag()) | 1046 if (this.isClosingTag()) |
| 1047 return; | 1047 return; |
| 1048 | 1048 |
| 1049 var node = this._node; | 1049 var node = this._node; |
| 1050 if (node.nodeType() !== Node.ELEMENT_NODE) | 1050 if (node.nodeType() !== Node.ELEMENT_NODE) |
| 1051 return; | 1051 return; |
| 1052 | 1052 |
| 1053 if (!this.treeOutline._decoratorExtensions) | 1053 if (!this.treeOutline._decoratorExtensions) |
| 1054 /** @type {!Array.<!Runtime.Extension>} */ | 1054 /** @type {!Array.<!Runtime.Extension>} */ |
| 1055 this.treeOutline._decoratorExtensions = runtime.extensions(WebInspector.DO
MPresentationUtils.MarkerDecorator); | 1055 this.treeOutline._decoratorExtensions = runtime.extensions(Components.DOMP
resentationUtils.MarkerDecorator); |
| 1056 | 1056 |
| 1057 var markerToExtension = new Map(); | 1057 var markerToExtension = new Map(); |
| 1058 for (var i = 0; i < this.treeOutline._decoratorExtensions.length; ++i) | 1058 for (var i = 0; i < this.treeOutline._decoratorExtensions.length; ++i) |
| 1059 markerToExtension.set( | 1059 markerToExtension.set( |
| 1060 this.treeOutline._decoratorExtensions[i].descriptor()['marker'], this.
treeOutline._decoratorExtensions[i]); | 1060 this.treeOutline._decoratorExtensions[i].descriptor()['marker'], this.
treeOutline._decoratorExtensions[i]); |
| 1061 | 1061 |
| 1062 var promises = []; | 1062 var promises = []; |
| 1063 var decorations = []; | 1063 var decorations = []; |
| 1064 var descendantDecorations = []; | 1064 var descendantDecorations = []; |
| 1065 node.traverseMarkers(visitor); | 1065 node.traverseMarkers(visitor); |
| 1066 | 1066 |
| 1067 /** | 1067 /** |
| 1068 * @param {!WebInspector.DOMNode} n | 1068 * @param {!SDK.DOMNode} n |
| 1069 * @param {string} marker | 1069 * @param {string} marker |
| 1070 */ | 1070 */ |
| 1071 function visitor(n, marker) { | 1071 function visitor(n, marker) { |
| 1072 var extension = markerToExtension.get(marker); | 1072 var extension = markerToExtension.get(marker); |
| 1073 if (!extension) | 1073 if (!extension) |
| 1074 return; | 1074 return; |
| 1075 promises.push(extension.instance().then(collectDecoration.bind(null, n))); | 1075 promises.push(extension.instance().then(collectDecoration.bind(null, n))); |
| 1076 } | 1076 } |
| 1077 | 1077 |
| 1078 /** | 1078 /** |
| 1079 * @param {!WebInspector.DOMNode} n | 1079 * @param {!SDK.DOMNode} n |
| 1080 * @param {!WebInspector.DOMPresentationUtils.MarkerDecorator} decorator | 1080 * @param {!Components.DOMPresentationUtils.MarkerDecorator} decorator |
| 1081 */ | 1081 */ |
| 1082 function collectDecoration(n, decorator) { | 1082 function collectDecoration(n, decorator) { |
| 1083 var decoration = decorator.decorate(n); | 1083 var decoration = decorator.decorate(n); |
| 1084 if (!decoration) | 1084 if (!decoration) |
| 1085 return; | 1085 return; |
| 1086 (n === node ? decorations : descendantDecorations).push(decoration); | 1086 (n === node ? decorations : descendantDecorations).push(decoration); |
| 1087 } | 1087 } |
| 1088 | 1088 |
| 1089 Promise.all(promises).then(updateDecorationsUI.bind(this)); | 1089 Promise.all(promises).then(updateDecorationsUI.bind(this)); |
| 1090 | 1090 |
| 1091 /** | 1091 /** |
| 1092 * @this {WebInspector.ElementsTreeElement} | 1092 * @this {Elements.ElementsTreeElement} |
| 1093 */ | 1093 */ |
| 1094 function updateDecorationsUI() { | 1094 function updateDecorationsUI() { |
| 1095 this._decorationsElement.removeChildren(); | 1095 this._decorationsElement.removeChildren(); |
| 1096 this._decorationsElement.classList.add('hidden'); | 1096 this._decorationsElement.classList.add('hidden'); |
| 1097 this._gutterContainer.classList.toggle('has-decorations', decorations.leng
th || descendantDecorations.length); | 1097 this._gutterContainer.classList.toggle('has-decorations', decorations.leng
th || descendantDecorations.length); |
| 1098 | 1098 |
| 1099 if (!decorations.length && !descendantDecorations.length) | 1099 if (!decorations.length && !descendantDecorations.length) |
| 1100 return; | 1100 return; |
| 1101 | 1101 |
| 1102 var colors = new Set(); | 1102 var colors = new Set(); |
| 1103 var titles = createElement('div'); | 1103 var titles = createElement('div'); |
| 1104 | 1104 |
| 1105 for (var decoration of decorations) { | 1105 for (var decoration of decorations) { |
| 1106 var titleElement = titles.createChild('div'); | 1106 var titleElement = titles.createChild('div'); |
| 1107 titleElement.textContent = decoration.title; | 1107 titleElement.textContent = decoration.title; |
| 1108 colors.add(decoration.color); | 1108 colors.add(decoration.color); |
| 1109 } | 1109 } |
| 1110 if (this.expanded && !decorations.length) | 1110 if (this.expanded && !decorations.length) |
| 1111 return; | 1111 return; |
| 1112 | 1112 |
| 1113 var descendantColors = new Set(); | 1113 var descendantColors = new Set(); |
| 1114 if (descendantDecorations.length) { | 1114 if (descendantDecorations.length) { |
| 1115 var element = titles.createChild('div'); | 1115 var element = titles.createChild('div'); |
| 1116 element.textContent = WebInspector.UIString('Children:'); | 1116 element.textContent = Common.UIString('Children:'); |
| 1117 for (var decoration of descendantDecorations) { | 1117 for (var decoration of descendantDecorations) { |
| 1118 element = titles.createChild('div'); | 1118 element = titles.createChild('div'); |
| 1119 element.style.marginLeft = '15px'; | 1119 element.style.marginLeft = '15px'; |
| 1120 element.textContent = decoration.title; | 1120 element.textContent = decoration.title; |
| 1121 descendantColors.add(decoration.color); | 1121 descendantColors.add(decoration.color); |
| 1122 } | 1122 } |
| 1123 } | 1123 } |
| 1124 | 1124 |
| 1125 var offset = 0; | 1125 var offset = 0; |
| 1126 processColors.call(this, colors, 'elements-gutter-decoration'); | 1126 processColors.call(this, colors, 'elements-gutter-decoration'); |
| 1127 if (!this.expanded) | 1127 if (!this.expanded) |
| 1128 processColors.call(this, descendantColors, 'elements-gutter-decoration e
lements-has-decorated-children'); | 1128 processColors.call(this, descendantColors, 'elements-gutter-decoration e
lements-has-decorated-children'); |
| 1129 WebInspector.Tooltip.install(this._decorationsElement, titles); | 1129 UI.Tooltip.install(this._decorationsElement, titles); |
| 1130 | 1130 |
| 1131 /** | 1131 /** |
| 1132 * @param {!Set<string>} colors | 1132 * @param {!Set<string>} colors |
| 1133 * @param {string} className | 1133 * @param {string} className |
| 1134 * @this {WebInspector.ElementsTreeElement} | 1134 * @this {Elements.ElementsTreeElement} |
| 1135 */ | 1135 */ |
| 1136 function processColors(colors, className) { | 1136 function processColors(colors, className) { |
| 1137 for (var color of colors) { | 1137 for (var color of colors) { |
| 1138 var child = this._decorationsElement.createChild('div', className); | 1138 var child = this._decorationsElement.createChild('div', className); |
| 1139 this._decorationsElement.classList.remove('hidden'); | 1139 this._decorationsElement.classList.remove('hidden'); |
| 1140 child.style.backgroundColor = color; | 1140 child.style.backgroundColor = color; |
| 1141 child.style.borderColor = color; | 1141 child.style.borderColor = color; |
| 1142 if (offset) | 1142 if (offset) |
| 1143 child.style.marginLeft = offset + 'px'; | 1143 child.style.marginLeft = offset + 'px'; |
| 1144 offset += 3; | 1144 offset += 3; |
| 1145 } | 1145 } |
| 1146 } | 1146 } |
| 1147 } | 1147 } |
| 1148 } | 1148 } |
| 1149 | 1149 |
| 1150 /** | 1150 /** |
| 1151 * @param {!Node} parentElement | 1151 * @param {!Node} parentElement |
| 1152 * @param {string} name | 1152 * @param {string} name |
| 1153 * @param {string} value | 1153 * @param {string} value |
| 1154 * @param {?WebInspector.ElementsTreeOutline.UpdateRecord} updateRecord | 1154 * @param {?Elements.ElementsTreeOutline.UpdateRecord} updateRecord |
| 1155 * @param {boolean=} forceValue | 1155 * @param {boolean=} forceValue |
| 1156 * @param {!WebInspector.DOMNode=} node | 1156 * @param {!SDK.DOMNode=} node |
| 1157 */ | 1157 */ |
| 1158 _buildAttributeDOM(parentElement, name, value, updateRecord, forceValue, node)
{ | 1158 _buildAttributeDOM(parentElement, name, value, updateRecord, forceValue, node)
{ |
| 1159 var closingPunctuationRegex = /[\/;:\)\]\}]/g; | 1159 var closingPunctuationRegex = /[\/;:\)\]\}]/g; |
| 1160 var highlightIndex = 0; | 1160 var highlightIndex = 0; |
| 1161 var highlightCount; | 1161 var highlightCount; |
| 1162 var additionalHighlightOffset = 0; | 1162 var additionalHighlightOffset = 0; |
| 1163 var result; | 1163 var result; |
| 1164 | 1164 |
| 1165 /** | 1165 /** |
| 1166 * @param {string} match | 1166 * @param {string} match |
| 1167 * @param {number} replaceOffset | 1167 * @param {number} replaceOffset |
| 1168 * @return {string} | 1168 * @return {string} |
| 1169 */ | 1169 */ |
| 1170 function replacer(match, replaceOffset) { | 1170 function replacer(match, replaceOffset) { |
| 1171 while (highlightIndex < highlightCount && result.entityRanges[highlightInd
ex].offset < replaceOffset) { | 1171 while (highlightIndex < highlightCount && result.entityRanges[highlightInd
ex].offset < replaceOffset) { |
| 1172 result.entityRanges[highlightIndex].offset += additionalHighlightOffset; | 1172 result.entityRanges[highlightIndex].offset += additionalHighlightOffset; |
| 1173 ++highlightIndex; | 1173 ++highlightIndex; |
| 1174 } | 1174 } |
| 1175 additionalHighlightOffset += 1; | 1175 additionalHighlightOffset += 1; |
| 1176 return match + '\u200B'; | 1176 return match + '\u200B'; |
| 1177 } | 1177 } |
| 1178 | 1178 |
| 1179 /** | 1179 /** |
| 1180 * @param {!Element} element | 1180 * @param {!Element} element |
| 1181 * @param {string} value | 1181 * @param {string} value |
| 1182 * @this {WebInspector.ElementsTreeElement} | 1182 * @this {Elements.ElementsTreeElement} |
| 1183 */ | 1183 */ |
| 1184 function setValueWithEntities(element, value) { | 1184 function setValueWithEntities(element, value) { |
| 1185 result = this._convertWhitespaceToEntities(value); | 1185 result = this._convertWhitespaceToEntities(value); |
| 1186 highlightCount = result.entityRanges.length; | 1186 highlightCount = result.entityRanges.length; |
| 1187 value = result.text.replace(closingPunctuationRegex, replacer); | 1187 value = result.text.replace(closingPunctuationRegex, replacer); |
| 1188 while (highlightIndex < highlightCount) { | 1188 while (highlightIndex < highlightCount) { |
| 1189 result.entityRanges[highlightIndex].offset += additionalHighlightOffset; | 1189 result.entityRanges[highlightIndex].offset += additionalHighlightOffset; |
| 1190 ++highlightIndex; | 1190 ++highlightIndex; |
| 1191 } | 1191 } |
| 1192 element.setTextContentTruncatedIfNeeded(value); | 1192 element.setTextContentTruncatedIfNeeded(value); |
| 1193 WebInspector.highlightRangesWithStyleClass(element, result.entityRanges, '
webkit-html-entity-value'); | 1193 UI.highlightRangesWithStyleClass(element, result.entityRanges, 'webkit-htm
l-entity-value'); |
| 1194 } | 1194 } |
| 1195 | 1195 |
| 1196 var hasText = (forceValue || value.length > 0); | 1196 var hasText = (forceValue || value.length > 0); |
| 1197 var attrSpanElement = parentElement.createChild('span', 'webkit-html-attribu
te'); | 1197 var attrSpanElement = parentElement.createChild('span', 'webkit-html-attribu
te'); |
| 1198 var attrNameElement = attrSpanElement.createChild('span', 'webkit-html-attri
bute-name'); | 1198 var attrNameElement = attrSpanElement.createChild('span', 'webkit-html-attri
bute-name'); |
| 1199 attrNameElement.textContent = name; | 1199 attrNameElement.textContent = name; |
| 1200 | 1200 |
| 1201 if (hasText) | 1201 if (hasText) |
| 1202 attrSpanElement.createTextChild('=\u200B"'); | 1202 attrSpanElement.createTextChild('=\u200B"'); |
| 1203 | 1203 |
| 1204 var attrValueElement = attrSpanElement.createChild('span', 'webkit-html-attr
ibute-value'); | 1204 var attrValueElement = attrSpanElement.createChild('span', 'webkit-html-attr
ibute-value'); |
| 1205 | 1205 |
| 1206 if (updateRecord && updateRecord.isAttributeModified(name)) | 1206 if (updateRecord && updateRecord.isAttributeModified(name)) |
| 1207 WebInspector.runCSSAnimationOnce(hasText ? attrValueElement : attrNameElem
ent, 'dom-update-highlight'); | 1207 UI.runCSSAnimationOnce(hasText ? attrValueElement : attrNameElement, 'dom-
update-highlight'); |
| 1208 | 1208 |
| 1209 /** | 1209 /** |
| 1210 * @this {WebInspector.ElementsTreeElement} | 1210 * @this {Elements.ElementsTreeElement} |
| 1211 * @param {string} value | 1211 * @param {string} value |
| 1212 * @return {!Element} | 1212 * @return {!Element} |
| 1213 */ | 1213 */ |
| 1214 function linkifyValue(value) { | 1214 function linkifyValue(value) { |
| 1215 var rewrittenHref = node.resolveURL(value); | 1215 var rewrittenHref = node.resolveURL(value); |
| 1216 if (rewrittenHref === null) { | 1216 if (rewrittenHref === null) { |
| 1217 var span = createElement('span'); | 1217 var span = createElement('span'); |
| 1218 setValueWithEntities.call(this, span, value); | 1218 setValueWithEntities.call(this, span, value); |
| 1219 return span; | 1219 return span; |
| 1220 } | 1220 } |
| 1221 value = value.replace(closingPunctuationRegex, '$&\u200B'); | 1221 value = value.replace(closingPunctuationRegex, '$&\u200B'); |
| 1222 if (value.startsWith('data:')) | 1222 if (value.startsWith('data:')) |
| 1223 value = value.trimMiddle(60); | 1223 value = value.trimMiddle(60); |
| 1224 var anchor = WebInspector.linkifyURLAsNode(rewrittenHref, value, '', node.
nodeName().toLowerCase() === 'a'); | 1224 var anchor = UI.linkifyURLAsNode(rewrittenHref, value, '', node.nodeName()
.toLowerCase() === 'a'); |
| 1225 anchor.preventFollow = true; | 1225 anchor.preventFollow = true; |
| 1226 return anchor; | 1226 return anchor; |
| 1227 } | 1227 } |
| 1228 | 1228 |
| 1229 if (node && (name === 'src' || name === 'href')) { | 1229 if (node && (name === 'src' || name === 'href')) { |
| 1230 attrValueElement.appendChild(linkifyValue.call(this, value)); | 1230 attrValueElement.appendChild(linkifyValue.call(this, value)); |
| 1231 } else if ( | 1231 } else if ( |
| 1232 node && (node.nodeName().toLowerCase() === 'img' || node.nodeName().toLo
werCase() === 'source') && | 1232 node && (node.nodeName().toLowerCase() === 'img' || node.nodeName().toLo
werCase() === 'source') && |
| 1233 name === 'srcset') { | 1233 name === 'srcset') { |
| 1234 var sources = value.split(','); | 1234 var sources = value.split(','); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1267 var pseudoElement = parentElement.createChild('span', 'webkit-html-pseudo-el
ement'); | 1267 var pseudoElement = parentElement.createChild('span', 'webkit-html-pseudo-el
ement'); |
| 1268 pseudoElement.textContent = '::' + pseudoElementName; | 1268 pseudoElement.textContent = '::' + pseudoElementName; |
| 1269 parentElement.createTextChild('\u200B'); | 1269 parentElement.createTextChild('\u200B'); |
| 1270 } | 1270 } |
| 1271 | 1271 |
| 1272 /** | 1272 /** |
| 1273 * @param {!Node} parentElement | 1273 * @param {!Node} parentElement |
| 1274 * @param {string} tagName | 1274 * @param {string} tagName |
| 1275 * @param {boolean} isClosingTag | 1275 * @param {boolean} isClosingTag |
| 1276 * @param {boolean} isDistinctTreeElement | 1276 * @param {boolean} isDistinctTreeElement |
| 1277 * @param {?WebInspector.ElementsTreeOutline.UpdateRecord} updateRecord | 1277 * @param {?Elements.ElementsTreeOutline.UpdateRecord} updateRecord |
| 1278 */ | 1278 */ |
| 1279 _buildTagDOM(parentElement, tagName, isClosingTag, isDistinctTreeElement, upda
teRecord) { | 1279 _buildTagDOM(parentElement, tagName, isClosingTag, isDistinctTreeElement, upda
teRecord) { |
| 1280 var node = this._node; | 1280 var node = this._node; |
| 1281 var classes = ['webkit-html-tag']; | 1281 var classes = ['webkit-html-tag']; |
| 1282 if (isClosingTag && isDistinctTreeElement) | 1282 if (isClosingTag && isDistinctTreeElement) |
| 1283 classes.push('close'); | 1283 classes.push('close'); |
| 1284 var tagElement = parentElement.createChild('span', classes.join(' ')); | 1284 var tagElement = parentElement.createChild('span', classes.join(' ')); |
| 1285 tagElement.createTextChild('<'); | 1285 tagElement.createTextChild('<'); |
| 1286 var tagNameElement = | 1286 var tagNameElement = |
| 1287 tagElement.createChild('span', isClosingTag ? 'webkit-html-close-tag-nam
e' : 'webkit-html-tag-name'); | 1287 tagElement.createChild('span', isClosingTag ? 'webkit-html-close-tag-nam
e' : 'webkit-html-tag-name'); |
| 1288 tagNameElement.textContent = (isClosingTag ? '/' : '') + tagName; | 1288 tagNameElement.textContent = (isClosingTag ? '/' : '') + tagName; |
| 1289 if (!isClosingTag) { | 1289 if (!isClosingTag) { |
| 1290 if (node.hasAttributes()) { | 1290 if (node.hasAttributes()) { |
| 1291 var attributes = node.attributes(); | 1291 var attributes = node.attributes(); |
| 1292 for (var i = 0; i < attributes.length; ++i) { | 1292 for (var i = 0; i < attributes.length; ++i) { |
| 1293 var attr = attributes[i]; | 1293 var attr = attributes[i]; |
| 1294 tagElement.createTextChild(' '); | 1294 tagElement.createTextChild(' '); |
| 1295 this._buildAttributeDOM(tagElement, attr.name, attr.value, updateRecor
d, false, node); | 1295 this._buildAttributeDOM(tagElement, attr.name, attr.value, updateRecor
d, false, node); |
| 1296 } | 1296 } |
| 1297 } | 1297 } |
| 1298 if (updateRecord) { | 1298 if (updateRecord) { |
| 1299 var hasUpdates = updateRecord.hasRemovedAttributes() || updateRecord.has
RemovedChildren(); | 1299 var hasUpdates = updateRecord.hasRemovedAttributes() || updateRecord.has
RemovedChildren(); |
| 1300 hasUpdates |= !this.expanded && updateRecord.hasChangedChildren(); | 1300 hasUpdates |= !this.expanded && updateRecord.hasChangedChildren(); |
| 1301 if (hasUpdates) | 1301 if (hasUpdates) |
| 1302 WebInspector.runCSSAnimationOnce(tagNameElement, 'dom-update-highlight
'); | 1302 UI.runCSSAnimationOnce(tagNameElement, 'dom-update-highlight'); |
| 1303 } | 1303 } |
| 1304 } | 1304 } |
| 1305 | 1305 |
| 1306 tagElement.createTextChild('>'); | 1306 tagElement.createTextChild('>'); |
| 1307 parentElement.createTextChild('\u200B'); | 1307 parentElement.createTextChild('\u200B'); |
| 1308 } | 1308 } |
| 1309 | 1309 |
| 1310 /** | 1310 /** |
| 1311 * @param {string} text | 1311 * @param {string} text |
| 1312 * @return {!{text: string, entityRanges: !Array.<!WebInspector.SourceRange>}} | 1312 * @return {!{text: string, entityRanges: !Array.<!Common.SourceRange>}} |
| 1313 */ | 1313 */ |
| 1314 _convertWhitespaceToEntities(text) { | 1314 _convertWhitespaceToEntities(text) { |
| 1315 var result = ''; | 1315 var result = ''; |
| 1316 var lastIndexAfterEntity = 0; | 1316 var lastIndexAfterEntity = 0; |
| 1317 var entityRanges = []; | 1317 var entityRanges = []; |
| 1318 var charToEntity = WebInspector.ElementsTreeOutline.MappedCharToEntity; | 1318 var charToEntity = Elements.ElementsTreeOutline.MappedCharToEntity; |
| 1319 for (var i = 0, size = text.length; i < size; ++i) { | 1319 for (var i = 0, size = text.length; i < size; ++i) { |
| 1320 var char = text.charAt(i); | 1320 var char = text.charAt(i); |
| 1321 if (charToEntity[char]) { | 1321 if (charToEntity[char]) { |
| 1322 result += text.substring(lastIndexAfterEntity, i); | 1322 result += text.substring(lastIndexAfterEntity, i); |
| 1323 var entityValue = '&' + charToEntity[char] + ';'; | 1323 var entityValue = '&' + charToEntity[char] + ';'; |
| 1324 entityRanges.push({offset: result.length, length: entityValue.length}); | 1324 entityRanges.push({offset: result.length, length: entityValue.length}); |
| 1325 result += entityValue; | 1325 result += entityValue; |
| 1326 lastIndexAfterEntity = i + 1; | 1326 lastIndexAfterEntity = i + 1; |
| 1327 } | 1327 } |
| 1328 } | 1328 } |
| 1329 if (result) | 1329 if (result) |
| 1330 result += text.substring(lastIndexAfterEntity); | 1330 result += text.substring(lastIndexAfterEntity); |
| 1331 return {text: result || text, entityRanges: entityRanges}; | 1331 return {text: result || text, entityRanges: entityRanges}; |
| 1332 } | 1332 } |
| 1333 | 1333 |
| 1334 /** | 1334 /** |
| 1335 * @param {?WebInspector.ElementsTreeOutline.UpdateRecord} updateRecord | 1335 * @param {?Elements.ElementsTreeOutline.UpdateRecord} updateRecord |
| 1336 * @return {!DocumentFragment} result | 1336 * @return {!DocumentFragment} result |
| 1337 */ | 1337 */ |
| 1338 _nodeTitleInfo(updateRecord) { | 1338 _nodeTitleInfo(updateRecord) { |
| 1339 var node = this._node; | 1339 var node = this._node; |
| 1340 var titleDOM = createDocumentFragment(); | 1340 var titleDOM = createDocumentFragment(); |
| 1341 | 1341 |
| 1342 switch (node.nodeType()) { | 1342 switch (node.nodeType()) { |
| 1343 case Node.ATTRIBUTE_NODE: | 1343 case Node.ATTRIBUTE_NODE: |
| 1344 this._buildAttributeDOM( | 1344 this._buildAttributeDOM( |
| 1345 titleDOM, /** @type {string} */ (node.name), /** @type {string} */ (
node.value), updateRecord, true); | 1345 titleDOM, /** @type {string} */ (node.name), /** @type {string} */ (
node.value), updateRecord, true); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1363 if (this.isExpandable()) { | 1363 if (this.isExpandable()) { |
| 1364 if (!this.expanded) { | 1364 if (!this.expanded) { |
| 1365 var textNodeElement = titleDOM.createChild('span', 'webkit-html-text
-node bogus'); | 1365 var textNodeElement = titleDOM.createChild('span', 'webkit-html-text
-node bogus'); |
| 1366 textNodeElement.textContent = '\u2026'; | 1366 textNodeElement.textContent = '\u2026'; |
| 1367 titleDOM.createTextChild('\u200B'); | 1367 titleDOM.createTextChild('\u200B'); |
| 1368 this._buildTagDOM(titleDOM, tagName, true, false, updateRecord); | 1368 this._buildTagDOM(titleDOM, tagName, true, false, updateRecord); |
| 1369 } | 1369 } |
| 1370 break; | 1370 break; |
| 1371 } | 1371 } |
| 1372 | 1372 |
| 1373 if (WebInspector.ElementsTreeElement.canShowInlineText(node)) { | 1373 if (Elements.ElementsTreeElement.canShowInlineText(node)) { |
| 1374 var textNodeElement = titleDOM.createChild('span', 'webkit-html-text-n
ode'); | 1374 var textNodeElement = titleDOM.createChild('span', 'webkit-html-text-n
ode'); |
| 1375 var result = this._convertWhitespaceToEntities(node.firstChild.nodeVal
ue()); | 1375 var result = this._convertWhitespaceToEntities(node.firstChild.nodeVal
ue()); |
| 1376 textNodeElement.textContent = result.text; | 1376 textNodeElement.textContent = result.text; |
| 1377 WebInspector.highlightRangesWithStyleClass(textNodeElement, result.ent
ityRanges, 'webkit-html-entity-value'); | 1377 UI.highlightRangesWithStyleClass(textNodeElement, result.entityRanges,
'webkit-html-entity-value'); |
| 1378 titleDOM.createTextChild('\u200B'); | 1378 titleDOM.createTextChild('\u200B'); |
| 1379 this._buildTagDOM(titleDOM, tagName, true, false, updateRecord); | 1379 this._buildTagDOM(titleDOM, tagName, true, false, updateRecord); |
| 1380 if (updateRecord && updateRecord.hasChangedChildren()) | 1380 if (updateRecord && updateRecord.hasChangedChildren()) |
| 1381 WebInspector.runCSSAnimationOnce(textNodeElement, 'dom-update-highli
ght'); | 1381 UI.runCSSAnimationOnce(textNodeElement, 'dom-update-highlight'); |
| 1382 if (updateRecord && updateRecord.isCharDataModified()) | 1382 if (updateRecord && updateRecord.isCharDataModified()) |
| 1383 WebInspector.runCSSAnimationOnce(textNodeElement, 'dom-update-highli
ght'); | 1383 UI.runCSSAnimationOnce(textNodeElement, 'dom-update-highlight'); |
| 1384 break; | 1384 break; |
| 1385 } | 1385 } |
| 1386 | 1386 |
| 1387 if (this.treeOutline.isXMLMimeType || | 1387 if (this.treeOutline.isXMLMimeType || |
| 1388 !WebInspector.ElementsTreeElement.ForbiddenClosingTagElements.has(ta
gName)) | 1388 !Elements.ElementsTreeElement.ForbiddenClosingTagElements.has(tagNam
e)) |
| 1389 this._buildTagDOM(titleDOM, tagName, true, false, updateRecord); | 1389 this._buildTagDOM(titleDOM, tagName, true, false, updateRecord); |
| 1390 break; | 1390 break; |
| 1391 | 1391 |
| 1392 case Node.TEXT_NODE: | 1392 case Node.TEXT_NODE: |
| 1393 if (node.parentNode && node.parentNode.nodeName().toLowerCase() === 'scr
ipt') { | 1393 if (node.parentNode && node.parentNode.nodeName().toLowerCase() === 'scr
ipt') { |
| 1394 var newNode = titleDOM.createChild('span', 'webkit-html-text-node webk
it-html-js-node'); | 1394 var newNode = titleDOM.createChild('span', 'webkit-html-text-node webk
it-html-js-node'); |
| 1395 var text = node.nodeValue(); | 1395 var text = node.nodeValue(); |
| 1396 newNode.textContent = text.startsWith('\n') ? text.substring(1) : text
; | 1396 newNode.textContent = text.startsWith('\n') ? text.substring(1) : text
; |
| 1397 | 1397 |
| 1398 var javascriptSyntaxHighlighter = new WebInspector.DOMSyntaxHighlighte
r('text/javascript', true); | 1398 var javascriptSyntaxHighlighter = new UI.DOMSyntaxHighlighter('text/ja
vascript', true); |
| 1399 javascriptSyntaxHighlighter.syntaxHighlightNode(newNode).then(updateSe
archHighlight.bind(this)); | 1399 javascriptSyntaxHighlighter.syntaxHighlightNode(newNode).then(updateSe
archHighlight.bind(this)); |
| 1400 } else if (node.parentNode && node.parentNode.nodeName().toLowerCase() =
== 'style') { | 1400 } else if (node.parentNode && node.parentNode.nodeName().toLowerCase() =
== 'style') { |
| 1401 var newNode = titleDOM.createChild('span', 'webkit-html-text-node webk
it-html-css-node'); | 1401 var newNode = titleDOM.createChild('span', 'webkit-html-text-node webk
it-html-css-node'); |
| 1402 var text = node.nodeValue(); | 1402 var text = node.nodeValue(); |
| 1403 newNode.textContent = text.startsWith('\n') ? text.substring(1) : text
; | 1403 newNode.textContent = text.startsWith('\n') ? text.substring(1) : text
; |
| 1404 | 1404 |
| 1405 var cssSyntaxHighlighter = new WebInspector.DOMSyntaxHighlighter('text
/css', true); | 1405 var cssSyntaxHighlighter = new UI.DOMSyntaxHighlighter('text/css', tru
e); |
| 1406 cssSyntaxHighlighter.syntaxHighlightNode(newNode).then(updateSearchHig
hlight.bind(this)); | 1406 cssSyntaxHighlighter.syntaxHighlightNode(newNode).then(updateSearchHig
hlight.bind(this)); |
| 1407 } else { | 1407 } else { |
| 1408 titleDOM.createTextChild('"'); | 1408 titleDOM.createTextChild('"'); |
| 1409 var textNodeElement = titleDOM.createChild('span', 'webkit-html-text-n
ode'); | 1409 var textNodeElement = titleDOM.createChild('span', 'webkit-html-text-n
ode'); |
| 1410 var result = this._convertWhitespaceToEntities(node.nodeValue()); | 1410 var result = this._convertWhitespaceToEntities(node.nodeValue()); |
| 1411 textNodeElement.textContent = result.text; | 1411 textNodeElement.textContent = result.text; |
| 1412 WebInspector.highlightRangesWithStyleClass(textNodeElement, result.ent
ityRanges, 'webkit-html-entity-value'); | 1412 UI.highlightRangesWithStyleClass(textNodeElement, result.entityRanges,
'webkit-html-entity-value'); |
| 1413 titleDOM.createTextChild('"'); | 1413 titleDOM.createTextChild('"'); |
| 1414 if (updateRecord && updateRecord.isCharDataModified()) | 1414 if (updateRecord && updateRecord.isCharDataModified()) |
| 1415 WebInspector.runCSSAnimationOnce(textNodeElement, 'dom-update-highli
ght'); | 1415 UI.runCSSAnimationOnce(textNodeElement, 'dom-update-highlight'); |
| 1416 } | 1416 } |
| 1417 break; | 1417 break; |
| 1418 | 1418 |
| 1419 case Node.COMMENT_NODE: | 1419 case Node.COMMENT_NODE: |
| 1420 var commentElement = titleDOM.createChild('span', 'webkit-html-comment')
; | 1420 var commentElement = titleDOM.createChild('span', 'webkit-html-comment')
; |
| 1421 commentElement.createTextChild('<!--' + node.nodeValue() + '-->'); | 1421 commentElement.createTextChild('<!--' + node.nodeValue() + '-->'); |
| 1422 break; | 1422 break; |
| 1423 | 1423 |
| 1424 case Node.DOCUMENT_TYPE_NODE: | 1424 case Node.DOCUMENT_TYPE_NODE: |
| 1425 var docTypeElement = titleDOM.createChild('span', 'webkit-html-doctype')
; | 1425 var docTypeElement = titleDOM.createChild('span', 'webkit-html-doctype')
; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1444 | 1444 |
| 1445 case Node.DOCUMENT_FRAGMENT_NODE: | 1445 case Node.DOCUMENT_FRAGMENT_NODE: |
| 1446 var fragmentElement = titleDOM.createChild('span', 'webkit-html-fragment
'); | 1446 var fragmentElement = titleDOM.createChild('span', 'webkit-html-fragment
'); |
| 1447 fragmentElement.textContent = node.nodeNameInCorrectCase().collapseWhite
space(); | 1447 fragmentElement.textContent = node.nodeNameInCorrectCase().collapseWhite
space(); |
| 1448 break; | 1448 break; |
| 1449 default: | 1449 default: |
| 1450 titleDOM.createTextChild(node.nodeNameInCorrectCase().collapseWhitespace
()); | 1450 titleDOM.createTextChild(node.nodeNameInCorrectCase().collapseWhitespace
()); |
| 1451 } | 1451 } |
| 1452 | 1452 |
| 1453 /** | 1453 /** |
| 1454 * @this {WebInspector.ElementsTreeElement} | 1454 * @this {Elements.ElementsTreeElement} |
| 1455 */ | 1455 */ |
| 1456 function updateSearchHighlight() { | 1456 function updateSearchHighlight() { |
| 1457 delete this._highlightResult; | 1457 delete this._highlightResult; |
| 1458 this._highlightSearchResults(); | 1458 this._highlightSearchResults(); |
| 1459 } | 1459 } |
| 1460 | 1460 |
| 1461 return titleDOM; | 1461 return titleDOM; |
| 1462 } | 1462 } |
| 1463 | 1463 |
| 1464 remove() { | 1464 remove() { |
| 1465 if (this._node.pseudoType()) | 1465 if (this._node.pseudoType()) |
| 1466 return; | 1466 return; |
| 1467 var parentElement = this.parent; | 1467 var parentElement = this.parent; |
| 1468 if (!parentElement) | 1468 if (!parentElement) |
| 1469 return; | 1469 return; |
| 1470 | 1470 |
| 1471 if (!this._node.parentNode || this._node.parentNode.nodeType() === Node.DOCU
MENT_NODE) | 1471 if (!this._node.parentNode || this._node.parentNode.nodeType() === Node.DOCU
MENT_NODE) |
| 1472 return; | 1472 return; |
| 1473 this._node.removeNode(); | 1473 this._node.removeNode(); |
| 1474 } | 1474 } |
| 1475 | 1475 |
| 1476 /** | 1476 /** |
| 1477 * @param {function(boolean)=} callback | 1477 * @param {function(boolean)=} callback |
| 1478 * @param {boolean=} startEditing | 1478 * @param {boolean=} startEditing |
| 1479 */ | 1479 */ |
| 1480 toggleEditAsHTML(callback, startEditing) { | 1480 toggleEditAsHTML(callback, startEditing) { |
| 1481 if (this._editing && this._htmlEditElement && WebInspector.isBeingEdited(thi
s._htmlEditElement)) { | 1481 if (this._editing && this._htmlEditElement && UI.isBeingEdited(this._htmlEdi
tElement)) { |
| 1482 this._editing.commit(); | 1482 this._editing.commit(); |
| 1483 return; | 1483 return; |
| 1484 } | 1484 } |
| 1485 | 1485 |
| 1486 if (startEditing === false) | 1486 if (startEditing === false) |
| 1487 return; | 1487 return; |
| 1488 | 1488 |
| 1489 /** | 1489 /** |
| 1490 * @param {?Protocol.Error} error | 1490 * @param {?Protocol.Error} error |
| 1491 */ | 1491 */ |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1506 function disposeCallback() { | 1506 function disposeCallback() { |
| 1507 if (callback) | 1507 if (callback) |
| 1508 callback(false); | 1508 callback(false); |
| 1509 } | 1509 } |
| 1510 | 1510 |
| 1511 var node = this._node; | 1511 var node = this._node; |
| 1512 node.getOuterHTML(this._startEditingAsHTML.bind(this, commitChange, disposeC
allback)); | 1512 node.getOuterHTML(this._startEditingAsHTML.bind(this, commitChange, disposeC
allback)); |
| 1513 } | 1513 } |
| 1514 | 1514 |
| 1515 _copyCSSPath() { | 1515 _copyCSSPath() { |
| 1516 InspectorFrontendHost.copyText(WebInspector.DOMPresentationUtils.cssPath(thi
s._node, true)); | 1516 InspectorFrontendHost.copyText(Components.DOMPresentationUtils.cssPath(this.
_node, true)); |
| 1517 } | 1517 } |
| 1518 | 1518 |
| 1519 _copyXPath() { | 1519 _copyXPath() { |
| 1520 InspectorFrontendHost.copyText(WebInspector.DOMPresentationUtils.xPath(this.
_node, true)); | 1520 InspectorFrontendHost.copyText(Components.DOMPresentationUtils.xPath(this._n
ode, true)); |
| 1521 } | 1521 } |
| 1522 | 1522 |
| 1523 _highlightSearchResults() { | 1523 _highlightSearchResults() { |
| 1524 if (!this._searchQuery || !this._searchHighlightsVisible) | 1524 if (!this._searchQuery || !this._searchHighlightsVisible) |
| 1525 return; | 1525 return; |
| 1526 this._hideSearchHighlight(); | 1526 this._hideSearchHighlight(); |
| 1527 | 1527 |
| 1528 var text = this.listItemElement.textContent; | 1528 var text = this.listItemElement.textContent; |
| 1529 var regexObject = createPlainTextSearchRegex(this._searchQuery, 'gi'); | 1529 var regexObject = createPlainTextSearchRegex(this._searchQuery, 'gi'); |
| 1530 | 1530 |
| 1531 var match = regexObject.exec(text); | 1531 var match = regexObject.exec(text); |
| 1532 var matchRanges = []; | 1532 var matchRanges = []; |
| 1533 while (match) { | 1533 while (match) { |
| 1534 matchRanges.push(new WebInspector.SourceRange(match.index, match[0].length
)); | 1534 matchRanges.push(new Common.SourceRange(match.index, match[0].length)); |
| 1535 match = regexObject.exec(text); | 1535 match = regexObject.exec(text); |
| 1536 } | 1536 } |
| 1537 | 1537 |
| 1538 // Fall back for XPath, etc. matches. | 1538 // Fall back for XPath, etc. matches. |
| 1539 if (!matchRanges.length) | 1539 if (!matchRanges.length) |
| 1540 matchRanges.push(new WebInspector.SourceRange(0, text.length)); | 1540 matchRanges.push(new Common.SourceRange(0, text.length)); |
| 1541 | 1541 |
| 1542 this._highlightResult = []; | 1542 this._highlightResult = []; |
| 1543 WebInspector.highlightSearchResults(this.listItemElement, matchRanges, this.
_highlightResult); | 1543 UI.highlightSearchResults(this.listItemElement, matchRanges, this._highlight
Result); |
| 1544 } | 1544 } |
| 1545 | 1545 |
| 1546 _scrollIntoView() { | 1546 _scrollIntoView() { |
| 1547 function scrollIntoViewCallback(object) { | 1547 function scrollIntoViewCallback(object) { |
| 1548 /** | 1548 /** |
| 1549 * @suppressReceiverCheck | 1549 * @suppressReceiverCheck |
| 1550 * @this {!Element} | 1550 * @this {!Element} |
| 1551 */ | 1551 */ |
| 1552 function scrollIntoView() { | 1552 function scrollIntoView() { |
| 1553 this.scrollIntoViewIfNeeded(true); | 1553 this.scrollIntoViewIfNeeded(true); |
| 1554 } | 1554 } |
| 1555 | 1555 |
| 1556 if (object) | 1556 if (object) |
| 1557 object.callFunction(scrollIntoView); | 1557 object.callFunction(scrollIntoView); |
| 1558 } | 1558 } |
| 1559 | 1559 |
| 1560 this._node.resolveToObject('', scrollIntoViewCallback); | 1560 this._node.resolveToObject('', scrollIntoViewCallback); |
| 1561 } | 1561 } |
| 1562 | 1562 |
| 1563 _editAsHTML() { | 1563 _editAsHTML() { |
| 1564 var promise = WebInspector.Revealer.revealPromise(this.node()); | 1564 var promise = Common.Revealer.revealPromise(this.node()); |
| 1565 promise.then(() => WebInspector.actionRegistry.action('elements.edit-as-html
').execute()); | 1565 promise.then(() => UI.actionRegistry.action('elements.edit-as-html').execute
()); |
| 1566 } | 1566 } |
| 1567 }; | 1567 }; |
| 1568 | 1568 |
| 1569 WebInspector.ElementsTreeElement.InitialChildrenLimit = 500; | 1569 Elements.ElementsTreeElement.InitialChildrenLimit = 500; |
| 1570 | 1570 |
| 1571 // A union of HTML4 and HTML5-Draft elements that explicitly | 1571 // A union of HTML4 and HTML5-Draft elements that explicitly |
| 1572 // or implicitly (for HTML5) forbid the closing tag. | 1572 // or implicitly (for HTML5) forbid the closing tag. |
| 1573 WebInspector.ElementsTreeElement.ForbiddenClosingTagElements = new Set([ | 1573 Elements.ElementsTreeElement.ForbiddenClosingTagElements = new Set([ |
| 1574 'area', 'base', 'basefont', 'br', 'canvas', 'col', 'command', 'embed',
'frame', 'hr', | 1574 'area', 'base', 'basefont', 'br', 'canvas', 'col', 'command', 'embed',
'frame', 'hr', |
| 1575 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source',
'track', 'wbr' | 1575 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source',
'track', 'wbr' |
| 1576 ]); | 1576 ]); |
| 1577 | 1577 |
| 1578 // These tags we do not allow editing their tag name. | 1578 // These tags we do not allow editing their tag name. |
| 1579 WebInspector.ElementsTreeElement.EditTagBlacklist = new Set(['html', 'head', 'bo
dy']); | 1579 Elements.ElementsTreeElement.EditTagBlacklist = new Set(['html', 'head', 'body']
); |
| OLD | NEW |