Commit 7064551a authored by Adam Barth's avatar Adam Barth

Move mojo frontend into services.dart

What's important about this code is that it's presenting services outside the
VM, not the particular technology used to present the services.
parent 41b8ffd6
......@@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:sky/mojo/activity.dart';
import 'package:sky/mojo/asset_bundle.dart';
import 'package:sky/services.dart';
import 'package:sky/painting.dart';
import 'package:sky/theme/colors.dart' as colors;
import 'package:sky/theme/typography.dart' as typography;
......
......@@ -9,7 +9,7 @@ import 'dart:async';
import 'package:path/path.dart' as path;
import 'main.dart';
import 'package:sky/mojo/activity.dart';
import 'package:sky/services.dart';
String cachedDataFilePath = null;
......
......@@ -4,7 +4,7 @@
import 'dart:async';
import 'package:sky/mojo/asset_bundle.dart';
import 'package:sky/services.dart';
import 'package:sky/painting.dart';
import 'package:sky/src/rendering/object.dart';
import 'package:sky/src/widgets/basic.dart';
......
import 'dart:sky';
import 'package:sky/mojo/asset_bundle.dart';
import 'package:sky/services.dart';
import 'package:sky/rendering.dart';
import 'package:sky/theme/colors.dart' as colors;
import 'package:sky/widgets.dart';
......
import 'dart:sky' as sky;
import 'dart:math' as math;
import 'package:sky/mojo/asset_bundle.dart';
import 'package:sky/services.dart';
import 'package:sky/rendering.dart';
import 'package:sky/theme/colors.dart' as colors;
import 'package:sky/widgets.dart';
......
......@@ -4,7 +4,7 @@
import 'dart:sky' as sky;
import 'dart:math';
import 'package:sky/mojo/activity.dart' as activity;
import 'package:sky/services.dart';
import 'package:sky/painting.dart';
import 'package:sky/rendering.dart';
import 'package:sky/theme/colors.dart' as colors;
......@@ -113,7 +113,7 @@ class MineDiggerApp extends App {
probe(ix, iy);
},
onLongPress: () {
activity.userFeedback.performHapticFeedback(activity.HapticFeedbackType_LONG_PRESS);
userFeedback.performHapticFeedback(HapticFeedbackType_LONG_PRESS);
flag(ix, iy);
},
child: new Listener(
......
......@@ -6,7 +6,7 @@ import 'dart:math' as math;
import 'dart:sky' as sky;
import 'dart:typed_data';
import 'package:sky/mojo/net/image_cache.dart' as image_cache;
import 'package:sky/services.dart';
double timeBase = null;
......@@ -84,7 +84,7 @@ bool handleEvent(sky.Event event) {
}
if (event.type == "pointerup") {
image_cache.load(url2).first.then(handleImageLoad);
imageCache.load(url2).first.then(handleImageLoad);
return true;
}
......@@ -92,7 +92,7 @@ bool handleEvent(sky.Event event) {
}
void main() {
image_cache.load(url1).first.then(handleImageLoad);
imageCache.load(url1).first.then(handleImageLoad);
sky.view.setEventCallback(handleEvent);
sky.view.setFrameCallback(beginFrame);
}
......@@ -5,8 +5,7 @@
import 'dart:sky' as sky;
import 'dart:math' as math;
import 'package:sky/mojo/activity.dart';
import 'package:sky/mojo/net/image_cache.dart' as image_cache;
import 'package:sky/services.dart';
import 'package:sky/rendering.dart';
import 'solid_color_box.dart';
......@@ -60,7 +59,7 @@ void main() {
// Resizeable image
image = new RenderImageGrow(null, new Size(100.0, null));
image_cache.load("https://www.dartlang.org/logos/dart-logo.png").first.then((sky.Image dartLogo) {
imageCache.load("https://www.dartlang.org/logos/dart-logo.png").first.then((sky.Image dartLogo) {
image.image = dartLogo;
});
......
......@@ -10,8 +10,7 @@
import 'dart:convert';
import 'dart:math' as math;
import 'package:sky/mojo/asset_bundle.dart';
import 'package:sky/mojo/net/fetch.dart';
import 'package:sky/services.dart';
final math.Random _rng = new math.Random();
......
......@@ -4,8 +4,7 @@
import 'package:mojo/mojo/url_response.mojom.dart';
import 'package:sky_services/media/media.mojom.dart';
import 'package:sky/mojo/net/fetch.dart';
import 'package:sky/mojo/shell.dart' as shell;
import 'package:sky/services.dart';
import 'package:sky/rendering.dart';
import 'package:sky/theme/colors.dart' as colors;
import 'package:sky/widgets.dart';
......
......@@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:math' as math;
import 'package:sky/rendering.dart';
import 'package:sky/theme/colors.dart' as colors;
import 'package:sky/widgets.dart';
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:collection';
import 'dart:sky' as sky;
import 'package:mojo/mojo/url_response.mojom.dart';
import 'package:sky/mojo/image_resource.dart';
import 'package:sky/mojo/net/fetch.dart';
final HashMap<String, ImageResource> _cache = new Map<String, ImageResource>();
ImageResource load(String url) {
return _cache.putIfAbsent(url, () {
Completer<sky.Image> completer = new Completer<sky.Image>();
fetchUrl(url).then((UrlResponse response) {
if (response.statusCode >= 400) {
print("Failed (${response.statusCode}) to load image ${url}");
completer.complete(null);
} else {
new sky.ImageDecoder(response.body.handle.h, completer.complete);
}
});
return new ImageResource(completer.future);
});
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/// Services provided by Mojo
library services;
export 'src/services/activity.dart';
export 'src/services/asset_bundle.dart';
export 'src/services/embedder.dart';
export 'src/services/fetch.dart';
export 'src/services/image_cache.dart';
export 'src/services/image_resource.dart';
export 'src/services/keyboard.dart';
export 'src/services/shell.dart';
......@@ -6,7 +6,7 @@ import 'dart:math' as math;
import 'dart:sky' as sky;
import 'dart:sky' show Point, Offset, Size, Rect, Color, Paint, Path;
import 'package:sky/mojo/image_resource.dart';
import 'package:sky/services.dart';
import 'package:sky/src/painting/shadows.dart';
/// An immutable set of offsets in each of the four cardinal directions
......
......@@ -3,5 +3,5 @@ For example, keyboard.dart wraps the mojo keyboard service in a more
convenient Dart class.
Files in this directory (and its subdirectories) only depend on core
Dart libraries, `dart:sky`, `dart:sky.internals`, the 'mojo' package,
the 'mojo_services' package, and `../base/*`.
Dart libraries, `dart:sky`, `dart:sky.internals`, the `mojo` package,
and the `mojo_services` package.
......@@ -5,7 +5,7 @@
import 'dart:sky';
import 'dart:async';
import 'package:sky/mojo/shell.dart' as shell;
import 'package:sky/src/services/shell.dart';
import 'package:sky_services/activity/activity.mojom.dart';
export 'package:sky_services/activity/activity.mojom.dart';
......
......@@ -9,10 +9,10 @@ import 'dart:typed_data';
import 'package:mojo/core.dart' as core;
import 'package:mojo_services/mojo/asset_bundle/asset_bundle.mojom.dart';
import 'package:sky/mojo/image_resource.dart';
import 'package:sky/mojo/net/fetch.dart';
import 'package:sky/mojo/net/image_cache.dart' as image_cache;
import 'package:sky/mojo/shell.dart' as shell;
import 'package:sky/src/services/fetch.dart';
import 'package:sky/src/services/image_cache.dart';
import 'package:sky/src/services/image_resource.dart';
import 'package:sky/src/services/shell.dart';
abstract class AssetBundle {
void close();
......@@ -34,7 +34,7 @@ class NetworkAssetBundle extends AssetBundle {
return (await fetchUrl(_urlFromKey(key))).body;
}
ImageResource loadImage(String key) => image_cache.load(_urlFromKey(key));
ImageResource loadImage(String key) => imageCache.load(_urlFromKey(key));
Future<String> loadString(String key) => fetchString(_urlFromKey(key));
}
......
......@@ -10,7 +10,7 @@ import 'package:mojo/mojo/url_request.mojom.dart';
import 'package:mojo/mojo/url_response.mojom.dart';
import 'package:mojo_services/mojo/network_service.mojom.dart';
import 'package:mojo_services/mojo/url_loader.mojom.dart';
import 'package:sky/mojo/shell.dart' as shell;
import 'package:sky/src/services/shell.dart';
export 'package:mojo/mojo/url_response.mojom.dart' show UrlResponse;
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'dart:async';
import 'dart:collection';
import 'dart:sky' as sky;
import 'package:mojo/mojo/url_response.mojom.dart';
import 'package:sky/src/services/image_resource.dart';
import 'package:sky/src/services/fetch.dart';
class _ImageCache {
_ImageCache._();
final HashMap<String, ImageResource> _cache = new Map<String, ImageResource>();
ImageResource load(String url) {
return _cache.putIfAbsent(url, () {
Completer<sky.Image> completer = new Completer<sky.Image>();
fetchUrl(url).then((UrlResponse response) {
if (response.statusCode >= 400) {
print("Failed (${response.statusCode}) to load image ${url}");
completer.complete(null);
} else {
new sky.ImageDecoder(response.body.handle.h, completer.complete);
}
});
return new ImageResource(completer.future);
});
}
}
final _ImageCache imageCache = new _ImageCache._();
......@@ -3,7 +3,8 @@
// found in the LICENSE file.
import 'package:mojo_services/keyboard/keyboard.mojom.dart';
import 'package:sky/mojo/shell.dart' as shell;
import 'package:sky/src/services/shell.dart';
export 'package:mojo_services/keyboard/keyboard.mojom.dart';
class _KeyboardConnection {
......
......@@ -7,7 +7,7 @@ import 'dart:sky.internals' as internals;
import 'package:mojo/application.dart';
import 'package:mojo/core.dart' as core;
import 'package:mojo/mojo/service_provider.mojom.dart';
import 'package:sky/mojo/embedder.dart';
import 'package:sky/src/services/embedder.dart';
ApplicationConnection _initConnection() {
int rawHandle = internals.takeServicesProvidedByEmbedder();
......@@ -18,9 +18,15 @@ ApplicationConnection _initConnection() {
return new ApplicationConnection(null, serviceProvider);
}
final ApplicationConnection _connection = _initConnection();
class _ShellImpl {
_ShellImpl._();
void requestService(String url, Object proxy) {
if (embedder.shell == null) _connection.requestService(proxy);
else embedder.connectToService(url, proxy);
final ApplicationConnection _connection = _initConnection();
void requestService(String url, Object proxy) {
if (embedder.shell == null) _connection.requestService(proxy);
else embedder.connectToService(url, proxy);
}
}
final _ShellImpl shell = new _ShellImpl._();
......@@ -6,9 +6,7 @@ import 'dart:sky' as sky;
import 'package:vector_math/vector_math.dart';
import 'package:sky/mojo/asset_bundle.dart';
import 'package:sky/mojo/image_resource.dart';
import 'package:sky/mojo/net/image_cache.dart' as image_cache;
import 'package:sky/services.dart';
import 'package:sky/src/painting/text_painter.dart';
import 'package:sky/src/painting/text_style.dart';
import 'package:sky/src/rendering/block.dart';
......@@ -838,7 +836,7 @@ class NetworkImage extends Component {
Widget build() {
return new ImageListener(
image: image_cache.load(src),
image: imageCache.load(src),
width: width,
height: height,
colorFilter: colorFilter,
......
......@@ -6,7 +6,7 @@ import 'dart:async';
import 'package:intl/date_symbols.dart';
import 'package:intl/intl.dart';
import 'package:sky/mojo/activity.dart';
import 'package:sky/services.dart';
import 'package:sky/theme/colors.dart' as colors;
import 'package:sky/theme/typography.dart' as typography;
import 'package:sky/src/widgets/basic.dart';
......
......@@ -7,7 +7,7 @@ import 'dart:collection';
import 'dart:sky' as sky;
import 'package:sky/animation.dart';
import 'package:sky/mojo/activity.dart';
import 'package:sky/services.dart';
import 'package:sky/src/rendering/box.dart';
import 'package:sky/src/rendering/error.dart';
import 'package:sky/src/rendering/hit_test.dart';
......
......@@ -4,7 +4,7 @@
import 'dart:sky' as sky;
import 'package:sky/mojo/asset_bundle.dart';
import 'package:sky/services.dart';
import 'package:sky/src/widgets/basic.dart';
import 'package:sky/src/widgets/theme.dart';
import 'package:sky/src/widgets/framework.dart';
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:sky/mojo/keyboard.dart';
import 'package:sky/services.dart';
import 'package:sky/painting.dart';
import 'package:sky/src/widgets/basic.dart';
import 'package:sky/src/widgets/editable_text.dart';
......@@ -10,7 +10,7 @@ import 'package:sky/src/widgets/focus.dart';
import 'package:sky/src/widgets/framework.dart';
import 'package:sky/src/widgets/theme.dart';
export 'package:sky/mojo/keyboard.dart' show KeyboardType_TEXT, KeyboardType_NUMBER, KeyboardType_PHONE, KeyboardType_DATETIME;
export 'package:sky/services.dart' show KeyboardType_TEXT, KeyboardType_NUMBER, KeyboardType_PHONE, KeyboardType_DATETIME;
typedef void StringValueChanged(String value);
......
......@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:sky/mojo/activity.dart';
import 'package:sky/services.dart';
import 'package:sky/src/widgets/theme.dart';
import 'package:sky/src/widgets/framework.dart';
......
......@@ -12,9 +12,8 @@ import 'dart:sky';
import 'package:mojo/core.dart';
import 'package:sky/animation.dart';
import 'package:sky/mojo/asset_bundle.dart';
import 'package:sky/mojo/shell.dart' as shell;
import 'package:sky/painting.dart';
import 'package:sky/services.dart';
import 'package:sky/src/rendering/box.dart';
import 'package:sky/src/rendering/object.dart';
import 'package:sky/src/widgets/framework.dart';
......
......@@ -6,3 +6,6 @@ homepage: https://github.com/domokit/sky_engine/tree/master/sky/packages/sky
dependencies:
sky: ">=0.0.36 < 0.1.0"
sky_tools: ">=0.0.10 < 0.1.0"
dependency_overrides:
sky:
path: ../sky/packages/sky
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment