| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 class _EventFactoryProvider { | 5 class _EventFactoryProvider { |
| 6 factory Event(String type, [bool canBubble = true, | 6 static Event createEvent(String type, [bool canBubble = true, |
| 7 bool cancelable = true]) { | 7 bool cancelable = true]) { |
| 8 final _EventImpl e = _document.$dom_createEvent("Event"); | 8 final _EventImpl e = _document.$dom_createEvent("Event"); |
| 9 e.$dom_initEvent(type, canBubble, cancelable); | 9 e.$dom_initEvent(type, canBubble, cancelable); |
| 10 return e; | 10 return e; |
| 11 } | 11 } |
| 12 } | 12 } |
| 13 | 13 |
| 14 class _MouseEventFactoryProvider { | 14 class _MouseEventFactoryProvider { |
| 15 factory MouseEvent(String type, Window view, int detail, | 15 static MouseEvent createMouseEvent(String type, Window view, int detail, |
| 16 int screenX, int screenY, int clientX, int clientY, int button, | 16 int screenX, int screenY, int clientX, int clientY, int button, |
| 17 [bool canBubble = true, bool cancelable = true, bool ctrlKey = false, | 17 [bool canBubble = true, bool cancelable = true, bool ctrlKey = false, |
| 18 bool altKey = false, bool shiftKey = false, bool metaKey = false, | 18 bool altKey = false, bool shiftKey = false, bool metaKey = false, |
| 19 EventTarget relatedTarget = null]) { | 19 EventTarget relatedTarget = null]) { |
| 20 final e = _document.$dom_createEvent("MouseEvent"); | 20 final e = _document.$dom_createEvent("MouseEvent"); |
| 21 e.$dom_initMouseEvent(type, canBubble, cancelable, view, detail, | 21 e.$dom_initMouseEvent(type, canBubble, cancelable, view, detail, |
| 22 screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metaKey, | 22 screenX, screenY, clientX, clientY, ctrlKey, altKey, shiftKey, metaKey, |
| 23 button, relatedTarget); | 23 button, relatedTarget); |
| 24 return e; | 24 return e; |
| 25 } | 25 } |
| 26 } | 26 } |
| 27 | 27 |
| 28 class _CSSStyleDeclarationFactoryProvider { | 28 class _CSSStyleDeclarationFactoryProvider { |
| 29 factory CSSStyleDeclaration.css(String css) { | 29 static CSSStyleDeclaration createCSSStyleDeclaration_css(String css) { |
| 30 final style = new Element.tag('div').style; | 30 final style = new Element.tag('div').style; |
| 31 style.cssText = css; | 31 style.cssText = css; |
| 32 return style; | 32 return style; |
| 33 } | 33 } |
| 34 | 34 |
| 35 factory CSSStyleDeclaration() { | 35 static CSSStyleDeclaration createCSSStyleDeclaration() { |
| 36 return new CSSStyleDeclaration.css(''); | 36 return new CSSStyleDeclaration.css(''); |
| 37 } | 37 } |
| 38 } | 38 } |
| 39 | 39 |
| 40 class _DocumentFragmentFactoryProvider { | 40 class _DocumentFragmentFactoryProvider { |
| 41 /** @domName Document.createDocumentFragment */ | 41 /** @domName Document.createDocumentFragment */ |
| 42 factory DocumentFragment() => document.createDocumentFragment(); | 42 static DocumentFragment createDocumentFragment() => |
| 43 document.createDocumentFragment(); |
| 43 | 44 |
| 44 factory DocumentFragment.html(String html) { | 45 static DocumentFragment createDocumentFragment_html(String html) { |
| 45 final fragment = new DocumentFragment(); | 46 final fragment = new DocumentFragment(); |
| 46 fragment.innerHTML = html; | 47 fragment.innerHTML = html; |
| 47 return fragment; | 48 return fragment; |
| 48 } | 49 } |
| 49 | 50 |
| 50 // TODO(nweiz): enable this when XML is ported. | 51 // TODO(nweiz): enable this when XML is ported. |
| 51 // factory DocumentFragment.xml(String xml) { | 52 // factory DocumentFragment.xml(String xml) { |
| 52 // final fragment = new DocumentFragment(); | 53 // final fragment = new DocumentFragment(); |
| 53 // final e = new XMLElement.tag("xml"); | 54 // final e = new XMLElement.tag("xml"); |
| 54 // e.innerHTML = xml; | 55 // e.innerHTML = xml; |
| 55 // | 56 // |
| 56 // // Copy list first since we don't want liveness during iteration. | 57 // // Copy list first since we don't want liveness during iteration. |
| 57 // final List nodes = new List.from(e.nodes); | 58 // final List nodes = new List.from(e.nodes); |
| 58 // fragment.nodes.addAll(nodes); | 59 // fragment.nodes.addAll(nodes); |
| 59 // return fragment; | 60 // return fragment; |
| 60 // } | 61 // } |
| 61 | 62 |
| 62 factory DocumentFragment.svg(String svg) { | 63 static DocumentFragment createDocumentFragment_svg(String svg) { |
| 63 final fragment = new DocumentFragment(); | 64 final fragment = new DocumentFragment(); |
| 64 final e = new SVGSVGElement(); | 65 final e = new SVGSVGElement(); |
| 65 e.innerHTML = svg; | 66 e.innerHTML = svg; |
| 66 | 67 |
| 67 // Copy list first since we don't want liveness during iteration. | 68 // Copy list first since we don't want liveness during iteration. |
| 68 final List nodes = new List.from(e.nodes); | 69 final List nodes = new List.from(e.nodes); |
| 69 fragment.nodes.addAll(nodes); | 70 fragment.nodes.addAll(nodes); |
| 70 return fragment; | 71 return fragment; |
| 71 } | 72 } |
| 72 } | 73 } |
| 73 | 74 |
| 74 class _SVGElementFactoryProvider { | 75 class _SVGElementFactoryProvider { |
| 75 factory SVGElement.tag(String tag) { | 76 static SVGElement createSVGElement_tag(String tag) { |
| 76 final Element temp = | 77 final Element temp = |
| 77 _document.$dom_createElementNS("http://www.w3.org/2000/svg", tag); | 78 _document.$dom_createElementNS("http://www.w3.org/2000/svg", tag); |
| 78 return temp; | 79 return temp; |
| 79 } | 80 } |
| 80 | 81 |
| 81 factory SVGElement.svg(String svg) { | 82 static SVGElement createSVGElement_svg(String svg) { |
| 82 Element parentTag; | 83 Element parentTag; |
| 83 final match = _START_TAG_REGEXP.firstMatch(svg); | 84 final match = _START_TAG_REGEXP.firstMatch(svg); |
| 84 if (match != null && match.group(1).toLowerCase() == 'svg') { | 85 if (match != null && match.group(1).toLowerCase() == 'svg') { |
| 85 parentTag = new Element.tag('div'); | 86 parentTag = new Element.tag('div'); |
| 86 } else { | 87 } else { |
| 87 parentTag = new SVGSVGElement(); | 88 parentTag = new SVGSVGElement(); |
| 88 } | 89 } |
| 89 | 90 |
| 90 parentTag.innerHTML = svg; | 91 parentTag.innerHTML = svg; |
| 91 if (parentTag.elements.length == 1) return parentTag.nodes.removeLast(); | 92 if (parentTag.elements.length == 1) return parentTag.nodes.removeLast(); |
| 92 | 93 |
| 93 throw new IllegalArgumentException( | 94 throw new IllegalArgumentException( |
| 94 'SVG had ${parentTag.elements.length} ' | 95 'SVG had ${parentTag.elements.length} ' |
| 95 'top-level elements but 1 expected'); | 96 'top-level elements but 1 expected'); |
| 96 } | 97 } |
| 97 } | 98 } |
| 98 | 99 |
| 99 class _SVGSVGElementFactoryProvider { | 100 class _SVGSVGElementFactoryProvider { |
| 100 factory SVGSVGElement() { | 101 static SVGSVGElement createSVGSVGElement() { |
| 101 final el = new SVGElement.tag("svg"); | 102 final el = new SVGElement.tag("svg"); |
| 102 // The SVG spec requires the version attribute to match the spec version | 103 // The SVG spec requires the version attribute to match the spec version |
| 103 el.attributes['version'] = "1.1"; | 104 el.attributes['version'] = "1.1"; |
| 104 return el; | 105 return el; |
| 105 } | 106 } |
| 106 } | 107 } |
| OLD | NEW |