| 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 1444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1455 }; | 1455 }; |
| 1456 | 1456 |
| 1457 window.WeakMap = WeakMap; | 1457 window.WeakMap = WeakMap; |
| 1458 })(); | 1458 })(); |
| 1459 } | 1459 } |
| 1460 | 1460 |
| 1461 // Copyright 2012 The Polymer Authors. All rights reserved. | 1461 // Copyright 2012 The Polymer Authors. All rights reserved. |
| 1462 // Use of this source code is goverened by a BSD-style | 1462 // Use of this source code is goverened by a BSD-style |
| 1463 // license that can be found in the LICENSE file. | 1463 // license that can be found in the LICENSE file. |
| 1464 | 1464 |
| 1465 var ShadowDOMPolyfill = {}; | 1465 window.ShadowDOMPolyfill = {}; |
| 1466 | 1466 |
| 1467 (function(scope) { | 1467 (function(scope) { |
| 1468 'use strict'; | 1468 'use strict'; |
| 1469 | 1469 |
| 1470 var constructorTable = new WeakMap(); | 1470 var constructorTable = new WeakMap(); |
| 1471 var nativePrototypeTable = new WeakMap(); | 1471 var nativePrototypeTable = new WeakMap(); |
| 1472 var wrappers = Object.create(null); | 1472 var wrappers = Object.create(null); |
| 1473 | 1473 |
| 1474 // Don't test for eval if document has CSP securityPolicy object and we can | 1474 // Don't test for eval if document has CSP securityPolicy object and we can |
| 1475 // see that eval is not supported. This avoids an error message in console | 1475 // see that eval is not supported. This avoids an error message in console |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1824 scope.oneOf = oneOf; | 1824 scope.oneOf = oneOf; |
| 1825 scope.registerObject = registerObject; | 1825 scope.registerObject = registerObject; |
| 1826 scope.registerWrapper = register; | 1826 scope.registerWrapper = register; |
| 1827 scope.rewrap = rewrap; | 1827 scope.rewrap = rewrap; |
| 1828 scope.unwrap = unwrap; | 1828 scope.unwrap = unwrap; |
| 1829 scope.unwrapIfNeeded = unwrapIfNeeded; | 1829 scope.unwrapIfNeeded = unwrapIfNeeded; |
| 1830 scope.wrap = wrap; | 1830 scope.wrap = wrap; |
| 1831 scope.wrapIfNeeded = wrapIfNeeded; | 1831 scope.wrapIfNeeded = wrapIfNeeded; |
| 1832 scope.wrappers = wrappers; | 1832 scope.wrappers = wrappers; |
| 1833 | 1833 |
| 1834 })(this.ShadowDOMPolyfill); | 1834 })(window.ShadowDOMPolyfill); |
| 1835 |
| 1836 /* |
| 1837 * Copyright 2013 The Polymer Authors. All rights reserved. |
| 1838 * Use of this source code is goverened by a BSD-style |
| 1839 * license that can be found in the LICENSE file. |
| 1840 */ |
| 1841 |
| 1842 (function(context) { |
| 1843 'use strict'; |
| 1844 |
| 1845 var OriginalMutationObserver = window.MutationObserver; |
| 1846 var callbacks = []; |
| 1847 var pending = false; |
| 1848 var timerFunc; |
| 1849 |
| 1850 function handle() { |
| 1851 pending = false; |
| 1852 var copies = callbacks.slice(0); |
| 1853 callbacks = []; |
| 1854 for (var i = 0; i < copies.length; i++) { |
| 1855 (0, copies[i])(); |
| 1856 } |
| 1857 } |
| 1858 |
| 1859 if (OriginalMutationObserver) { |
| 1860 var counter = 1; |
| 1861 var observer = new OriginalMutationObserver(handle); |
| 1862 var textNode = document.createTextNode(counter); |
| 1863 observer.observe(textNode, {characterData: true}); |
| 1864 |
| 1865 timerFunc = function() { |
| 1866 counter = (counter + 1) % 2; |
| 1867 textNode.data = counter; |
| 1868 }; |
| 1869 |
| 1870 } else { |
| 1871 timerFunc = window.setImmediate || window.setTimeout; |
| 1872 } |
| 1873 |
| 1874 function setEndOfMicrotask(func) { |
| 1875 callbacks.push(func); |
| 1876 if (pending) |
| 1877 return; |
| 1878 pending = true; |
| 1879 timerFunc(handle, 0); |
| 1880 } |
| 1881 |
| 1882 context.setEndOfMicrotask = setEndOfMicrotask; |
| 1883 |
| 1884 })(window.ShadowDOMPolyfill); |
| 1885 |
| 1886 /* |
| 1887 * Copyright 2013 The Polymer Authors. All rights reserved. |
| 1888 * Use of this source code is goverened by a BSD-style |
| 1889 * license that can be found in the LICENSE file. |
| 1890 */ |
| 1891 |
| 1892 (function(scope) { |
| 1893 'use strict'; |
| 1894 |
| 1895 var setEndOfMicrotask = scope.setEndOfMicrotask |
| 1896 var wrapIfNeeded = scope.wrapIfNeeded |
| 1897 var wrappers = scope.wrappers; |
| 1898 |
| 1899 var registrationsTable = new WeakMap(); |
| 1900 var globalMutationObservers = []; |
| 1901 var isScheduled = false; |
| 1902 |
| 1903 function scheduleCallback(observer) { |
| 1904 if (isScheduled) |
| 1905 return; |
| 1906 setEndOfMicrotask(notifyObservers); |
| 1907 isScheduled = true; |
| 1908 } |
| 1909 |
| 1910 // http://dom.spec.whatwg.org/#mutation-observers |
| 1911 function notifyObservers() { |
| 1912 isScheduled = false; |
| 1913 |
| 1914 do { |
| 1915 var notifyList = globalMutationObservers.slice(); |
| 1916 var anyNonEmpty = false; |
| 1917 for (var i = 0; i < notifyList.length; i++) { |
| 1918 var mo = notifyList[i]; |
| 1919 var queue = mo.takeRecords(); |
| 1920 removeTransientObserversFor(mo); |
| 1921 if (queue.length) { |
| 1922 mo.callback_(queue, mo); |
| 1923 anyNonEmpty = true; |
| 1924 } |
| 1925 } |
| 1926 } while (anyNonEmpty); |
| 1927 } |
| 1928 |
| 1929 /** |
| 1930 * @param {string} type |
| 1931 * @param {Node} target |
| 1932 * @constructor |
| 1933 */ |
| 1934 function MutationRecord(type, target) { |
| 1935 this.type = type; |
| 1936 this.target = target; |
| 1937 this.addedNodes = new wrappers.NodeList(); |
| 1938 this.removedNodes = new wrappers.NodeList(); |
| 1939 this.previousSibling = null; |
| 1940 this.nextSibling = null; |
| 1941 this.attributeName = null; |
| 1942 this.attributeNamespace = null; |
| 1943 this.oldValue = null; |
| 1944 } |
| 1945 |
| 1946 /** |
| 1947 * Registers transient observers to ancestor and its ancesors for the node |
| 1948 * which was removed. |
| 1949 * @param {!Node} ancestor |
| 1950 * @param {!Node} node |
| 1951 */ |
| 1952 function registerTransientObservers(ancestor, node) { |
| 1953 for (; ancestor; ancestor = ancestor.parentNode) { |
| 1954 var registrations = registrationsTable.get(ancestor); |
| 1955 if (!registrations) |
| 1956 continue; |
| 1957 for (var i = 0; i < registrations.length; i++) { |
| 1958 var registration = registrations[i]; |
| 1959 if (registration.options.subtree) |
| 1960 registration.addTransientObserver(node); |
| 1961 } |
| 1962 } |
| 1963 } |
| 1964 |
| 1965 function removeTransientObserversFor(observer) { |
| 1966 for (var i = 0; i < observer.nodes_.length; i++) { |
| 1967 var node = observer.nodes_[i]; |
| 1968 var registrations = registrationsTable.get(node); |
| 1969 if (!registrations) |
| 1970 return; |
| 1971 for (var j = 0; j < registrations.length; j++) { |
| 1972 var registration = registrations[j]; |
| 1973 if (registration.observer === observer) |
| 1974 registration.removeTransientObservers(); |
| 1975 } |
| 1976 } |
| 1977 } |
| 1978 |
| 1979 // http://dom.spec.whatwg.org/#queue-a-mutation-record |
| 1980 function enqueueMutation(target, type, data) { |
| 1981 // 1. |
| 1982 var interestedObservers = Object.create(null); |
| 1983 var associatedStrings = Object.create(null); |
| 1984 |
| 1985 // 2. |
| 1986 for (var node = target; node; node = node.parentNode) { |
| 1987 // 3. |
| 1988 var registrations = registrationsTable.get(node); |
| 1989 if (!registrations) |
| 1990 continue; |
| 1991 for (var j = 0; j < registrations.length; j++) { |
| 1992 var registration = registrations[j]; |
| 1993 var options = registration.options; |
| 1994 // 1. |
| 1995 if (node !== target && !options.subtree) |
| 1996 continue; |
| 1997 |
| 1998 // 2. |
| 1999 if (type === 'attributes' && !options.attributes) |
| 2000 continue; |
| 2001 |
| 2002 // 3. If type is "attributes", options's attributeFilter is present, and |
| 2003 // either options's attributeFilter does not contain name or namespace |
| 2004 // is non-null, continue. |
| 2005 if (type === 'attributes' && options.attributeFilter && |
| 2006 (data.namespace !== null || |
| 2007 options.attributeFilter.indexOf(data.name) === -1)) { |
| 2008 continue; |
| 2009 } |
| 2010 |
| 2011 // 4. |
| 2012 if (type === 'characterData' && !options.characterData) |
| 2013 continue; |
| 2014 |
| 2015 // 5. |
| 2016 if (type === 'childList' && !options.childList) |
| 2017 continue; |
| 2018 |
| 2019 // 6. |
| 2020 var observer = registration.observer; |
| 2021 interestedObservers[observer.uid_] = observer; |
| 2022 |
| 2023 // 7. If either type is "attributes" and options's attributeOldValue is |
| 2024 // true, or type is "characterData" and options's characterDataOldValue |
| 2025 // is true, set the paired string of registered observer's observer in |
| 2026 // interested observers to oldValue. |
| 2027 if (type === 'attributes' && options.attributeOldValue || |
| 2028 type === 'characterData' && options.characterDataOldValue) { |
| 2029 associatedStrings[observer.uid_] = data.oldValue; |
| 2030 } |
| 2031 } |
| 2032 } |
| 2033 |
| 2034 var anyRecordsEnqueued = false; |
| 2035 |
| 2036 // 4. |
| 2037 for (var uid in interestedObservers) { |
| 2038 var observer = interestedObservers[uid]; |
| 2039 var record = new MutationRecord(type, target); |
| 2040 |
| 2041 // 2. |
| 2042 if ('name' in data && 'namespace' in data) { |
| 2043 record.attributeName = data.name; |
| 2044 record.attributeNamespace = data.namespace; |
| 2045 } |
| 2046 |
| 2047 // 3. |
| 2048 if (data.addedNodes) |
| 2049 record.addedNodes = data.addedNodes; |
| 2050 |
| 2051 // 4. |
| 2052 if (data.removedNodes) |
| 2053 record.removedNodes = data.removedNodes; |
| 2054 |
| 2055 // 5. |
| 2056 if (data.previousSibling) |
| 2057 record.previousSibling = data.previousSibling; |
| 2058 |
| 2059 // 6. |
| 2060 if (data.nextSibling) |
| 2061 record.nextSibling = data.nextSibling; |
| 2062 |
| 2063 // 7. |
| 2064 if (associatedStrings[uid] !== undefined) |
| 2065 record.oldValue = associatedStrings[uid]; |
| 2066 |
| 2067 // 8. |
| 2068 observer.records_.push(record); |
| 2069 |
| 2070 anyRecordsEnqueued = true; |
| 2071 } |
| 2072 |
| 2073 if (anyRecordsEnqueued) |
| 2074 scheduleCallback(); |
| 2075 } |
| 2076 |
| 2077 var slice = Array.prototype.slice; |
| 2078 |
| 2079 /** |
| 2080 * @param {!Object} options |
| 2081 * @constructor |
| 2082 */ |
| 2083 function MutationObserverOptions(options) { |
| 2084 this.childList = !!options.childList; |
| 2085 this.subtree = !!options.subtree; |
| 2086 |
| 2087 // 1. If either options' attributeOldValue or attributeFilter is present |
| 2088 // and options' attributes is omitted, set options' attributes to true. |
| 2089 if (!('attributes' in options) && |
| 2090 ('attributeOldValue' in options || 'attributeFilter' in options)) { |
| 2091 this.attributes = true; |
| 2092 } else { |
| 2093 this.attributes = !!options.attributes; |
| 2094 } |
| 2095 |
| 2096 // 2. If options' characterDataOldValue is present and options' |
| 2097 // characterData is omitted, set options' characterData to true. |
| 2098 if ('characterDataOldValue' in options && !('characterData' in options)) |
| 2099 this.characterData = true; |
| 2100 else |
| 2101 this.characterData = !!options.characterData; |
| 2102 |
| 2103 // 3. & 4. |
| 2104 if (!this.attributes && |
| 2105 (options.attributeOldValue || 'attributeFilter' in options) || |
| 2106 // 5. |
| 2107 !this.characterData && options.characterDataOldValue) { |
| 2108 throw new TypeError(); |
| 2109 } |
| 2110 |
| 2111 this.characterData = !!options.characterData; |
| 2112 this.attributeOldValue = !!options.attributeOldValue; |
| 2113 this.characterDataOldValue = !!options.characterDataOldValue; |
| 2114 if ('attributeFilter' in options) { |
| 2115 if (options.attributeFilter == null || |
| 2116 typeof options.attributeFilter !== 'object') { |
| 2117 throw new TypeError(); |
| 2118 } |
| 2119 this.attributeFilter = slice.call(options.attributeFilter); |
| 2120 } else { |
| 2121 this.attributeFilter = null; |
| 2122 } |
| 2123 } |
| 2124 |
| 2125 var uidCounter = 0; |
| 2126 |
| 2127 /** |
| 2128 * The class that maps to the DOM MutationObserver interface. |
| 2129 * @param {Function} callback. |
| 2130 * @constructor |
| 2131 */ |
| 2132 function MutationObserver(callback) { |
| 2133 this.callback_ = callback; |
| 2134 this.nodes_ = []; |
| 2135 this.records_ = []; |
| 2136 this.uid_ = ++uidCounter; |
| 2137 |
| 2138 // This will leak. There is no way to implement this without WeakRefs :'( |
| 2139 globalMutationObservers.push(this); |
| 2140 } |
| 2141 |
| 2142 MutationObserver.prototype = { |
| 2143 // http://dom.spec.whatwg.org/#dom-mutationobserver-observe |
| 2144 observe: function(target, options) { |
| 2145 target = wrapIfNeeded(target); |
| 2146 |
| 2147 var newOptions = new MutationObserverOptions(options); |
| 2148 |
| 2149 // 6. |
| 2150 var registration; |
| 2151 var registrations = registrationsTable.get(target); |
| 2152 if (!registrations) |
| 2153 registrationsTable.set(target, registrations = []); |
| 2154 |
| 2155 for (var i = 0; i < registrations.length; i++) { |
| 2156 if (registrations[i].observer === this) { |
| 2157 registration = registrations[i]; |
| 2158 // 6.1. |
| 2159 registration.removeTransientObservers(); |
| 2160 // 6.2. |
| 2161 registration.options = newOptions; |
| 2162 } |
| 2163 } |
| 2164 |
| 2165 // 7. |
| 2166 if (!registration) { |
| 2167 registration = new Registration(this, target, newOptions); |
| 2168 registrations.push(registration); |
| 2169 this.nodes_.push(target); |
| 2170 } |
| 2171 }, |
| 2172 |
| 2173 // http://dom.spec.whatwg.org/#dom-mutationobserver-disconnect |
| 2174 disconnect: function() { |
| 2175 this.nodes_.forEach(function(node) { |
| 2176 var registrations = registrationsTable.get(node); |
| 2177 for (var i = 0; i < registrations.length; i++) { |
| 2178 var registration = registrations[i]; |
| 2179 if (registration.observer === this) { |
| 2180 registrations.splice(i, 1); |
| 2181 // Each node can only have one registered observer associated with |
| 2182 // this observer. |
| 2183 break; |
| 2184 } |
| 2185 } |
| 2186 }, this); |
| 2187 this.records_ = []; |
| 2188 }, |
| 2189 |
| 2190 takeRecords: function() { |
| 2191 var copyOfRecords = this.records_; |
| 2192 this.records_ = []; |
| 2193 return copyOfRecords; |
| 2194 } |
| 2195 }; |
| 2196 |
| 2197 /** |
| 2198 * Class used to represent a registered observer. |
| 2199 * @param {MutationObserver} observer |
| 2200 * @param {Node} target |
| 2201 * @param {MutationObserverOptions} options |
| 2202 * @constructor |
| 2203 */ |
| 2204 function Registration(observer, target, options) { |
| 2205 this.observer = observer; |
| 2206 this.target = target; |
| 2207 this.options = options; |
| 2208 this.transientObservedNodes = []; |
| 2209 } |
| 2210 |
| 2211 Registration.prototype = { |
| 2212 /** |
| 2213 * Adds a transient observer on node. The transient observer gets removed |
| 2214 * next time we deliver the change records. |
| 2215 * @param {Node} node |
| 2216 */ |
| 2217 addTransientObserver: function(node) { |
| 2218 // Don't add transient observers on the target itself. We already have all |
| 2219 // the required listeners set up on the target. |
| 2220 if (node === this.target) |
| 2221 return; |
| 2222 |
| 2223 this.transientObservedNodes.push(node); |
| 2224 var registrations = registrationsTable.get(node); |
| 2225 if (!registrations) |
| 2226 registrationsTable.set(node, registrations = []); |
| 2227 |
| 2228 // We know that registrations does not contain this because we already |
| 2229 // checked if node === this.target. |
| 2230 registrations.push(this); |
| 2231 }, |
| 2232 |
| 2233 removeTransientObservers: function() { |
| 2234 var transientObservedNodes = this.transientObservedNodes; |
| 2235 this.transientObservedNodes = []; |
| 2236 |
| 2237 for (var i = 0; i < transientObservedNodes.length; i++) { |
| 2238 var node = transientObservedNodes[i]; |
| 2239 var registrations = registrationsTable.get(node); |
| 2240 for (var j = 0; j < registrations.length; j++) { |
| 2241 if (registrations[j] === this) { |
| 2242 registrations.splice(j, 1); |
| 2243 // Each node can only have one registered observer associated with |
| 2244 // this observer. |
| 2245 break; |
| 2246 } |
| 2247 } |
| 2248 } |
| 2249 } |
| 2250 }; |
| 2251 |
| 2252 scope.enqueueMutation = enqueueMutation; |
| 2253 scope.registerTransientObservers = registerTransientObservers; |
| 2254 scope.wrappers.MutationObserver = MutationObserver; |
| 2255 scope.wrappers.MutationRecord = MutationRecord; |
| 2256 |
| 2257 })(window.ShadowDOMPolyfill); |
| 1835 | 2258 |
| 1836 // Copyright 2013 The Polymer Authors. All rights reserved. | 2259 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 1837 // Use of this source code is goverened by a BSD-style | 2260 // Use of this source code is goverened by a BSD-style |
| 1838 // license that can be found in the LICENSE file. | 2261 // license that can be found in the LICENSE file. |
| 1839 | 2262 |
| 1840 (function(scope) { | 2263 (function(scope) { |
| 1841 'use strict'; | 2264 'use strict'; |
| 1842 | 2265 |
| 1843 var forwardMethodsToWrapper = scope.forwardMethodsToWrapper; | 2266 var forwardMethodsToWrapper = scope.forwardMethodsToWrapper; |
| 1844 var mixin = scope.mixin; | 2267 var mixin = scope.mixin; |
| (...skipping 727 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2572 scope.unmuteMutationEvents = unmuteMutationEvents; | 2995 scope.unmuteMutationEvents = unmuteMutationEvents; |
| 2573 scope.wrapEventTargetMethods = wrapEventTargetMethods; | 2996 scope.wrapEventTargetMethods = wrapEventTargetMethods; |
| 2574 scope.wrappers.CustomEvent = CustomEvent; | 2997 scope.wrappers.CustomEvent = CustomEvent; |
| 2575 scope.wrappers.Event = Event; | 2998 scope.wrappers.Event = Event; |
| 2576 scope.wrappers.EventTarget = EventTarget; | 2999 scope.wrappers.EventTarget = EventTarget; |
| 2577 scope.wrappers.FocusEvent = FocusEvent; | 3000 scope.wrappers.FocusEvent = FocusEvent; |
| 2578 scope.wrappers.MouseEvent = MouseEvent; | 3001 scope.wrappers.MouseEvent = MouseEvent; |
| 2579 scope.wrappers.MutationEvent = MutationEvent; | 3002 scope.wrappers.MutationEvent = MutationEvent; |
| 2580 scope.wrappers.UIEvent = UIEvent; | 3003 scope.wrappers.UIEvent = UIEvent; |
| 2581 | 3004 |
| 2582 })(this.ShadowDOMPolyfill); | 3005 })(window.ShadowDOMPolyfill); |
| 2583 | 3006 |
| 2584 // Copyright 2012 The Polymer Authors. All rights reserved. | 3007 // Copyright 2012 The Polymer Authors. All rights reserved. |
| 2585 // Use of this source code is goverened by a BSD-style | 3008 // Use of this source code is goverened by a BSD-style |
| 2586 // license that can be found in the LICENSE file. | 3009 // license that can be found in the LICENSE file. |
| 2587 | 3010 |
| 2588 (function(scope) { | 3011 (function(scope) { |
| 2589 'use strict'; | 3012 'use strict'; |
| 2590 | 3013 |
| 2591 var wrap = scope.wrap; | 3014 var wrap = scope.wrap; |
| 2592 | 3015 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2619 function addWrapNodeListMethod(wrapperConstructor, name) { | 3042 function addWrapNodeListMethod(wrapperConstructor, name) { |
| 2620 wrapperConstructor.prototype[name] = function() { | 3043 wrapperConstructor.prototype[name] = function() { |
| 2621 return wrapNodeList(this.impl[name].apply(this.impl, arguments)); | 3044 return wrapNodeList(this.impl[name].apply(this.impl, arguments)); |
| 2622 }; | 3045 }; |
| 2623 } | 3046 } |
| 2624 | 3047 |
| 2625 scope.wrappers.NodeList = NodeList; | 3048 scope.wrappers.NodeList = NodeList; |
| 2626 scope.addWrapNodeListMethod = addWrapNodeListMethod; | 3049 scope.addWrapNodeListMethod = addWrapNodeListMethod; |
| 2627 scope.wrapNodeList = wrapNodeList; | 3050 scope.wrapNodeList = wrapNodeList; |
| 2628 | 3051 |
| 2629 })(this.ShadowDOMPolyfill); | 3052 })(window.ShadowDOMPolyfill); |
| 3053 |
| 2630 // Copyright 2012 The Polymer Authors. All rights reserved. | 3054 // Copyright 2012 The Polymer Authors. All rights reserved. |
| 2631 // Use of this source code is goverened by a BSD-style | 3055 // Use of this source code is goverened by a BSD-style |
| 2632 // license that can be found in the LICENSE file. | 3056 // license that can be found in the LICENSE file. |
| 2633 | 3057 |
| 2634 (function(scope) { | 3058 (function(scope) { |
| 2635 'use strict'; | 3059 'use strict'; |
| 2636 | 3060 |
| 2637 var EventTarget = scope.wrappers.EventTarget; | 3061 var EventTarget = scope.wrappers.EventTarget; |
| 2638 var NodeList = scope.wrappers.NodeList; | 3062 var NodeList = scope.wrappers.NodeList; |
| 3063 var assert = scope.assert; |
| 2639 var defineWrapGetter = scope.defineWrapGetter; | 3064 var defineWrapGetter = scope.defineWrapGetter; |
| 2640 var assert = scope.assert; | 3065 var enqueueMutation = scope.enqueueMutation; |
| 2641 var mixin = scope.mixin; | 3066 var mixin = scope.mixin; |
| 3067 var registerTransientObservers = scope.registerTransientObservers; |
| 2642 var registerWrapper = scope.registerWrapper; | 3068 var registerWrapper = scope.registerWrapper; |
| 2643 var unwrap = scope.unwrap; | 3069 var unwrap = scope.unwrap; |
| 2644 var wrap = scope.wrap; | 3070 var wrap = scope.wrap; |
| 2645 var wrapIfNeeded = scope.wrapIfNeeded; | 3071 var wrapIfNeeded = scope.wrapIfNeeded; |
| 2646 | 3072 |
| 2647 function assertIsNodeWrapper(node) { | 3073 function assertIsNodeWrapper(node) { |
| 2648 assert(node instanceof Node); | 3074 assert(node instanceof Node); |
| 2649 } | 3075 } |
| 2650 | 3076 |
| 3077 function createOneElementNodeList(node) { |
| 3078 var nodes = new NodeList(); |
| 3079 nodes[0] = node; |
| 3080 nodes.length = 1; |
| 3081 return nodes; |
| 3082 } |
| 3083 |
| 3084 var surpressMutations = false; |
| 3085 |
| 3086 /** |
| 3087 * Called before node is inserted into a node to enqueue its removal from its |
| 3088 * old parent. |
| 3089 * @param {!Node} node The node that is about to be removed. |
| 3090 * @param {!Node} parent The parent node that the node is being removed from. |
| 3091 * @param {!NodeList} nodes The collected nodes. |
| 3092 */ |
| 3093 function enqueueRemovalForInsertedNodes(node, parent, nodes) { |
| 3094 enqueueMutation(parent, 'childList', { |
| 3095 removedNodes: nodes, |
| 3096 previousSibling: node.previousSibling, |
| 3097 nextSibling: node.nextSibling |
| 3098 }); |
| 3099 } |
| 3100 |
| 3101 function enqueueRemovalForInsertedDocumentFragment(df, nodes) { |
| 3102 enqueueMutation(df, 'childList', { |
| 3103 removedNodes: nodes |
| 3104 }); |
| 3105 } |
| 3106 |
| 2651 /** | 3107 /** |
| 2652 * Collects nodes from a DocumentFragment or a Node for removal followed | 3108 * Collects nodes from a DocumentFragment or a Node for removal followed |
| 2653 * by an insertion. | 3109 * by an insertion. |
| 2654 * | 3110 * |
| 2655 * This updates the internal pointers for node, previousNode and nextNode. | 3111 * This updates the internal pointers for node, previousNode and nextNode. |
| 2656 */ | 3112 */ |
| 2657 function collectNodes(node, parentNode, previousNode, nextNode) { | 3113 function collectNodes(node, parentNode, previousNode, nextNode) { |
| 2658 if (!(node instanceof DocumentFragment)) { | 3114 if (node instanceof DocumentFragment) { |
| 2659 if (node.parentNode) | 3115 var nodes = collectNodesForDocumentFragment(node); |
| 2660 node.parentNode.removeChild(node); | 3116 |
| 2661 node.parentNode_ = parentNode; | 3117 // The extra loop is to work around bugs with DocumentFragments in IE. |
| 2662 node.previousSibling_ = previousNode; | 3118 surpressMutations = true; |
| 2663 node.nextSibling_ = nextNode; | 3119 for (var i = nodes.length - 1; i >= 0; i--) { |
| 3120 node.removeChild(nodes[i]); |
| 3121 nodes[i].parentNode_ = parentNode; |
| 3122 } |
| 3123 surpressMutations = false; |
| 3124 |
| 3125 for (var i = 0; i < nodes.length; i++) { |
| 3126 nodes[i].previousSibling_ = nodes[i - 1] || previousNode; |
| 3127 nodes[i].nextSibling_ = nodes[i + 1] || nextNode; |
| 3128 } |
| 3129 |
| 2664 if (previousNode) | 3130 if (previousNode) |
| 2665 previousNode.nextSibling_ = node; | 3131 previousNode.nextSibling_ = nodes[0]; |
| 2666 if (nextNode) | 3132 if (nextNode) |
| 2667 nextNode.previousSibling_ = node; | 3133 nextNode.previousSibling_ = nodes[nodes.length - 1]; |
| 2668 return [node]; | 3134 |
| 3135 return nodes; |
| 2669 } | 3136 } |
| 2670 | 3137 |
| 2671 var nodes = []; | 3138 var nodes = createOneElementNodeList(node); |
| 2672 for (var child = node.firstChild; child; child = child.nextSibling) { | 3139 var oldParent = node.parentNode; |
| 2673 nodes.push(child); | 3140 if (oldParent) { |
| 3141 // This will enqueue the mutation record for the removal as needed. |
| 3142 oldParent.removeChild(node); |
| 2674 } | 3143 } |
| 2675 | 3144 |
| 2676 for (var i = nodes.length - 1; i >= 0; i--) { | 3145 node.parentNode_ = parentNode; |
| 2677 node.removeChild(nodes[i]); | 3146 node.previousSibling_ = previousNode; |
| 2678 nodes[i].parentNode_ = parentNode; | 3147 node.nextSibling_ = nextNode; |
| 2679 } | |
| 2680 | |
| 2681 for (var i = 0; i < nodes.length; i++) { | |
| 2682 nodes[i].previousSibling_ = nodes[i - 1] || previousNode; | |
| 2683 nodes[i].nextSibling_ = nodes[i + 1] || nextNode; | |
| 2684 } | |
| 2685 | |
| 2686 if (previousNode) | 3148 if (previousNode) |
| 2687 previousNode.nextSibling_ = nodes[0]; | 3149 previousNode.nextSibling_ = node; |
| 2688 if (nextNode) | 3150 if (nextNode) |
| 2689 nextNode.previousSibling_ = nodes[nodes.length - 1]; | 3151 nextNode.previousSibling_ = node; |
| 2690 | 3152 |
| 2691 return nodes; | 3153 return nodes; |
| 2692 } | 3154 } |
| 2693 | 3155 |
| 2694 function collectNodesNoNeedToUpdatePointers(node) { | 3156 function collectNodesNative(node) { |
| 2695 if (node instanceof DocumentFragment) { | 3157 if (node instanceof DocumentFragment) |
| 2696 var nodes = []; | 3158 return collectNodesForDocumentFragment(node); |
| 2697 var i = 0; | 3159 |
| 2698 for (var child = node.firstChild; child; child = child.nextSibling) { | 3160 var nodes = createOneElementNodeList(node); |
| 2699 nodes[i++] = child; | 3161 var oldParent = node.parentNode; |
| 2700 } | 3162 if (oldParent) |
| 2701 return nodes; | 3163 enqueueRemovalForInsertedNodes(node, oldParent, nodes); |
| 3164 return nodes; |
| 3165 } |
| 3166 |
| 3167 function collectNodesForDocumentFragment(node) { |
| 3168 var nodes = new NodeList(); |
| 3169 var i = 0; |
| 3170 for (var child = node.firstChild; child; child = child.nextSibling) { |
| 3171 nodes[i++] = child; |
| 2702 } | 3172 } |
| 2703 return [node]; | 3173 nodes.length = i; |
| 3174 enqueueRemovalForInsertedDocumentFragment(node, nodes); |
| 3175 return nodes; |
| 3176 } |
| 3177 |
| 3178 function snapshotNodeList(nodeList) { |
| 3179 // NodeLists are not live at the moment so just return the same object. |
| 3180 return nodeList; |
| 3181 } |
| 3182 |
| 3183 // http://dom.spec.whatwg.org/#node-is-inserted |
| 3184 function nodeWasAdded(node) { |
| 3185 node.nodeIsInserted_(); |
| 2704 } | 3186 } |
| 2705 | 3187 |
| 2706 function nodesWereAdded(nodes) { | 3188 function nodesWereAdded(nodes) { |
| 2707 for (var i = 0; i < nodes.length; i++) { | 3189 for (var i = 0; i < nodes.length; i++) { |
| 2708 nodes[i].nodeWasAdded_(); | 3190 nodeWasAdded(nodes[i]); |
| 2709 } | 3191 } |
| 2710 } | 3192 } |
| 2711 | 3193 |
| 3194 // http://dom.spec.whatwg.org/#node-is-removed |
| 3195 function nodeWasRemoved(node) { |
| 3196 // Nothing at this point in time. |
| 3197 } |
| 3198 |
| 3199 function nodesWereRemoved(nodes) { |
| 3200 // Nothing at this point in time. |
| 3201 } |
| 3202 |
| 2712 function ensureSameOwnerDocument(parent, child) { | 3203 function ensureSameOwnerDocument(parent, child) { |
| 2713 var ownerDoc = parent.nodeType === Node.DOCUMENT_NODE ? | 3204 var ownerDoc = parent.nodeType === Node.DOCUMENT_NODE ? |
| 2714 parent : parent.ownerDocument; | 3205 parent : parent.ownerDocument; |
| 2715 if (ownerDoc !== child.ownerDocument) | 3206 if (ownerDoc !== child.ownerDocument) |
| 2716 ownerDoc.adoptNode(child); | 3207 ownerDoc.adoptNode(child); |
| 2717 } | 3208 } |
| 2718 | 3209 |
| 2719 function adoptNodesIfNeeded(owner, nodes) { | 3210 function adoptNodesIfNeeded(owner, nodes) { |
| 2720 if (!nodes.length) | 3211 if (!nodes.length) |
| 2721 return; | 3212 return; |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2844 throw ex; | 3335 throw ex; |
| 2845 } | 3336 } |
| 2846 } : | 3337 } : |
| 2847 function(parent, child) { | 3338 function(parent, child) { |
| 2848 originalRemoveChild.call(parent, child); | 3339 originalRemoveChild.call(parent, child); |
| 2849 }; | 3340 }; |
| 2850 | 3341 |
| 2851 Node.prototype = Object.create(EventTarget.prototype); | 3342 Node.prototype = Object.create(EventTarget.prototype); |
| 2852 mixin(Node.prototype, { | 3343 mixin(Node.prototype, { |
| 2853 appendChild: function(childWrapper) { | 3344 appendChild: function(childWrapper) { |
| 3345 return this.insertBefore(childWrapper, null); |
| 3346 }, |
| 3347 |
| 3348 insertBefore: function(childWrapper, refWrapper) { |
| 2854 assertIsNodeWrapper(childWrapper); | 3349 assertIsNodeWrapper(childWrapper); |
| 2855 | 3350 |
| 3351 refWrapper = refWrapper || null; |
| 3352 refWrapper && assertIsNodeWrapper(refWrapper); |
| 3353 refWrapper && assert(refWrapper.parentNode === this); |
| 3354 |
| 2856 var nodes; | 3355 var nodes; |
| 3356 var previousNode = |
| 3357 refWrapper ? refWrapper.previousSibling : this.lastChild; |
| 2857 | 3358 |
| 2858 if (this.invalidateShadowRenderer() || invalidateParent(childWrapper)) { | 3359 var useNative = !this.invalidateShadowRenderer() && |
| 2859 var previousNode = this.lastChild; | 3360 !invalidateParent(childWrapper); |
| 2860 var nextNode = null; | |
| 2861 nodes = collectNodes(childWrapper, this, previousNode, nextNode); | |
| 2862 | 3361 |
| 2863 this.lastChild_ = nodes[nodes.length - 1]; | 3362 if (useNative) |
| 3363 nodes = collectNodesNative(childWrapper); |
| 3364 else |
| 3365 nodes = collectNodes(childWrapper, this, previousNode, refWrapper); |
| 3366 |
| 3367 if (useNative) { |
| 3368 ensureSameOwnerDocument(this, childWrapper); |
| 3369 originalInsertBefore.call(this.impl, unwrap(childWrapper), |
| 3370 unwrap(refWrapper)); |
| 3371 } else { |
| 2864 if (!previousNode) | 3372 if (!previousNode) |
| 2865 this.firstChild_ = nodes[0]; | 3373 this.firstChild_ = nodes[0]; |
| 3374 if (!refWrapper) |
| 3375 this.lastChild_ = nodes[nodes.length - 1]; |
| 2866 | 3376 |
| 2867 originalAppendChild.call(this.impl, unwrapNodesForInsertion(this, nodes)
); | 3377 var refNode = unwrap(refWrapper); |
| 2868 } else { | 3378 var parentNode = refNode ? refNode.parentNode : this.impl; |
| 2869 nodes = collectNodesNoNeedToUpdatePointers(childWrapper) | 3379 |
| 2870 ensureSameOwnerDocument(this, childWrapper); | 3380 // insertBefore refWrapper no matter what the parent is? |
| 2871 originalAppendChild.call(this.impl, unwrap(childWrapper)); | 3381 if (parentNode) { |
| 3382 originalInsertBefore.call(parentNode, |
| 3383 unwrapNodesForInsertion(this, nodes), refNode); |
| 3384 } else { |
| 3385 adoptNodesIfNeeded(this, nodes); |
| 3386 } |
| 2872 } | 3387 } |
| 2873 | 3388 |
| 3389 enqueueMutation(this, 'childList', { |
| 3390 addedNodes: nodes, |
| 3391 nextSibling: refWrapper, |
| 3392 previousSibling: previousNode |
| 3393 }); |
| 3394 |
| 2874 nodesWereAdded(nodes); | 3395 nodesWereAdded(nodes); |
| 2875 | 3396 |
| 2876 return childWrapper; | 3397 return childWrapper; |
| 2877 }, | |
| 2878 | |
| 2879 insertBefore: function(childWrapper, refWrapper) { | |
| 2880 // TODO(arv): Unify with appendChild | |
| 2881 if (!refWrapper) | |
| 2882 return this.appendChild(childWrapper); | |
| 2883 | |
| 2884 assertIsNodeWrapper(childWrapper); | |
| 2885 assertIsNodeWrapper(refWrapper); | |
| 2886 assert(refWrapper.parentNode === this); | |
| 2887 | |
| 2888 var nodes; | |
| 2889 | |
| 2890 if (this.invalidateShadowRenderer() || invalidateParent(childWrapper)) { | |
| 2891 var previousNode = refWrapper.previousSibling; | |
| 2892 var nextNode = refWrapper; | |
| 2893 nodes = collectNodes(childWrapper, this, previousNode, nextNode); | |
| 2894 | |
| 2895 if (this.firstChild === refWrapper) | |
| 2896 this.firstChild_ = nodes[0]; | |
| 2897 | |
| 2898 // insertBefore refWrapper no matter what the parent is? | |
| 2899 var refNode = unwrap(refWrapper); | |
| 2900 var parentNode = refNode.parentNode; | |
| 2901 | |
| 2902 if (parentNode) { | |
| 2903 originalInsertBefore.call( | |
| 2904 parentNode, | |
| 2905 unwrapNodesForInsertion(this, nodes), | |
| 2906 refNode); | |
| 2907 } else { | |
| 2908 adoptNodesIfNeeded(this, nodes); | |
| 2909 } | |
| 2910 } else { | |
| 2911 nodes = collectNodesNoNeedToUpdatePointers(childWrapper); | |
| 2912 ensureSameOwnerDocument(this, childWrapper); | |
| 2913 originalInsertBefore.call(this.impl, unwrap(childWrapper), | |
| 2914 unwrap(refWrapper)); | |
| 2915 } | |
| 2916 | |
| 2917 nodesWereAdded(nodes); | |
| 2918 | |
| 2919 return childWrapper; | |
| 2920 }, | 3398 }, |
| 2921 | 3399 |
| 2922 removeChild: function(childWrapper) { | 3400 removeChild: function(childWrapper) { |
| 2923 assertIsNodeWrapper(childWrapper); | 3401 assertIsNodeWrapper(childWrapper); |
| 2924 if (childWrapper.parentNode !== this) { | 3402 if (childWrapper.parentNode !== this) { |
| 2925 // IE has invalid DOM trees at times. | 3403 // IE has invalid DOM trees at times. |
| 2926 var found = false; | 3404 var found = false; |
| 2927 var childNodes = this.childNodes; | 3405 var childNodes = this.childNodes; |
| 2928 for (var ieChild = this.firstChild; ieChild; | 3406 for (var ieChild = this.firstChild; ieChild; |
| 2929 ieChild = ieChild.nextSibling) { | 3407 ieChild = ieChild.nextSibling) { |
| 2930 if (ieChild === childWrapper) { | 3408 if (ieChild === childWrapper) { |
| 2931 found = true; | 3409 found = true; |
| 2932 break; | 3410 break; |
| 2933 } | 3411 } |
| 2934 } | 3412 } |
| 2935 if (!found) { | 3413 if (!found) { |
| 2936 // TODO(arv): DOMException | 3414 // TODO(arv): DOMException |
| 2937 throw new Error('NotFoundError'); | 3415 throw new Error('NotFoundError'); |
| 2938 } | 3416 } |
| 2939 } | 3417 } |
| 2940 | 3418 |
| 2941 var childNode = unwrap(childWrapper); | 3419 var childNode = unwrap(childWrapper); |
| 3420 var childWrapperNextSibling = childWrapper.nextSibling; |
| 3421 var childWrapperPreviousSibling = childWrapper.previousSibling; |
| 3422 |
| 2942 if (this.invalidateShadowRenderer()) { | 3423 if (this.invalidateShadowRenderer()) { |
| 2943 | |
| 2944 // We need to remove the real node from the DOM before updating the | 3424 // We need to remove the real node from the DOM before updating the |
| 2945 // pointers. This is so that that mutation event is dispatched before | 3425 // pointers. This is so that that mutation event is dispatched before |
| 2946 // the pointers have changed. | 3426 // the pointers have changed. |
| 2947 var thisFirstChild = this.firstChild; | 3427 var thisFirstChild = this.firstChild; |
| 2948 var thisLastChild = this.lastChild; | 3428 var thisLastChild = this.lastChild; |
| 2949 var childWrapperNextSibling = childWrapper.nextSibling; | |
| 2950 var childWrapperPreviousSibling = childWrapper.previousSibling; | |
| 2951 | 3429 |
| 2952 var parentNode = childNode.parentNode; | 3430 var parentNode = childNode.parentNode; |
| 2953 if (parentNode) | 3431 if (parentNode) |
| 2954 removeChildOriginalHelper(parentNode, childNode); | 3432 removeChildOriginalHelper(parentNode, childNode); |
| 2955 | 3433 |
| 2956 if (thisFirstChild === childWrapper) | 3434 if (thisFirstChild === childWrapper) |
| 2957 this.firstChild_ = childWrapperNextSibling; | 3435 this.firstChild_ = childWrapperNextSibling; |
| 2958 if (thisLastChild === childWrapper) | 3436 if (thisLastChild === childWrapper) |
| 2959 this.lastChild_ = childWrapperPreviousSibling; | 3437 this.lastChild_ = childWrapperPreviousSibling; |
| 2960 if (childWrapperPreviousSibling) | 3438 if (childWrapperPreviousSibling) |
| 2961 childWrapperPreviousSibling.nextSibling_ = childWrapperNextSibling; | 3439 childWrapperPreviousSibling.nextSibling_ = childWrapperNextSibling; |
| 2962 if (childWrapperNextSibling) { | 3440 if (childWrapperNextSibling) { |
| 2963 childWrapperNextSibling.previousSibling_ = | 3441 childWrapperNextSibling.previousSibling_ = |
| 2964 childWrapperPreviousSibling; | 3442 childWrapperPreviousSibling; |
| 2965 } | 3443 } |
| 2966 | 3444 |
| 2967 childWrapper.previousSibling_ = childWrapper.nextSibling_ = | 3445 childWrapper.previousSibling_ = childWrapper.nextSibling_ = |
| 2968 childWrapper.parentNode_ = undefined; | 3446 childWrapper.parentNode_ = undefined; |
| 2969 } else { | 3447 } else { |
| 2970 removeChildOriginalHelper(this.impl, childNode); | 3448 removeChildOriginalHelper(this.impl, childNode); |
| 2971 } | 3449 } |
| 2972 | 3450 |
| 3451 if (!surpressMutations) { |
| 3452 enqueueMutation(this, 'childList', { |
| 3453 removedNodes: createOneElementNodeList(childWrapper), |
| 3454 nextSibling: childWrapperNextSibling, |
| 3455 previousSibling: childWrapperPreviousSibling |
| 3456 }); |
| 3457 } |
| 3458 |
| 3459 registerTransientObservers(this, childWrapper); |
| 3460 |
| 2973 return childWrapper; | 3461 return childWrapper; |
| 2974 }, | 3462 }, |
| 2975 | 3463 |
| 2976 replaceChild: function(newChildWrapper, oldChildWrapper) { | 3464 replaceChild: function(newChildWrapper, oldChildWrapper) { |
| 2977 assertIsNodeWrapper(newChildWrapper); | 3465 assertIsNodeWrapper(newChildWrapper); |
| 2978 assertIsNodeWrapper(oldChildWrapper); | 3466 assertIsNodeWrapper(oldChildWrapper); |
| 2979 | 3467 |
| 2980 if (oldChildWrapper.parentNode !== this) { | 3468 if (oldChildWrapper.parentNode !== this) { |
| 2981 // TODO(arv): DOMException | 3469 // TODO(arv): DOMException |
| 2982 throw new Error('NotFoundError'); | 3470 throw new Error('NotFoundError'); |
| 2983 } | 3471 } |
| 2984 | 3472 |
| 2985 var oldChildNode = unwrap(oldChildWrapper); | 3473 var oldChildNode = unwrap(oldChildWrapper); |
| 3474 var nextNode = oldChildWrapper.nextSibling; |
| 3475 var previousNode = oldChildWrapper.previousSibling; |
| 2986 var nodes; | 3476 var nodes; |
| 2987 | 3477 |
| 2988 if (this.invalidateShadowRenderer() || | 3478 var useNative = !this.invalidateShadowRenderer() && |
| 2989 invalidateParent(newChildWrapper)) { | 3479 !invalidateParent(newChildWrapper); |
| 2990 var previousNode = oldChildWrapper.previousSibling; | 3480 |
| 2991 var nextNode = oldChildWrapper.nextSibling; | 3481 if (useNative) { |
| 3482 nodes = collectNodesNative(newChildWrapper); |
| 3483 } else { |
| 2992 if (nextNode === newChildWrapper) | 3484 if (nextNode === newChildWrapper) |
| 2993 nextNode = newChildWrapper.nextSibling; | 3485 nextNode = newChildWrapper.nextSibling; |
| 2994 nodes = collectNodes(newChildWrapper, this, previousNode, nextNode); | 3486 nodes = collectNodes(newChildWrapper, this, previousNode, nextNode); |
| 3487 } |
| 2995 | 3488 |
| 3489 if (!useNative) { |
| 2996 if (this.firstChild === oldChildWrapper) | 3490 if (this.firstChild === oldChildWrapper) |
| 2997 this.firstChild_ = nodes[0]; | 3491 this.firstChild_ = nodes[0]; |
| 2998 if (this.lastChild === oldChildWrapper) | 3492 if (this.lastChild === oldChildWrapper) |
| 2999 this.lastChild_ = nodes[nodes.length - 1]; | 3493 this.lastChild_ = nodes[nodes.length - 1]; |
| 3000 | 3494 |
| 3001 oldChildWrapper.previousSibling_ = oldChildWrapper.nextSibling_ = | 3495 oldChildWrapper.previousSibling_ = oldChildWrapper.nextSibling_ = |
| 3002 oldChildWrapper.parentNode_ = undefined; | 3496 oldChildWrapper.parentNode_ = undefined; |
| 3003 | 3497 |
| 3004 // replaceChild no matter what the parent is? | 3498 // replaceChild no matter what the parent is? |
| 3005 if (oldChildNode.parentNode) { | 3499 if (oldChildNode.parentNode) { |
| 3006 originalReplaceChild.call( | 3500 originalReplaceChild.call( |
| 3007 oldChildNode.parentNode, | 3501 oldChildNode.parentNode, |
| 3008 unwrapNodesForInsertion(this, nodes), | 3502 unwrapNodesForInsertion(this, nodes), |
| 3009 oldChildNode); | 3503 oldChildNode); |
| 3010 } | 3504 } |
| 3011 } else { | 3505 } else { |
| 3012 nodes = collectNodesNoNeedToUpdatePointers(newChildWrapper); | |
| 3013 ensureSameOwnerDocument(this, newChildWrapper); | 3506 ensureSameOwnerDocument(this, newChildWrapper); |
| 3014 originalReplaceChild.call(this.impl, unwrap(newChildWrapper), | 3507 originalReplaceChild.call(this.impl, unwrap(newChildWrapper), |
| 3015 oldChildNode); | 3508 oldChildNode); |
| 3016 } | 3509 } |
| 3017 | 3510 |
| 3511 enqueueMutation(this, 'childList', { |
| 3512 addedNodes: nodes, |
| 3513 removedNodes: createOneElementNodeList(oldChildWrapper), |
| 3514 nextSibling: nextNode, |
| 3515 previousSibling: previousNode |
| 3516 }); |
| 3517 |
| 3518 nodeWasRemoved(oldChildWrapper); |
| 3018 nodesWereAdded(nodes); | 3519 nodesWereAdded(nodes); |
| 3019 | 3520 |
| 3020 return oldChildWrapper; | 3521 return oldChildWrapper; |
| 3021 }, | 3522 }, |
| 3022 | 3523 |
| 3023 /** | 3524 /** |
| 3024 * Called after a node was added. Subclasses override this to invalidate | 3525 * Called after a node was inserted. Subclasses override this to invalidate |
| 3025 * the renderer as needed. | 3526 * the renderer as needed. |
| 3026 * @private | 3527 * @private |
| 3027 */ | 3528 */ |
| 3028 nodeWasAdded_: function() { | 3529 nodeIsInserted_: function() { |
| 3029 for (var child = this.firstChild; child; child = child.nextSibling) { | 3530 for (var child = this.firstChild; child; child = child.nextSibling) { |
| 3030 child.nodeWasAdded_(); | 3531 child.nodeIsInserted_(); |
| 3031 } | 3532 } |
| 3032 }, | 3533 }, |
| 3033 | 3534 |
| 3034 hasChildNodes: function() { | 3535 hasChildNodes: function() { |
| 3035 return this.firstChild !== null; | 3536 return this.firstChild !== null; |
| 3036 }, | 3537 }, |
| 3037 | 3538 |
| 3038 /** @type {Node} */ | 3539 /** @type {Node} */ |
| 3039 get parentNode() { | 3540 get parentNode() { |
| 3040 // If the parentNode has not been overridden, use the original parentNode. | 3541 // If the parentNode has not been overridden, use the original parentNode. |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3077 get textContent() { | 3578 get textContent() { |
| 3078 // TODO(arv): This should fallback to this.impl.textContent if there | 3579 // TODO(arv): This should fallback to this.impl.textContent if there |
| 3079 // are no shadow trees below or above the context node. | 3580 // are no shadow trees below or above the context node. |
| 3080 var s = ''; | 3581 var s = ''; |
| 3081 for (var child = this.firstChild; child; child = child.nextSibling) { | 3582 for (var child = this.firstChild; child; child = child.nextSibling) { |
| 3082 s += child.textContent; | 3583 s += child.textContent; |
| 3083 } | 3584 } |
| 3084 return s; | 3585 return s; |
| 3085 }, | 3586 }, |
| 3086 set textContent(textContent) { | 3587 set textContent(textContent) { |
| 3588 var removedNodes = snapshotNodeList(this.childNodes); |
| 3589 |
| 3087 if (this.invalidateShadowRenderer()) { | 3590 if (this.invalidateShadowRenderer()) { |
| 3088 removeAllChildNodes(this); | 3591 removeAllChildNodes(this); |
| 3089 if (textContent !== '') { | 3592 if (textContent !== '') { |
| 3090 var textNode = this.impl.ownerDocument.createTextNode(textContent); | 3593 var textNode = this.impl.ownerDocument.createTextNode(textContent); |
| 3091 this.appendChild(textNode); | 3594 this.appendChild(textNode); |
| 3092 } | 3595 } |
| 3093 } else { | 3596 } else { |
| 3094 this.impl.textContent = textContent; | 3597 this.impl.textContent = textContent; |
| 3095 } | 3598 } |
| 3599 |
| 3600 var addedNodes = snapshotNodeList(this.childNodes); |
| 3601 |
| 3602 enqueueMutation(this, 'childList', { |
| 3603 addedNodes: addedNodes, |
| 3604 removedNodes: removedNodes |
| 3605 }); |
| 3606 |
| 3607 nodesWereRemoved(removedNodes); |
| 3608 nodesWereAdded(addedNodes); |
| 3096 }, | 3609 }, |
| 3097 | 3610 |
| 3098 get childNodes() { | 3611 get childNodes() { |
| 3099 var wrapperList = new NodeList(); | 3612 var wrapperList = new NodeList(); |
| 3100 var i = 0; | 3613 var i = 0; |
| 3101 for (var child = this.firstChild; child; child = child.nextSibling) { | 3614 for (var child = this.firstChild; child; child = child.nextSibling) { |
| 3102 wrapperList[i++] = child; | 3615 wrapperList[i++] = child; |
| 3103 } | 3616 } |
| 3104 wrapperList.length = i; | 3617 wrapperList.length = i; |
| 3105 return wrapperList; | 3618 return wrapperList; |
| 3106 }, | 3619 }, |
| 3107 | 3620 |
| 3108 cloneNode: function(deep) { | 3621 cloneNode: function(deep) { |
| 3109 if (!this.invalidateShadowRenderer()) | |
| 3110 return wrap(this.impl.cloneNode(deep)); | |
| 3111 | |
| 3112 var clone = wrap(this.impl.cloneNode(false)); | 3622 var clone = wrap(this.impl.cloneNode(false)); |
| 3113 if (deep) { | 3623 if (deep) { |
| 3114 for (var child = this.firstChild; child; child = child.nextSibling) { | 3624 for (var child = this.firstChild; child; child = child.nextSibling) { |
| 3115 clone.appendChild(child.cloneNode(true)); | 3625 clone.appendChild(child.cloneNode(true)); |
| 3116 } | 3626 } |
| 3117 } | 3627 } |
| 3118 // TODO(arv): Some HTML elements also clone other data like value. | 3628 // TODO(arv): Some HTML elements also clone other data like value. |
| 3119 return clone; | 3629 return clone; |
| 3120 }, | 3630 }, |
| 3121 | 3631 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3144 defineWrapGetter(Node, 'ownerDocument'); | 3654 defineWrapGetter(Node, 'ownerDocument'); |
| 3145 | 3655 |
| 3146 // We use a DocumentFragment as a base and then delete the properties of | 3656 // We use a DocumentFragment as a base and then delete the properties of |
| 3147 // DocumentFragment.prototype from the wrapper Node. Since delete makes | 3657 // DocumentFragment.prototype from the wrapper Node. Since delete makes |
| 3148 // objects slow in some JS engines we recreate the prototype object. | 3658 // objects slow in some JS engines we recreate the prototype object. |
| 3149 registerWrapper(OriginalNode, Node, document.createDocumentFragment()); | 3659 registerWrapper(OriginalNode, Node, document.createDocumentFragment()); |
| 3150 delete Node.prototype.querySelector; | 3660 delete Node.prototype.querySelector; |
| 3151 delete Node.prototype.querySelectorAll; | 3661 delete Node.prototype.querySelectorAll; |
| 3152 Node.prototype = mixin(Object.create(EventTarget.prototype), Node.prototype); | 3662 Node.prototype = mixin(Object.create(EventTarget.prototype), Node.prototype); |
| 3153 | 3663 |
| 3664 scope.nodeWasAdded = nodeWasAdded; |
| 3665 scope.nodeWasRemoved = nodeWasRemoved; |
| 3666 scope.nodesWereAdded = nodesWereAdded; |
| 3667 scope.nodesWereRemoved = nodesWereRemoved; |
| 3668 scope.snapshotNodeList = snapshotNodeList; |
| 3154 scope.wrappers.Node = Node; | 3669 scope.wrappers.Node = Node; |
| 3155 | 3670 |
| 3156 })(this.ShadowDOMPolyfill); | 3671 })(window.ShadowDOMPolyfill); |
| 3157 | 3672 |
| 3158 // Copyright 2013 The Polymer Authors. All rights reserved. | 3673 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 3159 // Use of this source code is governed by a BSD-style | 3674 // Use of this source code is governed by a BSD-style |
| 3160 // license that can be found in the LICENSE file. | 3675 // license that can be found in the LICENSE file. |
| 3161 | 3676 |
| 3162 (function(scope) { | 3677 (function(scope) { |
| 3163 'use strict'; | 3678 'use strict'; |
| 3164 | 3679 |
| 3165 function findOne(node, selector) { | 3680 function findOne(node, selector) { |
| 3166 var m, el = node.firstElementChild; | 3681 var m, el = node.firstElementChild; |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3220 result[j++] = els[i]; | 3735 result[j++] = els[i]; |
| 3221 } | 3736 } |
| 3222 result.length = j; | 3737 result.length = j; |
| 3223 return result; | 3738 return result; |
| 3224 } | 3739 } |
| 3225 }; | 3740 }; |
| 3226 | 3741 |
| 3227 scope.GetElementsByInterface = GetElementsByInterface; | 3742 scope.GetElementsByInterface = GetElementsByInterface; |
| 3228 scope.SelectorsInterface = SelectorsInterface; | 3743 scope.SelectorsInterface = SelectorsInterface; |
| 3229 | 3744 |
| 3230 })(this.ShadowDOMPolyfill); | 3745 })(window.ShadowDOMPolyfill); |
| 3231 | 3746 |
| 3232 // Copyright 2013 The Polymer Authors. All rights reserved. | 3747 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 3233 // Use of this source code is goverened by a BSD-style | 3748 // Use of this source code is goverened by a BSD-style |
| 3234 // license that can be found in the LICENSE file. | 3749 // license that can be found in the LICENSE file. |
| 3235 | 3750 |
| 3236 (function(scope) { | 3751 (function(scope) { |
| 3237 'use strict'; | 3752 'use strict'; |
| 3238 | 3753 |
| 3239 var NodeList = scope.wrappers.NodeList; | 3754 var NodeList = scope.wrappers.NodeList; |
| 3240 | 3755 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3290 }, | 3805 }, |
| 3291 | 3806 |
| 3292 get previousElementSibling() { | 3807 get previousElementSibling() { |
| 3293 return backwardsElement(this.previousSibling); | 3808 return backwardsElement(this.previousSibling); |
| 3294 } | 3809 } |
| 3295 }; | 3810 }; |
| 3296 | 3811 |
| 3297 scope.ChildNodeInterface = ChildNodeInterface; | 3812 scope.ChildNodeInterface = ChildNodeInterface; |
| 3298 scope.ParentNodeInterface = ParentNodeInterface; | 3813 scope.ParentNodeInterface = ParentNodeInterface; |
| 3299 | 3814 |
| 3300 })(this.ShadowDOMPolyfill); | 3815 })(window.ShadowDOMPolyfill); |
| 3301 | 3816 |
| 3302 // Copyright 2013 The Polymer Authors. All rights reserved. | 3817 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 3303 // Use of this source code is goverened by a BSD-style | 3818 // Use of this source code is goverened by a BSD-style |
| 3304 // license that can be found in the LICENSE file. | 3819 // license that can be found in the LICENSE file. |
| 3305 | 3820 |
| 3306 (function(scope) { | 3821 (function(scope) { |
| 3307 'use strict'; | 3822 'use strict'; |
| 3308 | 3823 |
| 3309 var ChildNodeInterface = scope.ChildNodeInterface; | 3824 var ChildNodeInterface = scope.ChildNodeInterface; |
| 3310 var Node = scope.wrappers.Node; | 3825 var Node = scope.wrappers.Node; |
| 3826 var enqueueMutation = scope.enqueueMutation; |
| 3311 var mixin = scope.mixin; | 3827 var mixin = scope.mixin; |
| 3312 var registerWrapper = scope.registerWrapper; | 3828 var registerWrapper = scope.registerWrapper; |
| 3313 | 3829 |
| 3314 var OriginalCharacterData = window.CharacterData; | 3830 var OriginalCharacterData = window.CharacterData; |
| 3315 | 3831 |
| 3316 function CharacterData(node) { | 3832 function CharacterData(node) { |
| 3317 Node.call(this, node); | 3833 Node.call(this, node); |
| 3318 } | 3834 } |
| 3319 CharacterData.prototype = Object.create(Node.prototype); | 3835 CharacterData.prototype = Object.create(Node.prototype); |
| 3320 mixin(CharacterData.prototype, { | 3836 mixin(CharacterData.prototype, { |
| 3321 get textContent() { | 3837 get textContent() { |
| 3322 return this.data; | 3838 return this.data; |
| 3323 }, | 3839 }, |
| 3324 set textContent(value) { | 3840 set textContent(value) { |
| 3325 this.data = value; | 3841 this.data = value; |
| 3842 }, |
| 3843 get data() { |
| 3844 return this.impl.data; |
| 3845 }, |
| 3846 set data(value) { |
| 3847 var oldValue = this.impl.data; |
| 3848 enqueueMutation(this, 'characterData', { |
| 3849 oldValue: oldValue |
| 3850 }); |
| 3851 this.impl.data = value; |
| 3326 } | 3852 } |
| 3327 }); | 3853 }); |
| 3328 | 3854 |
| 3329 mixin(CharacterData.prototype, ChildNodeInterface); | 3855 mixin(CharacterData.prototype, ChildNodeInterface); |
| 3330 | 3856 |
| 3331 registerWrapper(OriginalCharacterData, CharacterData, | 3857 registerWrapper(OriginalCharacterData, CharacterData, |
| 3332 document.createTextNode('')); | 3858 document.createTextNode('')); |
| 3333 | 3859 |
| 3334 scope.wrappers.CharacterData = CharacterData; | 3860 scope.wrappers.CharacterData = CharacterData; |
| 3335 })(this.ShadowDOMPolyfill); | 3861 })(window.ShadowDOMPolyfill); |
| 3336 | 3862 |
| 3337 // Copyright 2013 The Polymer Authors. All rights reserved. | 3863 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 3338 // Use of this source code is goverened by a BSD-style | 3864 // Use of this source code is goverened by a BSD-style |
| 3339 // license that can be found in the LICENSE file. | 3865 // license that can be found in the LICENSE file. |
| 3340 | 3866 |
| 3341 (function(scope) { | 3867 (function(scope) { |
| 3342 'use strict'; | 3868 'use strict'; |
| 3343 | 3869 |
| 3344 var ChildNodeInterface = scope.ChildNodeInterface; | 3870 var ChildNodeInterface = scope.ChildNodeInterface; |
| 3345 var GetElementsByInterface = scope.GetElementsByInterface; | 3871 var GetElementsByInterface = scope.GetElementsByInterface; |
| 3346 var Node = scope.wrappers.Node; | 3872 var Node = scope.wrappers.Node; |
| 3347 var ParentNodeInterface = scope.ParentNodeInterface; | 3873 var ParentNodeInterface = scope.ParentNodeInterface; |
| 3348 var SelectorsInterface = scope.SelectorsInterface; | 3874 var SelectorsInterface = scope.SelectorsInterface; |
| 3349 var addWrapNodeListMethod = scope.addWrapNodeListMethod; | 3875 var addWrapNodeListMethod = scope.addWrapNodeListMethod; |
| 3876 var enqueueMutation = scope.enqueueMutation; |
| 3350 var mixin = scope.mixin; | 3877 var mixin = scope.mixin; |
| 3351 var oneOf = scope.oneOf; | 3878 var oneOf = scope.oneOf; |
| 3352 var registerWrapper = scope.registerWrapper; | 3879 var registerWrapper = scope.registerWrapper; |
| 3353 var wrappers = scope.wrappers; | 3880 var wrappers = scope.wrappers; |
| 3354 | 3881 |
| 3355 var OriginalElement = window.Element; | 3882 var OriginalElement = window.Element; |
| 3356 | 3883 |
| 3357 var matchesName = oneOf(OriginalElement.prototype, [ | 3884 var matchesName = oneOf(OriginalElement.prototype, [ |
| 3358 'matches', | 3885 'matches', |
| 3359 'mozMatchesSelector', | 3886 'mozMatchesSelector', |
| 3360 'msMatchesSelector', | 3887 'msMatchesSelector', |
| 3361 'webkitMatchesSelector', | 3888 'webkitMatchesSelector', |
| 3362 ]); | 3889 ]); |
| 3363 | 3890 |
| 3364 var originalMatches = OriginalElement.prototype[matchesName]; | 3891 var originalMatches = OriginalElement.prototype[matchesName]; |
| 3365 | 3892 |
| 3366 function invalidateRendererBasedOnAttribute(element, name) { | 3893 function invalidateRendererBasedOnAttribute(element, name) { |
| 3367 // Only invalidate if parent node is a shadow host. | 3894 // Only invalidate if parent node is a shadow host. |
| 3368 var p = element.parentNode; | 3895 var p = element.parentNode; |
| 3369 if (!p || !p.shadowRoot) | 3896 if (!p || !p.shadowRoot) |
| 3370 return; | 3897 return; |
| 3371 | 3898 |
| 3372 var renderer = scope.getRendererForHost(p); | 3899 var renderer = scope.getRendererForHost(p); |
| 3373 if (renderer.dependsOnAttribute(name)) | 3900 if (renderer.dependsOnAttribute(name)) |
| 3374 renderer.invalidate(); | 3901 renderer.invalidate(); |
| 3375 } | 3902 } |
| 3376 | 3903 |
| 3904 function enqueAttributeChange(element, name, oldValue) { |
| 3905 // This is not fully spec compliant. We should use localName (which might |
| 3906 // have a different case than name) and the namespace (which requires us |
| 3907 // to get the Attr object). |
| 3908 enqueueMutation(element, 'attributes', { |
| 3909 name: name, |
| 3910 namespace: null, |
| 3911 oldValue: oldValue |
| 3912 }); |
| 3913 } |
| 3914 |
| 3377 function Element(node) { | 3915 function Element(node) { |
| 3378 Node.call(this, node); | 3916 Node.call(this, node); |
| 3379 } | 3917 } |
| 3380 Element.prototype = Object.create(Node.prototype); | 3918 Element.prototype = Object.create(Node.prototype); |
| 3381 mixin(Element.prototype, { | 3919 mixin(Element.prototype, { |
| 3382 createShadowRoot: function() { | 3920 createShadowRoot: function() { |
| 3383 var newShadowRoot = new wrappers.ShadowRoot(this); | 3921 var newShadowRoot = new wrappers.ShadowRoot(this); |
| 3384 this.impl.polymerShadowRoot_ = newShadowRoot; | 3922 this.impl.polymerShadowRoot_ = newShadowRoot; |
| 3385 | 3923 |
| 3386 var renderer = scope.getRendererForHost(this); | 3924 var renderer = scope.getRendererForHost(this); |
| 3387 renderer.invalidate(); | 3925 renderer.invalidate(); |
| 3388 | 3926 |
| 3389 return newShadowRoot; | 3927 return newShadowRoot; |
| 3390 }, | 3928 }, |
| 3391 | 3929 |
| 3392 get shadowRoot() { | 3930 get shadowRoot() { |
| 3393 return this.impl.polymerShadowRoot_ || null; | 3931 return this.impl.polymerShadowRoot_ || null; |
| 3394 }, | 3932 }, |
| 3395 | 3933 |
| 3396 setAttribute: function(name, value) { | 3934 setAttribute: function(name, value) { |
| 3935 var oldValue = this.impl.getAttribute(name); |
| 3397 this.impl.setAttribute(name, value); | 3936 this.impl.setAttribute(name, value); |
| 3937 enqueAttributeChange(this, name, oldValue); |
| 3398 invalidateRendererBasedOnAttribute(this, name); | 3938 invalidateRendererBasedOnAttribute(this, name); |
| 3399 }, | 3939 }, |
| 3400 | 3940 |
| 3401 removeAttribute: function(name) { | 3941 removeAttribute: function(name) { |
| 3942 var oldValue = this.impl.getAttribute(name); |
| 3402 this.impl.removeAttribute(name); | 3943 this.impl.removeAttribute(name); |
| 3944 enqueAttributeChange(this, name, oldValue); |
| 3403 invalidateRendererBasedOnAttribute(this, name); | 3945 invalidateRendererBasedOnAttribute(this, name); |
| 3404 }, | 3946 }, |
| 3405 | 3947 |
| 3406 matches: function(selector) { | 3948 matches: function(selector) { |
| 3407 return originalMatches.call(this.impl, selector); | 3949 return originalMatches.call(this.impl, selector); |
| 3408 } | 3950 } |
| 3409 }); | 3951 }); |
| 3410 | 3952 |
| 3411 Element.prototype[matchesName] = function(selector) { | 3953 Element.prototype[matchesName] = function(selector) { |
| 3412 return this.matches(selector); | 3954 return this.matches(selector); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3443 mixin(Element.prototype, GetElementsByInterface); | 3985 mixin(Element.prototype, GetElementsByInterface); |
| 3444 mixin(Element.prototype, ParentNodeInterface); | 3986 mixin(Element.prototype, ParentNodeInterface); |
| 3445 mixin(Element.prototype, SelectorsInterface); | 3987 mixin(Element.prototype, SelectorsInterface); |
| 3446 | 3988 |
| 3447 registerWrapper(OriginalElement, Element); | 3989 registerWrapper(OriginalElement, Element); |
| 3448 | 3990 |
| 3449 // TODO(arv): Export setterDirtiesAttribute and apply it to more bindings | 3991 // TODO(arv): Export setterDirtiesAttribute and apply it to more bindings |
| 3450 // that reflect attributes. | 3992 // that reflect attributes. |
| 3451 scope.matchesName = matchesName; | 3993 scope.matchesName = matchesName; |
| 3452 scope.wrappers.Element = Element; | 3994 scope.wrappers.Element = Element; |
| 3453 })(this.ShadowDOMPolyfill); | 3995 })(window.ShadowDOMPolyfill); |
| 3454 | 3996 |
| 3455 // Copyright 2013 The Polymer Authors. All rights reserved. | 3997 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 3456 // Use of this source code is goverened by a BSD-style | 3998 // Use of this source code is goverened by a BSD-style |
| 3457 // license that can be found in the LICENSE file. | 3999 // license that can be found in the LICENSE file. |
| 3458 | 4000 |
| 3459 (function(scope) { | 4001 (function(scope) { |
| 3460 'use strict'; | 4002 'use strict'; |
| 3461 | 4003 |
| 3462 var Element = scope.wrappers.Element; | 4004 var Element = scope.wrappers.Element; |
| 3463 var defineGetter = scope.defineGetter; | 4005 var defineGetter = scope.defineGetter; |
| 4006 var enqueueMutation = scope.enqueueMutation; |
| 3464 var mixin = scope.mixin; | 4007 var mixin = scope.mixin; |
| 4008 var nodesWereAdded = scope.nodesWereAdded; |
| 4009 var nodesWereRemoved = scope.nodesWereRemoved; |
| 3465 var registerWrapper = scope.registerWrapper; | 4010 var registerWrapper = scope.registerWrapper; |
| 4011 var snapshotNodeList = scope.snapshotNodeList; |
| 3466 var unwrap = scope.unwrap; | 4012 var unwrap = scope.unwrap; |
| 3467 var wrap = scope.wrap; | 4013 var wrap = scope.wrap; |
| 3468 | 4014 |
| 3469 ///////////////////////////////////////////////////////////////////////////// | 4015 ///////////////////////////////////////////////////////////////////////////// |
| 3470 // innerHTML and outerHTML | 4016 // innerHTML and outerHTML |
| 3471 | 4017 |
| 3472 var escapeRegExp = /&|<|"/g; | 4018 var escapeRegExp = /&|<|"/g; |
| 3473 | 4019 |
| 3474 function escapeReplace(c) { | 4020 function escapeReplace(c) { |
| 3475 switch (c) { | 4021 switch (c) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3557 Element.call(this, node); | 4103 Element.call(this, node); |
| 3558 } | 4104 } |
| 3559 HTMLElement.prototype = Object.create(Element.prototype); | 4105 HTMLElement.prototype = Object.create(Element.prototype); |
| 3560 mixin(HTMLElement.prototype, { | 4106 mixin(HTMLElement.prototype, { |
| 3561 get innerHTML() { | 4107 get innerHTML() { |
| 3562 // TODO(arv): This should fallback to this.impl.innerHTML if there | 4108 // TODO(arv): This should fallback to this.impl.innerHTML if there |
| 3563 // are no shadow trees below or above the context node. | 4109 // are no shadow trees below or above the context node. |
| 3564 return getInnerHTML(this); | 4110 return getInnerHTML(this); |
| 3565 }, | 4111 }, |
| 3566 set innerHTML(value) { | 4112 set innerHTML(value) { |
| 4113 var removedNodes = snapshotNodeList(this.childNodes); |
| 4114 |
| 3567 if (this.invalidateShadowRenderer()) | 4115 if (this.invalidateShadowRenderer()) |
| 3568 setInnerHTML(this, value, this.tagName); | 4116 setInnerHTML(this, value, this.tagName); |
| 3569 else | 4117 else |
| 3570 this.impl.innerHTML = value; | 4118 this.impl.innerHTML = value; |
| 4119 var addedNodes = snapshotNodeList(this.childNodes); |
| 4120 |
| 4121 enqueueMutation(this, 'childList', { |
| 4122 addedNodes: addedNodes, |
| 4123 removedNodes: removedNodes |
| 4124 }); |
| 4125 |
| 4126 nodesWereRemoved(removedNodes); |
| 4127 nodesWereAdded(addedNodes); |
| 3571 }, | 4128 }, |
| 3572 | 4129 |
| 3573 get outerHTML() { | 4130 get outerHTML() { |
| 3574 // TODO(arv): This should fallback to HTMLElement_prototype.outerHTML if t
here | 4131 // TODO(arv): This should fallback to HTMLElement_prototype.outerHTML if t
here |
| 3575 // are no shadow trees below or above the context node. | 4132 // are no shadow trees below or above the context node. |
| 3576 return getOuterHTML(this); | 4133 return getOuterHTML(this); |
| 3577 }, | 4134 }, |
| 3578 set outerHTML(value) { | 4135 set outerHTML(value) { |
| 3579 var p = this.parentNode; | 4136 var p = this.parentNode; |
| 3580 if (p) { | 4137 if (p) { |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3644 | 4201 |
| 3645 // HTMLElement is abstract so we use a subclass that has no members. | 4202 // HTMLElement is abstract so we use a subclass that has no members. |
| 3646 registerWrapper(OriginalHTMLElement, HTMLElement, | 4203 registerWrapper(OriginalHTMLElement, HTMLElement, |
| 3647 document.createElement('b')); | 4204 document.createElement('b')); |
| 3648 | 4205 |
| 3649 scope.wrappers.HTMLElement = HTMLElement; | 4206 scope.wrappers.HTMLElement = HTMLElement; |
| 3650 | 4207 |
| 3651 // TODO: Find a better way to share these two with WrapperShadowRoot. | 4208 // TODO: Find a better way to share these two with WrapperShadowRoot. |
| 3652 scope.getInnerHTML = getInnerHTML; | 4209 scope.getInnerHTML = getInnerHTML; |
| 3653 scope.setInnerHTML = setInnerHTML | 4210 scope.setInnerHTML = setInnerHTML |
| 3654 })(this.ShadowDOMPolyfill); | 4211 })(window.ShadowDOMPolyfill); |
| 4212 |
| 3655 // Copyright 2013 The Polymer Authors. All rights reserved. | 4213 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 3656 // Use of this source code is goverened by a BSD-style | 4214 // Use of this source code is goverened by a BSD-style |
| 3657 // license that can be found in the LICENSE file. | 4215 // license that can be found in the LICENSE file. |
| 3658 | 4216 |
| 3659 (function(scope) { | 4217 (function(scope) { |
| 3660 'use strict'; | 4218 'use strict'; |
| 3661 | 4219 |
| 3662 var HTMLElement = scope.wrappers.HTMLElement; | 4220 var HTMLElement = scope.wrappers.HTMLElement; |
| 3663 var mixin = scope.mixin; | 4221 var mixin = scope.mixin; |
| 3664 var registerWrapper = scope.registerWrapper; | 4222 var registerWrapper = scope.registerWrapper; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3675 getContext: function() { | 4233 getContext: function() { |
| 3676 var context = this.impl.getContext.apply(this.impl, arguments); | 4234 var context = this.impl.getContext.apply(this.impl, arguments); |
| 3677 return context && wrap(context); | 4235 return context && wrap(context); |
| 3678 } | 4236 } |
| 3679 }); | 4237 }); |
| 3680 | 4238 |
| 3681 registerWrapper(OriginalHTMLCanvasElement, HTMLCanvasElement, | 4239 registerWrapper(OriginalHTMLCanvasElement, HTMLCanvasElement, |
| 3682 document.createElement('canvas')); | 4240 document.createElement('canvas')); |
| 3683 | 4241 |
| 3684 scope.wrappers.HTMLCanvasElement = HTMLCanvasElement; | 4242 scope.wrappers.HTMLCanvasElement = HTMLCanvasElement; |
| 3685 })(this.ShadowDOMPolyfill); | 4243 })(window.ShadowDOMPolyfill); |
| 3686 | 4244 |
| 3687 // Copyright 2013 The Polymer Authors. All rights reserved. | 4245 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 3688 // Use of this source code is goverened by a BSD-style | 4246 // Use of this source code is goverened by a BSD-style |
| 3689 // license that can be found in the LICENSE file. | 4247 // license that can be found in the LICENSE file. |
| 3690 | 4248 |
| 3691 (function(scope) { | 4249 (function(scope) { |
| 3692 'use strict'; | 4250 'use strict'; |
| 3693 | 4251 |
| 3694 var HTMLElement = scope.wrappers.HTMLElement; | 4252 var HTMLElement = scope.wrappers.HTMLElement; |
| 3695 var mixin = scope.mixin; | 4253 var mixin = scope.mixin; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3717 | 4275 |
| 3718 // getDistributedNodes is added in ShadowRenderer | 4276 // getDistributedNodes is added in ShadowRenderer |
| 3719 | 4277 |
| 3720 // TODO: attribute boolean resetStyleInheritance; | 4278 // TODO: attribute boolean resetStyleInheritance; |
| 3721 }); | 4279 }); |
| 3722 | 4280 |
| 3723 if (OriginalHTMLContentElement) | 4281 if (OriginalHTMLContentElement) |
| 3724 registerWrapper(OriginalHTMLContentElement, HTMLContentElement); | 4282 registerWrapper(OriginalHTMLContentElement, HTMLContentElement); |
| 3725 | 4283 |
| 3726 scope.wrappers.HTMLContentElement = HTMLContentElement; | 4284 scope.wrappers.HTMLContentElement = HTMLContentElement; |
| 3727 })(this.ShadowDOMPolyfill); | 4285 })(window.ShadowDOMPolyfill); |
| 4286 |
| 3728 // Copyright 2013 The Polymer Authors. All rights reserved. | 4287 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 3729 // Use of this source code is goverened by a BSD-style | 4288 // Use of this source code is goverened by a BSD-style |
| 3730 // license that can be found in the LICENSE file. | 4289 // license that can be found in the LICENSE file. |
| 3731 | 4290 |
| 3732 (function(scope) { | 4291 (function(scope) { |
| 3733 'use strict'; | 4292 'use strict'; |
| 3734 | 4293 |
| 3735 var HTMLElement = scope.wrappers.HTMLElement; | 4294 var HTMLElement = scope.wrappers.HTMLElement; |
| 3736 var registerWrapper = scope.registerWrapper; | 4295 var registerWrapper = scope.registerWrapper; |
| 3737 var unwrap = scope.unwrap; | 4296 var unwrap = scope.unwrap; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3760 if (width !== undefined) | 4319 if (width !== undefined) |
| 3761 node.width = width; | 4320 node.width = width; |
| 3762 if (height !== undefined) | 4321 if (height !== undefined) |
| 3763 node.height = height; | 4322 node.height = height; |
| 3764 } | 4323 } |
| 3765 | 4324 |
| 3766 Image.prototype = HTMLImageElement.prototype; | 4325 Image.prototype = HTMLImageElement.prototype; |
| 3767 | 4326 |
| 3768 scope.wrappers.HTMLImageElement = HTMLImageElement; | 4327 scope.wrappers.HTMLImageElement = HTMLImageElement; |
| 3769 scope.wrappers.Image = Image; | 4328 scope.wrappers.Image = Image; |
| 3770 })(this.ShadowDOMPolyfill); | 4329 })(window.ShadowDOMPolyfill); |
| 3771 | 4330 |
| 3772 // Copyright 2013 The Polymer Authors. All rights reserved. | 4331 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 3773 // Use of this source code is goverened by a BSD-style | 4332 // Use of this source code is goverened by a BSD-style |
| 3774 // license that can be found in the LICENSE file. | 4333 // license that can be found in the LICENSE file. |
| 3775 | 4334 |
| 3776 (function(scope) { | 4335 (function(scope) { |
| 3777 'use strict'; | 4336 'use strict'; |
| 3778 | 4337 |
| 3779 var HTMLElement = scope.wrappers.HTMLElement; | 4338 var HTMLElement = scope.wrappers.HTMLElement; |
| 3780 var mixin = scope.mixin; | 4339 var mixin = scope.mixin; |
| 3781 var registerWrapper = scope.registerWrapper; | 4340 var registerWrapper = scope.registerWrapper; |
| 3782 | 4341 |
| 3783 var OriginalHTMLShadowElement = window.HTMLShadowElement; | 4342 var OriginalHTMLShadowElement = window.HTMLShadowElement; |
| 3784 | 4343 |
| 3785 function HTMLShadowElement(node) { | 4344 function HTMLShadowElement(node) { |
| 3786 HTMLElement.call(this, node); | 4345 HTMLElement.call(this, node); |
| 3787 } | 4346 } |
| 3788 HTMLShadowElement.prototype = Object.create(HTMLElement.prototype); | 4347 HTMLShadowElement.prototype = Object.create(HTMLElement.prototype); |
| 3789 mixin(HTMLShadowElement.prototype, { | 4348 mixin(HTMLShadowElement.prototype, { |
| 3790 // TODO: attribute boolean resetStyleInheritance; | 4349 // TODO: attribute boolean resetStyleInheritance; |
| 3791 }); | 4350 }); |
| 3792 | 4351 |
| 3793 if (OriginalHTMLShadowElement) | 4352 if (OriginalHTMLShadowElement) |
| 3794 registerWrapper(OriginalHTMLShadowElement, HTMLShadowElement); | 4353 registerWrapper(OriginalHTMLShadowElement, HTMLShadowElement); |
| 3795 | 4354 |
| 3796 scope.wrappers.HTMLShadowElement = HTMLShadowElement; | 4355 scope.wrappers.HTMLShadowElement = HTMLShadowElement; |
| 3797 })(this.ShadowDOMPolyfill); | 4356 })(window.ShadowDOMPolyfill); |
| 3798 | 4357 |
| 3799 // Copyright 2013 The Polymer Authors. All rights reserved. | 4358 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 3800 // Use of this source code is goverened by a BSD-style | 4359 // Use of this source code is goverened by a BSD-style |
| 3801 // license that can be found in the LICENSE file. | 4360 // license that can be found in the LICENSE file. |
| 3802 | 4361 |
| 3803 (function(scope) { | 4362 (function(scope) { |
| 3804 'use strict'; | 4363 'use strict'; |
| 3805 | 4364 |
| 3806 var HTMLElement = scope.wrappers.HTMLElement; | 4365 var HTMLElement = scope.wrappers.HTMLElement; |
| 3807 var getInnerHTML = scope.getInnerHTML; | 4366 var getInnerHTML = scope.getInnerHTML; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3872 } | 4431 } |
| 3873 | 4432 |
| 3874 // TODO(arv): cloneNode needs to clone content. | 4433 // TODO(arv): cloneNode needs to clone content. |
| 3875 | 4434 |
| 3876 }); | 4435 }); |
| 3877 | 4436 |
| 3878 if (OriginalHTMLTemplateElement) | 4437 if (OriginalHTMLTemplateElement) |
| 3879 registerWrapper(OriginalHTMLTemplateElement, HTMLTemplateElement); | 4438 registerWrapper(OriginalHTMLTemplateElement, HTMLTemplateElement); |
| 3880 | 4439 |
| 3881 scope.wrappers.HTMLTemplateElement = HTMLTemplateElement; | 4440 scope.wrappers.HTMLTemplateElement = HTMLTemplateElement; |
| 3882 })(this.ShadowDOMPolyfill); | 4441 })(window.ShadowDOMPolyfill); |
| 4442 |
| 3883 // Copyright 2013 The Polymer Authors. All rights reserved. | 4443 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 3884 // Use of this source code is goverened by a BSD-style | 4444 // Use of this source code is goverened by a BSD-style |
| 3885 // license that can be found in the LICENSE file. | 4445 // license that can be found in the LICENSE file. |
| 3886 | 4446 |
| 3887 (function(scope) { | 4447 (function(scope) { |
| 3888 'use strict'; | 4448 'use strict'; |
| 3889 | 4449 |
| 3890 var HTMLElement = scope.wrappers.HTMLElement; | 4450 var HTMLElement = scope.wrappers.HTMLElement; |
| 3891 var registerWrapper = scope.registerWrapper; | 4451 var registerWrapper = scope.registerWrapper; |
| 3892 | 4452 |
| 3893 var OriginalHTMLMediaElement = window.HTMLMediaElement; | 4453 var OriginalHTMLMediaElement = window.HTMLMediaElement; |
| 3894 | 4454 |
| 3895 function HTMLMediaElement(node) { | 4455 function HTMLMediaElement(node) { |
| 3896 HTMLElement.call(this, node); | 4456 HTMLElement.call(this, node); |
| 3897 } | 4457 } |
| 3898 HTMLMediaElement.prototype = Object.create(HTMLElement.prototype); | 4458 HTMLMediaElement.prototype = Object.create(HTMLElement.prototype); |
| 3899 | 4459 |
| 3900 registerWrapper(OriginalHTMLMediaElement, HTMLMediaElement, | 4460 registerWrapper(OriginalHTMLMediaElement, HTMLMediaElement, |
| 3901 document.createElement('audio')); | 4461 document.createElement('audio')); |
| 3902 | 4462 |
| 3903 scope.wrappers.HTMLMediaElement = HTMLMediaElement; | 4463 scope.wrappers.HTMLMediaElement = HTMLMediaElement; |
| 3904 })(this.ShadowDOMPolyfill); | 4464 })(window.ShadowDOMPolyfill); |
| 3905 | 4465 |
| 3906 // Copyright 2013 The Polymer Authors. All rights reserved. | 4466 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 3907 // Use of this source code is goverened by a BSD-style | 4467 // Use of this source code is goverened by a BSD-style |
| 3908 // license that can be found in the LICENSE file. | 4468 // license that can be found in the LICENSE file. |
| 3909 | 4469 |
| 3910 (function(scope) { | 4470 (function(scope) { |
| 3911 'use strict'; | 4471 'use strict'; |
| 3912 | 4472 |
| 3913 var HTMLMediaElement = scope.wrappers.HTMLMediaElement; | 4473 var HTMLMediaElement = scope.wrappers.HTMLMediaElement; |
| 3914 var registerWrapper = scope.registerWrapper; | 4474 var registerWrapper = scope.registerWrapper; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3937 | 4497 |
| 3938 node.setAttribute('preload', 'auto'); | 4498 node.setAttribute('preload', 'auto'); |
| 3939 if (src !== undefined) | 4499 if (src !== undefined) |
| 3940 node.setAttribute('src', src); | 4500 node.setAttribute('src', src); |
| 3941 } | 4501 } |
| 3942 | 4502 |
| 3943 Audio.prototype = HTMLAudioElement.prototype; | 4503 Audio.prototype = HTMLAudioElement.prototype; |
| 3944 | 4504 |
| 3945 scope.wrappers.HTMLAudioElement = HTMLAudioElement; | 4505 scope.wrappers.HTMLAudioElement = HTMLAudioElement; |
| 3946 scope.wrappers.Audio = Audio; | 4506 scope.wrappers.Audio = Audio; |
| 3947 })(this.ShadowDOMPolyfill); | 4507 })(window.ShadowDOMPolyfill); |
| 3948 | 4508 |
| 3949 // Copyright 2013 The Polymer Authors. All rights reserved. | 4509 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 3950 // Use of this source code is goverened by a BSD-style | 4510 // Use of this source code is goverened by a BSD-style |
| 3951 // license that can be found in the LICENSE file. | 4511 // license that can be found in the LICENSE file. |
| 3952 | 4512 |
| 3953 (function(scope) { | 4513 (function(scope) { |
| 3954 'use strict'; | 4514 'use strict'; |
| 3955 | 4515 |
| 3956 var HTMLElement = scope.wrappers.HTMLElement; | 4516 var HTMLElement = scope.wrappers.HTMLElement; |
| 3957 var mixin = scope.mixin; | 4517 var mixin = scope.mixin; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4001 node.setAttribute('value', value); | 4561 node.setAttribute('value', value); |
| 4002 if (defaultSelected === true) | 4562 if (defaultSelected === true) |
| 4003 node.setAttribute('selected', ''); | 4563 node.setAttribute('selected', ''); |
| 4004 node.selected = selected === true; | 4564 node.selected = selected === true; |
| 4005 } | 4565 } |
| 4006 | 4566 |
| 4007 Option.prototype = HTMLOptionElement.prototype; | 4567 Option.prototype = HTMLOptionElement.prototype; |
| 4008 | 4568 |
| 4009 scope.wrappers.HTMLOptionElement = HTMLOptionElement; | 4569 scope.wrappers.HTMLOptionElement = HTMLOptionElement; |
| 4010 scope.wrappers.Option = Option; | 4570 scope.wrappers.Option = Option; |
| 4011 })(this.ShadowDOMPolyfill); | 4571 })(window.ShadowDOMPolyfill); |
| 4012 | 4572 |
| 4013 // Copyright 2013 The Polymer Authors. All rights reserved. | 4573 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 4014 // Use of this source code is goverened by a BSD-style | 4574 // Use of this source code is goverened by a BSD-style |
| 4015 // license that can be found in the LICENSE file. | 4575 // license that can be found in the LICENSE file. |
| 4016 | 4576 |
| 4017 (function(scope) { | 4577 (function(scope) { |
| 4018 'use strict'; | 4578 'use strict'; |
| 4019 | 4579 |
| 4020 var HTMLContentElement = scope.wrappers.HTMLContentElement; | 4580 var HTMLContentElement = scope.wrappers.HTMLContentElement; |
| 4021 var HTMLElement = scope.wrappers.HTMLElement; | 4581 var HTMLElement = scope.wrappers.HTMLElement; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4033 case 'shadow': | 4593 case 'shadow': |
| 4034 return new HTMLShadowElement(node); | 4594 return new HTMLShadowElement(node); |
| 4035 case 'template': | 4595 case 'template': |
| 4036 return new HTMLTemplateElement(node); | 4596 return new HTMLTemplateElement(node); |
| 4037 } | 4597 } |
| 4038 HTMLElement.call(this, node); | 4598 HTMLElement.call(this, node); |
| 4039 } | 4599 } |
| 4040 HTMLUnknownElement.prototype = Object.create(HTMLElement.prototype); | 4600 HTMLUnknownElement.prototype = Object.create(HTMLElement.prototype); |
| 4041 registerWrapper(OriginalHTMLUnknownElement, HTMLUnknownElement); | 4601 registerWrapper(OriginalHTMLUnknownElement, HTMLUnknownElement); |
| 4042 scope.wrappers.HTMLUnknownElement = HTMLUnknownElement; | 4602 scope.wrappers.HTMLUnknownElement = HTMLUnknownElement; |
| 4043 })(this.ShadowDOMPolyfill); | 4603 })(window.ShadowDOMPolyfill); |
| 4604 |
| 4044 // Copyright 2013 The Polymer Authors. All rights reserved. | 4605 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 4045 // Use of this source code is goverened by a BSD-style | 4606 // Use of this source code is goverened by a BSD-style |
| 4046 // license that can be found in the LICENSE file. | 4607 // license that can be found in the LICENSE file. |
| 4047 | 4608 |
| 4048 (function(scope) { | 4609 (function(scope) { |
| 4049 'use strict'; | 4610 'use strict'; |
| 4050 | 4611 |
| 4051 var mixin = scope.mixin; | 4612 var mixin = scope.mixin; |
| 4052 var registerWrapper = scope.registerWrapper; | 4613 var registerWrapper = scope.registerWrapper; |
| 4053 var unwrap = scope.unwrap; | 4614 var unwrap = scope.unwrap; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 4069 arguments[0] = unwrapIfNeeded(arguments[0]); | 4630 arguments[0] = unwrapIfNeeded(arguments[0]); |
| 4070 this.impl.drawImage.apply(this.impl, arguments); | 4631 this.impl.drawImage.apply(this.impl, arguments); |
| 4071 }, | 4632 }, |
| 4072 | 4633 |
| 4073 createPattern: function() { | 4634 createPattern: function() { |
| 4074 arguments[0] = unwrap(arguments[0]); | 4635 arguments[0] = unwrap(arguments[0]); |
| 4075 return this.impl.createPattern.apply(this.impl, arguments); | 4636 return this.impl.createPattern.apply(this.impl, arguments); |
| 4076 } | 4637 } |
| 4077 }); | 4638 }); |
| 4078 | 4639 |
| 4079 registerWrapper(OriginalCanvasRenderingContext2D, CanvasRenderingContext2D); | 4640 registerWrapper(OriginalCanvasRenderingContext2D, CanvasRenderingContext2D, |
| 4641 document.createElement('canvas').getContext('2d')); |
| 4080 | 4642 |
| 4081 scope.wrappers.CanvasRenderingContext2D = CanvasRenderingContext2D; | 4643 scope.wrappers.CanvasRenderingContext2D = CanvasRenderingContext2D; |
| 4082 })(this.ShadowDOMPolyfill); | 4644 })(window.ShadowDOMPolyfill); |
| 4083 | 4645 |
| 4084 // Copyright 2013 The Polymer Authors. All rights reserved. | 4646 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 4085 // Use of this source code is goverened by a BSD-style | 4647 // Use of this source code is goverened by a BSD-style |
| 4086 // license that can be found in the LICENSE file. | 4648 // license that can be found in the LICENSE file. |
| 4087 | 4649 |
| 4088 (function(scope) { | 4650 (function(scope) { |
| 4089 'use strict'; | 4651 'use strict'; |
| 4090 | 4652 |
| 4091 var mixin = scope.mixin; | 4653 var mixin = scope.mixin; |
| 4092 var registerWrapper = scope.registerWrapper; | 4654 var registerWrapper = scope.registerWrapper; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 4112 arguments[5] = unwrapIfNeeded(arguments[5]); | 4674 arguments[5] = unwrapIfNeeded(arguments[5]); |
| 4113 this.impl.texImage2D.apply(this.impl, arguments); | 4675 this.impl.texImage2D.apply(this.impl, arguments); |
| 4114 }, | 4676 }, |
| 4115 | 4677 |
| 4116 texSubImage2D: function() { | 4678 texSubImage2D: function() { |
| 4117 arguments[6] = unwrapIfNeeded(arguments[6]); | 4679 arguments[6] = unwrapIfNeeded(arguments[6]); |
| 4118 this.impl.texSubImage2D.apply(this.impl, arguments); | 4680 this.impl.texSubImage2D.apply(this.impl, arguments); |
| 4119 } | 4681 } |
| 4120 }); | 4682 }); |
| 4121 | 4683 |
| 4122 registerWrapper(OriginalWebGLRenderingContext, WebGLRenderingContext); | 4684 // Blink/WebKit has broken DOM bindings. Usually we would create an instance |
| 4685 // of the object and pass it into registerWrapper as a "blueprint" but |
| 4686 // creating WebGL contexts is expensive and might fail so we use a dummy |
| 4687 // object with dummy instance properties for these broken browsers. |
| 4688 var instanceProperties = /WebKit/.test(navigator.userAgent) ? |
| 4689 {drawingBufferHeight: null, drawingBufferWidth: null} : {}; |
| 4690 |
| 4691 registerWrapper(OriginalWebGLRenderingContext, WebGLRenderingContext, |
| 4692 instanceProperties); |
| 4123 | 4693 |
| 4124 scope.wrappers.WebGLRenderingContext = WebGLRenderingContext; | 4694 scope.wrappers.WebGLRenderingContext = WebGLRenderingContext; |
| 4125 })(this.ShadowDOMPolyfill); | 4695 })(window.ShadowDOMPolyfill); |
| 4126 | 4696 |
| 4127 // Copyright 2013 The Polymer Authors. All rights reserved. | 4697 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 4128 // Use of this source code is goverened by a BSD-style | 4698 // Use of this source code is goverened by a BSD-style |
| 4699 // license that can be found in the LICENSE file. |
| 4700 |
| 4701 (function(scope) { |
| 4702 'use strict'; |
| 4703 |
| 4704 var registerWrapper = scope.registerWrapper; |
| 4705 var unwrap = scope.unwrap; |
| 4706 var unwrapIfNeeded = scope.unwrapIfNeeded; |
| 4707 var wrap = scope.wrap; |
| 4708 |
| 4709 var OriginalRange = window.Range; |
| 4710 |
| 4711 function Range(impl) { |
| 4712 this.impl = impl; |
| 4713 } |
| 4714 Range.prototype = { |
| 4715 get startContainer() { |
| 4716 return wrap(this.impl.startContainer); |
| 4717 }, |
| 4718 get endContainer() { |
| 4719 return wrap(this.impl.endContainer); |
| 4720 }, |
| 4721 get commonAncestorContainer() { |
| 4722 return wrap(this.impl.commonAncestorContainer); |
| 4723 }, |
| 4724 setStart: function(refNode,offset) { |
| 4725 this.impl.setStart(unwrapIfNeeded(refNode), offset); |
| 4726 }, |
| 4727 setEnd: function(refNode,offset) { |
| 4728 this.impl.setEnd(unwrapIfNeeded(refNode), offset); |
| 4729 }, |
| 4730 setStartBefore: function(refNode) { |
| 4731 this.impl.setStartBefore(unwrapIfNeeded(refNode)); |
| 4732 }, |
| 4733 setStartAfter: function(refNode) { |
| 4734 this.impl.setStartAfter(unwrapIfNeeded(refNode)); |
| 4735 }, |
| 4736 setEndBefore: function(refNode) { |
| 4737 this.impl.setEndBefore(unwrapIfNeeded(refNode)); |
| 4738 }, |
| 4739 setEndAfter: function(refNode) { |
| 4740 this.impl.setEndAfter(unwrapIfNeeded(refNode)); |
| 4741 }, |
| 4742 selectNode: function(refNode) { |
| 4743 this.impl.selectNode(unwrapIfNeeded(refNode)); |
| 4744 }, |
| 4745 selectNodeContents: function(refNode) { |
| 4746 this.impl.selectNodeContents(unwrapIfNeeded(refNode)); |
| 4747 }, |
| 4748 compareBoundaryPoints: function(how, sourceRange) { |
| 4749 return this.impl.compareBoundaryPoints(how, unwrap(sourceRange)); |
| 4750 }, |
| 4751 extractContents: function() { |
| 4752 return wrap(this.impl.extractContents()); |
| 4753 }, |
| 4754 cloneContents: function() { |
| 4755 return wrap(this.impl.cloneContents()); |
| 4756 }, |
| 4757 insertNode: function(node) { |
| 4758 this.impl.insertNode(unwrapIfNeeded(node)); |
| 4759 }, |
| 4760 surroundContents: function(newParent) { |
| 4761 this.impl.surroundContents(unwrapIfNeeded(newParent)); |
| 4762 }, |
| 4763 cloneRange: function() { |
| 4764 return wrap(this.impl.cloneRange()); |
| 4765 }, |
| 4766 isPointInRange: function(node, offset) { |
| 4767 return this.impl.isPointInRange(unwrapIfNeeded(node), offset); |
| 4768 }, |
| 4769 comparePoint: function(node, offset) { |
| 4770 return this.impl.comparePoint(unwrapIfNeeded(node), offset); |
| 4771 }, |
| 4772 intersectsNode: function(node) { |
| 4773 return this.impl.intersectsNode(unwrapIfNeeded(node)); |
| 4774 } |
| 4775 }; |
| 4776 |
| 4777 // IE9 does not have createContextualFragment. |
| 4778 if (OriginalRange.prototype.createContextualFragment) { |
| 4779 Range.prototype.createContextualFragment = function(html) { |
| 4780 return wrap(this.impl.createContextualFragment(html)); |
| 4781 }; |
| 4782 } |
| 4783 |
| 4784 registerWrapper(window.Range, Range, document.createRange()); |
| 4785 |
| 4786 scope.wrappers.Range = Range; |
| 4787 |
| 4788 })(window.ShadowDOMPolyfill); |
| 4789 |
| 4790 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 4791 // Use of this source code is goverened by a BSD-style |
| 4129 // license that can be found in the LICENSE file. | 4792 // license that can be found in the LICENSE file. |
| 4130 | 4793 |
| 4131 (function(scope) { | 4794 (function(scope) { |
| 4132 'use strict'; | 4795 'use strict'; |
| 4133 | 4796 |
| 4134 var GetElementsByInterface = scope.GetElementsByInterface; | 4797 var GetElementsByInterface = scope.GetElementsByInterface; |
| 4135 var ParentNodeInterface = scope.ParentNodeInterface; | 4798 var ParentNodeInterface = scope.ParentNodeInterface; |
| 4136 var SelectorsInterface = scope.SelectorsInterface; | 4799 var SelectorsInterface = scope.SelectorsInterface; |
| 4137 var mixin = scope.mixin; | 4800 var mixin = scope.mixin; |
| 4138 var registerObject = scope.registerObject; | 4801 var registerObject = scope.registerObject; |
| 4139 | 4802 |
| 4140 var DocumentFragment = registerObject(document.createDocumentFragment()); | 4803 var DocumentFragment = registerObject(document.createDocumentFragment()); |
| 4141 mixin(DocumentFragment.prototype, ParentNodeInterface); | 4804 mixin(DocumentFragment.prototype, ParentNodeInterface); |
| 4142 mixin(DocumentFragment.prototype, SelectorsInterface); | 4805 mixin(DocumentFragment.prototype, SelectorsInterface); |
| 4143 mixin(DocumentFragment.prototype, GetElementsByInterface); | 4806 mixin(DocumentFragment.prototype, GetElementsByInterface); |
| 4144 | 4807 |
| 4145 var Text = registerObject(document.createTextNode('')); | 4808 var Text = registerObject(document.createTextNode('')); |
| 4146 var Comment = registerObject(document.createComment('')); | 4809 var Comment = registerObject(document.createComment('')); |
| 4147 | 4810 |
| 4148 scope.wrappers.Comment = Comment; | 4811 scope.wrappers.Comment = Comment; |
| 4149 scope.wrappers.DocumentFragment = DocumentFragment; | 4812 scope.wrappers.DocumentFragment = DocumentFragment; |
| 4150 scope.wrappers.Text = Text; | 4813 scope.wrappers.Text = Text; |
| 4151 | 4814 |
| 4152 })(this.ShadowDOMPolyfill); | 4815 })(window.ShadowDOMPolyfill); |
| 4153 | 4816 |
| 4154 // Copyright 2013 The Polymer Authors. All rights reserved. | 4817 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 4155 // Use of this source code is goverened by a BSD-style | 4818 // Use of this source code is goverened by a BSD-style |
| 4156 // license that can be found in the LICENSE file. | 4819 // license that can be found in the LICENSE file. |
| 4157 | 4820 |
| 4158 (function(scope) { | 4821 (function(scope) { |
| 4159 'use strict'; | 4822 'use strict'; |
| 4160 | 4823 |
| 4161 var DocumentFragment = scope.wrappers.DocumentFragment; | 4824 var DocumentFragment = scope.wrappers.DocumentFragment; |
| 4162 var elementFromPoint = scope.elementFromPoint; | 4825 var elementFromPoint = scope.elementFromPoint; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4207 elementFromPoint: function(x, y) { | 4870 elementFromPoint: function(x, y) { |
| 4208 return elementFromPoint(this, this.ownerDocument, x, y); | 4871 return elementFromPoint(this, this.ownerDocument, x, y); |
| 4209 }, | 4872 }, |
| 4210 | 4873 |
| 4211 getElementById: function(id) { | 4874 getElementById: function(id) { |
| 4212 return this.querySelector('#' + id); | 4875 return this.querySelector('#' + id); |
| 4213 } | 4876 } |
| 4214 }); | 4877 }); |
| 4215 | 4878 |
| 4216 scope.wrappers.ShadowRoot = ShadowRoot; | 4879 scope.wrappers.ShadowRoot = ShadowRoot; |
| 4217 })(this.ShadowDOMPolyfill); | 4880 |
| 4881 })(window.ShadowDOMPolyfill); |
| 4882 |
| 4218 // Copyright 2013 The Polymer Authors. All rights reserved. | 4883 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 4219 // Use of this source code is governed by a BSD-style | 4884 // Use of this source code is governed by a BSD-style |
| 4220 // license that can be found in the LICENSE file. | 4885 // license that can be found in the LICENSE file. |
| 4221 | 4886 |
| 4222 (function(scope) { | 4887 (function(scope) { |
| 4223 'use strict'; | 4888 'use strict'; |
| 4224 | 4889 |
| 4225 var Element = scope.wrappers.Element; | 4890 var Element = scope.wrappers.Element; |
| 4226 var HTMLContentElement = scope.wrappers.HTMLContentElement; | 4891 var HTMLContentElement = scope.wrappers.HTMLContentElement; |
| 4227 var HTMLShadowElement = scope.wrappers.HTMLShadowElement; | 4892 var HTMLShadowElement = scope.wrappers.HTMLShadowElement; |
| (...skipping 614 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4842 return false; | 5507 return false; |
| 4843 }; | 5508 }; |
| 4844 | 5509 |
| 4845 HTMLContentElement.prototype.getDistributedNodes = function() { | 5510 HTMLContentElement.prototype.getDistributedNodes = function() { |
| 4846 // TODO(arv): We should only rerender the dirty ancestor renderers (from | 5511 // TODO(arv): We should only rerender the dirty ancestor renderers (from |
| 4847 // the root and down). | 5512 // the root and down). |
| 4848 renderAllPending(); | 5513 renderAllPending(); |
| 4849 return getDistributedChildNodes(this); | 5514 return getDistributedChildNodes(this); |
| 4850 }; | 5515 }; |
| 4851 | 5516 |
| 4852 HTMLShadowElement.prototype.nodeWasAdded_ = | 5517 HTMLShadowElement.prototype.nodeIsInserted_ = |
| 4853 HTMLContentElement.prototype.nodeWasAdded_ = function() { | 5518 HTMLContentElement.prototype.nodeIsInserted_ = function() { |
| 4854 // Invalidate old renderer if any. | 5519 // Invalidate old renderer if any. |
| 4855 this.invalidateShadowRenderer(); | 5520 this.invalidateShadowRenderer(); |
| 4856 | 5521 |
| 4857 var shadowRoot = getShadowRootAncestor(this); | 5522 var shadowRoot = getShadowRootAncestor(this); |
| 4858 var renderer; | 5523 var renderer; |
| 4859 if (shadowRoot) | 5524 if (shadowRoot) |
| 4860 renderer = getRendererForShadowRoot(shadowRoot); | 5525 renderer = getRendererForShadowRoot(shadowRoot); |
| 4861 this.impl.polymerShadowRenderer_ = renderer; | 5526 this.impl.polymerShadowRenderer_ = renderer; |
| 4862 if (renderer) | 5527 if (renderer) |
| 4863 renderer.invalidate(); | 5528 renderer.invalidate(); |
| 4864 }; | 5529 }; |
| 4865 | 5530 |
| 4866 scope.eventParentsTable = eventParentsTable; | 5531 scope.eventParentsTable = eventParentsTable; |
| 4867 scope.getRendererForHost = getRendererForHost; | 5532 scope.getRendererForHost = getRendererForHost; |
| 4868 scope.getShadowTrees = getShadowTrees; | 5533 scope.getShadowTrees = getShadowTrees; |
| 4869 scope.insertionParentTable = insertionParentTable; | 5534 scope.insertionParentTable = insertionParentTable; |
| 4870 scope.renderAllPending = renderAllPending; | 5535 scope.renderAllPending = renderAllPending; |
| 4871 | 5536 |
| 4872 // Exposed for testing | 5537 // Exposed for testing |
| 4873 scope.visual = { | 5538 scope.visual = { |
| 4874 insertBefore: insertBefore, | 5539 insertBefore: insertBefore, |
| 4875 remove: remove, | 5540 remove: remove, |
| 4876 }; | 5541 }; |
| 4877 | 5542 |
| 4878 })(this.ShadowDOMPolyfill); | 5543 })(window.ShadowDOMPolyfill); |
| 5544 |
| 4879 // Copyright 2013 The Polymer Authors. All rights reserved. | 5545 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 4880 // Use of this source code is goverened by a BSD-style | 5546 // Use of this source code is goverened by a BSD-style |
| 4881 // license that can be found in the LICENSE file. | 5547 // license that can be found in the LICENSE file. |
| 4882 | 5548 |
| 4883 (function(scope) { | 5549 (function(scope) { |
| 4884 'use strict'; | 5550 'use strict'; |
| 4885 | 5551 |
| 4886 var HTMLElement = scope.wrappers.HTMLElement; | 5552 var HTMLElement = scope.wrappers.HTMLElement; |
| 4887 var assert = scope.assert; | 5553 var assert = scope.assert; |
| 4888 var mixin = scope.mixin; | 5554 var mixin = scope.mixin; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4922 }, | 5588 }, |
| 4923 }); | 5589 }); |
| 4924 | 5590 |
| 4925 registerWrapper(window[name], GeneratedWrapper, | 5591 registerWrapper(window[name], GeneratedWrapper, |
| 4926 document.createElement(name.slice(4, -7))); | 5592 document.createElement(name.slice(4, -7))); |
| 4927 scope.wrappers[name] = GeneratedWrapper; | 5593 scope.wrappers[name] = GeneratedWrapper; |
| 4928 } | 5594 } |
| 4929 | 5595 |
| 4930 elementsWithFormProperty.forEach(createWrapperConstructor); | 5596 elementsWithFormProperty.forEach(createWrapperConstructor); |
| 4931 | 5597 |
| 4932 })(this.ShadowDOMPolyfill); | 5598 })(window.ShadowDOMPolyfill); |
| 4933 | 5599 |
| 4934 // Copyright 2013 The Polymer Authors. All rights reserved. | 5600 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 4935 // Use of this source code is goverened by a BSD-style | 5601 // Use of this source code is goverened by a BSD-style |
| 4936 // license that can be found in the LICENSE file. | 5602 // license that can be found in the LICENSE file. |
| 4937 | 5603 |
| 4938 (function(scope) { | 5604 (function(scope) { |
| 4939 'use strict'; | 5605 'use strict'; |
| 4940 | 5606 |
| 4941 var GetElementsByInterface = scope.GetElementsByInterface; | 5607 var GetElementsByInterface = scope.GetElementsByInterface; |
| 4942 var Node = scope.wrappers.Node; | 5608 var Node = scope.wrappers.Node; |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5214 'createDocumentType', | 5880 'createDocumentType', |
| 5215 'createDocument', | 5881 'createDocument', |
| 5216 'createHTMLDocument', | 5882 'createHTMLDocument', |
| 5217 'hasFeature', | 5883 'hasFeature', |
| 5218 ]); | 5884 ]); |
| 5219 | 5885 |
| 5220 scope.adoptNodeNoRemove = adoptNodeNoRemove; | 5886 scope.adoptNodeNoRemove = adoptNodeNoRemove; |
| 5221 scope.wrappers.DOMImplementation = DOMImplementation; | 5887 scope.wrappers.DOMImplementation = DOMImplementation; |
| 5222 scope.wrappers.Document = Document; | 5888 scope.wrappers.Document = Document; |
| 5223 | 5889 |
| 5224 })(this.ShadowDOMPolyfill); | 5890 })(window.ShadowDOMPolyfill); |
| 5225 | 5891 |
| 5226 // Copyright 2013 The Polymer Authors. All rights reserved. | 5892 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 5227 // Use of this source code is goverened by a BSD-style | 5893 // Use of this source code is goverened by a BSD-style |
| 5228 // license that can be found in the LICENSE file. | 5894 // license that can be found in the LICENSE file. |
| 5229 | 5895 |
| 5230 (function(scope) { | 5896 (function(scope) { |
| 5231 'use strict'; | 5897 'use strict'; |
| 5232 | 5898 |
| 5233 var EventTarget = scope.wrappers.EventTarget; | 5899 var EventTarget = scope.wrappers.EventTarget; |
| 5234 var mixin = scope.mixin; | 5900 var mixin = scope.mixin; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 5264 getComputedStyle: function(el, pseudo) { | 5930 getComputedStyle: function(el, pseudo) { |
| 5265 return originalGetComputedStyle.call(unwrap(this), unwrapIfNeeded(el), | 5931 return originalGetComputedStyle.call(unwrap(this), unwrapIfNeeded(el), |
| 5266 pseudo); | 5932 pseudo); |
| 5267 } | 5933 } |
| 5268 }); | 5934 }); |
| 5269 | 5935 |
| 5270 registerWrapper(OriginalWindow, Window); | 5936 registerWrapper(OriginalWindow, Window); |
| 5271 | 5937 |
| 5272 scope.wrappers.Window = Window; | 5938 scope.wrappers.Window = Window; |
| 5273 | 5939 |
| 5274 })(this.ShadowDOMPolyfill); | 5940 })(window.ShadowDOMPolyfill); |
| 5275 | 5941 |
| 5276 // Copyright 2013 The Polymer Authors. All rights reserved. | 5942 // Copyright 2013 The Polymer Authors. All rights reserved. |
| 5277 // Use of this source code is goverened by a BSD-style | 5943 // Use of this source code is goverened by a BSD-style |
| 5278 // license that can be found in the LICENSE file. | |
| 5279 | |
| 5280 (function(scope) { | |
| 5281 'use strict'; | |
| 5282 | |
| 5283 var defineGetter = scope.defineGetter; | |
| 5284 var defineWrapGetter = scope.defineWrapGetter; | |
| 5285 var registerWrapper = scope.registerWrapper; | |
| 5286 var unwrapIfNeeded = scope.unwrapIfNeeded; | |
| 5287 var wrapNodeList = scope.wrapNodeList; | |
| 5288 var wrappers = scope.wrappers; | |
| 5289 | |
| 5290 var OriginalMutationObserver = window.MutationObserver || | |
| 5291 window.WebKitMutationObserver; | |
| 5292 | |
| 5293 if (!OriginalMutationObserver) | |
| 5294 return; | |
| 5295 | |
| 5296 var OriginalMutationRecord = window.MutationRecord; | |
| 5297 | |
| 5298 function MutationRecord(impl) { | |
| 5299 this.impl = impl; | |
| 5300 } | |
| 5301 | |
| 5302 MutationRecord.prototype = { | |
| 5303 get addedNodes() { | |
| 5304 return wrapNodeList(this.impl.addedNodes); | |
| 5305 }, | |
| 5306 get removedNodes() { | |
| 5307 return wrapNodeList(this.impl.removedNodes); | |
| 5308 } | |
| 5309 }; | |
| 5310 | |
| 5311 ['target', 'previousSibling', 'nextSibling'].forEach(function(name) { | |
| 5312 defineWrapGetter(MutationRecord, name); | |
| 5313 }); | |
| 5314 | |
| 5315 // WebKit/Blink treats these as instance properties so we override | |
| 5316 [ | |
| 5317 'type', | |
| 5318 'attributeName', | |
| 5319 'attributeNamespace', | |
| 5320 'oldValue' | |
| 5321 ].forEach(function(name) { | |
| 5322 defineGetter(MutationRecord, name, function() { | |
| 5323 return this.impl[name]; | |
| 5324 }); | |
| 5325 }); | |
| 5326 | |
| 5327 if (OriginalMutationRecord) | |
| 5328 registerWrapper(OriginalMutationRecord, MutationRecord); | |
| 5329 | |
| 5330 function wrapRecord(record) { | |
| 5331 return new MutationRecord(record); | |
| 5332 } | |
| 5333 | |
| 5334 function wrapRecords(records) { | |
| 5335 return records.map(wrapRecord); | |
| 5336 } | |
| 5337 | |
| 5338 function MutationObserver(callback) { | |
| 5339 var self = this; | |
| 5340 this.impl = new OriginalMutationObserver(function(mutations, observer) { | |
| 5341 callback.call(self, wrapRecords(mutations), self); | |
| 5342 }); | |
| 5343 } | |
| 5344 | |
| 5345 var OriginalNode = window.Node; | |
| 5346 | |
| 5347 MutationObserver.prototype = { | |
| 5348 observe: function(target, options) { | |
| 5349 this.impl.observe(unwrapIfNeeded(target), options); | |
| 5350 }, | |
| 5351 disconnect: function() { | |
| 5352 this.impl.disconnect(); | |
| 5353 }, | |
| 5354 takeRecords: function() { | |
| 5355 return wrapRecords(this.impl.takeRecords()); | |
| 5356 } | |
| 5357 }; | |
| 5358 | |
| 5359 scope.wrappers.MutationObserver = MutationObserver; | |
| 5360 scope.wrappers.MutationRecord = MutationRecord; | |
| 5361 | |
| 5362 })(this.ShadowDOMPolyfill); | |
| 5363 | |
| 5364 // Copyright 2013 The Polymer Authors. All rights reserved. | |
| 5365 // Use of this source code is goverened by a BSD-style | |
| 5366 // license that can be found in the LICENSE file. | |
| 5367 | |
| 5368 (function(scope) { | |
| 5369 'use strict'; | |
| 5370 | |
| 5371 var registerWrapper = scope.registerWrapper; | |
| 5372 var unwrap = scope.unwrap; | |
| 5373 var unwrapIfNeeded = scope.unwrapIfNeeded; | |
| 5374 var wrap = scope.wrap; | |
| 5375 | |
| 5376 var OriginalRange = window.Range; | |
| 5377 | |
| 5378 function Range(impl) { | |
| 5379 this.impl = impl; | |
| 5380 } | |
| 5381 Range.prototype = { | |
| 5382 get startContainer() { | |
| 5383 return wrap(this.impl.startContainer); | |
| 5384 }, | |
| 5385 get endContainer() { | |
| 5386 return wrap(this.impl.endContainer); | |
| 5387 }, | |
| 5388 get commonAncestorContainer() { | |
| 5389 return wrap(this.impl.commonAncestorContainer); | |
| 5390 }, | |
| 5391 setStart: function(refNode,offset) { | |
| 5392 this.impl.setStart(unwrapIfNeeded(refNode), offset); | |
| 5393 }, | |
| 5394 setEnd: function(refNode,offset) { | |
| 5395 this.impl.setEnd(unwrapIfNeeded(refNode), offset); | |
| 5396 }, | |
| 5397 setStartBefore: function(refNode) { | |
| 5398 this.impl.setStartBefore(unwrapIfNeeded(refNode)); | |
| 5399 }, | |
| 5400 setStartAfter: function(refNode) { | |
| 5401 this.impl.setStartAfter(unwrapIfNeeded(refNode)); | |
| 5402 }, | |
| 5403 setEndBefore: function(refNode) { | |
| 5404 this.impl.setEndBefore(unwrapIfNeeded(refNode)); | |
| 5405 }, | |
| 5406 setEndAfter: function(refNode) { | |
| 5407 this.impl.setEndAfter(unwrapIfNeeded(refNode)); | |
| 5408 }, | |
| 5409 selectNode: function(refNode) { | |
| 5410 this.impl.selectNode(unwrapIfNeeded(refNode)); | |
| 5411 }, | |
| 5412 selectNodeContents: function(refNode) { | |
| 5413 this.impl.selectNodeContents(unwrapIfNeeded(refNode)); | |
| 5414 }, | |
| 5415 compareBoundaryPoints: function(how, sourceRange) { | |
| 5416 return this.impl.compareBoundaryPoints(how, unwrap(sourceRange)); | |
| 5417 }, | |
| 5418 extractContents: function() { | |
| 5419 return wrap(this.impl.extractContents()); | |
| 5420 }, | |
| 5421 cloneContents: function() { | |
| 5422 return wrap(this.impl.cloneContents()); | |
| 5423 }, | |
| 5424 insertNode: function(node) { | |
| 5425 this.impl.insertNode(unwrapIfNeeded(node)); | |
| 5426 }, | |
| 5427 surroundContents: function(newParent) { | |
| 5428 this.impl.surroundContents(unwrapIfNeeded(newParent)); | |
| 5429 }, | |
| 5430 cloneRange: function() { | |
| 5431 return wrap(this.impl.cloneRange()); | |
| 5432 }, | |
| 5433 isPointInRange: function(node, offset) { | |
| 5434 return this.impl.isPointInRange(unwrapIfNeeded(node), offset); | |
| 5435 }, | |
| 5436 comparePoint: function(node, offset) { | |
| 5437 return this.impl.comparePoint(unwrapIfNeeded(node), offset); | |
| 5438 }, | |
| 5439 intersectsNode: function(node) { | |
| 5440 return this.impl.intersectsNode(unwrapIfNeeded(node)); | |
| 5441 } | |
| 5442 }; | |
| 5443 | |
| 5444 // IE9 does not have createContextualFragment. | |
| 5445 if (OriginalRange.prototype.createContextualFragment) { | |
| 5446 Range.prototype.createContextualFragment = function(html) { | |
| 5447 return wrap(this.impl.createContextualFragment(html)); | |
| 5448 }; | |
| 5449 } | |
| 5450 | |
| 5451 registerWrapper(window.Range, Range); | |
| 5452 | |
| 5453 scope.wrappers.Range = Range; | |
| 5454 | |
| 5455 })(this.ShadowDOMPolyfill); | |
| 5456 | |
| 5457 // Copyright 2013 The Polymer Authors. All rights reserved. | |
| 5458 // Use of this source code is goverened by a BSD-style | |
| 5459 // license that can be found in the LICENSE file. | 5944 // license that can be found in the LICENSE file. |
| 5460 | 5945 |
| 5461 (function(scope) { | 5946 (function(scope) { |
| 5462 'use strict'; | 5947 'use strict'; |
| 5463 | 5948 |
| 5464 var isWrapperFor = scope.isWrapperFor; | 5949 var isWrapperFor = scope.isWrapperFor; |
| 5465 | 5950 |
| 5466 // This is a list of the elements we currently override the global constructor | 5951 // This is a list of the elements we currently override the global constructor |
| 5467 // for. | 5952 // for. |
| 5468 var elements = { | 5953 var elements = { |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5547 | 6032 |
| 5548 Object.keys(elements).forEach(overrideConstructor); | 6033 Object.keys(elements).forEach(overrideConstructor); |
| 5549 | 6034 |
| 5550 Object.getOwnPropertyNames(scope.wrappers).forEach(function(name) { | 6035 Object.getOwnPropertyNames(scope.wrappers).forEach(function(name) { |
| 5551 window[name] = scope.wrappers[name] | 6036 window[name] = scope.wrappers[name] |
| 5552 }); | 6037 }); |
| 5553 | 6038 |
| 5554 // Export for testing. | 6039 // Export for testing. |
| 5555 scope.knownElements = elements; | 6040 scope.knownElements = elements; |
| 5556 | 6041 |
| 5557 })(this.ShadowDOMPolyfill); | 6042 })(window.ShadowDOMPolyfill); |
| 6043 |
| 5558 /* | 6044 /* |
| 5559 * Copyright 2013 The Polymer Authors. All rights reserved. | 6045 * Copyright 2013 The Polymer Authors. All rights reserved. |
| 5560 * Use of this source code is governed by a BSD-style | 6046 * Use of this source code is governed by a BSD-style |
| 5561 * license that can be found in the LICENSE file. | 6047 * license that can be found in the LICENSE file. |
| 5562 */ | 6048 */ |
| 5563 (function() { | 6049 (function() { |
| 5564 var ShadowDOMPolyfill = window.ShadowDOMPolyfill; | 6050 var ShadowDOMPolyfill = window.ShadowDOMPolyfill; |
| 5565 var wrap = ShadowDOMPolyfill.wrap; | 6051 var wrap = ShadowDOMPolyfill.wrap; |
| 5566 | 6052 |
| 5567 // patch in prefixed name | 6053 // patch in prefixed name |
| (...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6050 } | 6536 } |
| 6051 } else { | 6537 } else { |
| 6052 return p1 + p3; | 6538 return p1 + p3; |
| 6053 } | 6539 } |
| 6054 }); | 6540 }); |
| 6055 }, | 6541 }, |
| 6056 /* | 6542 /* |
| 6057 * Convert ^ and ^^ combinators by replacing with space. | 6543 * Convert ^ and ^^ combinators by replacing with space. |
| 6058 */ | 6544 */ |
| 6059 convertCombinators: function(cssText) { | 6545 convertCombinators: function(cssText) { |
| 6060 return cssText.replace('^^', ' ').replace('^', ' '); | 6546 return cssText.replace(/\^\^/g, ' ').replace(/\^/g, ' '); |
| 6061 }, | 6547 }, |
| 6062 // change a selector like 'div' to 'name div' | 6548 // change a selector like 'div' to 'name div' |
| 6063 scopeRules: function(cssRules, name, typeExtension) { | 6549 scopeRules: function(cssRules, name, typeExtension) { |
| 6064 var cssText = ''; | 6550 var cssText = ''; |
| 6065 Array.prototype.forEach.call(cssRules, function(rule) { | 6551 Array.prototype.forEach.call(cssRules, function(rule) { |
| 6066 if (rule.selectorText && (rule.style && rule.style.cssText)) { | 6552 if (rule.selectorText && (rule.style && rule.style.cssText)) { |
| 6067 cssText += this.scopeSelector(rule.selectorText, name, typeExtension, | 6553 cssText += this.scopeSelector(rule.selectorText, name, typeExtension, |
| 6068 this.strictStyling) + ' {\n\t'; | 6554 this.strictStyling) + ' {\n\t'; |
| 6069 cssText += this.propertiesFromRule(rule) + '\n}\n\n'; | 6555 cssText += this.propertiesFromRule(rule) + '\n}\n\n'; |
| 6070 } else if (rule.media) { | 6556 } else if (rule.media) { |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6215 addCssToDocument('style { display: none !important; }\n'); | 6701 addCssToDocument('style { display: none !important; }\n'); |
| 6216 var head = document.querySelector('head'); | 6702 var head = document.querySelector('head'); |
| 6217 head.insertBefore(getSheet(), head.childNodes[0]); | 6703 head.insertBefore(getSheet(), head.childNodes[0]); |
| 6218 } | 6704 } |
| 6219 | 6705 |
| 6220 // exports | 6706 // exports |
| 6221 scope.ShadowCSS = ShadowCSS; | 6707 scope.ShadowCSS = ShadowCSS; |
| 6222 | 6708 |
| 6223 })(window.Platform); | 6709 })(window.Platform); |
| 6224 } | 6710 } |
| OLD | NEW |