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 // WARNING: Do not edit - generated code. | 5 // WARNING: Do not edit - generated code. |
6 | 6 |
7 part of $LIBRARYNAME; | 7 part of $LIBRARYNAME; |
8 | 8 |
9 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS
{ | 9 $(ANNOTATIONS)$(NATIVESPEC)$(CLASS_MODIFIERS)class $CLASSNAME$EXTENDS$IMPLEMENTS
{ |
10 $!MEMBERS | 10 $!MEMBERS |
11 | 11 |
12 $if DART2JS | 12 $if DART2JS |
13 @DomName('Document.body') | 13 @DomName('Document.body') |
14 BodyElement body; | 14 BodyElement body; |
15 $else | 15 $else |
16 @DomName('Document.body') | 16 @DomName('Document.body') |
17 BodyElement get body => _body; | 17 BodyElement get body => _body; |
18 | 18 |
19 @DomName('Document.body') | 19 @DomName('Document.body') |
20 set body(BodyElement value) { | 20 void set body(BodyElement value) { |
21 _body = value; | 21 _body = value; |
22 } | 22 } |
23 $endif | 23 $endif |
24 | 24 |
25 @DomName('Document.caretRangeFromPoint') | 25 @DomName('Document.caretRangeFromPoint') |
26 Range caretRangeFromPoint(int x, int y) { | 26 Range caretRangeFromPoint(int x, int y) { |
27 return _caretRangeFromPoint(x, y); | 27 return _caretRangeFromPoint(x, y); |
28 } | 28 } |
29 | 29 |
30 @DomName('Document.elementFromPoint') | 30 @DomName('Document.elementFromPoint') |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 String get lastModified => _lastModified; | 83 String get lastModified => _lastModified; |
84 | 84 |
85 @DomName('Document.preferredStylesheetSet') | 85 @DomName('Document.preferredStylesheetSet') |
86 String get preferredStylesheetSet => _preferredStylesheetSet; | 86 String get preferredStylesheetSet => _preferredStylesheetSet; |
87 | 87 |
88 @DomName('Document.referrer') | 88 @DomName('Document.referrer') |
89 String get referrer => _referrer; | 89 String get referrer => _referrer; |
90 | 90 |
91 @DomName('Document.selectedStylesheetSet') | 91 @DomName('Document.selectedStylesheetSet') |
92 String get selectedStylesheetSet => _selectedStylesheetSet; | 92 String get selectedStylesheetSet => _selectedStylesheetSet; |
93 set selectedStylesheetSet(String value) { | 93 void set selectedStylesheetSet(String value) { |
94 _selectedStylesheetSet = value; | 94 _selectedStylesheetSet = value; |
95 } | 95 } |
96 | 96 |
97 @DomName('Document.styleSheets') | 97 @DomName('Document.styleSheets') |
98 List<StyleSheet> get styleSheets => _styleSheets; | 98 List<StyleSheet> get styleSheets => _styleSheets; |
99 | 99 |
100 @DomName('Document.title') | 100 @DomName('Document.title') |
101 String get title => _title; | 101 String get title => _title; |
102 | 102 |
103 @DomName('Document.title') | 103 @DomName('Document.title') |
104 set title(String value) { | 104 void set title(String value) { |
105 _title = value; | 105 _title = value; |
106 } | 106 } |
107 | 107 |
108 /** | 108 /** |
109 * Returns page to standard layout. | 109 * Returns page to standard layout. |
110 * | 110 * |
111 * Has no effect if the page is not in fullscreen mode. | 111 * Has no effect if the page is not in fullscreen mode. |
112 * | 112 * |
113 * ## Other resources | 113 * ## Other resources |
114 * | 114 * |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 @SupportedBrowser(SupportedBrowser.FIREFOX) | 180 @SupportedBrowser(SupportedBrowser.FIREFOX) |
181 @SupportedBrowser(SupportedBrowser.IE, '10') | 181 @SupportedBrowser(SupportedBrowser.IE, '10') |
182 @Experimental() | 182 @Experimental() |
183 $if DART2JS | 183 $if DART2JS |
184 String get visibilityState => JS('String', | 184 String get visibilityState => JS('String', |
185 '(#.visibilityState || #.mozVisibilityState || #.msVisibilityState ||' | 185 '(#.visibilityState || #.mozVisibilityState || #.msVisibilityState ||' |
186 '#.webkitVisibilityState)', this, this, this, this); | 186 '#.webkitVisibilityState)', this, this, this, this); |
187 $else | 187 $else |
188 String get visibilityState => _webkitVisibilityState; | 188 String get visibilityState => _webkitVisibilityState; |
189 $endif | 189 $endif |
190 $if DARTIUM | |
191 | |
192 /** | |
193 * Internal routine to find the DOM JS class name being extended for custom | |
194 * elements. | |
195 */ | |
196 String _getJSClassName(ClassMirror classMirror) { | |
197 var jsClassName = null; | |
198 var isElement = false; | |
199 | |
200 while (classMirror.superclass != null) { | |
201 var fullName = classMirror.superclass.qualifiedName; | |
202 isElement = isElement || (fullName == #dart.dom.html.Element); | |
203 | |
204 var domLibrary = MirrorSystem.getName(fullName).startsWith('dart.dom.'); | |
205 if (jsClassName == null && domLibrary) { | |
206 // Lookup JS class name (if not found). | |
207 var metadatas = classMirror.metadata; | |
208 for (var metadata in metadatas) { | |
209 var metaDataMirror = metadata.reflectee; | |
210 var metaType = reflectClass(metaDataMirror.runtimeType); | |
211 if (MirrorSystem.getName(metaType.simpleName) == 'DomName' && | |
212 metaDataMirror.name.startsWith('HTML')) { | |
213 jsClassName = metadata.reflectee.name; | |
214 } | |
215 } | |
216 } | |
217 | |
218 classMirror = classMirror.superclass; | |
219 } | |
220 | |
221 // If we're an element then everything is okay. | |
222 return isElement ? jsClassName : null; | |
223 } | |
224 $endif | |
225 | 190 |
226 @Experimental() | 191 @Experimental() |
227 /** | 192 /** |
228 * Register a custom subclass of Element to be instantiatable by the DOM. | 193 * Register a custom subclass of Element to be instantiatable by the DOM. |
229 * | 194 * |
230 * This is necessary to allow the construction of any custom elements. | 195 * This is necessary to allow the construction of any custom elements. |
231 * | 196 * |
232 * The class being registered must either subclass HtmlElement or SvgElement. | 197 * The class being registered must either subclass HtmlElement or SvgElement. |
233 * If they subclass these directly then they can be used as: | 198 * If they subclass these directly then they can be used as: |
234 * | 199 * |
(...skipping 29 matching lines...) Expand all Loading... |
264 * This custom element can also be instantiated via HTML using the syntax | 229 * This custom element can also be instantiated via HTML using the syntax |
265 * `<input is="x-bar"></input>` | 230 * `<input is="x-bar"></input>` |
266 * | 231 * |
267 */ | 232 */ |
268 void registerElement(String tag, Type customElementClass, | 233 void registerElement(String tag, Type customElementClass, |
269 {String extendsTag}) { | 234 {String extendsTag}) { |
270 $if DART2JS | 235 $if DART2JS |
271 _registerCustomElement(JS('', 'window'), this, tag, customElementClass, | 236 _registerCustomElement(JS('', 'window'), this, tag, customElementClass, |
272 extendsTag); | 237 extendsTag); |
273 $else | 238 $else |
274 // TODO(terry): Need to handle the extendsTag. | 239 _Utils.register(this, tag, customElementClass, extendsTag); |
275 | |
276 // Figure out which DOM class is being extended from the user's Dart class. | |
277 var classMirror = reflectClass(customElementClass); | |
278 var jsClassName = _getJSClassName(classMirror); | |
279 if (jsClassName == null) { | |
280 // Only components derived from HTML* can be extended. | |
281 throw new DomException.jsInterop("HierarchyRequestError: Only HTML element
s can be customized."); | |
282 } | |
283 | |
284 // Start the hookup the JS way create an <x-foo> element that extends the | |
285 // <x-base> custom element. Inherit its prototype and signal what tag is | |
286 // inherited: | |
287 // | |
288 // var myProto = Object.create(HTMLElement.prototype); | |
289 // var myElement = document.registerElement('x-foo', {prototype: myProto
}); | |
290 var baseElement = js.context[jsClassName]; | |
291 if (baseElement == null) { | |
292 // Couldn't find the HTML element so use a generic one. | |
293 baseElement = js.context['HTMLElement']; | |
294 } | |
295 var elemProto = js.context['Object'].callMethod("create", [baseElement['prot
otype']]); | |
296 | |
297 // TODO(terry): Hack to stop recursion re-creating custom element when the | |
298 // created() constructor of the custom element does e.g., | |
299 // | |
300 // MyElement.created() : super.created() { | |
301 // this.innerHtml = "<b>I'm an x-foo-with-markup!</b>"; | |
302 // } | |
303 // | |
304 // sanitizing causes custom element to created recursively | |
305 // until stack overflow. | |
306 // | |
307 // See https://github.com/dart-lang/sdk/issues/23666 | |
308 int creating = 0; | |
309 elemProto['createdCallback'] = new js.JsFunction.withThis(($this) { | |
310 if (_getJSClassName(reflectClass(customElementClass).superclass) != null &
& creating < 2) { | |
311 creating++; | |
312 | |
313 var dartClass = _blink.Blink_Utils.constructElement(customElementClass,
$this); | |
314 | |
315 // Need to remember the Dart class that was created for this custom so | |
316 // return it and setup the blink_jsObject to the $this that we'll be wor
king | |
317 // with as we talk to blink. | |
318 $this['dart_class'] = dartClass; | |
319 | |
320 creating--; | |
321 } | |
322 }); | |
323 elemProto['attributeChangedCallback'] = new js.JsFunction.withThis(($this, a
ttrName, oldVal, newVal) { | |
324 if ($this["dart_class"] != null && $this['dart_class'].attributeChanged !=
null) { | |
325 $this['dart_class'].attributeChanged(attrName, oldVal, newVal); | |
326 } | |
327 }); | |
328 elemProto['attachedCallback'] = new js.JsFunction.withThis(($this) { | |
329 if ($this["dart_class"] != null && $this['dart_class'].attached != null) { | |
330 $this['dart_class'].attached(); | |
331 } | |
332 }); | |
333 elemProto['detachedCallback'] = new js.JsFunction.withThis(($this) { | |
334 if ($this["dart_class"] != null && $this['dart_class'].detached != null) { | |
335 $this['dart_class'].detached(); | |
336 } | |
337 }); | |
338 // document.registerElement('x-foo', {prototype: elemProto, extends: extends
Tag}); | |
339 var jsMap = new js.JsObject.jsify({'prototype': elemProto, 'extends': extend
sTag}); | |
340 js.context['document'].callMethod('registerElement', [tag, jsMap]); | |
341 $endif | 240 $endif |
342 } | 241 } |
343 | 242 |
344 /** *Deprecated*: use [registerElement] instead. */ | 243 /** *Deprecated*: use [registerElement] instead. */ |
345 @deprecated | 244 @deprecated |
346 @Experimental() | 245 @Experimental() |
347 void register(String tag, Type customElementClass, {String extendsTag}) { | 246 void register(String tag, Type customElementClass, {String extendsTag}) { |
348 return registerElement(tag, customElementClass, extendsTag: extendsTag); | 247 return registerElement(tag, customElementClass, extendsTag: extendsTag); |
349 } | 248 } |
350 | 249 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 /// parameter must be provided. | 297 /// parameter must be provided. |
399 @Experimental() | 298 @Experimental() |
400 ElementUpgrader createElementUpgrader(Type type, {String extendsTag}) { | 299 ElementUpgrader createElementUpgrader(Type type, {String extendsTag}) { |
401 $if DART2JS | 300 $if DART2JS |
402 return new _JSElementUpgrader(this, type, extendsTag); | 301 return new _JSElementUpgrader(this, type, extendsTag); |
403 $else | 302 $else |
404 return new _VMElementUpgrader(this, type, extendsTag); | 303 return new _VMElementUpgrader(this, type, extendsTag); |
405 $endif | 304 $endif |
406 } | 305 } |
407 } | 306 } |
OLD | NEW |