OLD | NEW |
| (Empty) |
1 <!-- | |
2 // Copyright 2015 The Chromium Authors. All rights reserved. | |
3 // Use of this source code is governed by a BSD-style license that can be | |
4 // found in the LICENSE file. | |
5 --> | |
6 <import src="sky-element.sky" /> | |
7 | |
8 <sky-element name="sky-input" attributes="value:string"> | |
9 <template> | |
10 <style> | |
11 :host { | |
12 display: flex; | |
13 } | |
14 #control { | |
15 margin: 8px; | |
16 padding: 8px; | |
17 border-bottom: 1px solid #E7E7E7; | |
18 flex: 1; | |
19 align-self: center; | |
20 height: 1.2em; | |
21 white-space: nowrap; | |
22 overflow: hidden; | |
23 } | |
24 #control.focused { | |
25 padding-bottom: 7px; | |
26 border-bottom: 2px solid #009cf3; | |
27 } | |
28 </style> | |
29 <div id="control" contenteditable /> | |
30 </template> | |
31 <script> | |
32 import "dart:sky"; | |
33 | |
34 // TODO(abarth): Connect to the mojo:keyboard service. | |
35 | |
36 @Tagname('sky-input') | |
37 class SkyInput extends SkyElement { | |
38 Element _control; | |
39 | |
40 static String _textForValue(String value) => value == null ? '' : value; | |
41 | |
42 shadowRootReady() { | |
43 _control = shadowRoot.getElementById('control'); | |
44 _control.setChild(new Text(_textForValue(getAttribute('text')))); | |
45 _control.addEventListener('focus', _handleFocus); | |
46 _control.addEventListener('blur', _handleBlur); | |
47 _control.addEventListener('keydown', _handleKeyDown); | |
48 } | |
49 | |
50 String get text => _control == null ? null : _control.textContent; | |
51 | |
52 void textChanged(String oldValue, String newValue) { | |
53 if (_control != null) | |
54 _control.setChild(new Text(_textForValue(newValue))); | |
55 } | |
56 | |
57 void _handleKeyDown(KeyboardEvent event) { | |
58 // TODO(abarth): You can still get newlines if the user pastes them. | |
59 if (event.key == 0xD) | |
60 event.preventDefault(); | |
61 } | |
62 | |
63 void _handleFocus(_) { | |
64 if (_control) | |
65 _control.setAttribute('class', 'focused'); | |
66 // TODO(abarth): Show the keyboard. | |
67 } | |
68 | |
69 void _handleBlur(_) { | |
70 if (_control) | |
71 _control.removeAttribute('class'); | |
72 // TODO(abarth): Hide the keyboard. | |
73 } | |
74 } | |
75 | |
76 _init(script) => register(script, SkyInput); | |
77 </script> | |
78 </sky-element> | |
OLD | NEW |