Fix OOP <webview> resize and autosize.
[chromium-blink-merge.git] / third_party / polymer / v1_0 / components-chromium / iron-overlay-behavior / iron-overlay-manager-extracted.js
blob128a38229d812eede286b5ef0350362a4efc4717
1 Polymer.IronOverlayManager = (function() {
3 var overlays = [];
4 var DEFAULT_Z = 10;
5 var backdrops = [];
7 // track overlays for z-index and focus managemant
8 function addOverlay(overlay) {
9 var z0 = currentOverlayZ();
10 overlays.push(overlay);
11 var z1 = currentOverlayZ();
12 if (z1 <= z0) {
13 applyOverlayZ(overlay, z0);
17 function removeOverlay(overlay) {
18 var i = overlays.indexOf(overlay);
19 if (i >= 0) {
20 overlays.splice(i, 1);
21 setZ(overlay, '');
25 function applyOverlayZ(overlay, aboveZ) {
26 setZ(overlay, aboveZ + 2);
29 function setZ(element, z) {
30 element.style.zIndex = z;
33 function currentOverlay() {
34 var i = overlays.length - 1;
35 while (overlays[i] && !overlays[i].opened) {
36 --i;
38 return overlays[i];
41 function currentOverlayZ() {
42 var z;
43 var current = currentOverlay();
44 if (current) {
45 var z1 = window.getComputedStyle(current).zIndex;
46 if (!isNaN(z1)) {
47 z = Number(z1);
50 return z || DEFAULT_Z;
53 function focusOverlay() {
54 var current = currentOverlay();
55 // We have to be careful to focus the next overlay _after_ any current
56 // transitions are complete (due to the state being toggled prior to the
57 // transition). Otherwise, we risk infinite recursion when a transitioning
58 // (closed) overlay becomes the current overlay.
60 // NOTE: We make the assumption that any overlay that completes a transition
61 // will call into focusOverlay to kick the process back off. Currently:
62 // transitionend -> _applyFocus -> focusOverlay.
63 if (current && !current.transitioning) {
64 current._applyFocus();
68 function trackBackdrop(element) {
69 // backdrops contains the overlays with a backdrop that are currently
70 // visible
71 if (element.opened) {
72 backdrops.push(element);
73 } else {
74 var index = backdrops.indexOf(element);
75 if (index >= 0) {
76 backdrops.splice(index, 1);
81 function getBackdrops() {
82 return backdrops;
85 return {
86 addOverlay: addOverlay,
87 removeOverlay: removeOverlay,
88 currentOverlay: currentOverlay,
89 currentOverlayZ: currentOverlayZ,
90 focusOverlay: focusOverlay,
91 trackBackdrop: trackBackdrop,
92 getBackdrops: getBackdrops
95 })();