1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 var onResize = function() {
6 var x = window.innerWidth;
7 var y = window.innerHeight;
8 var height = (x > ASPECT_RATIO * y) ? y : Math.floor(x / ASPECT_RATIO);
9 keyboard.style.height = height + 'px';
10 keyboard.style.width = Math.floor(ASPECT_RATIO * height) + 'px';
11 keyboard.style.fontSize = (height / FONT_SIZE_RATIO / ROW_LENGTH) + 'px';
15 * Recursively replace all kb-key-import elements with imported documents.
16 * @param {!Document} content Document to process.
18 function importHTML(content) {
19 var dom = content.querySelector('template').createInstance();
20 var keyImports = dom.querySelectorAll('kb-key-import');
21 if (keyImports.length != 0) {
22 keyImports.forEach(function(element) {
23 if (element.importDoc(content)) {
24 var generatedDom = importHTML(element.importDoc(content));
25 element.parentNode.replaceChild(generatedDom, element);
33 * Replace all kb-key-sequence elements with generated kb-key elements.
34 * @param {!DocumentFragment} importedContent The imported dom structure.
36 function expandHTML(importedContent) {
37 var keySequences = importedContent.querySelectorAll('kb-key-sequence');
38 if (keySequences.length != 0) {
39 keySequences.forEach(function(element) {
40 var generatedDom = element.generateDom();
41 element.parentNode.replaceChild(generatedDom, element);
47 * Flatten the keysets which represents a keyboard layout. It has two steps:
48 * 1) Replace all kb-key-import elements with imported document that associated
50 * 2) Replace all kb-key-sequence elements with generated DOM structures.
51 * @param {!Document} content Document to process.
53 function flattenKeysets(content) {
54 var importedContent = importHTML(content);
55 expandHTML(importedContent);
56 return importedContent;
59 addEventListener('resize', onResize);
61 addEventListener('load', onResize);
63 // Prevents all default actions of touch. Keyboard should use its own gesture
65 addEventListener('touchstart', function(e) { e.preventDefault() });
66 addEventListener('touchend', function(e) { e.preventDefault() });
67 addEventListener('touchmove', function(e) { e.preventDefault() });