Commit 9d9b00dc authored by kevers's avatar kevers Committed by Commit bot

Add third_party/google-input-tools: Take 2

BUG=401729

Abandoning Issue 451873002 in favor of directly adding google-input-tools to src/third_party.  A subset of the open sourced library depends on third_party code where the licensing is unclear.  The required pieces strictly support Apache 2.0 licensing.

Review URL: https://codereview.chromium.org/674153004

Cr-Commit-Position: refs/heads/master@{#301361}
parent 48e356db
This diff is collapsed.
# Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
# limitations under the License.
# See the License for the specific language governing permissions and
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# distributed under the License is distributed on an "AS-IS" BASIS,
# Unless required by applicable law or agreed to in writing, software
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# You may obtain a copy of the License at
# you may not use this file except in compliance with the License.
# Licensed under the Apache License, Version 2.0 (the "License");
#
SHELL:=/bin/bash
BUILD_DIR:=src/chrome/os/inputview/build
all: inputview.js
inputview.js: clean
@make -C $(BUILD_DIR)
@cp $(BUILD_DIR)/inputview.js .
clean:
$(RM) $(BUILD_DIR)/inputview.js
bshe@chromium.org
kevers@chromium.org
rsadam@chromium.org
shuchen@chromium.org
Name: Google Input Tools
Short Name: google_input_tools
URL: https://github.com/googlei18n/google-input-tools.git
Version: 1.0.4.0
Revision: @b99e802e53613e07f24a779695c1c6f3bd2f864a
License: Apache 2.0
License File: LICENSE
Security Critical: yes
Description:
This directory contains source for the google-input-tools project, which
provides multi-lingual input support. In particular, google-input-tools is
used in ChromeOS to provide a fallback virtual keyboard for IMEs that are not
VK-aware.
To update to a newer version of google-input-tools, run the following script:
update.py --input=_path_to_google_input_tools_ --lib=_path_to_closure_lib_
Local Modifications:
Only includes the portion of google-input-tools required to build an inputview-
based virtual keyboard.
\ No newline at end of file
// Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
// limitations under the License.
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// distributed under the License is distributed on an "AS-IS" BASIS,
// Unless required by applicable law or agreed to in writing, software
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// You may obtain a copy of the License at
// you may not use this file except in compliance with the License.
// Licensed under the Apache License, Version 2.0 (the "License");
//
goog.provide('i18n.input.chrome.DataSource');
goog.require('goog.events');
goog.require('goog.events.Event');
goog.require('goog.events.EventTarget');
goog.require('goog.functions');
/**
* The data source.
*
* @param {number} numOfCanddiate The number of canddiate to fetch.
* @param {function(string, !Array.<!Object>)} callback .
* @constructor
* @extends {goog.events.EventTarget}
*/
i18n.input.chrome.DataSource = function(numOfCanddiate, callback) {
goog.base(this);
/**
* The number of candidates to fetch.
*
* @type {number}
*/
this.numOfCandidate = numOfCanddiate;
/** @protected {function(string, !Array.<!Object>)} */
this.callback = callback;
};
goog.inherits(i18n.input.chrome.DataSource, goog.events.EventTarget);
/** @type {boolean} */
i18n.input.chrome.DataSource.prototype.ready = false;
/**
* The correction level.
*
* @protected {number}
*/
i18n.input.chrome.DataSource.prototype.correctionLevel = 0;
/**
* The language code.
*
* @type {string}
* @protected
*/
i18n.input.chrome.DataSource.prototype.language;
/**
* Sets the langauge code.
*
* @param {string} language The language code.
*/
i18n.input.chrome.DataSource.prototype.setLanguage = function(
language) {
this.language = language;
};
/**
* True if the datasource is ready.
*
* @return {boolean} .
*/
i18n.input.chrome.DataSource.prototype.isReady = function() {
return this.ready;
};
/**
* Creates the common payload for completion or prediction request.
*
* @return {!Object} The payload.
* @protected
*/
i18n.input.chrome.DataSource.prototype.createCommonPayload =
function() {
return {
'itc': this.getInputToolCode(),
'num': this.numOfCandidate
};
};
/**
* Gets the input tool code.
*
* @return {string} .
*/
i18n.input.chrome.DataSource.prototype.getInputToolCode = function() {
return this.language + '-t-i0-und';
};
/**
* Sends completion request.
*
* @param {string} query The query .
* @param {string} context The context .
* @param {!Object=} opt_spatialData .
*/
i18n.input.chrome.DataSource.prototype.sendCompletionRequest =
goog.functions.NULL;
/**
* Sends prediciton request.
*
* @param {string} context The context.
*/
i18n.input.chrome.DataSource.prototype.sendPredictionRequest =
goog.functions.NULL;
/**
* Sets the correction level.
*
* @param {number} level .
*/
i18n.input.chrome.DataSource.prototype.setCorrectionLevel = function(level) {
this.correctionLevel = level;
};
/**
* Clears the data source.
*/
i18n.input.chrome.DataSource.prototype.clear = goog.functions.NULL;
/**
* The event type.
*
* @enum {string}
*/
i18n.input.chrome.DataSource.EventType = {
CANDIDATES_BACK: goog.events.getUniqueId('cb'),
READY: goog.events.getUniqueId('r')
};
/**
* The candidates is fetched back.
*
* @param {string} source The source.
* @param {!Array.<!Object>} candidates The candidates.
* @constructor
* @extends {goog.events.Event}
*/
i18n.input.chrome.DataSource.CandidatesBackEvent =
function(source, candidates) {
goog.base(this, i18n.input.chrome.DataSource.EventType.CANDIDATES_BACK);
/**
* The source.
*
* @type {string}
*/
this.source = source;
/**
* The candidate list.
*
* @type {!Array.<!Object>}
*/
this.candidates = candidates;
};
goog.inherits(i18n.input.chrome.DataSource.CandidatesBackEvent,
goog.events.Event);
// Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
// limitations under the License.
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// distributed under the License is distributed on an "AS-IS" BASIS,
// Unless required by applicable law or agreed to in writing, software
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// You may obtain a copy of the License at
// you may not use this file except in compliance with the License.
// Licensed under the Apache License, Version 2.0 (the "License");
//
goog.provide('i18n.input.chrome.inputview.CandidatesInfo');
/**
* The candidates information.
*
* @param {string} source .
* @param {!Array.<!Object>} candidates .
* @constructor
*/
i18n.input.chrome.inputview.CandidatesInfo = function(source, candidates) {
/** @type {string} */
this.source = source;
/** @type {!Array.<!Object>} */
this.candidates = candidates;
};
/**
* Gets an empty suggestions instance.
*
* @return {!i18n.input.chrome.inputview.CandidatesInfo} .
*/
i18n.input.chrome.inputview.CandidatesInfo.getEmpty = function() {
return new i18n.input.chrome.inputview.CandidatesInfo('', []);
};
// Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
// limitations under the License.
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// distributed under the License is distributed on an "AS-IS" BASIS,
// Unless required by applicable law or agreed to in writing, software
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// You may obtain a copy of the License at
// you may not use this file except in compliance with the License.
// Licensed under the Apache License, Version 2.0 (the "License");
//
goog.provide('i18n.input.chrome.inputview.ConditionName');
/**
* The conditions used in layout files.
*
* @enum {string}
*/
i18n.input.chrome.inputview.ConditionName = {
SHOW_COMPACT_LAYOUT_SWITCHER: 'showCompactLayoutSwitcher',
SHOW_ALTGR: 'showAltGr',
SHOW_HANDWRITING_SWITCHER: 'showHandwritingSwitcher',
SHOW_MENU: 'showMenu',
SHOW_GLOBE_OR_SYMBOL: 'showGlobeOrSymbol',
SHOW_EN_SWITCHER_KEY: 'showEnSwitcherKey'
};
// Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
// limitations under the License.
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// distributed under the License is distributed on an "AS-IS" BASIS,
// Unless required by applicable law or agreed to in writing, software
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// You may obtain a copy of the License at
// you may not use this file except in compliance with the License.
// Licensed under the Apache License, Version 2.0 (the "License");
//
goog.provide('i18n.input.chrome.inputview.content.compact.more');
goog.require('i18n.input.chrome.inputview.content.constants');
goog.scope(function() {
var NonLetterKeys = i18n.input.chrome.inputview.content.constants.NonLetterKeys;
/**
* North American More keyset characters.
*
* @return {!Array.<!Object>}
*/
i18n.input.chrome.inputview.content.compact.more.keyNAMoreCharacters =
function() {
return [
/* 0 */ { 'text': '~' },
/* 1 */ { 'text': '`' },
/* 2 */ { 'text': '|' },
// Keep in sync with rowkeys_symbols_shift1.xml in android input tool.
/* 3 */ { 'text': '\u2022',
'moreKeys': ['\u266A', '\u2665', '\u2660', '\u2666', '\u2663']},
/* 4 */ { 'text': '\u23B7' },
// Keep in sync with rowkeys_symbols_shift1.xml in android input tool.
/* 5 */ { 'text': '\u03C0',
'moreKeys': ['\u03A0']},
/* 6 */ { 'text': '\u00F7' },
/* 7 */ { 'text': '\u00D7' },
/* 8 */ { 'text': '\u00B6',
'moreKeys': ['\u00A7']},
/* 9 */ { 'text': '\u0394' },
/* 10 */ NonLetterKeys.BACKSPACE,
/* 11 */ { 'text': '\u00A3', 'marginLeftPercent': 0.33 },
/* 12 */ { 'text': '\u00A2' },
/* 13 */ { 'text': '\u20AC' },
/* 14 */ { 'text': '\u00A5' },
// Keep in sync with rowkeys_symbols_shift2.xml in android input tool.
/* 15 */ { 'text': '^',
'moreKeys': ['\u2191', '\u2193', '\u2190', '\u2192']},
/* 16 */ { 'text': '\u00B0',
'moreKeys': ['\u2032', '\u2033']},
/* 17 */ { 'text': '=',
'moreKeys': ['\u2260', '\u2248', '\u221E']},
/* 18 */ { 'text': '{' },
/* 19 */ { 'text': '}' },
/* 20 */ NonLetterKeys.ENTER,
/* 21 */ NonLetterKeys.SWITCHER,
/* 22 */ { 'text': '\\' },
/* 23 */ { 'text': '\u00A9' },
/* 24 */ { 'text': '\u00AE' },
/* 25 */ { 'text': '\u2122' },
/* 26 */ { 'text': '\u2105' },
/* 27 */ { 'text': '[' },
/* 28 */ { 'text': ']' },
/* 29 */ { 'text': '\u00A1' },
/* 30 */ { 'text': '\u00BF' },
/* 31 */ NonLetterKeys.SWITCHER,
/* 32 */ NonLetterKeys.SWITCHER,
/* 33 */ { 'text': '<', 'isGrey': true,
'moreKeys': ['\u2039', '\u2264', '\u00AB']},
/* 34 */ NonLetterKeys.MENU,
/* 35 */ { 'text': '>', 'isGrey': true,
'moreKeys': ['\u203A', '\u2265', '\u00BB']},
/* 36 */ NonLetterKeys.SPACE,
/* 37 */ { 'text': ',', 'isGrey': true },
/* 38 */ { 'text': '.', 'isGrey': true,
'moreKeys': ['\u2026']},
/* 39 */ NonLetterKeys.HIDE
];
};
/**
* Gets United Kingdom More keyset characters.
*
* @return {!Array.<!Object>}
*/
i18n.input.chrome.inputview.content.compact.more.keyUKMoreCharacters =
function() {
// Copy North America more characters.
var data = i18n.input.chrome.inputview.content.compact.more.
keyNAMoreCharacters();
data[11]['text'] = '\u20AC'; // pound -> euro
data[12]['text'] = '\u00A5'; // cent -> yen
data[13]['text'] = '$'; // euro -> dollar
data[13]['moreKeys'] = ['\u00A2'];
data[14]['text'] = '\u00A2'; // yen -> cent
return data;
};
/**
* Gets European More keyset characters.
*
* @return {!Array.<!Object>}
*/
i18n.input.chrome.inputview.content.compact.more.keyEUMoreCharacters =
function() {
// Copy UK more characters.
var data = i18n.input.chrome.inputview.content.compact.more.
keyUKMoreCharacters();
data[11]['text'] = '\u00A3'; // euro -> pound
return data;
};
/**
* Gets Pinyin More keyset characters.
*
* @return {!Array.<!Object>}
*/
i18n.input.chrome.inputview.content.compact.more.keyPinyinMoreCharacters =
function() {
var data = i18n.input.chrome.inputview.content.compact.more.
keyNAMoreCharacters();
data[0]['text'] = '\uff5e';
data[1]['text'] = '\u2194';
data[1]['moreKeys'] = ['\u2191', '\u2193', '\u2190', '\u2192'];
data[11]['text'] = '\u00a5';
data[11]['moreKeys'] = ['\u00a2', '\u00a3', '\u20ac'];
data[12]['text'] = '\u3010';
data[13]['text'] = '\u3011';
data[14]['text'] = '\u300e';
data[15]['text'] = '\u300f';
data[15]['moreKeys'] = undefined;
data[17]['text'] = '\u2026';
data[17]['moreKeys'] = undefined;
data[18]['text'] = '\uff5b';
data[19]['text'] = '\uff5d';
data[22]['text'] = '\u003d';
data[22]['moreKeys'] = ['\u2260', '\u2248', '\u221E'];
data[27]['text'] = '\uff3b';
data[28]['text'] = '\uff3d';
data[29]['text'] = '\u300a';
data[29]['moreKeys'] = ['\u2039', '\u2264', '\u00AB'];
data[30]['text'] = '\u300b';
data[30]['moreKeys'] = ['\u203A', '\u2265', '\u00BB'];
data[33]['text'] = '\uff01';
data[33]['moreKeys'] = undefined;
data[35]['text'] = '\uff1f';
data[35]['moreKeys'] = undefined;
data[37]['text'] = '\uff0c';
data[38]['text'] = '\u3002';
return data;
};
}); // goog.scope
// Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
// limitations under the License.
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// distributed under the License is distributed on an "AS-IS" BASIS,
// Unless required by applicable law or agreed to in writing, software
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// You may obtain a copy of the License at
// you may not use this file except in compliance with the License.
// Licensed under the Apache License, Version 2.0 (the "License");
//
goog.provide('i18n.input.chrome.inputview.content.compact.numberpad');
goog.require('i18n.input.chrome.inputview.content.constants');
goog.scope(function() {
var NonLetterKeys = i18n.input.chrome.inputview.content.constants.NonLetterKeys;
/**
* Generic numberpad keyset characters.
*
* @return {!Array.<!Object>}
*/
i18n.input.chrome.inputview.content.compact.numberpad.keyNumberpadCharacters =
function() {
return [
/* 0 */ { 'text': '-',
'isGrey': true},
/* 1 */ { 'text': '+',
'isGrey': true},
/* 2 */ { 'text': '.',
'isGrey': true},
/* 3 */ { 'text': '1'},
/* 4 */ { 'text': '2'},
/* 5 */ { 'text': '3'},
/* 6 */ NonLetterKeys.BACKSPACE,
/* 7 */ { 'text': '*',
'isGrey': true},
/* 8 */ { 'text': '/',
'isGrey': true},
/* 9 */ { 'text': ',',
'isGrey': true},
/* 10 */ { 'text': '4'},
/* 11 */ { 'text': '5'},
/* 12 */ { 'text': '6'},
/* 13 */ NonLetterKeys.ENTER,
/* 14 */ { 'text': '(',
'isGrey': true},
/* 15 */ { 'text': ')',
'isGrey': true},
/* 16 */ { 'text': '=',
'isGrey': true},
/* 17 */ { 'text': '7'},
/* 18 */ { 'text': '8'},
/* 19 */ { 'text': '9',
'marginRightPercent': 0.545454},
/* 20 */ NonLetterKeys.SPACE,
/* 21 */ { 'text': '*'},
/* 22 */ { 'text': '0'},
/* 23 */ { 'text': '#'},
/* 24 */ NonLetterKeys.HIDE
];
};
// TODO(rsadam): Add phone numberpad keyset here.
}); // goog.scope
// Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
// limitations under the License.
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// distributed under the License is distributed on an "AS-IS" BASIS,
// Unless required by applicable law or agreed to in writing, software
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// You may obtain a copy of the License at
// you may not use this file except in compliance with the License.
// Licensed under the Apache License, Version 2.0 (the "License");
//
goog.provide('i18n.input.chrome.inputview.content.compact.symbol');
goog.require('i18n.input.chrome.inputview.content.constants');
goog.scope(function() {
var NonLetterKeys = i18n.input.chrome.inputview.content.constants.NonLetterKeys;
/**
* Gets North American Symbol keyset characters.
*
* @return {!Array.<!Object>}
*/
i18n.input.chrome.inputview.content.compact.symbol.keyNASymbolCharacters =
function() {
return [
/* 0 */ { 'text': '1',
'moreKeys': ['\u00B9', '\u00BD', '\u2153', '\u00BC', '\u215B']},
/* 1 */ { 'text': '2',
'moreKeys': ['\u00B2', '\u2154']},
/* 2 */ { 'text': '3',
'moreKeys': ['\u00B3', '\u00BE', '\u215C']},
/* 3 */ { 'text': '4',
'moreKeys': ['\u2074']},
/* 4 */ { 'text': '5',
'moreKeys': ['\u215D']},
/* 5 */ { 'text': '6' },
/* 6 */ { 'text': '7',
'moreKeys': ['\u215E']},
/* 7 */ { 'text': '8' },
/* 8 */ { 'text': '9' },
/* 9 */ { 'text': '0',
'moreKeys': ['\u207F', '\u2205']},
/* 10 */ NonLetterKeys.BACKSPACE,
/* 11 */ { 'text': '@', 'marginLeftPercent': 0.33 },
/* 12 */ { 'text': '#' },
/* 13 */ { 'text': '$',
'moreKeys': ['\u00A2', '\u00A3', '\u20AC', '\u00A5', '\u20B1']},
/* 14 */ { 'text': '%',
'moreKeys': ['\u2030']},
/* 15 */ { 'text': '&' },
// Keep in sync with rowkeys_symbols2.xml in android input tool.
/* 16 */ { 'text': '-',
'moreKeys': ['_', '\u2013', '\u2014', '\u00B7']},
/* 17 */ { 'text': '+',
'moreKeys': ['\u00B1']},
/* 18 */ { 'text': '(',
'moreKeys': ['\u007B', '\u003C', '\u005B']},
/* 19 */ { 'text': ')',
'moreKeys': ['\u007D', '\u003E', '\u005D']},
/* 20 */ NonLetterKeys.ENTER,
/* 21 */ NonLetterKeys.SWITCHER,
/* 22 */ { 'text': '\\' },
/* 23 */ { 'text': '=' },
/* 24 */ { 'text': '*',
'moreKeys': ['\u2020', '\u2021', '\u2605']},
// keep in sync with double_lqm_rqm and double_laqm_raqm in android input
// tool.
/* 25 */ { 'text': '"',
'moreKeys': ['\u201C', '\u201E', '\u201D', '\u00AB', '\u00BB']},
// keep in sync with single_lqm_rqm and single_laqm_raqm in android input
// tool
/* 26 */ { 'text': '\'',
'moreKeys': ['\u2018', '\u201A', '\u2019', '\u2039', '\u203A']},
/* 27 */ { 'text': ':' },
/* 28 */ { 'text': ';' },
/* 29 */ { 'text': '!',
'moreKeys': ['\u00A1']},
/* 30 */ { 'text': '?',
'moreKeys': ['\u00BF']},
/* 31 */ NonLetterKeys.SWITCHER,
/* 32 */ NonLetterKeys.SWITCHER,
/* 33 */ { 'text': '_', 'isGrey': true },
/* 34 */ NonLetterKeys.MENU,
/* 35 */ { 'text': '/', 'isGrey': true },
/* 36 */ NonLetterKeys.SPACE,
/* 37 */ { 'text': ',', 'isGrey': true },
/* 38 */ { 'text': '.', 'isGrey': true,
'moreKeys': ['\u2026']},
/* 39 */ NonLetterKeys.HIDE
];
};
/**
* Gets United Kingdom Symbol keyset characters.
*
* @return {!Array.<!Object>}
*/
i18n.input.chrome.inputview.content.compact.symbol.keyUKSymbolCharacters =
function() {
// Copy North America symbol characters.
var data = i18n.input.chrome.inputview.content.compact.symbol.
keyNASymbolCharacters();
// UK uses pound sign instead of dollar sign.
data[13] = { 'text': '\u00A3',
'moreKeys': ['\u00A2', '$', '\u20AC', '\u00A5', '\u20B1']};
return data;
};
/**
* Gets European Symbol keyset characters.
*
* @return {!Array.<!Object>}
*/
i18n.input.chrome.inputview.content.compact.symbol.keyEUSymbolCharacters =
function() {
// Copy UK symbol characters.
var data = i18n.input.chrome.inputview.content.compact.symbol.
keyUKSymbolCharacters();
// European uses euro sign instead of pound sign.
data[13] = { 'text': '\u20AC',
'moreKeys': ['\u00A2', '$', '\u00A3', '\u00A5', '\u20B1']};
return data;
};
/**
* Gets Pinyin Symbol keyset characters.
*
* @return {!Array.<!Object>}
*/
i18n.input.chrome.inputview.content.compact.symbol.keyPinyinSymbolCharacters =
function() {
var data = i18n.input.chrome.inputview.content.compact.symbol.
keyNASymbolCharacters();
data[13]['text'] = '\u00A5';
data[13]['moreKeys'] = ['\u0024', '\u00A2', '\u00A3', '\u20AC', '\u20B1'];
data[15]['text'] = '\uff0f';
data[16]['text'] = '\uff0d';
data[18]['text'] = '\uff08';
data[18]['moreKeys'] = ['\uff5b', '\u300a', '\uff3b', '\u3010'];
data[19]['text'] = '\uff09';
data[19]['moreKeys'] = ['\uff5d', '\u300b', '\uff3d', '\u3001'];
data[22]['text'] = '\u3001';
data[24]['text'] = '\u00D7';
data[25]['text'] = '\u201C';
data[25]['moreKeys'] = ['\u0022', '\u00AB'];
data[26]['text'] = '\u201D';
data[26]['moreKeys'] = ['\u0022', '\u00BB'];
data[27]['text'] = '\uff1a';
data[28]['text'] = '\uff1b';
data[29]['text'] = '\u2018';
data[29]['moreKeys'] = ['\u0027', '\u2039'];
data[30]['text'] = '\u2019';
data[30]['moreKeys'] = ['\u0027', '\u203a'];
data[33]['text'] = '\uff01';
data[33]['moreKeys'] = ['\u00a1'];
data[35]['text'] = '\uff1f';
data[35]['moreKeys'] = ['\u00bf'];
data[37]['text'] = '\uff0c';
data[38]['text'] = '\u3002';
return data;
};
}); // goog.scope
// Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
// limitations under the License.
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// distributed under the License is distributed on an "AS-IS" BASIS,
// Unless required by applicable law or agreed to in writing, software
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// You may obtain a copy of the License at
// you may not use this file except in compliance with the License.
// Licensed under the Apache License, Version 2.0 (the "License");
//
goog.provide('i18n.input.chrome.inputview.content.constants');
goog.require('i18n.input.chrome.inputview.Css');
goog.require('i18n.input.chrome.inputview.StateType');
goog.require('i18n.input.chrome.inputview.elements.ElementType');
goog.scope(function() {
var ElementType = i18n.input.chrome.inputview.elements.ElementType;
/**
* The non letter keys.
*
* @const
* @enum {Object}
*/
i18n.input.chrome.inputview.content.constants.NonLetterKeys = {
BACKSPACE: {
'iconCssClass': i18n.input.chrome.inputview.Css.BACKSPACE_ICON,
'type': ElementType.BACKSPACE_KEY,
'id': 'Backspace'
},
ENTER: {
'iconCssClass': i18n.input.chrome.inputview.Css.ENTER_ICON,
'type': ElementType.ENTER_KEY,
'id': 'Enter'
},
HIDE: {
'iconCssClass': i18n.input.chrome.inputview.Css.HIDE_KEYBOARD_ICON,
'type': ElementType.HIDE_KEYBOARD_KEY,
'id': 'HideKeyboard'
},
LEFT_SHIFT: {
'toState': i18n.input.chrome.inputview.StateType.SHIFT,
'iconCssClass': i18n.input.chrome.inputview.Css.SHIFT_ICON,
'type': ElementType.MODIFIER_KEY,
'id': 'ShiftLeft',
'supportSticky': true
},
RIGHT_SHIFT: {
'toState': i18n.input.chrome.inputview.StateType.SHIFT,
'iconCssClass': i18n.input.chrome.inputview.Css.SHIFT_ICON,
'type': ElementType.MODIFIER_KEY,
'id': 'ShiftRight',
'supportSticky': true
},
SPACE: {
'name': ' ',
'type': ElementType.SPACE_KEY,
'id': 'Space'
},
SWITCHER: {
'type': ElementType.SWITCHER_KEY
},
MENU: {
'iconCssClass': i18n.input.chrome.inputview.Css.MENU_ICON,
'type': ElementType.MENU_KEY,
'id': 'Menu'
},
GLOBE: {
'iconCssClass': i18n.input.chrome.inputview.Css.GLOBE_ICON,
'type': ElementType.GLOBE_KEY,
'id': 'Globe'
}
};
}); // goog.scope
// Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
// limitations under the License.
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// distributed under the License is distributed on an "AS-IS" BASIS,
// Unless required by applicable law or agreed to in writing, software
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// You may obtain a copy of the License at
// you may not use this file except in compliance with the License.
// Licensed under the Apache License, Version 2.0 (the "License");
//
goog.provide('i18n.input.chrome.inputview.content.ContextlayoutUtil');
goog.require('i18n.input.chrome.inputview.content.compact.util');
goog.require('i18n.input.chrome.inputview.content.compact.util.CompactKeysetSpec');
goog.require('i18n.input.chrome.message.ContextType');
goog.scope(function() {
var ContextType = i18n.input.chrome.message.ContextType;
var util = i18n.input.chrome.inputview.content.ContextlayoutUtil;
var compact = i18n.input.chrome.inputview.content.compact.util;
var keysetSpecNode = compact.CompactKeysetSpec;
/**
* Generates custom layouts to be displayed on specified input type contexts.
*
*
* @param {Object.<ContextType, !Object>} inputTypeToKeysetSpecMap Map from
* input types to context-specific keysets.
* @param {!function(!Object): void} onLoaded The function to call once a keyset
* data is ready.
*/
util.generateContextLayouts = function(inputTypeToKeysetSpecMap, onLoaded) {
// Creates context-specific keysets.
if (inputTypeToKeysetSpecMap) {
for (var inputType in inputTypeToKeysetSpecMap) {
var spec = inputTypeToKeysetSpecMap[inputType];
var data = compact.createCompactData(
spec, 'compactkbd-k-', 'compactkbd-k-key-');
data['id'] = spec[keysetSpecNode.ID];
data['showMenuKey'] = false;
data['noShift'] = true;
data['onContext'] = inputType;
onLoaded(data);
}
}
};
}); // goog.scope
// Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
// limitations under the License.
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// distributed under the License is distributed on an "AS-IS" BASIS,
// Unless required by applicable law or agreed to in writing, software
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// You may obtain a copy of the License at
// you may not use this file except in compliance with the License.
// Licensed under the Apache License, Version 2.0 (the "License");
//
goog.provide('i18n.input.chrome.inputview.Covariance');
goog.require('i18n.input.chrome.inputview.elements.ElementType');
goog.scope(function() {
var ElementType = i18n.input.chrome.inputview.elements.ElementType;
/**
* The covariance used for gaussian model.
*
* @constructor
*/
i18n.input.chrome.inputview.Covariance = function() {
/** @private {number} */
this.breakDown_ = 0;
};
var Covariance = i18n.input.chrome.inputview.Covariance;
/**
* The break-down for covariance.
*
* @enum {number}
*/
Covariance.BreakDown = {
A11Y: 1,
HORIZONTAL: 2,
WIDE_SCREEN: 4
};
/**
* The key type.
*
* @type {!Object.<ElementType, number>}
*/
Covariance.ElementTypeMap = goog.object.create(
ElementType.CHARACTER_KEY, 0,
ElementType.COMPACT_KEY, 1
);
/**
* The value.
* Key: the break down value.
* Value: A list - first is the covariance for full keyboard, second is for
* compact.
*
* @private {!Object.<!Array.<number>>}
*/
Covariance.VALUE_ = {
0: [120, 160],
1: [130, 0],
2: [235, 342],
3: [162, 0],
4: [160, 213],
5: [142, 0],
6: [230, 332],
7: [162, 0]
};
/**
* Updates the covariance.
*
* @param {boolean} isWideScreen .
* @param {boolean} isHorizontal .
* @param {boolean} isA11y .
*/
Covariance.prototype.update = function(isWideScreen, isHorizontal, isA11y) {
this.breakDown_ = 0;
if (isWideScreen) {
this.breakDown_ |= Covariance.BreakDown.WIDE_SCREEN;
}
if (isHorizontal) {
this.breakDown_ |= Covariance.BreakDown.HORIZONTAL;
}
if (isA11y) {
this.breakDown_ |= Covariance.BreakDown.A11Y;
}
};
/**
* Gets the covariance value.
*
* @param {ElementType} type .
*/
Covariance.prototype.getValue = function(type) {
var index = Covariance.ElementTypeMap[type];
return Covariance.VALUE_[this.breakDown_][index];
};
}); // goog.scope
// Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
// limitations under the License.
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// distributed under the License is distributed on an "AS-IS" BASIS,
// Unless required by applicable law or agreed to in writing, software
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// You may obtain a copy of the License at
// you may not use this file except in compliance with the License.
// Licensed under the Apache License, Version 2.0 (the "License");
//
goog.provide('i18n.input.chrome.inputview.Css');
/**
* The css used for input view keyboard.
*
* @enum {string}
*/
i18n.input.chrome.inputview.Css = {
A11Y: goog.getCssName('inputview-a11y'),
ALTDATA_COVER: goog.getCssName('inputview-altdata-cover'),
ALTDATA_KEY: goog.getCssName('inputview-altdata-key'),
ALTDATA_SEPARATOR: goog.getCssName('inputview-altdata-separator'),
ALTDATA_VIEW: goog.getCssName('inputview-altdata-view'),
ALTGR_CONTENT: goog.getCssName('inputview-ac'),
ARROW_KEY: goog.getCssName('inputview-arrow-key'),
BACKSPACE_ICON: goog.getCssName('inputview-backspace-icon'),
CANDIDATE: goog.getCssName('inputview-candidate'),
CANDIDATES_LINE: goog.getCssName('inputview-candidates-line'),
CANDIDATES_TOP_LINE: goog.getCssName('inputview-candidates-top-line'),
CANDIDATE_AUTOCORRECT: goog.getCssName('inputview-candidate-autocorrect'),
CANDIDATE_BUTTON: goog.getCssName('inputview-candidate-button'),
CANDIDATE_DEFAULT: goog.getCssName('inputview-candidate-default'),
CANDIDATE_HIGHLIGHT: goog.getCssName('inputview-candidate-highlight'),
CANDIDATE_INTER_CONTAINER: goog.getCssName('inputview-candiate-ic'),
CANDIDATE_SEPARATOR: goog.getCssName('inputview-candidate-separator'),
CANDIDATE_VIEW: goog.getCssName('inputview-candidate-view'),
CANVAS: goog.getCssName('inputview-canvas'),
CANVAS_LEFT_COLUMN: goog.getCssName('inputview-canvas-left-column'),
CANVAS_RIGHT_COLUMN: goog.getCssName('inputview-canvas-right-column'),
CANVAS_VIEW: goog.getCssName('inputview-canvasview'),
CAPSLOCK_DOT: goog.getCssName('inputview-capslock-dot'),
CAPSLOCK_DOT_HIGHLIGHT: goog.getCssName('inputview-capslock-dot-highlight'),
CHARACTER: goog.getCssName('inputview-character'),
CHARACTER_HIGHLIGHT: goog.getCssName('inputview-ch'),
CHECKED_MENU_LIST: goog.getCssName('inputview-checked-menu-list'),
COMPACT_KEY: goog.getCssName('inputview-compact-key'),
COMPACT_SWITCHER: goog.getCssName('inputview-compact-switcher'),
CONTAINER: goog.getCssName('inputview-container'),
DEFAULT_CONTENT: goog.getCssName('inputview-dc'),
DIGIT_CHARACTER: goog.getCssName('inputview-digit-character'),
DOWN_KEY: goog.getCssName('inputview-down-key'),
ELEMENT_HIGHLIGHT: goog.getCssName('inputview-element-highlight'),
EMOJI: goog.getCssName('inputview-emoji'),
EMOJI_BACK: goog.getCssName('inputview-emoji-back'),
EMOJI_FONT: goog.getCssName('inputview-emoji-font'),
EMOJI_KEY: goog.getCssName('inputview-emoji-key'),
EMOJI_KEY_HIGHLIGHT: goog.getCssName('inputview-emoji-key-highlight'),
EMOJI_SWITCH: goog.getCssName('inputview-emoji-switch'),
EMOJI_SWITCH_CAR:
goog.getCssName('inputview-emoji-switch-car'),
EMOJI_SWITCH_EMOJI:
goog.getCssName('inputview-emoji-switch-emoji'),
EMOJI_SWITCH_EMOTICON:
goog.getCssName('inputview-emoji-switch-emoticon'),
EMOJI_SWITCH_FAVORITS:
goog.getCssName('inputview-emoji-switch-favorits'),
EMOJI_SWITCH_FLOWER:
goog.getCssName('inputview-emoji-switch-flower'),
EMOJI_SWITCH_HIGHLIGHT:
goog.getCssName('inputview-emoji-switch-highlight'),
EMOJI_SWITCH_RECENT:
goog.getCssName('inputview-emoji-switch-recent'),
EMOJI_SWITCH_SPECIAL:
goog.getCssName('inputview-emoji-switch-special'),
EMOJI_SWITCH_SYMBOL:
goog.getCssName('inputview-emoji-switch-symbol'),
EMOJI_SWITCH_TRIANGLE:
goog.getCssName('inputview-emoji-switch-triangle'),
EMOJI_TABBAR_KEY: goog.getCssName('inputview-emoji-tabbar-key'),
EMOJI_TABBAR_KEY_HIGHLIGHT:
goog.getCssName('inputview-emoji-tabbar-key-highlight'),
EMOJI_TABBAR_SK: goog.getCssName('inputview-emoji-tabbar-sk'),
EMOJI_TEXT: goog.getCssName('inputview-emoji-text'),
ENTER_ICON: goog.getCssName('inputview-enter-icon'),
EN_SWITCHER_DEFAULT: goog.getCssName('inputview-en-switcher-default'),
EN_SWITCHER_ENGLISH: goog.getCssName('inputview-en-switcher-english'),
EXPAND_CANDIDATES_ICON: goog.getCssName('inputview-expand-candidates-icon'),
EXTENDED_LAYOUT_TRANSITION: goog.getCssName('inputview-extended-transition'),
FONT: goog.getCssName('inputview-font'),
GLOBE_ICON: goog.getCssName('inputview-globe-icon'),
HANDWRITING: goog.getCssName('inputview-handwriting'),
HANDWRITING_BACK: goog.getCssName('inputview-handwriting-back'),
HANDWRITING_LAYOUT: goog.getCssName('inputview-handwriting-layout'),
HANDWRITING_NETWORK_ERROR:
goog.getCssName('inputview-handwriting-network-error'),
HANDWRITING_SWITCHER: goog.getCssName('inputview-handwriting-switcher'),
HANDWRITING_PRIVACY_COVER:
goog.getCssName('inputview-handwriting-privacy-cover'),
HANDWRITING_PRIVACY_INFO:
goog.getCssName('inputview-handwriting-privacy-info'),
HANDWRITING_PRIVACY_INFO_HIDDEN:
goog.getCssName('inputview-handwriting-privacy-info-hidden'),
HIDE_KEYBOARD_ICON: goog.getCssName('inputview-hide-keyboard-icon'),
HINT_TEXT: goog.getCssName('inputview-hint-text'),
HOLD: goog.getCssName('inputview-hold'),
IME_LIST_CONTAINER: goog.getCssName('inputview-ime-list-container'),
INDICATOR: goog.getCssName('inputview-indicator'),
INDICATOR_BACKGROUND: goog.getCssName('inputview-indicator-background'),
INLINE_DIV: goog.getCssName('inputview-inline-div'),
JP_IME_SWITCH: goog.getCssName('inputview-jp-ime-switch'),
KEY_HOLD: goog.getCssName('inputview-key-hold'),
LAYOUT_VIEW: goog.getCssName('inputview-layoutview'),
LEFT_KEY: goog.getCssName('inputview-left-key'),
LINEAR_LAYOUT: goog.getCssName('inputview-linear'),
LINEAR_LAYOUT_BORDER: goog.getCssName('inputview-linear-border'),
MENU_LIST_CHECK_MARK: goog.getCssName('inputview-menu-list-check-mark'),
MENU_FOOTER: goog.getCssName('inputview-menu-footer'),
MENU_FOOTER_EMOJI_BUTTON:
goog.getCssName('inputview-menu-footer-emoji-button'),
MENU_FOOTER_HANDWRITING_BUTTON:
goog.getCssName('inputview-menu-footer-handwriting-button'),
MENU_FOOTER_ITEM: goog.getCssName('inputview-menu-footer-item'),
MENU_FOOTER_SETTING_BUTTON:
goog.getCssName('inputview-menu-footer-setting-button'),
MENU_ICON: goog.getCssName('inputview-menu-icon'),
MENU_LIST_INDICATOR: goog.getCssName('inputview-menu-list-indicator'),
MENU_LIST_INDICATOR_NAME:
goog.getCssName('inputview-menu-list-indicator-name'),
MENU_LIST_ITEM: goog.getCssName('inputview-menu-list-item'),
MENU_LIST_NAME: goog.getCssName('inputview-menu-list-name'),
MENU_VIEW: goog.getCssName('inputview-menu-view'),
MODIFIER: goog.getCssName('inputview-modifier'),
MODIFIER_ON: goog.getCssName('inputview-modifier-on'),
MODIFIER_STATE_ICON: goog.getCssName('inputview-modifier-state-icon'),
PAGE_DOWN_ICON: goog.getCssName('inputview-page-down-icon'),
PAGE_UP_ICON: goog.getCssName('inputview-page-up-icon'),
PINYIN: goog.getCssName('inputview-pinyin'),
REGULAR_SWITCHER: goog.getCssName('inputview-regular-switcher'),
RIGHT_KEY: goog.getCssName('inputview-right-key'),
SHIFT_ICON: goog.getCssName('inputview-shift-icon'),
SHRINK_CANDIDATES_ICON: goog.getCssName('inputview-shrink-candidates-icon'),
SOFT_KEY: goog.getCssName('inputview-sk'),
SOFT_KEY_VIEW: goog.getCssName('inputview-skv'),
SPACE_ICON: goog.getCssName('inputview-space-icon'),
SPECIAL_KEY_BG: goog.getCssName('inputview-special-key-bg'),
SPECIAL_KEY_HIGHLIGHT: goog.getCssName('inputview-special-key-highlight'),
SPECIAL_KEY_NAME: goog.getCssName('inputview-special-key-name'),
SWITCHER_CHINESE: goog.getCssName('inputview-switcher-chinese'),
SWITCHER_ENGLISH: goog.getCssName('inputview-switcher-english'),
TABLE_CELL: goog.getCssName('inputview-table-cell'),
TAB_ICON: goog.getCssName('inputview-tab-icon'),
THREE_CANDIDATES: goog.getCssName('inputview-three-candidates'),
TITLE: goog.getCssName('inputview-title'),
TITLE_BAR: goog.getCssName('inputview-title-bar'),
UP_KEY: goog.getCssName('inputview-up-key'),
VERTICAL_LAYOUT: goog.getCssName('inputview-vertical'),
VIEW: goog.getCssName('inputview-view'),
WRAPPER: goog.getCssName('inputview-wrapper')
};
// Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
// limitations under the License.
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// distributed under the License is distributed on an "AS-IS" BASIS,
// Unless required by applicable law or agreed to in writing, software
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// You may obtain a copy of the License at
// you may not use this file except in compliance with the License.
// Licensed under the Apache License, Version 2.0 (the "License");
//
goog.provide('i18n.input.chrome.inputview.Direction');
/**
* The direction.
*
* @enum {number}
*/
i18n.input.chrome.inputview.Direction = {
UP: 0,
DOWN: 1,
LEFT: 2,
RIGHT: 3
};
// Copyright 2014 The Cloud Input Tools Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/**
* @fileoverview Provides common operation of dom for input tools.
*/
goog.provide('i18n.input.common.dom');
goog.require('goog.array');
goog.require('goog.dom');
goog.require('goog.dom.TagName');
goog.require('goog.dom.classlist');
goog.require('goog.style');
goog.require('goog.uri.utils');
goog.require('i18n.input.common.GlobalSettings');
/**
* When detects whether the same domain iframe, browser will throw
* exceptions on accessing the cross domain iframe. Stores result to avoid to
* throws exception twice.
* Key is document uid, value is object. ifrmae uid : true/false
*
* @type {!Object.<number, !Object.<number, boolean>>}
* @private
*/
i18n.input.common.dom.sameDomainIframes_ = {};
/**
* Checks the given element whether is editable.
*
* @param {!Element} element The element.
* @return {boolean} Whether the give element is editable.
*/
i18n.input.common.dom.isEditable = function(element) {
if (!element.tagName) {
return false;
}
if (element.readOnly) {
return false;
}
switch (element.tagName.toUpperCase()) {
case 'TEXTAREA':
return true;
case 'INPUT':
return (element.type.toUpperCase() == 'TEXT' ||
element.type.toUpperCase() == 'SEARCH');
case 'DIV':
return element.isContentEditable;
case 'IFRAME':
// Accessing iframe's contents or properties throws exception when the
// iframe is not hosted on the same domain.
// When it happens, ignore it and consider this iframe isn't editable.
/** @preserveTry */
try {
var ifdoc = i18n.input.common.dom.getSameDomainFrameDoc(element);
return !!ifdoc && (ifdoc.designMode &&
ifdoc.designMode.toUpperCase() == 'ON' ||
ifdoc.body && ifdoc.body.isContentEditable);
} catch (e) {
return false;
}
}
return false;
};
/**
* Sets class names to an element.
*
* @param {Element} elem Element to set class names.
* @param {Array.<string>} classes Class names.
*/
i18n.input.common.dom.setClasses = function(elem, classes) {
if (elem) {
for (var i = 0; i < classes.length; i++) {
if (i == 0) {
goog.dom.classlist.set(elem, classes[0]);
} else {
goog.dom.classlist.add(elem, classes[i]);
}
}
}
};
/**
* Check the iframe whether is the same domain as the current domain.
* Returns the iframe content document when it's the same domain,
* otherwise return null.
*
* @param {!Element} element The iframe element.
* @return {Document} The iframe content document.
*/
i18n.input.common.dom.getSameDomainFrameDoc = function(element) {
var uid = goog.getUid(document);
var frameUid = goog.getUid(element);
var states = i18n.input.common.dom.sameDomainIframes_[uid];
if (!states) {
states = i18n.input.common.dom.sameDomainIframes_[uid] = {};
}
/** @preserveTry */
try {
var url = window.location.href || '';
//Note: cross-domain IFRAME's src can be:
// http://www...
// https://www....
// //www.
// Non-cross-domain IFRAME's src can be:
// javascript:...
// javascript://...
// abc:...
// abc://...
// abc//...
// path/index.html
if (!(frameUid in states)) {
if (element.src) {
var pos = element.src.indexOf('//');
var protocol = pos < 0 ? 'N/A' : element.src.slice(0, pos);
states[frameUid] = (protocol != '' &&
protocol != 'http:' &&
protocol != 'https:' ||
goog.uri.utils.haveSameDomain(element.src, url));
} else {
states[frameUid] = true;
}
}
return states[frameUid] ? goog.dom.getFrameContentDocument(element) : null;
} catch (e) {
states[frameUid] = false;
return null;
}
};
/**
* Gets the same domain iframe or frame document in given document, default
* given document is current document.
*
* @param {Document=} opt_doc The given document.
* @return {Array.<!Document>} The same domain iframe document.
*/
i18n.input.common.dom.getSameDomainDocuments = function(opt_doc) {
var doc = opt_doc || document;
var iframes = [];
var rets = [];
goog.array.extend(iframes,
doc.getElementsByTagName(goog.dom.TagName.IFRAME),
doc.getElementsByTagName(goog.dom.TagName.FRAME));
goog.array.forEach(iframes, function(frame) {
var frameDoc = i18n.input.common.dom.getSameDomainFrameDoc(frame);
frameDoc && rets.push(frameDoc);
});
return rets;
};
/**
* Create the iframe in given document or default document. Then the input tool
* UI element will be create inside the iframe document to avoid CSS conflict.
*
* @param {Document=} opt_doc The given document.
* @return {!Element} The iframe element.
*/
i18n.input.common.dom.createIframeWrapper = function(opt_doc) {
var doc = opt_doc || document;
var dom = goog.dom.getDomHelper();
var frame = dom.createDom(goog.dom.TagName.IFRAME, {
'frameborder': '0',
'scrolling': 'no',
'style': 'background-color:transparent;border:0;display:none;'
});
dom.append(/** @type {!Element} */ (doc.body), frame);
var frameDoc = dom.getFrameContentDocument(frame);
var css = i18n.input.common.GlobalSettings.alternativeImageUrl ?
i18n.input.common.GlobalSettings.css.replace(
/\/\/ssl.gstatic.com\/inputtools\/images/g,
i18n.input.common.GlobalSettings.alternativeImageUrl) :
i18n.input.common.GlobalSettings.css;
goog.style.installStyles(
'html body{border:0;margin:0;padding:0} html,body{overflow:hidden}' +
css, /** @type {!Element} */(frameDoc.body));
return frame;
};
/**
* The property need to be copied from original element to its iframe wrapper.
*
* @type {!Array.<string>}
* @private
*/
i18n.input.common.dom.iframeWrapperProperty_ = ['box-shadow', 'z-index',
'margin', 'position', 'display'];
/**
* Copies the necessary properties value from original element to its iframe
* wrapper element.
*
* @param {Element} element .
* @param {Element} iframe The iframe wrapper element.
*/
i18n.input.common.dom.copyNecessaryStyle = function(element, iframe) {
goog.style.setContentBoxSize(iframe, goog.style.getSize(element));
goog.array.forEach(i18n.input.common.dom.iframeWrapperProperty_,
function(property) {
goog.style.setStyle(iframe, property,
goog.style.getComputedStyle(element, property));
});
};
// Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
// limitations under the License.
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// distributed under the License is distributed on an "AS-IS" BASIS,
// Unless required by applicable law or agreed to in writing, software
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// You may obtain a copy of the License at
// you may not use this file except in compliance with the License.
// Licensed under the Apache License, Version 2.0 (the "License");
//
goog.provide('i18n.input.chrome.inputview.elements.content.AltDataView');
goog.require('goog.array');
goog.require('goog.dom');
goog.require('goog.dom.TagName');
goog.require('goog.dom.classlist');
goog.require('goog.style');
goog.require('i18n.input.chrome.inputview.Css');
goog.require('i18n.input.chrome.inputview.elements.Element');
goog.require('i18n.input.chrome.inputview.elements.ElementType');
goog.require('i18n.input.chrome.inputview.util');
goog.scope(function() {
/**
* The view for alt data.
*
* @param {goog.events.EventTarget=} opt_eventTarget The parent event target.
* @constructor
* @extends {i18n.input.chrome.inputview.elements.Element}
*/
i18n.input.chrome.inputview.elements.content.AltDataView = function(
opt_eventTarget) {
goog.base(this, '', i18n.input.chrome.inputview.elements.ElementType.
ALTDATA_VIEW, opt_eventTarget);
/**
* The alternative elements.
*
* @type {!Array.<!Element>}
* @private
*/
this.altdataElements_ = [];
};
goog.inherits(i18n.input.chrome.inputview.elements.content.AltDataView,
i18n.input.chrome.inputview.elements.Element);
var AltDataView = i18n.input.chrome.inputview.elements.content.AltDataView;
/**
* The padding between the alt data view and the key.
*
* @type {number}
* @private
*/
AltDataView.PADDING_ = 6;
/**
* The distance between finger to altdata view which will cancel the altdata
* view.
*
* @type {number}
* @private
*/
AltDataView.FINGER_DISTANCE_TO_CANCEL_ALTDATA_ = 100;
/**
* The cover element.
* Note: The reason we use a separate cover element instead of the view is
* because of the opacity. We can not reassign the opacity in child element.
*
* @type {!Element}
* @private
*/
AltDataView.prototype.coverElement_;
/**
* The index of the alternative element which is highlighted.
*
* @type {number}
* @private
*/
AltDataView.prototype.highlightIndex_ = 0;
/**
* The key which trigger this alternative data view.
*
* @type {!i18n.input.chrome.inputview.elements.content.SoftKey}
*/
AltDataView.prototype.triggeredBy;
/** @override */
AltDataView.prototype.createDom = function() {
goog.base(this, 'createDom');
var dom = this.getDomHelper();
var elem = this.getElement();
goog.dom.classlist.add(elem, i18n.input.chrome.inputview.Css.ALTDATA_VIEW);
this.coverElement_ = dom.createDom(goog.dom.TagName.DIV,
i18n.input.chrome.inputview.Css.ALTDATA_COVER);
dom.appendChild(document.body, this.coverElement_);
goog.style.setElementShown(this.coverElement_, false);
this.coverElement_['view'] = this;
};
/** @override */
AltDataView.prototype.enterDocument = function() {
goog.base(this, 'enterDocument');
goog.style.setElementShown(this.getElement(), false);
};
/**
* Shows the alt data viwe.
*
* @param {!i18n.input.chrome.inputview.elements.content.SoftKey} key The key
* triggerred this altdata view.
* @param {boolean} isRTL Whether to show the key characters as RTL.
*/
AltDataView.prototype.show = function(key, isRTL) {
this.triggeredBy = key;
var coordinate = goog.style.getClientPosition(key.getElement());
var x = coordinate.x;
var y = coordinate.y;
var width = key.availableWidth;
var height = key.availableHeight;
var ElementType = i18n.input.chrome.inputview.elements.ElementType;
var characters;
if (key.type == ElementType.CHARACTER_KEY) {
key = /** @type {!i18n.input.chrome.inputview.elements.content.
CharacterKey} */ (key);
characters = key.getAltCharacters();
} else if (key.type == ElementType.COMPACT_KEY) {
key = /** @type {!i18n.input.chrome.inputview.elements.content.
CompactKey} */ (key);
characters = key.getMoreCharacters();
if (key.hintText) {
goog.array.insertAt(characters, key.hintText, 0);
}
}
if (!characters || characters.length == 0) {
return;
}
goog.style.setElementShown(this.getElement(), true);
this.getDomHelper().removeChildren(this.getElement());
// The total width of the characters + the separators, every separator has
// width = 1.
var altDataWidth = width * characters.length;
var showingLeft = (x + altDataWidth) > screen.width;
if (showingLeft) {
characters.reverse();
}
for (var i = 0; i < characters.length; i++) {
var keyElem = this.addKey_(characters[i], isRTL);
goog.style.setSize(keyElem, width, height);
this.altdataElements_.push(keyElem);
if (i != characters.length - 1) {
this.addSeparator_(height);
}
}
var left = x;
if (showingLeft) {
// If no enough space at the right, then make it to the left.
left = x + width - altDataWidth;
this.highlightIndex_ = this.altdataElements_.length - 1;
this.setElementBackground_(this.altdataElements_[this.highlightIndex_],
true);
} else {
this.setElementBackground_(this.altdataElements_[0], true);
}
var elemTop = y - height - AltDataView.PADDING_;
if (elemTop < 0) {
elemTop = y + height + AltDataView.PADDING_;
}
goog.style.setPosition(this.getElement(), left, elemTop);
goog.style.setElementShown(this.coverElement_, true);
this.triggeredBy.setHighlighted(true);
};
/**
* Hides the alt data view.
*/
AltDataView.prototype.hide = function() {
this.altdataElements_ = [];
this.highlightIndex_ = 0;
goog.style.setElementShown(this.getElement(), false);
goog.style.setElementShown(this.coverElement_, false);
this.triggeredBy.setHighlighted(false);
};
/**
* Highlights the item according to the current coordinate of the finger.
*
* @param {number} x .
* @param {number} y .
*/
AltDataView.prototype.highlightItem = function(x, y) {
for (var i = 0; i < this.altdataElements_.length; i++) {
var elem = this.altdataElements_[i];
var coordinate = goog.style.getClientPosition(elem);
var size = goog.style.getSize(elem);
if (coordinate.x < x && (coordinate.x + size.width) > x) {
this.highlightIndex_ = i;
this.clearAllHighlights_();
this.setElementBackground_(elem, true);
}
var verticalDist = Math.min(Math.abs(y - coordinate.y),
Math.abs(y - coordinate.y - size.height));
if (verticalDist > AltDataView.
FINGER_DISTANCE_TO_CANCEL_ALTDATA_) {
this.hide();
return;
}
}
};
/**
* Clears all the highlights.
*
* @private
*/
AltDataView.prototype.clearAllHighlights_ =
function() {
for (var i = 0; i < this.altdataElements_.length; i++) {
this.setElementBackground_(this.altdataElements_[i], false);
}
};
/**
* Sets the background style of the element.
*
* @param {!Element} element The element.
* @param {boolean} highlight True to highlight the element.
* @private
*/
AltDataView.prototype.setElementBackground_ =
function(element, highlight) {
if (highlight) {
goog.dom.classlist.add(element, i18n.input.chrome.inputview.Css.
ELEMENT_HIGHLIGHT);
} else {
goog.dom.classlist.remove(element, i18n.input.chrome.inputview.Css.
ELEMENT_HIGHLIGHT);
}
};
/**
* Gets the highlighted character.
*
* @return {string} The character.
*/
AltDataView.prototype.getHighlightedCharacter = function() {
return goog.dom.getTextContent(this.altdataElements_[this.highlightIndex_]);
};
/**
* Adds a alt data key into the view.
*
* @param {string} character The alt character.
* @param {boolean} isRTL Whether to show the character as RTL.
* @return {!Element} The create key element.
* @private
*/
AltDataView.prototype.addKey_ = function(character, isRTL) {
var dom = this.getDomHelper();
var keyElem = dom.createDom(goog.dom.TagName.DIV,
i18n.input.chrome.inputview.Css.ALTDATA_KEY,
i18n.input.chrome.inputview.util.getVisibleCharacter(character));
keyElem.style.direction = isRTL ? 'rtl' : 'ltr';
dom.appendChild(this.getElement(), keyElem);
return keyElem;
};
/**
* Adds a separator.
*
* @param {number} height .
* @private
*/
AltDataView.prototype.addSeparator_ = function(height) {
var dom = this.getDomHelper();
var tableCell = dom.createDom(goog.dom.TagName.DIV,
i18n.input.chrome.inputview.Css.TABLE_CELL);
tableCell.style.height = height + 'px';
var separator = dom.createDom(goog.dom.TagName.DIV,
i18n.input.chrome.inputview.Css.ALTDATA_SEPARATOR);
dom.appendChild(tableCell, separator);
dom.appendChild(this.getElement(), tableCell);
};
/**
* Gets the cover element.
*
* @return {!Element} The cover element.
*/
AltDataView.prototype.getCoverElement = function() {
return this.coverElement_;
};
/** @override */
AltDataView.prototype.resize = function(width, height) {
goog.base(this, 'resize', width, height);
goog.style.setSize(this.coverElement_, width, height);
};
/** @override */
AltDataView.prototype.disposeInternal = function() {
this.getElement()['view'] = null;
goog.base(this, 'disposeInternal');
};
}); // goog.scope
// Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
// limitations under the License.
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// distributed under the License is distributed on an "AS-IS" BASIS,
// Unless required by applicable law or agreed to in writing, software
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// You may obtain a copy of the License at
// you may not use this file except in compliance with the License.
// Licensed under the Apache License, Version 2.0 (the "License");
//
goog.provide('i18n.input.chrome.inputview.elements.content.Candidate');
goog.require('goog.dom.classlist');
goog.require('i18n.input.chrome.inputview.Css');
goog.require('i18n.input.chrome.inputview.elements.Element');
goog.require('i18n.input.chrome.inputview.elements.ElementType');
goog.require('i18n.input.chrome.message.Name');
goog.scope(function() {
var ElementType = i18n.input.chrome.inputview.elements.ElementType;
var Css = i18n.input.chrome.inputview.Css;
var TagName = goog.dom.TagName;
var Name = i18n.input.chrome.message.Name;
/**
* The candidate component.
*
* @param {string} id .
* @param {!Object} candidate .
* @param {i18n.input.chrome.inputview.elements.content.Candidate.Type}
* candidateType .
* @param {number} height .
* @param {boolean} isDefault .
* @param {number=} opt_width .
* @param {goog.events.EventTarget=} opt_eventTarget .
* @constructor
* @extends {i18n.input.chrome.inputview.elements.Element}
*/
i18n.input.chrome.inputview.elements.content.Candidate = function(id,
candidate, candidateType, height, isDefault, opt_width, opt_eventTarget) {
goog.base(this, id, ElementType.CANDIDATE, opt_eventTarget);
/** @type {!Object} */
this.candidate = candidate;
/** @type {i18n.input.chrome.inputview.elements.content.Candidate.Type} */
this.candidateType = candidateType;
/** @type {number} */
this.width = opt_width || 0;
/** @type {number} */
this.height = height;
/** @type {boolean} */
this.isDefault = isDefault;
};
var Candidate = i18n.input.chrome.inputview.elements.content.Candidate;
goog.inherits(Candidate, i18n.input.chrome.inputview.elements.Element);
/**
* The type of this candidate.
*
* @enum {number}
*/
Candidate.Type = {
CANDIDATE: 0,
NUMBER: 1
};
/** @override */
Candidate.prototype.createDom = function() {
goog.base(this, 'createDom');
var dom = this.getDomHelper();
var elem = this.getElement();
goog.dom.classlist.add(elem, Css.CANDIDATE);
if (this.candidate['isEmoji']) {
goog.dom.classlist.add(elem, Css.EMOJI_FONT);
}
dom.setTextContent(elem, this.candidate[Name.CANDIDATE]);
elem.style.height = this.height + 'px';
if (this.width > 0) {
elem.style.width = this.width + 'px';
}
if (this.isDefault) {
goog.dom.classlist.add(elem, Css.CANDIDATE_DEFAULT);
}
if (!!this.candidate[Name.IS_AUTOCORRECT]) {
goog.dom.classlist.add(elem, Css.CANDIDATE_AUTOCORRECT);
}
};
/** @override */
Candidate.prototype.setHighlighted = function(highlight) {
if (highlight) {
goog.dom.classlist.add(this.getElement(), Css.CANDIDATE_HIGHLIGHT);
} else {
goog.dom.classlist.remove(this.getElement(), Css.CANDIDATE_HIGHLIGHT);
}
};
}); // goog.scope
// Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
// limitations under the License.
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// distributed under the License is distributed on an "AS-IS" BASIS,
// Unless required by applicable law or agreed to in writing, software
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// You may obtain a copy of the License at
// you may not use this file except in compliance with the License.
// Licensed under the Apache License, Version 2.0 (the "License");
//
goog.provide('i18n.input.chrome.inputview.elements.content.CandidateButton');
goog.require('goog.dom.TagName');
goog.require('goog.dom.classlist');
goog.require('goog.style');
goog.require('i18n.input.chrome.inputview.Css');
goog.require('i18n.input.chrome.inputview.elements.Element');
goog.scope(function() {
var ElementType = i18n.input.chrome.inputview.elements.ElementType;
var Css = i18n.input.chrome.inputview.Css;
/**
* The icon button in the candidate view.
*
* @param {string} id .
* @param {ElementType} type .
* @param {string} iconCss .
* @param {string} text .
* @param {!goog.events.EventTarget=} opt_eventTarget .
* @constructor
* @extends {i18n.input.chrome.inputview.elements.Element}
*/
i18n.input.chrome.inputview.elements.content.CandidateButton = function(
id, type, iconCss, text, opt_eventTarget) {
goog.base(this, id, type, opt_eventTarget);
/** @type {string} */
this.text = text;
/** @type {string} */
this.iconCss = iconCss;
};
var CandidateButton = i18n.input.chrome.inputview.elements.content.
CandidateButton;
goog.inherits(CandidateButton, i18n.input.chrome.inputview.elements.Element);
/** @type {!Element} */
CandidateButton.prototype.iconCell;
/** @type {!Element} */
CandidateButton.prototype.separatorCell;
/** @override */
CandidateButton.prototype.createDom = function() {
goog.base(this, 'createDom');
var dom = this.getDomHelper();
var elem = this.getElement();
goog.dom.classlist.addAll(elem, [Css.CANDIDATE_INTER_CONTAINER,
Css.CANDIDATE_BUTTON]);
this.separatorCell = this.createSeparator_();
this.iconCell = dom.createDom(goog.dom.TagName.DIV, Css.TABLE_CELL);
dom.appendChild(elem, this.iconCell);
var iconElem = dom.createDom(goog.dom.TagName.DIV, Css.INLINE_DIV);
if (this.iconCss) {
goog.dom.classlist.add(iconElem, this.iconCss);
}
if (this.text) {
dom.setTextContent(iconElem, this.text);
}
dom.appendChild(this.iconCell, iconElem);
};
/**
* Creates a separator.
*
* @private
*/
CandidateButton.prototype.createSeparator_ = function() {
var dom = this.getDomHelper();
var tableCell = dom.createDom(goog.dom.TagName.DIV,
i18n.input.chrome.inputview.Css.TABLE_CELL);
var separator = dom.createDom(goog.dom.TagName.DIV,
i18n.input.chrome.inputview.Css.CANDIDATE_SEPARATOR);
separator.style.height = '32%';
dom.appendChild(tableCell, separator);
dom.appendChild(this.getElement(), tableCell);
return tableCell;
};
/** @override */
CandidateButton.prototype.resize = function(width, height) {
goog.style.setSize(this.separatorCell, 1, height);
goog.style.setSize(this.iconCell, width - 1, height);
goog.base(this, 'resize', width, height);
};
}); // goog.scope
// Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
// limitations under the License.
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// distributed under the License is distributed on an "AS-IS" BASIS,
// Unless required by applicable law or agreed to in writing, software
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// You may obtain a copy of the License at
// you may not use this file except in compliance with the License.
// Licensed under the Apache License, Version 2.0 (the "License");
//
goog.provide('i18n.input.chrome.inputview.elements.content.Character');
goog.require('goog.dom');
goog.require('goog.dom.classlist');
goog.require('goog.style');
goog.require('i18n.input.chrome.inputview.Css');
goog.require('i18n.input.chrome.inputview.elements.Element');
goog.require('i18n.input.chrome.inputview.elements.ElementType');
goog.require('i18n.input.chrome.inputview.util');
goog.scope(function() {
/**
* The letter in the soft key.
*
* @param {string} id The id.
* @param {!i18n.input.chrome.inputview.elements.content.CharacterModel} model
* The character model.
* @param {boolean} isRTL Whether the character is shown in a RTL layout.
* @constructor
* @extends {i18n.input.chrome.inputview.elements.Element}
*/
i18n.input.chrome.inputview.elements.content.Character = function(
id, model, isRTL) {
goog.base(this, id, i18n.input.chrome.inputview.elements.ElementType.
CHARACTER);
/**
* The model.
*
* @type {!i18n.input.chrome.inputview.elements.content.CharacterModel}
* @private
*/
this.characterModel_ = model;
/**
* Whether the character is shown in a RTL layout.
*
* @type {boolean}
* @private
*/
this.isRTL_ = isRTL;
};
goog.inherits(i18n.input.chrome.inputview.elements.content.Character,
i18n.input.chrome.inputview.elements.Element);
var Character = i18n.input.chrome.inputview.elements.content.Character;
/**
* The padding.
*
* @type {number}
* @private
*/
Character.PADDING_ = 2;
/** @override */
Character.prototype.createDom = function() {
goog.base(this, 'createDom');
var elem = this.getElement();
var dom = this.getDomHelper();
this.getElement()['view'] = null;
var character = this.characterModel_.getContent();
dom.appendChild(elem, dom.createTextNode(character));
goog.dom.classlist.add(elem, i18n.input.chrome.inputview.Css.CHARACTER);
if (/[0-9]/.test(character)) {
// Digits 0-9 looks bigger than it should be, so decrease the font-size for
// them.
goog.dom.classlist.add(elem,
i18n.input.chrome.inputview.Css.DIGIT_CHARACTER);
}
elem.style.direction = this.isRTL_ ? 'rtl' : 'ltr';
};
/**
* Reposition the character.
*
* @private
*/
Character.prototype.reposition_ = function() {
var width = this.width;
var height = this.height;
var size = goog.style.getSize(this.getElement());
var paddingVertical;
var paddingHorizontal;
if (this.characterModel_.isHorizontalAlignCenter()) {
paddingHorizontal = Math.floor((width - size.width) / 2);
} else {
paddingHorizontal = Character.PADDING_;
}
if (this.characterModel_.isVerticalAlignCenter()) {
paddingVertical = Math.floor((height - size.height) / 2);
} else {
paddingVertical = Character.PADDING_;
}
var attributes = this.characterModel_.getPositionAttribute();
var elem = this.getElement();
elem.style[attributes[0]] = paddingVertical + 'px';
elem.style[attributes[1]] = paddingHorizontal + 'px';
};
/**
* Highlights the letter or not.
*/
Character.prototype.highlight = function() {
if (this.characterModel_.isHighlighted()) {
goog.dom.classlist.add(this.getElement(),
i18n.input.chrome.inputview.Css.CHARACTER_HIGHLIGHT);
} else {
goog.dom.classlist.remove(this.getElement(),
i18n.input.chrome.inputview.Css.CHARACTER_HIGHLIGHT);
}
};
/**
* Updates the content.
*/
Character.prototype.updateContent = function() {
var ch = this.characterModel_.getContent();
goog.dom.setTextContent(this.getElement(),
i18n.input.chrome.inputview.util.getVisibleCharacter(ch));
};
/** @override */
Character.prototype.setVisible = function(visibility) {
this.getElement().style.display = visibility ? 'inline-block' : 'none';
};
/** @override */
Character.prototype.resize = function(width, height) {
goog.base(this, 'resize', width, height);
this.update();
};
/** @override */
Character.prototype.update = function() {
this.highlight();
this.reposition_();
this.updateContent();
this.setVisible(this.characterModel_.isVisible());
};
/**
* Gets the letter.
*
* @return {string} The letter.
*/
Character.prototype.getContent = function() {
return this.characterModel_.getContent();
};
/** @override */
Character.prototype.isVisible = function() {
return this.characterModel_.isVisible();
};
/**
* True if this character is highlighted.
*
* @return {boolean} True if this character is highlighted.
*/
Character.prototype.isHighlighted = function() {
return this.characterModel_.isHighlighted();
};
}); // goog.scope
// Copyright 2014 The ChromeOS IME Authors. All Rights Reserved.
// limitations under the License.
// See the License for the specific language governing permissions and
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// distributed under the License is distributed on an "AS-IS" BASIS,
// Unless required by applicable law or agreed to in writing, software
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// You may obtain a copy of the License at
// you may not use this file except in compliance with the License.
// Licensed under the Apache License, Version 2.0 (the "License");
//
goog.provide('i18n.input.chrome.inputview.elements.content.MenuKey');
goog.require('i18n.input.chrome.inputview.elements.content.FunctionalKey');
goog.scope(function() {
/**
* The three dots menu key.
*
* @param {string} id The id.
* @param {!i18n.input.chrome.inputview.elements.ElementType} type The element
* type.
* @param {string} text The text.
* @param {string} iconCssClass The css class for the icon.
* @param {string} toKeyset The keyset id.
* @param {goog.events.EventTarget=} opt_eventTarget The event target.
* @constructor
* @extends {i18n.input.chrome.inputview.elements.content.FunctionalKey}
*/
i18n.input.chrome.inputview.elements.content.MenuKey = function(id, type,
text, iconCssClass, toKeyset, opt_eventTarget) {
goog.base(this, id, type, text, iconCssClass, opt_eventTarget);
/**
* The id of the key set to go after this switcher key in menu is pressed.
*
* @type {string}
*/
this.toKeyset = toKeyset;
};
goog.inherits(i18n.input.chrome.inputview.elements.content.MenuKey,
i18n.input.chrome.inputview.elements.content.FunctionalKey);
var MenuKey = i18n.input.chrome.inputview.elements.content.MenuKey;
/** @override */
MenuKey.prototype.resize = function(width,
height) {
goog.base(this, 'resize', width, height);
// TODO: override width to remove space between menu key and the
// following key.
};
}); // goog.scope
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment