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

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: setDefaultFocusedChild 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
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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 * @param {!WebInspector.Widget} parentWidget 232 * @param {!WebInspector.Widget} parentWidget
232 */ 233 */
233 attach: function(parentWidget) 234 attach: function(parentWidget)
234 { 235 {
235 if (parentWidget === this._parentWidget) 236 if (parentWidget === this._parentWidget)
236 return; 237 return;
237 if (this._parentWidget) 238 if (this._parentWidget)
238 this.detach(); 239 this.detach();
239 this._parentWidget = parentWidget; 240 this._parentWidget = parentWidget;
240 this._parentWidget._children.push(this); 241 this._parentWidget._children.push(this);
242 if (!this._parentWidget._defaultFocusedChild)
243 this._parentWidget._defaultFocusedChild = this;
241 this._isRoot = false; 244 this._isRoot = false;
242 }, 245 },
243 246
244 /** 247 /**
245 * @param {!Element} parentElement 248 * @param {!Element} parentElement
246 * @param {?Element=} insertBefore 249 * @param {?Element=} insertBefore
247 */ 250 */
248 showWidget: function(parentElement, insertBefore) 251 showWidget: function(parentElement, insertBefore)
249 { 252 {
250 var currentParent = parentElement; 253 var currentParent = parentElement;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 return; 328 return;
326 329
327 if (this._visible) 330 if (this._visible)
328 this._hideWidget(true); 331 this._hideWidget(true);
329 332
330 // Update widget hierarchy. 333 // Update widget hierarchy.
331 if (this._parentWidget) { 334 if (this._parentWidget) {
332 var childIndex = this._parentWidget._children.indexOf(this); 335 var childIndex = this._parentWidget._children.indexOf(this);
333 WebInspector.Widget.__assert(childIndex >= 0, "Attempt to remove non -child widget"); 336 WebInspector.Widget.__assert(childIndex >= 0, "Attempt to remove non -child widget");
334 this._parentWidget._children.splice(childIndex, 1); 337 this._parentWidget._children.splice(childIndex, 1);
338 if (this._parentWidget._defaultFocusedChild === this)
339 this._parentWidget._defaultFocusedChild = this._parentWidget._ch ildren[0] || null;
335 this._parentWidget.childWasDetached(this); 340 this._parentWidget.childWasDetached(this);
336 var parent = this._parentWidget; 341 var parent = this._parentWidget;
337 this._parentWidget = null; 342 this._parentWidget = null;
338 } else { 343 } else {
339 WebInspector.Widget.__assert(this._isRoot, "Removing non-root widget from DOM"); 344 WebInspector.Widget.__assert(this._isRoot, "Removing non-root widget from DOM");
340 } 345 }
341 }, 346 },
342 347
343 detachChildWidgets: function() 348 detachChildWidgets: function()
344 { 349 {
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
421 }, 426 },
422 427
423 /** 428 /**
424 * @param {!Element} element 429 * @param {!Element} element
425 */ 430 */
426 setDefaultFocusedElement: function(element) 431 setDefaultFocusedElement: function(element)
427 { 432 {
428 this._defaultFocusedElement = element; 433 this._defaultFocusedElement = element;
429 }, 434 },
430 435
436 /**
437 * @param {!WebInspector.Widget} child
438 */
439 setDefaultFocusedChild: function(child)
440 {
441 var childIndex = this._children.indexOf(child);
442 WebInspector.Widget.__assert(childIndex >= 0, "Attempt to set non-child widget as default focused.");
dgozman 2016/09/12 16:50:22 Let's instead check child._parentWidget === this.
einbinder 2016/09/12 18:18:54 Done.
443 this._defaultFocusedChild = child;
444 },
445
431 focus: function() 446 focus: function()
432 { 447 {
433 var element = this._defaultFocusedElement; 448 var element = this._defaultFocusedElement;
434 if (element && !element.isAncestor(this.element.ownerDocument.activeElem ent)) { 449 if (element && !element.isAncestor(this.element.ownerDocument.activeElem ent)) {
435 WebInspector.setCurrentFocusElement(element); 450 WebInspector.setCurrentFocusElement(element);
436 return; 451 return;
437 } 452 }
438 453
439 if (this._children.length) 454 if (this._defaultFocusedChild)
dgozman 2016/09/12 16:50:22 Let's go to the first visible children if this is
einbinder 2016/09/12 18:18:54 Done.
440 this._children[0].focus(); 455 this._defaultFocusedChild.focus();
456 },
457
458 _wasFocused: function()
dgozman 2016/09/12 16:50:22 Let's inline this into focusWidgetForNode.
einbinder 2016/09/12 18:18:54 Done.
459 {
460 var widget = this;
461 while (widget._parentWidget) {
462 widget._parentWidget._defaultFocusedChild = widget;
463 widget = widget._parentWidget;
464 }
441 }, 465 },
442 466
443 /** 467 /**
444 * @return {boolean} 468 * @return {boolean}
445 */ 469 */
446 hasFocus: function() 470 hasFocus: function()
447 { 471 {
448 var activeElement = this.element.ownerDocument.activeElement; 472 var activeElement = this.element.ownerDocument.activeElement;
449 return activeElement && activeElement.isSelfOrDescendant(this.element); 473 return activeElement && activeElement.isSelfOrDescendant(this.element);
450 }, 474 },
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 613
590 WebInspector.Widget.__assert = function(condition, message) 614 WebInspector.Widget.__assert = function(condition, message)
591 { 615 {
592 if (!condition) { 616 if (!condition) {
593 console.trace(); 617 console.trace();
594 throw new Error(message); 618 throw new Error(message);
595 } 619 }
596 } 620 }
597 621
598 /** 622 /**
623 * @param {?Node} node
624 */
625 WebInspector.Widget.focusWidgetForNode = function(node)
626 {
627 while (node) {
628 if (node.__widget) {
629 node.__widget._wasFocused();
630 return;
631 }
632 node = node.parentNodeOrShadowHost();
633 }
634 }
635
636 /**
599 * @constructor 637 * @constructor
600 * @extends {WebInspector.Widget} 638 * @extends {WebInspector.Widget}
601 * @param {boolean=} isWebComponent 639 * @param {boolean=} isWebComponent
602 */ 640 */
603 WebInspector.VBox = function(isWebComponent) 641 WebInspector.VBox = function(isWebComponent)
604 { 642 {
605 WebInspector.Widget.call(this, isWebComponent); 643 WebInspector.Widget.call(this, isWebComponent);
606 this.contentElement.classList.add("vbox"); 644 this.contentElement.classList.add("vbox");
607 }; 645 };
608 646
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 { 764 {
727 WebInspector.Widget.__assert(!child.__widgetCounter && !child.__widget, "Att empt to remove element containing widget via regular DOM operation"); 765 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); 766 return WebInspector.Widget._originalRemoveChild.call(this, child);
729 } 767 }
730 768
731 Element.prototype.removeChildren = function() 769 Element.prototype.removeChildren = function()
732 { 770 {
733 WebInspector.Widget.__assert(!this.__widgetCounter, "Attempt to remove eleme nt containing widget via regular DOM operation"); 771 WebInspector.Widget.__assert(!this.__widgetCounter, "Attempt to remove eleme nt containing widget via regular DOM operation");
734 WebInspector.Widget._originalRemoveChildren.call(this); 772 WebInspector.Widget._originalRemoveChildren.call(this);
735 } 773 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698