Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 | 6 |
| 7 import '../painting/text_style.dart'; | |
| 7 import '../widgets/basic.dart'; | 8 import '../widgets/basic.dart'; |
| 8 import 'editable_string.dart'; | 9 import 'editable_string.dart'; |
| 9 | 10 |
| 10 class EditableText extends Component { | 11 class EditableText extends Component { |
| 11 | 12 |
| 12 EditableText({String key, this.value, this.focused}) | 13 EditableText({String key, this.value, this.focused}) |
| 13 : super(key: key, stateful: true); | 14 : super(key: key, stateful: true); |
| 14 | 15 |
| 15 // static final Style _cursorStyle = new Style(''' | 16 // static final Style _cursorStyle = new Style(''' |
| 16 // width: 2px; | 17 // width: 2px; |
| 17 // height: 1.2em; | 18 // height: 1.2em; |
| 18 // vertical-align: top; | 19 // vertical-align: top; |
| 19 // background-color: ${Blue[500]};''' | 20 // background-color: ${Blue[500]};''' |
| 20 // ); | 21 // ); |
| 21 | 22 |
| 22 // static final Style _composingStyle = new Style(''' | 23 static const TextStyle _plainStyle = const TextStyle(); |
|
Hixie
2015/06/19 22:39:44
Can't this be null?
hansmuller
2015/06/19 23:32:11
Not at the moment (StyledText doesn't support that
| |
| 23 // text-decoration: underline;''' | 24 static const TextStyle _composingStyle = const TextStyle(decoration: underline ); |
|
abarth-chromium
2015/06/19 22:41:38
I would just inline these in the one place they're
hansmuller
2015/06/19 23:32:11
Done.
| |
| 24 // ); | |
| 25 | 25 |
| 26 EditableString value; | 26 EditableString value; |
| 27 bool focused; | 27 bool focused; |
| 28 | 28 |
| 29 void syncFields(EditableText source) { | 29 void syncFields(EditableText source) { |
| 30 value = source.value; | 30 value = source.value; |
| 31 focused = source.focused; | 31 focused = source.focused; |
| 32 } | 32 } |
| 33 | 33 |
| 34 Timer _cursorTimer; | 34 Timer _cursorTimer; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 57 _cursorTimer = null; | 57 _cursorTimer = null; |
| 58 _showCursor = false; | 58 _showCursor = false; |
| 59 } | 59 } |
| 60 | 60 |
| 61 Widget build() { | 61 Widget build() { |
| 62 if (focused && _cursorTimer == null) | 62 if (focused && _cursorTimer == null) |
| 63 _startCursorTimer(); | 63 _startCursorTimer(); |
| 64 else if (!focused && _cursorTimer != null) | 64 else if (!focused && _cursorTimer != null) |
| 65 _stopCursorTimer(); | 65 _stopCursorTimer(); |
| 66 | 66 |
| 67 //List<Widget> children = new List<Widget>(); | |
| 68 String hack = ""; | |
| 69 | |
| 70 if (!value.composing.isValid) { | 67 if (!value.composing.isValid) { |
| 71 // children.add(new TextFragment(value.text)); | 68 return new Text(value.text); |
| 72 hack += value.text; | |
| 73 } else { | |
| 74 hack += value.textBefore(value.composing); | |
| 75 hack += value.textInside(value.composing); | |
| 76 hack += value.textAfter(value.composing); | |
| 77 // if (!composing.isEmpty) { | |
| 78 // children.add(new TextFragment( | |
| 79 // composing, | |
| 80 // key: 'composing', | |
| 81 // style: _composingStyle | |
| 82 // )); | |
| 83 // } | |
| 84 | |
| 85 // String afterComposing = value.textAfter(value.composing); | |
| 86 // if (!afterComposing.isEmpty) | |
| 87 // children.add(new TextFragment(afterComposing)); | |
| 88 } | 69 } |
| 89 | 70 |
| 90 // if (_showCursor) | 71 return new StyledText(elements: [ |
| 91 // children.add(new Container( | 72 _plainStyle, |
| 92 // key: 'cursor', | 73 value.textBefore(value.composing), |
| 93 // // style: _cursorStyle | 74 [_composingStyle, value.textInside(value.composing)], |
| 94 // )); | 75 value.textAfter(value.composing) |
| 95 | 76 ]); |
| 96 return new Text(hack); | |
| 97 } | 77 } |
| 98 } | 78 } |
| OLD | NEW |