| OLD | NEW |
| 1 if (!HTMLElement.prototype.createShadowRoot | 1 if (!HTMLElement.prototype.createShadowRoot |
| 2 || window.__forceShadowDomPolyfill) { | 2 || window.__forceShadowDomPolyfill) { |
| 3 | 3 |
| 4 /* | 4 /* |
| 5 * Copyright 2013 The Polymer Authors. All rights reserved. | 5 * Copyright 2013 The Polymer Authors. All rights reserved. |
| 6 * Use of this source code is governed by a BSD-style | 6 * Use of this source code is governed by a BSD-style |
| 7 * license that can be found in the LICENSE file. | 7 * license that can be found in the LICENSE file. |
| 8 */ | 8 */ |
| 9 (function() { | 9 (function() { |
| 10 // TODO(jmesserly): fix dart:html to use unprefixed name | 10 // TODO(jmesserly): fix dart:html to use unprefixed name |
| (...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 897 if (arguments.length === 2) | 897 if (arguments.length === 2) |
| 898 changeRecord.oldValue = oldValue; | 898 changeRecord.oldValue = oldValue; |
| 899 notifier.notify(changeRecord); | 899 notifier.notify(changeRecord); |
| 900 } | 900 } |
| 901 } | 901 } |
| 902 | 902 |
| 903 // TODO(rafaelw): It should be possible for the Object.observe case to have | 903 // TODO(rafaelw): It should be possible for the Object.observe case to have |
| 904 // every PathObserver used by defineProperty share a single Object.observe | 904 // every PathObserver used by defineProperty share a single Object.observe |
| 905 // callback, and thus get() can simply call observer.deliver() and any changes | 905 // callback, and thus get() can simply call observer.deliver() and any changes |
| 906 // to any dependent value will be observed. | 906 // to any dependent value will be observed. |
| 907 PathObserver.defineProperty = function(object, name, descriptor) { | 907 PathObserver.defineProperty = function(target, name, object, path) { |
| 908 // TODO(rafaelw): Validate errors | 908 // TODO(rafaelw): Validate errors |
| 909 var obj = descriptor.object; | 909 path = getPath(path); |
| 910 var path = getPath(descriptor.path); | 910 var notify = notifyFunction(target, name); |
| 911 var notify = notifyFunction(object, name); | |
| 912 | 911 |
| 913 var observer = new PathObserver(obj, descriptor.path, | 912 var observer = new PathObserver(object, path, |
| 914 function(newValue, oldValue) { | 913 function(newValue, oldValue) { |
| 915 if (notify) | 914 if (notify) |
| 916 notify(PROP_UPDATE_TYPE, oldValue); | 915 notify(PROP_UPDATE_TYPE, oldValue); |
| 917 } | 916 } |
| 918 ); | 917 ); |
| 919 | 918 |
| 920 Object.defineProperty(object, name, { | 919 Object.defineProperty(target, name, { |
| 921 get: function() { | 920 get: function() { |
| 922 return path.getValueFrom(obj); | 921 return path.getValueFrom(object); |
| 923 }, | 922 }, |
| 924 set: function(newValue) { | 923 set: function(newValue) { |
| 925 path.setValueFrom(obj, newValue); | 924 path.setValueFrom(object, newValue); |
| 926 }, | 925 }, |
| 927 configurable: true | 926 configurable: true |
| 928 }); | 927 }); |
| 929 | 928 |
| 930 return { | 929 return { |
| 931 close: function() { | 930 close: function() { |
| 932 var oldValue = path.getValueFrom(obj); | 931 var oldValue = path.getValueFrom(object); |
| 933 if (notify) | 932 if (notify) |
| 934 observer.deliver(); | 933 observer.deliver(); |
| 935 observer.close(); | 934 observer.close(); |
| 936 Object.defineProperty(object, name, { | 935 Object.defineProperty(target, name, { |
| 937 value: oldValue, | 936 value: oldValue, |
| 938 writable: true, | 937 writable: true, |
| 939 configurable: true | 938 configurable: true |
| 940 }); | 939 }); |
| 941 } | 940 } |
| 942 }; | 941 }; |
| 943 } | 942 } |
| 944 | 943 |
| 945 function diffObjectFromChangeRecords(object, changeRecords, oldValues) { | 944 function diffObjectFromChangeRecords(object, changeRecords, oldValues) { |
| 946 var added = {}; | 945 var added = {}; |
| (...skipping 465 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1412 | 1411 |
| 1413 // TODO(rafaelw): Only needed for testing until new change record names | 1412 // TODO(rafaelw): Only needed for testing until new change record names |
| 1414 // make it to release. | 1413 // make it to release. |
| 1415 global.Observer.changeRecordTypes = { | 1414 global.Observer.changeRecordTypes = { |
| 1416 add: PROP_ADD_TYPE, | 1415 add: PROP_ADD_TYPE, |
| 1417 update: PROP_UPDATE_TYPE, | 1416 update: PROP_UPDATE_TYPE, |
| 1418 reconfigure: PROP_RECONFIGURE_TYPE, | 1417 reconfigure: PROP_RECONFIGURE_TYPE, |
| 1419 'delete': PROP_DELETE_TYPE, | 1418 'delete': PROP_DELETE_TYPE, |
| 1420 splice: ARRAY_SPLICE_TYPE | 1419 splice: ARRAY_SPLICE_TYPE |
| 1421 }; | 1420 }; |
| 1422 })(typeof global !== 'undefined' && global ? global : this); | 1421 })(typeof global !== 'undefined' && global ? global : this || window); |
| 1423 | 1422 |
| 1424 /* | 1423 /* |
| 1425 * Copyright 2012 The Polymer Authors. All rights reserved. | 1424 * Copyright 2012 The Polymer Authors. All rights reserved. |
| 1426 * Use of this source code is governed by a BSD-style | 1425 * Use of this source code is governed by a BSD-style |
| 1427 * license that can be found in the LICENSE file. | 1426 * license that can be found in the LICENSE file. |
| 1428 */ | 1427 */ |
| 1429 | 1428 |
| 1430 if (typeof WeakMap === 'undefined') { | 1429 if (typeof WeakMap === 'undefined') { |
| 1431 (function() { | 1430 (function() { |
| 1432 var defineProperty = Object.defineProperty; | 1431 var defineProperty = Object.defineProperty; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1483 } catch (ex) { | 1482 } catch (ex) { |
| 1484 hasEval = false; | 1483 hasEval = false; |
| 1485 } | 1484 } |
| 1486 } | 1485 } |
| 1487 | 1486 |
| 1488 function assert(b) { | 1487 function assert(b) { |
| 1489 if (!b) | 1488 if (!b) |
| 1490 throw new Error('Assertion failed'); | 1489 throw new Error('Assertion failed'); |
| 1491 }; | 1490 }; |
| 1492 | 1491 |
| 1492 var defineProperty = Object.defineProperty; |
| 1493 var getOwnPropertyNames = Object.getOwnPropertyNames; |
| 1494 var getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor; |
| 1495 |
| 1493 function mixin(to, from) { | 1496 function mixin(to, from) { |
| 1494 Object.getOwnPropertyNames(from).forEach(function(name) { | 1497 getOwnPropertyNames(from).forEach(function(name) { |
| 1495 Object.defineProperty(to, name, | 1498 defineProperty(to, name, getOwnPropertyDescriptor(from, name)); |
| 1496 Object.getOwnPropertyDescriptor(from, name)); | |
| 1497 }); | 1499 }); |
| 1498 return to; | 1500 return to; |
| 1499 }; | 1501 }; |
| 1500 | 1502 |
| 1501 function mixinStatics(to, from) { | 1503 function mixinStatics(to, from) { |
| 1502 Object.getOwnPropertyNames(from).forEach(function(name) { | 1504 getOwnPropertyNames(from).forEach(function(name) { |
| 1503 switch (name) { | 1505 switch (name) { |
| 1504 case 'arguments': | 1506 case 'arguments': |
| 1505 case 'caller': | 1507 case 'caller': |
| 1506 case 'length': | 1508 case 'length': |
| 1507 case 'name': | 1509 case 'name': |
| 1508 case 'prototype': | 1510 case 'prototype': |
| 1509 case 'toString': | 1511 case 'toString': |
| 1510 return; | 1512 return; |
| 1511 } | 1513 } |
| 1512 Object.defineProperty(to, name, | 1514 defineProperty(to, name, getOwnPropertyDescriptor(from, name)); |
| 1513 Object.getOwnPropertyDescriptor(from, name)); | |
| 1514 }); | 1515 }); |
| 1515 return to; | 1516 return to; |
| 1516 }; | 1517 }; |
| 1517 | 1518 |
| 1518 function oneOf(object, propertyNames) { | 1519 function oneOf(object, propertyNames) { |
| 1519 for (var i = 0; i < propertyNames.length; i++) { | 1520 for (var i = 0; i < propertyNames.length; i++) { |
| 1520 if (propertyNames[i] in object) | 1521 if (propertyNames[i] in object) |
| 1521 return propertyNames[i]; | 1522 return propertyNames[i]; |
| 1522 } | 1523 } |
| 1523 } | 1524 } |
| 1524 | 1525 |
| 1525 // Mozilla's old DOM bindings are bretty busted: | 1526 // Mozilla's old DOM bindings are bretty busted: |
| 1526 // https://bugzilla.mozilla.org/show_bug.cgi?id=855844 | 1527 // https://bugzilla.mozilla.org/show_bug.cgi?id=855844 |
| 1527 // Make sure they are create before we start modifying things. | 1528 // Make sure they are create before we start modifying things. |
| 1528 Object.getOwnPropertyNames(window); | 1529 getOwnPropertyNames(window); |
| 1529 | 1530 |
| 1530 function getWrapperConstructor(node) { | 1531 function getWrapperConstructor(node) { |
| 1531 var nativePrototype = node.__proto__ || Object.getPrototypeOf(node); | 1532 var nativePrototype = node.__proto__ || Object.getPrototypeOf(node); |
| 1532 var wrapperConstructor = constructorTable.get(nativePrototype); | 1533 var wrapperConstructor = constructorTable.get(nativePrototype); |
| 1533 if (wrapperConstructor) | 1534 if (wrapperConstructor) |
| 1534 return wrapperConstructor; | 1535 return wrapperConstructor; |
| 1535 | 1536 |
| 1536 var parentWrapperConstructor = getWrapperConstructor(nativePrototype); | 1537 var parentWrapperConstructor = getWrapperConstructor(nativePrototype); |
| 1537 | 1538 |
| 1538 var GeneratedWrapper = createWrapperConstructor(parentWrapperConstructor); | 1539 var GeneratedWrapper = createWrapperConstructor(parentWrapperConstructor); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1580 function(v) { this.impl[name] = v; }; | 1581 function(v) { this.impl[name] = v; }; |
| 1581 } | 1582 } |
| 1582 | 1583 |
| 1583 function getMethod(name) { | 1584 function getMethod(name) { |
| 1584 return hasEval && isIdentifierName(name) ? | 1585 return hasEval && isIdentifierName(name) ? |
| 1585 new Function('return this.impl.' + name + | 1586 new Function('return this.impl.' + name + |
| 1586 '.apply(this.impl, arguments)') : | 1587 '.apply(this.impl, arguments)') : |
| 1587 function() { return this.impl[name].apply(this.impl, arguments); }; | 1588 function() { return this.impl[name].apply(this.impl, arguments); }; |
| 1588 } | 1589 } |
| 1589 | 1590 |
| 1590 function installProperty(source, target, allowMethod) { | 1591 function getDescriptor(source, name) { |
| 1591 Object.getOwnPropertyNames(source).forEach(function(name) { | 1592 try { |
| 1593 return Object.getOwnPropertyDescriptor(source, name); |
| 1594 } catch (ex) { |
| 1595 // JSC and V8 both use data properties instead of accessors which can |
| 1596 // cause getting the property desciptor to throw an exception. |
| 1597 // https://bugs.webkit.org/show_bug.cgi?id=49739 |
| 1598 return dummyDescriptor; |
| 1599 } |
| 1600 } |
| 1601 |
| 1602 function installProperty(source, target, allowMethod, opt_blacklist) { |
| 1603 var names = getOwnPropertyNames(source); |
| 1604 for (var i = 0; i < names.length; i++) { |
| 1605 var name = names[i]; |
| 1606 if (name === 'polymerBlackList_') |
| 1607 continue; |
| 1608 |
| 1592 if (name in target) | 1609 if (name in target) |
| 1593 return; | 1610 continue; |
| 1611 |
| 1612 if (source.polymerBlackList_ && source.polymerBlackList_[name]) |
| 1613 continue; |
| 1594 | 1614 |
| 1595 if (isFirefox) { | 1615 if (isFirefox) { |
| 1596 // Tickle Firefox's old bindings. | 1616 // Tickle Firefox's old bindings. |
| 1597 source.__lookupGetter__(name); | 1617 source.__lookupGetter__(name); |
| 1598 } | 1618 } |
| 1599 var descriptor; | 1619 var descriptor = getDescriptor(source, name); |
| 1600 try { | |
| 1601 descriptor = Object.getOwnPropertyDescriptor(source, name); | |
| 1602 } catch (ex) { | |
| 1603 // JSC and V8 both use data properties instead of accessors which can | |
| 1604 // cause getting the property desciptor to throw an exception. | |
| 1605 // https://bugs.webkit.org/show_bug.cgi?id=49739 | |
| 1606 descriptor = dummyDescriptor; | |
| 1607 } | |
| 1608 var getter, setter; | 1620 var getter, setter; |
| 1609 if (allowMethod && typeof descriptor.value === 'function') { | 1621 if (allowMethod && typeof descriptor.value === 'function') { |
| 1610 target[name] = getMethod(name); | 1622 target[name] = getMethod(name); |
| 1611 return; | 1623 continue; |
| 1612 } | 1624 } |
| 1613 | 1625 |
| 1614 var isEvent = isEventHandlerName(name); | 1626 var isEvent = isEventHandlerName(name); |
| 1615 if (isEvent) | 1627 if (isEvent) |
| 1616 getter = scope.getEventHandlerGetter(name); | 1628 getter = scope.getEventHandlerGetter(name); |
| 1617 else | 1629 else |
| 1618 getter = getGetter(name); | 1630 getter = getGetter(name); |
| 1619 | 1631 |
| 1620 if (descriptor.writable || descriptor.set) { | 1632 if (descriptor.writable || descriptor.set) { |
| 1621 if (isEvent) | 1633 if (isEvent) |
| 1622 setter = scope.getEventHandlerSetter(name); | 1634 setter = scope.getEventHandlerSetter(name); |
| 1623 else | 1635 else |
| 1624 setter = getSetter(name); | 1636 setter = getSetter(name); |
| 1625 } | 1637 } |
| 1626 | 1638 |
| 1627 Object.defineProperty(target, name, { | 1639 defineProperty(target, name, { |
| 1628 get: getter, | 1640 get: getter, |
| 1629 set: setter, | 1641 set: setter, |
| 1630 configurable: descriptor.configurable, | 1642 configurable: descriptor.configurable, |
| 1631 enumerable: descriptor.enumerable | 1643 enumerable: descriptor.enumerable |
| 1632 }); | 1644 }); |
| 1633 }); | 1645 } |
| 1634 } | 1646 } |
| 1635 | 1647 |
| 1636 /** | 1648 /** |
| 1637 * @param {Function} nativeConstructor | 1649 * @param {Function} nativeConstructor |
| 1638 * @param {Function} wrapperConstructor | 1650 * @param {Function} wrapperConstructor |
| 1639 * @param {Object=} opt_instance If present, this is used to extract | 1651 * @param {Object=} opt_instance If present, this is used to extract |
| 1640 * properties from an instance object. | 1652 * properties from an instance object. |
| 1641 */ | 1653 */ |
| 1642 function register(nativeConstructor, wrapperConstructor, opt_instance) { | 1654 function register(nativeConstructor, wrapperConstructor, opt_instance) { |
| 1643 var nativePrototype = nativeConstructor.prototype; | 1655 var nativePrototype = nativeConstructor.prototype; |
| 1644 registerInternal(nativePrototype, wrapperConstructor, opt_instance); | 1656 registerInternal(nativePrototype, wrapperConstructor, opt_instance); |
| 1645 mixinStatics(wrapperConstructor, nativeConstructor); | 1657 mixinStatics(wrapperConstructor, nativeConstructor); |
| 1646 } | 1658 } |
| 1647 | 1659 |
| 1648 function registerInternal(nativePrototype, wrapperConstructor, opt_instance) { | 1660 function registerInternal(nativePrototype, wrapperConstructor, opt_instance) { |
| 1649 var wrapperPrototype = wrapperConstructor.prototype; | 1661 var wrapperPrototype = wrapperConstructor.prototype; |
| 1650 assert(constructorTable.get(nativePrototype) === undefined); | 1662 assert(constructorTable.get(nativePrototype) === undefined); |
| 1651 | 1663 |
| 1652 constructorTable.set(nativePrototype, wrapperConstructor); | 1664 constructorTable.set(nativePrototype, wrapperConstructor); |
| 1653 nativePrototypeTable.set(wrapperPrototype, nativePrototype); | 1665 nativePrototypeTable.set(wrapperPrototype, nativePrototype); |
| 1654 | 1666 |
| 1655 addForwardingProperties(nativePrototype, wrapperPrototype); | 1667 addForwardingProperties(nativePrototype, wrapperPrototype); |
| 1656 if (opt_instance) | 1668 if (opt_instance) |
| 1657 registerInstanceProperties(wrapperPrototype, opt_instance); | 1669 registerInstanceProperties(wrapperPrototype, opt_instance); |
| 1670 defineProperty(wrapperPrototype, 'constructor', { |
| 1671 value: wrapperConstructor, |
| 1672 configurable: true, |
| 1673 enumerable: false, |
| 1674 writable: true |
| 1675 }); |
| 1658 } | 1676 } |
| 1659 | 1677 |
| 1660 function isWrapperFor(wrapperConstructor, nativeConstructor) { | 1678 function isWrapperFor(wrapperConstructor, nativeConstructor) { |
| 1661 return constructorTable.get(nativeConstructor.prototype) === | 1679 return constructorTable.get(nativeConstructor.prototype) === |
| 1662 wrapperConstructor; | 1680 wrapperConstructor; |
| 1663 } | 1681 } |
| 1664 | 1682 |
| 1665 /** | 1683 /** |
| 1666 * Creates a generic wrapper constructor based on |object| and its | 1684 * Creates a generic wrapper constructor based on |object| and its |
| 1667 * constructor. | 1685 * constructor. |
| 1668 * Sometimes the constructor does not have an associated instance | |
| 1669 * (CharacterData for example). In that case you can pass the constructor that | |
| 1670 * you want to map the object to using |opt_nativeConstructor|. | |
| 1671 * @param {Node} object | 1686 * @param {Node} object |
| 1672 * @param {Function=} opt_nativeConstructor | |
| 1673 * @return {Function} The generated constructor. | 1687 * @return {Function} The generated constructor. |
| 1674 */ | 1688 */ |
| 1675 function registerObject(object) { | 1689 function registerObject(object) { |
| 1676 var nativePrototype = Object.getPrototypeOf(object); | 1690 var nativePrototype = Object.getPrototypeOf(object); |
| 1677 | 1691 |
| 1678 var superWrapperConstructor = getWrapperConstructor(nativePrototype); | 1692 var superWrapperConstructor = getWrapperConstructor(nativePrototype); |
| 1679 var GeneratedWrapper = createWrapperConstructor(superWrapperConstructor); | 1693 var GeneratedWrapper = createWrapperConstructor(superWrapperConstructor); |
| 1680 registerInternal(nativePrototype, GeneratedWrapper, object); | 1694 registerInternal(nativePrototype, GeneratedWrapper, object); |
| 1681 | 1695 |
| 1682 return GeneratedWrapper; | 1696 return GeneratedWrapper; |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1775 */ | 1789 */ |
| 1776 function rewrap(node, wrapper) { | 1790 function rewrap(node, wrapper) { |
| 1777 if (wrapper === null) | 1791 if (wrapper === null) |
| 1778 return; | 1792 return; |
| 1779 assert(isNative(node)); | 1793 assert(isNative(node)); |
| 1780 assert(wrapper === undefined || isWrapper(wrapper)); | 1794 assert(wrapper === undefined || isWrapper(wrapper)); |
| 1781 node.polymerWrapper_ = wrapper; | 1795 node.polymerWrapper_ = wrapper; |
| 1782 } | 1796 } |
| 1783 | 1797 |
| 1784 function defineGetter(constructor, name, getter) { | 1798 function defineGetter(constructor, name, getter) { |
| 1785 Object.defineProperty(constructor.prototype, name, { | 1799 defineProperty(constructor.prototype, name, { |
| 1786 get: getter, | 1800 get: getter, |
| 1787 configurable: true, | 1801 configurable: true, |
| 1788 enumerable: true | 1802 enumerable: true |
| 1789 }); | 1803 }); |
| 1790 } | 1804 } |
| 1791 | 1805 |
| 1792 function defineWrapGetter(constructor, name) { | 1806 function defineWrapGetter(constructor, name) { |
| 1793 defineGetter(constructor, name, function() { | 1807 defineGetter(constructor, name, function() { |
| 1794 return wrap(this.impl[name]); | 1808 return wrap(this.impl[name]); |
| 1795 }); | 1809 }); |
| (...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2430 } | 2444 } |
| 2431 | 2445 |
| 2432 function enclosedBy(a, b) { | 2446 function enclosedBy(a, b) { |
| 2433 if (a === b) | 2447 if (a === b) |
| 2434 return true; | 2448 return true; |
| 2435 if (a instanceof wrappers.ShadowRoot) | 2449 if (a instanceof wrappers.ShadowRoot) |
| 2436 return enclosedBy(rootOfNode(a.host), b); | 2450 return enclosedBy(rootOfNode(a.host), b); |
| 2437 return false; | 2451 return false; |
| 2438 } | 2452 } |
| 2439 | 2453 |
| 2440 var mutationEventsAreSilenced = 0; | |
| 2441 | |
| 2442 function muteMutationEvents() { | |
| 2443 mutationEventsAreSilenced++; | |
| 2444 } | |
| 2445 | |
| 2446 function unmuteMutationEvents() { | |
| 2447 mutationEventsAreSilenced--; | |
| 2448 } | |
| 2449 | |
| 2450 var OriginalMutationEvent = window.MutationEvent; | |
| 2451 | 2454 |
| 2452 function dispatchOriginalEvent(originalEvent) { | 2455 function dispatchOriginalEvent(originalEvent) { |
| 2453 // Make sure this event is only dispatched once. | 2456 // Make sure this event is only dispatched once. |
| 2454 if (handledEventsTable.get(originalEvent)) | 2457 if (handledEventsTable.get(originalEvent)) |
| 2455 return; | 2458 return; |
| 2456 handledEventsTable.set(originalEvent, true); | 2459 handledEventsTable.set(originalEvent, true); |
| 2457 | 2460 |
| 2458 // Don't do rendering if this is a mutation event since rendering might | 2461 // Render before dispatching the event to ensure that the event path is |
| 2459 // mutate the DOM which would fire more events and we would most likely | 2462 // correct. |
| 2460 // just iloop. | 2463 scope.renderAllPending(); |
| 2461 if (originalEvent instanceof OriginalMutationEvent) { | |
| 2462 if (mutationEventsAreSilenced) | |
| 2463 return; | |
| 2464 } else { | |
| 2465 scope.renderAllPending(); | |
| 2466 } | |
| 2467 | 2464 |
| 2468 var target = wrap(originalEvent.target); | 2465 var target = wrap(originalEvent.target); |
| 2469 var event = wrap(originalEvent); | 2466 var event = wrap(originalEvent); |
| 2470 return dispatchEvent(event, target); | 2467 return dispatchEvent(event, target); |
| 2471 } | 2468 } |
| 2472 | 2469 |
| 2473 function dispatchEvent(event, originalWrapperTarget) { | 2470 function dispatchEvent(event, originalWrapperTarget) { |
| 2474 var eventPath = retarget(originalWrapperTarget); | 2471 var eventPath = retarget(originalWrapperTarget); |
| 2475 | 2472 |
| 2476 // For window load events the load event is dispatched at the window but | 2473 // For window load events the load event is dispatched at the window but |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2626 }, | 2623 }, |
| 2627 get removed() { | 2624 get removed() { |
| 2628 return this.handler === null; | 2625 return this.handler === null; |
| 2629 }, | 2626 }, |
| 2630 remove: function() { | 2627 remove: function() { |
| 2631 this.handler = null; | 2628 this.handler = null; |
| 2632 } | 2629 } |
| 2633 }; | 2630 }; |
| 2634 | 2631 |
| 2635 var OriginalEvent = window.Event; | 2632 var OriginalEvent = window.Event; |
| 2633 OriginalEvent.prototype.polymerBlackList_ = {returnValue: true}; |
| 2636 | 2634 |
| 2637 /** | 2635 /** |
| 2638 * Creates a new Event wrapper or wraps an existin native Event object. | 2636 * Creates a new Event wrapper or wraps an existin native Event object. |
| 2639 * @param {string|Event} type | 2637 * @param {string|Event} type |
| 2640 * @param {Object=} options | 2638 * @param {Object=} options |
| 2641 * @constructor | 2639 * @constructor |
| 2642 */ | 2640 */ |
| 2643 function Event(type, options) { | 2641 function Event(type, options) { |
| 2644 if (type instanceof OriginalEvent) | 2642 if (type instanceof OriginalEvent) |
| 2645 this.impl = type; | 2643 this.impl = type; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2741 initMouseEvent: getInitFunction('initMouseEvent', 14) | 2739 initMouseEvent: getInitFunction('initMouseEvent', 14) |
| 2742 }, relatedTargetProto); | 2740 }, relatedTargetProto); |
| 2743 | 2741 |
| 2744 var focusEventProto = mixin({ | 2742 var focusEventProto = mixin({ |
| 2745 initFocusEvent: getInitFunction('initFocusEvent', 5) | 2743 initFocusEvent: getInitFunction('initFocusEvent', 5) |
| 2746 }, relatedTargetProto); | 2744 }, relatedTargetProto); |
| 2747 | 2745 |
| 2748 var MouseEvent = registerGenericEvent('MouseEvent', UIEvent, mouseEventProto); | 2746 var MouseEvent = registerGenericEvent('MouseEvent', UIEvent, mouseEventProto); |
| 2749 var FocusEvent = registerGenericEvent('FocusEvent', UIEvent, focusEventProto); | 2747 var FocusEvent = registerGenericEvent('FocusEvent', UIEvent, focusEventProto); |
| 2750 | 2748 |
| 2751 var MutationEvent = registerGenericEvent('MutationEvent', Event, { | |
| 2752 initMutationEvent: getInitFunction('initMutationEvent', 3), | |
| 2753 get relatedNode() { | |
| 2754 return wrap(this.impl.relatedNode); | |
| 2755 }, | |
| 2756 }); | |
| 2757 | |
| 2758 // In case the browser does not support event constructors we polyfill that | 2749 // In case the browser does not support event constructors we polyfill that |
| 2759 // by calling `createEvent('Foo')` and `initFooEvent` where the arguments to | 2750 // by calling `createEvent('Foo')` and `initFooEvent` where the arguments to |
| 2760 // `initFooEvent` are derived from the registered default event init dict. | 2751 // `initFooEvent` are derived from the registered default event init dict. |
| 2761 var defaultInitDicts = Object.create(null); | 2752 var defaultInitDicts = Object.create(null); |
| 2762 | 2753 |
| 2763 var supportsEventConstructors = (function() { | 2754 var supportsEventConstructors = (function() { |
| 2764 try { | 2755 try { |
| 2765 new window.MouseEvent('click'); | 2756 new window.MouseEvent('click'); |
| 2766 } catch (ex) { | 2757 } catch (ex) { |
| 2767 return false; | 2758 return false; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2814 ctrlKey: false, | 2805 ctrlKey: false, |
| 2815 altKey: false, | 2806 altKey: false, |
| 2816 shiftKey: false, | 2807 shiftKey: false, |
| 2817 metaKey: false, | 2808 metaKey: false, |
| 2818 button: 0, | 2809 button: 0, |
| 2819 relatedTarget: null | 2810 relatedTarget: null |
| 2820 }, 'UIEvent'); | 2811 }, 'UIEvent'); |
| 2821 configureEventConstructor('FocusEvent', {relatedTarget: null}, 'UIEvent'); | 2812 configureEventConstructor('FocusEvent', {relatedTarget: null}, 'UIEvent'); |
| 2822 } | 2813 } |
| 2823 | 2814 |
| 2815 function BeforeUnloadEvent(impl) { |
| 2816 Event.call(this); |
| 2817 } |
| 2818 BeforeUnloadEvent.prototype = Object.create(Event.prototype); |
| 2819 mixin(BeforeUnloadEvent.prototype, { |
| 2820 get returnValue() { |
| 2821 return this.impl.returnValue; |
| 2822 }, |
| 2823 set returnValue(v) { |
| 2824 this.impl.returnValue = v; |
| 2825 } |
| 2826 }); |
| 2827 |
| 2824 function isValidListener(fun) { | 2828 function isValidListener(fun) { |
| 2825 if (typeof fun === 'function') | 2829 if (typeof fun === 'function') |
| 2826 return true; | 2830 return true; |
| 2827 return fun && fun.handleEvent; | 2831 return fun && fun.handleEvent; |
| 2828 } | 2832 } |
| 2829 | 2833 |
| 2834 function isMutationEvent(type) { |
| 2835 switch (type) { |
| 2836 case 'DOMAttrModified': |
| 2837 case 'DOMAttributeNameChanged': |
| 2838 case 'DOMCharacterDataModified': |
| 2839 case 'DOMElementNameChanged': |
| 2840 case 'DOMNodeInserted': |
| 2841 case 'DOMNodeInsertedIntoDocument': |
| 2842 case 'DOMNodeRemoved': |
| 2843 case 'DOMNodeRemovedFromDocument': |
| 2844 case 'DOMSubtreeModified': |
| 2845 return true; |
| 2846 } |
| 2847 return false; |
| 2848 } |
| 2849 |
| 2830 var OriginalEventTarget = window.EventTarget; | 2850 var OriginalEventTarget = window.EventTarget; |
| 2831 | 2851 |
| 2832 /** | 2852 /** |
| 2833 * This represents a wrapper for an EventTarget. | 2853 * This represents a wrapper for an EventTarget. |
| 2834 * @param {!EventTarget} impl The original event target. | 2854 * @param {!EventTarget} impl The original event target. |
| 2835 * @constructor | 2855 * @constructor |
| 2836 */ | 2856 */ |
| 2837 function EventTarget(impl) { | 2857 function EventTarget(impl) { |
| 2838 this.impl = impl; | 2858 this.impl = impl; |
| 2839 } | 2859 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2854 }); | 2874 }); |
| 2855 | 2875 |
| 2856 function getTargetToListenAt(wrapper) { | 2876 function getTargetToListenAt(wrapper) { |
| 2857 if (wrapper instanceof wrappers.ShadowRoot) | 2877 if (wrapper instanceof wrappers.ShadowRoot) |
| 2858 wrapper = wrapper.host; | 2878 wrapper = wrapper.host; |
| 2859 return unwrap(wrapper); | 2879 return unwrap(wrapper); |
| 2860 } | 2880 } |
| 2861 | 2881 |
| 2862 EventTarget.prototype = { | 2882 EventTarget.prototype = { |
| 2863 addEventListener: function(type, fun, capture) { | 2883 addEventListener: function(type, fun, capture) { |
| 2864 if (!isValidListener(fun)) | 2884 if (!isValidListener(fun) || isMutationEvent(type)) |
| 2865 return; | 2885 return; |
| 2866 | 2886 |
| 2867 var listener = new Listener(type, fun, capture); | 2887 var listener = new Listener(type, fun, capture); |
| 2868 var listeners = listenersTable.get(this); | 2888 var listeners = listenersTable.get(this); |
| 2869 if (!listeners) { | 2889 if (!listeners) { |
| 2870 listeners = []; | 2890 listeners = []; |
| 2871 listenersTable.set(this, listeners); | 2891 listenersTable.set(this, listeners); |
| 2872 } else { | 2892 } else { |
| 2873 // Might have a duplicate. | 2893 // Might have a duplicate. |
| 2874 for (var i = 0; i < listeners.length; i++) { | 2894 for (var i = 0; i < listeners.length; i++) { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2984 wrapped: wrapped | 3004 wrapped: wrapped |
| 2985 }; | 3005 }; |
| 2986 } | 3006 } |
| 2987 }; | 3007 }; |
| 2988 } | 3008 } |
| 2989 | 3009 |
| 2990 scope.adjustRelatedTarget = adjustRelatedTarget; | 3010 scope.adjustRelatedTarget = adjustRelatedTarget; |
| 2991 scope.elementFromPoint = elementFromPoint; | 3011 scope.elementFromPoint = elementFromPoint; |
| 2992 scope.getEventHandlerGetter = getEventHandlerGetter; | 3012 scope.getEventHandlerGetter = getEventHandlerGetter; |
| 2993 scope.getEventHandlerSetter = getEventHandlerSetter; | 3013 scope.getEventHandlerSetter = getEventHandlerSetter; |
| 2994 scope.muteMutationEvents = muteMutationEvents; | |
| 2995 scope.unmuteMutationEvents = unmuteMutationEvents; | |
| 2996 scope.wrapEventTargetMethods = wrapEventTargetMethods; | 3014 scope.wrapEventTargetMethods = wrapEventTargetMethods; |
| 3015 scope.wrappers.BeforeUnloadEvent = BeforeUnloadEvent; |
| 2997 scope.wrappers.CustomEvent = CustomEvent; | 3016 scope.wrappers.CustomEvent = CustomEvent; |
| 2998 scope.wrappers.Event = Event; | 3017 scope.wrappers.Event = Event; |
| 2999 scope.wrappers.EventTarget = EventTarget; | 3018 scope.wrappers.EventTarget = EventTarget; |
| 3000 scope.wrappers.FocusEvent = FocusEvent; | 3019 scope.wrappers.FocusEvent = FocusEvent; |
| 3001 scope.wrappers.MouseEvent = MouseEvent; | 3020 scope.wrappers.MouseEvent = MouseEvent; |
| 3002 scope.wrappers.MutationEvent = MutationEvent; | |
| 3003 scope.wrappers.UIEvent = UIEvent; | 3021 scope.wrappers.UIEvent = UIEvent; |
| 3004 | 3022 |
| 3005 })(window.ShadowDOMPolyfill); | 3023 })(window.ShadowDOMPolyfill); |
| 3006 | 3024 |
| 3007 // Copyright 2012 The Polymer Authors. All rights reserved. | 3025 // Copyright 2012 The Polymer Authors. All rights reserved. |
| 3008 // Use of this source code is goverened by a BSD-style | 3026 // Use of this source code is goverened by a BSD-style |
| 3009 // license that can be found in the LICENSE file. | 3027 // license that can be found in the LICENSE file. |
| 3010 | 3028 |
| 3011 (function(scope) { | 3029 (function(scope) { |
| 3012 'use strict'; | 3030 'use strict'; |
| (...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4358 // Copyright 2013 The Polymer Authors. All rights reserved. | 4376 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 4359 // Use of this source code is goverened by a BSD-style | 4377 // Use of this source code is goverened by a BSD-style |
| 4360 // license that can be found in the LICENSE file. | 4378 // license that can be found in the LICENSE file. |
| 4361 | 4379 |
| 4362 (function(scope) { | 4380 (function(scope) { |
| 4363 'use strict'; | 4381 'use strict'; |
| 4364 | 4382 |
| 4365 var HTMLElement = scope.wrappers.HTMLElement; | 4383 var HTMLElement = scope.wrappers.HTMLElement; |
| 4366 var getInnerHTML = scope.getInnerHTML; | 4384 var getInnerHTML = scope.getInnerHTML; |
| 4367 var mixin = scope.mixin; | 4385 var mixin = scope.mixin; |
| 4368 var muteMutationEvents = scope.muteMutationEvents; | |
| 4369 var registerWrapper = scope.registerWrapper; | 4386 var registerWrapper = scope.registerWrapper; |
| 4370 var setInnerHTML = scope.setInnerHTML; | 4387 var setInnerHTML = scope.setInnerHTML; |
| 4371 var unmuteMutationEvents = scope.unmuteMutationEvents; | |
| 4372 var unwrap = scope.unwrap; | 4388 var unwrap = scope.unwrap; |
| 4373 var wrap = scope.wrap; | 4389 var wrap = scope.wrap; |
| 4374 | 4390 |
| 4375 var contentTable = new WeakMap(); | 4391 var contentTable = new WeakMap(); |
| 4376 var templateContentsOwnerTable = new WeakMap(); | 4392 var templateContentsOwnerTable = new WeakMap(); |
| 4377 | 4393 |
| 4378 // http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/templates/index.html#
dfn-template-contents-owner | 4394 // http://dvcs.w3.org/hg/webcomponents/raw-file/tip/spec/templates/index.html#
dfn-template-contents-owner |
| 4379 function getTemplateContentsOwner(doc) { | 4395 function getTemplateContentsOwner(doc) { |
| 4380 if (!doc.defaultView) | 4396 if (!doc.defaultView) |
| 4381 return doc; | 4397 return doc; |
| 4382 var d = templateContentsOwnerTable.get(doc); | 4398 var d = templateContentsOwnerTable.get(doc); |
| 4383 if (!d) { | 4399 if (!d) { |
| 4384 // TODO(arv): This should either be a Document or HTMLDocument depending | 4400 // TODO(arv): This should either be a Document or HTMLDocument depending |
| 4385 // on doc. | 4401 // on doc. |
| 4386 d = doc.implementation.createHTMLDocument(''); | 4402 d = doc.implementation.createHTMLDocument(''); |
| 4387 while (d.lastChild) { | 4403 while (d.lastChild) { |
| 4388 d.removeChild(d.lastChild); | 4404 d.removeChild(d.lastChild); |
| 4389 } | 4405 } |
| 4390 templateContentsOwnerTable.set(doc, d); | 4406 templateContentsOwnerTable.set(doc, d); |
| 4391 } | 4407 } |
| 4392 return d; | 4408 return d; |
| 4393 } | 4409 } |
| 4394 | 4410 |
| 4395 function extractContent(templateElement) { | 4411 function extractContent(templateElement) { |
| 4396 // templateElement is not a wrapper here. | 4412 // templateElement is not a wrapper here. |
| 4397 var doc = getTemplateContentsOwner(templateElement.ownerDocument); | 4413 var doc = getTemplateContentsOwner(templateElement.ownerDocument); |
| 4398 var df = unwrap(doc.createDocumentFragment()); | 4414 var df = unwrap(doc.createDocumentFragment()); |
| 4399 var child; | 4415 var child; |
| 4400 muteMutationEvents(); | |
| 4401 while (child = templateElement.firstChild) { | 4416 while (child = templateElement.firstChild) { |
| 4402 df.appendChild(child); | 4417 df.appendChild(child); |
| 4403 } | 4418 } |
| 4404 unmuteMutationEvents(); | |
| 4405 return df; | 4419 return df; |
| 4406 } | 4420 } |
| 4407 | 4421 |
| 4408 var OriginalHTMLTemplateElement = window.HTMLTemplateElement; | 4422 var OriginalHTMLTemplateElement = window.HTMLTemplateElement; |
| 4409 | 4423 |
| 4410 function HTMLTemplateElement(node) { | 4424 function HTMLTemplateElement(node) { |
| 4411 HTMLElement.call(this, node); | 4425 HTMLElement.call(this, node); |
| 4412 if (!OriginalHTMLTemplateElement) { | 4426 if (!OriginalHTMLTemplateElement) { |
| 4413 var content = extractContent(node); | 4427 var content = extractContent(node); |
| 4414 contentTable.set(this, wrap(content)); | 4428 contentTable.set(this, wrap(content)); |
| (...skipping 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4887 (function(scope) { | 4901 (function(scope) { |
| 4888 'use strict'; | 4902 'use strict'; |
| 4889 | 4903 |
| 4890 var Element = scope.wrappers.Element; | 4904 var Element = scope.wrappers.Element; |
| 4891 var HTMLContentElement = scope.wrappers.HTMLContentElement; | 4905 var HTMLContentElement = scope.wrappers.HTMLContentElement; |
| 4892 var HTMLShadowElement = scope.wrappers.HTMLShadowElement; | 4906 var HTMLShadowElement = scope.wrappers.HTMLShadowElement; |
| 4893 var Node = scope.wrappers.Node; | 4907 var Node = scope.wrappers.Node; |
| 4894 var ShadowRoot = scope.wrappers.ShadowRoot; | 4908 var ShadowRoot = scope.wrappers.ShadowRoot; |
| 4895 var assert = scope.assert; | 4909 var assert = scope.assert; |
| 4896 var mixin = scope.mixin; | 4910 var mixin = scope.mixin; |
| 4897 var muteMutationEvents = scope.muteMutationEvents; | |
| 4898 var oneOf = scope.oneOf; | 4911 var oneOf = scope.oneOf; |
| 4899 var unmuteMutationEvents = scope.unmuteMutationEvents; | |
| 4900 var unwrap = scope.unwrap; | 4912 var unwrap = scope.unwrap; |
| 4901 var wrap = scope.wrap; | 4913 var wrap = scope.wrap; |
| 4902 | 4914 |
| 4903 /** | 4915 /** |
| 4904 * Updates the fields of a wrapper to a snapshot of the logical DOM as needed. | 4916 * Updates the fields of a wrapper to a snapshot of the logical DOM as needed. |
| 4905 * Up means parentNode | 4917 * Up means parentNode |
| 4906 * Sideways means previous and next sibling. | 4918 * Sideways means previous and next sibling. |
| 4907 * @param {!Node} wrapper | 4919 * @param {!Node} wrapper |
| 4908 */ | 4920 */ |
| 4909 function updateWrapperUpAndSideways(wrapper) { | 4921 function updateWrapperUpAndSideways(wrapper) { |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5233 var shadowRoot = host.shadowRoot; | 5245 var shadowRoot = host.shadowRoot; |
| 5234 | 5246 |
| 5235 this.associateNode(host); | 5247 this.associateNode(host); |
| 5236 var topMostRenderer = !renderNode; | 5248 var topMostRenderer = !renderNode; |
| 5237 var renderNode = opt_renderNode || new RenderNode(host); | 5249 var renderNode = opt_renderNode || new RenderNode(host); |
| 5238 | 5250 |
| 5239 for (var node = shadowRoot.firstChild; node; node = node.nextSibling) { | 5251 for (var node = shadowRoot.firstChild; node; node = node.nextSibling) { |
| 5240 this.renderNode(shadowRoot, renderNode, node, false); | 5252 this.renderNode(shadowRoot, renderNode, node, false); |
| 5241 } | 5253 } |
| 5242 | 5254 |
| 5243 if (topMostRenderer) { | 5255 if (topMostRenderer) |
| 5244 //muteMutationEvents(); | |
| 5245 renderNode.sync(); | 5256 renderNode.sync(); |
| 5246 //unmuteMutationEvents(); | |
| 5247 } | |
| 5248 | 5257 |
| 5249 this.dirty = false; | 5258 this.dirty = false; |
| 5250 }, | 5259 }, |
| 5251 | 5260 |
| 5252 invalidate: function() { | 5261 invalidate: function() { |
| 5253 if (!this.dirty) { | 5262 if (!this.dirty) { |
| 5254 this.dirty = true; | 5263 this.dirty = true; |
| 5255 pendingDirtyRenderers.push(this); | 5264 pendingDirtyRenderers.push(this); |
| 5256 if (renderTimer) | 5265 if (renderTimer) |
| 5257 return; | 5266 return; |
| (...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5672 adoptSubtree(child, doc); | 5681 adoptSubtree(child, doc); |
| 5673 } | 5682 } |
| 5674 } | 5683 } |
| 5675 | 5684 |
| 5676 function adoptOlderShadowRoots(shadowRoot, doc) { | 5685 function adoptOlderShadowRoots(shadowRoot, doc) { |
| 5677 var oldShadowRoot = shadowRoot.olderShadowRoot; | 5686 var oldShadowRoot = shadowRoot.olderShadowRoot; |
| 5678 if (oldShadowRoot) | 5687 if (oldShadowRoot) |
| 5679 doc.adoptNode(oldShadowRoot); | 5688 doc.adoptNode(oldShadowRoot); |
| 5680 } | 5689 } |
| 5681 | 5690 |
| 5691 var originalImportNode = document.importNode; |
| 5692 |
| 5682 mixin(Document.prototype, { | 5693 mixin(Document.prototype, { |
| 5683 adoptNode: function(node) { | 5694 adoptNode: function(node) { |
| 5684 if (node.parentNode) | 5695 if (node.parentNode) |
| 5685 node.parentNode.removeChild(node); | 5696 node.parentNode.removeChild(node); |
| 5686 adoptNodeNoRemove(node, this); | 5697 adoptNodeNoRemove(node, this); |
| 5687 return node; | 5698 return node; |
| 5688 }, | 5699 }, |
| 5689 elementFromPoint: function(x, y) { | 5700 elementFromPoint: function(x, y) { |
| 5690 return elementFromPoint(this, this, x, y); | 5701 return elementFromPoint(this, this, x, y); |
| 5702 }, |
| 5703 importNode: function(node, deep) { |
| 5704 // We need to manually walk the tree to ensure we do not include rendered |
| 5705 // shadow trees. |
| 5706 var clone = wrap(originalImportNode.call(this.impl, unwrap(node), false)); |
| 5707 if (deep) { |
| 5708 for (var child = node.firstChild; child; child = child.nextSibling) { |
| 5709 clone.appendChild(this.importNode(child, true)); |
| 5710 } |
| 5711 } |
| 5712 return clone; |
| 5691 } | 5713 } |
| 5692 }); | 5714 }); |
| 5693 | 5715 |
| 5694 if (document.register) { | 5716 if (document.register) { |
| 5695 var originalRegister = document.register; | 5717 var originalRegister = document.register; |
| 5696 Document.prototype.register = function(tagName, object) { | 5718 Document.prototype.register = function(tagName, object) { |
| 5697 var prototype = object.prototype; | 5719 var prototype = object.prototype; |
| 5698 | 5720 |
| 5699 // If we already used the object as a prototype for another custom | 5721 // If we already used the object as a prototype for another custom |
| 5700 // element. | 5722 // element. |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5799 'querySelectorAll', | 5821 'querySelectorAll', |
| 5800 'removeChild', | 5822 'removeChild', |
| 5801 'replaceChild', | 5823 'replaceChild', |
| 5802 matchesName, | 5824 matchesName, |
| 5803 ]); | 5825 ]); |
| 5804 | 5826 |
| 5805 forwardMethodsToWrapper([ | 5827 forwardMethodsToWrapper([ |
| 5806 window.HTMLDocument || window.Document, // Gecko adds these to HTMLDocument | 5828 window.HTMLDocument || window.Document, // Gecko adds these to HTMLDocument |
| 5807 ], [ | 5829 ], [ |
| 5808 'adoptNode', | 5830 'adoptNode', |
| 5831 'importNode', |
| 5809 'contains', | 5832 'contains', |
| 5810 'createComment', | 5833 'createComment', |
| 5811 'createDocumentFragment', | 5834 'createDocumentFragment', |
| 5812 'createElement', | 5835 'createElement', |
| 5813 'createElementNS', | 5836 'createElementNS', |
| 5814 'createEvent', | 5837 'createEvent', |
| 5815 'createEventNS', | 5838 'createEventNS', |
| 5816 'createRange', | 5839 'createRange', |
| 5817 'createTextNode', | 5840 'createTextNode', |
| 5818 'elementFromPoint', | 5841 'elementFromPoint', |
| (...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6522 * | 6545 * |
| 6523 * to | 6546 * to |
| 6524 * | 6547 * |
| 6525 * scopeName.foo .bar { ... } | 6548 * scopeName.foo .bar { ... } |
| 6526 */ | 6549 */ |
| 6527 convertColonHost: function(cssText) { | 6550 convertColonHost: function(cssText) { |
| 6528 // p1 = :host, p2 = contents of (), p3 rest of rule | 6551 // p1 = :host, p2 = contents of (), p3 rest of rule |
| 6529 return cssText.replace(cssColonHostRe, function(m, p1, p2, p3) { | 6552 return cssText.replace(cssColonHostRe, function(m, p1, p2, p3) { |
| 6530 p1 = polyfillHostNoCombinator; | 6553 p1 = polyfillHostNoCombinator; |
| 6531 if (p2) { | 6554 if (p2) { |
| 6532 if (p2.match(polyfillHost)) { | 6555 var parts = p2.split(','), r = []; |
| 6533 return p1 + p2.replace(polyfillHost, '') + p3; | 6556 for (var i=0, l=parts.length, p; (i<l) && (p=parts[i]); i++) { |
| 6534 } else { | 6557 p = p.trim(); |
| 6535 return p1 + p2 + p3 + ', ' + p2 + ' ' + p1 + p3; | 6558 if (p.match(polyfillHost)) { |
| 6559 r.push(p1 + p.replace(polyfillHost, '') + p3); |
| 6560 } else { |
| 6561 r.push(p1 + p + p3 + ', ' + p + ' ' + p1 + p3); |
| 6562 } |
| 6536 } | 6563 } |
| 6564 return r.join(','); |
| 6537 } else { | 6565 } else { |
| 6538 return p1 + p3; | 6566 return p1 + p3; |
| 6539 } | 6567 } |
| 6540 }); | 6568 }); |
| 6541 }, | 6569 }, |
| 6542 /* | 6570 /* |
| 6543 * Convert ^ and ^^ combinators by replacing with space. | 6571 * Convert ^ and ^^ combinators by replacing with space. |
| 6544 */ | 6572 */ |
| 6545 convertCombinators: function(cssText) { | 6573 convertCombinators: function(cssText) { |
| 6546 return cssText.replace(/\^\^/g, ' ').replace(/\^/g, ' '); | 6574 return cssText.replace(/\^\^/g, ' ').replace(/\^/g, ' '); |
| 6547 }, | 6575 }, |
| 6548 // change a selector like 'div' to 'name div' | 6576 // change a selector like 'div' to 'name div' |
| 6549 scopeRules: function(cssRules, name, typeExtension) { | 6577 scopeRules: function(cssRules, name, typeExtension) { |
| 6550 var cssText = ''; | 6578 var cssText = ''; |
| 6551 Array.prototype.forEach.call(cssRules, function(rule) { | 6579 Array.prototype.forEach.call(cssRules, function(rule) { |
| 6552 if (rule.selectorText && (rule.style && rule.style.cssText)) { | 6580 if (rule.selectorText && (rule.style && rule.style.cssText)) { |
| 6553 cssText += this.scopeSelector(rule.selectorText, name, typeExtension, | 6581 cssText += this.scopeSelector(rule.selectorText, name, typeExtension, |
| 6554 this.strictStyling) + ' {\n\t'; | 6582 this.strictStyling) + ' {\n\t'; |
| 6555 cssText += this.propertiesFromRule(rule) + '\n}\n\n'; | 6583 cssText += this.propertiesFromRule(rule) + '\n}\n\n'; |
| 6556 } else if (rule.media) { | 6584 } else if (rule.media) { |
| 6557 cssText += '@media ' + rule.media.mediaText + ' {\n'; | 6585 cssText += '@media ' + rule.media.mediaText + ' {\n'; |
| 6558 cssText += this.scopeRules(rule.cssRules, name); | 6586 cssText += this.scopeRules(rule.cssRules, name, typeExtension); |
| 6559 cssText += '\n}\n\n'; | 6587 cssText += '\n}\n\n'; |
| 6560 } else if (rule.cssText) { | 6588 } else if (rule.cssText) { |
| 6561 cssText += rule.cssText + '\n\n'; | 6589 cssText += rule.cssText + '\n\n'; |
| 6562 } | 6590 } |
| 6563 }, this); | 6591 }, this); |
| 6564 return cssText; | 6592 return cssText; |
| 6565 }, | 6593 }, |
| 6566 scopeSelector: function(selector, name, typeExtension, strict) { | 6594 scopeSelector: function(selector, name, typeExtension, strict) { |
| 6567 var r = [], parts = selector.split(','); | 6595 var r = [], parts = selector.split(','); |
| 6568 parts.forEach(function(p) { | 6596 parts.forEach(function(p) { |
| 6569 p = p.trim(); | 6597 p = p.trim(); |
| 6570 if (this.selectorNeedsScoping(p, name, typeExtension)) { | 6598 if (this.selectorNeedsScoping(p, name, typeExtension)) { |
| 6571 p = strict ? this.applyStrictSelectorScope(p, name) : | 6599 p = (strict && !p.match(polyfillHostNoCombinator)) ? |
| 6572 this.applySimpleSelectorScope(p, name, typeExtension); | 6600 this.applyStrictSelectorScope(p, name) : |
| 6601 this.applySimpleSelectorScope(p, name, typeExtension); |
| 6573 } | 6602 } |
| 6574 r.push(p); | 6603 r.push(p); |
| 6575 }, this); | 6604 }, this); |
| 6576 return r.join(', '); | 6605 return r.join(', '); |
| 6577 }, | 6606 }, |
| 6578 selectorNeedsScoping: function(selector, name, typeExtension) { | 6607 selectorNeedsScoping: function(selector, name, typeExtension) { |
| 6579 var re = this.makeScopeMatcher(name, typeExtension); | 6608 var re = this.makeScopeMatcher(name, typeExtension); |
| 6580 return !selector.match(re); | 6609 return !selector.match(re); |
| 6581 }, | 6610 }, |
| 6582 makeScopeMatcher: function(name, typeExtension) { | 6611 makeScopeMatcher: function(name, typeExtension) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 6610 return p; | 6639 return p; |
| 6611 }).join(sep); | 6640 }).join(sep); |
| 6612 }); | 6641 }); |
| 6613 return scoped; | 6642 return scoped; |
| 6614 }, | 6643 }, |
| 6615 insertPolyfillHostInCssText: function(selector) { | 6644 insertPolyfillHostInCssText: function(selector) { |
| 6616 return selector.replace(hostRe, polyfillHost).replace(colonHostRe, | 6645 return selector.replace(hostRe, polyfillHost).replace(colonHostRe, |
| 6617 polyfillHost); | 6646 polyfillHost); |
| 6618 }, | 6647 }, |
| 6619 propertiesFromRule: function(rule) { | 6648 propertiesFromRule: function(rule) { |
| 6620 var properties = rule.style.cssText; | 6649 return rule.style.cssText; |
| 6621 // TODO(sorvell): Chrome cssom incorrectly removes quotes from the content | |
| 6622 // property. (https://code.google.com/p/chromium/issues/detail?id=247231) | |
| 6623 if (rule.style.content && !rule.style.content.match(/['"]+/)) { | |
| 6624 properties = 'content: \'' + rule.style.content + '\';\n' + | |
| 6625 rule.style.cssText.replace(/content:[^;]*;/g, ''); | |
| 6626 } | |
| 6627 return properties; | |
| 6628 } | 6650 } |
| 6629 }; | 6651 }; |
| 6630 | 6652 |
| 6631 var hostRuleRe = /@host[^{]*{(([^}]*?{[^{]*?}[\s\S]*?)+)}/gim, | 6653 var hostRuleRe = /@host[^{]*{(([^}]*?{[^{]*?}[\s\S]*?)+)}/gim, |
| 6632 selectorRe = /([^{]*)({[\s\S]*?})/gim, | 6654 selectorRe = /([^{]*)({[\s\S]*?})/gim, |
| 6633 hostElementRe = /(.*)((?:\*)|(?:\:scope))(.*)/, | 6655 hostElementRe = /(.*)((?:\*)|(?:\:scope))(.*)/, |
| 6634 hostFixableRe = /^[.\[:]/, | 6656 hostFixableRe = /^[.\[:]/, |
| 6635 cssCommentRe = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//gim, | 6657 cssCommentRe = /\/\*[^*]*\*+([^/*][^*]*\*+)*\//gim, |
| 6636 cssPolyfillCommentRe = /\/\*\s*@polyfill ([^*]*\*+([^/*][^*]*\*+)*\/)([^{]*?
){/gim, | 6658 cssPolyfillCommentRe = /\/\*\s*@polyfill ([^*]*\*+([^/*][^*]*\*+)*\/)([^{]*?
){/gim, |
| 6637 cssPolyfillRuleCommentRe = /\/\*\s@polyfill-rule([^*]*\*+([^/*][^*]*\*+)*)\/
/gim, | 6659 cssPolyfillRuleCommentRe = /\/\*\s@polyfill-rule([^*]*\*+([^/*][^*]*\*+)*)\/
/gim, |
| 6638 cssPolyfillUnscopedRuleCommentRe = /\/\*\s@polyfill-unscoped-rule([^*]*\*+([
^/*][^*]*\*+)*)\//gim, | 6660 cssPolyfillUnscopedRuleCommentRe = /\/\*\s@polyfill-unscoped-rule([^*]*\*+([
^/*][^*]*\*+)*)\//gim, |
| 6639 cssPseudoRe = /::(x-[^\s{,(]*)/gim, | 6661 cssPseudoRe = /::(x-[^\s{,(]*)/gim, |
| 6640 cssPartRe = /::part\(([^)]*)\)/gim, | 6662 cssPartRe = /::part\(([^)]*)\)/gim, |
| 6641 // note: :host pre-processed to -host. | 6663 // note: :host pre-processed to -shadowcsshost. |
| 6642 cssColonHostRe = /(-host)(?:\(([^)]*)\))?([^,{]*)/gim, | 6664 polyfillHost = '-shadowcsshost', |
| 6665 cssColonHostRe = new RegExp('(' + polyfillHost + |
| 6666 ')(?:\\((' + |
| 6667 '(?:\\([^)(]*\\)|[^)(]*)+?' + |
| 6668 ')\\))?([^,{]*)', 'gim'), |
| 6643 selectorReSuffix = '([>\\s~+\[.,{:][\\s\\S]*)?$', | 6669 selectorReSuffix = '([>\\s~+\[.,{:][\\s\\S]*)?$', |
| 6644 hostRe = /@host/gim, | 6670 hostRe = /@host/gim, |
| 6645 colonHostRe = /\:host/gim, | 6671 colonHostRe = /\:host/gim, |
| 6646 polyfillHost = '-host', | |
| 6647 /* host name without combinator */ | 6672 /* host name without combinator */ |
| 6648 polyfillHostNoCombinator = '-host-no-combinator', | 6673 polyfillHostNoCombinator = polyfillHost + '-no-combinator', |
| 6649 polyfillHostRe = /-host/gim; | 6674 polyfillHostRe = new RegExp(polyfillHost, 'gim'); |
| 6650 | 6675 |
| 6651 function stylesToCssText(styles, preserveComments) { | 6676 function stylesToCssText(styles, preserveComments) { |
| 6652 var cssText = ''; | 6677 var cssText = ''; |
| 6653 Array.prototype.forEach.call(styles, function(s) { | 6678 Array.prototype.forEach.call(styles, function(s) { |
| 6654 cssText += s.textContent + '\n\n'; | 6679 cssText += s.textContent + '\n\n'; |
| 6655 }); | 6680 }); |
| 6656 // strip comments for easier processing | 6681 // strip comments for easier processing |
| 6657 if (!preserveComments) { | 6682 if (!preserveComments) { |
| 6658 cssText = cssText.replace(cssCommentRe, ''); | 6683 cssText = cssText.replace(cssCommentRe, ''); |
| 6659 } | 6684 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6701 addCssToDocument('style { display: none !important; }\n'); | 6726 addCssToDocument('style { display: none !important; }\n'); |
| 6702 var head = document.querySelector('head'); | 6727 var head = document.querySelector('head'); |
| 6703 head.insertBefore(getSheet(), head.childNodes[0]); | 6728 head.insertBefore(getSheet(), head.childNodes[0]); |
| 6704 } | 6729 } |
| 6705 | 6730 |
| 6706 // exports | 6731 // exports |
| 6707 scope.ShadowCSS = ShadowCSS; | 6732 scope.ShadowCSS = ShadowCSS; |
| 6708 | 6733 |
| 6709 })(window.Platform); | 6734 })(window.Platform); |
| 6710 } | 6735 } |
| OLD | NEW |