mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
This CL updates sky-box, sky-button, sky-checkbox, sky-input, and sky-radio to work in Dart. We don't have a data binding system yet, so there's a bit more plumbing in the code. This CL adds support for sky-element@attributes, which lets you specify which attributes your element supports. We use this information to synthesize getters and setters for those attributes and to dispatch to mumbleChanged methods when the attributes change. I've also wrapped the widgets demo itself in a sky-scrollable so the whole thing scrolls. R=eseidel@chromium.org Review URL: https://codereview.chromium.org/946813005
71 lines
1.7 KiB
Plaintext
71 lines
1.7 KiB
Plaintext
<!--
|
|
// 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 src="sky-element.sky" />
|
|
|
|
<sky-element name="sky-input" attributes="value:string">
|
|
<template>
|
|
<style>
|
|
:host {
|
|
display: flex;
|
|
border: 1px solid blue;
|
|
margin: 5px;
|
|
padding: 4px;
|
|
}
|
|
#control {
|
|
flex: 1;
|
|
align-self: center;
|
|
height: 1.2em;
|
|
white-space: nowrap;
|
|
overflow: hidden;
|
|
}
|
|
</style>
|
|
<div id="control" contenteditable />
|
|
</template>
|
|
<script>
|
|
import "dart:sky";
|
|
|
|
// TODO(abarth): Connect to the mojo:keyboard service.
|
|
|
|
@Tagname('sky-input')
|
|
class SkyInput extends SkyElement {
|
|
Element _control;
|
|
|
|
static String _textForValue(String value) => value == null ? '' : value;
|
|
|
|
shadowRootReady() {
|
|
_control = shadowRoot.getElementById('control');
|
|
_control.setChild(new Text(_textForValue(getAttribute('text'))));
|
|
_control.addEventListener('focus', _handleFocus);
|
|
_control.addEventListener('blur', _handleBlur);
|
|
_control.addEventListener('keydown', _handleKeyDown);
|
|
}
|
|
|
|
String get text => _control == null ? null : _control.textContent;
|
|
|
|
void textChanged(String oldValue, String newValue) {
|
|
if (_control != null)
|
|
_control.setChild(new Text(_textForValue(newValue)));
|
|
}
|
|
|
|
void _handleKeyDown(KeyboardEvent event) {
|
|
// TODO(abarth): You can still get newlines if the user pastes them.
|
|
if (event.key == 0xD)
|
|
event.preventDefault();
|
|
}
|
|
|
|
void _handleFocus(_) {
|
|
// TODO(abarth): Show the keyboard.
|
|
}
|
|
|
|
void _handleBlur(_) {
|
|
// TODO(abarth): Hide the keyboard.
|
|
}
|
|
}
|
|
|
|
_init(script) => register(script, SkyInput);
|
|
</script>
|
|
</sky-element>
|