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

Side by Side Diff: ui/keyboard/resources/elements/kb-keyboard.html

Issue 140123002: Work around for content select not supporting touch events on it's children. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 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
OLDNEW
1 <!-- 1 <!--
2 -- Copyright 2013 The Chromium Authors. All rights reserved. 2 -- Copyright 2013 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 6
7 <polymer-element name="kb-keyboard" on-key-over="{{keyOver}}" 7 <polymer-element name="kb-keyboard" on-key-over="{{keyOver}}"
8 on-key-up="{{keyUp}}" on-key-down="{{keyDown}}" 8 on-key-up="{{keyUp}}" on-key-down="{{keyDown}}"
9 on-key-longpress="{{keyLongpress}}" on-pointerup="{{up}}" 9 on-key-longpress="{{keyLongpress}}" on-pointerup="{{up}}"
10 on-pointerdown="{{down}}" on-pointerout="{{out}}" 10 on-pointerdown="{{down}}" on-pointerout="{{out}}"
11 on-enable-sel="{{enableSel}}" on-enable-dbl="{{enableDbl}}" 11 on-enable-sel="{{enableSel}}" on-enable-dbl="{{enableDbl}}"
12 on-key-out="{{keyOut}}" on-show-options="{{showOptions}}" 12 on-key-out="{{keyOut}}" on-show-options="{{showOptions}}"
13 on-set-layout="{{setLayout}}" on-type-key="{{type}}" 13 on-set-layout="{{setLayout}}" on-type-key="{{type}}"
14 attributes="keyset layout inputType inputTypeToLayoutMap"> 14 attributes="keyset layout inputType inputTypeToLayoutMap">
15 <template> 15 <template>
16 <style> 16 <style>
17 @host { 17 @host {
18 * { 18 * {
19 position: relative; 19 position: relative;
20 } 20 }
21 } 21 }
22 </style> 22 </style>
23 <!-- The ID for a keyset follows the naming convention of combining the 23 <!-- The ID for a keyset follows the naming convention of combining the
24 -- layout name with a base keyset name. This convention is used to 24 -- layout name with a base keyset name. This convention is used to
25 -- allow multiple layouts to be loaded (enablign fast switching) while 25 -- allow multiple layouts to be loaded (enablign fast switching) while
26 -- allowing the shift and spacebar keys to be common across multiple 26 -- allowing the shift and spacebar keys to be common across multiple
27 -- keyboard layouts. 27 -- keyboard layouts.
28 --> 28 -->
29 <content id="content" select="#{{layout}}-{{keyset}}"></content> 29 <content id="content"></content>
30 <kb-keyboard-overlay id="overlay" hidden></kb-keyboard-overlay> 30 <kb-keyboard-overlay id="overlay" hidden></kb-keyboard-overlay>
31 <kb-key-codes id="keyCodeMetadata"></kb-key-codes> 31 <kb-key-codes id="keyCodeMetadata"></kb-key-codes>
32 </template> 32 </template>
33 <script> 33 <script>
34 /** 34 /**
35 * The repeat delay in milliseconds before a key starts repeating. Use the 35 * The repeat delay in milliseconds before a key starts repeating. Use the
36 * same rate as Chromebook. 36 * same rate as Chromebook.
37 * (See chrome/browser/chromeos/language_preferences.cc) 37 * (See chrome/browser/chromeos/language_preferences.cc)
38 * @const 38 * @const
39 * @type {number} 39 * @type {number}
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 } 330 }
331 var toKeyset = detail.toKeyset; 331 var toKeyset = detail.toKeyset;
332 if (toKeyset) { 332 if (toKeyset) {
333 this.keyset = toKeyset; 333 this.keyset = toKeyset;
334 this.activeKeyset.nextKeyset = detail.nextKeyset; 334 this.activeKeyset.nextKeyset = detail.nextKeyset;
335 return true; 335 return true;
336 } 336 }
337 return false; 337 return false;
338 }, 338 },
339 339
340 keysetChanged: function(old) {
341 // TODO(rsadam): Remove once content select support touch events on
342 // children.
kevers 2014/01/15 23:33:07 Don't think it's necessary to revert to old method
rsadam 2014/01/17 15:43:53 Done.
343 if (old) {
344 var keyset = this.querySelector("#" + this.layout + "-" + old);
345 if (keyset)
346 keyset.hide();
347 }
348 var keyset = this.activeKeyset;
349 // Show the keyset if it has been initialized.
350 if (keyset)
351 keyset.show();
352 },
353
340 ready: function() { 354 ready: function() {
341 this.voiceInput_ = new VoiceInput(this); 355 this.voiceInput_ = new VoiceInput(this);
342 this.swipeHandler = this.move.bind(this); 356 this.swipeHandler = this.move.bind(this);
343 }, 357 },
344 358
345 /** 359 /**
346 * Registers a callback for state change events. Lazy initializes a 360 * Registers a callback for state change events. Lazy initializes a
347 * mutation observer used to detect when the keyset selection is changed. 361 * mutation observer used to detect when the keyset selection is changed.
348 * @param{!Function} callback Callback function to register. 362 * @param{!Function} callback Callback function to register.
349 */ 363 */
350 addKeysetChangedObserver: function(callback) { 364 addKeysetChangedObserver: function(callback) {
365 // TODO(rsadam): Uncomment this when we switch back to keysets being
366 // displayed by content-select.
kevers 2014/01/15 23:33:07 Nuke it. Content select offers no real advantage
rsadam 2014/01/17 15:43:53 Done.
367 /*
351 if (!this.keysetChangedObserver) { 368 if (!this.keysetChangedObserver) {
352 var target = this.$.content; 369 var target = this.$.content;
353 var self = this; 370 var self = this;
354 var observer = new MutationObserver(function(mutations) { 371 var observer = new MutationObserver(function(mutations) {
355 mutations.forEach(function(m) { 372 mutations.forEach(function(m) {
356 if (m.type == 'attributes' && m.attributeName == 'select') { 373 if (m.type == 'attributes' && m.attributeName == 'select') {
357 var value = m.target.getAttribute('select'); 374 var value = m.target.getAttribute('select');
358 self.fire('stateChange', { 375 self.fire('stateChange', {
359 state: 'keysetChanged', 376 state: 'keysetChanged',
360 value: value 377 value: value
361 }); 378 });
362 } 379 }
363 }); 380 });
364 }); 381 });
365 382
366 observer.observe(target, { 383 observer.observe(target, {
367 attributes: true, 384 attributes: true,
368 childList: true, 385 childList: true,
369 subtree: true 386 subtree: true
370 }); 387 });
371 this.keysetChangedObserver = observer; 388 this.keysetChangedObserver = observer;
372
373 } 389 }
390 */
374 this.addEventListener('stateChange', callback); 391 this.addEventListener('stateChange', callback);
375 }, 392 },
376 393
377 /** 394 /**
378 * Called when the type of focused input box changes. If a keyboard layout 395 * Called when the type of focused input box changes. If a keyboard layout
379 * is defined for the current input type, that layout will be loaded. 396 * is defined for the current input type, that layout will be loaded.
380 * Otherwise, the keyboard layout for 'text' type will be loaded. 397 * Otherwise, the keyboard layout for 'text' type will be loaded.
381 */ 398 */
382 inputTypeChanged: function() { 399 inputTypeChanged: function() {
383 // TODO(bshe): Toggle visibility of some keys in a keyboard layout 400 // TODO(bshe): Toggle visibility of some keys in a keyboard layout
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after
795 * @param {{layout: string}} details Details of the event, which contains 812 * @param {{layout: string}} details Details of the event, which contains
796 * the name of the layout to activate. 813 * the name of the layout to activate.
797 */ 814 */
798 setLayout: function(event, details) { 815 setLayout: function(event, details) {
799 this.layout = details.layout; 816 this.layout = details.layout;
800 }, 817 },
801 818
802 /** 819 /**
803 * Handles a change in the keyboard layout. Auto-selects the default 820 * Handles a change in the keyboard layout. Auto-selects the default
804 * keyset for the new layout. 821 * keyset for the new layout.
822 * @param {string | null} oldLayout The previous layout.
kevers 2014/01/15 23:33:07 ?string
rsadam 2014/01/17 15:43:53 No longer needed
805 */ 823 */
806 layoutChanged: function() { 824 layoutChanged: function(oldLayout) {
825 if (oldLayout){
826 var keyset = this.querySelector("#" + oldLayout + "-" + this.keyset);
827 if(keyset)
828 keyset.classList.remove("activeKeyset");
kevers 2014/01/15 23:33:07 keyset.hide() or alternatively why not leave the o
rsadam 2014/01/17 15:43:53 Done.
829 }
807 if (!this.selectDefaultKeyset()) { 830 if (!this.selectDefaultKeyset()) {
808 this.fire('stateChange', {state: 'loadingKeyset'}); 831 this.fire('stateChange', {state: 'loadingKeyset'});
809 832
810 // Keyset selection fails if the keysets have not been loaded yet. 833 // Keyset selection fails if the keysets have not been loaded yet.
811 var keysets = document.querySelector('#' + this.layout); 834 var keysets = document.querySelector('#' + this.layout);
812 if (keysets && keysets.content) { 835 if (keysets && keysets.content) {
813 var content = flattenKeysets(keysets.content); 836 var content = flattenKeysets(keysets.content);
814 this.appendChild(content); 837 this.appendChild(content);
815 this.selectDefaultKeyset(); 838 this.selectDefaultKeyset();
816 } else { 839 } else {
817 // Add link for the keysets if missing from the document. Force 840 // Add link for the keysets if missing from the document. Force
818 // a layout change after resolving the import of the link. 841 // a layout change after resolving the import of the link.
819 var query = 'link[id=' + this.layout + ']'; 842 var query = 'link[id=' + this.layout + ']';
820 if (!document.querySelector(query)) { 843 if (!document.querySelector(query)) {
821 // Layout has not beeen loaded yet. 844 // Layout has not beeen loaded yet.
822 var link = document.createElement('link'); 845 var link = document.createElement('link');
823 link.id = this.layout; 846 link.id = this.layout;
824 link.setAttribute('rel', 'import'); 847 link.setAttribute('rel', 'import');
825 link.setAttribute('href', 'layouts/' + this.layout + '.html'); 848 link.setAttribute('href', 'layouts/' + this.layout + '.html');
826 document.head.appendChild(link); 849 document.head.appendChild(link);
827 850
828 // Load content for the new link element. 851 // Load content for the new link element.
829 var self = this; 852 var self = this;
830 HTMLImports.importer.load(document, function() { 853 HTMLImports.importer.load(document, function() {
831 HTMLImports.parser.parseLink(link); 854 HTMLImports.parser.parseLink(link);
832 self.layoutChanged(); 855 self.layoutChanged();
833 }); 856 });
834 } 857 }
835 } 858 }
859 // New keyset has already been loaded, can show immediately.
860 // TODO(rsadam): Remove once content select supports touch on children.
861 } else {
862 this.activeKeyset.show();
836 } 863 }
837 }, 864 },
838 865
839 /** 866 /**
840 * Notifies the modifier keys that a non-control key was typed. This 867 * Notifies the modifier keys that a non-control key was typed. This
841 * lets them reset sticky behaviour. A non-control key is defined as 868 * lets them reset sticky behaviour. A non-control key is defined as
842 * any key that is not Control, Alt, or Shift. 869 * any key that is not Control, Alt, or Shift.
843 */ 870 */
844 onNonControlKeyTyped: function() { 871 onNonControlKeyTyped: function() {
845 if (this.shift) 872 if (this.shift)
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
890 917
891 /** 918 /**
892 * The keyboard is ready for input once the target keyset appears 919 * The keyboard is ready for input once the target keyset appears
893 * in the distributed nodes for the keyboard. 920 * in the distributed nodes for the keyboard.
894 * @return {boolean} Indicates if the keyboard is ready for input. 921 * @return {boolean} Indicates if the keyboard is ready for input.
895 */ 922 */
896 isReady: function() { 923 isReady: function() {
897 var keyset = this.activeKeyset; 924 var keyset = this.activeKeyset;
898 if (!keyset) 925 if (!keyset)
899 return false; 926 return false;
900 var content = this.$.content.getDistributedNodes()[0]; 927 var nodes = this.$.content.getDistributedNodes();
kevers 2014/01/15 23:33:07 If we simply append children to the keyboard, I do
rsadam 2014/01/17 15:43:53 As we discussed offline, Polymer replaces appendCh
901 return content == keyset; 928 for (var i = 0; i < nodes.length; i++) {
929 if (nodes[i].id && nodes[i].id == keyset.id)
930 return true;
931 }
932 return false;
902 }, 933 },
903 934
904 /** 935 /**
905 * Generates fabricated key events to simulate typing on a 936 * Generates fabricated key events to simulate typing on a
906 * physical keyboard. 937 * physical keyboard.
907 * @param {Object} detail Attributes of the key being typed. 938 * @param {Object} detail Attributes of the key being typed.
908 * @return {boolean} Whether the key type succeeded. 939 * @return {boolean} Whether the key type succeeded.
909 */ 940 */
910 keyTyped: function(detail) { 941 keyTyped: function(detail) {
911 var builder = this.$.keyCodeMetadata; 942 var builder = this.$.keyCodeMetadata;
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
970 } 1001 }
971 } 1002 }
972 } 1003 }
973 if (keysetsLoaded) 1004 if (keysetsLoaded)
974 console.error('No default keyset found for ' + this.layout); 1005 console.error('No default keyset found for ' + this.layout);
975 return false; 1006 return false;
976 } 1007 }
977 }); 1008 });
978 </script> 1009 </script>
979 </polymer-element> 1010 </polymer-element>
OLDNEW
« no previous file with comments | « no previous file | ui/keyboard/resources/elements/kb-keyset.html » ('j') | ui/keyboard/resources/elements/kb-keyset.html » ('J')

Powered by Google App Engine
This is Rietveld 408576698