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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/ui/Widget.js

Issue 2319523004: DevTools: Remember the last focused widget. (Closed)
Patch Set: Fix test Created 4 years, 3 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
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/UIUtils.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved. 2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 * Copyright (C) 2011 Google Inc. All Rights Reserved. 3 * Copyright (C) 2011 Google Inc. All Rights Reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 30 matching lines...) Expand all
41 } 41 }
42 this._isWebComponent = isWebComponent; 42 this._isWebComponent = isWebComponent;
43 this.element.__widget = this; 43 this.element.__widget = this;
44 this._visible = false; 44 this._visible = false;
45 this._isRoot = false; 45 this._isRoot = false;
46 this._isShowing = false; 46 this._isShowing = false;
47 this._children = []; 47 this._children = [];
48 this._hideOnDetach = false; 48 this._hideOnDetach = false;
49 this._notificationDepth = 0; 49 this._notificationDepth = 0;
50 this._invalidationsSuspended = 0; 50 this._invalidationsSuspended = 0;
51 this._defaultFocusedChild = null;
51 } 52 }
52 53
53 WebInspector.Widget.prototype = { 54 WebInspector.Widget.prototype = {
54 markAsRoot: function() 55 markAsRoot: function()
55 { 56 {
56 WebInspector.Widget.__assert(!this.element.parentElement, "Attempt to ma rk as root attached node"); 57 WebInspector.Widget.__assert(!this.element.parentElement, "Attempt to ma rk as root attached node");
57 this._isRoot = true; 58 this._isRoot = true;
58 }, 59 },
59 60
60 /** 61 /**
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 return; 326 return;
326 327
327 if (this._visible) 328 if (this._visible)
328 this._hideWidget(true); 329 this._hideWidget(true);
329 330
330 // Update widget hierarchy. 331 // Update widget hierarchy.
331 if (this._parentWidget) { 332 if (this._parentWidget) {
332 var childIndex = this._parentWidget._children.indexOf(this); 333 var childIndex = this._parentWidget._children.indexOf(this);
333 WebInspector.Widget.__assert(childIndex >= 0, "Attempt to remove non -child widget"); 334 WebInspector.Widget.__assert(childIndex >= 0, "Attempt to remove non -child widget");
334 this._parentWidget._children.splice(childIndex, 1); 335 this._parentWidget._children.splice(childIndex, 1);
336 if (this._parentWidget._defaultFocusedChild === this)
337 this._parentWidget._defaultFocusedChild = null;
335 this._parentWidget.childWasDetached(this); 338 this._parentWidget.childWasDetached(this);
336 var parent = this._parentWidget; 339 var parent = this._parentWidget;
337 this._parentWidget = null; 340 this._parentWidget = null;
338 } else { 341 } else {
339 WebInspector.Widget.__assert(this._isRoot, "Removing non-root widget from DOM"); 342 WebInspector.Widget.__assert(this._isRoot, "Removing non-root widget from DOM");
340 } 343 }
341 }, 344 },
342 345
343 detachChildWidgets: function() 346 detachChildWidgets: function()
344 { 347 {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 }, 424 },
422 425
423 /** 426 /**
424 * @param {!Element} element 427 * @param {!Element} element
425 */ 428 */
426 setDefaultFocusedElement: function(element) 429 setDefaultFocusedElement: function(element)
427 { 430 {
428 this._defaultFocusedElement = element; 431 this._defaultFocusedElement = element;
429 }, 432 },
430 433
434 /**
435 * @param {!WebInspector.Widget} child
436 */
437 setDefaultFocusedChild: function(child)
438 {
439 WebInspector.Widget.__assert(child._parentWidget === this, "Attempt to s et non-child widget as default focused.");
440 this._defaultFocusedChild = child;
441 },
442
431 focus: function() 443 focus: function()
432 { 444 {
433 var element = this._defaultFocusedElement; 445 var element = this._defaultFocusedElement;
434 if (element && !element.isAncestor(this.element.ownerDocument.activeElem ent)) { 446 if (element && !element.isAncestor(this.element.ownerDocument.activeElem ent)) {
435 WebInspector.setCurrentFocusElement(element); 447 WebInspector.setCurrentFocusElement(element);
436 return; 448 return;
437 } 449 }
438 450
439 if (this._children.length) 451 if (this._defaultFocusedChild && this._defaultFocusedChild._visible) {
440 this._children[0].focus(); 452 this._defaultFocusedChild.focus();
453 } else {
454 for (var child of this._children) {
455 if (child._visible) {
456 child.focus();
457 break;
458 }
459 }
460 }
461
441 }, 462 },
442 463
443 /** 464 /**
444 * @return {boolean} 465 * @return {boolean}
445 */ 466 */
446 hasFocus: function() 467 hasFocus: function()
447 { 468 {
448 var activeElement = this.element.ownerDocument.activeElement; 469 var activeElement = this.element.ownerDocument.activeElement;
449 return activeElement && activeElement.isSelfOrDescendant(this.element); 470 return activeElement && activeElement.isSelfOrDescendant(this.element);
450 }, 471 },
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 610
590 WebInspector.Widget.__assert = function(condition, message) 611 WebInspector.Widget.__assert = function(condition, message)
591 { 612 {
592 if (!condition) { 613 if (!condition) {
593 console.trace(); 614 console.trace();
594 throw new Error(message); 615 throw new Error(message);
595 } 616 }
596 } 617 }
597 618
598 /** 619 /**
620 * @param {?Node} node
621 */
622 WebInspector.Widget.focusWidgetForNode = function(node)
623 {
624 while (node) {
625 if (node.__widget)
626 break;
627 node = node.parentNodeOrShadowHost();
628 }
629 if (!node)
630 return;
631
632 var widget = node.__widget;
633 while (widget._parentWidget) {
634 widget._parentWidget._defaultFocusedChild = widget;
635 widget = widget._parentWidget;
636 }
637 }
638
639 /**
599 * @constructor 640 * @constructor
600 * @extends {WebInspector.Widget} 641 * @extends {WebInspector.Widget}
601 * @param {boolean=} isWebComponent 642 * @param {boolean=} isWebComponent
602 */ 643 */
603 WebInspector.VBox = function(isWebComponent) 644 WebInspector.VBox = function(isWebComponent)
604 { 645 {
605 WebInspector.Widget.call(this, isWebComponent); 646 WebInspector.Widget.call(this, isWebComponent);
606 this.contentElement.classList.add("vbox"); 647 this.contentElement.classList.add("vbox");
607 }; 648 };
608 649
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 { 767 {
727 WebInspector.Widget.__assert(!child.__widgetCounter && !child.__widget, "Att empt to remove element containing widget via regular DOM operation"); 768 WebInspector.Widget.__assert(!child.__widgetCounter && !child.__widget, "Att empt to remove element containing widget via regular DOM operation");
728 return WebInspector.Widget._originalRemoveChild.call(this, child); 769 return WebInspector.Widget._originalRemoveChild.call(this, child);
729 } 770 }
730 771
731 Element.prototype.removeChildren = function() 772 Element.prototype.removeChildren = function()
732 { 773 {
733 WebInspector.Widget.__assert(!this.__widgetCounter, "Attempt to remove eleme nt containing widget via regular DOM operation"); 774 WebInspector.Widget.__assert(!this.__widgetCounter, "Attempt to remove eleme nt containing widget via regular DOM operation");
734 WebInspector.Widget._originalRemoveChildren.call(this); 775 WebInspector.Widget._originalRemoveChildren.call(this);
735 } 776 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/UIUtils.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698