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

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

Issue 2932543002: DevTools: reveal and highlight dom nodes when searching in elements panel. (Closed)
Patch Set: rebaseline Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 442 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 this.treeOutline.showContextMenu(this, event); 453 this.treeOutline.showContextMenu(this, event);
454 } 454 }
455 455
456 /** 456 /**
457 * @param {!UI.ContextMenu} contextMenu 457 * @param {!UI.ContextMenu} contextMenu
458 * @param {!Event} event 458 * @param {!Event} event
459 */ 459 */
460 populateTagContextMenu(contextMenu, event) { 460 populateTagContextMenu(contextMenu, event) {
461 // Add attribute-related actions. 461 // Add attribute-related actions.
462 var treeElement = this._elementCloseTag ? this.treeOutline.findTreeElement(t his._node) : this; 462 var treeElement = this._elementCloseTag ? this.treeOutline.findTreeElement(t his._node) : this;
463 contextMenu.appendItem( 463 contextMenu.appendItem(Common.UIString('Add attribute'), treeElement._addNew Attribute.bind(treeElement));
464 Common.UIString.capitalize('Add ^attribute'), treeElement._addNewAttribu te.bind(treeElement));
465 464
466 var attribute = event.target.enclosingNodeOrSelfWithClass('webkit-html-attri bute'); 465 var attribute = event.target.enclosingNodeOrSelfWithClass('webkit-html-attri bute');
467 var newAttribute = event.target.enclosingNodeOrSelfWithClass('add-attribute' ); 466 var newAttribute = event.target.enclosingNodeOrSelfWithClass('add-attribute' );
468 if (attribute && !newAttribute) { 467 if (attribute && !newAttribute) {
469 contextMenu.appendItem( 468 contextMenu.appendItem(
470 Common.UIString.capitalize('Edit ^attribute'), 469 Common.UIString('Edit attribute'), this._startEditingAttribute.bind(th is, attribute, event.target));
471 this._startEditingAttribute.bind(this, attribute, event.target));
472 } 470 }
473 this.populateNodeContextMenu(contextMenu); 471 this.populateNodeContextMenu(contextMenu);
474 Elements.ElementsTreeElement.populateForcedPseudoStateItems(contextMenu, tre eElement.node()); 472 Elements.ElementsTreeElement.populateForcedPseudoStateItems(contextMenu, tre eElement.node());
475 contextMenu.appendSeparator(); 473 contextMenu.appendSeparator();
476 this.populateScrollIntoView(contextMenu); 474 this.populateScrollIntoView(contextMenu);
477 } 475 }
478 476
479 /** 477 /**
480 * @param {!UI.ContextMenu} contextMenu 478 * @param {!UI.ContextMenu} contextMenu
481 */ 479 */
482 populateScrollIntoView(contextMenu) { 480 populateScrollIntoView(contextMenu) {
483 contextMenu.appendItem(Common.UIString.capitalize('Scroll into ^view'), this ._scrollIntoView.bind(this)); 481 contextMenu.appendItem(Common.UIString('Scroll into view'), () => this._node .scrollIntoView());
484 } 482 }
485 483
486 populateTextContextMenu(contextMenu, textNode) { 484 populateTextContextMenu(contextMenu, textNode) {
487 if (!this._editing) 485 if (!this._editing)
488 contextMenu.appendItem(Common.UIString.capitalize('Edit ^text'), this._sta rtEditingTextNode.bind(this, textNode)); 486 contextMenu.appendItem(Common.UIString('Edit text'), this._startEditingTex tNode.bind(this, textNode));
489 this.populateNodeContextMenu(contextMenu); 487 this.populateNodeContextMenu(contextMenu);
490 } 488 }
491 489
492 populateNodeContextMenu(contextMenu) { 490 populateNodeContextMenu(contextMenu) {
493 // Add free-form node-related actions. 491 // Add free-form node-related actions.
494 var isEditable = this.hasEditableNode(); 492 var isEditable = this.hasEditableNode();
495 if (isEditable && !this._editing) 493 if (isEditable && !this._editing)
496 contextMenu.appendItem(Common.UIString('Edit as HTML'), this._editAsHTML.b ind(this)); 494 contextMenu.appendItem(Common.UIString('Edit as HTML'), this._editAsHTML.b ind(this));
497 var isShadowRoot = this._node.isShadowRoot(); 495 var isShadowRoot = this._node.isShadowRoot();
498 496
499 // Place it here so that all "Copy"-ing items stick together. 497 // Place it here so that all "Copy"-ing items stick together.
500 var copyMenu = contextMenu.appendSubMenuItem(Common.UIString('Copy')); 498 var copyMenu = contextMenu.appendSubMenuItem(Common.UIString('Copy'));
501 var createShortcut = UI.KeyboardShortcut.shortcutToString; 499 var createShortcut = UI.KeyboardShortcut.shortcutToString;
502 var modifier = UI.KeyboardShortcut.Modifiers.CtrlOrMeta; 500 var modifier = UI.KeyboardShortcut.Modifiers.CtrlOrMeta;
503 var treeOutline = this.treeOutline; 501 var treeOutline = this.treeOutline;
504 var menuItem; 502 var menuItem;
505 if (!isShadowRoot) { 503 if (!isShadowRoot) {
506 menuItem = copyMenu.appendItem( 504 menuItem = copyMenu.appendItem(
507 Common.UIString('Copy outerHTML'), treeOutline.performCopyOrCut.bind(t reeOutline, false, this._node)); 505 Common.UIString('Copy outerHTML'), treeOutline.performCopyOrCut.bind(t reeOutline, false, this._node));
508 menuItem.setShortcut(createShortcut('V', modifier)); 506 menuItem.setShortcut(createShortcut('V', modifier));
509 } 507 }
510 if (this._node.nodeType() === Node.ELEMENT_NODE) 508 if (this._node.nodeType() === Node.ELEMENT_NODE)
511 copyMenu.appendItem(Common.UIString.capitalize('Copy selector'), this._cop yCSSPath.bind(this)); 509 copyMenu.appendItem(Common.UIString('Copy selector'), this._copyCSSPath.bi nd(this));
512 if (!isShadowRoot) 510 if (!isShadowRoot)
513 copyMenu.appendItem(Common.UIString('Copy XPath'), this._copyXPath.bind(th is)); 511 copyMenu.appendItem(Common.UIString('Copy XPath'), this._copyXPath.bind(th is));
514 if (!isShadowRoot) { 512 if (!isShadowRoot) {
515 menuItem = copyMenu.appendItem( 513 menuItem = copyMenu.appendItem(
516 Common.UIString('Cut element'), treeOutline.performCopyOrCut.bind(tree Outline, true, this._node), 514 Common.UIString('Cut element'), treeOutline.performCopyOrCut.bind(tree Outline, true, this._node),
517 !this.hasEditableNode()); 515 !this.hasEditableNode());
518 menuItem.setShortcut(createShortcut('X', modifier)); 516 menuItem.setShortcut(createShortcut('X', modifier));
519 menuItem = copyMenu.appendItem( 517 menuItem = copyMenu.appendItem(
520 Common.UIString('Copy element'), treeOutline.performCopyOrCut.bind(tre eOutline, false, this._node)); 518 Common.UIString('Copy element'), treeOutline.performCopyOrCut.bind(tre eOutline, false, this._node));
521 menuItem.setShortcut(createShortcut('C', modifier)); 519 menuItem.setShortcut(createShortcut('C', modifier));
(...skipping 1100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1622 } 1620 }
1623 1621
1624 // Fall back for XPath, etc. matches. 1622 // Fall back for XPath, etc. matches.
1625 if (!matchRanges.length) 1623 if (!matchRanges.length)
1626 matchRanges.push(new TextUtils.SourceRange(0, text.length)); 1624 matchRanges.push(new TextUtils.SourceRange(0, text.length));
1627 1625
1628 this._highlightResult = []; 1626 this._highlightResult = [];
1629 UI.highlightSearchResults(this.listItemElement, matchRanges, this._highlight Result); 1627 UI.highlightSearchResults(this.listItemElement, matchRanges, this._highlight Result);
1630 } 1628 }
1631 1629
1632 _scrollIntoView() {
1633 function scrollIntoViewCallback(object) {
1634 /**
1635 * @suppressReceiverCheck
1636 * @this {!Element}
1637 */
1638 function scrollIntoView() {
1639 this.scrollIntoViewIfNeeded(true);
1640 }
1641
1642 if (object)
1643 object.callFunction(scrollIntoView);
1644 }
1645
1646 this._node.resolveToObject('', scrollIntoViewCallback);
1647 }
1648
1649 _editAsHTML() { 1630 _editAsHTML() {
1650 var promise = Common.Revealer.revealPromise(this.node()); 1631 var promise = Common.Revealer.revealPromise(this.node());
1651 promise.then(() => UI.actionRegistry.action('elements.edit-as-html').execute ()); 1632 promise.then(() => UI.actionRegistry.action('elements.edit-as-html').execute ());
1652 } 1633 }
1653 }; 1634 };
1654 1635
1655 Elements.ElementsTreeElement.HrefSymbol = Symbol('ElementsTreeElement.Href'); 1636 Elements.ElementsTreeElement.HrefSymbol = Symbol('ElementsTreeElement.Href');
1656 1637
1657 Elements.ElementsTreeElement.InitialChildrenLimit = 500; 1638 Elements.ElementsTreeElement.InitialChildrenLimit = 500;
1658 1639
1659 // A union of HTML4 and HTML5-Draft elements that explicitly 1640 // A union of HTML4 and HTML5-Draft elements that explicitly
1660 // or implicitly (for HTML5) forbid the closing tag. 1641 // or implicitly (for HTML5) forbid the closing tag.
1661 Elements.ElementsTreeElement.ForbiddenClosingTagElements = new Set([ 1642 Elements.ElementsTreeElement.ForbiddenClosingTagElements = new Set([
1662 'area', 'base', 'basefont', 'br', 'canvas', 'col', 'command', 'embed', 'frame', 'hr', 1643 'area', 'base', 'basefont', 'br', 'canvas', 'col', 'command', 'embed', 'frame', 'hr',
1663 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr' 1644 'img', 'input', 'keygen', 'link', 'menuitem', 'meta', 'param', 'source', 'track', 'wbr'
1664 ]); 1645 ]);
1665 1646
1666 // These tags we do not allow editing their tag name. 1647 // These tags we do not allow editing their tag name.
1667 Elements.ElementsTreeElement.EditTagBlacklist = new Set(['html', 'head', 'body'] ); 1648 Elements.ElementsTreeElement.EditTagBlacklist = new Set(['html', 'head', 'body'] );
1668 1649
1669 /** @typedef {{cancel: function(), commit: function(), resize: function(), edito r:!UI.TextEditor}} */ 1650 /** @typedef {{cancel: function(), commit: function(), resize: function(), edito r:!UI.TextEditor}} */
1670 Elements.MultilineEditorController; 1651 Elements.MultilineEditorController;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698