Add an exponential backoff to rechecking the app list doodle.
[chromium-blink-merge.git] / third_party / polymer / components / core-overlay / core-overlay-layer.html
blob2388d4ab6cd78318cf309a83067f7ef250a13baa
1 <!--
2 Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
3 This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
5 The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
6 Code distributed by Google as part of the polymer project is also
7 subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
8 -->
9 <link rel="import" href="../polymer/polymer.html">
11 <polymer-element name="core-overlay-layer">
12 <template>
13 <style>
14 :host {
15 position: fixed;
16 top: 0;
17 left: 0;
18 z-index: 1000;
19 display: none;
22 :host(.core-opened) {
23 display: block;
25 </style>
26 <content></content>
27 </template>
28 <script>
29 (function() {
31 Polymer('core-overlay-layer', {
32 publish: {
33 opened: false
35 openedChanged: function() {
36 this.classList.toggle('core-opened', this.opened);
38 /**
39 * Adds an element to the overlay layer
41 addElement: function(element) {
42 if (!this.parentNode) {
43 document.querySelector('body').appendChild(this);
45 if (element.parentNode !== this) {
46 element.__contents = [];
47 var ip$ = element.querySelectorAll('content');
48 for (var i=0, l=ip$.length, n; (i<l) && (n = ip$[i]); i++) {
49 this.moveInsertedElements(n);
50 this.cacheDomLocation(n);
51 n.parentNode.removeChild(n);
52 element.__contents.push(n);
54 this.cacheDomLocation(element);
55 this.updateEventController(element);
56 var h = this.makeHost();
57 h.shadowRoot.appendChild(element);
58 element.__host = h;
61 makeHost: function() {
62 var h = document.createElement('overlay-host');
63 h.createShadowRoot();
64 this.appendChild(h);
65 return h;
67 moveInsertedElements: function(insertionPoint) {
68 var n$ = insertionPoint.getDistributedNodes();
69 var parent = insertionPoint.parentNode;
70 insertionPoint.__contents = [];
71 for (var i=0, l=n$.length, n; (i<l) && (n=n$[i]); i++) {
72 this.cacheDomLocation(n);
73 this.updateEventController(n);
74 insertionPoint.__contents.push(n);
75 parent.appendChild(n);
78 updateEventController: function(element) {
79 element.eventController = this.element.findController(element);
81 /**
82 * Removes an element from the overlay layer
84 removeElement: function(element) {
85 element.eventController = null;
86 this.replaceElement(element);
87 var h = element.__host;
88 if (h) {
89 h.parentNode.removeChild(h);
92 replaceElement: function(element) {
93 if (element.__contents) {
94 for (var i=0, c$=element.__contents, c; (c=c$[i]); i++) {
95 this.replaceElement(c);
97 element.__contents = null;
99 if (element.__parentNode) {
100 var n = element.__nextElementSibling && element.__nextElementSibling
101 === element.__parentNode ? element.__nextElementSibling : null;
102 element.__parentNode.insertBefore(element, n);
105 cacheDomLocation: function(element) {
106 element.__nextElementSibling = element.nextElementSibling;
107 element.__parentNode = element.parentNode;
111 })();
112 </script>
113 </polymer-element>