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

Side by Side Diff: pkg/web_components/lib/dart_support.js

Issue 158083002: introduce web_components pkg for consolidated polyfills (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « pkg/web_components/lib/build.log ('k') | pkg/web_components/lib/platform.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 * Copyright 2013 The Polymer Authors. All rights reserved. 2 // for details. All rights reserved. Use of this source code is governed by a
3 * Use of this source code is governed by a BSD-style 3 // BSD-style license that can be found in the LICENSE file.
4 * license that can be found in the LICENSE file. 4
5 */
6 (function() { 5 (function() {
7 var ShadowDOMPolyfill = window.ShadowDOMPolyfill; 6 var ShadowDOMPolyfill = window.ShadowDOMPolyfill;
8 var wrap = ShadowDOMPolyfill.wrap; 7 if (!ShadowDOMPolyfill) return;
9 8
10 // patch in prefixed name 9 var needsConstructorFix = window.constructor === window.Window;
11 Object.defineProperties(HTMLElement.prototype, {
12 //TODO(sjmiles): review accessor alias with Arv
13 webkitShadowRoot: {
14 get: function() {
15 return this.shadowRoot;
16 }
17 }
18 });
19
20 // ShadowCSS needs this:
21 window.wrap = window.ShadowDOMPolyfill.wrap;
22 window.unwrap = window.ShadowDOMPolyfill.unwrap;
23
24 //TODO(sjmiles): review method alias with Arv
25 HTMLElement.prototype.webkitCreateShadowRoot =
26 HTMLElement.prototype.createShadowRoot;
27 10
28 // TODO(jmesserly): we need to wrap document somehow (a dart:html hook?) 11 // TODO(jmesserly): we need to wrap document somehow (a dart:html hook?)
29 window.dartExperimentalFixupGetTag = function(originalGetTag) { 12 window.dartExperimentalFixupGetTag = function(originalGetTag) {
30 var NodeList = ShadowDOMPolyfill.wrappers.NodeList; 13 var NodeList = ShadowDOMPolyfill.wrappers.NodeList;
31 var ShadowRoot = ShadowDOMPolyfill.wrappers.ShadowRoot; 14 var ShadowRoot = ShadowDOMPolyfill.wrappers.ShadowRoot;
32 var unwrapIfNeeded = ShadowDOMPolyfill.unwrapIfNeeded; 15 var unwrapIfNeeded = ShadowDOMPolyfill.unwrapIfNeeded;
33 function getTag(obj) { 16 function getTag(obj) {
34 // TODO(jmesserly): do we still need these? 17 // TODO(jmesserly): do we still need these?
35 if (obj instanceof NodeList) return 'NodeList'; 18 if (obj instanceof NodeList) return 'NodeList';
36 if (obj instanceof ShadowRoot) return 'ShadowRoot'; 19 if (obj instanceof ShadowRoot) return 'ShadowRoot';
37 if (window.MutationRecord && (obj instanceof MutationRecord)) 20 if (MutationRecord && (obj instanceof MutationRecord))
38 return 'MutationRecord'; 21 return 'MutationRecord';
39 if (window.MutationObserver && (obj instanceof MutationObserver)) 22 if (MutationObserver && (obj instanceof MutationObserver))
40 return 'MutationObserver'; 23 return 'MutationObserver';
41 24
42 // TODO(jmesserly): this prevents incorrect interaction between ShadowDOM 25 // TODO(jmesserly): this prevents incorrect interaction between ShadowDOM
43 // and dart:html's <template> polyfill. Essentially, ShadowDOM is 26 // and dart:html's <template> polyfill. Essentially, ShadowDOM is
44 // polyfilling native template, but our Dart polyfill fails to detect this 27 // polyfilling native template, but our Dart polyfill fails to detect this
45 // because the unwrapped node is an HTMLUnknownElement, leading it to 28 // because the unwrapped node is an HTMLUnknownElement, leading it to
46 // think the node has no content. 29 // think the node has no content.
47 if (obj instanceof HTMLTemplateElement) return 'HTMLTemplateElement'; 30 if (obj instanceof HTMLTemplateElement) return 'HTMLTemplateElement';
48 31
49 var unwrapped = unwrapIfNeeded(obj); 32 var unwrapped = unwrapIfNeeded(obj);
50 if (obj !== unwrapped) { 33 if (needsConstructorFix || obj !== unwrapped) {
51 // Fix up class names for Firefox. 34 // Fix up class names for Firefox, or if using the minified polyfill.
52 // For some of them (like HTMLFormElement and HTMLInputElement), 35 // dart2js prefers .constructor.name, but there are all kinds of cases
53 // the "constructor" property of the unwrapped nodes points at the 36 // where this will give the wrong answer.
54 // same constructor as the wrapper.
55 var ctor = obj.constructor 37 var ctor = obj.constructor
56 if (ctor === unwrapped.constructor) { 38 if (ctor === unwrapped.constructor) {
57 var name = ctor._ShadowDOMPolyfill$cacheTag_; 39 var name = ctor._ShadowDOMPolyfill$cacheTag_;
58 if (!name) { 40 if (!name) {
59 name = Object.prototype.toString.call(unwrapped); 41 name = Object.prototype.toString.call(unwrapped);
60 name = name.substring(8, name.length - 1); 42 name = name.substring(8, name.length - 1);
61 ctor._ShadowDOMPolyfill$cacheTag_ = name; 43 ctor._ShadowDOMPolyfill$cacheTag_ = name;
62 } 44 }
63 return name; 45 return name;
64 } 46 }
65 47
66 obj = unwrapped; 48 obj = unwrapped;
67 } 49 }
68 return originalGetTag(obj); 50 return originalGetTag(obj);
69 } 51 }
70 52
71 return getTag; 53 return getTag;
72 }; 54 };
73 })(); 55 })();
OLDNEW
« no previous file with comments | « pkg/web_components/lib/build.log ('k') | pkg/web_components/lib/platform.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698