Commit c80d9919 authored by Rose Garcia's avatar Rose Garcia Committed by Commit Bot

Merging basic text selection into text_navigation_manager.js.

Merged the basic text selection functionality from the text_input_manager.js to text_navigation_manager.js. Also added variables to keep track of the start and end node for the selection and and added functionality to hide the set selection end button is the start of the selection is not set and show it as soon as the start is set.

Bug: 982004
Change-Id: I94b1e1dd3bf3636034276d0ee7db8c95a5711df1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1707036Reviewed-by: default avatarAnastasia Helfinstein <anastasi@google.com>
Commit-Queue: Rose Garcia <rosalindag@google.com>
Cr-Commit-Position: refs/heads/master@{#678935}
parent 0f25ee54
...@@ -102,6 +102,44 @@ class MenuManager { ...@@ -102,6 +102,44 @@ class MenuManager {
} }
} }
/**
* Reload the menu.
* @param {!chrome.automation.AutomationNode} navNode the node for which the
* menu is to be displayed.
* @private
*/
reloadMenu_(navNode) {
const actionNode = this.node_;
if (!this.menuPanel_) {
console.log('Error: Menu panel has not loaded.');
return;
}
const actions = this.getActionsForNode_(navNode);
if (actions === null) {
return;
}
this.inMenu_ = true;
if (actions !== this.actions_) {
this.actions_ = actions;
this.menuPanel_.setActions(this.actions_);
}
if (navNode.location) {
chrome.accessibilityPrivate.setSwitchAccessMenuState(
true /* show menu */, navNode.location, actions.length);
} else {
console.log('Unable to show Switch Access menu.');
}
if (actionNode) {
this.node_ = actionNode;
this.updateFocusRing_();
}
}
/** /**
* Exits the menu. * Exits the menu.
*/ */
...@@ -285,8 +323,10 @@ class MenuManager { ...@@ -285,8 +323,10 @@ class MenuManager {
actions.push(SAConstants.MenuAction.MOVE_FORWARD_ONE_WORD_OF_TEXT); actions.push(SAConstants.MenuAction.MOVE_FORWARD_ONE_WORD_OF_TEXT);
actions.push(SAConstants.MenuAction.MOVE_UP_ONE_LINE_OF_TEXT); actions.push(SAConstants.MenuAction.MOVE_UP_ONE_LINE_OF_TEXT);
actions.push(SAConstants.MenuAction.SELECT_START); actions.push(SAConstants.MenuAction.SELECT_START);
if (this.navigationManager_.selectionStarted()) {
actions.push(SAConstants.MenuAction.SELECT_END); actions.push(SAConstants.MenuAction.SELECT_END);
} }
}
} else if (actions.length > 0) { } else if (actions.length > 0) {
actions.push(SAConstants.MenuAction.SELECT); actions.push(SAConstants.MenuAction.SELECT);
} }
...@@ -375,10 +415,13 @@ class MenuManager { ...@@ -375,10 +415,13 @@ class MenuManager {
exitAfterAction = false; exitAfterAction = false;
break; break;
case SAConstants.MenuAction.SELECT_START: case SAConstants.MenuAction.SELECT_START:
this.navigationManager_.textInputManager().setSelectStart(); this.navigationManager_.setSelectStart();
this.reloadMenu_(this.navigationManager_.currentNode());
exitAfterAction = false;
break; break;
case SAConstants.MenuAction.SELECT_END: case SAConstants.MenuAction.SELECT_END:
this.navigationManager_.textInputManager().setSelectEnd(); this.navigationManager_.setSelectEnd();
exitAfterAction = false;
break; break;
default: default:
this.navigationManager_.performActionOnCurrentNode(action); this.navigationManager_.performActionOnCurrentNode(action);
......
...@@ -35,7 +35,7 @@ class NavigationManager { ...@@ -35,7 +35,7 @@ class NavigationManager {
* Handles text navigation actions. * Handles text navigation actions.
* @private {!TextNavigationManager} * @private {!TextNavigationManager}
*/ */
this.textNavigationManager_ = new TextNavigationManager(); this.textNavigationManager_ = new TextNavigationManager(this);
/** /**
* The desktop node. * The desktop node.
...@@ -105,19 +105,12 @@ class NavigationManager { ...@@ -105,19 +105,12 @@ class NavigationManager {
/** /**
* Get the currently highlighted node. * Get the currently highlighted node.
* @return {!chrome.automation.AutomationNode} the current node
*/ */
currentNode() { currentNode() {
return this.node_; return this.node_;
} }
/**
* TODO(rosalindag): get rid of this after moving text selection to new file
* Get the text_input_manager.
*/
textInputManager() {
return this.textInputManager_;
}
/** /**
* Open the Switch Access menu for the currently highlighted node. * Open the Switch Access menu for the currently highlighted node.
*/ */
...@@ -318,6 +311,32 @@ class NavigationManager { ...@@ -318,6 +311,32 @@ class NavigationManager {
this.textNavigationManager_.moveUpOneLine(); this.textNavigationManager_.moveUpOneLine();
} }
/**
* Sets the selectionStart variable based on the selection of the current
* node.
* @public
*/
setSelectStart() {
this.textNavigationManager_.setSelectStart();
}
/**
* Sets the selectionEnd variable based on the selection of the current node.
* @public
*/
setSelectEnd() {
this.textNavigationManager_.setSelectEnd();
}
/**
* Returns whether or not the first selection index has been set.
* @return {boolean}
* @public
*/
selectionStarted() {
return this.textNavigationManager_.isSelStartIndexSet();
}
/** /**
* Perform the default action for the currently highlighted node. If the node * Perform the default action for the currently highlighted node. If the node
* is the current scope, go back to the previous scope. If the node is a group * is the current scope, go back to the previous scope. If the node is a group
......
...@@ -2,9 +2,6 @@ ...@@ -2,9 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// Constant to indicate selection index is not set.
const NO_SELECTION = -1;
/** /**
* Class to handle text input for improved accuracy and efficiency. * Class to handle text input for improved accuracy and efficiency.
*/ */
...@@ -26,12 +23,6 @@ class TextInputManager { ...@@ -26,12 +23,6 @@ class TextInputManager {
color: SAConstants.Focus.PRIMARY_COLOR, color: SAConstants.Focus.PRIMARY_COLOR,
secondaryColor: SAConstants.Focus.SECONDARY_COLOR secondaryColor: SAConstants.Focus.SECONDARY_COLOR
}; };
/** @private {number} */
this.selectionStart_ = NO_SELECTION;
/** @private {number} */
this.selectionEnd_ = NO_SELECTION;
} }
/** /**
...@@ -140,52 +131,4 @@ class TextInputManager { ...@@ -140,52 +131,4 @@ class TextInputManager {
this.textInputFocusRing_.rects = []; this.textInputFocusRing_.rects = [];
chrome.accessibilityPrivate.setFocusRings([this.textInputFocusRing_]); chrome.accessibilityPrivate.setFocusRings([this.textInputFocusRing_]);
} }
/**
* IN PROGRESS TEXT SELECTION BELOW
* TODO(rosalindag): Move this into the text navigation file when
* creation of that file is merged
*/
/**
* TODO(rosalindag): Check for value is -1 for selectionStart and
* selectionEnd and handle error.
*
* TODO(rosalindag): Add variables to pass into anchorObject and focusObject.
*
* Sets the selection using the selectionStart and selectionEnd
* as the offset input for setDocumentSelection and the parameter
* textNode as the object input for setDocumentSelection.
* @param {!chrome.automation.AutomationNode} textNode
* @private
*/
setSelection_(textNode) {
chrome.automation.setDocumentSelection({
anchorObject: textNode,
anchorOffset: this.selectionStart_,
focusObject: textNode,
focusOffset: this.selectionEnd_
});
}
/**
* Sets the selectionStart variable based on the selection of the current
* node.
* @public
*/
setSelectStart() {
var textNode = this.navigationManager_.currentNode();
this.selectionStart_ = textNode.textSelStart;
}
/**
* Sets the selectionEnd variable based on the selection of the current node.
* @public
*/
setSelectEnd() {
var textNode = this.navigationManager_.currentNode();
this.selectionEnd_ = textNode.textSelEnd;
this.setSelection_(textNode);
}
} }
...@@ -2,11 +2,32 @@ ...@@ -2,11 +2,32 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
// Constant to indicate selection index is not set.
const NO_SELECT_INDEX = -1;
/** /**
* Class to handle navigating text. Currently, only * Class to handle navigating text. Currently, only
* navigation of editable text fields is supported. * navigation and selection in editable text fields is supported.
*/ */
class TextNavigationManager { class TextNavigationManager {
/** @param {!NavigationManager} navigationManager */
constructor(navigationManager) {
/** @private {!NavigationManager} */
this.navigationManager_ = navigationManager;
/** @private {number} */
this.selectionStartIndex_ = NO_SELECT_INDEX;
/** @private {number} */
this.selectionEndIndex_ = NO_SELECT_INDEX;
/** @private {chrome.automation.AutomationNode} */
this.selectionStartObject_;
/** @private {chrome.automation.AutomationNode} */
this.selectionEndObject_;
}
/** /**
* Jumps to the beginning of the text field (does nothing * Jumps to the beginning of the text field (does nothing
* if already at the beginning). * if already at the beginning).
...@@ -109,4 +130,89 @@ class TextNavigationManager { ...@@ -109,4 +130,89 @@ class TextNavigationManager {
modifiers: modifiers modifiers: modifiers
}); });
} }
/**
* TODO(rosalindag): Work on text selection functionality below.
*/
/**
* Get the currently selected node.
* @private
* @return {!chrome.automation.AutomationNode}
*/
node_() {
return this.navigationManager_.currentNode();
}
/**
* Sets the selection using the selectionStart and selectionEnd
* as the offset input for setDocumentSelection and the parameter
* textNode as the object input for setDocumentSelection.
* @private
*/
setSelection_() {
if (this.selectionStartIndex_ == NO_SELECT_INDEX ||
this.selectionEndIndex_ == NO_SELECT_INDEX) {
console.log('Selection bounds are not set properly.');
} else {
chrome.automation.setDocumentSelection({
anchorObject: this.selectionStartObject_,
anchorOffset: this.selectionStartIndex_,
focusObject: this.selectionEndObject_,
focusOffset: this.selectionEndIndex_
});
}
}
/**
* Returns the selection start index.
* @return {boolean}
* @public
*/
isSelStartIndexSet() {
return this.selectionStartIndex_ !== NO_SELECT_INDEX;
}
/**
* Returns either the selection start index or the selection end index of the
* node based on the getStart param.
* @param {!chrome.accessibilityPrivate.SyntheticKeyboardModifiers} node
* @param {boolean} getStart
* @return {number} selection start if getStart is true otherwise selection
* end
* @private
*/
getSelectionIndexFromNode_(node, getStart) {
let indexFromNode = NO_SELECT_INDEX;
if (getStart) {
indexFromNode = node.textSelStart;
} else {
indexFromNode = node.textSelEnd;
}
if (indexFromNode === undefined) {
return NO_SELECT_INDEX;
}
return indexFromNode;
}
/**
* Sets the selectionStart variable based on the selection of the current
* node.
* @public
*/
setSelectStart() {
this.selectionStartObject_ = this.node_();
this.selectionStartIndex_ =
this.getSelectionIndexFromNode_(this.selectionStartObject_, true);
}
/**
* Sets the selectionEnd variable based on the selection of the current node.
* @public
*/
setSelectEnd() {
this.selectionEndObject_ = this.node_();
this.selectionEndIndex_ =
this.getSelectionIndexFromNode_(this.selectionEndObject_, false);
this.setSelection_();
}
} }
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