Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / third_party / polymer / v1_0 / components / iron-overlay-behavior / iron-overlay-manager.html
blobc66f9aa77c031476d782fe54af269b0903ddac28
1 <!--
2 @license
3 Copyright (c) 2015 The Polymer Project Authors. All rights reserved.
4 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7 Code distributed by Google as part of the polymer project is also
8 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9 -->
11 <link rel="import" href="../polymer/polymer.html">
13 <script>
15 Polymer.IronOverlayManager = (function() {
17 var overlays = [];
18 var DEFAULT_Z = 10;
19 var backdrops = [];
21 // track overlays for z-index and focus managemant
22 function addOverlay(overlay) {
23 var z0 = currentOverlayZ();
24 overlays.push(overlay);
25 var z1 = currentOverlayZ();
26 if (z1 <= z0) {
27 applyOverlayZ(overlay, z0);
31 function removeOverlay(overlay) {
32 var i = overlays.indexOf(overlay);
33 if (i >= 0) {
34 overlays.splice(i, 1);
35 setZ(overlay, '');
39 function applyOverlayZ(overlay, aboveZ) {
40 setZ(overlay, aboveZ + 2);
43 function setZ(element, z) {
44 element.style.zIndex = z;
47 function currentOverlay() {
48 return overlays[overlays.length-1];
51 function currentOverlayZ() {
52 var z;
53 var current = currentOverlay();
54 if (current) {
55 var z1 = window.getComputedStyle(current).zIndex;
56 if (!isNaN(z1)) {
57 z = Number(z1);
60 return z || DEFAULT_Z;
63 function focusOverlay() {
64 var current = currentOverlay();
65 // We have to be careful to focus the next overlay _after_ any current
66 // transitions are complete (due to the state being toggled prior to the
67 // transition). Otherwise, we risk infinite recursion when a transitioning
68 // (closed) overlay becomes the current overlay.
70 // NOTE: We make the assumption that any overlay that completes a transition
71 // will call into focusOverlay to kick the process back off. Currently:
72 // transitionend -> _applyFocus -> focusOverlay.
73 if (current && !current.transitioning) {
74 current._applyFocus();
78 function trackBackdrop(element) {
79 // backdrops contains the overlays with a backdrop that are currently
80 // visible
81 if (element.opened) {
82 backdrops.push(element);
83 } else {
84 var index = backdrops.indexOf(element);
85 if (index >= 0) {
86 backdrops.splice(index, 1);
91 function getBackdrops() {
92 return backdrops;
95 return {
96 addOverlay: addOverlay,
97 removeOverlay: removeOverlay,
98 currentOverlay: currentOverlay,
99 currentOverlayZ: currentOverlayZ,
100 focusOverlay: focusOverlay,
101 trackBackdrop: trackBackdrop,
102 getBackdrops: getBackdrops
105 })();
107 </script>