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 { ...@@ -69,12 +69,10 @@ class MenuManager {
this.selectionExists_ = false; this.selectionExists_ = false;
/** /**
* Callback for reloading the menu when the text selection has changed. * A function to be called when the menu exits.
* Bind creates a new function, so this function is saved as a field to * @private {?function()}
* add and remove the selection event listener properly.
* @private {function(chrome.automation.AutomationEvent): undefined}
*/ */
this.onSelectionChanged_ = this.reloadMenuForSelectionChange_.bind(this); this.onExitCallback_ = null;
/** /**
* Keeps track of when the clipboard is empty. * Keeps track of when the clipboard is empty.
...@@ -150,16 +148,14 @@ class MenuManager { ...@@ -150,16 +148,14 @@ class MenuManager {
this.closeCurrentMenu_(); this.closeCurrentMenu_();
this.inMenu_ = false; this.inMenu_ = false;
if (window.switchAccess.improvedTextInputEnabled() && if (this.onExitCallback_) {
this.menuOriginNode_) { this.onExitCallback_();
this.menuOriginNode_.removeEventListener( this.onExitCallback_ = null;
chrome.automation.EventType.TEXT_SELECTION_CHANGED,
this.onSelectionChanged_, false /** Don't use capture. */);
} }
this.menuOriginNode_ = null; this.menuOriginNode_ = null;
chrome.accessibilityPrivate.setSwitchAccessMenuState( chrome.accessibilityPrivate.setSwitchAccessMenuState(
false /** Hide the menu. */, RectHelper.ZERO_RECT, 0); false /** should_show */, RectHelper.ZERO_RECT, 0);
} }
/** /**
...@@ -227,9 +223,15 @@ class MenuManager { ...@@ -227,9 +223,15 @@ class MenuManager {
this.menuOriginNode_ = navNode; this.menuOriginNode_ = navNode;
if (!shouldReloadMenu && window.switchAccess.improvedTextInputEnabled()) { if (!shouldReloadMenu && window.switchAccess.improvedTextInputEnabled()) {
const callback = this.reloadMenuForSelectionChange_.bind(this);
this.menuOriginNode_.addEventListener( this.menuOriginNode_.addEventListener(
chrome.automation.EventType.TEXT_SELECTION_CHANGED, chrome.automation.EventType.TEXT_SELECTION_CHANGED, callback,
this.onSelectionChanged_, false /** Don't use capture. */); false /** use_capture */);
this.onExitCallback_ = this.menuOriginNode_.removeEventListener.bind(
this.menuOriginNode_,
chrome.automation.EventType.TEXT_SELECTION_CHANGED, callback,
false /** use_capture */);
} }
if (shouldReloadMenu && actionNode) { 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