| OLD | NEW |
| 1 library chrome; | 1 library chrome; |
| 2 | 2 |
| 3 import 'dart:html_common'; |
| 4 import 'dart:html'; |
| 3 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 5 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 4 // for details. All rights reserved. Use of this source code is governed by a | 6 // for details. All rights reserved. Use of this source code is governed by a |
| 5 // BSD-style license that can be found in the LICENSE file. | 7 // BSD-style license that can be found in the LICENSE file. |
| 6 | 8 |
| 7 // DO NOT EDIT | 9 // DO NOT EDIT |
| 8 // Auto-generated dart:chrome library. | 10 // Auto-generated dart:chrome library. |
| 9 | 11 |
| 10 | 12 |
| 13 |
| 14 |
| 15 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 16 // for details. All rights reserved. Use of this source code is governed by a |
| 17 // BSD-style license that can be found in the LICENSE file. |
| 18 |
| 19 /** |
| 20 * A set of utilities for use with the Chrome Extension APIs. |
| 21 * |
| 22 * Allows for easy access to required JS objects. |
| 23 */ |
| 24 |
| 25 /** |
| 26 * A dart object, that is convertible to JS. Used for creating objects in dart, |
| 27 * then passing them to JS. |
| 28 * |
| 29 * Objects that are passable to JS need to implement this interface. |
| 30 */ |
| 31 abstract class ChromeObject { |
| 32 /* |
| 33 * Default Constructor |
| 34 * |
| 35 * Called by child objects during their regular construction. |
| 36 */ |
| 37 ChromeObject() : _jsObject = JS('var', '{}'); |
| 38 |
| 39 /* |
| 40 * Internal proxy constructor |
| 41 * |
| 42 * Creates a new Dart object using this existing proxy. |
| 43 */ |
| 44 ChromeObject._proxy(this._jsObject); |
| 45 |
| 46 /* |
| 47 * JS Object Representation |
| 48 */ |
| 49 Object _jsObject; |
| 50 } |
| 51 |
| 52 /** |
| 53 * Useful functions for converting arguments. |
| 54 */ |
| 55 |
| 56 /** |
| 57 * Converts the given map-type argument to js-friendly format, recursively. |
| 58 * Returns the new Map object. |
| 59 */ |
| 60 Object _convertMapArgument(Map argument) { |
| 61 Map m = new Map(); |
| 62 for (Object key in argument.keys) |
| 63 m[key] = convertArgument(argument[key]); |
| 64 return convertDartToNative_Dictionary(m); |
| 65 } |
| 66 |
| 67 /** |
| 68 * Converts the given list-type argument to js-friendly format, recursively. |
| 69 * Returns the new List object. |
| 70 */ |
| 71 List _convertListArgument(List argument) { |
| 72 List l = new List(); |
| 73 for (var i = 0; i < argument.length; i ++) |
| 74 l.add(convertArgument(argument[i])); |
| 75 return l; |
| 76 } |
| 77 |
| 78 /** |
| 79 * Converts the given argument Object to js-friendly format, recursively. |
| 80 * |
| 81 * Flattens out all Chrome objects into their corresponding ._toMap() |
| 82 * definitions, then converts them to JS objects. |
| 83 * |
| 84 * Returns the new argument. |
| 85 * |
| 86 * Cannot be used for functions. |
| 87 */ |
| 88 Object convertArgument(var argument) { |
| 89 if (argument == null) |
| 90 return argument; |
| 91 |
| 92 if (argument is num || argument is String || argument is bool) |
| 93 return argument; |
| 94 |
| 95 if (argument is ChromeObject) |
| 96 return argument._jsObject; |
| 97 |
| 98 if (argument is List) |
| 99 return _convertListArgument(argument); |
| 100 |
| 101 if (argument is Map) |
| 102 return _convertMapArgument(argument); |
| 103 |
| 104 if (argument is Function) |
| 105 throw new Exception("Cannot serialize Function argument ${argument}."); |
| 106 |
| 107 // TODO(sashab): Try and detect whether the argument is already serialized. |
| 108 return argument; |
| 109 } |
| 110 |
| 111 /// Description of a declarative rule for handling events. |
| 112 class Rule extends ChromeObject { |
| 113 /* |
| 114 * Public (Dart) constructor |
| 115 */ |
| 116 Rule({String id, List conditions, List actions, int priority}) { |
| 117 this.id = id; |
| 118 this.conditions = conditions; |
| 119 this.actions = actions; |
| 120 this.priority = priority; |
| 121 } |
| 122 |
| 123 /* |
| 124 * Private (JS) constructor |
| 125 */ |
| 126 Rule._proxy(_jsObject) : super._proxy(_jsObject); |
| 127 |
| 128 /* |
| 129 * Public accessors |
| 130 */ |
| 131 String get id => JS('String', '#.id', this._jsObject); |
| 132 |
| 133 void set id(String id) { |
| 134 JS('void', '#.id = #', this._jsObject, id); |
| 135 } |
| 136 |
| 137 // TODO(sashab): Wrap these generic Lists somehow. |
| 138 List get conditions => JS('List', '#.conditions', this._jsObject); |
| 139 |
| 140 void set conditions(List conditions) { |
| 141 JS('void', '#.conditions = #', this._jsObject, convertArgument(conditions)); |
| 142 } |
| 143 |
| 144 // TODO(sashab): Wrap these generic Lists somehow. |
| 145 List get actions => JS('List', '#.actions', this._jsObject); |
| 146 |
| 147 void set actions(List actions) { |
| 148 JS('void', '#.actions = #', this._jsObject, convertArgument(actions)); |
| 149 } |
| 150 |
| 151 int get priority => JS('int', '#.priority', this._jsObject); |
| 152 |
| 153 void set priority(int priority) { |
| 154 JS('void', '#.priority = #', this._jsObject, priority); |
| 155 } |
| 156 |
| 157 } |
| 158 |
| 159 /** |
| 160 * The Event class. |
| 161 * |
| 162 * Chrome Event classes extend this interface. |
| 163 * |
| 164 * e.g. |
| 165 * |
| 166 * // chrome.app.runtime.onLaunched |
| 167 * class Event_ChromeAppRuntimeOnLaunched extends Event { |
| 168 * // constructor, passing the arity of the callback |
| 169 * Event_ChromeAppRuntimeOnLaunched(jsObject) : |
| 170 * super._(jsObject, 1); |
| 171 * |
| 172 * // methods, strengthening the Function parameter specificity |
| 173 * void addListener(void callback(LaunchData launchData)) |
| 174 * => super.addListener(callback); |
| 175 * void removeListener(void callback(LaunchData launchData)) |
| 176 * => super.removeListener(callback); |
| 177 * bool hasListener(void callback(LaunchData launchData)) |
| 178 * => super.hasListener(callback); |
| 179 * } |
| 180 * |
| 181 */ |
| 182 class Event { |
| 183 /* |
| 184 * JS Object Representation |
| 185 */ |
| 186 Object _jsObject; |
| 187 |
| 188 /* |
| 189 * Number of arguments the callback takes. |
| 190 */ |
| 191 int _callbackArity; |
| 192 |
| 193 /* |
| 194 * Private constructor |
| 195 */ |
| 196 Event._(this._jsObject, this._callbackArity); |
| 197 |
| 198 /* |
| 199 * Methods |
| 200 */ |
| 201 |
| 202 /// Registers an event listener <em>callback</em> to an event. |
| 203 void addListener(Function callback) => |
| 204 JS('void', |
| 205 '#.addListener(#)', |
| 206 this._jsObject, |
| 207 convertDartClosureToJS(callback, this._callbackArity) |
| 208 ); |
| 209 |
| 210 /// Deregisters an event listener <em>callback</em> from an event. |
| 211 void removeListener(Function callback) => |
| 212 JS('void', |
| 213 '#.removeListener(#)', |
| 214 this._jsObject, |
| 215 convertDartClosureToJS(callback, this._callbackArity) |
| 216 ); |
| 217 |
| 218 /// Returns True if <em>callback</em> is registered to the event. |
| 219 bool hasListener(Function callback) => |
| 220 JS('bool', |
| 221 '#.hasListener(#)', |
| 222 this._jsObject, |
| 223 convertDartClosureToJS(callback, this._callbackArity) |
| 224 ); |
| 225 |
| 226 /// Returns true if any event listeners are registered to the event. |
| 227 bool hasListeners() => |
| 228 JS('bool', |
| 229 '#.hasListeners()', |
| 230 this._jsObject |
| 231 ); |
| 232 |
| 233 /// Registers rules to handle events. |
| 234 /// |
| 235 /// [eventName] is the name of the event this function affects and [rules] are |
| 236 /// the rules to be registered. These do not replace previously registered |
| 237 /// rules. [callback] is called with registered rules. |
| 238 /// |
| 239 void addRules(String eventName, List<Rule> rules, |
| 240 [void callback(List<Rule> rules)]) { |
| 241 // proxy the callback |
| 242 void __proxy_callback(List rules) { |
| 243 if (?callback) { |
| 244 List<Rule> __proxy_rules = new List<Rule>(); |
| 245 |
| 246 for (Object o in rules) |
| 247 __proxy_rules.add(new Rule._proxy(o)); |
| 248 |
| 249 callback(__proxy_rules); |
| 250 } |
| 251 } |
| 252 |
| 253 JS('void', |
| 254 '#.addRules(#, #, #)', |
| 255 this._jsObject, |
| 256 convertArgument(eventName), |
| 257 convertArgument(rules), |
| 258 convertDartClosureToJS(__proxy_callback, 1) |
| 259 ); |
| 260 } |
| 261 |
| 262 /// Returns currently registered rules. |
| 263 /// |
| 264 /// [eventName] is the name of the event this function affects and, if an arra
y |
| 265 /// is passed as [ruleIdentifiers], only rules with identifiers contained in |
| 266 /// this array are returned. [callback] is called with registered rules. |
| 267 /// |
| 268 void getRules(String eventName, [List<String> ruleIdentifiers, |
| 269 void callback(List<Rule> rules)]) { |
| 270 // proxy the callback |
| 271 void __proxy_callback(List rules) { |
| 272 if (?callback) { |
| 273 List<Rule> __proxy_rules = new List<Rule>(); |
| 274 |
| 275 for (Object o in rules) |
| 276 __proxy_rules.add(new Rule._proxy(o)); |
| 277 |
| 278 callback(__proxy_rules); |
| 279 } |
| 280 } |
| 281 |
| 282 JS('void', |
| 283 '#.getRules(#, #, #)', |
| 284 this._jsObject, |
| 285 convertArgument(eventName), |
| 286 convertArgument(ruleIdentifiers), |
| 287 convertDartClosureToJS(__proxy_callback, 1) |
| 288 ); |
| 289 } |
| 290 |
| 291 /// Unregisters currently registered rules. |
| 292 /// |
| 293 /// [eventName] is the name of the event this function affects and, if an arra
y |
| 294 /// is passed as [ruleIdentifiers], only rules with identifiers contained in |
| 295 /// this array are unregistered. [callback] is called when the rules are |
| 296 /// unregistered. |
| 297 /// |
| 298 void removeRules(String eventName, [List<String> ruleIdentifiers, |
| 299 void callback()]) => |
| 300 JS('void', |
| 301 '#.removeRules(#, #, #)', |
| 302 this._jsObject, |
| 303 convertArgument(eventName), |
| 304 convertArgument(ruleIdentifiers), |
| 305 convertDartClosureToJS(callback, 0) |
| 306 ); |
| 307 } |
| 308 |
| 11 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 309 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 12 // for details. All rights reserved. Use of this source code is governed by a | 310 // for details. All rights reserved. Use of this source code is governed by a |
| 13 // BSD-style license that can be found in the LICENSE file. | 311 // BSD-style license that can be found in the LICENSE file. |
| 14 | 312 |
| 15 | 313 |
| 16 // This is an example of exposing chrome APIs in Dart and will be replaced with | 314 // chrome.app |
| 17 // the proper implementation in the future. | 315 class API_ChromeApp { |
| 18 | 316 /* |
| 19 class AppModule { | 317 * JS Variable |
| 20 AppModule._(); | 318 */ |
| 21 | 319 Object _jsObject; |
| 22 WindowModule get window => new WindowModule._(); | 320 |
| 23 } | 321 /* |
| 24 | 322 * Members |
| 25 class WindowModule { | 323 */ |
| 26 WindowModule._(); | 324 API_ChromeAppWindow window; |
| 27 | 325 API_ChromeAppRuntime runtime; |
| 28 void create(String url) { | 326 |
| 29 var chrome = JS('', 'chrome'); | 327 /* |
| 30 | 328 * Constructor |
| 31 if (chrome == null) { | 329 */ |
| 32 throw new UnsupportedError('Not supported by current browser'); | 330 API_ChromeApp(this._jsObject) { |
| 331 var window_object = JS('', '#.window', this._jsObject); |
| 332 if (window_object == null) |
| 333 throw new UnsupportedError('Not supported by current browser.'); |
| 334 window = new API_ChromeAppWindow(window_object); |
| 335 |
| 336 var runtime_object = JS('', '#.runtime', this._jsObject); |
| 337 if (runtime_object == null) |
| 338 throw new UnsupportedError('Not supported by current browser.'); |
| 339 runtime = new API_ChromeAppRuntime(runtime_object); |
| 340 } |
| 341 } |
| 342 |
| 343 // chrome |
| 344 class API_Chrome { |
| 345 /* |
| 346 * JS Variable |
| 347 */ |
| 348 Object _jsObject; |
| 349 |
| 350 /* |
| 351 * Members |
| 352 */ |
| 353 API_ChromeApp app; |
| 354 |
| 355 /* |
| 356 * Constructor |
| 357 */ |
| 358 API_Chrome() { |
| 359 this._jsObject = JS("Object", "chrome"); |
| 360 if (this._jsObject == null) |
| 361 throw new UnsupportedError('Not supported by current browser.'); |
| 362 |
| 363 var app_object = JS('', '#.app', this._jsObject); |
| 364 if (app_object == null) |
| 365 throw new UnsupportedError('Not supported by current browser.'); |
| 366 app = new API_ChromeApp(app_object); |
| 367 } |
| 368 } |
| 369 |
| 370 // The final chrome objects |
| 371 final API_Chrome chrome = new API_Chrome(); |
| 372 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 373 // for details. All rights reserved. Use of this source code is governed by a |
| 374 // BSD-style license that can be found in the LICENSE file. |
| 375 |
| 376 // from app_runtime.idl |
| 377 |
| 378 /** |
| 379 * Types |
| 380 */ |
| 381 |
| 382 /// A WebIntents intent object. Deprecated. |
| 383 class Intent extends ChromeObject { |
| 384 /* |
| 385 * Public (Dart) constructor |
| 386 */ |
| 387 Intent({String action, String type, var data}) { |
| 388 this.action = action; |
| 389 this.type = type; |
| 390 this.data = data; |
| 391 } |
| 392 |
| 393 /* |
| 394 * Private (JS) constructor |
| 395 */ |
| 396 Intent._proxy(_jsObject) : super._proxy(_jsObject); |
| 397 |
| 398 /* |
| 399 * Public accessors |
| 400 */ |
| 401 |
| 402 /// The WebIntent being invoked. |
| 403 String get action => JS('String', '#.action', this._jsObject); |
| 404 |
| 405 void set action(String action) { |
| 406 JS('void', '#.action = #', this._jsObject, action); |
| 407 } |
| 408 |
| 409 /// The MIME type of the data. |
| 410 String get type => JS('String', '#.type', this._jsObject); |
| 411 |
| 412 void set type(String type) { |
| 413 JS('void', '#.type = #', this._jsObject, type); |
| 414 } |
| 415 |
| 416 /// Data associated with the intent. |
| 417 // TODO(sashab): What is the best way to serialize/return generic JS objects? |
| 418 Object get data => JS('Object', '#.data', this._jsObject); |
| 419 |
| 420 void set data(Object data) { |
| 421 JS('void', '#.data = #', this._jsObject, convertArgument(data)); |
| 422 } |
| 423 |
| 424 /* |
| 425 * TODO(sashab): What is a NullCallback() type? |
| 426 * Add postResult and postFailure once understanding what this type is, and |
| 427 * once there is a way to pass functions back from JS. |
| 428 */ |
| 429 } |
| 430 |
| 431 class LaunchItem extends ChromeObject { |
| 432 /* |
| 433 * Public constructor |
| 434 */ |
| 435 LaunchItem({FileEntry entry, String type}) { |
| 436 this.entry = entry; |
| 437 this.type = type; |
| 438 } |
| 439 |
| 440 /* |
| 441 * Private constructor |
| 442 */ |
| 443 LaunchItem._proxy(_jsObject) : super._proxy(_jsObject); |
| 444 |
| 445 /* |
| 446 * Public accessors |
| 447 */ |
| 448 |
| 449 /// FileEntry for the file. |
| 450 FileEntry get entry => JS('FileEntry', '#.entry', this._jsObject); |
| 451 |
| 452 void set entry(FileEntry entry) { |
| 453 JS('void', '#.entry = #', this._jsObject, entry); |
| 454 } |
| 455 |
| 456 /// The MIME type of the file. |
| 457 String get type => JS('String', '#.type', this._jsObject); |
| 458 |
| 459 void set type(String type) { |
| 460 JS('void', '#.type = #', this._jsObject, type); |
| 461 } |
| 462 } |
| 463 |
| 464 /// Optional data for the launch. |
| 465 class LaunchData extends ChromeObject { |
| 466 /* |
| 467 * Public constructor |
| 468 */ |
| 469 LaunchData({Intent intent, String id, List<LaunchItem> items}) { |
| 470 this.intent = intent; |
| 471 this.id = id; |
| 472 this.items = items; |
| 473 } |
| 474 |
| 475 /* |
| 476 * Private constructor |
| 477 */ |
| 478 LaunchData._proxy(_jsObject) : super._proxy(_jsObject); |
| 479 |
| 480 /* |
| 481 * Public accessors |
| 482 */ |
| 483 Intent get intent => new Intent._proxy(JS('', '#.intent', this._jsObject)); |
| 484 |
| 485 void set intent(Intent intent) { |
| 486 JS('void', '#.intent = #', this._jsObject, convertArgument(intent)); |
| 487 } |
| 488 |
| 489 /// The id of the file handler that the app is being invoked with. |
| 490 String get id => JS('String', '#.id', this._jsObject); |
| 491 |
| 492 void set id(String id) { |
| 493 JS('void', '#.id = #', this._jsObject, id); |
| 494 } |
| 495 |
| 496 List<LaunchItem> get items() { |
| 497 List<LaunchItem> items_final = new List<LaunchItem>(); |
| 498 for (var o in JS('List', '#.items', this._jsObject)) { |
| 499 items_final.add(new LaunchItem._proxy(o)); |
| 33 } | 500 } |
| 34 var app = JS('', '#.app', chrome); | 501 return items_final; |
| 35 if (app == null) { | 502 } |
| 36 throw new UnsupportedError('Not supported by current browser'); | 503 |
| 504 void set items(List<LaunchItem> items) { |
| 505 JS('void', '#.items = #', this._jsObject, convertArgument(items)); |
| 506 } |
| 507 } |
| 508 |
| 509 class IntentResponse extends ChromeObject { |
| 510 /* |
| 511 * Public constructor |
| 512 */ |
| 513 IntentResponse({int intentId, bool success, Object data}) { |
| 514 this.intentId = intentId; |
| 515 this.success = success; |
| 516 this.data = data; |
| 517 } |
| 518 |
| 519 /* |
| 520 * Private constructor |
| 521 */ |
| 522 IntentResponse._proxy(_jsObject) : super._proxy(_jsObject); |
| 523 |
| 524 /* |
| 525 * Public accessors |
| 526 */ |
| 527 |
| 528 /// Identifies the intent. |
| 529 int get intentId => JS('int', '#.intentId', this._jsObject); |
| 530 |
| 531 void set intentId(int intentId) { |
| 532 JS('void', '#.intentId = #', this._jsObject, intentId); |
| 533 } |
| 534 |
| 535 /// Was this intent successful? (i.e., postSuccess vs postFailure). |
| 536 bool get success => JS('bool', '#.success', this._jsObject); |
| 537 |
| 538 void set success(bool success) { |
| 539 JS('void', '#.success = #', this._jsObject, success); |
| 540 } |
| 541 |
| 542 /// Data associated with the intent response. |
| 543 // TODO(sashab): What's the best way to serialize/return generic JS objects? |
| 544 Object get data => JS('Object', '#.data', this._jsObject); |
| 545 |
| 546 void set data(Object data) { |
| 547 JS('void', '#.data = #', this._jsObject, convertArgument(data)); |
| 548 } |
| 549 } |
| 550 |
| 551 /** |
| 552 * Events |
| 553 */ |
| 554 |
| 555 /// Fired at Chrome startup to apps that were running when Chrome last shut |
| 556 /// down. |
| 557 class Event_ChromeAppRuntimeOnRestarted extends Event { |
| 558 /* |
| 559 * Override callback type definitions |
| 560 */ |
| 561 void addListener(void callback()) |
| 562 => super.addListener(callback); |
| 563 void removeListener(void callback()) |
| 564 => super.removeListener(callback); |
| 565 bool hasListener(void callback()) |
| 566 => super.hasListener(callback); |
| 567 |
| 568 /* |
| 569 * Constructor |
| 570 */ |
| 571 Event_ChromeAppRuntimeOnRestarted(jsObject) : super._(jsObject, 0); |
| 572 } |
| 573 |
| 574 /// Fired when an app is launched from the launcher or in response to a web |
| 575 /// intent. |
| 576 class Event_ChromeAppRuntimeOnLaunched extends Event { |
| 577 /* |
| 578 * Override callback type definitions |
| 579 */ |
| 580 void addListener(void callback(LaunchData launchData)) |
| 581 => super.addListener(callback); |
| 582 void removeListener(void callback(LaunchData launchData)) |
| 583 => super.removeListener(callback); |
| 584 bool hasListener(void callback(LaunchData launchData)) |
| 585 => super.hasListener(callback); |
| 586 |
| 587 /* |
| 588 * Constructor |
| 589 */ |
| 590 Event_ChromeAppRuntimeOnLaunched(jsObject) : super._(jsObject, 1); |
| 591 } |
| 592 |
| 593 /** |
| 594 * Functions |
| 595 */ |
| 596 class API_ChromeAppRuntime { |
| 597 /* |
| 598 * API connection |
| 599 */ |
| 600 Object _jsObject; |
| 601 |
| 602 /* |
| 603 * Events |
| 604 */ |
| 605 Event_ChromeAppRuntimeOnRestarted onRestarted; |
| 606 Event_ChromeAppRuntimeOnLaunched onLaunched; |
| 607 |
| 608 /* |
| 609 * Functions |
| 610 */ |
| 611 void postIntentResponse(IntentResponse intentResponse) => |
| 612 JS('void', '#.postIntentResponse(#)', this._jsObject, |
| 613 convertArgument(intentResponse)); |
| 614 |
| 615 /* |
| 616 * Constructor |
| 617 */ |
| 618 API_ChromeAppRuntime(this._jsObject) { |
| 619 onRestarted = new Event_ChromeAppRuntimeOnRestarted(JS('Object', |
| 620 '#.onRestarted', |
| 621 this._jsObject)); |
| 622 onLaunched = new Event_ChromeAppRuntimeOnLaunched(JS('Object', |
| 623 '#.onLaunched', |
| 624 this._jsObject)); |
| 625 } |
| 626 } |
| 627 |
| 628 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 629 // for details. All rights reserved. Use of this source code is governed by a |
| 630 // BSD-style license that can be found in the LICENSE file. |
| 631 |
| 632 // from app.window.idl |
| 633 |
| 634 /** |
| 635 * Types |
| 636 */ |
| 637 class CreateWindowOptions extends ChromeObject { |
| 638 /* |
| 639 * Public constructor |
| 640 */ |
| 641 CreateWindowOptions({String id, int defaultWidth, int defaultHeight, |
| 642 int defaultLeft, int defaultTop, int width, int height, int left, int top, |
| 643 int minWidth, int minHeight, int maxWidth, int maxHeight, String type, |
| 644 String frame, Bounds bounds, bool hidden}) { |
| 645 this.id = id; |
| 646 this.defaultWidth = defaultWidth; |
| 647 this.defaultHeight = defaultHeight; |
| 648 this.defaultLeft = defaultLeft; |
| 649 this.defaultTop = defaultTop; |
| 650 this.width = width; |
| 651 this.height = height; |
| 652 this.left = left; |
| 653 this.top = top; |
| 654 this.minWidth = minWidth; |
| 655 this.minHeight = minHeight; |
| 656 this.maxWidth = maxWidth; |
| 657 this.maxHeight = maxHeight; |
| 658 this.type = type; |
| 659 this.frame = frame; |
| 660 this.bounds = bounds; |
| 661 this.hidden = hidden; |
| 662 } |
| 663 |
| 664 /* |
| 665 * Private constructor |
| 666 */ |
| 667 CreateWindowOptions._proxy(_jsObject) : super._proxy(_jsObject); |
| 668 |
| 669 /* |
| 670 * Public accessors |
| 671 */ |
| 672 /// Id to identify the window. This will be used to remember the size |
| 673 /// and position of the window and restore that geometry when a window |
| 674 /// with the same id (and no explicit size or position) is later opened. |
| 675 String get id => JS('String', '#.id', this._jsObject); |
| 676 |
| 677 void set id(String id) { |
| 678 JS('void', '#.id = #', this._jsObject, id); |
| 679 } |
| 680 |
| 681 /// Default width of the window. (Deprecated; regular bounds act like this |
| 682 /// now.) |
| 683 int get defaultWidth => JS('int', '#.defaultWidth', this._jsObject); |
| 684 |
| 685 void set defaultWidth(int defaultWidth) { |
| 686 JS('void', '#.defaultWidth = #', this._jsObject, defaultWidth); |
| 687 } |
| 688 |
| 689 /// Default height of the window. (Deprecated; regular bounds act like this |
| 690 /// now.) |
| 691 int get defaultHeight => JS('int', '#.defaultHeight', this._jsObject); |
| 692 |
| 693 void set defaultHeight(int defaultHeight) { |
| 694 JS('void', '#.defaultHeight = #', this._jsObject, defaultHeight); |
| 695 } |
| 696 |
| 697 /// Default X coordinate of the window. (Deprecated; regular bounds act like |
| 698 /// this now.) |
| 699 int get defaultLeft => JS('int', '#.defaultLeft', this._jsObject); |
| 700 |
| 701 void set defaultLeft(int defaultLeft) { |
| 702 JS('void', '#.defaultLeft = #', this._jsObject, defaultLeft); |
| 703 } |
| 704 |
| 705 /// Default Y coordinate of the window. (Deprecated; regular bounds act like |
| 706 /// this now.) |
| 707 int get defaultTop => JS('int', '#.defaultTop', this._jsObject); |
| 708 |
| 709 void set defaultTop(int defaultTop) { |
| 710 JS('void', '#.defaultTop = #', this._jsObject, defaultTop); |
| 711 } |
| 712 |
| 713 /// Width of the window. (Deprecated; use 'bounds'.) |
| 714 int get width => JS('int', '#.width', this._jsObject); |
| 715 |
| 716 void set width(int width) { |
| 717 JS('void', '#.width = #', this._jsObject, width); |
| 718 } |
| 719 |
| 720 /// Height of the window. (Deprecated; use 'bounds'.) |
| 721 int get height => JS('int', '#.height', this._jsObject); |
| 722 |
| 723 void set height(int height) { |
| 724 JS('void', '#.height = #', this._jsObject, height); |
| 725 } |
| 726 |
| 727 /// X coordinate of the window. (Deprecated; use 'bounds'.) |
| 728 int get left => JS('int', '#.left', this._jsObject); |
| 729 |
| 730 void set left(int left) { |
| 731 JS('void', '#.left = #', this._jsObject, left); |
| 732 } |
| 733 |
| 734 /// Y coordinate of the window. (Deprecated; use 'bounds'.) |
| 735 int get top => JS('int', '#.top', this._jsObject); |
| 736 |
| 737 void set top(int top) { |
| 738 JS('void', '#.top = #', this._jsObject, top); |
| 739 } |
| 740 |
| 741 /// Minimium width of the window. |
| 742 int get minWidth => JS('int', '#.minWidth', this._jsObject); |
| 743 |
| 744 void set minWidth(int minWidth) { |
| 745 JS('void', '#.minWidth = #', this._jsObject, minWidth); |
| 746 } |
| 747 |
| 748 /// Minimum height of the window. |
| 749 int get minHeight => JS('int', '#.minHeight', this._jsObject); |
| 750 |
| 751 void set minHeight(int minHeight) { |
| 752 JS('void', '#.minHeight = #', this._jsObject, minHeight); |
| 753 } |
| 754 |
| 755 /// Maximum width of the window. |
| 756 int get maxWidth => JS('int', '#.maxWidth', this._jsObject); |
| 757 |
| 758 void set maxWidth(int maxWidth) { |
| 759 JS('void', '#.maxWidth = #', this._jsObject, maxWidth); |
| 760 } |
| 761 |
| 762 /// Maximum height of the window. |
| 763 int get maxHeight => JS('int', '#.maxHeight', this._jsObject); |
| 764 |
| 765 void set maxHeight(int maxHeight) { |
| 766 JS('void', '#.maxHeight = #', this._jsObject, maxHeight); |
| 767 } |
| 768 |
| 769 /// Window type: 'shell' (the default) is the only currently supported value. |
| 770 String get type => JS('String', '#.type', this._jsObject); |
| 771 |
| 772 void set type(String type) { |
| 773 JS('void', '#.type = #', this._jsObject, type); |
| 774 } |
| 775 |
| 776 /// Frame type: 'none' or 'chrome' (defaults to 'chrome'). |
| 777 String get frame => JS('String', '#.frame', this._jsObject); |
| 778 |
| 779 void set frame(String frame) { |
| 780 JS('void', '#.frame = #', this._jsObject, frame); |
| 781 } |
| 782 |
| 783 /// Size of the content in the window (excluding the titlebar). If specified |
| 784 /// in addition to any of the left/top/width/height parameters, this field |
| 785 /// takes precedence. If a frameBounds is specified, the frameBounds take |
| 786 /// precedence. |
| 787 Bounds get bounds => |
| 788 new Bounds._proxy(JS('Bounds', '#.bounds', this._jsObject)); |
| 789 |
| 790 void set bounds(Bounds bounds) { |
| 791 JS('void', '#.bounds = #', this._jsObject, convertArgument(bounds)); |
| 792 } |
| 793 |
| 794 /// If true, the window will be created in a hidden state. Call show() on |
| 795 /// the window to show it once it has been created. Defaults to false. |
| 796 bool get hidden => JS('bool', '#.hidden', this._jsObject); |
| 797 |
| 798 void set hidden(bool hidden) { |
| 799 JS('void', '#.hidden = #', this._jsObject, hidden); |
| 800 } |
| 801 } |
| 802 |
| 803 class Bounds extends ChromeObject { |
| 804 /* |
| 805 * Public constructor |
| 806 */ |
| 807 Bounds({int left, int top, int width, int height}) { |
| 808 this.left = left; |
| 809 this.top = top; |
| 810 this.width = width; |
| 811 this.height = height; |
| 812 } |
| 813 |
| 814 /* |
| 815 * Private constructor |
| 816 */ |
| 817 Bounds._proxy(_jsObject) : super._proxy(_jsObject); |
| 818 |
| 819 /* |
| 820 * Public accessors |
| 821 */ |
| 822 int get left => JS('int', '#.left', this._jsObject); |
| 823 |
| 824 void set left(int left) { |
| 825 JS('void', '#.left = #', this._jsObject, left); |
| 826 } |
| 827 |
| 828 int get top => JS('int', '#.top', this._jsObject); |
| 829 |
| 830 void set top(int top) { |
| 831 JS('void', '#.top = #', this._jsObject, top); |
| 832 } |
| 833 |
| 834 int get width => JS('int', '#.width', this._jsObject); |
| 835 |
| 836 void set width(int width) { |
| 837 JS('void', '#.width = #', this._jsObject, width); |
| 838 } |
| 839 |
| 840 int get height => JS('int', '#.height', this._jsObject); |
| 841 |
| 842 void set height(int height) { |
| 843 JS('void', '#.height = #', this._jsObject, height); |
| 844 } |
| 845 } |
| 846 |
| 847 class AppWindow extends ChromeObject { |
| 848 /* |
| 849 * Public constructor |
| 850 * TODO(sashab): Does it make sense to be able to create a new AppWindow this |
| 851 * way? |
| 852 */ |
| 853 //AppWindow(); |
| 854 |
| 855 /* |
| 856 * Private constructor |
| 857 */ |
| 858 AppWindow._proxy(jsObject) : super._proxy(jsObject); |
| 859 |
| 860 /* |
| 861 * Public accessors |
| 862 */ |
| 863 /// The JavaScript 'window' object for the created child. |
| 864 // TODO(sashab, sra): Detect whether this is the current window, or an |
| 865 // external one, and return an appropriately-typed object |
| 866 WindowBase get contentWindow => |
| 867 JS("Window", "#.contentWindow", this._jsObject); |
| 868 |
| 869 /* |
| 870 * Functions |
| 871 */ |
| 872 |
| 873 /// Focus the window. |
| 874 void focus() => JS("void", "#.focus()", this._jsObject); |
| 875 |
| 876 /// Minimize the window. |
| 877 void minimize() => JS("void", "#.minimize()", this._jsObject); |
| 878 |
| 879 /// Is the window minimized? |
| 880 bool isMinimized() => JS("bool", "#.isMinimized()", this._jsObject); |
| 881 |
| 882 /// Maximize the window. |
| 883 void maximize() => JS("void", "#.maximize()", this._jsObject); |
| 884 |
| 885 /// Is the window maximized? |
| 886 bool isMaximized() => JS("bool", "c#.isMaximized()", this._jsObject); |
| 887 |
| 888 /// Restore the window. |
| 889 void restore() => JS("void", "#.restore()", this._jsObject); |
| 890 |
| 891 /// Move the window to the position (|left|, |top|). |
| 892 void moveTo(int left, int top) => |
| 893 JS("void", "#.moveTo(#, #)", this._jsObject, left, top); |
| 894 |
| 895 /// Resize the window to |width|x|height| pixels in size. |
| 896 void resizeTo(int width, int height) => |
| 897 JS("void", "#.resizeTo(#, #)", this._jsObject, width, height); |
| 898 |
| 899 /// Draw attention to the window. |
| 900 void drawAttention() => JS("void", "#.drawAttention()", this._jsObject); |
| 901 |
| 902 /// Clear attention to the window. |
| 903 void clearAttention() => JS("void", "#.clearAttention()", this._jsObject); |
| 904 |
| 905 /// Close the window. |
| 906 void close() => JS("void", "#.close()", this._jsObject); |
| 907 |
| 908 /// Show the window. Does nothing if the window is already visible. |
| 909 void show() => JS("void", "#.show()", this._jsObject); |
| 910 |
| 911 /// Hide the window. Does nothing if the window is already hidden. |
| 912 void hide() => JS("void", "#.hide()", this._jsObject); |
| 913 |
| 914 /// Set the window's bounds. |
| 915 void setBounds(Bounds bounds) => |
| 916 JS("void", "#.setBounds(#)", this._jsObject, convertArgument(bounds)); |
| 917 |
| 918 } |
| 919 |
| 920 /** |
| 921 * Functions |
| 922 */ |
| 923 class API_ChromeAppWindow { |
| 924 /** |
| 925 * JS object |
| 926 */ |
| 927 Object _jsObject; |
| 928 |
| 929 /** |
| 930 * Constructor |
| 931 */ |
| 932 API_ChromeAppWindow(this._jsObject); |
| 933 |
| 934 /** |
| 935 * Functions |
| 936 */ |
| 937 |
| 938 /// Returns an <a href="#type-AppWindow">AppWindow</a> object for the |
| 939 /// current script context (ie JavaScript 'window' object). This can also be |
| 940 /// called on a handle to a script context for another page, for example: |
| 941 /// otherWindow.chrome.app.window.current(). |
| 942 AppWindow current() => |
| 943 new AppWindow._proxy(JS("Object", "#.current()", this._jsObject)); |
| 944 |
| 945 /// The size and position of a window can be specified in a number of |
| 946 /// different ways. The most simple option is not specifying anything at |
| 947 /// all, in which case a default size and platform dependent position will |
| 948 /// be used. |
| 949 /// |
| 950 /// Another option is to use the top/left and width/height properties, |
| 951 /// which will always put the window at the specified coordinates with the |
| 952 /// specified size. |
| 953 /// |
| 954 /// Yet another option is to give the window a (unique) id. This id is then |
| 955 /// used to remember the size and position of the window whenever it is |
| 956 /// moved or resized. This size and position is then used instead of the |
| 957 /// specified bounds on subsequent opening of a window with the same id. If |
| 958 /// you need to open a window with an id at a location other than the |
| 959 /// remembered default, you can create it hidden, move it to the desired |
| 960 /// location, then show it. |
| 961 /// |
| 962 /// You can also combine these various options, explicitly specifying for |
| 963 /// example the size while having the position be remembered or other |
| 964 /// combinations like that. Size and position are dealt with seperately, |
| 965 /// but individual coordinates are not. So if you specify a top (or left) |
| 966 /// coordinate, you should also specify a left (or top) coordinate, and |
| 967 /// similar for size. |
| 968 /// |
| 969 /// If you specify both a regular and a default value for the same option |
| 970 /// the regular value is the only one that takes effect. |
| 971 void create(String url, [CreateWindowOptions options, |
| 972 void callback(AppWindow created_window)]) { |
| 973 void __proxy_callback(Object created_window) { |
| 974 if (?callback) |
| 975 callback(new AppWindow._proxy(created_window)); |
| 37 } | 976 } |
| 38 var window = JS('', '#.window', app); | 977 |
| 39 if (app == null) { | 978 JS("void", "#.create(#, #, #)", |
| 40 throw new UnsupportedError('Not supported by current browser'); | 979 this._jsObject, |
| 41 } | 980 url, |
| 42 JS('void', '#.create(#)', window, url); | 981 convertArgument(options), |
| 43 } | 982 convertDartClosureToJS(__proxy_callback, 1) |
| 44 } | 983 ); |
| 45 | 984 } |
| 46 final app = new AppModule._(); | 985 } |
| OLD | NEW |