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

Make RectUtil a shared class amongst a11y extensions

As part of the overall effort to share more code between the
accessibility component extensions, move Switch Access' RectUtil class
into the common/ directory.

This change is a pure refactor.

AX-Relnotes: n/a.
Bug: None.
Change-Id: I2980080ad643bef76720095c67bbd9165e645f6b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2368481Reviewed-by: default avatarAkihiro Ota <akihiroota@chromium.org>
Commit-Queue: Anastasia Helfinstein <anastasi@google.com>
Cr-Commit-Position: refs/heads/master@{#801604}
parent 469da494
...@@ -145,21 +145,21 @@ js2gtest("misc_unit_tests_js") { ...@@ -145,21 +145,21 @@ js2gtest("misc_unit_tests_js") {
test_type = "unit" test_type = "unit"
sources = [ sources = [
"braille_ime/braille_ime_unittest.js", "braille_ime/braille_ime_unittest.js",
"common/rect_util_unittest.js",
"select_to_speak/node_utils_unittest.js", "select_to_speak/node_utils_unittest.js",
"select_to_speak/paragraph_utils_unittest.js", "select_to_speak/paragraph_utils_unittest.js",
"select_to_speak/rect_utils_unittest.js", "select_to_speak/rect_utils_unittest.js",
"select_to_speak/select_to_speak_unittest.js", "select_to_speak/select_to_speak_unittest.js",
"select_to_speak/word_utils_unittest.js", "select_to_speak/word_utils_unittest.js",
"switch_access/rect_helper_unittest.js",
] ]
extra_js_files = [ extra_js_files = [
"braille_ime/braille_ime.js", "braille_ime/braille_ime.js",
"common/rect_util.js",
"select_to_speak/paragraph_utils.js", "select_to_speak/paragraph_utils.js",
"select_to_speak/rect_utils.js", "select_to_speak/rect_utils.js",
"select_to_speak/select_to_speak.js", "select_to_speak/select_to_speak.js",
"select_to_speak/test_support.js", "select_to_speak/test_support.js",
"select_to_speak/word_utils.js", "select_to_speak/word_utils.js",
"select_to_speak/node_utils.js", "select_to_speak/node_utils.js",
"switch_access/rect_helper.js",
] ]
} }
...@@ -30,6 +30,7 @@ run_jsbundler("accessibility_common_copied_files") { ...@@ -30,6 +30,7 @@ run_jsbundler("accessibility_common_copied_files") {
"closure_shim.js", "closure_shim.js",
"constants.js", "constants.js",
"event_handler.js", "event_handler.js",
"rect_util.js",
"repeated_event_handler.js", "repeated_event_handler.js",
"repeated_tree_change_handler.js", "repeated_tree_change_handler.js",
"tree_walker.js", "tree_walker.js",
...@@ -85,6 +86,10 @@ js_library("event_handler") { ...@@ -85,6 +86,10 @@ js_library("event_handler") {
externs_list = [ "$externs_path/automation.js" ] externs_list = [ "$externs_path/automation.js" ]
} }
js_library("rect_util") {
externs_list = [ "$externs_path/accessibility_private.js" ]
}
js_library("repeated_event_handler") { js_library("repeated_event_handler") {
externs_list = [ "$externs_path/automation.js" ] externs_list = [ "$externs_path/automation.js" ]
} }
......
...@@ -41,7 +41,7 @@ TEST_F('ArrayUtilTest', 'ContentsAreEqual', function() { ...@@ -41,7 +41,7 @@ TEST_F('ArrayUtilTest', 'ContentsAreEqual', function() {
assertTrue( assertTrue(
ArrayUtil.contentsAreEqual(arrayWithObj, secondArrayWithObj), ArrayUtil.contentsAreEqual(arrayWithObj, secondArrayWithObj),
'Different array instances with references to the same object ' + 'Different array instances with references to the same object ' +
'instance should be equal with contentsareEqual.'); 'instance should be equal with contentsAreEqual.');
assertFalse( assertFalse(
ArrayUtil.contentsAreEqual(arrayWithObj, arrayWithDifferentObj), ArrayUtil.contentsAreEqual(arrayWithObj, arrayWithDifferentObj),
'Arrays with different objects should not be equal (ArrayUtil.' + 'Arrays with different objects should not be equal (ArrayUtil.' +
......
...@@ -74,7 +74,6 @@ run_jsbundler("switch_access_copied_files") { ...@@ -74,7 +74,6 @@ run_jsbundler("switch_access_copied_files") {
"nodes/tab_node.js", "nodes/tab_node.js",
"nodes/window_node.js", "nodes/window_node.js",
"preferences.js", "preferences.js",
"rect_helper.js",
"switch_access.js", "switch_access.js",
"switch_access_constants.js", "switch_access_constants.js",
"switch_access_predicate.js", "switch_access_predicate.js",
...@@ -150,7 +149,6 @@ js_type_check("closure_compile") { ...@@ -150,7 +149,6 @@ js_type_check("closure_compile") {
":navigation_manager", ":navigation_manager",
":node_wrapper", ":node_wrapper",
":preferences", ":preferences",
":rect_helper",
":slider_node", ":slider_node",
":switch_access", ":switch_access",
":switch_access_constants", ":switch_access_constants",
...@@ -162,6 +160,7 @@ js_type_check("closure_compile") { ...@@ -162,6 +160,7 @@ js_type_check("closure_compile") {
"../common:automation_predicate", "../common:automation_predicate",
"../common:closure_shim", "../common:closure_shim",
"../common:constants", "../common:constants",
"../common:rect_util",
"../common:repeated_event_handler", "../common:repeated_event_handler",
"../common:repeated_tree_change_handler", "../common:repeated_tree_change_handler",
"../common:tree_walker", "../common:tree_walker",
...@@ -180,9 +179,9 @@ js_library("background") { ...@@ -180,9 +179,9 @@ js_library("background") {
js_library("back_button_node") { js_library("back_button_node") {
sources = [ "nodes/back_button_node.js" ] sources = [ "nodes/back_button_node.js" ]
deps = [ deps = [
":rect_helper",
":switch_access_constants", ":switch_access_constants",
":switch_access_node", ":switch_access_node",
"../common:rect_util",
] ]
externs_list = [ externs_list = [
"$externs_path/accessibility_private.js", "$externs_path/accessibility_private.js",
...@@ -250,9 +249,9 @@ js_library("group_node") { ...@@ -250,9 +249,9 @@ js_library("group_node") {
deps = [ deps = [
":back_button_node", ":back_button_node",
":node_wrapper", ":node_wrapper",
":rect_helper",
":switch_access_constants", ":switch_access_constants",
":switch_access_node", ":switch_access_node",
"../common:rect_util",
] ]
externs_list = [ externs_list = [
"$externs_path/accessibility_private.js", "$externs_path/accessibility_private.js",
...@@ -277,11 +276,11 @@ js_library("keyboard_node") { ...@@ -277,11 +276,11 @@ js_library("keyboard_node") {
":event_helper", ":event_helper",
":group_node", ":group_node",
":node_wrapper", ":node_wrapper",
":rect_helper",
":switch_access_constants", ":switch_access_constants",
":switch_access_node", ":switch_access_node",
":switch_access_predicate", ":switch_access_predicate",
"../common:constants", "../common:constants",
"../common:rect_util",
"../common:tree_walker", "../common:tree_walker",
] ]
externs_list = [ externs_list = [
...@@ -365,10 +364,6 @@ js_library("preferences") { ...@@ -365,10 +364,6 @@ js_library("preferences") {
externs_list = [ "$externs_path/settings_private.js" ] externs_list = [ "$externs_path/settings_private.js" ]
} }
js_library("rect_helper") {
externs_list = [ "$externs_path/accessibility_private.js" ]
}
js_library("slider_node") { js_library("slider_node") {
sources = [ "nodes/slider_node.js" ] sources = [ "nodes/slider_node.js" ]
deps = [ deps = [
...@@ -424,9 +419,9 @@ js_library("tab_node") { ...@@ -424,9 +419,9 @@ js_library("tab_node") {
sources = [ "nodes/tab_node.js" ] sources = [ "nodes/tab_node.js" ]
deps = [ deps = [
":node_wrapper", ":node_wrapper",
":rect_helper",
":switch_access_constants", ":switch_access_constants",
":switch_access_node", ":switch_access_node",
"../common:rect_util",
] ]
externs_list = [ "$externs_path/automation.js" ] externs_list = [ "$externs_path/automation.js" ]
} }
......
...@@ -97,7 +97,7 @@ class FocusRingManager { ...@@ -97,7 +97,7 @@ class FocusRingManager {
if (childRect) { if (childRect) {
// If the current element is not the back button, the focus rect should // If the current element is not the back button, the focus rect should
// expand to contain the child rect. // expand to contain the child rect.
focusRect = RectHelper.expandToFitWithPadding( focusRect = RectUtil.expandToFitWithPadding(
SAConstants.Focus.GROUP_BUFFER, focusRect, childRect); SAConstants.Focus.GROUP_BUFFER, focusRect, childRect);
manager.rings_.get(SAConstants.Focus.ID.NEXT).rects = [childRect]; manager.rings_.get(SAConstants.Focus.ID.NEXT).rects = [childRect];
} }
......
...@@ -203,11 +203,11 @@ class NavigationManager { ...@@ -203,11 +203,11 @@ class NavigationManager {
if (!location) { if (!location) {
// Closure compiler doesn't realize we already checked isValidAndVisible // Closure compiler doesn't realize we already checked isValidAndVisible
// before calling tryMoving, so we need to explicitly check location here // before calling tryMoving, so we need to explicitly check location here
// so that RectHelper.center does not cause a closure error. // so that RectUtil.center does not cause a closure error.
NavigationManager.moveToValidNode(); NavigationManager.moveToValidNode();
return; return;
} }
const center = RectHelper.center(location); const center = RectUtil.center(location);
// Check if the top center is visible as a proxy for occlusion. It's // Check if the top center is visible as a proxy for occlusion. It's
// possible that other parts of the window are occluded, but in Chrome we // possible that other parts of the window are occluded, but in Chrome we
// can't drag windows off the top of the screen. // can't drag windows off the top of the screen.
......
...@@ -36,7 +36,7 @@ class GroupNode extends SAChildNode { ...@@ -36,7 +36,7 @@ class GroupNode extends SAChildNode {
/** @override */ /** @override */
get location() { get location() {
const childLocations = this.children_.map(c => c.location); const childLocations = this.children_.map(c => c.location);
return RectHelper.unionAll(childLocations); return RectUtil.unionAll(childLocations);
} }
/** @override */ /** @override */
...@@ -134,7 +134,7 @@ class GroupNode extends SAChildNode { ...@@ -134,7 +134,7 @@ class GroupNode extends SAChildNode {
i++; i++;
while (i < nodes.length && while (i < nodes.length &&
RectHelper.sameRow(children[0].location, nodes[i].location)) { RectUtil.sameRow(children[0].location, nodes[i].location)) {
children.push(nodes[i]); children.push(nodes[i]);
i++; i++;
} }
......
...@@ -47,7 +47,7 @@ class KeyboardNode extends NodeWrapper { ...@@ -47,7 +47,7 @@ class KeyboardNode extends NodeWrapper {
// doDefault() does nothing on Virtual Keyboard buttons, so we must // doDefault() does nothing on Virtual Keyboard buttons, so we must
// simulate a mouse click. // simulate a mouse click.
const center = RectHelper.center(keyLocation); const center = RectUtil.center(keyLocation);
EventHelper.simulateMouseClick( EventHelper.simulateMouseClick(
center.x, center.y, SAConstants.VK_KEY_PRESS_DURATION_MS); center.x, center.y, SAConstants.VK_KEY_PRESS_DURATION_MS);
......
...@@ -224,7 +224,7 @@ class SAChildNode { ...@@ -224,7 +224,7 @@ class SAChildNode {
const loc = this.location; const loc = this.location;
if (loc) { if (loc) {
str += 'loc(' + RectHelper.toString(loc) + ') '; str += 'loc(' + RectUtil.toString(loc) + ') ';
} }
if (this.isGroup()) { if (this.isGroup()) {
...@@ -299,7 +299,7 @@ class SARootNode { ...@@ -299,7 +299,7 @@ class SARootNode {
const children = const children =
this.children_.filter((c) => !(c instanceof BackButtonNode)); this.children_.filter((c) => !(c instanceof BackButtonNode));
const childLocations = children.map((c) => c.location); const childLocations = children.map((c) => c.location);
return RectHelper.unionAll(childLocations); return RectUtil.unionAll(childLocations);
} }
// ================= General methods ================= // ================= General methods =================
...@@ -413,7 +413,7 @@ class SARootNode { ...@@ -413,7 +413,7 @@ class SARootNode {
const loc = this.location; const loc = this.location;
if (loc) { if (loc) {
str += 'loc(' + RectHelper.toString(loc) + ') '; str += 'loc(' + RectUtil.toString(loc) + ') ';
} }
......
...@@ -102,7 +102,7 @@ class ActionableTabNode extends NodeWrapper { ...@@ -102,7 +102,7 @@ class ActionableTabNode extends NodeWrapper {
if (!this.closeButton_) { if (!this.closeButton_) {
return super.location; return super.location;
} }
return RectHelper.difference(super.location, this.closeButton_.location); return RectUtil.difference(super.location, this.closeButton_.location);
} }
// ================= General methods ================= // ================= General methods =================
......
...@@ -42,7 +42,7 @@ TEST_F('SwitchAccessTabNodeTest', 'Construction', function() { ...@@ -42,7 +42,7 @@ TEST_F('SwitchAccessTabNodeTest', 'Construction', function() {
const tabAsRoot = NavigationManager.instance.group_; const tabAsRoot = NavigationManager.instance.group_;
assertTrue( assertTrue(
RectHelper.areEqual(tab.location, tabAsRoot.location), RectUtil.equal(tab.location, tabAsRoot.location),
'Tab location should not change when treated as root'); 'Tab location should not change when treated as root');
assertEquals( assertEquals(
3, tabAsRoot.children.length, 'Tab as root should have 3 children'); 3, tabAsRoot.children.length, 'Tab as root should have 3 children');
...@@ -57,7 +57,7 @@ TEST_F('SwitchAccessTabNodeTest', 'Construction', function() { ...@@ -57,7 +57,7 @@ TEST_F('SwitchAccessTabNodeTest', 'Construction', function() {
tabToSelect.hasAction(SwitchAccessMenuAction.SELECT), tabToSelect.hasAction(SwitchAccessMenuAction.SELECT),
'Tab as a group should have a SELECT action'); 'Tab as a group should have a SELECT action');
assertFalse( assertFalse(
RectHelper.areEqual(tabAsRoot.location, tabToSelect.location), RectUtil.equal(tabAsRoot.location, tabToSelect.location),
'Tab node to select should not have the same location as tab as root'); 'Tab node to select should not have the same location as tab as root');
assertEquals( assertEquals(
null, tabToSelect.asRootNode(), null, tabToSelect.asRootNode(),
...@@ -74,12 +74,11 @@ TEST_F('SwitchAccessTabNodeTest', 'Construction', function() { ...@@ -74,12 +74,11 @@ TEST_F('SwitchAccessTabNodeTest', 'Construction', function() {
close.hasAction(SwitchAccessMenuAction.SELECT), close.hasAction(SwitchAccessMenuAction.SELECT),
'Close button should have a SELECT action'); 'Close button should have a SELECT action');
assertFalse( assertFalse(
RectHelper.areEqual(tabAsRoot.location, close.location), RectUtil.equal(tabAsRoot.location, close.location),
'Close button should not have the same location as tab as root'); 'Close button should not have the same location as tab as root');
const overlap = const overlap = RectUtil.intersection(tabToSelect.location, close.location);
RectHelper.intersection(tabToSelect.location, close.location);
assertTrue( assertTrue(
RectHelper.areEqual(RectHelper.ZERO_RECT, overlap), RectUtil.equal(RectUtil.ZERO_RECT, overlap),
'Close button and tab node to select should not overlap'); 'Close button and tab node to select should not overlap');
BackButtonNode BackButtonNode
......
...@@ -134,7 +134,7 @@ const SwitchAccessPredicate = { ...@@ -134,7 +134,7 @@ const SwitchAccessPredicate = {
(scope instanceof SARootNode ? scope.isEquivalentTo(node) : (scope instanceof SARootNode ? scope.isEquivalentTo(node) :
scope === node); scope === node);
if (scope && !scopeEqualsNode && if (scope && !scopeEqualsNode &&
RectHelper.areEqual(node.location, scope.location)) { RectUtil.equal(node.location, scope.location)) {
cache.isGroup.set(node, false); cache.isGroup.set(node, false);
return false; return false;
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
"common/automation_predicate.js", "common/automation_predicate.js",
"common/automation_util.js", "common/automation_util.js",
"common/event_handler.js", "common/event_handler.js",
"common/rect_util.js",
"common/repeated_event_handler.js", "common/repeated_event_handler.js",
"common/repeated_tree_change_handler.js", "common/repeated_tree_change_handler.js",
"common/tree_walker.js", "common/tree_walker.js",
...@@ -42,7 +43,6 @@ ...@@ -42,7 +43,6 @@
"switch_access/nodes/tab_node.js", "switch_access/nodes/tab_node.js",
"switch_access/nodes/window_node.js", "switch_access/nodes/window_node.js",
"switch_access/preferences.js", "switch_access/preferences.js",
"switch_access/rect_helper.js",
"switch_access/switch_access.js", "switch_access/switch_access.js",
"switch_access/switch_access_constants.js", "switch_access/switch_access_constants.js",
"switch_access/switch_access_predicate.js", "switch_access/switch_access_predicate.js",
......
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