Skip to content

Commit

Permalink
Remove keyboard navigation from core (#4593)
Browse files Browse the repository at this point in the history
  • Loading branch information
alschmiedt authored Jan 19, 2021
1 parent a9ea08a commit a3adc42
Show file tree
Hide file tree
Showing 21 changed files with 50 additions and 2,800 deletions.
1 change: 0 additions & 1 deletion core/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ goog.require('Blockly.Events.BlockMove');
goog.require('Blockly.Extensions');
goog.require('Blockly.fieldRegistry');
goog.require('Blockly.Input');
goog.require('Blockly.navigation');
goog.require('Blockly.Tooltip');
goog.require('Blockly.utils');
goog.require('Blockly.utils.deprecation');
Expand Down
17 changes: 7 additions & 10 deletions core/block_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ goog.require('Blockly.Events');
goog.require('Blockly.Events.BlockMove');
goog.require('Blockly.Events.Selected');
goog.require('Blockly.Msg');
goog.require('Blockly.navigation');
goog.require('Blockly.RenderedConnection');
goog.require('Blockly.TabNavigateCursor');
goog.require('Blockly.Tooltip');
Expand Down Expand Up @@ -692,11 +691,12 @@ Blockly.BlockSvg.prototype.tab = function(start, forward) {
var tabCursor = new Blockly.TabNavigateCursor();
tabCursor.setCurNode(Blockly.ASTNode.createFieldNode(start));
var currentNode = tabCursor.getCurNode();
var actionName = forward ?
Blockly.navigation.actionNames.NEXT : Blockly.navigation.actionNames.PREVIOUS;

tabCursor.onBlocklyAction(
/** @type {!Blockly.ShortcutRegistry.KeyboardShortcut} */ ({name: actionName}));
if (forward) {
tabCursor.next();
} else {
tabCursor.prev();
}

var nextNode = tabCursor.getCurNode();
if (nextNode && nextNode !== currentNode) {
Expand Down Expand Up @@ -907,10 +907,6 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) {
Blockly.ContextMenu.hide();
}

if (this.workspace.keyboardAccessibilityMode) {
Blockly.navigation.moveCursorOnBlockDelete(this);
}

if (animate && this.rendered) {
this.unplug(healStack);
Blockly.blockAnimations.disposeUiEffect(this);
Expand Down Expand Up @@ -1660,7 +1656,8 @@ Blockly.BlockSvg.prototype.updateMarkers_ = function() {
this.workspace.getCursor().draw();
}
if (this.workspace.keyboardAccessibilityMode && this.pathObject.markerSvg) {
this.workspace.getMarker(Blockly.navigation.MARKER_NAME).draw();
// TODO(#4592): Update all markers on the block.
this.workspace.getMarker(Blockly.MarkerManager.LOCAL_MARKER).draw();
}
};

Expand Down
18 changes: 9 additions & 9 deletions core/field.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ goog.require('Blockly.utils.userAgent');
goog.requireType('Blockly.blockRendering.ConstantProvider');
goog.requireType('Blockly.IASTNodeLocationSvg');
goog.requireType('Blockly.IASTNodeLocationWithBlock');
goog.requireType('Blockly.IBlocklyActionable');
goog.requireType('Blockly.IKeyboardAccessible');
goog.requireType('Blockly.IRegistrable');
goog.requireType('Blockly.ShortcutRegistry');

Expand All @@ -46,7 +46,7 @@ goog.requireType('Blockly.ShortcutRegistry');
* @constructor
* @implements {Blockly.IASTNodeLocationSvg}
* @implements {Blockly.IASTNodeLocationWithBlock}
* @implements {Blockly.IBlocklyActionable}
* @implements {Blockly.IKeyboardAccessible}
* @implements {Blockly.IRegistrable}
*/
Blockly.Field = function(value, opt_validator, opt_config) {
Expand Down Expand Up @@ -1024,13 +1024,12 @@ Blockly.Field.prototype.isTabNavigable = function() {
};

/**
* Handles the given action.
* This is only triggered when keyboard accessibility mode is enabled.
* @param {!Blockly.ShortcutRegistry.KeyboardShortcut} _action The action to be handled.
* @return {boolean} True if the field handled the action, false otherwise.
* @package
* Handles the given keyboard shortcut.
* @param {!Blockly.ShortcutRegistry.KeyboardShortcut} _shortcut The shortcut to be handled.
* @return {boolean} True if the shortcut has been handled, false otherwise.
* @public
*/
Blockly.Field.prototype.onBlocklyAction = function(_action) {
Blockly.Field.prototype.onShortcut = function(_shortcut) {
return false;
};

Expand Down Expand Up @@ -1077,6 +1076,7 @@ Blockly.Field.prototype.updateMarkers_ = function() {
workspace.getCursor().draw();
}
if (workspace.keyboardAccessibilityMode && this.markerSvg_) {
workspace.getMarker(Blockly.navigation.MARKER_NAME).draw();
// TODO(#4592): Update all markers on the field.
workspace.getMarker(Blockly.MarkerManager.LOCAL_MARKER).draw();
}
};
30 changes: 0 additions & 30 deletions core/field_colour.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ goog.require('Blockly.Events');
goog.require('Blockly.Events.BlockChange');
goog.require('Blockly.Field');
goog.require('Blockly.fieldRegistry');
goog.require('Blockly.navigation');
goog.require('Blockly.utils.aria');
goog.require('Blockly.utils.colour');
goog.require('Blockly.utils.dom');
Expand Down Expand Up @@ -382,35 +381,6 @@ Blockly.FieldColour.prototype.onKeyDown_ = function(e) {
}
};

/**
* Handles the given action.
* This is only triggered when keyboard accessibility mode is enabled.
* @param {!Blockly.ShortcutRegistry.KeyboardShortcut} action The action to be handled.
* @return {boolean} True if the field handled the action, false otherwise.
* @package
*/
Blockly.FieldColour.prototype.onBlocklyAction = function(action) {
if (this.picker_) {
switch (action.name) {
case Blockly.navigation.actionNames.PREVIOUS:
this.moveHighlightBy_(0, -1);
return true;
case Blockly.navigation.actionNames.NEXT:
this.moveHighlightBy_(0, 1);
return true;
case Blockly.navigation.actionNames.OUT:
this.moveHighlightBy_(-1, 0);
return true;
case Blockly.navigation.actionNames.IN:
this.moveHighlightBy_(1, 0);
return true;
default:
return false;
}
}
return Blockly.FieldColour.superClass_.onBlocklyAction.call(this, action);
};

/**
* Move the currently highlighted position by dx and dy.
* @param {number} dx Change of x
Expand Down
25 changes: 0 additions & 25 deletions core/field_dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ goog.require('Blockly.Field');
goog.require('Blockly.fieldRegistry');
goog.require('Blockly.Menu');
goog.require('Blockly.MenuItem');
goog.require('Blockly.navigation');
goog.require('Blockly.utils');
goog.require('Blockly.utils.aria');
goog.require('Blockly.utils.Coordinate');
Expand Down Expand Up @@ -738,28 +737,4 @@ Blockly.FieldDropdown.validateOptions_ = function(options) {
}
};

/**
* Handles the given action.
* This is only triggered when keyboard accessibility mode is enabled.
* @param {!Blockly.ShortcutRegistry.KeyboardShortcut} action The action to be handled.
* @return {boolean} True if the field handled the action, false otherwise.
* @package
*/
Blockly.FieldDropdown.prototype.onBlocklyAction = function(action) {
if (this.menu_) {
switch (action.name) {
case Blockly.navigation.actionNames.PREVIOUS:
this.menu_.highlightPrevious();
return true;
case Blockly.navigation.actionNames.NEXT:
this.menu_.highlightNext();
return true;
default:
return false;
}
}
return Blockly.FieldDropdown.superClass_.onBlocklyAction.call(this, action);
};


Blockly.fieldRegistry.register('field_dropdown', Blockly.FieldDropdown);
16 changes: 0 additions & 16 deletions core/flyout_base.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ goog.require('Blockly.blockRendering');
goog.require('Blockly.Events');
goog.require('Blockly.Events.BlockCreate');
goog.require('Blockly.Events.VarCreate');
goog.require('Blockly.FlyoutCursor');
goog.require('Blockly.Gesture');
goog.require('Blockly.Marker');
goog.require('Blockly.Scrollbar');
Expand All @@ -31,7 +30,6 @@ goog.require('Blockly.utils.toolbox');
goog.require('Blockly.WorkspaceSvg');
goog.require('Blockly.Xml');

goog.requireType('Blockly.IBlocklyActionable');
goog.requireType('Blockly.IDeleteArea');
goog.requireType('Blockly.IFlyout');
goog.requireType('Blockly.ShortcutRegistry');
Expand All @@ -44,7 +42,6 @@ goog.requireType('Blockly.utils.Metrics');
* workspace.
* @constructor
* @abstract
* @implements {Blockly.IBlocklyActionable}
* @implements {Blockly.IDeleteArea}
* @implements {Blockly.IFlyout}
*/
Expand Down Expand Up @@ -253,7 +250,6 @@ Blockly.Flyout.prototype.createDom = function(tagName) {
this.svgBackground_, 'flyoutBackgroundColour', 'fill');
this.workspace_.getThemeManager().subscribe(
this.svgBackground_, 'flyoutOpacity', 'fill-opacity');
this.workspace_.getMarkerManager().setCursor(new Blockly.FlyoutCursor());
return this.svgGroup_;
};

Expand Down Expand Up @@ -995,18 +991,6 @@ Blockly.Flyout.prototype.placeNewBlock_ = function(oldBlock) {
return block;
};

/**
* Handles the given action.
* This is only triggered when keyboard accessibility mode is enabled.
* @param {!Blockly.ShortcutRegistry.KeyboardShortcut} action The action to be handled.
* @return {boolean} True if the flyout handled the action, false otherwise.
* @package
*/
Blockly.Flyout.prototype.onBlocklyAction = function(action) {
var cursor = this.workspace_.getCursor();
return cursor.onBlocklyAction(action);
};

/**
* Return the deletion rectangle for this flyout in viewport coordinates.
* @return {Blockly.utils.Rect} Rectangle in which to delete.
Expand Down
24 changes: 4 additions & 20 deletions core/gesture.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ goog.require('Blockly.constants');
goog.require('Blockly.Events');
goog.require('Blockly.Events.Click');
goog.require('Blockly.FlyoutDragger');
goog.require('Blockly.navigation');
goog.require('Blockly.Tooltip');
goog.require('Blockly.Touch');
goog.require('Blockly.utils');
Expand Down Expand Up @@ -488,13 +487,7 @@ Blockly.Gesture.prototype.doStart = function(e) {
Blockly.Tooltip.block();

if (this.targetBlock_) {
if (!this.targetBlock_.isInFlyout && e.shiftKey &&
this.targetBlock_.workspace.keyboardAccessibilityMode) {
this.creatorWorkspace_.getCursor().setCurNode(
Blockly.ASTNode.createTopNode(this.targetBlock_));
} else {
this.targetBlock_.select();
}
this.targetBlock_.select();
}

if (Blockly.utils.isRightButton(e)) {
Expand Down Expand Up @@ -582,7 +575,7 @@ Blockly.Gesture.prototype.handleUp = function(e) {
} else if (this.isBlockClick_()) {
this.doBlockClick_();
} else if (this.isWorkspaceClick_()) {
this.doWorkspaceClick_(e);
this.doWorkspaceClick_();
}

e.preventDefault();
Expand Down Expand Up @@ -654,9 +647,6 @@ Blockly.Gesture.prototype.handleWsStart = function(e, ws) {
this.setStartWorkspace_(ws);
this.mostRecentEvent_ = e;
this.doStart(e);
if (this.startWorkspace_.keyboardAccessibilityMode) {
Blockly.navigation.setState(Blockly.navigation.STATE_WS);
}
};

/**
Expand Down Expand Up @@ -767,17 +757,11 @@ Blockly.Gesture.prototype.doBlockClick_ = function() {
/**
* Execute a workspace click. When in accessibility mode shift clicking will
* move the cursor.
* @param {!Event} e A mouse up or touch end event.
* @private
*/
Blockly.Gesture.prototype.doWorkspaceClick_ = function(e) {
Blockly.Gesture.prototype.doWorkspaceClick_ = function() {
var ws = this.creatorWorkspace_;
if (e.shiftKey && ws.keyboardAccessibilityMode) {
var screenCoord = new Blockly.utils.Coordinate(e.clientX, e.clientY);
var wsCoord = Blockly.utils.screenToWsCoordinates(ws, screenCoord);
var wsNode = Blockly.ASTNode.createWorkspaceNode(ws, wsCoord);
ws.getCursor().setCurNode(wsNode);
} else if (Blockly.selected) {
if (Blockly.selected) {
Blockly.selected.unselect();
}
this.fireWorkspaceClick_(this.startWorkspace_ || ws);
Expand Down
15 changes: 7 additions & 8 deletions core/interfaces/i_accessibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
goog.provide('Blockly.IASTNodeLocation');
goog.provide('Blockly.IASTNodeLocationSvg');
goog.provide('Blockly.IASTNodeLocationWithBlock');
goog.provide('Blockly.IBlocklyActionable');
goog.provide('Blockly.IKeyboardAccessible');
goog.requireType('Blockly.ShortcutRegistry');

/**
Expand Down Expand Up @@ -59,15 +59,14 @@ Blockly.IASTNodeLocationWithBlock.prototype.getSourceBlock;


/**
* An interface for an object that handles Blockly actions when keyboard
* navigation is enabled.
* An interface for an object that handles keyboard shortcuts.
* @interface
*/
Blockly.IBlocklyActionable = function() {};
Blockly.IKeyboardAccessible = function() {};

/**
* Handles the given action.
* @param {!Blockly.ShortcutRegistry.KeyboardShortcut} action The action to be handled.
* @return {boolean} True if the action has been handled, false otherwise.
* Handles the given keyboard shortcut.
* @param {!Blockly.ShortcutRegistry.KeyboardShortcut} shortcut The shortcut to be handled.
* @return {boolean} True if the shortcut has been handled, false otherwise.
*/
Blockly.IBlocklyActionable.prototype.onBlocklyAction;
Blockly.IKeyboardAccessible.prototype.onShortcut;
Loading

0 comments on commit a3adc42

Please sign in to comment.