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

Side by Side Diff: polymer_0.5.0/bower_components/webcomponentsjs/ShadowDOM.js

Issue 786953007: npm_modules: Fork bower_components into Polymer 0.4.0 and 0.5.0 versions (Closed) Base URL: https://chromium.googlesource.com/infra/third_party/npm_modules.git@master
Patch Set: Created 5 years, 11 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
(Empty)
1 /**
2 * @license
3 * Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
4 * This code may only be used under the BSD style license found at http://polyme r.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/CON TRIBUTORS.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/PA TENTS.txt
9 */
10 // @version 0.5.1-1
11 if (typeof WeakMap === "undefined") {
12 (function() {
13 var defineProperty = Object.defineProperty;
14 var counter = Date.now() % 1e9;
15 var WeakMap = function() {
16 this.name = "__st" + (Math.random() * 1e9 >>> 0) + (counter++ + "__");
17 };
18 WeakMap.prototype = {
19 set: function(key, value) {
20 var entry = key[this.name];
21 if (entry && entry[0] === key) entry[1] = value; else defineProperty(key , this.name, {
22 value: [ key, value ],
23 writable: true
24 });
25 return this;
26 },
27 get: function(key) {
28 var entry;
29 return (entry = key[this.name]) && entry[0] === key ? entry[1] : undefin ed;
30 },
31 "delete": function(key) {
32 var entry = key[this.name];
33 if (!entry || entry[0] !== key) return false;
34 entry[0] = entry[1] = undefined;
35 return true;
36 },
37 has: function(key) {
38 var entry = key[this.name];
39 if (!entry) return false;
40 return entry[0] === key;
41 }
42 };
43 window.WeakMap = WeakMap;
44 })();
45 }
46
47 window.ShadowDOMPolyfill = {};
48
49 (function(scope) {
50 "use strict";
51 var constructorTable = new WeakMap();
52 var nativePrototypeTable = new WeakMap();
53 var wrappers = Object.create(null);
54 function detectEval() {
55 if (typeof chrome !== "undefined" && chrome.app && chrome.app.runtime) {
56 return false;
57 }
58 if (navigator.getDeviceStorage) {
59 return false;
60 }
61 try {
62 var f = new Function("return true;");
63 return f();
64 } catch (ex) {
65 return false;
66 }
67 }
68 var hasEval = detectEval();
69 function assert(b) {
70 if (!b) throw new Error("Assertion failed");
71 }
72 var defineProperty = Object.defineProperty;
73 var getOwnPropertyNames = Object.getOwnPropertyNames;
74 var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
75 function mixin(to, from) {
76 var names = getOwnPropertyNames(from);
77 for (var i = 0; i < names.length; i++) {
78 var name = names[i];
79 defineProperty(to, name, getOwnPropertyDescriptor(from, name));
80 }
81 return to;
82 }
83 function mixinStatics(to, from) {
84 var names = getOwnPropertyNames(from);
85 for (var i = 0; i < names.length; i++) {
86 var name = names[i];
87 switch (name) {
88 case "arguments":
89 case "caller":
90 case "length":
91 case "name":
92 case "prototype":
93 case "toString":
94 continue;
95 }
96 defineProperty(to, name, getOwnPropertyDescriptor(from, name));
97 }
98 return to;
99 }
100 function oneOf(object, propertyNames) {
101 for (var i = 0; i < propertyNames.length; i++) {
102 if (propertyNames[i] in object) return propertyNames[i];
103 }
104 }
105 var nonEnumerableDataDescriptor = {
106 value: undefined,
107 configurable: true,
108 enumerable: false,
109 writable: true
110 };
111 function defineNonEnumerableDataProperty(object, name, value) {
112 nonEnumerableDataDescriptor.value = value;
113 defineProperty(object, name, nonEnumerableDataDescriptor);
114 }
115 getOwnPropertyNames(window);
116 function getWrapperConstructor(node) {
117 var nativePrototype = node.__proto__ || Object.getPrototypeOf(node);
118 var wrapperConstructor = constructorTable.get(nativePrototype);
119 if (wrapperConstructor) return wrapperConstructor;
120 var parentWrapperConstructor = getWrapperConstructor(nativePrototype);
121 var GeneratedWrapper = createWrapperConstructor(parentWrapperConstructor);
122 registerInternal(nativePrototype, GeneratedWrapper, node);
123 return GeneratedWrapper;
124 }
125 function addForwardingProperties(nativePrototype, wrapperPrototype) {
126 installProperty(nativePrototype, wrapperPrototype, true);
127 }
128 function registerInstanceProperties(wrapperPrototype, instanceObject) {
129 installProperty(instanceObject, wrapperPrototype, false);
130 }
131 var isFirefox = /Firefox/.test(navigator.userAgent);
132 var dummyDescriptor = {
133 get: function() {},
134 set: function(v) {},
135 configurable: true,
136 enumerable: true
137 };
138 function isEventHandlerName(name) {
139 return /^on[a-z]+$/.test(name);
140 }
141 function isIdentifierName(name) {
142 return /^\w[a-zA-Z_0-9]*$/.test(name);
143 }
144 function getGetter(name) {
145 return hasEval && isIdentifierName(name) ? new Function("return this.__impl4 cf1e782hg__." + name) : function() {
146 return this.__impl4cf1e782hg__[name];
147 };
148 }
149 function getSetter(name) {
150 return hasEval && isIdentifierName(name) ? new Function("v", "this.__impl4cf 1e782hg__." + name + " = v") : function(v) {
151 this.__impl4cf1e782hg__[name] = v;
152 };
153 }
154 function getMethod(name) {
155 return hasEval && isIdentifierName(name) ? new Function("return this.__impl4 cf1e782hg__." + name + ".apply(this.__impl4cf1e782hg__, arguments)") : function( ) {
156 return this.__impl4cf1e782hg__[name].apply(this.__impl4cf1e782hg__, argume nts);
157 };
158 }
159 function getDescriptor(source, name) {
160 try {
161 return Object.getOwnPropertyDescriptor(source, name);
162 } catch (ex) {
163 return dummyDescriptor;
164 }
165 }
166 var isBrokenSafari = function() {
167 var descr = Object.getOwnPropertyDescriptor(Node.prototype, "nodeType");
168 return descr && !descr.get && !descr.set;
169 }();
170 function installProperty(source, target, allowMethod, opt_blacklist) {
171 var names = getOwnPropertyNames(source);
172 for (var i = 0; i < names.length; i++) {
173 var name = names[i];
174 if (name === "polymerBlackList_") continue;
175 if (name in target) continue;
176 if (source.polymerBlackList_ && source.polymerBlackList_[name]) continue;
177 if (isFirefox) {
178 source.__lookupGetter__(name);
179 }
180 var descriptor = getDescriptor(source, name);
181 var getter, setter;
182 if (allowMethod && typeof descriptor.value === "function") {
183 target[name] = getMethod(name);
184 continue;
185 }
186 var isEvent = isEventHandlerName(name);
187 if (isEvent) getter = scope.getEventHandlerGetter(name); else getter = get Getter(name);
188 if (descriptor.writable || descriptor.set || isBrokenSafari) {
189 if (isEvent) setter = scope.getEventHandlerSetter(name); else setter = g etSetter(name);
190 }
191 defineProperty(target, name, {
192 get: getter,
193 set: setter,
194 configurable: descriptor.configurable,
195 enumerable: descriptor.enumerable
196 });
197 }
198 }
199 function register(nativeConstructor, wrapperConstructor, opt_instance) {
200 var nativePrototype = nativeConstructor.prototype;
201 registerInternal(nativePrototype, wrapperConstructor, opt_instance);
202 mixinStatics(wrapperConstructor, nativeConstructor);
203 }
204 function registerInternal(nativePrototype, wrapperConstructor, opt_instance) {
205 var wrapperPrototype = wrapperConstructor.prototype;
206 assert(constructorTable.get(nativePrototype) === undefined);
207 constructorTable.set(nativePrototype, wrapperConstructor);
208 nativePrototypeTable.set(wrapperPrototype, nativePrototype);
209 addForwardingProperties(nativePrototype, wrapperPrototype);
210 if (opt_instance) registerInstanceProperties(wrapperPrototype, opt_instance) ;
211 defineNonEnumerableDataProperty(wrapperPrototype, "constructor", wrapperCons tructor);
212 wrapperConstructor.prototype = wrapperPrototype;
213 }
214 function isWrapperFor(wrapperConstructor, nativeConstructor) {
215 return constructorTable.get(nativeConstructor.prototype) === wrapperConstruc tor;
216 }
217 function registerObject(object) {
218 var nativePrototype = Object.getPrototypeOf(object);
219 var superWrapperConstructor = getWrapperConstructor(nativePrototype);
220 var GeneratedWrapper = createWrapperConstructor(superWrapperConstructor);
221 registerInternal(nativePrototype, GeneratedWrapper, object);
222 return GeneratedWrapper;
223 }
224 function createWrapperConstructor(superWrapperConstructor) {
225 function GeneratedWrapper(node) {
226 superWrapperConstructor.call(this, node);
227 }
228 var p = Object.create(superWrapperConstructor.prototype);
229 p.constructor = GeneratedWrapper;
230 GeneratedWrapper.prototype = p;
231 return GeneratedWrapper;
232 }
233 function isWrapper(object) {
234 return object && object.__impl4cf1e782hg__;
235 }
236 function isNative(object) {
237 return !isWrapper(object);
238 }
239 function wrap(impl) {
240 if (impl === null) return null;
241 assert(isNative(impl));
242 return impl.__wrapper8e3dd93a60__ || (impl.__wrapper8e3dd93a60__ = new (getW rapperConstructor(impl))(impl));
243 }
244 function unwrap(wrapper) {
245 if (wrapper === null) return null;
246 assert(isWrapper(wrapper));
247 return wrapper.__impl4cf1e782hg__;
248 }
249 function unsafeUnwrap(wrapper) {
250 return wrapper.__impl4cf1e782hg__;
251 }
252 function setWrapper(impl, wrapper) {
253 wrapper.__impl4cf1e782hg__ = impl;
254 impl.__wrapper8e3dd93a60__ = wrapper;
255 }
256 function unwrapIfNeeded(object) {
257 return object && isWrapper(object) ? unwrap(object) : object;
258 }
259 function wrapIfNeeded(object) {
260 return object && !isWrapper(object) ? wrap(object) : object;
261 }
262 function rewrap(node, wrapper) {
263 if (wrapper === null) return;
264 assert(isNative(node));
265 assert(wrapper === undefined || isWrapper(wrapper));
266 node.__wrapper8e3dd93a60__ = wrapper;
267 }
268 var getterDescriptor = {
269 get: undefined,
270 configurable: true,
271 enumerable: true
272 };
273 function defineGetter(constructor, name, getter) {
274 getterDescriptor.get = getter;
275 defineProperty(constructor.prototype, name, getterDescriptor);
276 }
277 function defineWrapGetter(constructor, name) {
278 defineGetter(constructor, name, function() {
279 return wrap(this.__impl4cf1e782hg__[name]);
280 });
281 }
282 function forwardMethodsToWrapper(constructors, names) {
283 constructors.forEach(function(constructor) {
284 names.forEach(function(name) {
285 constructor.prototype[name] = function() {
286 var w = wrapIfNeeded(this);
287 return w[name].apply(w, arguments);
288 };
289 });
290 });
291 }
292 scope.assert = assert;
293 scope.constructorTable = constructorTable;
294 scope.defineGetter = defineGetter;
295 scope.defineWrapGetter = defineWrapGetter;
296 scope.forwardMethodsToWrapper = forwardMethodsToWrapper;
297 scope.isWrapper = isWrapper;
298 scope.isWrapperFor = isWrapperFor;
299 scope.mixin = mixin;
300 scope.nativePrototypeTable = nativePrototypeTable;
301 scope.oneOf = oneOf;
302 scope.registerObject = registerObject;
303 scope.registerWrapper = register;
304 scope.rewrap = rewrap;
305 scope.setWrapper = setWrapper;
306 scope.unsafeUnwrap = unsafeUnwrap;
307 scope.unwrap = unwrap;
308 scope.unwrapIfNeeded = unwrapIfNeeded;
309 scope.wrap = wrap;
310 scope.wrapIfNeeded = wrapIfNeeded;
311 scope.wrappers = wrappers;
312 })(window.ShadowDOMPolyfill);
313
314 (function(scope) {
315 "use strict";
316 function newSplice(index, removed, addedCount) {
317 return {
318 index: index,
319 removed: removed,
320 addedCount: addedCount
321 };
322 }
323 var EDIT_LEAVE = 0;
324 var EDIT_UPDATE = 1;
325 var EDIT_ADD = 2;
326 var EDIT_DELETE = 3;
327 function ArraySplice() {}
328 ArraySplice.prototype = {
329 calcEditDistances: function(current, currentStart, currentEnd, old, oldStart , oldEnd) {
330 var rowCount = oldEnd - oldStart + 1;
331 var columnCount = currentEnd - currentStart + 1;
332 var distances = new Array(rowCount);
333 for (var i = 0; i < rowCount; i++) {
334 distances[i] = new Array(columnCount);
335 distances[i][0] = i;
336 }
337 for (var j = 0; j < columnCount; j++) distances[0][j] = j;
338 for (var i = 1; i < rowCount; i++) {
339 for (var j = 1; j < columnCount; j++) {
340 if (this.equals(current[currentStart + j - 1], old[oldStart + i - 1])) distances[i][j] = distances[i - 1][j - 1]; else {
341 var north = distances[i - 1][j] + 1;
342 var west = distances[i][j - 1] + 1;
343 distances[i][j] = north < west ? north : west;
344 }
345 }
346 }
347 return distances;
348 },
349 spliceOperationsFromEditDistances: function(distances) {
350 var i = distances.length - 1;
351 var j = distances[0].length - 1;
352 var current = distances[i][j];
353 var edits = [];
354 while (i > 0 || j > 0) {
355 if (i == 0) {
356 edits.push(EDIT_ADD);
357 j--;
358 continue;
359 }
360 if (j == 0) {
361 edits.push(EDIT_DELETE);
362 i--;
363 continue;
364 }
365 var northWest = distances[i - 1][j - 1];
366 var west = distances[i - 1][j];
367 var north = distances[i][j - 1];
368 var min;
369 if (west < north) min = west < northWest ? west : northWest; else min = north < northWest ? north : northWest;
370 if (min == northWest) {
371 if (northWest == current) {
372 edits.push(EDIT_LEAVE);
373 } else {
374 edits.push(EDIT_UPDATE);
375 current = northWest;
376 }
377 i--;
378 j--;
379 } else if (min == west) {
380 edits.push(EDIT_DELETE);
381 i--;
382 current = west;
383 } else {
384 edits.push(EDIT_ADD);
385 j--;
386 current = north;
387 }
388 }
389 edits.reverse();
390 return edits;
391 },
392 calcSplices: function(current, currentStart, currentEnd, old, oldStart, oldE nd) {
393 var prefixCount = 0;
394 var suffixCount = 0;
395 var minLength = Math.min(currentEnd - currentStart, oldEnd - oldStart);
396 if (currentStart == 0 && oldStart == 0) prefixCount = this.sharedPrefix(cu rrent, old, minLength);
397 if (currentEnd == current.length && oldEnd == old.length) suffixCount = th is.sharedSuffix(current, old, minLength - prefixCount);
398 currentStart += prefixCount;
399 oldStart += prefixCount;
400 currentEnd -= suffixCount;
401 oldEnd -= suffixCount;
402 if (currentEnd - currentStart == 0 && oldEnd - oldStart == 0) return [];
403 if (currentStart == currentEnd) {
404 var splice = newSplice(currentStart, [], 0);
405 while (oldStart < oldEnd) splice.removed.push(old[oldStart++]);
406 return [ splice ];
407 } else if (oldStart == oldEnd) return [ newSplice(currentStart, [], curren tEnd - currentStart) ];
408 var ops = this.spliceOperationsFromEditDistances(this.calcEditDistances(cu rrent, currentStart, currentEnd, old, oldStart, oldEnd));
409 var splice = undefined;
410 var splices = [];
411 var index = currentStart;
412 var oldIndex = oldStart;
413 for (var i = 0; i < ops.length; i++) {
414 switch (ops[i]) {
415 case EDIT_LEAVE:
416 if (splice) {
417 splices.push(splice);
418 splice = undefined;
419 }
420 index++;
421 oldIndex++;
422 break;
423
424 case EDIT_UPDATE:
425 if (!splice) splice = newSplice(index, [], 0);
426 splice.addedCount++;
427 index++;
428 splice.removed.push(old[oldIndex]);
429 oldIndex++;
430 break;
431
432 case EDIT_ADD:
433 if (!splice) splice = newSplice(index, [], 0);
434 splice.addedCount++;
435 index++;
436 break;
437
438 case EDIT_DELETE:
439 if (!splice) splice = newSplice(index, [], 0);
440 splice.removed.push(old[oldIndex]);
441 oldIndex++;
442 break;
443 }
444 }
445 if (splice) {
446 splices.push(splice);
447 }
448 return splices;
449 },
450 sharedPrefix: function(current, old, searchLength) {
451 for (var i = 0; i < searchLength; i++) if (!this.equals(current[i], old[i] )) return i;
452 return searchLength;
453 },
454 sharedSuffix: function(current, old, searchLength) {
455 var index1 = current.length;
456 var index2 = old.length;
457 var count = 0;
458 while (count < searchLength && this.equals(current[--index1], old[--index2 ])) count++;
459 return count;
460 },
461 calculateSplices: function(current, previous) {
462 return this.calcSplices(current, 0, current.length, previous, 0, previous. length);
463 },
464 equals: function(currentValue, previousValue) {
465 return currentValue === previousValue;
466 }
467 };
468 scope.ArraySplice = ArraySplice;
469 })(window.ShadowDOMPolyfill);
470
471 (function(context) {
472 "use strict";
473 var OriginalMutationObserver = window.MutationObserver;
474 var callbacks = [];
475 var pending = false;
476 var timerFunc;
477 function handle() {
478 pending = false;
479 var copies = callbacks.slice(0);
480 callbacks = [];
481 for (var i = 0; i < copies.length; i++) {
482 (0, copies[i])();
483 }
484 }
485 if (OriginalMutationObserver) {
486 var counter = 1;
487 var observer = new OriginalMutationObserver(handle);
488 var textNode = document.createTextNode(counter);
489 observer.observe(textNode, {
490 characterData: true
491 });
492 timerFunc = function() {
493 counter = (counter + 1) % 2;
494 textNode.data = counter;
495 };
496 } else {
497 timerFunc = window.setTimeout;
498 }
499 function setEndOfMicrotask(func) {
500 callbacks.push(func);
501 if (pending) return;
502 pending = true;
503 timerFunc(handle, 0);
504 }
505 context.setEndOfMicrotask = setEndOfMicrotask;
506 })(window.ShadowDOMPolyfill);
507
508 (function(scope) {
509 "use strict";
510 var setEndOfMicrotask = scope.setEndOfMicrotask;
511 var wrapIfNeeded = scope.wrapIfNeeded;
512 var wrappers = scope.wrappers;
513 var registrationsTable = new WeakMap();
514 var globalMutationObservers = [];
515 var isScheduled = false;
516 function scheduleCallback(observer) {
517 if (observer.scheduled_) return;
518 observer.scheduled_ = true;
519 globalMutationObservers.push(observer);
520 if (isScheduled) return;
521 setEndOfMicrotask(notifyObservers);
522 isScheduled = true;
523 }
524 function notifyObservers() {
525 isScheduled = false;
526 while (globalMutationObservers.length) {
527 var notifyList = globalMutationObservers;
528 globalMutationObservers = [];
529 notifyList.sort(function(x, y) {
530 return x.uid_ - y.uid_;
531 });
532 for (var i = 0; i < notifyList.length; i++) {
533 var mo = notifyList[i];
534 mo.scheduled_ = false;
535 var queue = mo.takeRecords();
536 removeTransientObserversFor(mo);
537 if (queue.length) {
538 mo.callback_(queue, mo);
539 }
540 }
541 }
542 }
543 function MutationRecord(type, target) {
544 this.type = type;
545 this.target = target;
546 this.addedNodes = new wrappers.NodeList();
547 this.removedNodes = new wrappers.NodeList();
548 this.previousSibling = null;
549 this.nextSibling = null;
550 this.attributeName = null;
551 this.attributeNamespace = null;
552 this.oldValue = null;
553 }
554 function registerTransientObservers(ancestor, node) {
555 for (;ancestor; ancestor = ancestor.parentNode) {
556 var registrations = registrationsTable.get(ancestor);
557 if (!registrations) continue;
558 for (var i = 0; i < registrations.length; i++) {
559 var registration = registrations[i];
560 if (registration.options.subtree) registration.addTransientObserver(node );
561 }
562 }
563 }
564 function removeTransientObserversFor(observer) {
565 for (var i = 0; i < observer.nodes_.length; i++) {
566 var node = observer.nodes_[i];
567 var registrations = registrationsTable.get(node);
568 if (!registrations) return;
569 for (var j = 0; j < registrations.length; j++) {
570 var registration = registrations[j];
571 if (registration.observer === observer) registration.removeTransientObse rvers();
572 }
573 }
574 }
575 function enqueueMutation(target, type, data) {
576 var interestedObservers = Object.create(null);
577 var associatedStrings = Object.create(null);
578 for (var node = target; node; node = node.parentNode) {
579 var registrations = registrationsTable.get(node);
580 if (!registrations) continue;
581 for (var j = 0; j < registrations.length; j++) {
582 var registration = registrations[j];
583 var options = registration.options;
584 if (node !== target && !options.subtree) continue;
585 if (type === "attributes" && !options.attributes) continue;
586 if (type === "attributes" && options.attributeFilter && (data.namespace !== null || options.attributeFilter.indexOf(data.name) === -1)) {
587 continue;
588 }
589 if (type === "characterData" && !options.characterData) continue;
590 if (type === "childList" && !options.childList) continue;
591 var observer = registration.observer;
592 interestedObservers[observer.uid_] = observer;
593 if (type === "attributes" && options.attributeOldValue || type === "char acterData" && options.characterDataOldValue) {
594 associatedStrings[observer.uid_] = data.oldValue;
595 }
596 }
597 }
598 for (var uid in interestedObservers) {
599 var observer = interestedObservers[uid];
600 var record = new MutationRecord(type, target);
601 if ("name" in data && "namespace" in data) {
602 record.attributeName = data.name;
603 record.attributeNamespace = data.namespace;
604 }
605 if (data.addedNodes) record.addedNodes = data.addedNodes;
606 if (data.removedNodes) record.removedNodes = data.removedNodes;
607 if (data.previousSibling) record.previousSibling = data.previousSibling;
608 if (data.nextSibling) record.nextSibling = data.nextSibling;
609 if (associatedStrings[uid] !== undefined) record.oldValue = associatedStri ngs[uid];
610 scheduleCallback(observer);
611 observer.records_.push(record);
612 }
613 }
614 var slice = Array.prototype.slice;
615 function MutationObserverOptions(options) {
616 this.childList = !!options.childList;
617 this.subtree = !!options.subtree;
618 if (!("attributes" in options) && ("attributeOldValue" in options || "attrib uteFilter" in options)) {
619 this.attributes = true;
620 } else {
621 this.attributes = !!options.attributes;
622 }
623 if ("characterDataOldValue" in options && !("characterData" in options)) thi s.characterData = true; else this.characterData = !!options.characterData;
624 if (!this.attributes && (options.attributeOldValue || "attributeFilter" in o ptions) || !this.characterData && options.characterDataOldValue) {
625 throw new TypeError();
626 }
627 this.characterData = !!options.characterData;
628 this.attributeOldValue = !!options.attributeOldValue;
629 this.characterDataOldValue = !!options.characterDataOldValue;
630 if ("attributeFilter" in options) {
631 if (options.attributeFilter == null || typeof options.attributeFilter !== "object") {
632 throw new TypeError();
633 }
634 this.attributeFilter = slice.call(options.attributeFilter);
635 } else {
636 this.attributeFilter = null;
637 }
638 }
639 var uidCounter = 0;
640 function MutationObserver(callback) {
641 this.callback_ = callback;
642 this.nodes_ = [];
643 this.records_ = [];
644 this.uid_ = ++uidCounter;
645 this.scheduled_ = false;
646 }
647 MutationObserver.prototype = {
648 constructor: MutationObserver,
649 observe: function(target, options) {
650 target = wrapIfNeeded(target);
651 var newOptions = new MutationObserverOptions(options);
652 var registration;
653 var registrations = registrationsTable.get(target);
654 if (!registrations) registrationsTable.set(target, registrations = []);
655 for (var i = 0; i < registrations.length; i++) {
656 if (registrations[i].observer === this) {
657 registration = registrations[i];
658 registration.removeTransientObservers();
659 registration.options = newOptions;
660 }
661 }
662 if (!registration) {
663 registration = new Registration(this, target, newOptions);
664 registrations.push(registration);
665 this.nodes_.push(target);
666 }
667 },
668 disconnect: function() {
669 this.nodes_.forEach(function(node) {
670 var registrations = registrationsTable.get(node);
671 for (var i = 0; i < registrations.length; i++) {
672 var registration = registrations[i];
673 if (registration.observer === this) {
674 registrations.splice(i, 1);
675 break;
676 }
677 }
678 }, this);
679 this.records_ = [];
680 },
681 takeRecords: function() {
682 var copyOfRecords = this.records_;
683 this.records_ = [];
684 return copyOfRecords;
685 }
686 };
687 function Registration(observer, target, options) {
688 this.observer = observer;
689 this.target = target;
690 this.options = options;
691 this.transientObservedNodes = [];
692 }
693 Registration.prototype = {
694 addTransientObserver: function(node) {
695 if (node === this.target) return;
696 scheduleCallback(this.observer);
697 this.transientObservedNodes.push(node);
698 var registrations = registrationsTable.get(node);
699 if (!registrations) registrationsTable.set(node, registrations = []);
700 registrations.push(this);
701 },
702 removeTransientObservers: function() {
703 var transientObservedNodes = this.transientObservedNodes;
704 this.transientObservedNodes = [];
705 for (var i = 0; i < transientObservedNodes.length; i++) {
706 var node = transientObservedNodes[i];
707 var registrations = registrationsTable.get(node);
708 for (var j = 0; j < registrations.length; j++) {
709 if (registrations[j] === this) {
710 registrations.splice(j, 1);
711 break;
712 }
713 }
714 }
715 }
716 };
717 scope.enqueueMutation = enqueueMutation;
718 scope.registerTransientObservers = registerTransientObservers;
719 scope.wrappers.MutationObserver = MutationObserver;
720 scope.wrappers.MutationRecord = MutationRecord;
721 })(window.ShadowDOMPolyfill);
722
723 (function(scope) {
724 "use strict";
725 function TreeScope(root, parent) {
726 this.root = root;
727 this.parent = parent;
728 }
729 TreeScope.prototype = {
730 get renderer() {
731 if (this.root instanceof scope.wrappers.ShadowRoot) {
732 return scope.getRendererForHost(this.root.host);
733 }
734 return null;
735 },
736 contains: function(treeScope) {
737 for (;treeScope; treeScope = treeScope.parent) {
738 if (treeScope === this) return true;
739 }
740 return false;
741 }
742 };
743 function setTreeScope(node, treeScope) {
744 if (node.treeScope_ !== treeScope) {
745 node.treeScope_ = treeScope;
746 for (var sr = node.shadowRoot; sr; sr = sr.olderShadowRoot) {
747 sr.treeScope_.parent = treeScope;
748 }
749 for (var child = node.firstChild; child; child = child.nextSibling) {
750 setTreeScope(child, treeScope);
751 }
752 }
753 }
754 function getTreeScope(node) {
755 if (node instanceof scope.wrappers.Window) {
756 debugger;
757 }
758 if (node.treeScope_) return node.treeScope_;
759 var parent = node.parentNode;
760 var treeScope;
761 if (parent) treeScope = getTreeScope(parent); else treeScope = new TreeScope (node, null);
762 return node.treeScope_ = treeScope;
763 }
764 scope.TreeScope = TreeScope;
765 scope.getTreeScope = getTreeScope;
766 scope.setTreeScope = setTreeScope;
767 })(window.ShadowDOMPolyfill);
768
769 (function(scope) {
770 "use strict";
771 var forwardMethodsToWrapper = scope.forwardMethodsToWrapper;
772 var getTreeScope = scope.getTreeScope;
773 var mixin = scope.mixin;
774 var registerWrapper = scope.registerWrapper;
775 var setWrapper = scope.setWrapper;
776 var unsafeUnwrap = scope.unsafeUnwrap;
777 var unwrap = scope.unwrap;
778 var wrap = scope.wrap;
779 var wrappers = scope.wrappers;
780 var wrappedFuns = new WeakMap();
781 var listenersTable = new WeakMap();
782 var handledEventsTable = new WeakMap();
783 var currentlyDispatchingEvents = new WeakMap();
784 var targetTable = new WeakMap();
785 var currentTargetTable = new WeakMap();
786 var relatedTargetTable = new WeakMap();
787 var eventPhaseTable = new WeakMap();
788 var stopPropagationTable = new WeakMap();
789 var stopImmediatePropagationTable = new WeakMap();
790 var eventHandlersTable = new WeakMap();
791 var eventPathTable = new WeakMap();
792 function isShadowRoot(node) {
793 return node instanceof wrappers.ShadowRoot;
794 }
795 function rootOfNode(node) {
796 return getTreeScope(node).root;
797 }
798 function getEventPath(node, event) {
799 var path = [];
800 var current = node;
801 path.push(current);
802 while (current) {
803 var destinationInsertionPoints = getDestinationInsertionPoints(current);
804 if (destinationInsertionPoints && destinationInsertionPoints.length > 0) {
805 for (var i = 0; i < destinationInsertionPoints.length; i++) {
806 var insertionPoint = destinationInsertionPoints[i];
807 if (isShadowInsertionPoint(insertionPoint)) {
808 var shadowRoot = rootOfNode(insertionPoint);
809 var olderShadowRoot = shadowRoot.olderShadowRoot;
810 if (olderShadowRoot) path.push(olderShadowRoot);
811 }
812 path.push(insertionPoint);
813 }
814 current = destinationInsertionPoints[destinationInsertionPoints.length - 1];
815 } else {
816 if (isShadowRoot(current)) {
817 if (inSameTree(node, current) && eventMustBeStopped(event)) {
818 break;
819 }
820 current = current.host;
821 path.push(current);
822 } else {
823 current = current.parentNode;
824 if (current) path.push(current);
825 }
826 }
827 }
828 return path;
829 }
830 function eventMustBeStopped(event) {
831 if (!event) return false;
832 switch (event.type) {
833 case "abort":
834 case "error":
835 case "select":
836 case "change":
837 case "load":
838 case "reset":
839 case "resize":
840 case "scroll":
841 case "selectstart":
842 return true;
843 }
844 return false;
845 }
846 function isShadowInsertionPoint(node) {
847 return node instanceof HTMLShadowElement;
848 }
849 function getDestinationInsertionPoints(node) {
850 return scope.getDestinationInsertionPoints(node);
851 }
852 function eventRetargetting(path, currentTarget) {
853 if (path.length === 0) return currentTarget;
854 if (currentTarget instanceof wrappers.Window) currentTarget = currentTarget. document;
855 var currentTargetTree = getTreeScope(currentTarget);
856 var originalTarget = path[0];
857 var originalTargetTree = getTreeScope(originalTarget);
858 var relativeTargetTree = lowestCommonInclusiveAncestor(currentTargetTree, or iginalTargetTree);
859 for (var i = 0; i < path.length; i++) {
860 var node = path[i];
861 if (getTreeScope(node) === relativeTargetTree) return node;
862 }
863 return path[path.length - 1];
864 }
865 function getTreeScopeAncestors(treeScope) {
866 var ancestors = [];
867 for (;treeScope; treeScope = treeScope.parent) {
868 ancestors.push(treeScope);
869 }
870 return ancestors;
871 }
872 function lowestCommonInclusiveAncestor(tsA, tsB) {
873 var ancestorsA = getTreeScopeAncestors(tsA);
874 var ancestorsB = getTreeScopeAncestors(tsB);
875 var result = null;
876 while (ancestorsA.length > 0 && ancestorsB.length > 0) {
877 var a = ancestorsA.pop();
878 var b = ancestorsB.pop();
879 if (a === b) result = a; else break;
880 }
881 return result;
882 }
883 function getTreeScopeRoot(ts) {
884 if (!ts.parent) return ts;
885 return getTreeScopeRoot(ts.parent);
886 }
887 function relatedTargetResolution(event, currentTarget, relatedTarget) {
888 if (currentTarget instanceof wrappers.Window) currentTarget = currentTarget. document;
889 var currentTargetTree = getTreeScope(currentTarget);
890 var relatedTargetTree = getTreeScope(relatedTarget);
891 var relatedTargetEventPath = getEventPath(relatedTarget, event);
892 var lowestCommonAncestorTree;
893 var lowestCommonAncestorTree = lowestCommonInclusiveAncestor(currentTargetTr ee, relatedTargetTree);
894 if (!lowestCommonAncestorTree) lowestCommonAncestorTree = relatedTargetTree. root;
895 for (var commonAncestorTree = lowestCommonAncestorTree; commonAncestorTree; commonAncestorTree = commonAncestorTree.parent) {
896 var adjustedRelatedTarget;
897 for (var i = 0; i < relatedTargetEventPath.length; i++) {
898 var node = relatedTargetEventPath[i];
899 if (getTreeScope(node) === commonAncestorTree) return node;
900 }
901 }
902 return null;
903 }
904 function inSameTree(a, b) {
905 return getTreeScope(a) === getTreeScope(b);
906 }
907 var NONE = 0;
908 var CAPTURING_PHASE = 1;
909 var AT_TARGET = 2;
910 var BUBBLING_PHASE = 3;
911 var pendingError;
912 function dispatchOriginalEvent(originalEvent) {
913 if (handledEventsTable.get(originalEvent)) return;
914 handledEventsTable.set(originalEvent, true);
915 dispatchEvent(wrap(originalEvent), wrap(originalEvent.target));
916 if (pendingError) {
917 var err = pendingError;
918 pendingError = null;
919 throw err;
920 }
921 }
922 function isLoadLikeEvent(event) {
923 switch (event.type) {
924 case "load":
925 case "beforeunload":
926 case "unload":
927 return true;
928 }
929 return false;
930 }
931 function dispatchEvent(event, originalWrapperTarget) {
932 if (currentlyDispatchingEvents.get(event)) throw new Error("InvalidStateErro r");
933 currentlyDispatchingEvents.set(event, true);
934 scope.renderAllPending();
935 var eventPath;
936 var overrideTarget;
937 var win;
938 if (isLoadLikeEvent(event) && !event.bubbles) {
939 var doc = originalWrapperTarget;
940 if (doc instanceof wrappers.Document && (win = doc.defaultView)) {
941 overrideTarget = doc;
942 eventPath = [];
943 }
944 }
945 if (!eventPath) {
946 if (originalWrapperTarget instanceof wrappers.Window) {
947 win = originalWrapperTarget;
948 eventPath = [];
949 } else {
950 eventPath = getEventPath(originalWrapperTarget, event);
951 if (!isLoadLikeEvent(event)) {
952 var doc = eventPath[eventPath.length - 1];
953 if (doc instanceof wrappers.Document) win = doc.defaultView;
954 }
955 }
956 }
957 eventPathTable.set(event, eventPath);
958 if (dispatchCapturing(event, eventPath, win, overrideTarget)) {
959 if (dispatchAtTarget(event, eventPath, win, overrideTarget)) {
960 dispatchBubbling(event, eventPath, win, overrideTarget);
961 }
962 }
963 eventPhaseTable.set(event, NONE);
964 currentTargetTable.delete(event, null);
965 currentlyDispatchingEvents.delete(event);
966 return event.defaultPrevented;
967 }
968 function dispatchCapturing(event, eventPath, win, overrideTarget) {
969 var phase = CAPTURING_PHASE;
970 if (win) {
971 if (!invoke(win, event, phase, eventPath, overrideTarget)) return false;
972 }
973 for (var i = eventPath.length - 1; i > 0; i--) {
974 if (!invoke(eventPath[i], event, phase, eventPath, overrideTarget)) return false;
975 }
976 return true;
977 }
978 function dispatchAtTarget(event, eventPath, win, overrideTarget) {
979 var phase = AT_TARGET;
980 var currentTarget = eventPath[0] || win;
981 return invoke(currentTarget, event, phase, eventPath, overrideTarget);
982 }
983 function dispatchBubbling(event, eventPath, win, overrideTarget) {
984 var phase = BUBBLING_PHASE;
985 for (var i = 1; i < eventPath.length; i++) {
986 if (!invoke(eventPath[i], event, phase, eventPath, overrideTarget)) return ;
987 }
988 if (win && eventPath.length > 0) {
989 invoke(win, event, phase, eventPath, overrideTarget);
990 }
991 }
992 function invoke(currentTarget, event, phase, eventPath, overrideTarget) {
993 var listeners = listenersTable.get(currentTarget);
994 if (!listeners) return true;
995 var target = overrideTarget || eventRetargetting(eventPath, currentTarget);
996 if (target === currentTarget) {
997 if (phase === CAPTURING_PHASE) return true;
998 if (phase === BUBBLING_PHASE) phase = AT_TARGET;
999 } else if (phase === BUBBLING_PHASE && !event.bubbles) {
1000 return true;
1001 }
1002 if ("relatedTarget" in event) {
1003 var originalEvent = unwrap(event);
1004 var unwrappedRelatedTarget = originalEvent.relatedTarget;
1005 if (unwrappedRelatedTarget) {
1006 if (unwrappedRelatedTarget instanceof Object && unwrappedRelatedTarget.a ddEventListener) {
1007 var relatedTarget = wrap(unwrappedRelatedTarget);
1008 var adjusted = relatedTargetResolution(event, currentTarget, relatedTa rget);
1009 if (adjusted === target) return true;
1010 } else {
1011 adjusted = null;
1012 }
1013 relatedTargetTable.set(event, adjusted);
1014 }
1015 }
1016 eventPhaseTable.set(event, phase);
1017 var type = event.type;
1018 var anyRemoved = false;
1019 targetTable.set(event, target);
1020 currentTargetTable.set(event, currentTarget);
1021 listeners.depth++;
1022 for (var i = 0, len = listeners.length; i < len; i++) {
1023 var listener = listeners[i];
1024 if (listener.removed) {
1025 anyRemoved = true;
1026 continue;
1027 }
1028 if (listener.type !== type || !listener.capture && phase === CAPTURING_PHA SE || listener.capture && phase === BUBBLING_PHASE) {
1029 continue;
1030 }
1031 try {
1032 if (typeof listener.handler === "function") listener.handler.call(curren tTarget, event); else listener.handler.handleEvent(event);
1033 if (stopImmediatePropagationTable.get(event)) return false;
1034 } catch (ex) {
1035 if (!pendingError) pendingError = ex;
1036 }
1037 }
1038 listeners.depth--;
1039 if (anyRemoved && listeners.depth === 0) {
1040 var copy = listeners.slice();
1041 listeners.length = 0;
1042 for (var i = 0; i < copy.length; i++) {
1043 if (!copy[i].removed) listeners.push(copy[i]);
1044 }
1045 }
1046 return !stopPropagationTable.get(event);
1047 }
1048 function Listener(type, handler, capture) {
1049 this.type = type;
1050 this.handler = handler;
1051 this.capture = Boolean(capture);
1052 }
1053 Listener.prototype = {
1054 equals: function(that) {
1055 return this.handler === that.handler && this.type === that.type && this.ca pture === that.capture;
1056 },
1057 get removed() {
1058 return this.handler === null;
1059 },
1060 remove: function() {
1061 this.handler = null;
1062 }
1063 };
1064 var OriginalEvent = window.Event;
1065 OriginalEvent.prototype.polymerBlackList_ = {
1066 returnValue: true,
1067 keyLocation: true
1068 };
1069 function Event(type, options) {
1070 if (type instanceof OriginalEvent) {
1071 var impl = type;
1072 if (!OriginalBeforeUnloadEvent && impl.type === "beforeunload" && !(this i nstanceof BeforeUnloadEvent)) {
1073 return new BeforeUnloadEvent(impl);
1074 }
1075 setWrapper(impl, this);
1076 } else {
1077 return wrap(constructEvent(OriginalEvent, "Event", type, options));
1078 }
1079 }
1080 Event.prototype = {
1081 get target() {
1082 return targetTable.get(this);
1083 },
1084 get currentTarget() {
1085 return currentTargetTable.get(this);
1086 },
1087 get eventPhase() {
1088 return eventPhaseTable.get(this);
1089 },
1090 get path() {
1091 var eventPath = eventPathTable.get(this);
1092 if (!eventPath) return [];
1093 return eventPath.slice();
1094 },
1095 stopPropagation: function() {
1096 stopPropagationTable.set(this, true);
1097 },
1098 stopImmediatePropagation: function() {
1099 stopPropagationTable.set(this, true);
1100 stopImmediatePropagationTable.set(this, true);
1101 }
1102 };
1103 registerWrapper(OriginalEvent, Event, document.createEvent("Event"));
1104 function unwrapOptions(options) {
1105 if (!options || !options.relatedTarget) return options;
1106 return Object.create(options, {
1107 relatedTarget: {
1108 value: unwrap(options.relatedTarget)
1109 }
1110 });
1111 }
1112 function registerGenericEvent(name, SuperEvent, prototype) {
1113 var OriginalEvent = window[name];
1114 var GenericEvent = function(type, options) {
1115 if (type instanceof OriginalEvent) setWrapper(type, this); else return wra p(constructEvent(OriginalEvent, name, type, options));
1116 };
1117 GenericEvent.prototype = Object.create(SuperEvent.prototype);
1118 if (prototype) mixin(GenericEvent.prototype, prototype);
1119 if (OriginalEvent) {
1120 try {
1121 registerWrapper(OriginalEvent, GenericEvent, new OriginalEvent("temp"));
1122 } catch (ex) {
1123 registerWrapper(OriginalEvent, GenericEvent, document.createEvent(name)) ;
1124 }
1125 }
1126 return GenericEvent;
1127 }
1128 var UIEvent = registerGenericEvent("UIEvent", Event);
1129 var CustomEvent = registerGenericEvent("CustomEvent", Event);
1130 var relatedTargetProto = {
1131 get relatedTarget() {
1132 var relatedTarget = relatedTargetTable.get(this);
1133 if (relatedTarget !== undefined) return relatedTarget;
1134 return wrap(unwrap(this).relatedTarget);
1135 }
1136 };
1137 function getInitFunction(name, relatedTargetIndex) {
1138 return function() {
1139 arguments[relatedTargetIndex] = unwrap(arguments[relatedTargetIndex]);
1140 var impl = unwrap(this);
1141 impl[name].apply(impl, arguments);
1142 };
1143 }
1144 var mouseEventProto = mixin({
1145 initMouseEvent: getInitFunction("initMouseEvent", 14)
1146 }, relatedTargetProto);
1147 var focusEventProto = mixin({
1148 initFocusEvent: getInitFunction("initFocusEvent", 5)
1149 }, relatedTargetProto);
1150 var MouseEvent = registerGenericEvent("MouseEvent", UIEvent, mouseEventProto);
1151 var FocusEvent = registerGenericEvent("FocusEvent", UIEvent, focusEventProto);
1152 var defaultInitDicts = Object.create(null);
1153 var supportsEventConstructors = function() {
1154 try {
1155 new window.FocusEvent("focus");
1156 } catch (ex) {
1157 return false;
1158 }
1159 return true;
1160 }();
1161 function constructEvent(OriginalEvent, name, type, options) {
1162 if (supportsEventConstructors) return new OriginalEvent(type, unwrapOptions( options));
1163 var event = unwrap(document.createEvent(name));
1164 var defaultDict = defaultInitDicts[name];
1165 var args = [ type ];
1166 Object.keys(defaultDict).forEach(function(key) {
1167 var v = options != null && key in options ? options[key] : defaultDict[key ];
1168 if (key === "relatedTarget") v = unwrap(v);
1169 args.push(v);
1170 });
1171 event["init" + name].apply(event, args);
1172 return event;
1173 }
1174 if (!supportsEventConstructors) {
1175 var configureEventConstructor = function(name, initDict, superName) {
1176 if (superName) {
1177 var superDict = defaultInitDicts[superName];
1178 initDict = mixin(mixin({}, superDict), initDict);
1179 }
1180 defaultInitDicts[name] = initDict;
1181 };
1182 configureEventConstructor("Event", {
1183 bubbles: false,
1184 cancelable: false
1185 });
1186 configureEventConstructor("CustomEvent", {
1187 detail: null
1188 }, "Event");
1189 configureEventConstructor("UIEvent", {
1190 view: null,
1191 detail: 0
1192 }, "Event");
1193 configureEventConstructor("MouseEvent", {
1194 screenX: 0,
1195 screenY: 0,
1196 clientX: 0,
1197 clientY: 0,
1198 ctrlKey: false,
1199 altKey: false,
1200 shiftKey: false,
1201 metaKey: false,
1202 button: 0,
1203 relatedTarget: null
1204 }, "UIEvent");
1205 configureEventConstructor("FocusEvent", {
1206 relatedTarget: null
1207 }, "UIEvent");
1208 }
1209 var OriginalBeforeUnloadEvent = window.BeforeUnloadEvent;
1210 function BeforeUnloadEvent(impl) {
1211 Event.call(this, impl);
1212 }
1213 BeforeUnloadEvent.prototype = Object.create(Event.prototype);
1214 mixin(BeforeUnloadEvent.prototype, {
1215 get returnValue() {
1216 return unsafeUnwrap(this).returnValue;
1217 },
1218 set returnValue(v) {
1219 unsafeUnwrap(this).returnValue = v;
1220 }
1221 });
1222 if (OriginalBeforeUnloadEvent) registerWrapper(OriginalBeforeUnloadEvent, Befo reUnloadEvent);
1223 function isValidListener(fun) {
1224 if (typeof fun === "function") return true;
1225 return fun && fun.handleEvent;
1226 }
1227 function isMutationEvent(type) {
1228 switch (type) {
1229 case "DOMAttrModified":
1230 case "DOMAttributeNameChanged":
1231 case "DOMCharacterDataModified":
1232 case "DOMElementNameChanged":
1233 case "DOMNodeInserted":
1234 case "DOMNodeInsertedIntoDocument":
1235 case "DOMNodeRemoved":
1236 case "DOMNodeRemovedFromDocument":
1237 case "DOMSubtreeModified":
1238 return true;
1239 }
1240 return false;
1241 }
1242 var OriginalEventTarget = window.EventTarget;
1243 function EventTarget(impl) {
1244 setWrapper(impl, this);
1245 }
1246 var methodNames = [ "addEventListener", "removeEventListener", "dispatchEvent" ];
1247 [ Node, Window ].forEach(function(constructor) {
1248 var p = constructor.prototype;
1249 methodNames.forEach(function(name) {
1250 Object.defineProperty(p, name + "_", {
1251 value: p[name]
1252 });
1253 });
1254 });
1255 function getTargetToListenAt(wrapper) {
1256 if (wrapper instanceof wrappers.ShadowRoot) wrapper = wrapper.host;
1257 return unwrap(wrapper);
1258 }
1259 EventTarget.prototype = {
1260 addEventListener: function(type, fun, capture) {
1261 if (!isValidListener(fun) || isMutationEvent(type)) return;
1262 var listener = new Listener(type, fun, capture);
1263 var listeners = listenersTable.get(this);
1264 if (!listeners) {
1265 listeners = [];
1266 listeners.depth = 0;
1267 listenersTable.set(this, listeners);
1268 } else {
1269 for (var i = 0; i < listeners.length; i++) {
1270 if (listener.equals(listeners[i])) return;
1271 }
1272 }
1273 listeners.push(listener);
1274 var target = getTargetToListenAt(this);
1275 target.addEventListener_(type, dispatchOriginalEvent, true);
1276 },
1277 removeEventListener: function(type, fun, capture) {
1278 capture = Boolean(capture);
1279 var listeners = listenersTable.get(this);
1280 if (!listeners) return;
1281 var count = 0, found = false;
1282 for (var i = 0; i < listeners.length; i++) {
1283 if (listeners[i].type === type && listeners[i].capture === capture) {
1284 count++;
1285 if (listeners[i].handler === fun) {
1286 found = true;
1287 listeners[i].remove();
1288 }
1289 }
1290 }
1291 if (found && count === 1) {
1292 var target = getTargetToListenAt(this);
1293 target.removeEventListener_(type, dispatchOriginalEvent, true);
1294 }
1295 },
1296 dispatchEvent: function(event) {
1297 var nativeEvent = unwrap(event);
1298 var eventType = nativeEvent.type;
1299 handledEventsTable.set(nativeEvent, false);
1300 scope.renderAllPending();
1301 var tempListener;
1302 if (!hasListenerInAncestors(this, eventType)) {
1303 tempListener = function() {};
1304 this.addEventListener(eventType, tempListener, true);
1305 }
1306 try {
1307 return unwrap(this).dispatchEvent_(nativeEvent);
1308 } finally {
1309 if (tempListener) this.removeEventListener(eventType, tempListener, true );
1310 }
1311 }
1312 };
1313 function hasListener(node, type) {
1314 var listeners = listenersTable.get(node);
1315 if (listeners) {
1316 for (var i = 0; i < listeners.length; i++) {
1317 if (!listeners[i].removed && listeners[i].type === type) return true;
1318 }
1319 }
1320 return false;
1321 }
1322 function hasListenerInAncestors(target, type) {
1323 for (var node = unwrap(target); node; node = node.parentNode) {
1324 if (hasListener(wrap(node), type)) return true;
1325 }
1326 return false;
1327 }
1328 if (OriginalEventTarget) registerWrapper(OriginalEventTarget, EventTarget);
1329 function wrapEventTargetMethods(constructors) {
1330 forwardMethodsToWrapper(constructors, methodNames);
1331 }
1332 var originalElementFromPoint = document.elementFromPoint;
1333 function elementFromPoint(self, document, x, y) {
1334 scope.renderAllPending();
1335 var element = wrap(originalElementFromPoint.call(unsafeUnwrap(document), x, y));
1336 if (!element) return null;
1337 var path = getEventPath(element, null);
1338 var idx = path.lastIndexOf(self);
1339 if (idx == -1) return null; else path = path.slice(0, idx);
1340 return eventRetargetting(path, self);
1341 }
1342 function getEventHandlerGetter(name) {
1343 return function() {
1344 var inlineEventHandlers = eventHandlersTable.get(this);
1345 return inlineEventHandlers && inlineEventHandlers[name] && inlineEventHand lers[name].value || null;
1346 };
1347 }
1348 function getEventHandlerSetter(name) {
1349 var eventType = name.slice(2);
1350 return function(value) {
1351 var inlineEventHandlers = eventHandlersTable.get(this);
1352 if (!inlineEventHandlers) {
1353 inlineEventHandlers = Object.create(null);
1354 eventHandlersTable.set(this, inlineEventHandlers);
1355 }
1356 var old = inlineEventHandlers[name];
1357 if (old) this.removeEventListener(eventType, old.wrapped, false);
1358 if (typeof value === "function") {
1359 var wrapped = function(e) {
1360 var rv = value.call(this, e);
1361 if (rv === false) e.preventDefault(); else if (name === "onbeforeunloa d" && typeof rv === "string") e.returnValue = rv;
1362 };
1363 this.addEventListener(eventType, wrapped, false);
1364 inlineEventHandlers[name] = {
1365 value: value,
1366 wrapped: wrapped
1367 };
1368 }
1369 };
1370 }
1371 scope.elementFromPoint = elementFromPoint;
1372 scope.getEventHandlerGetter = getEventHandlerGetter;
1373 scope.getEventHandlerSetter = getEventHandlerSetter;
1374 scope.wrapEventTargetMethods = wrapEventTargetMethods;
1375 scope.wrappers.BeforeUnloadEvent = BeforeUnloadEvent;
1376 scope.wrappers.CustomEvent = CustomEvent;
1377 scope.wrappers.Event = Event;
1378 scope.wrappers.EventTarget = EventTarget;
1379 scope.wrappers.FocusEvent = FocusEvent;
1380 scope.wrappers.MouseEvent = MouseEvent;
1381 scope.wrappers.UIEvent = UIEvent;
1382 })(window.ShadowDOMPolyfill);
1383
1384 (function(scope) {
1385 "use strict";
1386 var UIEvent = scope.wrappers.UIEvent;
1387 var mixin = scope.mixin;
1388 var registerWrapper = scope.registerWrapper;
1389 var setWrapper = scope.setWrapper;
1390 var unsafeUnwrap = scope.unsafeUnwrap;
1391 var wrap = scope.wrap;
1392 var OriginalTouchEvent = window.TouchEvent;
1393 if (!OriginalTouchEvent) return;
1394 var nativeEvent;
1395 try {
1396 nativeEvent = document.createEvent("TouchEvent");
1397 } catch (ex) {
1398 return;
1399 }
1400 var nonEnumDescriptor = {
1401 enumerable: false
1402 };
1403 function nonEnum(obj, prop) {
1404 Object.defineProperty(obj, prop, nonEnumDescriptor);
1405 }
1406 function Touch(impl) {
1407 setWrapper(impl, this);
1408 }
1409 Touch.prototype = {
1410 get target() {
1411 return wrap(unsafeUnwrap(this).target);
1412 }
1413 };
1414 var descr = {
1415 configurable: true,
1416 enumerable: true,
1417 get: null
1418 };
1419 [ "clientX", "clientY", "screenX", "screenY", "pageX", "pageY", "identifier", "webkitRadiusX", "webkitRadiusY", "webkitRotationAngle", "webkitForce" ].forEach (function(name) {
1420 descr.get = function() {
1421 return unsafeUnwrap(this)[name];
1422 };
1423 Object.defineProperty(Touch.prototype, name, descr);
1424 });
1425 function TouchList() {
1426 this.length = 0;
1427 nonEnum(this, "length");
1428 }
1429 TouchList.prototype = {
1430 item: function(index) {
1431 return this[index];
1432 }
1433 };
1434 function wrapTouchList(nativeTouchList) {
1435 var list = new TouchList();
1436 for (var i = 0; i < nativeTouchList.length; i++) {
1437 list[i] = new Touch(nativeTouchList[i]);
1438 }
1439 list.length = i;
1440 return list;
1441 }
1442 function TouchEvent(impl) {
1443 UIEvent.call(this, impl);
1444 }
1445 TouchEvent.prototype = Object.create(UIEvent.prototype);
1446 mixin(TouchEvent.prototype, {
1447 get touches() {
1448 return wrapTouchList(unsafeUnwrap(this).touches);
1449 },
1450 get targetTouches() {
1451 return wrapTouchList(unsafeUnwrap(this).targetTouches);
1452 },
1453 get changedTouches() {
1454 return wrapTouchList(unsafeUnwrap(this).changedTouches);
1455 },
1456 initTouchEvent: function() {
1457 throw new Error("Not implemented");
1458 }
1459 });
1460 registerWrapper(OriginalTouchEvent, TouchEvent, nativeEvent);
1461 scope.wrappers.Touch = Touch;
1462 scope.wrappers.TouchEvent = TouchEvent;
1463 scope.wrappers.TouchList = TouchList;
1464 })(window.ShadowDOMPolyfill);
1465
1466 (function(scope) {
1467 "use strict";
1468 var unsafeUnwrap = scope.unsafeUnwrap;
1469 var wrap = scope.wrap;
1470 var nonEnumDescriptor = {
1471 enumerable: false
1472 };
1473 function nonEnum(obj, prop) {
1474 Object.defineProperty(obj, prop, nonEnumDescriptor);
1475 }
1476 function NodeList() {
1477 this.length = 0;
1478 nonEnum(this, "length");
1479 }
1480 NodeList.prototype = {
1481 item: function(index) {
1482 return this[index];
1483 }
1484 };
1485 nonEnum(NodeList.prototype, "item");
1486 function wrapNodeList(list) {
1487 if (list == null) return list;
1488 var wrapperList = new NodeList();
1489 for (var i = 0, length = list.length; i < length; i++) {
1490 wrapperList[i] = wrap(list[i]);
1491 }
1492 wrapperList.length = length;
1493 return wrapperList;
1494 }
1495 function addWrapNodeListMethod(wrapperConstructor, name) {
1496 wrapperConstructor.prototype[name] = function() {
1497 return wrapNodeList(unsafeUnwrap(this)[name].apply(unsafeUnwrap(this), arg uments));
1498 };
1499 }
1500 scope.wrappers.NodeList = NodeList;
1501 scope.addWrapNodeListMethod = addWrapNodeListMethod;
1502 scope.wrapNodeList = wrapNodeList;
1503 })(window.ShadowDOMPolyfill);
1504
1505 (function(scope) {
1506 "use strict";
1507 scope.wrapHTMLCollection = scope.wrapNodeList;
1508 scope.wrappers.HTMLCollection = scope.wrappers.NodeList;
1509 })(window.ShadowDOMPolyfill);
1510
1511 (function(scope) {
1512 "use strict";
1513 var EventTarget = scope.wrappers.EventTarget;
1514 var NodeList = scope.wrappers.NodeList;
1515 var TreeScope = scope.TreeScope;
1516 var assert = scope.assert;
1517 var defineWrapGetter = scope.defineWrapGetter;
1518 var enqueueMutation = scope.enqueueMutation;
1519 var getTreeScope = scope.getTreeScope;
1520 var isWrapper = scope.isWrapper;
1521 var mixin = scope.mixin;
1522 var registerTransientObservers = scope.registerTransientObservers;
1523 var registerWrapper = scope.registerWrapper;
1524 var setTreeScope = scope.setTreeScope;
1525 var unsafeUnwrap = scope.unsafeUnwrap;
1526 var unwrap = scope.unwrap;
1527 var unwrapIfNeeded = scope.unwrapIfNeeded;
1528 var wrap = scope.wrap;
1529 var wrapIfNeeded = scope.wrapIfNeeded;
1530 var wrappers = scope.wrappers;
1531 function assertIsNodeWrapper(node) {
1532 assert(node instanceof Node);
1533 }
1534 function createOneElementNodeList(node) {
1535 var nodes = new NodeList();
1536 nodes[0] = node;
1537 nodes.length = 1;
1538 return nodes;
1539 }
1540 var surpressMutations = false;
1541 function enqueueRemovalForInsertedNodes(node, parent, nodes) {
1542 enqueueMutation(parent, "childList", {
1543 removedNodes: nodes,
1544 previousSibling: node.previousSibling,
1545 nextSibling: node.nextSibling
1546 });
1547 }
1548 function enqueueRemovalForInsertedDocumentFragment(df, nodes) {
1549 enqueueMutation(df, "childList", {
1550 removedNodes: nodes
1551 });
1552 }
1553 function collectNodes(node, parentNode, previousNode, nextNode) {
1554 if (node instanceof DocumentFragment) {
1555 var nodes = collectNodesForDocumentFragment(node);
1556 surpressMutations = true;
1557 for (var i = nodes.length - 1; i >= 0; i--) {
1558 node.removeChild(nodes[i]);
1559 nodes[i].parentNode_ = parentNode;
1560 }
1561 surpressMutations = false;
1562 for (var i = 0; i < nodes.length; i++) {
1563 nodes[i].previousSibling_ = nodes[i - 1] || previousNode;
1564 nodes[i].nextSibling_ = nodes[i + 1] || nextNode;
1565 }
1566 if (previousNode) previousNode.nextSibling_ = nodes[0];
1567 if (nextNode) nextNode.previousSibling_ = nodes[nodes.length - 1];
1568 return nodes;
1569 }
1570 var nodes = createOneElementNodeList(node);
1571 var oldParent = node.parentNode;
1572 if (oldParent) {
1573 oldParent.removeChild(node);
1574 }
1575 node.parentNode_ = parentNode;
1576 node.previousSibling_ = previousNode;
1577 node.nextSibling_ = nextNode;
1578 if (previousNode) previousNode.nextSibling_ = node;
1579 if (nextNode) nextNode.previousSibling_ = node;
1580 return nodes;
1581 }
1582 function collectNodesNative(node) {
1583 if (node instanceof DocumentFragment) return collectNodesForDocumentFragment (node);
1584 var nodes = createOneElementNodeList(node);
1585 var oldParent = node.parentNode;
1586 if (oldParent) enqueueRemovalForInsertedNodes(node, oldParent, nodes);
1587 return nodes;
1588 }
1589 function collectNodesForDocumentFragment(node) {
1590 var nodes = new NodeList();
1591 var i = 0;
1592 for (var child = node.firstChild; child; child = child.nextSibling) {
1593 nodes[i++] = child;
1594 }
1595 nodes.length = i;
1596 enqueueRemovalForInsertedDocumentFragment(node, nodes);
1597 return nodes;
1598 }
1599 function snapshotNodeList(nodeList) {
1600 return nodeList;
1601 }
1602 function nodeWasAdded(node, treeScope) {
1603 setTreeScope(node, treeScope);
1604 node.nodeIsInserted_();
1605 }
1606 function nodesWereAdded(nodes, parent) {
1607 var treeScope = getTreeScope(parent);
1608 for (var i = 0; i < nodes.length; i++) {
1609 nodeWasAdded(nodes[i], treeScope);
1610 }
1611 }
1612 function nodeWasRemoved(node) {
1613 setTreeScope(node, new TreeScope(node, null));
1614 }
1615 function nodesWereRemoved(nodes) {
1616 for (var i = 0; i < nodes.length; i++) {
1617 nodeWasRemoved(nodes[i]);
1618 }
1619 }
1620 function ensureSameOwnerDocument(parent, child) {
1621 var ownerDoc = parent.nodeType === Node.DOCUMENT_NODE ? parent : parent.owne rDocument;
1622 if (ownerDoc !== child.ownerDocument) ownerDoc.adoptNode(child);
1623 }
1624 function adoptNodesIfNeeded(owner, nodes) {
1625 if (!nodes.length) return;
1626 var ownerDoc = owner.ownerDocument;
1627 if (ownerDoc === nodes[0].ownerDocument) return;
1628 for (var i = 0; i < nodes.length; i++) {
1629 scope.adoptNodeNoRemove(nodes[i], ownerDoc);
1630 }
1631 }
1632 function unwrapNodesForInsertion(owner, nodes) {
1633 adoptNodesIfNeeded(owner, nodes);
1634 var length = nodes.length;
1635 if (length === 1) return unwrap(nodes[0]);
1636 var df = unwrap(owner.ownerDocument.createDocumentFragment());
1637 for (var i = 0; i < length; i++) {
1638 df.appendChild(unwrap(nodes[i]));
1639 }
1640 return df;
1641 }
1642 function clearChildNodes(wrapper) {
1643 if (wrapper.firstChild_ !== undefined) {
1644 var child = wrapper.firstChild_;
1645 while (child) {
1646 var tmp = child;
1647 child = child.nextSibling_;
1648 tmp.parentNode_ = tmp.previousSibling_ = tmp.nextSibling_ = undefined;
1649 }
1650 }
1651 wrapper.firstChild_ = wrapper.lastChild_ = undefined;
1652 }
1653 function removeAllChildNodes(wrapper) {
1654 if (wrapper.invalidateShadowRenderer()) {
1655 var childWrapper = wrapper.firstChild;
1656 while (childWrapper) {
1657 assert(childWrapper.parentNode === wrapper);
1658 var nextSibling = childWrapper.nextSibling;
1659 var childNode = unwrap(childWrapper);
1660 var parentNode = childNode.parentNode;
1661 if (parentNode) originalRemoveChild.call(parentNode, childNode);
1662 childWrapper.previousSibling_ = childWrapper.nextSibling_ = childWrapper .parentNode_ = null;
1663 childWrapper = nextSibling;
1664 }
1665 wrapper.firstChild_ = wrapper.lastChild_ = null;
1666 } else {
1667 var node = unwrap(wrapper);
1668 var child = node.firstChild;
1669 var nextSibling;
1670 while (child) {
1671 nextSibling = child.nextSibling;
1672 originalRemoveChild.call(node, child);
1673 child = nextSibling;
1674 }
1675 }
1676 }
1677 function invalidateParent(node) {
1678 var p = node.parentNode;
1679 return p && p.invalidateShadowRenderer();
1680 }
1681 function cleanupNodes(nodes) {
1682 for (var i = 0, n; i < nodes.length; i++) {
1683 n = nodes[i];
1684 n.parentNode.removeChild(n);
1685 }
1686 }
1687 var originalImportNode = document.importNode;
1688 var originalCloneNode = window.Node.prototype.cloneNode;
1689 function cloneNode(node, deep, opt_doc) {
1690 var clone;
1691 if (opt_doc) clone = wrap(originalImportNode.call(opt_doc, unsafeUnwrap(node ), false)); else clone = wrap(originalCloneNode.call(unsafeUnwrap(node), false)) ;
1692 if (deep) {
1693 for (var child = node.firstChild; child; child = child.nextSibling) {
1694 clone.appendChild(cloneNode(child, true, opt_doc));
1695 }
1696 if (node instanceof wrappers.HTMLTemplateElement) {
1697 var cloneContent = clone.content;
1698 for (var child = node.content.firstChild; child; child = child.nextSibli ng) {
1699 cloneContent.appendChild(cloneNode(child, true, opt_doc));
1700 }
1701 }
1702 }
1703 return clone;
1704 }
1705 function contains(self, child) {
1706 if (!child || getTreeScope(self) !== getTreeScope(child)) return false;
1707 for (var node = child; node; node = node.parentNode) {
1708 if (node === self) return true;
1709 }
1710 return false;
1711 }
1712 var OriginalNode = window.Node;
1713 function Node(original) {
1714 assert(original instanceof OriginalNode);
1715 EventTarget.call(this, original);
1716 this.parentNode_ = undefined;
1717 this.firstChild_ = undefined;
1718 this.lastChild_ = undefined;
1719 this.nextSibling_ = undefined;
1720 this.previousSibling_ = undefined;
1721 this.treeScope_ = undefined;
1722 }
1723 var OriginalDocumentFragment = window.DocumentFragment;
1724 var originalAppendChild = OriginalNode.prototype.appendChild;
1725 var originalCompareDocumentPosition = OriginalNode.prototype.compareDocumentPo sition;
1726 var originalInsertBefore = OriginalNode.prototype.insertBefore;
1727 var originalRemoveChild = OriginalNode.prototype.removeChild;
1728 var originalReplaceChild = OriginalNode.prototype.replaceChild;
1729 var isIe = /Trident|Edge/.test(navigator.userAgent);
1730 var removeChildOriginalHelper = isIe ? function(parent, child) {
1731 try {
1732 originalRemoveChild.call(parent, child);
1733 } catch (ex) {
1734 if (!(parent instanceof OriginalDocumentFragment)) throw ex;
1735 }
1736 } : function(parent, child) {
1737 originalRemoveChild.call(parent, child);
1738 };
1739 Node.prototype = Object.create(EventTarget.prototype);
1740 mixin(Node.prototype, {
1741 appendChild: function(childWrapper) {
1742 return this.insertBefore(childWrapper, null);
1743 },
1744 insertBefore: function(childWrapper, refWrapper) {
1745 assertIsNodeWrapper(childWrapper);
1746 var refNode;
1747 if (refWrapper) {
1748 if (isWrapper(refWrapper)) {
1749 refNode = unwrap(refWrapper);
1750 } else {
1751 refNode = refWrapper;
1752 refWrapper = wrap(refNode);
1753 }
1754 } else {
1755 refWrapper = null;
1756 refNode = null;
1757 }
1758 refWrapper && assert(refWrapper.parentNode === this);
1759 var nodes;
1760 var previousNode = refWrapper ? refWrapper.previousSibling : this.lastChil d;
1761 var useNative = !this.invalidateShadowRenderer() && !invalidateParent(chil dWrapper);
1762 if (useNative) nodes = collectNodesNative(childWrapper); else nodes = coll ectNodes(childWrapper, this, previousNode, refWrapper);
1763 if (useNative) {
1764 ensureSameOwnerDocument(this, childWrapper);
1765 clearChildNodes(this);
1766 originalInsertBefore.call(unsafeUnwrap(this), unwrap(childWrapper), refN ode);
1767 } else {
1768 if (!previousNode) this.firstChild_ = nodes[0];
1769 if (!refWrapper) {
1770 this.lastChild_ = nodes[nodes.length - 1];
1771 if (this.firstChild_ === undefined) this.firstChild_ = this.firstChild ;
1772 }
1773 var parentNode = refNode ? refNode.parentNode : unsafeUnwrap(this);
1774 if (parentNode) {
1775 originalInsertBefore.call(parentNode, unwrapNodesForInsertion(this, no des), refNode);
1776 } else {
1777 adoptNodesIfNeeded(this, nodes);
1778 }
1779 }
1780 enqueueMutation(this, "childList", {
1781 addedNodes: nodes,
1782 nextSibling: refWrapper,
1783 previousSibling: previousNode
1784 });
1785 nodesWereAdded(nodes, this);
1786 return childWrapper;
1787 },
1788 removeChild: function(childWrapper) {
1789 assertIsNodeWrapper(childWrapper);
1790 if (childWrapper.parentNode !== this) {
1791 var found = false;
1792 var childNodes = this.childNodes;
1793 for (var ieChild = this.firstChild; ieChild; ieChild = ieChild.nextSibli ng) {
1794 if (ieChild === childWrapper) {
1795 found = true;
1796 break;
1797 }
1798 }
1799 if (!found) {
1800 throw new Error("NotFoundError");
1801 }
1802 }
1803 var childNode = unwrap(childWrapper);
1804 var childWrapperNextSibling = childWrapper.nextSibling;
1805 var childWrapperPreviousSibling = childWrapper.previousSibling;
1806 if (this.invalidateShadowRenderer()) {
1807 var thisFirstChild = this.firstChild;
1808 var thisLastChild = this.lastChild;
1809 var parentNode = childNode.parentNode;
1810 if (parentNode) removeChildOriginalHelper(parentNode, childNode);
1811 if (thisFirstChild === childWrapper) this.firstChild_ = childWrapperNext Sibling;
1812 if (thisLastChild === childWrapper) this.lastChild_ = childWrapperPrevio usSibling;
1813 if (childWrapperPreviousSibling) childWrapperPreviousSibling.nextSibling _ = childWrapperNextSibling;
1814 if (childWrapperNextSibling) {
1815 childWrapperNextSibling.previousSibling_ = childWrapperPreviousSibling ;
1816 }
1817 childWrapper.previousSibling_ = childWrapper.nextSibling_ = childWrapper .parentNode_ = undefined;
1818 } else {
1819 clearChildNodes(this);
1820 removeChildOriginalHelper(unsafeUnwrap(this), childNode);
1821 }
1822 if (!surpressMutations) {
1823 enqueueMutation(this, "childList", {
1824 removedNodes: createOneElementNodeList(childWrapper),
1825 nextSibling: childWrapperNextSibling,
1826 previousSibling: childWrapperPreviousSibling
1827 });
1828 }
1829 registerTransientObservers(this, childWrapper);
1830 return childWrapper;
1831 },
1832 replaceChild: function(newChildWrapper, oldChildWrapper) {
1833 assertIsNodeWrapper(newChildWrapper);
1834 var oldChildNode;
1835 if (isWrapper(oldChildWrapper)) {
1836 oldChildNode = unwrap(oldChildWrapper);
1837 } else {
1838 oldChildNode = oldChildWrapper;
1839 oldChildWrapper = wrap(oldChildNode);
1840 }
1841 if (oldChildWrapper.parentNode !== this) {
1842 throw new Error("NotFoundError");
1843 }
1844 var nextNode = oldChildWrapper.nextSibling;
1845 var previousNode = oldChildWrapper.previousSibling;
1846 var nodes;
1847 var useNative = !this.invalidateShadowRenderer() && !invalidateParent(newC hildWrapper);
1848 if (useNative) {
1849 nodes = collectNodesNative(newChildWrapper);
1850 } else {
1851 if (nextNode === newChildWrapper) nextNode = newChildWrapper.nextSibling ;
1852 nodes = collectNodes(newChildWrapper, this, previousNode, nextNode);
1853 }
1854 if (!useNative) {
1855 if (this.firstChild === oldChildWrapper) this.firstChild_ = nodes[0];
1856 if (this.lastChild === oldChildWrapper) this.lastChild_ = nodes[nodes.le ngth - 1];
1857 oldChildWrapper.previousSibling_ = oldChildWrapper.nextSibling_ = oldChi ldWrapper.parentNode_ = undefined;
1858 if (oldChildNode.parentNode) {
1859 originalReplaceChild.call(oldChildNode.parentNode, unwrapNodesForInser tion(this, nodes), oldChildNode);
1860 }
1861 } else {
1862 ensureSameOwnerDocument(this, newChildWrapper);
1863 clearChildNodes(this);
1864 originalReplaceChild.call(unsafeUnwrap(this), unwrap(newChildWrapper), o ldChildNode);
1865 }
1866 enqueueMutation(this, "childList", {
1867 addedNodes: nodes,
1868 removedNodes: createOneElementNodeList(oldChildWrapper),
1869 nextSibling: nextNode,
1870 previousSibling: previousNode
1871 });
1872 nodeWasRemoved(oldChildWrapper);
1873 nodesWereAdded(nodes, this);
1874 return oldChildWrapper;
1875 },
1876 nodeIsInserted_: function() {
1877 for (var child = this.firstChild; child; child = child.nextSibling) {
1878 child.nodeIsInserted_();
1879 }
1880 },
1881 hasChildNodes: function() {
1882 return this.firstChild !== null;
1883 },
1884 get parentNode() {
1885 return this.parentNode_ !== undefined ? this.parentNode_ : wrap(unsafeUnwr ap(this).parentNode);
1886 },
1887 get firstChild() {
1888 return this.firstChild_ !== undefined ? this.firstChild_ : wrap(unsafeUnwr ap(this).firstChild);
1889 },
1890 get lastChild() {
1891 return this.lastChild_ !== undefined ? this.lastChild_ : wrap(unsafeUnwrap (this).lastChild);
1892 },
1893 get nextSibling() {
1894 return this.nextSibling_ !== undefined ? this.nextSibling_ : wrap(unsafeUn wrap(this).nextSibling);
1895 },
1896 get previousSibling() {
1897 return this.previousSibling_ !== undefined ? this.previousSibling_ : wrap( unsafeUnwrap(this).previousSibling);
1898 },
1899 get parentElement() {
1900 var p = this.parentNode;
1901 while (p && p.nodeType !== Node.ELEMENT_NODE) {
1902 p = p.parentNode;
1903 }
1904 return p;
1905 },
1906 get textContent() {
1907 var s = "";
1908 for (var child = this.firstChild; child; child = child.nextSibling) {
1909 if (child.nodeType != Node.COMMENT_NODE) {
1910 s += child.textContent;
1911 }
1912 }
1913 return s;
1914 },
1915 set textContent(textContent) {
1916 if (textContent == null) textContent = "";
1917 var removedNodes = snapshotNodeList(this.childNodes);
1918 if (this.invalidateShadowRenderer()) {
1919 removeAllChildNodes(this);
1920 if (textContent !== "") {
1921 var textNode = unsafeUnwrap(this).ownerDocument.createTextNode(textCon tent);
1922 this.appendChild(textNode);
1923 }
1924 } else {
1925 clearChildNodes(this);
1926 unsafeUnwrap(this).textContent = textContent;
1927 }
1928 var addedNodes = snapshotNodeList(this.childNodes);
1929 enqueueMutation(this, "childList", {
1930 addedNodes: addedNodes,
1931 removedNodes: removedNodes
1932 });
1933 nodesWereRemoved(removedNodes);
1934 nodesWereAdded(addedNodes, this);
1935 },
1936 get childNodes() {
1937 var wrapperList = new NodeList();
1938 var i = 0;
1939 for (var child = this.firstChild; child; child = child.nextSibling) {
1940 wrapperList[i++] = child;
1941 }
1942 wrapperList.length = i;
1943 return wrapperList;
1944 },
1945 cloneNode: function(deep) {
1946 return cloneNode(this, deep);
1947 },
1948 contains: function(child) {
1949 return contains(this, wrapIfNeeded(child));
1950 },
1951 compareDocumentPosition: function(otherNode) {
1952 return originalCompareDocumentPosition.call(unsafeUnwrap(this), unwrapIfNe eded(otherNode));
1953 },
1954 normalize: function() {
1955 var nodes = snapshotNodeList(this.childNodes);
1956 var remNodes = [];
1957 var s = "";
1958 var modNode;
1959 for (var i = 0, n; i < nodes.length; i++) {
1960 n = nodes[i];
1961 if (n.nodeType === Node.TEXT_NODE) {
1962 if (!modNode && !n.data.length) this.removeNode(n); else if (!modNode) modNode = n; else {
1963 s += n.data;
1964 remNodes.push(n);
1965 }
1966 } else {
1967 if (modNode && remNodes.length) {
1968 modNode.data += s;
1969 cleanupNodes(remNodes);
1970 }
1971 remNodes = [];
1972 s = "";
1973 modNode = null;
1974 if (n.childNodes.length) n.normalize();
1975 }
1976 }
1977 if (modNode && remNodes.length) {
1978 modNode.data += s;
1979 cleanupNodes(remNodes);
1980 }
1981 }
1982 });
1983 defineWrapGetter(Node, "ownerDocument");
1984 registerWrapper(OriginalNode, Node, document.createDocumentFragment());
1985 delete Node.prototype.querySelector;
1986 delete Node.prototype.querySelectorAll;
1987 Node.prototype = mixin(Object.create(EventTarget.prototype), Node.prototype);
1988 scope.cloneNode = cloneNode;
1989 scope.nodeWasAdded = nodeWasAdded;
1990 scope.nodeWasRemoved = nodeWasRemoved;
1991 scope.nodesWereAdded = nodesWereAdded;
1992 scope.nodesWereRemoved = nodesWereRemoved;
1993 scope.originalInsertBefore = originalInsertBefore;
1994 scope.originalRemoveChild = originalRemoveChild;
1995 scope.snapshotNodeList = snapshotNodeList;
1996 scope.wrappers.Node = Node;
1997 })(window.ShadowDOMPolyfill);
1998
1999 (function(scope) {
2000 "use strict";
2001 var HTMLCollection = scope.wrappers.HTMLCollection;
2002 var NodeList = scope.wrappers.NodeList;
2003 var getTreeScope = scope.getTreeScope;
2004 var unsafeUnwrap = scope.unsafeUnwrap;
2005 var wrap = scope.wrap;
2006 var originalDocumentQuerySelector = document.querySelector;
2007 var originalElementQuerySelector = document.documentElement.querySelector;
2008 var originalDocumentQuerySelectorAll = document.querySelectorAll;
2009 var originalElementQuerySelectorAll = document.documentElement.querySelectorAl l;
2010 var originalDocumentGetElementsByTagName = document.getElementsByTagName;
2011 var originalElementGetElementsByTagName = document.documentElement.getElements ByTagName;
2012 var originalDocumentGetElementsByTagNameNS = document.getElementsByTagNameNS;
2013 var originalElementGetElementsByTagNameNS = document.documentElement.getElemen tsByTagNameNS;
2014 var OriginalElement = window.Element;
2015 var OriginalDocument = window.HTMLDocument || window.Document;
2016 function filterNodeList(list, index, result, deep) {
2017 var wrappedItem = null;
2018 var root = null;
2019 for (var i = 0, length = list.length; i < length; i++) {
2020 wrappedItem = wrap(list[i]);
2021 if (!deep && (root = getTreeScope(wrappedItem).root)) {
2022 if (root instanceof scope.wrappers.ShadowRoot) {
2023 continue;
2024 }
2025 }
2026 result[index++] = wrappedItem;
2027 }
2028 return index;
2029 }
2030 function shimSelector(selector) {
2031 return String(selector).replace(/\/deep\//g, " ");
2032 }
2033 function findOne(node, selector) {
2034 var m, el = node.firstElementChild;
2035 while (el) {
2036 if (el.matches(selector)) return el;
2037 m = findOne(el, selector);
2038 if (m) return m;
2039 el = el.nextElementSibling;
2040 }
2041 return null;
2042 }
2043 function matchesSelector(el, selector) {
2044 return el.matches(selector);
2045 }
2046 var XHTML_NS = "http://www.w3.org/1999/xhtml";
2047 function matchesTagName(el, localName, localNameLowerCase) {
2048 var ln = el.localName;
2049 return ln === localName || ln === localNameLowerCase && el.namespaceURI === XHTML_NS;
2050 }
2051 function matchesEveryThing() {
2052 return true;
2053 }
2054 function matchesLocalNameOnly(el, ns, localName) {
2055 return el.localName === localName;
2056 }
2057 function matchesNameSpace(el, ns) {
2058 return el.namespaceURI === ns;
2059 }
2060 function matchesLocalNameNS(el, ns, localName) {
2061 return el.namespaceURI === ns && el.localName === localName;
2062 }
2063 function findElements(node, index, result, p, arg0, arg1) {
2064 var el = node.firstElementChild;
2065 while (el) {
2066 if (p(el, arg0, arg1)) result[index++] = el;
2067 index = findElements(el, index, result, p, arg0, arg1);
2068 el = el.nextElementSibling;
2069 }
2070 return index;
2071 }
2072 function querySelectorAllFiltered(p, index, result, selector, deep) {
2073 var target = unsafeUnwrap(this);
2074 var list;
2075 var root = getTreeScope(this).root;
2076 if (root instanceof scope.wrappers.ShadowRoot) {
2077 return findElements(this, index, result, p, selector, null);
2078 } else if (target instanceof OriginalElement) {
2079 list = originalElementQuerySelectorAll.call(target, selector);
2080 } else if (target instanceof OriginalDocument) {
2081 list = originalDocumentQuerySelectorAll.call(target, selector);
2082 } else {
2083 return findElements(this, index, result, p, selector, null);
2084 }
2085 return filterNodeList(list, index, result, deep);
2086 }
2087 var SelectorsInterface = {
2088 querySelector: function(selector) {
2089 var shimmed = shimSelector(selector);
2090 var deep = shimmed !== selector;
2091 selector = shimmed;
2092 var target = unsafeUnwrap(this);
2093 var wrappedItem;
2094 var root = getTreeScope(this).root;
2095 if (root instanceof scope.wrappers.ShadowRoot) {
2096 return findOne(this, selector);
2097 } else if (target instanceof OriginalElement) {
2098 wrappedItem = wrap(originalElementQuerySelector.call(target, selector));
2099 } else if (target instanceof OriginalDocument) {
2100 wrappedItem = wrap(originalDocumentQuerySelector.call(target, selector)) ;
2101 } else {
2102 return findOne(this, selector);
2103 }
2104 if (!wrappedItem) {
2105 return wrappedItem;
2106 } else if (!deep && (root = getTreeScope(wrappedItem).root)) {
2107 if (root instanceof scope.wrappers.ShadowRoot) {
2108 return findOne(this, selector);
2109 }
2110 }
2111 return wrappedItem;
2112 },
2113 querySelectorAll: function(selector) {
2114 var shimmed = shimSelector(selector);
2115 var deep = shimmed !== selector;
2116 selector = shimmed;
2117 var result = new NodeList();
2118 result.length = querySelectorAllFiltered.call(this, matchesSelector, 0, re sult, selector, deep);
2119 return result;
2120 }
2121 };
2122 function getElementsByTagNameFiltered(p, index, result, localName, lowercase) {
2123 var target = unsafeUnwrap(this);
2124 var list;
2125 var root = getTreeScope(this).root;
2126 if (root instanceof scope.wrappers.ShadowRoot) {
2127 return findElements(this, index, result, p, localName, lowercase);
2128 } else if (target instanceof OriginalElement) {
2129 list = originalElementGetElementsByTagName.call(target, localName, lowerca se);
2130 } else if (target instanceof OriginalDocument) {
2131 list = originalDocumentGetElementsByTagName.call(target, localName, lowerc ase);
2132 } else {
2133 return findElements(this, index, result, p, localName, lowercase);
2134 }
2135 return filterNodeList(list, index, result, false);
2136 }
2137 function getElementsByTagNameNSFiltered(p, index, result, ns, localName) {
2138 var target = unsafeUnwrap(this);
2139 var list;
2140 var root = getTreeScope(this).root;
2141 if (root instanceof scope.wrappers.ShadowRoot) {
2142 return findElements(this, index, result, p, ns, localName);
2143 } else if (target instanceof OriginalElement) {
2144 list = originalElementGetElementsByTagNameNS.call(target, ns, localName);
2145 } else if (target instanceof OriginalDocument) {
2146 list = originalDocumentGetElementsByTagNameNS.call(target, ns, localName);
2147 } else {
2148 return findElements(this, index, result, p, ns, localName);
2149 }
2150 return filterNodeList(list, index, result, false);
2151 }
2152 var GetElementsByInterface = {
2153 getElementsByTagName: function(localName) {
2154 var result = new HTMLCollection();
2155 var match = localName === "*" ? matchesEveryThing : matchesTagName;
2156 result.length = getElementsByTagNameFiltered.call(this, match, 0, result, localName, localName.toLowerCase());
2157 return result;
2158 },
2159 getElementsByClassName: function(className) {
2160 return this.querySelectorAll("." + className);
2161 },
2162 getElementsByTagNameNS: function(ns, localName) {
2163 var result = new HTMLCollection();
2164 var match = null;
2165 if (ns === "*") {
2166 match = localName === "*" ? matchesEveryThing : matchesLocalNameOnly;
2167 } else {
2168 match = localName === "*" ? matchesNameSpace : matchesLocalNameNS;
2169 }
2170 result.length = getElementsByTagNameNSFiltered.call(this, match, 0, result , ns || null, localName);
2171 return result;
2172 }
2173 };
2174 scope.GetElementsByInterface = GetElementsByInterface;
2175 scope.SelectorsInterface = SelectorsInterface;
2176 })(window.ShadowDOMPolyfill);
2177
2178 (function(scope) {
2179 "use strict";
2180 var NodeList = scope.wrappers.NodeList;
2181 function forwardElement(node) {
2182 while (node && node.nodeType !== Node.ELEMENT_NODE) {
2183 node = node.nextSibling;
2184 }
2185 return node;
2186 }
2187 function backwardsElement(node) {
2188 while (node && node.nodeType !== Node.ELEMENT_NODE) {
2189 node = node.previousSibling;
2190 }
2191 return node;
2192 }
2193 var ParentNodeInterface = {
2194 get firstElementChild() {
2195 return forwardElement(this.firstChild);
2196 },
2197 get lastElementChild() {
2198 return backwardsElement(this.lastChild);
2199 },
2200 get childElementCount() {
2201 var count = 0;
2202 for (var child = this.firstElementChild; child; child = child.nextElementS ibling) {
2203 count++;
2204 }
2205 return count;
2206 },
2207 get children() {
2208 var wrapperList = new NodeList();
2209 var i = 0;
2210 for (var child = this.firstElementChild; child; child = child.nextElementS ibling) {
2211 wrapperList[i++] = child;
2212 }
2213 wrapperList.length = i;
2214 return wrapperList;
2215 },
2216 remove: function() {
2217 var p = this.parentNode;
2218 if (p) p.removeChild(this);
2219 }
2220 };
2221 var ChildNodeInterface = {
2222 get nextElementSibling() {
2223 return forwardElement(this.nextSibling);
2224 },
2225 get previousElementSibling() {
2226 return backwardsElement(this.previousSibling);
2227 }
2228 };
2229 scope.ChildNodeInterface = ChildNodeInterface;
2230 scope.ParentNodeInterface = ParentNodeInterface;
2231 })(window.ShadowDOMPolyfill);
2232
2233 (function(scope) {
2234 "use strict";
2235 var ChildNodeInterface = scope.ChildNodeInterface;
2236 var Node = scope.wrappers.Node;
2237 var enqueueMutation = scope.enqueueMutation;
2238 var mixin = scope.mixin;
2239 var registerWrapper = scope.registerWrapper;
2240 var unsafeUnwrap = scope.unsafeUnwrap;
2241 var OriginalCharacterData = window.CharacterData;
2242 function CharacterData(node) {
2243 Node.call(this, node);
2244 }
2245 CharacterData.prototype = Object.create(Node.prototype);
2246 mixin(CharacterData.prototype, {
2247 get textContent() {
2248 return this.data;
2249 },
2250 set textContent(value) {
2251 this.data = value;
2252 },
2253 get data() {
2254 return unsafeUnwrap(this).data;
2255 },
2256 set data(value) {
2257 var oldValue = unsafeUnwrap(this).data;
2258 enqueueMutation(this, "characterData", {
2259 oldValue: oldValue
2260 });
2261 unsafeUnwrap(this).data = value;
2262 }
2263 });
2264 mixin(CharacterData.prototype, ChildNodeInterface);
2265 registerWrapper(OriginalCharacterData, CharacterData, document.createTextNode( ""));
2266 scope.wrappers.CharacterData = CharacterData;
2267 })(window.ShadowDOMPolyfill);
2268
2269 (function(scope) {
2270 "use strict";
2271 var CharacterData = scope.wrappers.CharacterData;
2272 var enqueueMutation = scope.enqueueMutation;
2273 var mixin = scope.mixin;
2274 var registerWrapper = scope.registerWrapper;
2275 function toUInt32(x) {
2276 return x >>> 0;
2277 }
2278 var OriginalText = window.Text;
2279 function Text(node) {
2280 CharacterData.call(this, node);
2281 }
2282 Text.prototype = Object.create(CharacterData.prototype);
2283 mixin(Text.prototype, {
2284 splitText: function(offset) {
2285 offset = toUInt32(offset);
2286 var s = this.data;
2287 if (offset > s.length) throw new Error("IndexSizeError");
2288 var head = s.slice(0, offset);
2289 var tail = s.slice(offset);
2290 this.data = head;
2291 var newTextNode = this.ownerDocument.createTextNode(tail);
2292 if (this.parentNode) this.parentNode.insertBefore(newTextNode, this.nextSi bling);
2293 return newTextNode;
2294 }
2295 });
2296 registerWrapper(OriginalText, Text, document.createTextNode(""));
2297 scope.wrappers.Text = Text;
2298 })(window.ShadowDOMPolyfill);
2299
2300 (function(scope) {
2301 "use strict";
2302 var setWrapper = scope.setWrapper;
2303 var unsafeUnwrap = scope.unsafeUnwrap;
2304 function invalidateClass(el) {
2305 scope.invalidateRendererBasedOnAttribute(el, "class");
2306 }
2307 function DOMTokenList(impl, ownerElement) {
2308 setWrapper(impl, this);
2309 this.ownerElement_ = ownerElement;
2310 }
2311 DOMTokenList.prototype = {
2312 constructor: DOMTokenList,
2313 get length() {
2314 return unsafeUnwrap(this).length;
2315 },
2316 item: function(index) {
2317 return unsafeUnwrap(this).item(index);
2318 },
2319 contains: function(token) {
2320 return unsafeUnwrap(this).contains(token);
2321 },
2322 add: function() {
2323 unsafeUnwrap(this).add.apply(unsafeUnwrap(this), arguments);
2324 invalidateClass(this.ownerElement_);
2325 },
2326 remove: function() {
2327 unsafeUnwrap(this).remove.apply(unsafeUnwrap(this), arguments);
2328 invalidateClass(this.ownerElement_);
2329 },
2330 toggle: function(token) {
2331 var rv = unsafeUnwrap(this).toggle.apply(unsafeUnwrap(this), arguments);
2332 invalidateClass(this.ownerElement_);
2333 return rv;
2334 },
2335 toString: function() {
2336 return unsafeUnwrap(this).toString();
2337 }
2338 };
2339 scope.wrappers.DOMTokenList = DOMTokenList;
2340 })(window.ShadowDOMPolyfill);
2341
2342 (function(scope) {
2343 "use strict";
2344 var ChildNodeInterface = scope.ChildNodeInterface;
2345 var GetElementsByInterface = scope.GetElementsByInterface;
2346 var Node = scope.wrappers.Node;
2347 var DOMTokenList = scope.wrappers.DOMTokenList;
2348 var ParentNodeInterface = scope.ParentNodeInterface;
2349 var SelectorsInterface = scope.SelectorsInterface;
2350 var addWrapNodeListMethod = scope.addWrapNodeListMethod;
2351 var enqueueMutation = scope.enqueueMutation;
2352 var mixin = scope.mixin;
2353 var oneOf = scope.oneOf;
2354 var registerWrapper = scope.registerWrapper;
2355 var unsafeUnwrap = scope.unsafeUnwrap;
2356 var wrappers = scope.wrappers;
2357 var OriginalElement = window.Element;
2358 var matchesNames = [ "matches", "mozMatchesSelector", "msMatchesSelector", "we bkitMatchesSelector" ].filter(function(name) {
2359 return OriginalElement.prototype[name];
2360 });
2361 var matchesName = matchesNames[0];
2362 var originalMatches = OriginalElement.prototype[matchesName];
2363 function invalidateRendererBasedOnAttribute(element, name) {
2364 var p = element.parentNode;
2365 if (!p || !p.shadowRoot) return;
2366 var renderer = scope.getRendererForHost(p);
2367 if (renderer.dependsOnAttribute(name)) renderer.invalidate();
2368 }
2369 function enqueAttributeChange(element, name, oldValue) {
2370 enqueueMutation(element, "attributes", {
2371 name: name,
2372 namespace: null,
2373 oldValue: oldValue
2374 });
2375 }
2376 var classListTable = new WeakMap();
2377 function Element(node) {
2378 Node.call(this, node);
2379 }
2380 Element.prototype = Object.create(Node.prototype);
2381 mixin(Element.prototype, {
2382 createShadowRoot: function() {
2383 var newShadowRoot = new wrappers.ShadowRoot(this);
2384 unsafeUnwrap(this).polymerShadowRoot_ = newShadowRoot;
2385 var renderer = scope.getRendererForHost(this);
2386 renderer.invalidate();
2387 return newShadowRoot;
2388 },
2389 get shadowRoot() {
2390 return unsafeUnwrap(this).polymerShadowRoot_ || null;
2391 },
2392 setAttribute: function(name, value) {
2393 var oldValue = unsafeUnwrap(this).getAttribute(name);
2394 unsafeUnwrap(this).setAttribute(name, value);
2395 enqueAttributeChange(this, name, oldValue);
2396 invalidateRendererBasedOnAttribute(this, name);
2397 },
2398 removeAttribute: function(name) {
2399 var oldValue = unsafeUnwrap(this).getAttribute(name);
2400 unsafeUnwrap(this).removeAttribute(name);
2401 enqueAttributeChange(this, name, oldValue);
2402 invalidateRendererBasedOnAttribute(this, name);
2403 },
2404 matches: function(selector) {
2405 return originalMatches.call(unsafeUnwrap(this), selector);
2406 },
2407 get classList() {
2408 var list = classListTable.get(this);
2409 if (!list) {
2410 classListTable.set(this, list = new DOMTokenList(unsafeUnwrap(this).clas sList, this));
2411 }
2412 return list;
2413 },
2414 get className() {
2415 return unsafeUnwrap(this).className;
2416 },
2417 set className(v) {
2418 this.setAttribute("class", v);
2419 },
2420 get id() {
2421 return unsafeUnwrap(this).id;
2422 },
2423 set id(v) {
2424 this.setAttribute("id", v);
2425 }
2426 });
2427 matchesNames.forEach(function(name) {
2428 if (name !== "matches") {
2429 Element.prototype[name] = function(selector) {
2430 return this.matches(selector);
2431 };
2432 }
2433 });
2434 if (OriginalElement.prototype.webkitCreateShadowRoot) {
2435 Element.prototype.webkitCreateShadowRoot = Element.prototype.createShadowRoo t;
2436 }
2437 mixin(Element.prototype, ChildNodeInterface);
2438 mixin(Element.prototype, GetElementsByInterface);
2439 mixin(Element.prototype, ParentNodeInterface);
2440 mixin(Element.prototype, SelectorsInterface);
2441 registerWrapper(OriginalElement, Element, document.createElementNS(null, "x")) ;
2442 scope.invalidateRendererBasedOnAttribute = invalidateRendererBasedOnAttribute;
2443 scope.matchesNames = matchesNames;
2444 scope.wrappers.Element = Element;
2445 })(window.ShadowDOMPolyfill);
2446
2447 (function(scope) {
2448 "use strict";
2449 var Element = scope.wrappers.Element;
2450 var defineGetter = scope.defineGetter;
2451 var enqueueMutation = scope.enqueueMutation;
2452 var mixin = scope.mixin;
2453 var nodesWereAdded = scope.nodesWereAdded;
2454 var nodesWereRemoved = scope.nodesWereRemoved;
2455 var registerWrapper = scope.registerWrapper;
2456 var snapshotNodeList = scope.snapshotNodeList;
2457 var unsafeUnwrap = scope.unsafeUnwrap;
2458 var unwrap = scope.unwrap;
2459 var wrap = scope.wrap;
2460 var wrappers = scope.wrappers;
2461 var escapeAttrRegExp = /[&\u00A0"]/g;
2462 var escapeDataRegExp = /[&\u00A0<>]/g;
2463 function escapeReplace(c) {
2464 switch (c) {
2465 case "&":
2466 return "&amp;";
2467
2468 case "<":
2469 return "&lt;";
2470
2471 case ">":
2472 return "&gt;";
2473
2474 case '"':
2475 return "&quot;";
2476
2477 case " ":
2478 return "&nbsp;";
2479 }
2480 }
2481 function escapeAttr(s) {
2482 return s.replace(escapeAttrRegExp, escapeReplace);
2483 }
2484 function escapeData(s) {
2485 return s.replace(escapeDataRegExp, escapeReplace);
2486 }
2487 function makeSet(arr) {
2488 var set = {};
2489 for (var i = 0; i < arr.length; i++) {
2490 set[arr[i]] = true;
2491 }
2492 return set;
2493 }
2494 var voidElements = makeSet([ "area", "base", "br", "col", "command", "embed", "hr", "img", "input", "keygen", "link", "meta", "param", "source", "track", "wbr " ]);
2495 var plaintextParents = makeSet([ "style", "script", "xmp", "iframe", "noembed" , "noframes", "plaintext", "noscript" ]);
2496 function getOuterHTML(node, parentNode) {
2497 switch (node.nodeType) {
2498 case Node.ELEMENT_NODE:
2499 var tagName = node.tagName.toLowerCase();
2500 var s = "<" + tagName;
2501 var attrs = node.attributes;
2502 for (var i = 0, attr; attr = attrs[i]; i++) {
2503 s += " " + attr.name + '="' + escapeAttr(attr.value) + '"';
2504 }
2505 s += ">";
2506 if (voidElements[tagName]) return s;
2507 return s + getInnerHTML(node) + "</" + tagName + ">";
2508
2509 case Node.TEXT_NODE:
2510 var data = node.data;
2511 if (parentNode && plaintextParents[parentNode.localName]) return data;
2512 return escapeData(data);
2513
2514 case Node.COMMENT_NODE:
2515 return "<!--" + node.data + "-->";
2516
2517 default:
2518 console.error(node);
2519 throw new Error("not implemented");
2520 }
2521 }
2522 function getInnerHTML(node) {
2523 if (node instanceof wrappers.HTMLTemplateElement) node = node.content;
2524 var s = "";
2525 for (var child = node.firstChild; child; child = child.nextSibling) {
2526 s += getOuterHTML(child, node);
2527 }
2528 return s;
2529 }
2530 function setInnerHTML(node, value, opt_tagName) {
2531 var tagName = opt_tagName || "div";
2532 node.textContent = "";
2533 var tempElement = unwrap(node.ownerDocument.createElement(tagName));
2534 tempElement.innerHTML = value;
2535 var firstChild;
2536 while (firstChild = tempElement.firstChild) {
2537 node.appendChild(wrap(firstChild));
2538 }
2539 }
2540 var oldIe = /MSIE/.test(navigator.userAgent);
2541 var OriginalHTMLElement = window.HTMLElement;
2542 var OriginalHTMLTemplateElement = window.HTMLTemplateElement;
2543 function HTMLElement(node) {
2544 Element.call(this, node);
2545 }
2546 HTMLElement.prototype = Object.create(Element.prototype);
2547 mixin(HTMLElement.prototype, {
2548 get innerHTML() {
2549 return getInnerHTML(this);
2550 },
2551 set innerHTML(value) {
2552 if (oldIe && plaintextParents[this.localName]) {
2553 this.textContent = value;
2554 return;
2555 }
2556 var removedNodes = snapshotNodeList(this.childNodes);
2557 if (this.invalidateShadowRenderer()) {
2558 if (this instanceof wrappers.HTMLTemplateElement) setInnerHTML(this.cont ent, value); else setInnerHTML(this, value, this.tagName);
2559 } else if (!OriginalHTMLTemplateElement && this instanceof wrappers.HTMLTe mplateElement) {
2560 setInnerHTML(this.content, value);
2561 } else {
2562 unsafeUnwrap(this).innerHTML = value;
2563 }
2564 var addedNodes = snapshotNodeList(this.childNodes);
2565 enqueueMutation(this, "childList", {
2566 addedNodes: addedNodes,
2567 removedNodes: removedNodes
2568 });
2569 nodesWereRemoved(removedNodes);
2570 nodesWereAdded(addedNodes, this);
2571 },
2572 get outerHTML() {
2573 return getOuterHTML(this, this.parentNode);
2574 },
2575 set outerHTML(value) {
2576 var p = this.parentNode;
2577 if (p) {
2578 p.invalidateShadowRenderer();
2579 var df = frag(p, value);
2580 p.replaceChild(df, this);
2581 }
2582 },
2583 insertAdjacentHTML: function(position, text) {
2584 var contextElement, refNode;
2585 switch (String(position).toLowerCase()) {
2586 case "beforebegin":
2587 contextElement = this.parentNode;
2588 refNode = this;
2589 break;
2590
2591 case "afterend":
2592 contextElement = this.parentNode;
2593 refNode = this.nextSibling;
2594 break;
2595
2596 case "afterbegin":
2597 contextElement = this;
2598 refNode = this.firstChild;
2599 break;
2600
2601 case "beforeend":
2602 contextElement = this;
2603 refNode = null;
2604 break;
2605
2606 default:
2607 return;
2608 }
2609 var df = frag(contextElement, text);
2610 contextElement.insertBefore(df, refNode);
2611 },
2612 get hidden() {
2613 return this.hasAttribute("hidden");
2614 },
2615 set hidden(v) {
2616 if (v) {
2617 this.setAttribute("hidden", "");
2618 } else {
2619 this.removeAttribute("hidden");
2620 }
2621 }
2622 });
2623 function frag(contextElement, html) {
2624 var p = unwrap(contextElement.cloneNode(false));
2625 p.innerHTML = html;
2626 var df = unwrap(document.createDocumentFragment());
2627 var c;
2628 while (c = p.firstChild) {
2629 df.appendChild(c);
2630 }
2631 return wrap(df);
2632 }
2633 function getter(name) {
2634 return function() {
2635 scope.renderAllPending();
2636 return unsafeUnwrap(this)[name];
2637 };
2638 }
2639 function getterRequiresRendering(name) {
2640 defineGetter(HTMLElement, name, getter(name));
2641 }
2642 [ "clientHeight", "clientLeft", "clientTop", "clientWidth", "offsetHeight", "o ffsetLeft", "offsetTop", "offsetWidth", "scrollHeight", "scrollWidth" ].forEach( getterRequiresRendering);
2643 function getterAndSetterRequiresRendering(name) {
2644 Object.defineProperty(HTMLElement.prototype, name, {
2645 get: getter(name),
2646 set: function(v) {
2647 scope.renderAllPending();
2648 unsafeUnwrap(this)[name] = v;
2649 },
2650 configurable: true,
2651 enumerable: true
2652 });
2653 }
2654 [ "scrollLeft", "scrollTop" ].forEach(getterAndSetterRequiresRendering);
2655 function methodRequiresRendering(name) {
2656 Object.defineProperty(HTMLElement.prototype, name, {
2657 value: function() {
2658 scope.renderAllPending();
2659 return unsafeUnwrap(this)[name].apply(unsafeUnwrap(this), arguments);
2660 },
2661 configurable: true,
2662 enumerable: true
2663 });
2664 }
2665 [ "getBoundingClientRect", "getClientRects", "scrollIntoView" ].forEach(method RequiresRendering);
2666 registerWrapper(OriginalHTMLElement, HTMLElement, document.createElement("b")) ;
2667 scope.wrappers.HTMLElement = HTMLElement;
2668 scope.getInnerHTML = getInnerHTML;
2669 scope.setInnerHTML = setInnerHTML;
2670 })(window.ShadowDOMPolyfill);
2671
2672 (function(scope) {
2673 "use strict";
2674 var HTMLElement = scope.wrappers.HTMLElement;
2675 var mixin = scope.mixin;
2676 var registerWrapper = scope.registerWrapper;
2677 var unsafeUnwrap = scope.unsafeUnwrap;
2678 var wrap = scope.wrap;
2679 var OriginalHTMLCanvasElement = window.HTMLCanvasElement;
2680 function HTMLCanvasElement(node) {
2681 HTMLElement.call(this, node);
2682 }
2683 HTMLCanvasElement.prototype = Object.create(HTMLElement.prototype);
2684 mixin(HTMLCanvasElement.prototype, {
2685 getContext: function() {
2686 var context = unsafeUnwrap(this).getContext.apply(unsafeUnwrap(this), argu ments);
2687 return context && wrap(context);
2688 }
2689 });
2690 registerWrapper(OriginalHTMLCanvasElement, HTMLCanvasElement, document.createE lement("canvas"));
2691 scope.wrappers.HTMLCanvasElement = HTMLCanvasElement;
2692 })(window.ShadowDOMPolyfill);
2693
2694 (function(scope) {
2695 "use strict";
2696 var HTMLElement = scope.wrappers.HTMLElement;
2697 var mixin = scope.mixin;
2698 var registerWrapper = scope.registerWrapper;
2699 var OriginalHTMLContentElement = window.HTMLContentElement;
2700 function HTMLContentElement(node) {
2701 HTMLElement.call(this, node);
2702 }
2703 HTMLContentElement.prototype = Object.create(HTMLElement.prototype);
2704 mixin(HTMLContentElement.prototype, {
2705 constructor: HTMLContentElement,
2706 get select() {
2707 return this.getAttribute("select");
2708 },
2709 set select(value) {
2710 this.setAttribute("select", value);
2711 },
2712 setAttribute: function(n, v) {
2713 HTMLElement.prototype.setAttribute.call(this, n, v);
2714 if (String(n).toLowerCase() === "select") this.invalidateShadowRenderer(tr ue);
2715 }
2716 });
2717 if (OriginalHTMLContentElement) registerWrapper(OriginalHTMLContentElement, HT MLContentElement);
2718 scope.wrappers.HTMLContentElement = HTMLContentElement;
2719 })(window.ShadowDOMPolyfill);
2720
2721 (function(scope) {
2722 "use strict";
2723 var HTMLElement = scope.wrappers.HTMLElement;
2724 var mixin = scope.mixin;
2725 var registerWrapper = scope.registerWrapper;
2726 var wrapHTMLCollection = scope.wrapHTMLCollection;
2727 var unwrap = scope.unwrap;
2728 var OriginalHTMLFormElement = window.HTMLFormElement;
2729 function HTMLFormElement(node) {
2730 HTMLElement.call(this, node);
2731 }
2732 HTMLFormElement.prototype = Object.create(HTMLElement.prototype);
2733 mixin(HTMLFormElement.prototype, {
2734 get elements() {
2735 return wrapHTMLCollection(unwrap(this).elements);
2736 }
2737 });
2738 registerWrapper(OriginalHTMLFormElement, HTMLFormElement, document.createEleme nt("form"));
2739 scope.wrappers.HTMLFormElement = HTMLFormElement;
2740 })(window.ShadowDOMPolyfill);
2741
2742 (function(scope) {
2743 "use strict";
2744 var HTMLElement = scope.wrappers.HTMLElement;
2745 var registerWrapper = scope.registerWrapper;
2746 var unwrap = scope.unwrap;
2747 var rewrap = scope.rewrap;
2748 var OriginalHTMLImageElement = window.HTMLImageElement;
2749 function HTMLImageElement(node) {
2750 HTMLElement.call(this, node);
2751 }
2752 HTMLImageElement.prototype = Object.create(HTMLElement.prototype);
2753 registerWrapper(OriginalHTMLImageElement, HTMLImageElement, document.createEle ment("img"));
2754 function Image(width, height) {
2755 if (!(this instanceof Image)) {
2756 throw new TypeError("DOM object constructor cannot be called as a function .");
2757 }
2758 var node = unwrap(document.createElement("img"));
2759 HTMLElement.call(this, node);
2760 rewrap(node, this);
2761 if (width !== undefined) node.width = width;
2762 if (height !== undefined) node.height = height;
2763 }
2764 Image.prototype = HTMLImageElement.prototype;
2765 scope.wrappers.HTMLImageElement = HTMLImageElement;
2766 scope.wrappers.Image = Image;
2767 })(window.ShadowDOMPolyfill);
2768
2769 (function(scope) {
2770 "use strict";
2771 var HTMLElement = scope.wrappers.HTMLElement;
2772 var mixin = scope.mixin;
2773 var NodeList = scope.wrappers.NodeList;
2774 var registerWrapper = scope.registerWrapper;
2775 var OriginalHTMLShadowElement = window.HTMLShadowElement;
2776 function HTMLShadowElement(node) {
2777 HTMLElement.call(this, node);
2778 }
2779 HTMLShadowElement.prototype = Object.create(HTMLElement.prototype);
2780 HTMLShadowElement.prototype.constructor = HTMLShadowElement;
2781 if (OriginalHTMLShadowElement) registerWrapper(OriginalHTMLShadowElement, HTML ShadowElement);
2782 scope.wrappers.HTMLShadowElement = HTMLShadowElement;
2783 })(window.ShadowDOMPolyfill);
2784
2785 (function(scope) {
2786 "use strict";
2787 var HTMLElement = scope.wrappers.HTMLElement;
2788 var mixin = scope.mixin;
2789 var registerWrapper = scope.registerWrapper;
2790 var unsafeUnwrap = scope.unsafeUnwrap;
2791 var unwrap = scope.unwrap;
2792 var wrap = scope.wrap;
2793 var contentTable = new WeakMap();
2794 var templateContentsOwnerTable = new WeakMap();
2795 function getTemplateContentsOwner(doc) {
2796 if (!doc.defaultView) return doc;
2797 var d = templateContentsOwnerTable.get(doc);
2798 if (!d) {
2799 d = doc.implementation.createHTMLDocument("");
2800 while (d.lastChild) {
2801 d.removeChild(d.lastChild);
2802 }
2803 templateContentsOwnerTable.set(doc, d);
2804 }
2805 return d;
2806 }
2807 function extractContent(templateElement) {
2808 var doc = getTemplateContentsOwner(templateElement.ownerDocument);
2809 var df = unwrap(doc.createDocumentFragment());
2810 var child;
2811 while (child = templateElement.firstChild) {
2812 df.appendChild(child);
2813 }
2814 return df;
2815 }
2816 var OriginalHTMLTemplateElement = window.HTMLTemplateElement;
2817 function HTMLTemplateElement(node) {
2818 HTMLElement.call(this, node);
2819 if (!OriginalHTMLTemplateElement) {
2820 var content = extractContent(node);
2821 contentTable.set(this, wrap(content));
2822 }
2823 }
2824 HTMLTemplateElement.prototype = Object.create(HTMLElement.prototype);
2825 mixin(HTMLTemplateElement.prototype, {
2826 constructor: HTMLTemplateElement,
2827 get content() {
2828 if (OriginalHTMLTemplateElement) return wrap(unsafeUnwrap(this).content);
2829 return contentTable.get(this);
2830 }
2831 });
2832 if (OriginalHTMLTemplateElement) registerWrapper(OriginalHTMLTemplateElement, HTMLTemplateElement);
2833 scope.wrappers.HTMLTemplateElement = HTMLTemplateElement;
2834 })(window.ShadowDOMPolyfill);
2835
2836 (function(scope) {
2837 "use strict";
2838 var HTMLElement = scope.wrappers.HTMLElement;
2839 var registerWrapper = scope.registerWrapper;
2840 var OriginalHTMLMediaElement = window.HTMLMediaElement;
2841 if (!OriginalHTMLMediaElement) return;
2842 function HTMLMediaElement(node) {
2843 HTMLElement.call(this, node);
2844 }
2845 HTMLMediaElement.prototype = Object.create(HTMLElement.prototype);
2846 registerWrapper(OriginalHTMLMediaElement, HTMLMediaElement, document.createEle ment("audio"));
2847 scope.wrappers.HTMLMediaElement = HTMLMediaElement;
2848 })(window.ShadowDOMPolyfill);
2849
2850 (function(scope) {
2851 "use strict";
2852 var HTMLMediaElement = scope.wrappers.HTMLMediaElement;
2853 var registerWrapper = scope.registerWrapper;
2854 var unwrap = scope.unwrap;
2855 var rewrap = scope.rewrap;
2856 var OriginalHTMLAudioElement = window.HTMLAudioElement;
2857 if (!OriginalHTMLAudioElement) return;
2858 function HTMLAudioElement(node) {
2859 HTMLMediaElement.call(this, node);
2860 }
2861 HTMLAudioElement.prototype = Object.create(HTMLMediaElement.prototype);
2862 registerWrapper(OriginalHTMLAudioElement, HTMLAudioElement, document.createEle ment("audio"));
2863 function Audio(src) {
2864 if (!(this instanceof Audio)) {
2865 throw new TypeError("DOM object constructor cannot be called as a function .");
2866 }
2867 var node = unwrap(document.createElement("audio"));
2868 HTMLMediaElement.call(this, node);
2869 rewrap(node, this);
2870 node.setAttribute("preload", "auto");
2871 if (src !== undefined) node.setAttribute("src", src);
2872 }
2873 Audio.prototype = HTMLAudioElement.prototype;
2874 scope.wrappers.HTMLAudioElement = HTMLAudioElement;
2875 scope.wrappers.Audio = Audio;
2876 })(window.ShadowDOMPolyfill);
2877
2878 (function(scope) {
2879 "use strict";
2880 var HTMLElement = scope.wrappers.HTMLElement;
2881 var mixin = scope.mixin;
2882 var registerWrapper = scope.registerWrapper;
2883 var rewrap = scope.rewrap;
2884 var unwrap = scope.unwrap;
2885 var wrap = scope.wrap;
2886 var OriginalHTMLOptionElement = window.HTMLOptionElement;
2887 function trimText(s) {
2888 return s.replace(/\s+/g, " ").trim();
2889 }
2890 function HTMLOptionElement(node) {
2891 HTMLElement.call(this, node);
2892 }
2893 HTMLOptionElement.prototype = Object.create(HTMLElement.prototype);
2894 mixin(HTMLOptionElement.prototype, {
2895 get text() {
2896 return trimText(this.textContent);
2897 },
2898 set text(value) {
2899 this.textContent = trimText(String(value));
2900 },
2901 get form() {
2902 return wrap(unwrap(this).form);
2903 }
2904 });
2905 registerWrapper(OriginalHTMLOptionElement, HTMLOptionElement, document.createE lement("option"));
2906 function Option(text, value, defaultSelected, selected) {
2907 if (!(this instanceof Option)) {
2908 throw new TypeError("DOM object constructor cannot be called as a function .");
2909 }
2910 var node = unwrap(document.createElement("option"));
2911 HTMLElement.call(this, node);
2912 rewrap(node, this);
2913 if (text !== undefined) node.text = text;
2914 if (value !== undefined) node.setAttribute("value", value);
2915 if (defaultSelected === true) node.setAttribute("selected", "");
2916 node.selected = selected === true;
2917 }
2918 Option.prototype = HTMLOptionElement.prototype;
2919 scope.wrappers.HTMLOptionElement = HTMLOptionElement;
2920 scope.wrappers.Option = Option;
2921 })(window.ShadowDOMPolyfill);
2922
2923 (function(scope) {
2924 "use strict";
2925 var HTMLElement = scope.wrappers.HTMLElement;
2926 var mixin = scope.mixin;
2927 var registerWrapper = scope.registerWrapper;
2928 var unwrap = scope.unwrap;
2929 var wrap = scope.wrap;
2930 var OriginalHTMLSelectElement = window.HTMLSelectElement;
2931 function HTMLSelectElement(node) {
2932 HTMLElement.call(this, node);
2933 }
2934 HTMLSelectElement.prototype = Object.create(HTMLElement.prototype);
2935 mixin(HTMLSelectElement.prototype, {
2936 add: function(element, before) {
2937 if (typeof before === "object") before = unwrap(before);
2938 unwrap(this).add(unwrap(element), before);
2939 },
2940 remove: function(indexOrNode) {
2941 if (indexOrNode === undefined) {
2942 HTMLElement.prototype.remove.call(this);
2943 return;
2944 }
2945 if (typeof indexOrNode === "object") indexOrNode = unwrap(indexOrNode);
2946 unwrap(this).remove(indexOrNode);
2947 },
2948 get form() {
2949 return wrap(unwrap(this).form);
2950 }
2951 });
2952 registerWrapper(OriginalHTMLSelectElement, HTMLSelectElement, document.createE lement("select"));
2953 scope.wrappers.HTMLSelectElement = HTMLSelectElement;
2954 })(window.ShadowDOMPolyfill);
2955
2956 (function(scope) {
2957 "use strict";
2958 var HTMLElement = scope.wrappers.HTMLElement;
2959 var mixin = scope.mixin;
2960 var registerWrapper = scope.registerWrapper;
2961 var unwrap = scope.unwrap;
2962 var wrap = scope.wrap;
2963 var wrapHTMLCollection = scope.wrapHTMLCollection;
2964 var OriginalHTMLTableElement = window.HTMLTableElement;
2965 function HTMLTableElement(node) {
2966 HTMLElement.call(this, node);
2967 }
2968 HTMLTableElement.prototype = Object.create(HTMLElement.prototype);
2969 mixin(HTMLTableElement.prototype, {
2970 get caption() {
2971 return wrap(unwrap(this).caption);
2972 },
2973 createCaption: function() {
2974 return wrap(unwrap(this).createCaption());
2975 },
2976 get tHead() {
2977 return wrap(unwrap(this).tHead);
2978 },
2979 createTHead: function() {
2980 return wrap(unwrap(this).createTHead());
2981 },
2982 createTFoot: function() {
2983 return wrap(unwrap(this).createTFoot());
2984 },
2985 get tFoot() {
2986 return wrap(unwrap(this).tFoot);
2987 },
2988 get tBodies() {
2989 return wrapHTMLCollection(unwrap(this).tBodies);
2990 },
2991 createTBody: function() {
2992 return wrap(unwrap(this).createTBody());
2993 },
2994 get rows() {
2995 return wrapHTMLCollection(unwrap(this).rows);
2996 },
2997 insertRow: function(index) {
2998 return wrap(unwrap(this).insertRow(index));
2999 }
3000 });
3001 registerWrapper(OriginalHTMLTableElement, HTMLTableElement, document.createEle ment("table"));
3002 scope.wrappers.HTMLTableElement = HTMLTableElement;
3003 })(window.ShadowDOMPolyfill);
3004
3005 (function(scope) {
3006 "use strict";
3007 var HTMLElement = scope.wrappers.HTMLElement;
3008 var mixin = scope.mixin;
3009 var registerWrapper = scope.registerWrapper;
3010 var wrapHTMLCollection = scope.wrapHTMLCollection;
3011 var unwrap = scope.unwrap;
3012 var wrap = scope.wrap;
3013 var OriginalHTMLTableSectionElement = window.HTMLTableSectionElement;
3014 function HTMLTableSectionElement(node) {
3015 HTMLElement.call(this, node);
3016 }
3017 HTMLTableSectionElement.prototype = Object.create(HTMLElement.prototype);
3018 mixin(HTMLTableSectionElement.prototype, {
3019 constructor: HTMLTableSectionElement,
3020 get rows() {
3021 return wrapHTMLCollection(unwrap(this).rows);
3022 },
3023 insertRow: function(index) {
3024 return wrap(unwrap(this).insertRow(index));
3025 }
3026 });
3027 registerWrapper(OriginalHTMLTableSectionElement, HTMLTableSectionElement, docu ment.createElement("thead"));
3028 scope.wrappers.HTMLTableSectionElement = HTMLTableSectionElement;
3029 })(window.ShadowDOMPolyfill);
3030
3031 (function(scope) {
3032 "use strict";
3033 var HTMLElement = scope.wrappers.HTMLElement;
3034 var mixin = scope.mixin;
3035 var registerWrapper = scope.registerWrapper;
3036 var wrapHTMLCollection = scope.wrapHTMLCollection;
3037 var unwrap = scope.unwrap;
3038 var wrap = scope.wrap;
3039 var OriginalHTMLTableRowElement = window.HTMLTableRowElement;
3040 function HTMLTableRowElement(node) {
3041 HTMLElement.call(this, node);
3042 }
3043 HTMLTableRowElement.prototype = Object.create(HTMLElement.prototype);
3044 mixin(HTMLTableRowElement.prototype, {
3045 get cells() {
3046 return wrapHTMLCollection(unwrap(this).cells);
3047 },
3048 insertCell: function(index) {
3049 return wrap(unwrap(this).insertCell(index));
3050 }
3051 });
3052 registerWrapper(OriginalHTMLTableRowElement, HTMLTableRowElement, document.cre ateElement("tr"));
3053 scope.wrappers.HTMLTableRowElement = HTMLTableRowElement;
3054 })(window.ShadowDOMPolyfill);
3055
3056 (function(scope) {
3057 "use strict";
3058 var HTMLContentElement = scope.wrappers.HTMLContentElement;
3059 var HTMLElement = scope.wrappers.HTMLElement;
3060 var HTMLShadowElement = scope.wrappers.HTMLShadowElement;
3061 var HTMLTemplateElement = scope.wrappers.HTMLTemplateElement;
3062 var mixin = scope.mixin;
3063 var registerWrapper = scope.registerWrapper;
3064 var OriginalHTMLUnknownElement = window.HTMLUnknownElement;
3065 function HTMLUnknownElement(node) {
3066 switch (node.localName) {
3067 case "content":
3068 return new HTMLContentElement(node);
3069
3070 case "shadow":
3071 return new HTMLShadowElement(node);
3072
3073 case "template":
3074 return new HTMLTemplateElement(node);
3075 }
3076 HTMLElement.call(this, node);
3077 }
3078 HTMLUnknownElement.prototype = Object.create(HTMLElement.prototype);
3079 registerWrapper(OriginalHTMLUnknownElement, HTMLUnknownElement);
3080 scope.wrappers.HTMLUnknownElement = HTMLUnknownElement;
3081 })(window.ShadowDOMPolyfill);
3082
3083 (function(scope) {
3084 "use strict";
3085 var Element = scope.wrappers.Element;
3086 var HTMLElement = scope.wrappers.HTMLElement;
3087 var registerObject = scope.registerObject;
3088 var SVG_NS = "http://www.w3.org/2000/svg";
3089 var svgTitleElement = document.createElementNS(SVG_NS, "title");
3090 var SVGTitleElement = registerObject(svgTitleElement);
3091 var SVGElement = Object.getPrototypeOf(SVGTitleElement.prototype).constructor;
3092 if (!("classList" in svgTitleElement)) {
3093 var descr = Object.getOwnPropertyDescriptor(Element.prototype, "classList");
3094 Object.defineProperty(HTMLElement.prototype, "classList", descr);
3095 delete Element.prototype.classList;
3096 }
3097 scope.wrappers.SVGElement = SVGElement;
3098 })(window.ShadowDOMPolyfill);
3099
3100 (function(scope) {
3101 "use strict";
3102 var mixin = scope.mixin;
3103 var registerWrapper = scope.registerWrapper;
3104 var unwrap = scope.unwrap;
3105 var wrap = scope.wrap;
3106 var OriginalSVGUseElement = window.SVGUseElement;
3107 var SVG_NS = "http://www.w3.org/2000/svg";
3108 var gWrapper = wrap(document.createElementNS(SVG_NS, "g"));
3109 var useElement = document.createElementNS(SVG_NS, "use");
3110 var SVGGElement = gWrapper.constructor;
3111 var parentInterfacePrototype = Object.getPrototypeOf(SVGGElement.prototype);
3112 var parentInterface = parentInterfacePrototype.constructor;
3113 function SVGUseElement(impl) {
3114 parentInterface.call(this, impl);
3115 }
3116 SVGUseElement.prototype = Object.create(parentInterfacePrototype);
3117 if ("instanceRoot" in useElement) {
3118 mixin(SVGUseElement.prototype, {
3119 get instanceRoot() {
3120 return wrap(unwrap(this).instanceRoot);
3121 },
3122 get animatedInstanceRoot() {
3123 return wrap(unwrap(this).animatedInstanceRoot);
3124 }
3125 });
3126 }
3127 registerWrapper(OriginalSVGUseElement, SVGUseElement, useElement);
3128 scope.wrappers.SVGUseElement = SVGUseElement;
3129 })(window.ShadowDOMPolyfill);
3130
3131 (function(scope) {
3132 "use strict";
3133 var EventTarget = scope.wrappers.EventTarget;
3134 var mixin = scope.mixin;
3135 var registerWrapper = scope.registerWrapper;
3136 var unsafeUnwrap = scope.unsafeUnwrap;
3137 var wrap = scope.wrap;
3138 var OriginalSVGElementInstance = window.SVGElementInstance;
3139 if (!OriginalSVGElementInstance) return;
3140 function SVGElementInstance(impl) {
3141 EventTarget.call(this, impl);
3142 }
3143 SVGElementInstance.prototype = Object.create(EventTarget.prototype);
3144 mixin(SVGElementInstance.prototype, {
3145 get correspondingElement() {
3146 return wrap(unsafeUnwrap(this).correspondingElement);
3147 },
3148 get correspondingUseElement() {
3149 return wrap(unsafeUnwrap(this).correspondingUseElement);
3150 },
3151 get parentNode() {
3152 return wrap(unsafeUnwrap(this).parentNode);
3153 },
3154 get childNodes() {
3155 throw new Error("Not implemented");
3156 },
3157 get firstChild() {
3158 return wrap(unsafeUnwrap(this).firstChild);
3159 },
3160 get lastChild() {
3161 return wrap(unsafeUnwrap(this).lastChild);
3162 },
3163 get previousSibling() {
3164 return wrap(unsafeUnwrap(this).previousSibling);
3165 },
3166 get nextSibling() {
3167 return wrap(unsafeUnwrap(this).nextSibling);
3168 }
3169 });
3170 registerWrapper(OriginalSVGElementInstance, SVGElementInstance);
3171 scope.wrappers.SVGElementInstance = SVGElementInstance;
3172 })(window.ShadowDOMPolyfill);
3173
3174 (function(scope) {
3175 "use strict";
3176 var mixin = scope.mixin;
3177 var registerWrapper = scope.registerWrapper;
3178 var setWrapper = scope.setWrapper;
3179 var unsafeUnwrap = scope.unsafeUnwrap;
3180 var unwrap = scope.unwrap;
3181 var unwrapIfNeeded = scope.unwrapIfNeeded;
3182 var wrap = scope.wrap;
3183 var OriginalCanvasRenderingContext2D = window.CanvasRenderingContext2D;
3184 function CanvasRenderingContext2D(impl) {
3185 setWrapper(impl, this);
3186 }
3187 mixin(CanvasRenderingContext2D.prototype, {
3188 get canvas() {
3189 return wrap(unsafeUnwrap(this).canvas);
3190 },
3191 drawImage: function() {
3192 arguments[0] = unwrapIfNeeded(arguments[0]);
3193 unsafeUnwrap(this).drawImage.apply(unsafeUnwrap(this), arguments);
3194 },
3195 createPattern: function() {
3196 arguments[0] = unwrap(arguments[0]);
3197 return unsafeUnwrap(this).createPattern.apply(unsafeUnwrap(this), argument s);
3198 }
3199 });
3200 registerWrapper(OriginalCanvasRenderingContext2D, CanvasRenderingContext2D, do cument.createElement("canvas").getContext("2d"));
3201 scope.wrappers.CanvasRenderingContext2D = CanvasRenderingContext2D;
3202 })(window.ShadowDOMPolyfill);
3203
3204 (function(scope) {
3205 "use strict";
3206 var mixin = scope.mixin;
3207 var registerWrapper = scope.registerWrapper;
3208 var setWrapper = scope.setWrapper;
3209 var unsafeUnwrap = scope.unsafeUnwrap;
3210 var unwrapIfNeeded = scope.unwrapIfNeeded;
3211 var wrap = scope.wrap;
3212 var OriginalWebGLRenderingContext = window.WebGLRenderingContext;
3213 if (!OriginalWebGLRenderingContext) return;
3214 function WebGLRenderingContext(impl) {
3215 setWrapper(impl, this);
3216 }
3217 mixin(WebGLRenderingContext.prototype, {
3218 get canvas() {
3219 return wrap(unsafeUnwrap(this).canvas);
3220 },
3221 texImage2D: function() {
3222 arguments[5] = unwrapIfNeeded(arguments[5]);
3223 unsafeUnwrap(this).texImage2D.apply(unsafeUnwrap(this), arguments);
3224 },
3225 texSubImage2D: function() {
3226 arguments[6] = unwrapIfNeeded(arguments[6]);
3227 unsafeUnwrap(this).texSubImage2D.apply(unsafeUnwrap(this), arguments);
3228 }
3229 });
3230 var instanceProperties = /WebKit/.test(navigator.userAgent) ? {
3231 drawingBufferHeight: null,
3232 drawingBufferWidth: null
3233 } : {};
3234 registerWrapper(OriginalWebGLRenderingContext, WebGLRenderingContext, instance Properties);
3235 scope.wrappers.WebGLRenderingContext = WebGLRenderingContext;
3236 })(window.ShadowDOMPolyfill);
3237
3238 (function(scope) {
3239 "use strict";
3240 var registerWrapper = scope.registerWrapper;
3241 var setWrapper = scope.setWrapper;
3242 var unsafeUnwrap = scope.unsafeUnwrap;
3243 var unwrap = scope.unwrap;
3244 var unwrapIfNeeded = scope.unwrapIfNeeded;
3245 var wrap = scope.wrap;
3246 var OriginalRange = window.Range;
3247 function Range(impl) {
3248 setWrapper(impl, this);
3249 }
3250 Range.prototype = {
3251 get startContainer() {
3252 return wrap(unsafeUnwrap(this).startContainer);
3253 },
3254 get endContainer() {
3255 return wrap(unsafeUnwrap(this).endContainer);
3256 },
3257 get commonAncestorContainer() {
3258 return wrap(unsafeUnwrap(this).commonAncestorContainer);
3259 },
3260 setStart: function(refNode, offset) {
3261 unsafeUnwrap(this).setStart(unwrapIfNeeded(refNode), offset);
3262 },
3263 setEnd: function(refNode, offset) {
3264 unsafeUnwrap(this).setEnd(unwrapIfNeeded(refNode), offset);
3265 },
3266 setStartBefore: function(refNode) {
3267 unsafeUnwrap(this).setStartBefore(unwrapIfNeeded(refNode));
3268 },
3269 setStartAfter: function(refNode) {
3270 unsafeUnwrap(this).setStartAfter(unwrapIfNeeded(refNode));
3271 },
3272 setEndBefore: function(refNode) {
3273 unsafeUnwrap(this).setEndBefore(unwrapIfNeeded(refNode));
3274 },
3275 setEndAfter: function(refNode) {
3276 unsafeUnwrap(this).setEndAfter(unwrapIfNeeded(refNode));
3277 },
3278 selectNode: function(refNode) {
3279 unsafeUnwrap(this).selectNode(unwrapIfNeeded(refNode));
3280 },
3281 selectNodeContents: function(refNode) {
3282 unsafeUnwrap(this).selectNodeContents(unwrapIfNeeded(refNode));
3283 },
3284 compareBoundaryPoints: function(how, sourceRange) {
3285 return unsafeUnwrap(this).compareBoundaryPoints(how, unwrap(sourceRange));
3286 },
3287 extractContents: function() {
3288 return wrap(unsafeUnwrap(this).extractContents());
3289 },
3290 cloneContents: function() {
3291 return wrap(unsafeUnwrap(this).cloneContents());
3292 },
3293 insertNode: function(node) {
3294 unsafeUnwrap(this).insertNode(unwrapIfNeeded(node));
3295 },
3296 surroundContents: function(newParent) {
3297 unsafeUnwrap(this).surroundContents(unwrapIfNeeded(newParent));
3298 },
3299 cloneRange: function() {
3300 return wrap(unsafeUnwrap(this).cloneRange());
3301 },
3302 isPointInRange: function(node, offset) {
3303 return unsafeUnwrap(this).isPointInRange(unwrapIfNeeded(node), offset);
3304 },
3305 comparePoint: function(node, offset) {
3306 return unsafeUnwrap(this).comparePoint(unwrapIfNeeded(node), offset);
3307 },
3308 intersectsNode: function(node) {
3309 return unsafeUnwrap(this).intersectsNode(unwrapIfNeeded(node));
3310 },
3311 toString: function() {
3312 return unsafeUnwrap(this).toString();
3313 }
3314 };
3315 if (OriginalRange.prototype.createContextualFragment) {
3316 Range.prototype.createContextualFragment = function(html) {
3317 return wrap(unsafeUnwrap(this).createContextualFragment(html));
3318 };
3319 }
3320 registerWrapper(window.Range, Range, document.createRange());
3321 scope.wrappers.Range = Range;
3322 })(window.ShadowDOMPolyfill);
3323
3324 (function(scope) {
3325 "use strict";
3326 var GetElementsByInterface = scope.GetElementsByInterface;
3327 var ParentNodeInterface = scope.ParentNodeInterface;
3328 var SelectorsInterface = scope.SelectorsInterface;
3329 var mixin = scope.mixin;
3330 var registerObject = scope.registerObject;
3331 var DocumentFragment = registerObject(document.createDocumentFragment());
3332 mixin(DocumentFragment.prototype, ParentNodeInterface);
3333 mixin(DocumentFragment.prototype, SelectorsInterface);
3334 mixin(DocumentFragment.prototype, GetElementsByInterface);
3335 var Comment = registerObject(document.createComment(""));
3336 scope.wrappers.Comment = Comment;
3337 scope.wrappers.DocumentFragment = DocumentFragment;
3338 })(window.ShadowDOMPolyfill);
3339
3340 (function(scope) {
3341 "use strict";
3342 var DocumentFragment = scope.wrappers.DocumentFragment;
3343 var TreeScope = scope.TreeScope;
3344 var elementFromPoint = scope.elementFromPoint;
3345 var getInnerHTML = scope.getInnerHTML;
3346 var getTreeScope = scope.getTreeScope;
3347 var mixin = scope.mixin;
3348 var rewrap = scope.rewrap;
3349 var setInnerHTML = scope.setInnerHTML;
3350 var unsafeUnwrap = scope.unsafeUnwrap;
3351 var unwrap = scope.unwrap;
3352 var shadowHostTable = new WeakMap();
3353 var nextOlderShadowTreeTable = new WeakMap();
3354 var spaceCharRe = /[ \t\n\r\f]/;
3355 function ShadowRoot(hostWrapper) {
3356 var node = unwrap(unsafeUnwrap(hostWrapper).ownerDocument.createDocumentFrag ment());
3357 DocumentFragment.call(this, node);
3358 rewrap(node, this);
3359 var oldShadowRoot = hostWrapper.shadowRoot;
3360 nextOlderShadowTreeTable.set(this, oldShadowRoot);
3361 this.treeScope_ = new TreeScope(this, getTreeScope(oldShadowRoot || hostWrap per));
3362 shadowHostTable.set(this, hostWrapper);
3363 }
3364 ShadowRoot.prototype = Object.create(DocumentFragment.prototype);
3365 mixin(ShadowRoot.prototype, {
3366 constructor: ShadowRoot,
3367 get innerHTML() {
3368 return getInnerHTML(this);
3369 },
3370 set innerHTML(value) {
3371 setInnerHTML(this, value);
3372 this.invalidateShadowRenderer();
3373 },
3374 get olderShadowRoot() {
3375 return nextOlderShadowTreeTable.get(this) || null;
3376 },
3377 get host() {
3378 return shadowHostTable.get(this) || null;
3379 },
3380 invalidateShadowRenderer: function() {
3381 return shadowHostTable.get(this).invalidateShadowRenderer();
3382 },
3383 elementFromPoint: function(x, y) {
3384 return elementFromPoint(this, this.ownerDocument, x, y);
3385 },
3386 getElementById: function(id) {
3387 if (spaceCharRe.test(id)) return null;
3388 return this.querySelector('[id="' + id + '"]');
3389 }
3390 });
3391 scope.wrappers.ShadowRoot = ShadowRoot;
3392 })(window.ShadowDOMPolyfill);
3393
3394 (function(scope) {
3395 "use strict";
3396 var Element = scope.wrappers.Element;
3397 var HTMLContentElement = scope.wrappers.HTMLContentElement;
3398 var HTMLShadowElement = scope.wrappers.HTMLShadowElement;
3399 var Node = scope.wrappers.Node;
3400 var ShadowRoot = scope.wrappers.ShadowRoot;
3401 var assert = scope.assert;
3402 var getTreeScope = scope.getTreeScope;
3403 var mixin = scope.mixin;
3404 var oneOf = scope.oneOf;
3405 var unsafeUnwrap = scope.unsafeUnwrap;
3406 var unwrap = scope.unwrap;
3407 var wrap = scope.wrap;
3408 var ArraySplice = scope.ArraySplice;
3409 function updateWrapperUpAndSideways(wrapper) {
3410 wrapper.previousSibling_ = wrapper.previousSibling;
3411 wrapper.nextSibling_ = wrapper.nextSibling;
3412 wrapper.parentNode_ = wrapper.parentNode;
3413 }
3414 function updateWrapperDown(wrapper) {
3415 wrapper.firstChild_ = wrapper.firstChild;
3416 wrapper.lastChild_ = wrapper.lastChild;
3417 }
3418 function updateAllChildNodes(parentNodeWrapper) {
3419 assert(parentNodeWrapper instanceof Node);
3420 for (var childWrapper = parentNodeWrapper.firstChild; childWrapper; childWra pper = childWrapper.nextSibling) {
3421 updateWrapperUpAndSideways(childWrapper);
3422 }
3423 updateWrapperDown(parentNodeWrapper);
3424 }
3425 function insertBefore(parentNodeWrapper, newChildWrapper, refChildWrapper) {
3426 var parentNode = unwrap(parentNodeWrapper);
3427 var newChild = unwrap(newChildWrapper);
3428 var refChild = refChildWrapper ? unwrap(refChildWrapper) : null;
3429 remove(newChildWrapper);
3430 updateWrapperUpAndSideways(newChildWrapper);
3431 if (!refChildWrapper) {
3432 parentNodeWrapper.lastChild_ = parentNodeWrapper.lastChild;
3433 if (parentNodeWrapper.lastChild === parentNodeWrapper.firstChild) parentNo deWrapper.firstChild_ = parentNodeWrapper.firstChild;
3434 var lastChildWrapper = wrap(parentNode.lastChild);
3435 if (lastChildWrapper) lastChildWrapper.nextSibling_ = lastChildWrapper.nex tSibling;
3436 } else {
3437 if (parentNodeWrapper.firstChild === refChildWrapper) parentNodeWrapper.fi rstChild_ = refChildWrapper;
3438 refChildWrapper.previousSibling_ = refChildWrapper.previousSibling;
3439 }
3440 scope.originalInsertBefore.call(parentNode, newChild, refChild);
3441 }
3442 function remove(nodeWrapper) {
3443 var node = unwrap(nodeWrapper);
3444 var parentNode = node.parentNode;
3445 if (!parentNode) return;
3446 var parentNodeWrapper = wrap(parentNode);
3447 updateWrapperUpAndSideways(nodeWrapper);
3448 if (nodeWrapper.previousSibling) nodeWrapper.previousSibling.nextSibling_ = nodeWrapper;
3449 if (nodeWrapper.nextSibling) nodeWrapper.nextSibling.previousSibling_ = node Wrapper;
3450 if (parentNodeWrapper.lastChild === nodeWrapper) parentNodeWrapper.lastChild _ = nodeWrapper;
3451 if (parentNodeWrapper.firstChild === nodeWrapper) parentNodeWrapper.firstChi ld_ = nodeWrapper;
3452 scope.originalRemoveChild.call(parentNode, node);
3453 }
3454 var distributedNodesTable = new WeakMap();
3455 var destinationInsertionPointsTable = new WeakMap();
3456 var rendererForHostTable = new WeakMap();
3457 function resetDistributedNodes(insertionPoint) {
3458 distributedNodesTable.set(insertionPoint, []);
3459 }
3460 function getDistributedNodes(insertionPoint) {
3461 var rv = distributedNodesTable.get(insertionPoint);
3462 if (!rv) distributedNodesTable.set(insertionPoint, rv = []);
3463 return rv;
3464 }
3465 function getChildNodesSnapshot(node) {
3466 var result = [], i = 0;
3467 for (var child = node.firstChild; child; child = child.nextSibling) {
3468 result[i++] = child;
3469 }
3470 return result;
3471 }
3472 var request = oneOf(window, [ "requestAnimationFrame", "mozRequestAnimationFra me", "webkitRequestAnimationFrame", "setTimeout" ]);
3473 var pendingDirtyRenderers = [];
3474 var renderTimer;
3475 function renderAllPending() {
3476 for (var i = 0; i < pendingDirtyRenderers.length; i++) {
3477 var renderer = pendingDirtyRenderers[i];
3478 var parentRenderer = renderer.parentRenderer;
3479 if (parentRenderer && parentRenderer.dirty) continue;
3480 renderer.render();
3481 }
3482 pendingDirtyRenderers = [];
3483 }
3484 function handleRequestAnimationFrame() {
3485 renderTimer = null;
3486 renderAllPending();
3487 }
3488 function getRendererForHost(host) {
3489 var renderer = rendererForHostTable.get(host);
3490 if (!renderer) {
3491 renderer = new ShadowRenderer(host);
3492 rendererForHostTable.set(host, renderer);
3493 }
3494 return renderer;
3495 }
3496 function getShadowRootAncestor(node) {
3497 var root = getTreeScope(node).root;
3498 if (root instanceof ShadowRoot) return root;
3499 return null;
3500 }
3501 function getRendererForShadowRoot(shadowRoot) {
3502 return getRendererForHost(shadowRoot.host);
3503 }
3504 var spliceDiff = new ArraySplice();
3505 spliceDiff.equals = function(renderNode, rawNode) {
3506 return unwrap(renderNode.node) === rawNode;
3507 };
3508 function RenderNode(node) {
3509 this.skip = false;
3510 this.node = node;
3511 this.childNodes = [];
3512 }
3513 RenderNode.prototype = {
3514 append: function(node) {
3515 var rv = new RenderNode(node);
3516 this.childNodes.push(rv);
3517 return rv;
3518 },
3519 sync: function(opt_added) {
3520 if (this.skip) return;
3521 var nodeWrapper = this.node;
3522 var newChildren = this.childNodes;
3523 var oldChildren = getChildNodesSnapshot(unwrap(nodeWrapper));
3524 var added = opt_added || new WeakMap();
3525 var splices = spliceDiff.calculateSplices(newChildren, oldChildren);
3526 var newIndex = 0, oldIndex = 0;
3527 var lastIndex = 0;
3528 for (var i = 0; i < splices.length; i++) {
3529 var splice = splices[i];
3530 for (;lastIndex < splice.index; lastIndex++) {
3531 oldIndex++;
3532 newChildren[newIndex++].sync(added);
3533 }
3534 var removedCount = splice.removed.length;
3535 for (var j = 0; j < removedCount; j++) {
3536 var wrapper = wrap(oldChildren[oldIndex++]);
3537 if (!added.get(wrapper)) remove(wrapper);
3538 }
3539 var addedCount = splice.addedCount;
3540 var refNode = oldChildren[oldIndex] && wrap(oldChildren[oldIndex]);
3541 for (var j = 0; j < addedCount; j++) {
3542 var newChildRenderNode = newChildren[newIndex++];
3543 var newChildWrapper = newChildRenderNode.node;
3544 insertBefore(nodeWrapper, newChildWrapper, refNode);
3545 added.set(newChildWrapper, true);
3546 newChildRenderNode.sync(added);
3547 }
3548 lastIndex += addedCount;
3549 }
3550 for (var i = lastIndex; i < newChildren.length; i++) {
3551 newChildren[i].sync(added);
3552 }
3553 }
3554 };
3555 function ShadowRenderer(host) {
3556 this.host = host;
3557 this.dirty = false;
3558 this.invalidateAttributes();
3559 this.associateNode(host);
3560 }
3561 ShadowRenderer.prototype = {
3562 render: function(opt_renderNode) {
3563 if (!this.dirty) return;
3564 this.invalidateAttributes();
3565 var host = this.host;
3566 this.distribution(host);
3567 var renderNode = opt_renderNode || new RenderNode(host);
3568 this.buildRenderTree(renderNode, host);
3569 var topMostRenderer = !opt_renderNode;
3570 if (topMostRenderer) renderNode.sync();
3571 this.dirty = false;
3572 },
3573 get parentRenderer() {
3574 return getTreeScope(this.host).renderer;
3575 },
3576 invalidate: function() {
3577 if (!this.dirty) {
3578 this.dirty = true;
3579 var parentRenderer = this.parentRenderer;
3580 if (parentRenderer) parentRenderer.invalidate();
3581 pendingDirtyRenderers.push(this);
3582 if (renderTimer) return;
3583 renderTimer = window[request](handleRequestAnimationFrame, 0);
3584 }
3585 },
3586 distribution: function(root) {
3587 this.resetAllSubtrees(root);
3588 this.distributionResolution(root);
3589 },
3590 resetAll: function(node) {
3591 if (isInsertionPoint(node)) resetDistributedNodes(node); else resetDestina tionInsertionPoints(node);
3592 this.resetAllSubtrees(node);
3593 },
3594 resetAllSubtrees: function(node) {
3595 for (var child = node.firstChild; child; child = child.nextSibling) {
3596 this.resetAll(child);
3597 }
3598 if (node.shadowRoot) this.resetAll(node.shadowRoot);
3599 if (node.olderShadowRoot) this.resetAll(node.olderShadowRoot);
3600 },
3601 distributionResolution: function(node) {
3602 if (isShadowHost(node)) {
3603 var shadowHost = node;
3604 var pool = poolPopulation(shadowHost);
3605 var shadowTrees = getShadowTrees(shadowHost);
3606 for (var i = 0; i < shadowTrees.length; i++) {
3607 this.poolDistribution(shadowTrees[i], pool);
3608 }
3609 for (var i = shadowTrees.length - 1; i >= 0; i--) {
3610 var shadowTree = shadowTrees[i];
3611 var shadow = getShadowInsertionPoint(shadowTree);
3612 if (shadow) {
3613 var olderShadowRoot = shadowTree.olderShadowRoot;
3614 if (olderShadowRoot) {
3615 pool = poolPopulation(olderShadowRoot);
3616 }
3617 for (var j = 0; j < pool.length; j++) {
3618 destributeNodeInto(pool[j], shadow);
3619 }
3620 }
3621 this.distributionResolution(shadowTree);
3622 }
3623 }
3624 for (var child = node.firstChild; child; child = child.nextSibling) {
3625 this.distributionResolution(child);
3626 }
3627 },
3628 poolDistribution: function(node, pool) {
3629 if (node instanceof HTMLShadowElement) return;
3630 if (node instanceof HTMLContentElement) {
3631 var content = node;
3632 this.updateDependentAttributes(content.getAttribute("select"));
3633 var anyDistributed = false;
3634 for (var i = 0; i < pool.length; i++) {
3635 var node = pool[i];
3636 if (!node) continue;
3637 if (matches(node, content)) {
3638 destributeNodeInto(node, content);
3639 pool[i] = undefined;
3640 anyDistributed = true;
3641 }
3642 }
3643 if (!anyDistributed) {
3644 for (var child = content.firstChild; child; child = child.nextSibling) {
3645 destributeNodeInto(child, content);
3646 }
3647 }
3648 return;
3649 }
3650 for (var child = node.firstChild; child; child = child.nextSibling) {
3651 this.poolDistribution(child, pool);
3652 }
3653 },
3654 buildRenderTree: function(renderNode, node) {
3655 var children = this.compose(node);
3656 for (var i = 0; i < children.length; i++) {
3657 var child = children[i];
3658 var childRenderNode = renderNode.append(child);
3659 this.buildRenderTree(childRenderNode, child);
3660 }
3661 if (isShadowHost(node)) {
3662 var renderer = getRendererForHost(node);
3663 renderer.dirty = false;
3664 }
3665 },
3666 compose: function(node) {
3667 var children = [];
3668 var p = node.shadowRoot || node;
3669 for (var child = p.firstChild; child; child = child.nextSibling) {
3670 if (isInsertionPoint(child)) {
3671 this.associateNode(p);
3672 var distributedNodes = getDistributedNodes(child);
3673 for (var j = 0; j < distributedNodes.length; j++) {
3674 var distributedNode = distributedNodes[j];
3675 if (isFinalDestination(child, distributedNode)) children.push(distri butedNode);
3676 }
3677 } else {
3678 children.push(child);
3679 }
3680 }
3681 return children;
3682 },
3683 invalidateAttributes: function() {
3684 this.attributes = Object.create(null);
3685 },
3686 updateDependentAttributes: function(selector) {
3687 if (!selector) return;
3688 var attributes = this.attributes;
3689 if (/\.\w+/.test(selector)) attributes["class"] = true;
3690 if (/#\w+/.test(selector)) attributes["id"] = true;
3691 selector.replace(/\[\s*([^\s=\|~\]]+)/g, function(_, name) {
3692 attributes[name] = true;
3693 });
3694 },
3695 dependsOnAttribute: function(name) {
3696 return this.attributes[name];
3697 },
3698 associateNode: function(node) {
3699 unsafeUnwrap(node).polymerShadowRenderer_ = this;
3700 }
3701 };
3702 function poolPopulation(node) {
3703 var pool = [];
3704 for (var child = node.firstChild; child; child = child.nextSibling) {
3705 if (isInsertionPoint(child)) {
3706 pool.push.apply(pool, getDistributedNodes(child));
3707 } else {
3708 pool.push(child);
3709 }
3710 }
3711 return pool;
3712 }
3713 function getShadowInsertionPoint(node) {
3714 if (node instanceof HTMLShadowElement) return node;
3715 if (node instanceof HTMLContentElement) return null;
3716 for (var child = node.firstChild; child; child = child.nextSibling) {
3717 var res = getShadowInsertionPoint(child);
3718 if (res) return res;
3719 }
3720 return null;
3721 }
3722 function destributeNodeInto(child, insertionPoint) {
3723 getDistributedNodes(insertionPoint).push(child);
3724 var points = destinationInsertionPointsTable.get(child);
3725 if (!points) destinationInsertionPointsTable.set(child, [ insertionPoint ]); else points.push(insertionPoint);
3726 }
3727 function getDestinationInsertionPoints(node) {
3728 return destinationInsertionPointsTable.get(node);
3729 }
3730 function resetDestinationInsertionPoints(node) {
3731 destinationInsertionPointsTable.set(node, undefined);
3732 }
3733 var selectorStartCharRe = /^(:not\()?[*.#[a-zA-Z_|]/;
3734 function matches(node, contentElement) {
3735 var select = contentElement.getAttribute("select");
3736 if (!select) return true;
3737 select = select.trim();
3738 if (!select) return true;
3739 if (!(node instanceof Element)) return false;
3740 if (!selectorStartCharRe.test(select)) return false;
3741 try {
3742 return node.matches(select);
3743 } catch (ex) {
3744 return false;
3745 }
3746 }
3747 function isFinalDestination(insertionPoint, node) {
3748 var points = getDestinationInsertionPoints(node);
3749 return points && points[points.length - 1] === insertionPoint;
3750 }
3751 function isInsertionPoint(node) {
3752 return node instanceof HTMLContentElement || node instanceof HTMLShadowEleme nt;
3753 }
3754 function isShadowHost(shadowHost) {
3755 return shadowHost.shadowRoot;
3756 }
3757 function getShadowTrees(host) {
3758 var trees = [];
3759 for (var tree = host.shadowRoot; tree; tree = tree.olderShadowRoot) {
3760 trees.push(tree);
3761 }
3762 return trees;
3763 }
3764 function render(host) {
3765 new ShadowRenderer(host).render();
3766 }
3767 Node.prototype.invalidateShadowRenderer = function(force) {
3768 var renderer = unsafeUnwrap(this).polymerShadowRenderer_;
3769 if (renderer) {
3770 renderer.invalidate();
3771 return true;
3772 }
3773 return false;
3774 };
3775 HTMLContentElement.prototype.getDistributedNodes = HTMLShadowElement.prototype .getDistributedNodes = function() {
3776 renderAllPending();
3777 return getDistributedNodes(this);
3778 };
3779 Element.prototype.getDestinationInsertionPoints = function() {
3780 renderAllPending();
3781 return getDestinationInsertionPoints(this) || [];
3782 };
3783 HTMLContentElement.prototype.nodeIsInserted_ = HTMLShadowElement.prototype.nod eIsInserted_ = function() {
3784 this.invalidateShadowRenderer();
3785 var shadowRoot = getShadowRootAncestor(this);
3786 var renderer;
3787 if (shadowRoot) renderer = getRendererForShadowRoot(shadowRoot);
3788 unsafeUnwrap(this).polymerShadowRenderer_ = renderer;
3789 if (renderer) renderer.invalidate();
3790 };
3791 scope.getRendererForHost = getRendererForHost;
3792 scope.getShadowTrees = getShadowTrees;
3793 scope.renderAllPending = renderAllPending;
3794 scope.getDestinationInsertionPoints = getDestinationInsertionPoints;
3795 scope.visual = {
3796 insertBefore: insertBefore,
3797 remove: remove
3798 };
3799 })(window.ShadowDOMPolyfill);
3800
3801 (function(scope) {
3802 "use strict";
3803 var HTMLElement = scope.wrappers.HTMLElement;
3804 var assert = scope.assert;
3805 var mixin = scope.mixin;
3806 var registerWrapper = scope.registerWrapper;
3807 var unwrap = scope.unwrap;
3808 var wrap = scope.wrap;
3809 var elementsWithFormProperty = [ "HTMLButtonElement", "HTMLFieldSetElement", " HTMLInputElement", "HTMLKeygenElement", "HTMLLabelElement", "HTMLLegendElement", "HTMLObjectElement", "HTMLOutputElement", "HTMLTextAreaElement" ];
3810 function createWrapperConstructor(name) {
3811 if (!window[name]) return;
3812 assert(!scope.wrappers[name]);
3813 var GeneratedWrapper = function(node) {
3814 HTMLElement.call(this, node);
3815 };
3816 GeneratedWrapper.prototype = Object.create(HTMLElement.prototype);
3817 mixin(GeneratedWrapper.prototype, {
3818 get form() {
3819 return wrap(unwrap(this).form);
3820 }
3821 });
3822 registerWrapper(window[name], GeneratedWrapper, document.createElement(name. slice(4, -7)));
3823 scope.wrappers[name] = GeneratedWrapper;
3824 }
3825 elementsWithFormProperty.forEach(createWrapperConstructor);
3826 })(window.ShadowDOMPolyfill);
3827
3828 (function(scope) {
3829 "use strict";
3830 var registerWrapper = scope.registerWrapper;
3831 var setWrapper = scope.setWrapper;
3832 var unsafeUnwrap = scope.unsafeUnwrap;
3833 var unwrap = scope.unwrap;
3834 var unwrapIfNeeded = scope.unwrapIfNeeded;
3835 var wrap = scope.wrap;
3836 var OriginalSelection = window.Selection;
3837 function Selection(impl) {
3838 setWrapper(impl, this);
3839 }
3840 Selection.prototype = {
3841 get anchorNode() {
3842 return wrap(unsafeUnwrap(this).anchorNode);
3843 },
3844 get focusNode() {
3845 return wrap(unsafeUnwrap(this).focusNode);
3846 },
3847 addRange: function(range) {
3848 unsafeUnwrap(this).addRange(unwrap(range));
3849 },
3850 collapse: function(node, index) {
3851 unsafeUnwrap(this).collapse(unwrapIfNeeded(node), index);
3852 },
3853 containsNode: function(node, allowPartial) {
3854 return unsafeUnwrap(this).containsNode(unwrapIfNeeded(node), allowPartial) ;
3855 },
3856 extend: function(node, offset) {
3857 unsafeUnwrap(this).extend(unwrapIfNeeded(node), offset);
3858 },
3859 getRangeAt: function(index) {
3860 return wrap(unsafeUnwrap(this).getRangeAt(index));
3861 },
3862 removeRange: function(range) {
3863 unsafeUnwrap(this).removeRange(unwrap(range));
3864 },
3865 selectAllChildren: function(node) {
3866 unsafeUnwrap(this).selectAllChildren(unwrapIfNeeded(node));
3867 },
3868 toString: function() {
3869 return unsafeUnwrap(this).toString();
3870 }
3871 };
3872 registerWrapper(window.Selection, Selection, window.getSelection());
3873 scope.wrappers.Selection = Selection;
3874 })(window.ShadowDOMPolyfill);
3875
3876 (function(scope) {
3877 "use strict";
3878 var GetElementsByInterface = scope.GetElementsByInterface;
3879 var Node = scope.wrappers.Node;
3880 var ParentNodeInterface = scope.ParentNodeInterface;
3881 var Selection = scope.wrappers.Selection;
3882 var SelectorsInterface = scope.SelectorsInterface;
3883 var ShadowRoot = scope.wrappers.ShadowRoot;
3884 var TreeScope = scope.TreeScope;
3885 var cloneNode = scope.cloneNode;
3886 var defineWrapGetter = scope.defineWrapGetter;
3887 var elementFromPoint = scope.elementFromPoint;
3888 var forwardMethodsToWrapper = scope.forwardMethodsToWrapper;
3889 var matchesNames = scope.matchesNames;
3890 var mixin = scope.mixin;
3891 var registerWrapper = scope.registerWrapper;
3892 var renderAllPending = scope.renderAllPending;
3893 var rewrap = scope.rewrap;
3894 var setWrapper = scope.setWrapper;
3895 var unsafeUnwrap = scope.unsafeUnwrap;
3896 var unwrap = scope.unwrap;
3897 var wrap = scope.wrap;
3898 var wrapEventTargetMethods = scope.wrapEventTargetMethods;
3899 var wrapNodeList = scope.wrapNodeList;
3900 var implementationTable = new WeakMap();
3901 function Document(node) {
3902 Node.call(this, node);
3903 this.treeScope_ = new TreeScope(this, null);
3904 }
3905 Document.prototype = Object.create(Node.prototype);
3906 defineWrapGetter(Document, "documentElement");
3907 defineWrapGetter(Document, "body");
3908 defineWrapGetter(Document, "head");
3909 function wrapMethod(name) {
3910 var original = document[name];
3911 Document.prototype[name] = function() {
3912 return wrap(original.apply(unsafeUnwrap(this), arguments));
3913 };
3914 }
3915 [ "createComment", "createDocumentFragment", "createElement", "createElementNS ", "createEvent", "createEventNS", "createRange", "createTextNode", "getElementB yId" ].forEach(wrapMethod);
3916 var originalAdoptNode = document.adoptNode;
3917 function adoptNodeNoRemove(node, doc) {
3918 originalAdoptNode.call(unsafeUnwrap(doc), unwrap(node));
3919 adoptSubtree(node, doc);
3920 }
3921 function adoptSubtree(node, doc) {
3922 if (node.shadowRoot) doc.adoptNode(node.shadowRoot);
3923 if (node instanceof ShadowRoot) adoptOlderShadowRoots(node, doc);
3924 for (var child = node.firstChild; child; child = child.nextSibling) {
3925 adoptSubtree(child, doc);
3926 }
3927 }
3928 function adoptOlderShadowRoots(shadowRoot, doc) {
3929 var oldShadowRoot = shadowRoot.olderShadowRoot;
3930 if (oldShadowRoot) doc.adoptNode(oldShadowRoot);
3931 }
3932 var originalGetSelection = document.getSelection;
3933 mixin(Document.prototype, {
3934 adoptNode: function(node) {
3935 if (node.parentNode) node.parentNode.removeChild(node);
3936 adoptNodeNoRemove(node, this);
3937 return node;
3938 },
3939 elementFromPoint: function(x, y) {
3940 return elementFromPoint(this, this, x, y);
3941 },
3942 importNode: function(node, deep) {
3943 return cloneNode(node, deep, unsafeUnwrap(this));
3944 },
3945 getSelection: function() {
3946 renderAllPending();
3947 return new Selection(originalGetSelection.call(unwrap(this)));
3948 },
3949 getElementsByName: function(name) {
3950 return SelectorsInterface.querySelectorAll.call(this, "[name=" + JSON.stri ngify(String(name)) + "]");
3951 }
3952 });
3953 if (document.registerElement) {
3954 var originalRegisterElement = document.registerElement;
3955 Document.prototype.registerElement = function(tagName, object) {
3956 var prototype, extendsOption;
3957 if (object !== undefined) {
3958 prototype = object.prototype;
3959 extendsOption = object.extends;
3960 }
3961 if (!prototype) prototype = Object.create(HTMLElement.prototype);
3962 if (scope.nativePrototypeTable.get(prototype)) {
3963 throw new Error("NotSupportedError");
3964 }
3965 var proto = Object.getPrototypeOf(prototype);
3966 var nativePrototype;
3967 var prototypes = [];
3968 while (proto) {
3969 nativePrototype = scope.nativePrototypeTable.get(proto);
3970 if (nativePrototype) break;
3971 prototypes.push(proto);
3972 proto = Object.getPrototypeOf(proto);
3973 }
3974 if (!nativePrototype) {
3975 throw new Error("NotSupportedError");
3976 }
3977 var newPrototype = Object.create(nativePrototype);
3978 for (var i = prototypes.length - 1; i >= 0; i--) {
3979 newPrototype = Object.create(newPrototype);
3980 }
3981 [ "createdCallback", "attachedCallback", "detachedCallback", "attributeCha ngedCallback" ].forEach(function(name) {
3982 var f = prototype[name];
3983 if (!f) return;
3984 newPrototype[name] = function() {
3985 if (!(wrap(this) instanceof CustomElementConstructor)) {
3986 rewrap(this);
3987 }
3988 f.apply(wrap(this), arguments);
3989 };
3990 });
3991 var p = {
3992 prototype: newPrototype
3993 };
3994 if (extendsOption) p.extends = extendsOption;
3995 function CustomElementConstructor(node) {
3996 if (!node) {
3997 if (extendsOption) {
3998 return document.createElement(extendsOption, tagName);
3999 } else {
4000 return document.createElement(tagName);
4001 }
4002 }
4003 setWrapper(node, this);
4004 }
4005 CustomElementConstructor.prototype = prototype;
4006 CustomElementConstructor.prototype.constructor = CustomElementConstructor;
4007 scope.constructorTable.set(newPrototype, CustomElementConstructor);
4008 scope.nativePrototypeTable.set(prototype, newPrototype);
4009 var nativeConstructor = originalRegisterElement.call(unwrap(this), tagName , p);
4010 return CustomElementConstructor;
4011 };
4012 forwardMethodsToWrapper([ window.HTMLDocument || window.Document ], [ "regis terElement" ]);
4013 }
4014 forwardMethodsToWrapper([ window.HTMLBodyElement, window.HTMLDocument || windo w.Document, window.HTMLHeadElement, window.HTMLHtmlElement ], [ "appendChild", " compareDocumentPosition", "contains", "getElementsByClassName", "getElementsByTa gName", "getElementsByTagNameNS", "insertBefore", "querySelector", "querySelecto rAll", "removeChild", "replaceChild" ].concat(matchesNames));
4015 forwardMethodsToWrapper([ window.HTMLDocument || window.Document ], [ "adoptNo de", "importNode", "contains", "createComment", "createDocumentFragment", "creat eElement", "createElementNS", "createEvent", "createEventNS", "createRange", "cr eateTextNode", "elementFromPoint", "getElementById", "getElementsByName", "getSe lection" ]);
4016 mixin(Document.prototype, GetElementsByInterface);
4017 mixin(Document.prototype, ParentNodeInterface);
4018 mixin(Document.prototype, SelectorsInterface);
4019 mixin(Document.prototype, {
4020 get implementation() {
4021 var implementation = implementationTable.get(this);
4022 if (implementation) return implementation;
4023 implementation = new DOMImplementation(unwrap(this).implementation);
4024 implementationTable.set(this, implementation);
4025 return implementation;
4026 },
4027 get defaultView() {
4028 return wrap(unwrap(this).defaultView);
4029 }
4030 });
4031 registerWrapper(window.Document, Document, document.implementation.createHTMLD ocument(""));
4032 if (window.HTMLDocument) registerWrapper(window.HTMLDocument, Document);
4033 wrapEventTargetMethods([ window.HTMLBodyElement, window.HTMLDocument || window .Document, window.HTMLHeadElement ]);
4034 function DOMImplementation(impl) {
4035 setWrapper(impl, this);
4036 }
4037 function wrapImplMethod(constructor, name) {
4038 var original = document.implementation[name];
4039 constructor.prototype[name] = function() {
4040 return wrap(original.apply(unsafeUnwrap(this), arguments));
4041 };
4042 }
4043 function forwardImplMethod(constructor, name) {
4044 var original = document.implementation[name];
4045 constructor.prototype[name] = function() {
4046 return original.apply(unsafeUnwrap(this), arguments);
4047 };
4048 }
4049 wrapImplMethod(DOMImplementation, "createDocumentType");
4050 wrapImplMethod(DOMImplementation, "createDocument");
4051 wrapImplMethod(DOMImplementation, "createHTMLDocument");
4052 forwardImplMethod(DOMImplementation, "hasFeature");
4053 registerWrapper(window.DOMImplementation, DOMImplementation);
4054 forwardMethodsToWrapper([ window.DOMImplementation ], [ "createDocumentType", "createDocument", "createHTMLDocument", "hasFeature" ]);
4055 scope.adoptNodeNoRemove = adoptNodeNoRemove;
4056 scope.wrappers.DOMImplementation = DOMImplementation;
4057 scope.wrappers.Document = Document;
4058 })(window.ShadowDOMPolyfill);
4059
4060 (function(scope) {
4061 "use strict";
4062 var EventTarget = scope.wrappers.EventTarget;
4063 var Selection = scope.wrappers.Selection;
4064 var mixin = scope.mixin;
4065 var registerWrapper = scope.registerWrapper;
4066 var renderAllPending = scope.renderAllPending;
4067 var unwrap = scope.unwrap;
4068 var unwrapIfNeeded = scope.unwrapIfNeeded;
4069 var wrap = scope.wrap;
4070 var OriginalWindow = window.Window;
4071 var originalGetComputedStyle = window.getComputedStyle;
4072 var originalGetDefaultComputedStyle = window.getDefaultComputedStyle;
4073 var originalGetSelection = window.getSelection;
4074 function Window(impl) {
4075 EventTarget.call(this, impl);
4076 }
4077 Window.prototype = Object.create(EventTarget.prototype);
4078 OriginalWindow.prototype.getComputedStyle = function(el, pseudo) {
4079 return wrap(this || window).getComputedStyle(unwrapIfNeeded(el), pseudo);
4080 };
4081 if (originalGetDefaultComputedStyle) {
4082 OriginalWindow.prototype.getDefaultComputedStyle = function(el, pseudo) {
4083 return wrap(this || window).getDefaultComputedStyle(unwrapIfNeeded(el), ps eudo);
4084 };
4085 }
4086 OriginalWindow.prototype.getSelection = function() {
4087 return wrap(this || window).getSelection();
4088 };
4089 delete window.getComputedStyle;
4090 delete window.getDefaultComputedStyle;
4091 delete window.getSelection;
4092 [ "addEventListener", "removeEventListener", "dispatchEvent" ].forEach(functio n(name) {
4093 OriginalWindow.prototype[name] = function() {
4094 var w = wrap(this || window);
4095 return w[name].apply(w, arguments);
4096 };
4097 delete window[name];
4098 });
4099 mixin(Window.prototype, {
4100 getComputedStyle: function(el, pseudo) {
4101 renderAllPending();
4102 return originalGetComputedStyle.call(unwrap(this), unwrapIfNeeded(el), pse udo);
4103 },
4104 getSelection: function() {
4105 renderAllPending();
4106 return new Selection(originalGetSelection.call(unwrap(this)));
4107 },
4108 get document() {
4109 return wrap(unwrap(this).document);
4110 }
4111 });
4112 if (originalGetDefaultComputedStyle) {
4113 Window.prototype.getDefaultComputedStyle = function(el, pseudo) {
4114 renderAllPending();
4115 return originalGetDefaultComputedStyle.call(unwrap(this), unwrapIfNeeded(e l), pseudo);
4116 };
4117 }
4118 registerWrapper(OriginalWindow, Window, window);
4119 scope.wrappers.Window = Window;
4120 })(window.ShadowDOMPolyfill);
4121
4122 (function(scope) {
4123 "use strict";
4124 var unwrap = scope.unwrap;
4125 var OriginalDataTransfer = window.DataTransfer || window.Clipboard;
4126 var OriginalDataTransferSetDragImage = OriginalDataTransfer.prototype.setDragI mage;
4127 if (OriginalDataTransferSetDragImage) {
4128 OriginalDataTransfer.prototype.setDragImage = function(image, x, y) {
4129 OriginalDataTransferSetDragImage.call(this, unwrap(image), x, y);
4130 };
4131 }
4132 })(window.ShadowDOMPolyfill);
4133
4134 (function(scope) {
4135 "use strict";
4136 var registerWrapper = scope.registerWrapper;
4137 var setWrapper = scope.setWrapper;
4138 var unwrap = scope.unwrap;
4139 var OriginalFormData = window.FormData;
4140 if (!OriginalFormData) return;
4141 function FormData(formElement) {
4142 var impl;
4143 if (formElement instanceof OriginalFormData) {
4144 impl = formElement;
4145 } else {
4146 impl = new OriginalFormData(formElement && unwrap(formElement));
4147 }
4148 setWrapper(impl, this);
4149 }
4150 registerWrapper(OriginalFormData, FormData, new OriginalFormData());
4151 scope.wrappers.FormData = FormData;
4152 })(window.ShadowDOMPolyfill);
4153
4154 (function(scope) {
4155 "use strict";
4156 var unwrapIfNeeded = scope.unwrapIfNeeded;
4157 var originalSend = XMLHttpRequest.prototype.send;
4158 XMLHttpRequest.prototype.send = function(obj) {
4159 return originalSend.call(this, unwrapIfNeeded(obj));
4160 };
4161 })(window.ShadowDOMPolyfill);
4162
4163 (function(scope) {
4164 "use strict";
4165 var isWrapperFor = scope.isWrapperFor;
4166 var elements = {
4167 a: "HTMLAnchorElement",
4168 area: "HTMLAreaElement",
4169 audio: "HTMLAudioElement",
4170 base: "HTMLBaseElement",
4171 body: "HTMLBodyElement",
4172 br: "HTMLBRElement",
4173 button: "HTMLButtonElement",
4174 canvas: "HTMLCanvasElement",
4175 caption: "HTMLTableCaptionElement",
4176 col: "HTMLTableColElement",
4177 content: "HTMLContentElement",
4178 data: "HTMLDataElement",
4179 datalist: "HTMLDataListElement",
4180 del: "HTMLModElement",
4181 dir: "HTMLDirectoryElement",
4182 div: "HTMLDivElement",
4183 dl: "HTMLDListElement",
4184 embed: "HTMLEmbedElement",
4185 fieldset: "HTMLFieldSetElement",
4186 font: "HTMLFontElement",
4187 form: "HTMLFormElement",
4188 frame: "HTMLFrameElement",
4189 frameset: "HTMLFrameSetElement",
4190 h1: "HTMLHeadingElement",
4191 head: "HTMLHeadElement",
4192 hr: "HTMLHRElement",
4193 html: "HTMLHtmlElement",
4194 iframe: "HTMLIFrameElement",
4195 img: "HTMLImageElement",
4196 input: "HTMLInputElement",
4197 keygen: "HTMLKeygenElement",
4198 label: "HTMLLabelElement",
4199 legend: "HTMLLegendElement",
4200 li: "HTMLLIElement",
4201 link: "HTMLLinkElement",
4202 map: "HTMLMapElement",
4203 marquee: "HTMLMarqueeElement",
4204 menu: "HTMLMenuElement",
4205 menuitem: "HTMLMenuItemElement",
4206 meta: "HTMLMetaElement",
4207 meter: "HTMLMeterElement",
4208 object: "HTMLObjectElement",
4209 ol: "HTMLOListElement",
4210 optgroup: "HTMLOptGroupElement",
4211 option: "HTMLOptionElement",
4212 output: "HTMLOutputElement",
4213 p: "HTMLParagraphElement",
4214 param: "HTMLParamElement",
4215 pre: "HTMLPreElement",
4216 progress: "HTMLProgressElement",
4217 q: "HTMLQuoteElement",
4218 script: "HTMLScriptElement",
4219 select: "HTMLSelectElement",
4220 shadow: "HTMLShadowElement",
4221 source: "HTMLSourceElement",
4222 span: "HTMLSpanElement",
4223 style: "HTMLStyleElement",
4224 table: "HTMLTableElement",
4225 tbody: "HTMLTableSectionElement",
4226 template: "HTMLTemplateElement",
4227 textarea: "HTMLTextAreaElement",
4228 thead: "HTMLTableSectionElement",
4229 time: "HTMLTimeElement",
4230 title: "HTMLTitleElement",
4231 tr: "HTMLTableRowElement",
4232 track: "HTMLTrackElement",
4233 ul: "HTMLUListElement",
4234 video: "HTMLVideoElement"
4235 };
4236 function overrideConstructor(tagName) {
4237 var nativeConstructorName = elements[tagName];
4238 var nativeConstructor = window[nativeConstructorName];
4239 if (!nativeConstructor) return;
4240 var element = document.createElement(tagName);
4241 var wrapperConstructor = element.constructor;
4242 window[nativeConstructorName] = wrapperConstructor;
4243 }
4244 Object.keys(elements).forEach(overrideConstructor);
4245 Object.getOwnPropertyNames(scope.wrappers).forEach(function(name) {
4246 window[name] = scope.wrappers[name];
4247 });
4248 })(window.ShadowDOMPolyfill);
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698