child_view.dart 1.48 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2016 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 'package:flutter/rendering.dart';

import 'framework.dart';
8
import 'media_query.dart';
9 10 11

export 'package:flutter/rendering.dart' show ChildViewConnection;

12 13 14 15
/// (mojo-only) A widget that is replaced by content from another process.
///
/// Requires a [MediaQuery] ancestor to provide appropriate media information to
/// the child.
16
class ChildView extends StatelessWidget {
17
  /// Creates a widget that is replaced by content from another process.
18 19
  ChildView({ Key key, this.child }) : super(key: key);

20
  /// A connection to the child whose content will replace this widget.
21 22
  final ChildViewConnection child;

23
  @override
24 25 26 27 28 29 30 31 32 33 34 35
  Widget build(BuildContext context) {
    return new _ChildViewWidget(
      child: child,
      scale: MediaQuery.of(context).devicePixelRatio
    );
  }
}

class _ChildViewWidget extends LeafRenderObjectWidget {
  _ChildViewWidget({
    ChildViewConnection child,
    this.scale
36 37 38
  }) : child = child, super(key: new GlobalObjectKey(child)) {
    assert(scale != null);
  }
39 40 41 42

  final ChildViewConnection child;
  final double scale;

43
  @override
44
  RenderChildView createRenderObject(BuildContext context) => new RenderChildView(child: child, scale: scale);
45

46
  @override
47
  void updateRenderObject(BuildContext context, RenderChildView renderObject) {
48 49 50 51 52
    renderObject
      ..child = child
      ..scale = scale;
  }
}