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 _XMLClassSet extends _CssClassSet { | 5 class _XMLClassSet extends _CssClassSet { |
6 _XMLClassSet(element) : super(element); | 6 _XMLClassSet(element) : super(element); |
7 | 7 |
8 String _className() { | 8 String _className() { |
9 final classStr = _element.getAttribute('class'); | 9 final classStr = _element.getAttribute('class'); |
10 return classStr == null ? '' : classStr; | 10 return classStr == null ? '' : classStr; |
(...skipping 11 matching lines...) Expand all Loading... |
22 | 22 |
23 factory XMLElementWrappingImplementation.xml(String xml) { | 23 factory XMLElementWrappingImplementation.xml(String xml) { |
24 XMLElement parentTag = new XMLElement.tag('xml'); | 24 XMLElement parentTag = new XMLElement.tag('xml'); |
25 parentTag.innerHTML = xml; | 25 parentTag.innerHTML = xml; |
26 if (parentTag.nodes.length == 1) return parentTag.nodes.removeLast(); | 26 if (parentTag.nodes.length == 1) return parentTag.nodes.removeLast(); |
27 | 27 |
28 throw new IllegalArgumentException( | 28 throw new IllegalArgumentException( |
29 'XML had ${parentTag.nodes.length} top-level nodes but 1 expected'); | 29 'XML had ${parentTag.nodes.length} top-level nodes but 1 expected'); |
30 } | 30 } |
31 | 31 |
32 CSSClassSet get classes() { | 32 CSSClassSet get classes { |
33 if (_cssClassSet === null) { | 33 if (_cssClassSet === null) { |
34 _cssClassSet = new _XMLClassSet(_ptr); | 34 _cssClassSet = new _XMLClassSet(_ptr); |
35 } | 35 } |
36 return _cssClassSet; | 36 return _cssClassSet; |
37 } | 37 } |
38 | 38 |
39 ElementList get elements() { | 39 ElementList get elements { |
40 if (_elements == null) { | 40 if (_elements == null) { |
41 _elements = new FilteredElementList(this); | 41 _elements = new FilteredElementList(this); |
42 } | 42 } |
43 return _elements; | 43 return _elements; |
44 } | 44 } |
45 | 45 |
46 void set elements(Collection<Element> value) { | 46 void set elements(Collection<Element> value) { |
47 final elements = this.elements; | 47 final elements = this.elements; |
48 elements.clear(); | 48 elements.clear(); |
49 elements.addAll(value); | 49 elements.addAll(value); |
50 } | 50 } |
51 | 51 |
52 String get outerHTML() { | 52 String get outerHTML { |
53 final container = new Element.tag("div"); | 53 final container = new Element.tag("div"); |
54 // Safari requires that the clone be removed from its owner document before | 54 // Safari requires that the clone be removed from its owner document before |
55 // being inserted into the HTML document. | 55 // being inserted into the HTML document. |
56 container.elements.add(this.clone(true).remove()); | 56 container.elements.add(this.clone(true).remove()); |
57 return container.innerHTML; | 57 return container.innerHTML; |
58 } | 58 } |
59 | 59 |
60 String get innerHTML() { | 60 String get innerHTML { |
61 final container = new Element.tag("div"); | 61 final container = new Element.tag("div"); |
62 // Safari requires that the clone be removed from its owner document before | 62 // Safari requires that the clone be removed from its owner document before |
63 // being inserted into the HTML document. | 63 // being inserted into the HTML document. |
64 container.nodes.addAll(this.clone(true).remove().nodes); | 64 container.nodes.addAll(this.clone(true).remove().nodes); |
65 return container.innerHTML; | 65 return container.innerHTML; |
66 } | 66 } |
67 | 67 |
68 void set innerHTML(String xml) { | 68 void set innerHTML(String xml) { |
69 final xmlDoc = new XMLDocument.xml('<xml>$xml</xml>'); | 69 final xmlDoc = new XMLDocument.xml('<xml>$xml</xml>'); |
70 // Safari requires that the root node be removed from the document before | 70 // Safari requires that the root node be removed from the document before |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 void insertAdjacentText([String where = null, String text = null]) { | 103 void insertAdjacentText([String where = null, String text = null]) { |
104 this._insertAdjacentNode(where, new Text(text)); | 104 this._insertAdjacentNode(where, new Text(text)); |
105 } | 105 } |
106 | 106 |
107 void insertAdjacentHTML( | 107 void insertAdjacentHTML( |
108 [String position_OR_where = null, String text = null]) { | 108 [String position_OR_where = null, String text = null]) { |
109 this._insertAdjacentNode( | 109 this._insertAdjacentNode( |
110 position_OR_where, new DocumentFragment.xml(text)); | 110 position_OR_where, new DocumentFragment.xml(text)); |
111 } | 111 } |
112 | 112 |
113 Future<ElementRect> get rect() { | 113 Future<ElementRect> get rect { |
114 return _createMeasurementFuture(() => const EmptyElementRect(), | 114 return _createMeasurementFuture(() => const EmptyElementRect(), |
115 new Completer<ElementRect>()); | 115 new Completer<ElementRect>()); |
116 } | 116 } |
117 | 117 |
118 // For HTML elemens, the default value of "contentEditable" is "inherit", so | 118 // For HTML elemens, the default value of "contentEditable" is "inherit", so |
119 // we'll use that here as well even though it doesn't really make sense. | 119 // we'll use that here as well even though it doesn't really make sense. |
120 String get contentEditable() => _attr('contentEditable', 'inherit'); | 120 String get contentEditable => _attr('contentEditable', 'inherit'); |
121 | 121 |
122 void set contentEditable(String value) { | 122 void set contentEditable(String value) { |
123 attributes['contentEditable'] = value; | 123 attributes['contentEditable'] = value; |
124 } | 124 } |
125 | 125 |
126 void blur() {} | 126 void blur() {} |
127 void focus() {} | 127 void focus() {} |
128 void scrollByLines([int lines = null]) {} | 128 void scrollByLines([int lines = null]) {} |
129 void scrollByPages([int pages = null]) {} | 129 void scrollByPages([int pages = null]) {} |
130 void scrollIntoView([bool centerIfNeeded = null]) {} | 130 void scrollIntoView([bool centerIfNeeded = null]) {} |
131 | 131 |
132 // Parentless HTML elements return false regardless of the value of their | 132 // Parentless HTML elements return false regardless of the value of their |
133 // contentEditable attribute, so XML elements do the same since they're never | 133 // contentEditable attribute, so XML elements do the same since they're never |
134 // actually editable. | 134 // actually editable. |
135 bool get isContentEditable() => false; | 135 bool get isContentEditable => false; |
136 | 136 |
137 bool get draggable() => attributes['draggable'] == 'true'; | 137 bool get draggable => attributes['draggable'] == 'true'; |
138 | 138 |
139 void set draggable(bool value) { attributes['draggable'] = value.toString(); } | 139 void set draggable(bool value) { attributes['draggable'] = value.toString(); } |
140 | 140 |
141 bool get spellcheck() => attributes['spellcheck'] == 'true'; | 141 bool get spellcheck => attributes['spellcheck'] == 'true'; |
142 | 142 |
143 void set spellcheck(bool value) { | 143 void set spellcheck(bool value) { |
144 attributes['spellcheck'] = value.toString(); | 144 attributes['spellcheck'] = value.toString(); |
145 } | 145 } |
146 | 146 |
147 bool get hidden() => attributes.containsKey('hidden'); | 147 bool get hidden => attributes.containsKey('hidden'); |
148 | 148 |
149 void set hidden(bool value) { | 149 void set hidden(bool value) { |
150 if (value) { | 150 if (value) { |
151 attributes['hidden'] = ''; | 151 attributes['hidden'] = ''; |
152 } else { | 152 } else { |
153 attributes.remove('hidden'); | 153 attributes.remove('hidden'); |
154 } | 154 } |
155 } | 155 } |
156 | 156 |
157 int get tabIndex() { | 157 int get tabIndex { |
158 try { | 158 try { |
159 return Math.parseInt(_attr('tabIndex')); | 159 return Math.parseInt(_attr('tabIndex')); |
160 } on FormatException catch (e) { | 160 } on FormatException catch (e) { |
161 return 0; | 161 return 0; |
162 } | 162 } |
163 } | 163 } |
164 | 164 |
165 void set tabIndex(int value) { attributes['tabIndex'] = value.toString(); } | 165 void set tabIndex(int value) { attributes['tabIndex'] = value.toString(); } |
166 | 166 |
167 String get id() => _attr('id'); | 167 String get id => _attr('id'); |
168 | 168 |
169 void set id(String value) { attributes['id'] = value; } | 169 void set id(String value) { attributes['id'] = value; } |
170 | 170 |
171 String get title() => _attr('title'); | 171 String get title => _attr('title'); |
172 | 172 |
173 void set title(String value) { attributes['title'] = value; } | 173 void set title(String value) { attributes['title'] = value; } |
174 | 174 |
175 String get webkitdropzone() => _attr('webkitdropzone'); | 175 String get webkitdropzone => _attr('webkitdropzone'); |
176 | 176 |
177 void set webkitdropzone(String value) { | 177 void set webkitdropzone(String value) { |
178 attributes['webkitdropzone'] = value; | 178 attributes['webkitdropzone'] = value; |
179 } | 179 } |
180 | 180 |
181 String get lang() => _attr('lang'); | 181 String get lang => _attr('lang'); |
182 | 182 |
183 void set lang(String value) { attributes['lang'] = value; } | 183 void set lang(String value) { attributes['lang'] = value; } |
184 | 184 |
185 String get dir() => _attr('dir'); | 185 String get dir => _attr('dir'); |
186 | 186 |
187 void set dir(String value) { attributes['dir'] = value; } | 187 void set dir(String value) { attributes['dir'] = value; } |
188 | 188 |
189 String _attr(String name, [String def = '']) => | 189 String _attr(String name, [String def = '']) => |
190 attributes.containsKey(name) ? attributes[name] : def; | 190 attributes.containsKey(name) ? attributes[name] : def; |
191 } | 191 } |
OLD | NEW |