Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8262981: Create implementation for NSAccessibilitySlider protocol
Reviewed-by: kizune
  • Loading branch information
Pankaj Bansal committed Apr 15, 2021
1 parent abdff79 commit 9d669c9
Show file tree
Hide file tree
Showing 4 changed files with 164 additions and 2 deletions.
Expand Up @@ -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"];
Expand All @@ -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"];

/*
* All the components below should be ignored by the accessibility subsystem,
Expand Down
@@ -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
69 changes: 68 additions & 1 deletion src/java.desktop/share/classes/javax/swing/JSlider.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
}

3 comments on commit 9d669c9

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RealCLanger
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/backport jdk11u-dev

@openjdk
Copy link

@openjdk openjdk bot commented on 9d669c9 Mar 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RealCLanger Could not automatically backport 9d669c91 to openjdk/jdk11u-dev due to conflicts in the following files:

  • src/java.desktop/macosx/native/libawt_lwawt/awt/a11y/CommonComponentAccessibility.m
  • src/java.desktop/share/classes/javax/swing/JSlider.java

Please fetch the appropriate branch/commit and manually resolve these conflicts by using the following commands in your personal fork of openjdk/jdk11u-dev. Note: these commands are just some suggestions and you can use other equivalent commands you know.

# Fetch the up-to-date version of the target branch
$ git fetch --no-tags https://git.openjdk.org/jdk11u-dev master:master

# Check out the target branch and create your own branch to backport
$ git checkout master
$ git checkout -b RealCLanger-backport-9d669c91

# Fetch the commit you want to backport
$ git fetch --no-tags https://git.openjdk.org/jdk 9d669c912d3977027f321a5e6b7f045ca2ce9482

# Backport the commit
$ git cherry-pick --no-commit 9d669c912d3977027f321a5e6b7f045ca2ce9482
# Resolve conflicts now

# Commit the files you have modified
$ git add files/with/resolved/conflicts
$ git commit -m 'Backport 9d669c912d3977027f321a5e6b7f045ca2ce9482'

Once you have resolved the conflicts as explained above continue with creating a pull request towards the openjdk/jdk11u-dev with the title Backport 9d669c912d3977027f321a5e6b7f045ca2ce9482.

Please sign in to comment.