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

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

Issue 946813005: Port Sky widgets demo to Dart (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 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/sky-element.sky ('k') | sky/framework/sky-radio.sky » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!-- 1 <!--
2 // Copyright 2015 The Chromium Authors. All rights reserved. 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 3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file. 4 // found in the LICENSE file.
5 --> 5 -->
6 <import src="/gen/mojo/services/keyboard/public/interfaces/keyboard.mojom.sky" a s="keyboard" /> 6 <import src="sky-element.sky" />
7 <import src="shell.sky" as="shell" />
8 <import src="sky-element/sky-element.sky" as="SkyElement" />
9 7
10 <sky-element name="sky-input" attributes="value:string"> 8 <sky-element name="sky-input" attributes="value:string">
11 <template> 9 <template>
12 <style> 10 <style>
13 :host { 11 :host {
14 display: flex; 12 display: flex;
15 border: 1px solid blue; 13 border: 1px solid blue;
16 margin: 5px; 14 margin: 5px;
17 padding: 4px; 15 padding: 4px;
18 } 16 }
19 #control { 17 #control {
20 flex: 1; 18 flex: 1;
21 align-self: center; 19 align-self: center;
22 height: 1.2em; 20 height: 1.2em;
23 white-space: nowrap; 21 white-space: nowrap;
24 overflow: hidden; 22 overflow: hidden;
25 } 23 }
26 </style> 24 </style>
27 <div id="control" contenteditable 25 <div id="control" contenteditable />
28 on-focus="handleFocus"
29 on-blur="handleBlur"
30 on-keydown="handleKeyDown">{{ value }}</div>
31 </template> 26 </template>
32 <script> 27 <script>
33 var keyboard = shell.connectToService("mojo:keyboard", keyboard.Keyboard); 28 import "dart:sky";
34 module.exports = class extends SkyElement { 29
30 // TODO(abarth): Connect to the mojo:keyboard service.
31
32 @Tagname('sky-input')
33 class SkyInput extends SkyElement {
34 Element _control;
35
36 static String _textForValue(String value) => value == null ? '' : value;
37
35 shadowRootReady() { 38 shadowRootReady() {
36 var control = this.shadowRoot.getElementById('control'); 39 _control = shadowRoot.getElementById('control');
37 var text = control.firstChild; 40 _control.setChild(new Text(_textForValue(getAttribute('text'))));
41 _control.addEventListener('focus', _handleFocus);
42 _control.addEventListener('blur', _handleBlur);
43 _control.addEventListener('keydown', _handleKeyDown);
44 }
38 45
39 var observer = new MutationObserver(function() { 46 String get text => _control == null ? null : _control.textContent;
40 // contenteditable might remove the text node, but we need to keep it
41 // since that's where the data binding is connected to.
42 if (!text.parentNode)
43 control.appendChild(text);
44 if (this.value == control.textContent)
45 return;
46 this.value = control.textContent;
47 this.dispatchEvent(new CustomEvent('change', {
48 bubbles: true,
49 }));
50 }.bind(this));
51 47
52 observer.observe(control, { 48 void textChanged(String oldValue, String newValue) {
53 subtree: true, 49 if (_control != null)
54 characterData: true, 50 _control.setChild(new Text(_textForValue(newValue)));
55 childList: true,
56 });
57 } 51 }
58 handleKeyDown(event) { 52
53 void _handleKeyDown(KeyboardEvent event) {
59 // TODO(abarth): You can still get newlines if the user pastes them. 54 // TODO(abarth): You can still get newlines if the user pastes them.
60 if (event.key == 0xD) 55 if (event.key == 0xD)
61 event.preventDefault(); 56 event.preventDefault();
62 } 57 }
63 handleFocus(event) { 58
64 keyboard.show(); 59 void _handleFocus(_) {
60 // TODO(abarth): Show the keyboard.
65 } 61 }
66 handleBlur(event) { 62
67 keyboard.hide(); 63 void _handleBlur(_) {
64 // TODO(abarth): Hide the keyboard.
68 } 65 }
69 }.register(); 66 }
67
68 _init(script) => register(script, SkyInput);
70 </script> 69 </script>
71 </sky-element> 70 </sky-element>
OLDNEW
« no previous file with comments | « sky/framework/sky-element.sky ('k') | sky/framework/sky-radio.sky » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698