Chromium Code Reviews| Index: sdk/lib/chrome/dart2js/chrome_dart2js.dart |
| diff --git a/sdk/lib/chrome/dart2js/chrome_dart2js.dart b/sdk/lib/chrome/dart2js/chrome_dart2js.dart |
| index 9ab5df76c696946e0dabee807690710ee49f56c2..ea5cee2f1fd98bf289f239793e19796c4e174dc0 100644 |
| --- a/sdk/lib/chrome/dart2js/chrome_dart2js.dart |
| +++ b/sdk/lib/chrome/dart2js/chrome_dart2js.dart |
| @@ -1,5 +1,7 @@ |
| library chrome; |
| +import 'dart:html_common'; |
| +import 'dart:html'; |
| // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| @@ -8,39 +10,1031 @@ library chrome; |
| // Auto-generated dart:chrome library. |
| -// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| + |
| + |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| // for details. All rights reserved. Use of this source code is governed by a |
| // BSD-style license that can be found in the LICENSE file. |
| +/** |
| + * A set of utilities for use with the Chrome Extension APIs. |
| + * |
| + * Allows for easy access to required JS objects. |
| + */ |
| + |
| +/** |
| + * A dart object, that is convertible to JS. Used for creating objects in dart, |
| + * then passing them to JS. |
| + * |
| + * Objects that are passable to JS need to implement this interface. |
| + */ |
| +abstract class ChromeObject { |
| + /* |
| + * Default Constructor |
| + * |
| + * Called by child objects during their regular construction. |
| + */ |
| + ChromeObject() : |
| + _jsObject = JS('var', '{}'); |
| + |
| + /* |
| + * Internal proxy constructor |
| + * |
| + * Creates a new Dart object using this existing proxy. |
| + */ |
| + ChromeObject._proxy(this._jsObject); |
| + |
| + /* |
| + * JS Object Representation |
| + */ |
| + Object _jsObject; |
| + |
| + /* |
| + * Retrieves the field of the given name. |
| + * |
| + * Returns the base JS representation of the object. |
| + */ |
| + Object getMember(String type, String fieldName) { |
| + return JS(type, '#[#]', this._jsObject, fieldName); |
| + } |
| + |
| + /* |
| + * Sets the field of the given name to the given value. |
| + * |
| + * Attempts to convert the given value to JS before assignment. |
| + */ |
| + void setMember(String fieldName, Object value) { |
| + JS('void', '#[#] = #', this._jsObject, fieldName, convertArgument(value)); |
| + } |
| +} |
| + |
| +/** |
| + * Useful functions for converting arguments. |
| + */ |
| + |
| +/** |
| + * Converts the given map-type argument to js-friendly format, recursively. |
| + * Returns the new Map object. |
| + */ |
| +Object _convertMapArgument(Map argument) { |
| + Map m = new Map(); |
| + for (Object key in argument.keys) |
| + m[key] = convertArgument(argument[key]); |
| + return convertDartToNative_Dictionary(m); |
| +} |
| + |
| +/** |
| + * Converts the given list-type argument to js-friendly format, recursively. |
| + * Returns the new List object. |
| + */ |
| +List _convertListArgument(List argument) { |
| + List l = new List(); |
| + for (var i = 0; i < argument.length; i ++) |
| + l.add(convertArgument(argument[i])); |
| + return l; |
| +} |
| + |
| +/** |
| + * Converts the given argument Object to js-friendly format, recursively. |
| + * |
| + * Flattens out all Chrome objects into their corresponding ._toMap() |
| + * definitions, then converts them to JS objects. |
| + * |
| + * Returns the new argument. |
| + * |
| + * Cannot be used for functions. |
| + */ |
| +Object convertArgument(var argument) { |
| + if (argument == null) |
| + return argument; |
| + |
| + if (argument is num || argument is String || argument is bool) |
| + return argument; |
| + |
| + if (argument is ChromeObject) |
| + return argument._jsObject; |
| + |
| + if (argument is List) |
| + return _convertListArgument(argument); |
| + |
| + if (argument is Map) |
| + return _convertMapArgument(argument); |
| + |
| + if (argument is Function) |
| + throw new Exception("Cannot serialize Function argument ${argument}."); |
| + |
| + // TODO(sashab): Try and detect whether the argument is already serialized. |
| + return argument; |
| +} |
| + |
| +/** |
| + * Description of a declarative rule for handling events. |
| + */ |
| +class Rule extends ChromeObject { |
| + /* |
| + * Public (Dart) constructor |
| + */ |
| + Rule({String id, List conditions, List actions, int priority}) { |
| + this.id = id; |
| + this.conditions = conditions; |
| + this.actions = actions; |
| + this.priority = priority; |
| + } |
| + |
| + /* |
| + * Private (JS) constructor |
| + */ |
| + Rule._proxy(_jsObject) |
| + : super._proxy(_jsObject); |
| + |
| + /* |
| + * Public accessors |
| + */ |
| + String get id => |
| + getMember('String', 'id'); |
| + |
| + void set id(String id) => |
| + setMember('id', id); |
| + |
| + // TODO(sashab): Wrap these generic Lists somehow. |
| + List get conditions => |
| + getMember('List', 'conditions'); |
| + |
| + void set conditions(List conditions) => |
| + setMember('conditions', conditions); |
| + |
| + // TODO(sashab): Wrap these generic Lists somehow. |
| + List get actions => |
| + getMember('List', 'actions'); |
| + |
| + void set actions(List actions) => |
| + setMember('actions', actions); |
| -// This is an example of exposing chrome APIs in Dart and will be replaced with |
| -// the proper implementation in the future. |
| + int get priority => |
| + getMember('int', 'priority'); |
| -class AppModule { |
| - AppModule._(); |
| + void set priority(int priority) => |
| + setMember('priority', priority); |
| - WindowModule get window => new WindowModule._(); |
| } |
| -class WindowModule { |
| - WindowModule._(); |
| +/** |
| + * The Event class. |
| + * |
| + * Chrome Event classes extend this interface. |
| + * |
| + * e.g. |
| + * |
| + * // chrome.app.runtime.onLaunched |
| + * class $Event_ChromeAppRuntimeOnLaunched extends $Event { |
| + * // constructor, passing the arity of the callback |
| + * $Event_ChromeAppRuntimeOnLaunched(jsObject) : |
| + * super._(jsObject, 1); |
| + * |
| + * // methods, strengthening the Function parameter specificity |
| + * void addListener(void callback(LaunchData launchData)) |
| + * => super.addListener(callback); |
| + * void removeListener(void callback(LaunchData launchData)) |
| + * => super.removeListener(callback); |
| + * bool hasListener(void callback(LaunchData launchData)) |
| + * => super.hasListener(callback); |
| + * } |
| + * |
| + */ |
| +class $Event { |
| + /* |
| + * JS Object Representation |
| + */ |
| + Object _jsObject; |
| + |
| + /* |
| + * Number of arguments the callback takes. |
| + */ |
| + int _callbackArity; |
| + |
| + /* |
| + * Private constructor |
| + */ |
| + $Event._(this._jsObject, this._callbackArity); |
| + |
| + /* |
| + * Methods |
| + */ |
| + |
| + /** |
| + * Registers an event listener <em>callback</em> to an event. |
| + */ |
| + void addListener(Function callback) => |
| + JS('void', |
| + '#.addListener(#)', |
| + this._jsObject, |
| + convertDartClosureToJS(callback, this._callbackArity) |
| + ); |
| + |
| + /** |
| + * Deregisters an event listener <em>callback</em> from an event. |
| + */ |
| + void removeListener(Function callback) => |
| + JS('void', |
| + '#.removeListener(#)', |
| + this._jsObject, |
| + convertDartClosureToJS(callback, this._callbackArity) |
| + ); |
| + |
| + /** |
| + * Returns True if <em>callback</em> is registered to the event. |
| + */ |
| + bool hasListener(Function callback) => |
| + JS('bool', |
| + '#.hasListener(#)', |
| + this._jsObject, |
| + convertDartClosureToJS(callback, this._callbackArity) |
| + ); |
| + |
| + /** |
| + * Returns true if any event listeners are registered to the event. |
| + */ |
| + bool hasListeners() => |
| + JS('bool', |
| + '#.hasListeners()', |
| + this._jsObject |
| + ); |
| - void create(String url) { |
| - var chrome = JS('', 'chrome'); |
| + /** |
| + * Registers rules to handle events. |
| + * |
| + * @param eventName Name of the event this function affects. |
|
Emily Fortuna
2013/01/23 19:28:04
FYI: Use markdown syntax for documentation http://
sashab
2013/01/23 22:24:53
Done.
|
| + * @param rules Rules to be registered. These do not replace previously registered rules. |
| + * @param callback Called with registered rules. |
| + */ |
| + void addRules(String eventName, List<Rule> rules, |
| + [void callback(List<Rule> rules)]) { |
| + // proxy the callback |
| + void __proxy_callback(List rules) { |
| + if (?callback) { |
| + List<Rule> __proxy_rules = new List<Rule>(); |
| - if (chrome == null) { |
| - throw new UnsupportedError('Not supported by current browser'); |
| + for (Object o in rules) |
| + __proxy_rules.add(new Rule._proxy(o)); |
| + |
| + callback(__proxy_rules); |
| + } |
| } |
| - var app = JS('', '#.app', chrome); |
| - if (app == null) { |
| - throw new UnsupportedError('Not supported by current browser'); |
| + |
| + JS('void', |
| + '#.addRules(#, #, #)', |
| + this._jsObject, |
| + convertArgument(eventName), |
| + convertArgument(rules), |
| + convertDartClosureToJS(__proxy_callback, 1) |
| + ); |
| + } |
| + |
| + /** |
| + * Returns currently registered rules. |
| + * |
| + * @param eventName Name of the event this function affects. |
| + * @param ruleIdentifiers If an array is passed, only rules with identifiers contained in this array are returned. |
| + * @param callback Called with registered rules. |
| + */ |
| + void getRules(String eventName, [List<String> ruleIdentifiers, |
| + void callback(List<Rule> rules)]) { |
| + // proxy the callback |
| + void __proxy_callback(List rules) { |
| + if (?callback) { |
| + List<Rule> __proxy_rules = new List<Rule>(); |
| + |
| + for (Object o in rules) |
| + __proxy_rules.add(new Rule._proxy(o)); |
| + |
| + callback(__proxy_rules); |
| + } |
| } |
| - var window = JS('', '#.window', app); |
| - if (app == null) { |
| - throw new UnsupportedError('Not supported by current browser'); |
| + |
| + JS('void', |
| + '#.getRules(#, #, #)', |
| + this._jsObject, |
| + convertArgument(eventName), |
| + convertArgument(ruleIdentifiers), |
| + convertDartClosureToJS(__proxy_callback, 1) |
| + ); |
| + } |
| + |
| + /** |
| + * Unregisters currently registered rules. |
| + * |
| + * @param eventName Name of the event this function affects. |
| + * @param ruleIdentifiers If an array is passed, only rules with identifiers contained in this array are unregistered. |
| + * @param callback Called when rules were unregistered. |
| + */ |
| + void removeRules(String eventName, [List<String> ruleIdentifiers, |
| + void callback()]) => |
| + JS('void', |
| + '#.removeRules(#, #, #)', |
| + this._jsObject, |
| + convertArgument(eventName), |
| + convertArgument(ruleIdentifiers), |
| + convertDartClosureToJS(callback, 0) |
| + ); |
| +} |
| + |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +// TODO(sashab): Change all chrome-API object types to be JS-bound, so that the |
| +// proxy types are not needed. Instead, creation of an object also creates its |
| +// JS counterpart, and all objects are proxies from the start. |
| + |
| +// chrome.app |
| +class $API_ChromeApp { |
|
Emily Fortuna
2013/01/23 19:28:04
any reason why you're using the $ to start all of
sashab
2013/01/23 22:24:53
I need to distinguish, for example:
chrome.app.w
|
| + /* |
| + * JS Variable |
| + */ |
| + Object _jsObject; |
| + |
| + /* |
| + * Members |
| + */ |
| + $API_ChromeAppWindow window; |
| + $API_ChromeAppRuntime runtime; |
| + |
| + /* |
| + * Constructor |
| + */ |
| + $API_ChromeApp(this._jsObject) { |
| + var window_object = JS('', '#.window', this._jsObject); |
| + if (window_object == null) |
| + throw new UnsupportedError('Not supported by current browser.'); |
| + window = new $API_ChromeAppWindow(window_object); |
| + |
| + var runtime_object = JS('', '#.runtime', this._jsObject); |
| + if (runtime_object == null) |
| + throw new UnsupportedError('Not supported by current browser.'); |
| + runtime = new $API_ChromeAppRuntime(runtime_object); |
| + } |
| +} |
| + |
| +// chrome |
| +class $API_Chrome { |
| + /* |
| + * JS Variable |
| + */ |
| + Object _jsObject; |
| + |
| + /* |
| + * Members |
| + */ |
| + $API_ChromeApp app; |
| + |
| + /* |
| + * Constructor |
| + */ |
| + $API_Chrome() { |
| + this._jsObject = JS("Object", "chrome"); |
| + if (this._jsObject == null) |
| + throw new UnsupportedError('Not supported by current browser.'); |
| + |
| + var app_object = JS('', '#.app', this._jsObject); |
| + if (app_object == null) |
| + throw new UnsupportedError('Not supported by current browser.'); |
| + app = new $API_ChromeApp(app_object); |
| + } |
| +} |
| + |
| +// The final chrome objects |
| +final $API_Chrome chrome = new $API_Chrome(); |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +// from app_runtime.idl |
| + |
| +/** |
| + * Types |
| + */ |
| + |
| +// A WebIntents intent object. Deprecated. |
| +class Intent extends ChromeObject { |
| + /* |
| + * Public (Dart) constructor |
| + */ |
| + Intent({String action, String type, var data}) { |
| + this.action = action; |
| + this.type = type; |
| + this.data = data; |
| + } |
| + |
| + /* |
| + * Private (JS) constructor |
| + */ |
| + Intent._proxy(_jsObject) |
| + : super._proxy(_jsObject); |
| + |
| + /* |
| + * Public accessors |
| + */ |
| + |
| + // The WebIntent being invoked. |
| + String get action => |
| + getMember('String', 'action'); |
| + |
| + void set action(String action) => |
| + setMember('action', action); |
| + |
| + // The MIME type of the data. |
| + String get type => |
| + getMember('String', 'type'); |
| + |
| + void set type(String type) => |
| + setMember('type', type); |
| + |
| + // Data associated with the intent. |
| + // TODO(sashab): What is the best way to serialize/return generic JS objects? |
| + Object get data => |
| + getMember('Object', 'data'); |
| + |
| + void set data(Object data) => |
| + setMember('data', data); |
| + |
| + /* |
| + * TODO(sashab): What is a NullCallback() type? |
| + * Add postResult and postFailure once understanding what this type is, and |
| + * once there is a way to pass functions back from JS. |
| + */ |
| +} |
| + |
| +class LaunchItem extends ChromeObject { |
| + /* |
| + * Public constructor |
| + */ |
| + LaunchItem({FileEntry entry, String type}) { |
| + this.entry = entry; |
| + this.type = type; |
| + } |
| + |
| + /* |
| + * Private constructor |
| + */ |
| + LaunchItem._proxy(_jsObject) |
| + : super._proxy(_jsObject); |
| + |
| + /* |
| + * Public accessors |
| + */ |
| + |
| + // FileEntry for the file. |
| + FileEntry get entry => |
| + getMember('FileEntry', 'entry'); |
| + |
| + void set entry(FileEntry entry) => |
| + setMember('entry', entry); |
| + |
| + // The MIME type of the file. |
| + String get type => |
| + getMember('String', 'type'); |
| + |
| + void set type(String type) => |
| + setMember('type', type); |
| +} |
| + |
| +// Optional data for the launch. |
| +class LaunchData extends ChromeObject { |
| + /* |
| + * Public constructor |
| + */ |
| + LaunchData({Intent intent, String id, List<LaunchItem> items}) { |
| + this.intent = intent; |
| + this.id = id; |
| + this.items = items; |
| + } |
| + |
| + /* |
| + * Private constructor |
| + */ |
| + LaunchData._proxy(_jsObject) |
| + : super._proxy(_jsObject); |
| + |
| + /* |
| + * Public accessors |
| + */ |
| + Intent get intent => |
| + new Intent._proxy(getMember('', 'intent')); |
| + |
| + void set intent(Intent intent) => |
| + setMember('intent', intent); |
| + |
| + // The id of the file handler that the app is being invoked with. |
| + String get id => |
| + getMember('String', 'id'); |
| + |
| + void set id(String id) => |
| + setMember('id', id); |
| + |
| + List<LaunchItem> get items() { |
| + List<LaunchItem> items_final = new List<LaunchItem>(); |
| + for (var o in getMember('List', 'items')) { |
| + items_final.add(new LaunchItem._proxy(o)); |
| } |
| - JS('void', '#.create(#)', window, url); |
| + return items_final; |
| } |
| + |
| + void set items(List<LaunchItem> items) => |
| + setMember('items', items); |
| } |
| -final app = new AppModule._(); |
| +class IntentResponse extends ChromeObject { |
| + /* |
| + * Public constructor |
| + */ |
| + IntentResponse({int intentId, bool success, Object data}) { |
| + this.intentId = intentId; |
| + this.success = success; |
| + this.data = data; |
| + } |
| + |
| + /* |
| + * Private constructor |
| + */ |
| + IntentResponse._proxy(_jsObject) |
| + : super._proxy(_jsObject); |
| + |
| + /* |
| + * Public accessors |
| + */ |
| + |
| + // Identifies the intent. |
| + int get intentId => |
| + getMember('int', 'intentId'); |
| + |
| + void set intentId(int intentId) => |
| + setMember('intentId', intentId); |
| + |
| + // Was this intent successful? (i.e., postSuccess vs postFailure). |
| + bool get success => |
| + getMember('bool', 'success'); |
| + |
| + void set success(bool success) => |
| + setMember('success', success); |
| + |
| + // Data associated with the intent response. |
| + // TODO(sashab): What's the best way to serialize/return generic JS objects? |
| + Object get data => |
| + getMember('Object', 'data'); |
| + |
| + void set data(Object data) => |
| + setMember('data', data); |
| +} |
| + |
| +/** |
| + * Events |
| + */ |
| + |
| +// Fired at Chrome startup to apps that were running when Chrome last shut |
| +// down. |
| +class $Event_ChromeAppRuntimeOnRestarted extends $Event { |
| + /* |
| + * Override callback type definitions |
| + */ |
| + void addListener(void callback()) |
| + => super.addListener(callback); |
| + void removeListener(void callback()) |
| + => super.removeListener(callback); |
| + bool hasListener(void callback()) |
| + => super.hasListener(callback); |
| + |
| + /* |
| + * Constructor |
| + */ |
| + $Event_ChromeAppRuntimeOnRestarted(jsObject) : |
| + super._(jsObject, 0); |
| +} |
| + |
| +// Fired when an app is launched from the launcher or in response to a web |
| +// intent. |
| +class $Event_ChromeAppRuntimeOnLaunched extends $Event { |
| + /* |
| + * Override callback type definitions |
| + */ |
| + void addListener(void callback(LaunchData launchData)) |
| + => super.addListener(callback); |
| + void removeListener(void callback(LaunchData launchData)) |
| + => super.removeListener(callback); |
| + bool hasListener(void callback(LaunchData launchData)) |
| + => super.hasListener(callback); |
| + |
| + /* |
| + * Constructor |
| + */ |
| + $Event_ChromeAppRuntimeOnLaunched(jsObject) : |
| + super._(jsObject, 1); |
| +} |
| + |
| +/** |
| + * Functions |
| + */ |
| +class $API_ChromeAppRuntime { |
| + /* |
| + * API connection |
| + */ |
| + Object _jsObject; |
| + |
| + /* |
| + * Events |
| + */ |
| + $Event_ChromeAppRuntimeOnRestarted onRestarted; |
| + $Event_ChromeAppRuntimeOnLaunched onLaunched; |
| + |
| + /* |
| + * Functions |
| + */ |
| + void postIntentResponse(IntentResponse intentResponse) { |
| + JS('void', '#.postIntentResponse(#)', this._jsObject, convertArgument(intentResponse)); |
| + } |
| + |
| + /* |
| + * Constructor |
| + */ |
| + $API_ChromeAppRuntime(this._jsObject) { |
| + onRestarted = new $Event_ChromeAppRuntimeOnRestarted(JS('Object', '#.onRestarted', this._jsObject)); |
| + onLaunched = new $Event_ChromeAppRuntimeOnLaunched(JS('Object', '#.onLaunched', this._jsObject)); |
| + } |
| +} |
| + |
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +// from app.window.idl |
| + |
| +/** |
| + * Types |
| + */ |
| +class CreateWindowOptions extends ChromeObject { |
| + /* |
| + * Public constructor |
| + */ |
| + CreateWindowOptions({String id, int defaultWidth, int defaultHeight, |
| + int defaultLeft, int defaultTop, int width, int height, int left, int top, |
| + int minWidth, int minHeight, int maxWidth, int maxHeight, String type, |
| + String frame, Bounds bounds, bool hidden}) { |
| + this.id = id; |
| + this.defaultWidth = defaultWidth; |
| + this.defaultHeight = defaultHeight; |
| + this.defaultLeft = defaultLeft; |
| + this.defaultTop = defaultTop; |
| + this.width = width; |
| + this.height = height; |
| + this.left = left; |
| + this.top = top; |
| + this.minWidth = minWidth; |
| + this.minHeight = minHeight; |
| + this.maxWidth = maxWidth; |
| + this.maxHeight = maxHeight; |
| + this.type = type; |
| + this.frame = frame; |
| + this.bounds = bounds; |
| + this.hidden = hidden; |
| + } |
| + |
| + /* |
| + * Private constructor |
| + */ |
| + CreateWindowOptions._proxy(_jsObject) |
| + : super._proxy(_jsObject); |
| + |
| + /* |
| + * Public accessors |
| + */ |
| + // Id to identify the window. This will be used to remember the size |
| + // and position of the window and restore that geometry when a window |
| + // with the same id (and no explicit size or position) is later opened. |
| + String get id => |
| + getMember('String', 'id'); |
| + |
| + void set id(String id) => |
| + setMember('id', id); |
| + |
| + // Default width of the window. (Deprecated; regular bounds act like this |
| + // now.) |
| + int get defaultWidth => |
| + getMember('int', 'defaultWidth'); |
| + |
| + void set defaultWidth(int defaultWidth) => |
| + setMember('defaultWidth', defaultWidth); |
| + |
| + // Default height of the window. (Deprecated; regular bounds act like this |
| + // now.) |
| + int get defaultHeight => |
| + getMember('int', 'defaultHeight'); |
| + |
| + void set defaultHeight(int defaultHeight) => |
| + setMember('defaultHeight', defaultHeight); |
| + |
| + // Default X coordinate of the window. (Deprecated; regular bounds act like |
| + // this now.) |
| + int get defaultLeft => |
| + getMember('int', 'defaultLeft'); |
| + |
| + void set defaultLeft(int defaultLeft) => |
| + setMember('defaultLeft', defaultLeft); |
| + |
| + // Default Y coordinate of the window. (Deprecated; regular bounds act like |
| + // this now.) |
| + int get defaultTop => |
| + getMember('int', 'defaultTop'); |
| + |
| + void set defaultTop(int defaultTop) => |
| + setMember('defaultTop', defaultTop); |
| + |
| + // Width of the window. (Deprecated; use 'bounds'.) |
| + int get width => |
| + getMember('int', 'width'); |
| + |
| + void set width(int width) => |
| + setMember('width', width); |
| + |
| + // Height of the window. (Deprecated; use 'bounds'.) |
| + int get height => |
| + getMember('int', 'height'); |
| + |
| + void set height(int height) => |
| + setMember('height', height); |
| + |
| + // X coordinate of the window. (Deprecated; use 'bounds'.) |
| + int get left => |
| + getMember('int', 'left'); |
| + |
| + void set left(int left) => |
| + setMember('left', left); |
| + |
| + // Y coordinate of the window. (Deprecated; use 'bounds'.) |
| + int get top => |
| + getMember('int', 'top'); |
| + |
| + void set top(int top) => |
| + setMember('top', top); |
| + |
| + // Minimium width of the window. |
| + int get minWidth => |
| + getMember('int', 'minWidth'); |
| + |
| + void set minWidth(int minWidth) => |
| + setMember('minWidth', minWidth); |
| + |
| + // Minimum height of the window. |
| + int get minHeight => |
| + getMember('int', 'minHeight'); |
| + |
| + void set minHeight(int minHeight) => |
| + setMember('minHeight', minHeight); |
| + |
| + // Maximum width of the window. |
| + int get maxWidth => |
| + getMember('int', 'maxWidth'); |
| + |
| + void set maxWidth(int maxWidth) => |
| + setMember('maxWidth', maxWidth); |
| + |
| + // Maximum height of the window. |
| + int get maxHeight => |
| + getMember('int', 'maxHeight'); |
| + |
| + void set maxHeight(int maxHeight) => |
| + setMember('maxHeight', maxHeight); |
| + |
| + // Window type: 'shell' (the default) is the only currently supported value. |
| + String get type => |
| + getMember('String', 'type'); |
| + |
| + void set type(String type) => |
| + setMember('type', type); |
| + |
| + // Frame type: 'none' or 'chrome' (defaults to 'chrome'). |
| + String get frame => |
| + getMember('String', 'frame'); |
| + |
| + void set frame(String frame) => |
| + setMember('frame', frame); |
| + |
| + // Size of the content in the window (excluding the titlebar). If specified |
| + // in addition to any of the left/top/width/height parameters, this field |
| + // takes precedence. If a frameBounds is specified, the frameBounds take |
| + // precedence. |
| + Bounds get bounds => |
| + new Bounds._proxy(getMember('Bounds', 'bounds')); |
| + |
| + void set bounds(Bounds bounds) => |
| + setMember('bounds', bounds); |
| + |
| + // If true, the window will be created in a hidden state. Call show() on |
| + // the window to show it once it has been created. Defaults to false. |
| + bool get hidden => |
| + getMember('bool', 'hidden'); |
| + |
| + void set hidden(bool hidden) => |
| + setMember('hidden', hidden); |
| +} |
| + |
| +class Bounds extends ChromeObject { |
| + int _left; |
| + int _top; |
| + int _width; |
| + int _height; |
| + |
| + /* |
| + * Public constructor |
| + */ |
| + Bounds({int left, int top, int width, int height}) { |
| + this.left = left; |
| + this.top = top; |
| + this.width = width; |
| + this.height = height; |
| + } |
| + |
| + /* |
| + * Private constructor |
| + */ |
| + Bounds._proxy(_jsObject) |
| + : super._proxy(_jsObject); |
| + |
| + /* |
| + * Public accessors |
| + */ |
| + int get left => |
| + getMember('int', 'left'); |
| + |
| + void set left(int left) => |
| + setMember('left', left); |
| + |
| + int get top => |
| + getMember('int', 'top'); |
| + |
| + void set top(int top) => |
| + setMember('top', top); |
| + |
| + int get width => |
| + getMember('int', 'width'); |
| + |
| + void set width(int width) => |
| + setMember('width', width); |
| + |
| + int get height => |
| + getMember('int', 'height'); |
| + |
| + void set height(int height) => |
| + setMember('height', height); |
| +} |
| + |
| +class AppWindow extends ChromeObject { |
| + /* |
| + * Public constructor |
| + * TODO(sashab): Does it make sense to be able to create a new AppWindow this |
| + * way? |
| + */ |
| + //AppWindow(); |
| + |
| + /* |
| + * Private constructor |
| + */ |
| + AppWindow._proxy(jsObject) |
| + : super._proxy(jsObject); |
| + |
| + /* |
| + * Public accessors |
| + */ |
| + // The JavaScript 'window' object for the created child. |
| + // TODO(sashab, sra): Detect whether this is the current window, or an |
| + // external one, and return an appropriately-typed object |
| + WindowBase get contentWindow { |
| + return JS("Window", "#.contentWindow", this._jsObject); |
| + } |
| + |
| + /* |
| + * Functions |
| + */ |
| + |
| + // Focus the window. |
| + void focus() => |
| + JS("void", "#.focus()", this._jsObject); |
| + |
| + // Minimize the window. |
| + void minimize() => |
| + JS("void", "#.minimize()", this._jsObject); |
| + |
| + // Is the window minimized? |
| + bool isMinimized() => |
| + JS("bool", "#.isMinimized()", this._jsObject); |
| + |
| + // Maximize the window. |
| + void maximize() => |
| + JS("void", "#.maximize()", this._jsObject); |
| + |
| + // Is the window maximized? |
| + bool isMaximized() => |
| + JS("bool", "c#.isMaximized()", this._jsObject); |
| + |
| + // Restore the window. |
| + void restore() => |
| + JS("void", "#.restore()", this._jsObject); |
| + |
| + // Move the window to the position (|left|, |top|). |
| + void moveTo(int left, int top) => |
| + JS("void", "#.moveTo(#, #)", this._jsObject, left, top); |
| + |
| + // Resize the window to |width|x|height| pixels in size. |
| + void resizeTo(int width, int height) => |
| + JS("void", "#.resizeTo(#, #)", this._jsObject, width, height); |
| + |
| + // Draw attention to the window. |
| + void drawAttention() => |
| + JS("void", "#.drawAttention()", this._jsObject); |
| + |
| + // Clear attention to the window. |
| + void clearAttention() => |
| + JS("void", "#.clearAttention()", this._jsObject); |
| + |
| + // Close the window. |
| + void close() => |
| + JS("void", "#.close()", this._jsObject); |
| + |
| + // Show the window. Does nothing if the window is already visible. |
| + void show() => |
| + JS("void", "#.show()", this._jsObject); |
| + |
| + // Hide the window. Does nothing if the window is already hidden. |
| + void hide() => |
| + JS("void", "#.hide()", this._jsObject); |
| + |
| + // Set the window's bounds. |
| + void setBounds(Bounds bounds) => |
| + JS("void", "#.setBounds(#)", this._jsObject, convertArgument(bounds)); |
| + |
| +} |
| + |
| +/** |
| + * Functions |
| + */ |
| +class $API_ChromeAppWindow { |
| + /** |
| + * JS object |
| + */ |
| + Object _jsObject; |
| + |
| + /** |
| + * Constructor |
| + */ |
| + $API_ChromeAppWindow(this._jsObject); |
| + |
| + /** |
| + * Functions |
| + */ |
| + |
| + // Returns an <a href="#type-AppWindow">AppWindow</a> object for the |
| + // current script context (ie JavaScript 'window' object). This can also be |
| + // called on a handle to a script context for another page, for example: |
| + // otherWindow.chrome.app.window.current(). |
| + AppWindow current() => |
| + new AppWindow._proxy(JS("Object", "#.current()", this._jsObject)); |
| + |
| + // The size and position of a window can be specified in a number of |
| + // different ways. The most simple option is not specifying anything at |
| + // all, in which case a default size and platform dependent position will |
| + // be used. |
| + // |
| + // Another option is to use the top/left and width/height properties, |
| + // which will always put the window at the specified coordinates with the |
| + // specified size. |
| + // |
| + // Yet another option is to give the window a (unique) id. This id is then |
| + // used to remember the size and position of the window whenever it is |
| + // moved or resized. This size and position is then used instead of the |
| + // specified bounds on subsequent opening of a window with the same id. If |
| + // you need to open a window with an id at a location other than the |
| + // remembered default, you can create it hidden, move it to the desired |
| + // location, then show it. |
| + // |
| + // You can also combine these various options, explicitly specifying for |
| + // example the size while having the position be remembered or other |
| + // combinations like that. Size and position are dealt with seperately, |
| + // but individual coordinates are not. So if you specify a top (or left) |
| + // coordinate, you should also specify a left (or top) coordinate, and |
| + // similar for size. |
| + // |
| + // If you specify both a regular and a default value for the same option |
| + // the regular value is the only one that takes effect. |
| + void create(String url, [CreateWindowOptions options, |
| + void callback(AppWindow created_window)]) { |
| + void __proxy_callback(Object created_window) { |
| + if (?callback) |
| + callback(new AppWindow._proxy(created_window)); |
| + } |
| + |
| + JS("void", "#.create(#, #, #)", |
| + this._jsObject, |
| + convertArgument(url), |
| + convertArgument(options), |
| + convertDartClosureToJS(__proxy_callback, 1) |
| + ); |
| + } |
| +} |