8262981: Create implementation for NSAccessibilitySlider protocol

Reviewed-by: kizune
This commit is contained in:
Pankaj Bansal 2021-04-15 11:45:41 +00:00
parent abdff7905f
commit 9d669c912d
4 changed files with 164 additions and 2 deletions

View File

@ -48,7 +48,7 @@ static jobject sAccessibilityClass = NULL;
/*
* Here we should keep all the mapping between the accessibility roles and implementing classes
*/
rolesMap = [[NSMutableDictionary alloc] initWithCapacity:26];
rolesMap = [[NSMutableDictionary alloc] initWithCapacity:27];
[rolesMap setObject:@"ButtonAccessibility" forKey:@"pushbutton"];
[rolesMap setObject:@"ImageAccessibility" forKey:@"icon"];
@ -58,6 +58,7 @@ static jobject sAccessibilityClass = NULL;
[rolesMap setObject:@"StaticTextAccessibility" forKey:@"label"];
[rolesMap setObject:@"RadiobuttonAccessibility" forKey:@"radiobutton"];
[rolesMap setObject:@"CheckboxAccessibility" forKey:@"checkbox"];
[rolesMap setObject:@"SliderAccessibility" forKey:@"slider"];
/*
* All the components below should be ignored by the accessibility subsystem,

View File

@ -0,0 +1,39 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#import "JavaComponentAccessibility.h"
#import "CommonComponentAccessibility.h"
#import <AppKit/AppKit.h>
@interface SliderAccessibility : CommonComponentAccessibility <NSAccessibilitySlider> {
};
- (nullable NSString *)accessibilityLabel;
- (nullable id)accessibilityValue;
- (BOOL)accessibilityPerformDecrement;
- (BOOL)accessibilityPerformIncrement;
@end

View File

@ -0,0 +1,55 @@
/*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
#import "SliderAccessibility.h"
#define INCREMENT 0
#define DECREMENT 1
/*
* Implementation of the accessibility peer for the slider role
*/
@implementation SliderAccessibility
- (nullable NSString *)accessibilityLabel
{
return [self accessibilityTitleAttribute];
}
- (nullable id)accessibilityValue
{
return [self accessibilityValueAttribute];
}
- (BOOL)accessibilityPerformIncrement
{
return [self performAccessibleAction:INCREMENT];
}
- (BOOL)accessibilityPerformDecrement
{
return [self performAccessibleAction:DECREMENT];
}
@end

View File

@ -42,6 +42,7 @@ import java.util.Enumeration;
import java.util.Hashtable;
import javax.accessibility.Accessible;
import javax.accessibility.AccessibleAction;
import javax.accessibility.AccessibleContext;
import javax.accessibility.AccessibleRole;
import javax.accessibility.AccessibleState;
@ -1421,7 +1422,7 @@ public class JSlider extends JComponent implements SwingConstants, Accessible {
*/
@SuppressWarnings("serial") // Same-version serialization only
protected class AccessibleJSlider extends AccessibleJComponent
implements AccessibleValue, ChangeListener {
implements AccessibleValue, ChangeListener, AccessibleAction {
private int oldModelValue;
@ -1536,5 +1537,71 @@ public class JSlider extends JComponent implements SwingConstants, Accessible {
BoundedRangeModel model = JSlider.this.getModel();
return Integer.valueOf(model.getMaximum() - model.getExtent());
}
/**
* Gets the AccessibleAction associated with this object that supports
* one or more actions.
*
* @return AccessibleAction if supported by object; else return null
* @see AccessibleAction
*/
public AccessibleAction getAccessibleAction() {
return this;
}
/* ===== Begin AccessibleAction impl ===== */
/**
* Returns the number of accessible actions available in this object
* If there are more than one, the first one is considered the "default"
* action of the object.
*
* Two actions are supported: AccessibleAction.INCREMENT which
* increments the slider value and AccessibleAction.DECREMENT
* which decrements the slider value
*
* @return the zero-based number of Actions in this object
*/
public int getAccessibleActionCount() {
return 2;
}
/**
* Returns a description of the specified action of the object.
*
* @param i zero-based index of the actions
* @return a String description of the action
* @see #getAccessibleActionCount
*/
public String getAccessibleActionDescription(int i) {
if (i == 0) {
return AccessibleAction.INCREMENT;
} else if (i == 1) {
return AccessibleAction.DECREMENT;
}
return null;
}
/**
* Performs the specified Action on the object
*
* @param i zero-based index of actions. The first action
* (index 0) is AccessibleAction.INCREMENT and the second
* action (index 1) is AccessibleAction.DECREMENT.
* @return true.
* @see #getAccessibleActionCount
*/
public boolean doAccessibleAction(int direction) {
if (direction < 0 || direction > 1) {
return false;
}
//0 is increment, 1 is decrrement
int delta = ((direction > 0) ? -1 : 1);
JSlider.this.setValue(oldModelValue + delta);
return true;
}
/* ===== End AccessibleAction impl ===== */
} // AccessibleJSlider
}