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

Side by Side Diff: sdk/lib/chrome/dart2js/chrome_dart2js.dart

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

Powered by Google App Engine
This is Rietveld 408576698