Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 function createShadowRoot() | 1 function createShadowRoot() |
| 2 { | 2 { |
| 3 var children = Array.prototype.slice.call(arguments); | 3 var children = Array.prototype.slice.call(arguments); |
| 4 if ((children[0] instanceof Object) && !(children[0] instanceof Node)) | 4 if ((children[0] instanceof Object) && !(children[0] instanceof Node)) { |
| 5 return {'isShadowRoot': true, | 5 var attributes = {}; |
| 6 'attributes': children[0], | 6 var parameter = {}; |
| 7 'children': children.slice(1)}; | 7 for (var key in children[0]) { |
| 8 if (key == 'mode') | |
| 9 parameter[key] = children[0][key]; | |
| 10 else | |
| 11 attributes[key] = children[0][key]; | |
| 12 } | |
| 13 var obj = {'isShadowRoot': true, | |
|
hayato
2015/06/09 04:34:38
Nit: I'd prefer returning obj as is here, e.g. re
kochi
2015/06/09 04:46:57
Done.
| |
| 14 'attributes': attributes, | |
| 15 'children': children.slice(1)}; | |
| 16 if (Object.keys(parameter).length > 0) | |
| 17 obj['parameter'] = parameter; | |
| 18 return obj; | |
| 19 } | |
| 8 return {'isShadowRoot': true, | 20 return {'isShadowRoot': true, |
| 9 'children': children}; | 21 'children': children}; |
| 10 } | 22 } |
| 11 | 23 |
| 12 function createUserAgentShadowRoot() | 24 function createUserAgentShadowRoot() |
| 13 { | 25 { |
| 14 var shadowRoot = createShadowRoot.apply(null, arguments); | 26 var shadowRoot = createShadowRoot.apply(null, arguments); |
| 15 shadowRoot.isUserAgentShadowRoot = true; | 27 shadowRoot.isUserAgentShadowRoot = true; |
| 16 return shadowRoot; | 28 return shadowRoot; |
| 17 } | 29 } |
| 18 | 30 |
| 19 // This function can take optional child elements, which might be a result of cr eateShadowRoot(), as arguments[2:]. | 31 // This function can take optional child elements, which might be a result of cr eateShadowRoot(), as arguments[2:]. |
| 20 function createDOM(tagName, attributes) | 32 function createDOM(tagName, attributes) |
| 21 { | 33 { |
| 22 var element = document.createElement(tagName); | 34 var element = document.createElement(tagName); |
| 23 for (var name in attributes) | 35 for (var name in attributes) |
| 24 element.setAttribute(name, attributes[name]); | 36 element.setAttribute(name, attributes[name]); |
| 25 var childElements = Array.prototype.slice.call(arguments, 2); | 37 var childElements = Array.prototype.slice.call(arguments, 2); |
| 26 for (var i = 0; i < childElements.length; ++i) { | 38 for (var i = 0; i < childElements.length; ++i) { |
| 27 var child = childElements[i]; | 39 var child = childElements[i]; |
| 28 if (child.isShadowRoot) { | 40 if (child.isShadowRoot) { |
| 29 var shadowRoot; | 41 var shadowRoot; |
| 30 if (child.isUserAgentShadowRoot) { | 42 if (child.isUserAgentShadowRoot) { |
| 31 shadowRoot = window.internals.createUserAgentShadowRoot(element) ; | 43 shadowRoot = window.internals.createUserAgentShadowRoot(element) ; |
| 32 } else { | 44 } else { |
| 33 shadowRoot = element.createShadowRoot(); | 45 if (child.parameter) |
| 46 shadowRoot = element.createShadowRoot(child.parameter); | |
| 47 else | |
| 48 shadowRoot = element.createShadowRoot(); | |
| 34 } | 49 } |
| 35 if (child.attributes) { | 50 if (child.attributes) { |
| 36 for (var attribute in child.attributes) { | 51 for (var attribute in child.attributes) { |
| 37 // Shadow Root does not have setAttribute. | 52 // Shadow Root does not have setAttribute. |
| 38 shadowRoot[attribute] = child.attributes[attribute]; | 53 shadowRoot[attribute] = child.attributes[attribute]; |
| 39 } | 54 } |
| 40 } | 55 } |
| 41 for (var j = 0; j < child.children.length; ++j) | 56 for (var j = 0; j < child.children.length; ++j) |
| 42 shadowRoot.appendChild(child.children[j]); | 57 shadowRoot.appendChild(child.children[j]); |
| 43 } else | 58 } else |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 259 debug('Traverse in backward.'); | 274 debug('Traverse in backward.'); |
| 260 showComposedShadowTreeByTraversingInBackward(node); | 275 showComposedShadowTreeByTraversingInBackward(node); |
| 261 | 276 |
| 262 debug(''); | 277 debug(''); |
| 263 } | 278 } |
| 264 | 279 |
| 265 function showNextNode(node) { | 280 function showNextNode(node) { |
| 266 var next = internals.nextInComposedTree(node); | 281 var next = internals.nextInComposedTree(node); |
| 267 debug('Next node of [' + dumpNode(node) + '] is [' + dumpNode(next) + ']'); | 282 debug('Next node of [' + dumpNode(node) + '] is [' + dumpNode(next) + ']'); |
| 268 } | 283 } |
| OLD | NEW |