| Index: third_party/google_input_tools/src/chrome/os/inputview/elements/content/menuview.js
|
| diff --git a/third_party/google_input_tools/src/chrome/os/inputview/elements/content/menuview.js b/third_party/google_input_tools/src/chrome/os/inputview/elements/content/menuview.js
|
| index 6cecdaae5d53bf4cef657573bf4e75ca902e42f3..3364504bc2cd777fd421187901ff2d26f7ec9694 100644
|
| --- a/third_party/google_input_tools/src/chrome/os/inputview/elements/content/menuview.js
|
| +++ b/third_party/google_input_tools/src/chrome/os/inputview/elements/content/menuview.js
|
| @@ -18,33 +18,58 @@ goog.require('goog.a11y.aria.State');
|
| goog.require('goog.array');
|
| goog.require('goog.dom.TagName');
|
| goog.require('goog.dom.classlist');
|
| +goog.require('goog.log');
|
| goog.require('goog.style');
|
| +goog.require('i18n.input.chrome.ElementType');
|
| 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.elements.content.MenuItem');
|
| goog.require('i18n.input.chrome.inputview.util');
|
|
|
|
|
|
|
| goog.scope(function() {
|
| -var ElementType = i18n.input.chrome.inputview.elements.ElementType;
|
| +var ElementType = i18n.input.chrome.ElementType;
|
| var MenuItem = i18n.input.chrome.inputview.elements.content.MenuItem;
|
| var Css = i18n.input.chrome.inputview.Css;
|
|
|
|
|
| /**
|
| * The view for IME switcher, layout switcher and settings menu popup.
|
| + * TODO(bshe): Refactor MenuView to extend AltDataView.
|
| *
|
| * @param {goog.events.EventTarget=} opt_eventTarget The parent event target.
|
| * @constructor
|
| * @extends {i18n.input.chrome.inputview.elements.Element}
|
| */
|
| -// TODO: Refactor MenuView to extend AltDataView.
|
| i18n.input.chrome.inputview.elements.content.MenuView = function(
|
| opt_eventTarget) {
|
| goog.base(this, '', ElementType.MENU_VIEW, opt_eventTarget);
|
|
|
| + /**
|
| + * 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.
|
| + *
|
| + * @private {!Element}
|
| + */
|
| + this.coverElement_ = this.getDomHelper().createDom(goog.dom.TagName.DIV,
|
| + Css.ALTDATA_COVER);
|
| +
|
| + /**
|
| + * The key triggered this menu view.
|
| + *
|
| + * @private {i18n.input.chrome.inputview.elements.content.SoftKey}
|
| + */
|
| + this.triggeredBy_ = null;
|
| +
|
| + /**
|
| + * Logger for MenuView.
|
| + * @private {goog.log.Logger}
|
| + */
|
| + this.logger_ = goog.log.getLogger(
|
| + 'i18n.input.chrome.inputview.elements.content.MenuView');
|
| +
|
| this.pointerConfig.stopEventPropagation = false;
|
| this.pointerConfig.preventDefault = false;
|
| };
|
| @@ -63,9 +88,7 @@ MenuView.Command = {
|
| SWITCH_KEYSET: 1,
|
| OPEN_EMOJI: 2,
|
| OPEN_HANDWRITING: 3,
|
| - OPEN_SETTING: 4,
|
| - FLOATING: 5,
|
| - DOCKING: 6
|
| + OPEN_SETTING: 4
|
| };
|
|
|
|
|
| @@ -77,16 +100,16 @@ MenuView.Command = {
|
| *
|
| * @private {number}
|
| */
|
| -MenuView.VISIBLE_ITEMS_ = 4;
|
| +MenuView.MAX_VISIBLE_ITEMS_ = 4;
|
|
|
|
|
| /**
|
| - * Same as VISIBLE_ITEM_ but for a11y keyboard. A11y virtual keyboard is shorter
|
| - * than normal keyboard so 3 is used.
|
| + * Same as MAX_VISIBLE_ITEM_ but for a11y keyboard. A11y virtual keyboard is
|
| + * shorter than normal keyboard so 3 is used.
|
| *
|
| * @private {number}
|
| */
|
| -MenuView.VISIBLE_ITEMS_A11Y_ = 3;
|
| +MenuView.MAX_VISIBLE_ITEMS_A11Y_ = 3;
|
|
|
|
|
| /**
|
| @@ -95,7 +118,7 @@ MenuView.VISIBLE_ITEMS_A11Y_ = 3;
|
| *
|
| * @private {number}
|
| */
|
| -MenuView.WIDTH_ = 275;
|
| +MenuView.WIDTH_PX_ = 275;
|
|
|
|
|
| /**
|
| @@ -103,7 +126,7 @@ MenuView.WIDTH_ = 275;
|
| *
|
| * @private {number}
|
| */
|
| -MenuView.PADDING_LEFT_ = 25;
|
| +MenuView.PADDING_LEFT_PX_ = 25;
|
|
|
|
|
| /**
|
| @@ -111,17 +134,7 @@ MenuView.PADDING_LEFT_ = 25;
|
| *
|
| * @private {number}
|
| */
|
| -MenuView.LIST_ITEM_HEIGHT_ = 45;
|
| -
|
| -
|
| -/**
|
| - * 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.
|
| - *
|
| - * @private {!Element}
|
| - */
|
| -MenuView.prototype.coverElement_;
|
| +MenuView.LIST_ITEM_HEIGHT_PX_ = 45;
|
|
|
|
|
| /** @override */
|
| @@ -131,7 +144,6 @@ MenuView.prototype.createDom = function() {
|
| var dom = this.getDomHelper();
|
| var elem = this.getElement();
|
| goog.dom.classlist.add(elem, Css.MENU_VIEW);
|
| - this.coverElement_ = dom.createDom(goog.dom.TagName.DIV, Css.ALTDATA_COVER);
|
| goog.a11y.aria.setState(this.coverElement_, goog.a11y.aria.State.LABEL,
|
| chrome.i18n.getMessage('DISMISS_MENU'));
|
| dom.appendChild(document.body, this.coverElement_);
|
| @@ -141,51 +153,41 @@ MenuView.prototype.createDom = function() {
|
| };
|
|
|
|
|
| -/** @override */
|
| -MenuView.prototype.enterDocument = function() {
|
| - goog.base(this, 'enterDocument');
|
| -
|
| - goog.style.setElementShown(this.getElement(), false);
|
| -};
|
| -
|
| -
|
| /**
|
| * Shows the menu view.
|
| * @param {!i18n.input.chrome.inputview.elements.content.SoftKey} key The key
|
| - * triggerred this menu view.
|
| + * triggered this menu view.
|
| * @param {!string} currentKeysetId The keyset ID that this menu key belongs to.
|
| * @param {boolean} isCompact True if the keyset that owns the menu key is a
|
| * compact layout.
|
| * @param {boolean} enableCompactLayout True if the keyset that owns the menu
|
| * key enabled compact layout.
|
| * @param {!string} currentInputMethod The current input method ID.
|
| - * @param {?Array.<Object<string, string, string>>} inputMethods The list of
|
| + * @param {?Array.<!Object<string, string, string>>} inputMethods The list of
|
| * activated input methods.
|
| * @param {boolean} hasHwt Whether to add handwriting button.
|
| * @param {boolean} enableSettings Whether to add a link to settings page.
|
| * @param {boolean} hasEmoji Whether to enable emoji.
|
| * @param {boolean} isA11y Whether the current keyboard is a11y-optimized.
|
| - * @param {boolean} enableFVK Whether to enable floating virtual keyboard.
|
| - * @param {boolean} isFloating Whether the virtual keyboard is floating.
|
| */
|
| MenuView.prototype.show = function(key, currentKeysetId, isCompact,
|
| enableCompactLayout, currentInputMethod, inputMethods, hasHwt,
|
| - enableSettings, hasEmoji, isA11y, enableFVK, isFloating) {
|
| - var ElementType = i18n.input.chrome.inputview.elements.ElementType;
|
| + enableSettings, hasEmoji, isA11y) {
|
| + var ElementType = i18n.input.chrome.ElementType;
|
| var dom = this.getDomHelper();
|
| if (key.type != ElementType.MENU_KEY) {
|
| - console.error('Unexpected key triggered the menu view. Key type = ' +
|
| - key.type + '.');
|
| + goog.log.warning(this.logger_,
|
| + 'Unexpected key triggered the menu view. Key type = ' + key.type + '.');
|
| return;
|
| }
|
| - this.triggeredBy = key;
|
| + this.triggeredBy_ = key;
|
| var coordinate = goog.style.getClientPosition(key.getElement());
|
| var x = coordinate.x;
|
| // y is the maximal height that menu view can have.
|
| var y = coordinate.y;
|
|
|
| goog.style.setElementShown(this.getElement(), true);
|
| - // TODO: May not need to remove child.
|
| + // TODO(bshe): May not need to remove child.
|
| dom.removeChildren(this.getElement());
|
|
|
| var totalHeight = 0;
|
| @@ -194,29 +196,26 @@ MenuView.prototype.show = function(key, currentKeysetId, isCompact,
|
| totalHeight += this.addLayoutSwitcherItem_(key, currentKeysetId, isCompact,
|
| enableCompactLayout);
|
| if (hasHwt || enableSettings || hasEmoji) {
|
| - totalHeight += this.addFooterItems_(hasHwt, enableSettings, hasEmoji,
|
| - enableFVK, isFloating);
|
| + totalHeight += this.addFooterItems_(hasHwt, enableSettings, hasEmoji);
|
| }
|
|
|
|
|
| var left = x;
|
| - // TODO: Take care of elemTop < 0. A scrollable view is probably needed.
|
| + // TODO(bshe): Take care of elemTop < 0. A scrollable view is probably needed.
|
| var elemTop = y - totalHeight;
|
|
|
| goog.style.setPosition(this.getElement(), left, elemTop);
|
| goog.style.setElementShown(this.coverElement_, true);
|
| - this.triggeredBy.setHighlighted(true);
|
| + this.triggeredBy_.setHighlighted(true);
|
| };
|
|
|
|
|
| -/**
|
| - * Hides the menu view.
|
| - */
|
| +/** Hides the menu view. */
|
| MenuView.prototype.hide = function() {
|
| goog.style.setElementShown(this.getElement(), false);
|
| goog.style.setElementShown(this.coverElement_, false);
|
| - if (this.triggeredBy) {
|
| - this.triggeredBy.setHighlighted(false);
|
| + if (this.triggeredBy_) {
|
| + this.triggeredBy_.setHighlighted(false);
|
| }
|
| };
|
|
|
| @@ -225,7 +224,7 @@ MenuView.prototype.hide = function() {
|
| * Adds the list of activated input methods.
|
| *
|
| * @param {!string} currentInputMethod The current input method ID.
|
| - * @param {?Array.<Object<string, string, string>>} inputMethods The list of
|
| + * @param {?Array.<!Object<string, string, string>>} inputMethods The list of
|
| * activated input methods.
|
| * @param {boolean} isA11y Whether the current keyboard is a11y-optimized.
|
| * @return {number} The height of the ime list container.
|
| @@ -237,15 +236,16 @@ MenuView.prototype.addInputMethodItems_ = function(currentInputMethod,
|
| var container = dom.createDom(goog.dom.TagName.DIV,
|
| Css.IME_LIST_CONTAINER);
|
| var visibleItems = isA11y ?
|
| - MenuView.VISIBLE_ITEMS_A11Y_ : MenuView.VISIBLE_ITEMS_;
|
| + MenuView.MAX_VISIBLE_ITEMS_A11Y_ : MenuView.MAX_VISIBLE_ITEMS_;
|
|
|
| for (var i = 0; i < inputMethods.length; i++) {
|
| var inputMethod = inputMethods[i];
|
| - var listItem = {};
|
| - listItem['indicator'] = inputMethod['indicator'];
|
| - listItem['name'] = inputMethod['name'];
|
| - listItem['command'] =
|
| - [MenuView.Command.SWITCH_IME, inputMethod['id']];
|
| + var listItem = {
|
| + 'indicator': inputMethod['indicator'],
|
| + 'name': inputMethod['name'],
|
| + 'command':
|
| + [MenuView.Command.SWITCH_IME, inputMethod['id']]
|
| + };
|
| var ariaLabel = chrome.i18n.getMessage('SWITCH_TO_KEYBOARD_PREFIX') +
|
| inputMethod['name'];
|
| if (currentInputMethod == inputMethod['id']) {
|
| @@ -259,14 +259,14 @@ MenuView.prototype.addInputMethodItems_ = function(currentInputMethod,
|
| imeItem.check();
|
| }
|
| goog.style.setSize(imeItem.getElement(),
|
| - (MenuView.WIDTH_ + MenuView.PADDING_LEFT_),
|
| - MenuView.LIST_ITEM_HEIGHT_);
|
| + MenuView.WIDTH_PX_ + MenuView.PADDING_LEFT_PX_,
|
| + MenuView.LIST_ITEM_HEIGHT_PX_);
|
| }
|
|
|
| var containerHeight = inputMethods.length > visibleItems ?
|
| - MenuView.LIST_ITEM_HEIGHT_ * visibleItems :
|
| - MenuView.LIST_ITEM_HEIGHT_ * inputMethods.length;
|
| - goog.style.setSize(container, MenuView.WIDTH_ + MenuView.PADDING_LEFT_,
|
| + MenuView.LIST_ITEM_HEIGHT_PX_ * visibleItems :
|
| + MenuView.LIST_ITEM_HEIGHT_PX_ * inputMethods.length;
|
| + goog.style.setSize(container, MenuView.WIDTH_PX_ + MenuView.PADDING_LEFT_PX_,
|
| containerHeight);
|
|
|
| dom.appendChild(this.getElement(), container);
|
| @@ -322,10 +322,10 @@ MenuView.prototype.addLayoutSwitcherItem_ = function(key, currentKeysetId,
|
| chrome.i18n.getMessage('SWITCH_TO_COMPACT_LAYOUT'));
|
| }
|
| layoutSwitcherItem.render(this.getElement());
|
| - goog.style.setSize(layoutSwitcherItem.getElement(), MenuView.WIDTH_,
|
| - MenuView.LIST_ITEM_HEIGHT_);
|
| + goog.style.setSize(layoutSwitcherItem.getElement(), MenuView.WIDTH_PX_,
|
| + MenuView.LIST_ITEM_HEIGHT_PX_);
|
|
|
| - return MenuView.LIST_ITEM_HEIGHT_;
|
| + return MenuView.LIST_ITEM_HEIGHT_PX_;
|
| };
|
|
|
|
|
| @@ -336,19 +336,18 @@ MenuView.prototype.addLayoutSwitcherItem_ = function(key, currentKeysetId,
|
| * @param {boolean} hasHwt Whether to add handwriting button.
|
| * @param {boolean} enableSettings Whether to add settings button.
|
| * @param {boolean} hasEmoji Whether to add emoji button.
|
| - * @param {boolean} enableFVK Whether to add floating virtual keyboard button.
|
| - * @param {boolean} isFloating Whether the virtual keyboard is floating.
|
| * @return {number} The height of the footer.
|
| * @private
|
| */
|
| MenuView.prototype.addFooterItems_ = function(hasHwt, enableSettings,
|
| - hasEmoji, enableFVK, isFloating) {
|
| + hasEmoji) {
|
| var dom = this.getDomHelper();
|
| var footer = dom.createDom(goog.dom.TagName.DIV, Css.MENU_FOOTER);
|
| if (hasEmoji) {
|
| - var emoji = {};
|
| - emoji['iconCssClass'] = Css.MENU_FOOTER_EMOJI_BUTTON;
|
| - emoji['command'] = [MenuView.Command.OPEN_EMOJI];
|
| + var emoji = {
|
| + 'iconCssClass': Css.MENU_FOOTER_EMOJI_BUTTON,
|
| + 'command': [MenuView.Command.OPEN_EMOJI]
|
| + };
|
| var emojiFooter = new MenuItem('emoji', emoji,
|
| MenuItem.Type.FOOTER_ITEM,
|
| chrome.i18n.getMessage('FOOTER_EMOJI_BUTTON'));
|
| @@ -356,9 +355,10 @@ MenuView.prototype.addFooterItems_ = function(hasHwt, enableSettings,
|
| }
|
|
|
| if (hasHwt) {
|
| - var handWriting = {};
|
| - handWriting['iconCssClass'] = Css.MENU_FOOTER_HANDWRITING_BUTTON;
|
| - handWriting['command'] = [MenuView.Command.OPEN_HANDWRITING];
|
| + var handWriting = {
|
| + 'iconCssClass': Css.MENU_FOOTER_HANDWRITING_BUTTON,
|
| + 'command': [MenuView.Command.OPEN_HANDWRITING]
|
| + };
|
| var handWritingFooter = new MenuItem('handwriting', handWriting,
|
| MenuItem.Type.FOOTER_ITEM,
|
| chrome.i18n.getMessage('FOOTER_HANDWRITING_BUTTON'));
|
| @@ -366,58 +366,36 @@ MenuView.prototype.addFooterItems_ = function(hasHwt, enableSettings,
|
| }
|
|
|
| if (enableSettings) {
|
| - var setting = {};
|
| - setting['iconCssClass'] = Css.MENU_FOOTER_SETTING_BUTTON;
|
| - setting['command'] = [MenuView.Command.OPEN_SETTING];
|
| + var setting = {
|
| + 'iconCssClass': Css.MENU_FOOTER_SETTING_BUTTON,
|
| + 'command': [MenuView.Command.OPEN_SETTING]
|
| + };
|
| var settingFooter = new MenuItem('setting', setting,
|
| MenuItem.Type.FOOTER_ITEM,
|
| chrome.i18n.getMessage('FOOTER_SETTINGS_BUTTON'));
|
| settingFooter.render(footer);
|
| }
|
|
|
| - if (enableFVK) {
|
| - var floating = {};
|
| - if (isFloating) {
|
| - floating['iconCssClass'] = Css.MENU_FOOTER_DOCKING_BUTTON;
|
| - floating['command'] = [MenuView.Command.DOCKING];
|
| - var floatingFooter = new MenuItem('dock', floating,
|
| - MenuItem.Type.FOOTER_ITEM,
|
| - chrome.i18n.getMessage('FOOTER_DOCKING_BUTTON'));
|
| - floatingFooter.render(footer);
|
| - } else {
|
| - floating['iconCssClass'] = Css.MENU_FOOTER_FLOATING_BUTTON;
|
| - floating['command'] = [MenuView.Command.FLOATING];
|
| - var floatingFooter = new MenuItem('floating', floating,
|
| - MenuItem.Type.FOOTER_ITEM,
|
| - chrome.i18n.getMessage('FOOTER_FLOATING_BUTTON'));
|
| - floatingFooter.render(footer);
|
| - }
|
| - }
|
| -
|
| // Sets footer itmes' width.
|
| var elems = dom.getChildren(footer);
|
| var len = elems.length;
|
| - var subWidth = Math.ceil((MenuView.WIDTH_ + MenuView.PADDING_LEFT_) / len);
|
| - var i = 0;
|
| - for (; i < len - 1; i++) {
|
| + var subWidth =
|
| + Math.ceil((MenuView.WIDTH_PX_ + MenuView.PADDING_LEFT_PX_) / len);
|
| + for (var i = 0; i < len - 1; i++) {
|
| elems[i].style.width = subWidth + 'px';
|
| }
|
| - elems[i].style.width = (MenuView.WIDTH_ + MenuView.PADDING_LEFT_ -
|
| + elems[len - 1].style.width = (MenuView.WIDTH_PX_ + MenuView.PADDING_LEFT_PX_ -
|
| subWidth * (len - 1)) + 'px';
|
|
|
| dom.appendChild(this.getElement(), footer);
|
| - goog.style.setSize(footer, (MenuView.WIDTH_ + MenuView.PADDING_LEFT_),
|
| - MenuView.LIST_ITEM_HEIGHT_);
|
| + goog.style.setSize(footer, (MenuView.WIDTH_PX_ + MenuView.PADDING_LEFT_PX_),
|
| + MenuView.LIST_ITEM_HEIGHT_PX_);
|
|
|
| - return MenuView.LIST_ITEM_HEIGHT_;
|
| + return MenuView.LIST_ITEM_HEIGHT_PX_;
|
| };
|
|
|
|
|
| -/**
|
| - * Gets the cover element.
|
| - *
|
| - * @return {!Element} The cover element.
|
| - */
|
| +/** @return {!Element} The cover element. */
|
| MenuView.prototype.getCoverElement = function() {
|
| return this.coverElement_;
|
| };
|
| @@ -435,7 +413,7 @@ MenuView.prototype.resize = function(width, height) {
|
|
|
| /** @override */
|
| MenuView.prototype.disposeInternal = function() {
|
| - this.getElement()['view'] = null;
|
| + this.coverElement_['view'] = null;
|
|
|
| goog.base(this, 'disposeInternal');
|
| };
|
|
|