Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Unified Diff: sky/sdk/lib/editing/editable_text.dart

Issue 1216133002: Theme Input, style EditableText, restore text input cursor (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sky/sdk/lib/editing/input.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sky/sdk/lib/editing/editable_text.dart
diff --git a/sky/sdk/lib/editing/editable_text.dart b/sky/sdk/lib/editing/editable_text.dart
index d49b410a1099c4d14535a05bed2d1d3ec456eec2..4012437ea684e41a5ed2b925611dddf492ee835d 100644
--- a/sky/sdk/lib/editing/editable_text.dart
+++ b/sky/sdk/lib/editing/editable_text.dart
@@ -3,29 +3,37 @@
// found in the LICENSE file.
import 'dart:async';
+import 'dart:sky' as sky;
import '../painting/text_style.dart';
+import '../rendering/object.dart';
import '../widgets/basic.dart';
import 'editable_string.dart';
-class EditableText extends Component {
+const _kCursorBlinkPeriod = 500; // milliseconds
+const _kCursorGap = 1.0;
+const _kCursorHeightOffset = 2.0;
+const _kCursorWidth = 1.0;
- EditableText({String key, this.value, this.focused})
- : super(key: key, stateful: true);
+class EditableText extends Component {
- // static final Style _cursorStyle = new Style('''
- // width: 2px;
- // height: 1.2em;
- // vertical-align: top;
- // background-color: ${Blue[500]};'''
- // );
+ EditableText({
+ String key,
+ this.value,
+ this.focused,
+ this.style,
+ this.cursorColor}) : super(key: key, stateful: true);
EditableString value;
bool focused;
+ TextStyle style;
+ Color cursorColor;
void syncFields(EditableText source) {
value = source.value;
focused = source.focused;
+ style = source.style;
+ cursorColor = source.cursorColor;
}
Timer _cursorTimer;
@@ -40,7 +48,7 @@ class EditableText extends Component {
void _startCursorTimer() {
_showCursor = true;
_cursorTimer = new Timer.periodic(
- new Duration(milliseconds: 500), _cursorTick);
+ new Duration(milliseconds: _kCursorBlinkPeriod), _cursorTick);
}
void didUnmount() {
@@ -55,21 +63,44 @@ class EditableText extends Component {
_showCursor = false;
}
+ void _paintCursor(sky.Canvas canvas, Size size) {
+ Rect cursorRect = new Rect.fromLTWH(
+ _kCursorGap,
+ -_kCursorHeightOffset,
+ _kCursorWidth,
+ style.fontSize + 2 * _kCursorHeightOffset
+ );
+ canvas.drawRect(cursorRect, new Paint()..color = cursorColor);
abarth-chromium 2015/06/29 23:33:08 Interesting that you're drawing outside the bounds
hansmuller 2015/06/29 23:56:34 The cursor extends _kCursorHeightOffset above and
+ }
+
+ Widget _buildCursor() {
+ return new Container(
+ height: style.fontSize,
+ width: _kCursorGap + _kCursorWidth,
+ child: new CustomPaint(callback: _paintCursor)
+ );
+ }
+
Widget build() {
- if (focused && _cursorTimer == null)
+ assert(style != null);
+
+ if (focused == true && _cursorTimer == null)
abarth-chromium 2015/06/29 23:33:08 Why compare against true? That shouldn't be neede
hansmuller 2015/06/29 23:56:34 I've asserted that the focused: must be set and re
_startCursorTimer();
- else if (!focused && _cursorTimer != null)
+ else if (focused != true && _cursorTimer != null)
abarth-chromium 2015/06/29 23:33:08 ditto
hansmuller 2015/06/29 23:56:34 Done.
_stopCursorTimer();
if (!value.composing.isValid) {
- return new Text(value.text);
+ return new Text(value.text, style: style);
}
- return new StyledText(elements: [
- const TextStyle(),
+ TextStyle composingStyle = style.merge(const TextStyle(decoration: underline));
+ StyledText text = new StyledText(elements: [
+ style,
value.textBefore(value.composing),
- [const TextStyle(decoration: underline), value.textInside(value.composing)],
+ [composingStyle, value.textInside(value.composing)],
value.textAfter(value.composing)
]);
+
+ return _showCursor ? new Flex([text, _buildCursor()]) : text;
abarth-chromium 2015/06/29 23:33:08 It would be more efficient to always build the ren
hansmuller 2015/06/29 23:56:34 Done.
}
}
« no previous file with comments | « no previous file | sky/sdk/lib/editing/input.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698