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

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

Issue 2377193004: [DevTools] Rework some focus code. (Closed)
Patch Set: Created 4 years, 2 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 406 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 lines.push(prefix + "[" + this.element.className + "]" + (this._children .length ? " {" : "")); 417 lines.push(prefix + "[" + this.element.className + "]" + (this._children .length ? " {" : ""));
418 418
419 for (var i = 0; i < this._children.length; ++i) 419 for (var i = 0; i < this._children.length; ++i)
420 this._children[i]._collectWidgetHierarchy(prefix + " ", lines); 420 this._children[i]._collectWidgetHierarchy(prefix + " ", lines);
421 421
422 if (this._children.length) 422 if (this._children.length)
423 lines.push(prefix + "}"); 423 lines.push(prefix + "}");
424 }, 424 },
425 425
426 /** 426 /**
427 * @param {!Element} element 427 * @param {?Element} element
428 */ 428 */
429 setDefaultFocusedElement: function(element) 429 setDefaultFocusedElement: function(element)
430 { 430 {
431 this._defaultFocusedElement = element; 431 this._defaultFocusedElement = element;
432 }, 432 },
433 433
434 /** 434 /**
435 * @param {!WebInspector.Widget} child 435 * @param {!WebInspector.Widget} child
436 */ 436 */
437 setDefaultFocusedChild: function(child) 437 setDefaultFocusedChild: function(child)
438 { 438 {
439 WebInspector.Widget.__assert(child._parentWidget === this, "Attempt to s et non-child widget as default focused."); 439 WebInspector.Widget.__assert(child._parentWidget === this, "Attempt to s et non-child widget as default focused.");
440 this._defaultFocusedChild = child; 440 this._defaultFocusedChild = child;
441 }, 441 },
442 442
443 focus: function() 443 focus: function()
444 { 444 {
445 if (!this.isShowing())
446 return;
447
445 var element = this._defaultFocusedElement; 448 var element = this._defaultFocusedElement;
446 if (element && !element.isAncestor(this.element.ownerDocument.activeElem ent)) { 449 if (element) {
447 WebInspector.setCurrentFocusElement(element); 450 if (!element.hasFocus())
451 element.focus();
448 return; 452 return;
449 } 453 }
450 454
451 if (this._defaultFocusedChild && this._defaultFocusedChild._visible) { 455 if (this._defaultFocusedChild && this._defaultFocusedChild._visible) {
452 this._defaultFocusedChild.focus(); 456 this._defaultFocusedChild.focus();
453 } else { 457 } else {
454 for (var child of this._children) { 458 for (var child of this._children) {
455 if (child._visible) { 459 if (child._visible) {
456 child.focus(); 460 child.focus();
457 break; 461 break;
458 } 462 }
459 } 463 }
460 } 464 }
461 465
462 }, 466 },
463 467
464 /** 468 /**
465 * @return {boolean} 469 * @return {boolean}
466 */ 470 */
467 hasFocus: function() 471 hasFocus: function()
468 { 472 {
469 var activeElement = this.element.ownerDocument.activeElement; 473 return this.element.hasFocus();
470 return activeElement && activeElement.isSelfOrDescendant(this.element);
471 }, 474 },
472 475
473 /** 476 /**
474 * @return {!Size} 477 * @return {!Size}
475 */ 478 */
476 measurePreferredSize: function() 479 measurePreferredSize: function()
477 { 480 {
478 var document = this.element.ownerDocument; 481 var document = this.element.ownerDocument;
479 var oldParent = this.element.parentElement; 482 var oldParent = this.element.parentElement;
480 var oldNextSibling = this.element.nextSibling; 483 var oldNextSibling = this.element.nextSibling;
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 { 770 {
768 WebInspector.Widget.__assert(!child.__widgetCounter && !child.__widget, "Att empt to remove element containing widget via regular DOM operation"); 771 WebInspector.Widget.__assert(!child.__widgetCounter && !child.__widget, "Att empt to remove element containing widget via regular DOM operation");
769 return WebInspector.Widget._originalRemoveChild.call(this, child); 772 return WebInspector.Widget._originalRemoveChild.call(this, child);
770 } 773 }
771 774
772 Element.prototype.removeChildren = function() 775 Element.prototype.removeChildren = function()
773 { 776 {
774 WebInspector.Widget.__assert(!this.__widgetCounter, "Attempt to remove eleme nt containing widget via regular DOM operation"); 777 WebInspector.Widget.__assert(!this.__widgetCounter, "Attempt to remove eleme nt containing widget via regular DOM operation");
775 WebInspector.Widget._originalRemoveChildren.call(this); 778 WebInspector.Widget._originalRemoveChildren.call(this);
776 } 779 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698