B2G/gaia/apps/keyboard/js/keyboard.js
// Show alternatives for the HTML node key
Show alternatives for the HTML node key
Show alternatives for the HTML node key
function showAlternatives(key) {
  var alternatives, altMap, value, keyObj, uppercaseValue, needsCapitalization;
  var r = key ? key.dataset.row : -1, c = key ? key.dataset.column : -1;
  if (r < 0 || c < 0 || r === undefined || c === undefined)
    return;
  keyObj = currentLayout.keys[r][c];
  if (keyObj.keyCode === SWITCH_KEYBOARD) {
    showKeyboardLayoutMenu(key);
    return;
  }
  altMap = currentLayout.alt || {};
  value = keyObj.value;
  alternatives = altMap[value] || '';
  if (isUpperCase || isUpperCaseLocked) {
    uppercaseValue = getUpperCaseValue(keyObj);
    if (altMap[uppercaseValue]) {
      alternatives = altMap[uppercaseValue];
    }
    else {
      needsCapitalization = true;
    }
  }
  if (alternatives.indexOf(' ') != -1) {
    alternatives = alternatives.split(' ');
    if (alternatives.length === 2 && alternatives[1] === '')
      alternatives.pop();
    if (needsCapitalization) {
      for (var i = 0; i < alternatives.length; i++) {
        if (isUpperCaseLocked) {
          alternatives[i] = alternatives[i].toLocaleUpperCase();
        }
        else {
          alternatives[i] = alternatives[i][0].toLocaleUpperCase() +
            alternatives[i].substring(1);
        }
      }
    }
  } else {
    if (needsCapitalization) 
      alternatives = alternatives.toLocaleUpperCase();
    alternatives = alternatives.split('');
  }
  if (!alternatives.length)
    return;
  var top = getWindowTop(key);
  var bottom = getWindowTop(key) + key.scrollHeight;
  IMERender.showAlternativesCharMenu(key, alternatives);
  isShowingAlternativesMenu = true;
  menuLockedArea = {
    top: top,
    bottom: bottom,
    left: getWindowLeft(IMERender.menu),
    right: getWindowLeft(IMERender.menu) + IMERender.menu.scrollWidth
  };
  menuLockedArea.width = menuLockedArea.right - menuLockedArea.left;
  menuLockedArea.ratio =
    menuLockedArea.width / IMERender.menu.children.length;
}
function showAlternatives ( key ) { var alternatives , altMap , value , keyObj , uppercaseValue , needsCapitalization ; var r = key ? key . dataset . row : - 1 , c = key ? key . dataset . column : - 1 ; if ( r < 0 || c < 0 || r === undefined || c === undefined ) return ; keyObj = currentLayout . keys [ r ] [ c ] ; if ( keyObj . keyCode === SWITCH_KEYBOARD ) { showKeyboardLayoutMenu ( key ) ; return ; } altMap = currentLayout . alt || { } ; value = keyObj . value ; alternatives = altMap [ value ] || '' ; if ( isUpperCase || isUpperCaseLocked ) { uppercaseValue = getUpperCaseValue ( keyObj ) ; if ( altMap [ uppercaseValue ] ) { alternatives = altMap [ uppercaseValue ] ; } else { needsCapitalization = true ; } } if ( alternatives . indexOf ( ' ' ) != - 1 ) { alternatives = alternatives . split ( ' ' ) ; if ( alternatives . length === 2 && alternatives [ 1 ] === '' ) alternatives . pop ( ) ; if ( needsCapitalization ) { for ( var i = 0 ; i < alternatives . length ; i ++ ) { if ( isUpperCaseLocked ) { alternatives [ i ] = alternatives [ i ] . toLocaleUpperCase ( ) ; } else { alternatives [ i ] = alternatives [ i ] [ 0 ] . toLocaleUpperCase ( ) + alternatives [ i ] . substring ( 1 ) ; } } } } else { if ( needsCapitalization ) alternatives = alternatives . toLocaleUpperCase ( ) ; alternatives = alternatives . split ( '' ) ; } if ( ! alternatives . length ) return ; var top = getWindowTop ( key ) ; var bottom = getWindowTop ( key ) + key . scrollHeight ; IMERender . showAlternativesCharMenu ( key , alternatives ) ; isShowingAlternativesMenu = true ; menuLockedArea = { top : top , bottom : bottom , left : getWindowLeft ( IMERender . menu ) , right : getWindowLeft ( IMERender . menu ) + IMERender . menu . scrollWidth } ; menuLockedArea . width = menuLockedArea . right - menuLockedArea . left ; menuLockedArea . ratio = menuLockedArea . width / IMERender . menu . children . length ; }
Show alternatives for the HTML node key
Show alternatives for the HTML node key
// Get the key object from layout // Handle languages alternatives // Handle key alternatives // If in uppercase, look for uppercase alternatives. If we don't find any // then set a flag so we can manually capitalize the alternatives below. // Split alternatives // If the alternatives are delimited by spaces, it means that one or more // of them is more than a single character long. // If there is just a single multi-character alternative, it will have // trailing whitespace which we have to discard here. // Caps lock is on, so capitalize all the characters // We're in uppercase, but not locked, so just capitalize 1st char. // No spaces, so all of the alternatives are single characters // Capitalize them all at once before splitting // Locked limits // TODO: look for [LOCKED_AREA] // Locked limits // TODO: look for [LOCKED_AREA]