John McCutchan b017dfd995 Rationalize Dart mojo and sky package structure.
NOTE: This CL appears far larger than it actually is for two reasons:

1) Many files were moved around to use the Dart package directory structure.
2) Many .dart files had to have import paths updated.

- Organize mojo/public/dart so that it uses standard Dart package layout
- Organize mojo/dart/apptest so that it uses a standard Dart package layout
- Organize sky/sdk so that it uses a standard Dart package layout
- Create a mojo/testing package (used by unittests)
- Introduce the 'dart_pkg' gn rule which populates gen/Config/dart-pkg
- All internally vended Dart packages must have a corresponding dart_pkg rule
- It is now possible to use dependency_overrides: in pubspec.yaml to mix internal and external package dependencies (enables analyzer, editor, webstorm usage for internal developers).
- Package root for dart content handler ends with "packages/"
- Imports of mojo package uris no longer need the "public/dart"
- mojo/public/tools/dart_package.py is a clone of mojo/public/tools/gn/zip.py
- Sky tests no longer run 'deploy_sdk' script.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/1132063007
2015-05-18 14:41:39 -07:00

97 lines
2.4 KiB
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 '../editing/editable_string.dart';
import '../editing/editable_text.dart';
import '../editing/keyboard.dart';
import '../fn.dart';
import '../layout.dart';
import '../theme/colors.dart';
import '../theme/typography.dart' as typography;
import 'dart:sky' as sky;
typedef void ValueChanged(value);
class Input extends Component {
static final Style _style = new Style('''
transform: translateX(0);
margin: 8px;
padding: 8px;
border-bottom: 1px solid ${Grey[200]};
align-self: center;
height: 1.2em;
white-space: pre;
overflow: hidden;'''
);
static final Style _placeholderStyle = new Style('''
top: 8px;
left: 8px;
position: absolute;
${typography.black.caption};'''
);
static final String _focusedInlineStyle = '''
padding: 7px;
border-bottom: 2px solid ${Blue[500]};''';
ValueChanged onChanged;
String placeholder;
bool focused = false;
String _value = '';
bool _isAttachedToKeyboard = false;
EditableString _editableValue;
Input({Object key,
this.placeholder,
this.onChanged,
this.focused})
: super(key: key, stateful: true) {
_editableValue = new EditableString(text: _value,
onUpdated: _handleTextUpdated);
onDidUnmount(() {
if (_isAttachedToKeyboard)
keyboard.hide();
});
}
void _handleTextUpdated() {
scheduleBuild();
if (_value != _editableValue.text) {
_value = _editableValue.text;
if (onChanged != null)
onChanged(_value);
}
}
UINode build() {
if (focused && !_isAttachedToKeyboard) {
keyboard.show(_editableValue.stub);
_isAttachedToKeyboard = true;
}
List<UINode> children = [];
if (placeholder != null && _value.isEmpty) {
children.add(new Container(
style: _placeholderStyle,
children: [new Text(placeholder)]
));
}
children.add(new EditableText(value: _editableValue, focused: focused));
return new EventListenerNode(
new FlexContainer(
direction: FlexDirection.Column,
style: _style,
inlineStyle: focused ? _focusedInlineStyle : null,
children: children
),
onPointerDown: (sky.Event e) => keyboard.showByRequest()
);
}
}