Commit 5e3c6de8 authored by Anastasia Helfinstein's avatar Anastasia Helfinstein Committed by Commit Bot

[Switch Access] Restructure selection callback for clarity.

This is a pure refactor.

Bug: None
Change-Id: I6b527024ef2a3d79b6c86e8c66b7d9c4853afd68
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1841740Reviewed-by: default avatarAkihiro Ota <akihiroota@chromium.org>
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Cr-Commit-Position: refs/heads/master@{#703507}
parent db6bbb5d
......@@ -69,12 +69,10 @@ class MenuManager {
this.selectionExists_ = false;
/**
* Callback for reloading the menu when the text selection has changed.
* Bind creates a new function, so this function is saved as a field to
* add and remove the selection event listener properly.
* @private {function(chrome.automation.AutomationEvent): undefined}
* A function to be called when the menu exits.
* @private {?function()}
*/
this.onSelectionChanged_ = this.reloadMenuForSelectionChange_.bind(this);
this.onExitCallback_ = null;
/**
* Keeps track of when the clipboard is empty.
......@@ -150,16 +148,14 @@ class MenuManager {
this.closeCurrentMenu_();
this.inMenu_ = false;
if (window.switchAccess.improvedTextInputEnabled() &&
this.menuOriginNode_) {
this.menuOriginNode_.removeEventListener(
chrome.automation.EventType.TEXT_SELECTION_CHANGED,
this.onSelectionChanged_, false /** Don't use capture. */);
if (this.onExitCallback_) {
this.onExitCallback_();
this.onExitCallback_ = null;
}
this.menuOriginNode_ = null;
chrome.accessibilityPrivate.setSwitchAccessMenuState(
false /** Hide the menu. */, RectHelper.ZERO_RECT, 0);
false /** should_show */, RectHelper.ZERO_RECT, 0);
}
/**
......@@ -227,9 +223,15 @@ class MenuManager {
this.menuOriginNode_ = navNode;
if (!shouldReloadMenu && window.switchAccess.improvedTextInputEnabled()) {
const callback = this.reloadMenuForSelectionChange_.bind(this);
this.menuOriginNode_.addEventListener(
chrome.automation.EventType.TEXT_SELECTION_CHANGED,
this.onSelectionChanged_, false /** Don't use capture. */);
chrome.automation.EventType.TEXT_SELECTION_CHANGED, callback,
false /** use_capture */);
this.onExitCallback_ = this.menuOriginNode_.removeEventListener.bind(
this.menuOriginNode_,
chrome.automation.EventType.TEXT_SELECTION_CHANGED, callback,
false /** use_capture */);
}
if (shouldReloadMenu && actionNode) {
......
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