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. 4 5var 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'; 12}; 13 14/** 15 * Recursively replace all kb-key-import elements with imported documents. 16 * @param {!Document} content Document to process. 17 */ 18function importHTML(content) { 19 var dom = content.querySelector('template').createInstance(); 20 var keyImports = dom.querySelectorAll('kb-key-import'); 21 if (keyImports.length != 0) { 22 keyImports.array().forEach(function(element) { 23 if (element.importDoc(content)) { 24 var generatedDom = importHTML(element.importDoc(content)); 25 element.parentNode.replaceChild(generatedDom, element); 26 } 27 }); 28 } 29 return dom; 30} 31 32/** 33 * Replace all kb-key-sequence elements with generated kb-key elements. 34 * @param {!DocumentFragment} importedContent The imported dom structure. 35 */ 36function expandHTML(importedContent) { 37 var keySequences = importedContent.querySelectorAll('kb-key-sequence'); 38 if (keySequences.length != 0) { 39 keySequences.array().forEach(function(element) { 40 var generatedDom = element.generateDom(); 41 element.parentNode.replaceChild(generatedDom, element); 42 }); 43 } 44} 45 46/** 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 49 * with linkid. 50 * 2) Replace all kb-key-sequence elements with generated DOM structures. 51 * @param {!Document} content Document to process. 52 */ 53function flattenKeysets(content) { 54 var importedContent = importHTML(content); 55 expandHTML(importedContent); 56 return importedContent; 57} 58 59addEventListener('resize', onResize); 60 61addEventListener('load', onResize); 62 63// Prevents all default actions of touch. Keyboard should use its own gesture 64// recognizer. 65addEventListener('touchstart', function(e) { e.preventDefault() }); 66addEventListener('touchend', function(e) { e.preventDefault() }); 67addEventListener('touchmove', function(e) { e.preventDefault() }); 68