Skip to content

Commit

Permalink
8291087: Wrong position of focus of screen reader on Windows with scr…
Browse files Browse the repository at this point in the history
…een scale > 1

Backport-of: 38324a70c3054e75cb22865e7ffcc5375b62939d
  • Loading branch information
kevinrushforth committed Nov 22, 2022
1 parent 8e1d7fe commit 16db452
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@
import javafx.scene.Scene;
import javafx.scene.input.KeyCombination;
import com.sun.glass.ui.Accessible;
import com.sun.glass.ui.Screen;
import com.sun.glass.ui.View;
import com.sun.javafx.stage.WindowHelper;
import com.sun.javafx.tk.TKStage;
import com.sun.javafx.tk.quantum.WindowStage;
import static javafx.scene.AccessibleAttribute.*;

/*
Expand Down Expand Up @@ -877,6 +881,27 @@ private WinVariant GetPropertyValue(int propertyId) {
return variant;
}

private Screen getScreen() {
Scene scene = (Scene) getAttribute(SCENE);
if (scene == null || scene.getWindow() == null) return null;
TKStage tkStage = WindowHelper.getPeer(scene.getWindow());
if (!(tkStage instanceof WindowStage)) return null;
WindowStage windowStage = (WindowStage) tkStage;
if (windowStage.getPlatformWindow() == null) return null;
return windowStage.getPlatformWindow().getScreen();
}

float[] getPlatformBounds(float x, float y, float w, float h) {
float[] platformBounds = new float[] { x, y, w, h };
Screen screen = getScreen();
if (screen == null) return platformBounds;
platformBounds[0] = screen.toPlatformX(x);
platformBounds[1] = screen.toPlatformY(y);
platformBounds[2] = (float) Math.ceil(w * screen.getPlatformScaleX());
platformBounds[3] = (float) Math.ceil(h * screen.getPlatformScaleY());
return platformBounds;
}

/***********************************************/
/* IRawElementProviderFragment */
/***********************************************/
Expand All @@ -887,8 +912,10 @@ private float[] get_BoundingRectangle() {

Bounds bounds = (Bounds)getAttribute(BOUNDS);
if (bounds != null) {
return new float[] {(float)bounds.getMinX(), (float)bounds.getMinY(),
(float)bounds.getWidth(), (float)bounds.getHeight()};
return getPlatformBounds((float) bounds.getMinX(),
(float) bounds.getMinY(),
(float) bounds.getWidth(),
(float) bounds.getHeight());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,10 +326,16 @@ private double[] GetBoundingRectangles() {
int index = 0;
for (int i = 0; i < bounds.length; i++) {
Bounds b = bounds[i];
result[index++] = b.getMinX();
result[index++] = b.getMinY();
result[index++] = b.getWidth();
result[index++] = b.getHeight();
float[] platformBounds = accessible.getPlatformBounds(
(float) b.getMinX(),
(float) b.getMinY(),
(float) b.getWidth(),
(float) b.getHeight());

result[index++] = platformBounds[0];
result[index++] = platformBounds[1];
result[index++] = platformBounds[2];
result[index++] = platformBounds[3];
}
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
import java.util.ResourceBundle;
import static com.sun.javafx.FXPermissions.*;

class WindowStage extends GlassStage {
public class WindowStage extends GlassStage {

protected Window platformWindow;

Expand Down Expand Up @@ -236,7 +236,7 @@ private void computeAndSetBackground(List<javafx.scene.paint.Stop> stops) {
}
}

final Window getPlatformWindow() {
public final Window getPlatformWindow() {
return platformWindow;
}

Expand Down

1 comment on commit 16db452

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

Please sign in to comment.