| Index: sdk/lib/html/dart2js/html_dart2js.dart
|
| diff --git a/sdk/lib/html/dart2js/html_dart2js.dart b/sdk/lib/html/dart2js/html_dart2js.dart
|
| index 78346e6ed9486540c3901ffd0a447720b0df3519..2b1abe7d149c42fa5eb0da300170968fc43c3aad 100644
|
| --- a/sdk/lib/html/dart2js/html_dart2js.dart
|
| +++ b/sdk/lib/html/dart2js/html_dart2js.dart
|
| @@ -11708,18 +11708,116 @@ class Gamepad native "*Gamepad" {
|
| @DomName('Geolocation')
|
| class Geolocation native "*Geolocation" {
|
|
|
| + @DomName('Geolocation.getCurrentPosition')
|
| + Future<Geoposition> getCurrentPosition({bool enableHighAccuracy,
|
| + Duration timeout, Duration maximumAge}) {
|
| + var options = {};
|
| + if (enableHighAccuracy != null) {
|
| + options['enableHighAccuracy'] = enableHighAccuracy;
|
| + }
|
| + if (timeout != null) {
|
| + options['timeout'] = timeout.inMilliseconds;
|
| + }
|
| + if (maximumAge != null) {
|
| + options['maximumAge'] = maximumAge.inMilliseconds;
|
| + }
|
| + var completer = new Completer<Geoposition>();
|
| + try {
|
| + $dom_getCurrentPosition(
|
| + (position) {
|
| + completer.complete(_ensurePosition(position));
|
| + },
|
| + (error) {
|
| + completer.completeError(error);
|
| + },
|
| + options);
|
| + } catch (e, stacktrace) {
|
| + completer.completeError(e, stacktrace);
|
| + }
|
| + return completer.future;
|
| + }
|
| +
|
| + @DomName('Geolocation.watchPosition')
|
| + Stream<Geoposition> watchPosition({bool enableHighAccuracy,
|
| + Duration timeout, Duration maximumAge}) {
|
| +
|
| + var options = {};
|
| + if (enableHighAccuracy != null) {
|
| + options['enableHighAccuracy'] = enableHighAccuracy;
|
| + }
|
| + if (timeout != null) {
|
| + options['timeout'] = timeout.inMilliseconds;
|
| + }
|
| + if (maximumAge != null) {
|
| + options['maximumAge'] = maximumAge.inMilliseconds;
|
| + }
|
| +
|
| + int watchId;
|
| + var controller;
|
| + controller = new StreamController<Geoposition>(
|
| + onSubscriptionStateChange: () {
|
| + if (controller.hasSubscribers) {
|
| + assert(watchId == null);
|
| + watchId = $dom_watchPosition(
|
| + (position) {
|
| + controller.add(_ensurePosition(position));
|
| + },
|
| + (error) {
|
| + controller.signalError(error);
|
| + },
|
| + options);
|
| + } else {
|
| + assert(watchId != null);
|
| + $dom_clearWatch(watchId);
|
| + }
|
| + });
|
| +
|
| + return controller.stream;
|
| + }
|
| +
|
| + Geoposition _ensurePosition(domPosition) {
|
| + try {
|
| + // Firefox may throw on this.
|
| + if (domPosition is Geoposition) {
|
| + return domPosition;
|
| + }
|
| + } catch(e) {}
|
| + return new _GeopositionWrapper(domPosition);
|
| + }
|
| +
|
| + /// Checks if this type is supported on the current platform.
|
| + static bool get supported => JS('bool', '!!(window.navigator.geolocation)');
|
| +
|
| + @JSName('clearWatch')
|
| @DomName('Geolocation.clearWatch')
|
| @DocsEditable
|
| - void clearWatch(int watchId) native;
|
| + void $dom_clearWatch(int watchId) native;
|
|
|
| + @JSName('getCurrentPosition')
|
| @DomName('Geolocation.getCurrentPosition')
|
| @DocsEditable
|
| - void getCurrentPosition(PositionCallback successCallback, [PositionErrorCallback errorCallback, Object options]) native;
|
| + void $dom_getCurrentPosition(_PositionCallback successCallback, [_PositionErrorCallback errorCallback, Object options]) native;
|
|
|
| + @JSName('watchPosition')
|
| @DomName('Geolocation.watchPosition')
|
| @DocsEditable
|
| - int watchPosition(PositionCallback successCallback, [PositionErrorCallback errorCallback, Object options]) native;
|
| + int $dom_watchPosition(_PositionCallback successCallback, [_PositionErrorCallback errorCallback, Object options]) native;
|
| +}
|
| +
|
| +/**
|
| + * Wrapper for FireFox- it returns an object which we cannot map correctly.
|
| + * Basically FireFox was returning a [xpconnect wrapped nsIDOMGeoPosition] but
|
| + * which has further oddities.
|
| + */
|
| +class _GeopositionWrapper implements Geoposition {
|
| + var _ptr;
|
| + _GeopositionWrapper(this._ptr);
|
| +
|
| + Coordinates get coords => JS('Coordinates', '#.coords', _ptr);
|
| + int get timestamp => JS('int', '#.timestamp', _ptr);
|
| }
|
| +
|
| +
|
| // 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.
|
| @@ -18389,7 +18487,7 @@ class PopStateEvent extends Event native "*PopStateEvent" {
|
| // WARNING: Do not edit - generated code.
|
|
|
|
|
| -typedef void PositionCallback(Geoposition position);
|
| +typedef void _PositionCallback(Geoposition position);
|
| // 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.
|
| @@ -18420,7 +18518,7 @@ class PositionError native "*PositionError" {
|
| // WARNING: Do not edit - generated code.
|
|
|
|
|
| -typedef void PositionErrorCallback(PositionError error);
|
| +typedef void _PositionErrorCallback(PositionError error);
|
| // 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.
|
|
|