Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8262981: Create implementation for NSAccessibilitySlider protocol #2874

Closed
wants to merge 7 commits into from
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -48,7 +48,7 @@ + (void) initializeRolesMap {
/*
* 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 @@ + (void) initializeRolesMap {
[rolesMap setObject:@"StaticTextAccessibility" forKey:@"label"];
[rolesMap setObject:@"RadiobuttonAccessibility" forKey:@"radiobutton"];
[rolesMap setObject:@"CheckboxAccessibility" forKey:@"checkbox"];
[rolesMap setObject:@"SliderAccessibility" forKey:@"slider"];
This conversation was marked as resolved by pankaj-bansal

This comment has been minimized.

@azuev-java

azuev-java Mar 9, 2021
Member

Shouldn't you also increase the rolesMap initial capacity?

This comment has been minimized.

@pankaj-bansal

pankaj-bansal Mar 10, 2021
Author

Shouldn't you also increase the rolesMap initial capacity?

ok, I will do that in next commit.

This comment has been minimized.


/*
* All the components below should be ignored by the accessibility subsystem,
@@ -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
@@ -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
@@ -42,6 +42,7 @@
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 AccessibleContext getAccessibleContext() {
*/
@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 Number getMaximumAccessibleValue() {
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
}