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

Unified Diff: tools/dom/templates/html/dartium/html_dartium.darttemplate

Issue 1173403004: Changed to use JSInterop (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Re-gen'd somehow diffs stopped showing up in CL Created 5 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: tools/dom/templates/html/dartium/html_dartium.darttemplate
diff --git a/tools/dom/templates/html/dartium/html_dartium.darttemplate b/tools/dom/templates/html/dartium/html_dartium.darttemplate
index 1d558264eec22d5235140d488454a4554a5fd59c..c6a200f94757e4538f55445d043f9a6f5b71ce8f 100644
--- a/tools/dom/templates/html/dartium/html_dartium.darttemplate
+++ b/tools/dom/templates/html/dartium/html_dartium.darttemplate
@@ -37,6 +37,7 @@ import 'dart:_internal' hide Symbol, deprecated;
import 'dart:html_common';
import 'dart:indexed_db';
import 'dart:indexed_db' show indexed_dbBlinkMap;
+import 'dart:indexed_db' show indexed_dbBlinkFunctionMap;
import 'dart:isolate';
import 'dart:js' as js;
import "dart:convert";
@@ -48,14 +49,17 @@ import 'dart:nativewrappers';
import 'dart:typed_data';
import 'dart:web_gl' as gl;
import 'dart:web_gl' show web_glBlinkMap;
+import 'dart:web_gl' show web_glBlinkFunctionMap;
import 'dart:web_sql';
// Not actually used, but imported since dart:html can generate these objects.
import 'dart:svg' as svg;
import 'dart:svg' show svgBlinkMap;
+import 'dart:svg' show svgBlinkFunctionMap;
import 'dart:svg' show Matrix;
import 'dart:svg' show SvgSvgElement;
import 'dart:web_audio' as web_audio;
import 'dart:web_audio' show web_audioBlinkMap;
+import 'dart:web_audio' show web_audioBlinkFunctionMap;
import 'dart:_blink' as _blink;
export 'dart:math' show Rectangle, Point;
@@ -111,7 +115,13 @@ Window get window {
if (_window != null) {
return _window;
}
+$if DARTIUM
+$if JSINTEROP
+ _window = wrap_jso(js.context['window']);
+$else
_window = _Utils.window();
+$endif
+$endif
return _window;
}
@@ -239,3 +249,187 @@ Type _getSvgType(String key) {
}
return null;
}
+
+
+$if JSINTEROP
+// FIXME: Can we make this private?
+final htmlBlinkFunctionMap = {
+$!TYPE_FUNCTION_MAP
+};
+
+// TODO(terry): We may want to move this elsewhere if html becomes
+// a package to avoid dartium depending on pkg:html.
+getHtmlCreateFunction(String key) {
+ var result;
+
+ // TODO(vsm): Add Cross Frame and JS types here as well.
+
+ // Check the html library.
+ result = _getHtmlFunction(key);
+ if (result != null) {
+ return result;
+ }
+
+ // Check the web gl library.
+ result = _getWebGlFunction(key);
+ if (result != null) {
+ return result;
+ }
+
+ // Check the indexed db library.
+ result = _getIndexDbFunction(key);
+ if (result != null) {
+ return result;
+ }
+
+ // Check the web audio library.
+ result = _getWebAudioFunction(key);
+ if (result != null) {
+ return result;
+ }
+
+ // Check the web sql library.
+ result = _getWebSqlFunction(key);
+ if (result != null) {
+ return result;
+ }
+
+ // Check the svg library.
+ result = _getSvgFunction(key);
+ if (result != null) {
+ return result;
+ }
+
+ return null;
+}
+
+Type _getHtmlFunction(String key) {
+ if (htmlBlinkFunctionMap.containsKey(key)) {
+ return htmlBlinkFunctionMap[key]();
+ }
+ return null;
+}
+
+Type _getWebGlFunction(String key) {
+ if (web_glBlinkFunctionMap.containsKey(key)) {
+ return web_glBlinkFunctionMap[key]();
+ }
+ return null;
+}
+
+Type _getIndexDbFunction(String key) {
+ if (indexed_dbBlinkFunctionMap.containsKey(key)) {
+ return indexed_dbBlinkFunctionMap[key]();
+ }
+ return null;
+}
+
+Type _getWebAudioFunction(String key) {
+ if (web_audioBlinkFunctionMap.containsKey(key)) {
+ return web_audioBlinkFunctionMap[key]();
+ }
+ return null;
+}
+
+Type _getWebSqlFunction(String key) {
+ if (web_sqlBlinkFunctionMap.containsKey(key)) {
+ return web_sqlBlinkFunctionMap[key]();
+ }
+ return null;
+}
+
+Type _getSvgFunction(String key) {
+ if (svgBlinkFunctionMap.containsKey(key)) {
+ return svgBlinkFunctionMap[key]();
+ }
+ return null;
+}
+
+
+/******************************************************************************
+ ********** **********
+ ********** JS Interop Support **********
+ ********** **********
+ ******************************************************************************/
+
+Rectangle make_dart_rectangle(r) => new Rectangle(r['top'], r['left'], r['width'], r['height']);
+
+
+/** Expando for JsObject, used by every Dart class associated with a Javascript
+ * class (e.g., DOM, WebAudio, etc.).
+ */
+
+/**
+ * Return the JsObject associated with a Dart class [dartClass_instance].
+ */
+js.JsObject unwrap_jso(dartClass_instance) {
+ try {
+ if (dartClass_instance != null)
+ return dartClass_instance is! Function ? dartClass_instance.blink_jsObject : dartClass_instance;
+ else
+ return null;
+// return dartClass_instance.dartium_expando[dartClass_instance.expandoJsObject];
+ } catch(NoSuchMethodException) {
+ // No blink_jsObject then return the dartClass_instance is probably an
+ // array that was already converted to a Dart class e.g., Uint8ClampedList.
+ return dartClass_instance;
+ }
+}
+
+/**
+ * Create Dart class that maps to the JS Type, add the JsObject as an expando
+ * on the Dart class and return the created Dart class.
+ */
+wrap_jso(jsObject) {
+try {
+// debug_or_assert("jsObject != null", jsObject != null);
+ if (jsObject is! js.JsObject) {
+ // JS Interop converted the object to a Dart class e.g., Uint8ClampedList.
+ return jsObject;
+ }
+ var constructor = jsObject['constructor'];
+ debug_or_assert("constructor != null", constructor != null);
+ var jsTypeName = constructor['name'];
+ debug_or_assert("constructor != null && jsTypeName.length > 0", constructor != null && jsTypeName.length > 0);
+ var func = getHtmlCreateFunction(jsTypeName);
+ debug_or_assert("func != null name = ${jsTypeName}", func != null);
+ var dartClass_instance = func();
+ dartClass_instance.blink_jsObject = jsObject;
+// dartClass_instance.dartium_expando[dartClass_instance.expandoJsObject] = jsObject;
+ return dartClass_instance;
+} catch(e, stacktrace){
+ if (e is DebugAssertException)
+ window.console.log("${e.message}\n ${stacktrace}");
+ else
+ window.console.log("${stacktrace}");
+}
+}
+
+class DebugAssertException implements Exception {
+ String message;
+ DebugAssertException(this.message);
+}
+
+debug_or_assert(message, expression) {
+ if (!expression) {
+ throw new DebugAssertException("$message");
+ }
+}
+
+// Wrap JsObject node list to return a List<node>.
+List<Node> wrap_jso_list(jso_nodes) {
+ List<Node> nodes = new List<Node>();
+ var collectionLen = jso_nodes['length'];
+ for (var i = 0; i < collectionLen; i++) {
+ nodes.add(wrap_jso(jso_nodes.callMethod('item', [i])));
+ }
+ var frozen_nodes = new _FrozenElementList._wrap(nodes);
+ frozen_nodes.dartClass_instance = jso_nodes;
+ return frozen_nodes;
+}
+$else
+unwrap_jso(dartClass_instance) => dartClass_instance;
+wrap_jso(jsObject) => jsObject;
+wrap_jso_list(jso_nodes) => jso_nodes;
+make_dart_rectangle(r) => r;
+$endif
« no previous file with comments | « tools/dom/src/native_DOMImplementation.dart ('k') | tools/dom/templates/html/dartium/indexed_db_dartium.darttemplate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698