paragraph.dart 2.0 KB
Newer Older
1 2 3 4 5
// 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:sky' as sky;
6
import 'box.dart';
H
Hixie 已提交
7
import 'object.dart';
8

H
Hixie 已提交
9
class RenderInline extends RenderObject {
10 11 12 13 14 15 16 17 18
  String data;

  RenderInline(this.data);
}

class RenderParagraph extends RenderBox {

  RenderParagraph({
    String text,
19
    Color color
20 21 22 23 24 25 26 27 28 29 30 31 32 33
  }) : _color = color {
    _layoutRoot.rootElement = _document.createElement('p');
    this.text = text;
  }

  final sky.Document _document = new sky.Document();
  final sky.LayoutRoot _layoutRoot = new sky.LayoutRoot();

  String get text => (_layoutRoot.rootElement.firstChild as sky.Text).data;
  void set text (String value) {
    _layoutRoot.rootElement.setChild(_document.createText(value));
    markNeedsLayout();
  }

34 35 36
  Color _color = const Color(0xFF000000);
  Color get color => _color;
  void set color (Color value) {
37 38 39 40 41 42
    if (_color != value) {
      _color = value;
      markNeedsPaint();
    }
  }

43
  Size getIntrinsicDimensions(BoxConstraints constraints) {
44 45 46 47 48 49 50 51 52 53 54
    assert(false);
    return null;
    // we don't currently support this for RenderParagraph
  }

  void performLayout() {
    _layoutRoot.maxWidth = constraints.maxWidth;
    _layoutRoot.minWidth = constraints.minWidth;
    _layoutRoot.minHeight = constraints.minHeight;
    _layoutRoot.maxHeight = constraints.maxHeight;
    _layoutRoot.layout();
55 56 57
    // rootElement.width always expands to fill, use maxContentWidth instead.
    sky.Element root = _layoutRoot.rootElement;
    size = constraints.constrain(new Size(root.maxContentWidth, root.height));
58 59
  }

H
Hixie 已提交
60
  void paint(RenderObjectDisplayList canvas) {
61 62 63 64 65
    // _layoutRoot.rootElement.style['color'] = 'rgba(' + ...color... + ')';
    _layoutRoot.paint(canvas);
  }

  // we should probably expose a way to do precise (inter-glpyh) hit testing
H
Hixie 已提交
66

67
  String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}color: ${color}\n${prefix}text: ${text}\n';
68
}