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