Commit e4e0c4a6 authored by Anastasia Helfinstein's avatar Anastasia Helfinstein Committed by Commit Bot

[Switch Access] Move calculation of text input actions

This is a step towards incorporating Rose and Sophie's code for text
navigation and selection from last summer into the new navigation
paradigm.

Bug: 982004
Change-Id: I4fc4b41b6a151992348e8558eb51cde5172667de
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2076552
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Cr-Commit-Position: refs/heads/master@{#746561}
parent 19a684d7
......@@ -47,24 +47,12 @@ class MenuManager {
*/
this.inMenu_ = false;
/**
* Keeps track of when there's a selection in the current node.
* @private {boolean}
*/
this.selectionExists_ = false;
/**
* A function to be called when the menu exits.
* @private {?function()}
*/
this.onExitCallback_ = null;
/**
* Keeps track of when the clipboard is empty.
* @private {boolean}
*/
this.clipboardHasData_ = false;
/**
* A reference to the Switch Access Menu Panel class.
* @private {PanelInterface}
......@@ -99,11 +87,6 @@ class MenuManager {
*/
this.menuStack_ = [];
if (SwitchAccess.instance.improvedTextInputEnabled()) {
chrome.clipboard.onClipboardDataChanged.addListener(
this.updateClipboardHasData_.bind(this));
}
if (window.menuPanel) {
this.connectMenuPanel(window.menuPanel);
}
......@@ -186,6 +169,14 @@ class MenuManager {
return true;
}
/** Reloads the menu, if it has changed. */
static reloadMenuIfNeeded() {
const manager = MenuManager.instance;
if (manager.menuOriginNode_) {
manager.openMenu_(manager.menuOriginNode_, SAConstants.MenuId.MAIN);
}
}
/**
* Perform the action indicated by the current button.
* @return {boolean} Whether this function had any effect.
......@@ -235,11 +226,9 @@ class MenuManager {
*/
closeCurrentMenu_() {
this.clearFocusRing_();
if (this.node_) {
this.node_ = null;
}
this.menuPanel_.clear();
this.actions_ = [];
this.node_ = null;
this.menuNode_ = null;
}
......@@ -304,44 +293,24 @@ class MenuManager {
getMainMenuActionsForNode_(node) {
const actions = node.actions;
// Add text editing and navigation options.
// TODO(anastasi): Move these actions into the node.
const autoNode = node.automationNode;
if (autoNode && SwitchAccess.instance.improvedTextInputEnabled() &&
SwitchAccessPredicate.isTextInput(autoNode) &&
autoNode.state[StateType.FOCUSED]) {
actions.push(SAConstants.MenuAction.MOVE_CURSOR);
actions.push(SAConstants.MenuAction.SELECT_START);
if (TextNavigationManager.currentlySelecting()) {
actions.push(SAConstants.MenuAction.SELECT_END);
}
if (this.selectionExists_) {
actions.push(SAConstants.MenuAction.CUT);
actions.push(SAConstants.MenuAction.COPY);
}
if (this.clipboardHasData_) {
actions.push(SAConstants.MenuAction.PASTE);
}
}
// If there is at most one available action, perform it by default.
if (actions.length <= 1) {
return null;
}
// Add global actions.
actions.push(SAConstants.MenuAction.SETTINGS);
return actions;
}
/**
* Get the actions applicable for |navNode| from the menu with given
* |menuId|.
* @param {!SAChildNode} navNode The currently selected node, for which the
* menu is being opened.
* @param {SAConstants.MenuId} menuId
* @return {Array<SAConstants.MenuAction>}
* @return {Array<!SAConstants.MenuAction>}
* @private
*/
getMenuActions_(navNode, menuId) {
......@@ -357,7 +326,7 @@ class MenuManager {
/**
* Get the actions in the text navigation submenu.
* @return {!Array<SAConstants.MenuAction>}
* @return {Array<!SAConstants.MenuAction>}
* @private
*/
getTextNavigationActions_() {
......@@ -587,8 +556,8 @@ class MenuManager {
*/
reloadMenuForSelectionChange_() {
const newSelectionState = this.nodeHasSelection_();
if (this.selectionExists_ != newSelectionState) {
this.selectionExists_ = newSelectionState;
if (TextNavigationManager.selectionExists != newSelectionState) {
TextNavigationManager.selectionExists = newSelectionState;
if (this.menuOriginNode_ && !TextNavigationManager.currentlySelecting()) {
const currentMenuId = this.menuPanel_.currentMenuId();
if (currentMenuId) {
......@@ -620,19 +589,6 @@ class MenuManager {
}
}
/**
* TODO(rosalindag): Add functionality to catch when clipboardHasData_ needs
* to be set to false.
* Set the clipboardHasData variable to true and reload the menu.
* @private
*/
updateClipboardHasData_() {
this.clipboardHasData_ = true;
if (this.menuOriginNode_) {
this.openMenu_(this.menuOriginNode_, SAConstants.MenuId.MAIN);
}
}
/**
* Send a message to the menu to update the focus ring around the current
* node.
......
......@@ -30,6 +30,22 @@ class EditableTextNode extends NodeWrapper {
actions.push(SAConstants.MenuAction.OPEN_KEYBOARD);
actions.push(SAConstants.MenuAction.DICTATION);
if (SwitchAccess.instance.improvedTextInputEnabled() &&
this.automationNode.state[StateType.FOCUSED]) {
actions.push(SAConstants.MenuAction.MOVE_CURSOR);
actions.push(SAConstants.MenuAction.SELECT_START);
if (TextNavigationManager.currentlySelecting()) {
actions.push(SAConstants.MenuAction.SELECT_END);
}
if (TextNavigationManager.selectionExists) {
actions.push(SAConstants.MenuAction.CUT);
actions.push(SAConstants.MenuAction.COPY);
}
if (TextNavigationManager.clipboardHasData) {
actions.push(SAConstants.MenuAction.PASTE);
}
}
return actions;
}
......
......@@ -26,6 +26,23 @@ class TextNavigationManager {
/** @private {function(chrome.automation.AutomationEvent): undefined} */
this.selectionListener_ = this.onNavChange_.bind(this);
/**
* Keeps track of when there's a selection in the current node.
* @private {boolean}
*/
this.selectionExists_ = false;
/**
* Keeps track of when the clipboard is empty.
* @private {boolean}
*/
this.clipboardHasData_ = false;
if (SwitchAccess.instance.improvedTextInputEnabled()) {
chrome.clipboard.onClipboardDataChanged.addListener(
this.updateClipboardHasData_.bind(this));
}
}
static initialize() {
......@@ -160,6 +177,58 @@ class TextNavigationManager {
manager.manageNavigationListener_(false /** Removing listener */);
manager.selectionStartIndex_ = TextNavigationManager.NO_SELECT_INDEX;
manager.selectionEndIndex_ = TextNavigationManager.NO_SELECT_INDEX;
if (manager.currentlySelecting_) {
manager.setupDynamicSelection_(true /* resetCursor */);
}
EventHelper.simulateKeyPress(EventHelper.KeyCode.DOWN_ARROW);
}
/** @return {boolean} */
static get clipboardHasData() {
return TextNavigationManager.instance.clipboardHasData_;
}
/** @return {boolean} */
static get selectionExists() {
return TextNavigationManager.instance.selectionExists_;
}
/** @param {boolean} newVal */
static set selectionExists(newVal) {
TextNavigationManager.instance.selectionExists_ = newVal;
}
/**
* Returns the selection end index.
* @return {number}
*/
getSelEndIndex() {
return this.selectionEndIndex_;
}
/**
* Reset the selectionStartIndex to NO_SELECT_INDEX.
*/
resetSelStartIndex() {
this.selectionStartIndex_ = TextNavigationManager.NO_SELECT_INDEX;
}
/**
* Returns the selection start index.
* @return {number}
*/
getSelStartIndex() {
return this.selectionStartIndex_;
}
/**
* Sets the selection start index.
* @param {number} startIndex
* @param {!chrome.automation.AutomationNode} textNode
*/
setSelStartIndexAndNode(startIndex, textNode) {
this.selectionStartIndex_ = startIndex;
this.selectionStartObject_ = textNode;
}
/**
......@@ -293,6 +362,17 @@ class TextNavigationManager {
}
this.manageNavigationListener_(true /** Add the listener */);
}
/*
* TODO(rosalindag): Add functionality to catch when clipboardHasData_ needs
* to be set to false.
* Set the clipboardHasData variable to true and reload the menu.
* @private
*/
updateClipboardHasData_() {
this.clipboardHasData_ = true;
MenuManager.reloadMenuIfNeeded();
}
}
// Constant to indicate selection index is not set.
......
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