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

Side by Side Diff: sky/framework/elements/sky-input.sky

Issue 1132063007: Rationalize Dart mojo and sky package structure (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 7 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 unified diff | Download patch
« no previous file with comments | « sky/framework/elements/sky-ink-splash.sky ('k') | sky/framework/elements/sky-menu-divider.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 flex-direction: row;
14 }
15 #control {
16 margin: 8px;
17 padding: 8px;
18 border-bottom: 1px solid #E7E7E7;
19 flex: 1;
20 align-self: center;
21 height: 1.2em;
22 white-space: nowrap;
23 overflow: hidden;
24 }
25 #control.focused {
26 padding-bottom: 7px;
27 border-bottom: 2px solid #009cf3;
28 }
29 </style>
30 <div id="control" contenteditable />
31 </template>
32 <script>
33 import "dart:sky";
34
35 // TODO(abarth): Connect to the mojo:keyboard service.
36
37 @Tagname('sky-input')
38 class SkyInput extends SkyElement {
39 Element _control;
40
41 static String _textForValue(String value) => value == null ? '' : value;
42
43 shadowRootReady() {
44 _control = shadowRoot.getElementById('control');
45 _control.setChild(new Text(_textForValue(getAttribute('text'))));
46 _control.addEventListener('focus', _handleFocus);
47 _control.addEventListener('blur', _handleBlur);
48 _control.addEventListener('keydown', _handleKeyDown);
49 }
50
51 String get text => _control == null ? null : _control.textContent;
52
53 void textChanged(String oldValue, String newValue) {
54 if (_control != null)
55 _control.setChild(new Text(_textForValue(newValue)));
56 }
57
58 void _handleKeyDown(KeyboardEvent event) {
59 // TODO(abarth): You can still get newlines if the user pastes them.
60 if (event.key == 0xD)
61 event.preventDefault();
62 }
63
64 void _handleFocus(_) {
65 if (_control)
66 _control.setAttribute('class', 'focused');
67 // TODO(abarth): Show the keyboard.
68 }
69
70 void _handleBlur(_) {
71 if (_control)
72 _control.removeAttribute('class');
73 // TODO(abarth): Hide the keyboard.
74 }
75 }
76
77 _init(script) => register(script, SkyInput);
78 </script>
79 </sky-element>
OLDNEW
« no previous file with comments | « sky/framework/elements/sky-ink-splash.sky ('k') | sky/framework/elements/sky-menu-divider.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698