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

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: 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/TabbedPane.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._boundWasFocused = this.wasFocused.bind(this);
52 this._lastFocusedChild = null;
51 } 53 }
52 54
53 WebInspector.Widget.prototype = { 55 WebInspector.Widget.prototype = {
54 markAsRoot: function() 56 markAsRoot: function()
55 { 57 {
56 WebInspector.Widget.__assert(!this.element.parentElement, "Attempt to ma rk as root attached node"); 58 WebInspector.Widget.__assert(!this.element.parentElement, "Attempt to ma rk as root attached node");
57 this._isRoot = true; 59 this._isRoot = true;
58 }, 60 },
59 61
60 /** 62 /**
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 * @param {!WebInspector.Widget} parentWidget 233 * @param {!WebInspector.Widget} parentWidget
232 */ 234 */
233 attach: function(parentWidget) 235 attach: function(parentWidget)
234 { 236 {
235 if (parentWidget === this._parentWidget) 237 if (parentWidget === this._parentWidget)
236 return; 238 return;
237 if (this._parentWidget) 239 if (this._parentWidget)
238 this.detach(); 240 this.detach();
239 this._parentWidget = parentWidget; 241 this._parentWidget = parentWidget;
240 this._parentWidget._children.push(this); 242 this._parentWidget._children.push(this);
243 if (!this._parentWidget._lastFocusedChild)
244 this._parentWidget._lastFocusedChild = this;
245 this._updateDefaultFocusedElementListener();
241 this._isRoot = false; 246 this._isRoot = false;
242 }, 247 },
243 248
244 /** 249 /**
245 * @param {!Element} parentElement 250 * @param {!Element} parentElement
246 * @param {?Element=} insertBefore 251 * @param {?Element=} insertBefore
247 */ 252 */
248 showWidget: function(parentElement, insertBefore) 253 showWidget: function(parentElement, insertBefore)
249 { 254 {
250 var currentParent = parentElement; 255 var currentParent = parentElement;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 return; 330 return;
326 331
327 if (this._visible) 332 if (this._visible)
328 this._hideWidget(true); 333 this._hideWidget(true);
329 334
330 // Update widget hierarchy. 335 // Update widget hierarchy.
331 if (this._parentWidget) { 336 if (this._parentWidget) {
332 var childIndex = this._parentWidget._children.indexOf(this); 337 var childIndex = this._parentWidget._children.indexOf(this);
333 WebInspector.Widget.__assert(childIndex >= 0, "Attempt to remove non -child widget"); 338 WebInspector.Widget.__assert(childIndex >= 0, "Attempt to remove non -child widget");
334 this._parentWidget._children.splice(childIndex, 1); 339 this._parentWidget._children.splice(childIndex, 1);
340 if (this._parentWidget._lastFocusedChild === this)
341 this._parentWidget._lastFocusedChild = this._parentWidget._child ren[0] || null;
335 this._parentWidget.childWasDetached(this); 342 this._parentWidget.childWasDetached(this);
336 var parent = this._parentWidget; 343 var parent = this._parentWidget;
337 this._parentWidget = null; 344 this._parentWidget = null;
345 this._updateDefaultFocusedElementListener();
338 } else { 346 } else {
339 WebInspector.Widget.__assert(this._isRoot, "Removing non-root widget from DOM"); 347 WebInspector.Widget.__assert(this._isRoot, "Removing non-root widget from DOM");
340 } 348 }
341 }, 349 },
342 350
343 detachChildWidgets: function() 351 detachChildWidgets: function()
344 { 352 {
345 var children = this._children.slice(); 353 var children = this._children.slice();
346 for (var i = 0; i < children.length; ++i) 354 for (var i = 0; i < children.length; ++i)
347 children[i].detach(); 355 children[i].detach();
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 426
419 if (this._children.length) 427 if (this._children.length)
420 lines.push(prefix + "}"); 428 lines.push(prefix + "}");
421 }, 429 },
422 430
423 /** 431 /**
424 * @param {!Element} element 432 * @param {!Element} element
425 */ 433 */
426 setDefaultFocusedElement: function(element) 434 setDefaultFocusedElement: function(element)
427 { 435 {
436 if (this._defaultFocusedElement)
437 this._defaultFocusedElement.removeEventListener("focus", this._bound WasFocused);
428 this._defaultFocusedElement = element; 438 this._defaultFocusedElement = element;
439 this._updateDefaultFocusedElementListener();
440 if (this._defaultFocusedElement.ownerDocument.activeElement.isSelfOrDesc endant(this._defaultFocusedElement))
441 this.wasFocused();
442 },
443
444 _updateDefaultFocusedElementListener: function()
445 {
446 if (!this._defaultFocusedElement)
447 return;
448 if (this._parentWidget)
449 this._defaultFocusedElement.addEventListener("focus", this._boundWas Focused, true);
450 else
451 this._defaultFocusedElement.removeEventListener("focus", this._bound WasFocused);
luoe 2016/09/08 20:48:56 Should this and L437 also get useCapture == true,
einbinder 2016/09/09 01:32:16 This was removed in the next patch.
429 }, 452 },
430 453
431 focus: function() 454 focus: function()
432 { 455 {
433 var element = this._defaultFocusedElement; 456 var element = this._defaultFocusedElement;
434 if (element && !element.isAncestor(this.element.ownerDocument.activeElem ent)) { 457 if (element && !element.isAncestor(this.element.ownerDocument.activeElem ent)) {
435 WebInspector.setCurrentFocusElement(element); 458 WebInspector.setCurrentFocusElement(element);
459 this.wasFocused();
436 return; 460 return;
437 } 461 }
438 462
439 if (this._children.length) 463 if (this._lastFocusedChild)
440 this._children[0].focus(); 464 this._lastFocusedChild.focus();
441 }, 465 },
442 466
443 /** 467 /**
468 * @final
469 */
470 wasFocused: function()
471 {
472 var widget = this;
473 while (widget._parentWidget) {
474 widget._parentWidget._lastFocusedChild = widget;
475 widget = widget._parentWidget;
476 }
477 },
478
479 /**
444 * @return {boolean} 480 * @return {boolean}
445 */ 481 */
446 hasFocus: function() 482 hasFocus: function()
447 { 483 {
448 var activeElement = this.element.ownerDocument.activeElement; 484 var activeElement = this.element.ownerDocument.activeElement;
449 return activeElement && activeElement.isSelfOrDescendant(this.element); 485 return activeElement && activeElement.isSelfOrDescendant(this.element);
450 }, 486 },
451 487
452 /** 488 /**
453 * @return {!Size} 489 * @return {!Size}
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 { 762 {
727 WebInspector.Widget.__assert(!child.__widgetCounter && !child.__widget, "Att empt to remove element containing widget via regular DOM operation"); 763 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); 764 return WebInspector.Widget._originalRemoveChild.call(this, child);
729 } 765 }
730 766
731 Element.prototype.removeChildren = function() 767 Element.prototype.removeChildren = function()
732 { 768 {
733 WebInspector.Widget.__assert(!this.__widgetCounter, "Attempt to remove eleme nt containing widget via regular DOM operation"); 769 WebInspector.Widget.__assert(!this.__widgetCounter, "Attempt to remove eleme nt containing widget via regular DOM operation");
734 WebInspector.Widget._originalRemoveChildren.call(this); 770 WebInspector.Widget._originalRemoveChildren.call(this);
735 } 771 }
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/front_end/ui/TabbedPane.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698