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

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/platform/DOMExtension.js

Issue 2377193004: [DevTools] Rework some focus code. (Closed)
Patch Set: FocusRestorer 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) 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2007 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2012 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 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 895
896 this.textContent = text; 896 this.textContent = text;
897 return false; 897 return false;
898 } 898 }
899 899
900 /** 900 /**
901 * @return {?Node} 901 * @return {?Node}
902 */ 902 */
903 Event.prototype.deepElementFromPoint = function() 903 Event.prototype.deepElementFromPoint = function()
904 { 904 {
905 // 1. climb to the component root. 905 var root = this.target && this.target.getComponentRoot();
906 var node = this.target; 906 return root ? root.deepElementFromPoint(this.pageX, this.pageY) : null;
907 while (node && node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE && node.nodeTyp e !== Node.DOCUMENT_NODE)
908 node = node.parentNode;
909
910 if (!node)
911 return null;
912
913 // 2. Find deepest node by coordinates.
914 node = node.elementFromPoint(this.pageX, this.pageY);
915 while (node && node.shadowRoot)
916 node = node.shadowRoot.elementFromPoint(this.pageX, this.pageY);
917 return node;
918 } 907 }
919 908
920 /** 909 /**
921 * @return {?Element} 910 * @return {?Element}
922 */ 911 */
923 Event.prototype.deepActiveElement = function() 912 Event.prototype.deepActiveElement = function()
924 { 913 {
925 var activeElement = this.target && this.target.ownerDocument ? this.target.o wnerDocument.activeElement : null; 914 var document = this.target && this.target.ownerDocument;
926 while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot .activeElement) 915 return document ? document.deepActiveElement() : null;
927 activeElement = activeElement.shadowRoot.activeElement;
928 return activeElement;
929 } 916 }
930 917
931 /** 918 /**
932 * @param {number} x 919 * @param {number} x
933 * @param {number} y 920 * @param {number} y
934 * @return {?Node} 921 * @return {?Node}
935 */ 922 */
936 Document.prototype.deepElementFromPoint = function(x, y) 923 Document.prototype.deepElementFromPoint = function(x, y)
937 { 924 {
938 var node = this.elementFromPoint(x, y); 925 var node = this.elementFromPoint(x, y);
939 while (node && node.shadowRoot) 926 while (node && node.shadowRoot)
940 node = node.shadowRoot.elementFromPoint(x, y); 927 node = node.shadowRoot.elementFromPoint(x, y);
941 return node; 928 return node;
942 } 929 }
943 930
931 DocumentFragment.prototype.deepElementFromPoint = Document.prototype.deepElement FromPoint;
932
933 /**
934 * @return {?Element}
935 */
936 Document.prototype.deepActiveElement = function()
937 {
938 var activeElement = this.activeElement;
939 while (activeElement && activeElement.shadowRoot && activeElement.shadowRoot .activeElement)
940 activeElement = activeElement.shadowRoot.activeElement;
941 return activeElement;
942 }
943
944 DocumentFragment.prototype.deepActiveElement = Document.prototype.deepActiveElem ent;
945
946 /**
947 * @return {boolean}
948 */
949 Element.prototype.hasFocus = function()
950 {
951 var root = this.getComponentRoot();
952 return !!root && this.isSelfOrAncestor(root.activeElement);
953 }
954
955 /**
956 * @return {?Document|?DocumentFragment}
957 */
958 Node.prototype.getComponentRoot = function()
959 {
960 var node = this;
961 while (node && node.nodeType !== Node.DOCUMENT_FRAGMENT_NODE && node.nodeTyp e !== Node.DOCUMENT_NODE)
962 node = node.parentNode;
963 return /** @type {?Document|?DocumentFragment} */ (node);
964 }
965
944 /** 966 /**
945 * @param {!Event} event 967 * @param {!Event} event
946 * @return {boolean} 968 * @return {boolean}
947 */ 969 */
948 function isEnterKey(event) 970 function isEnterKey(event)
949 { 971 {
950 // Check if in IME. 972 // Check if in IME.
951 return event.keyCode !== 229 && event.key === "Enter"; 973 return event.keyCode !== 229 && event.key === "Enter";
952 } 974 }
953 975
(...skipping 24 matching lines...) Expand all
978 { 1000 {
979 window.removeEventListener("DOMContentLoaded", windowLoaded, false); 1001 window.removeEventListener("DOMContentLoaded", windowLoaded, false);
980 callback(); 1002 callback();
981 } 1003 }
982 1004
983 if (document.readyState === "complete" || document.readyState === "interacti ve") 1005 if (document.readyState === "complete" || document.readyState === "interacti ve")
984 callback(); 1006 callback();
985 else 1007 else
986 window.addEventListener("DOMContentLoaded", windowLoaded, false); 1008 window.addEventListener("DOMContentLoaded", windowLoaded, false);
987 } 1009 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698