Skip to content

Commit 996b6ce

Browse files
accessibility - Support 3:1 contrast focus indicator for buttons in chat view (#1096)
1 parent 83214c1 commit 996b6ce

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/swt/CssConstants.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,11 @@ public static Color getButtonFocusBgColor(Display display) {
6060
return new Color(display, 216, 216, 216);
6161
}
6262

63+
/**
64+
* Get the button border color.
65+
*/
66+
public static Color getButtonBorderColor(Display display) {
67+
return new Color(display, 55, 134, 246);
68+
}
69+
6370
}

com.microsoft.copilot.eclipse.ui/src/com/microsoft/copilot/eclipse/ui/utils/UiUtils.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,19 @@ public static <T> T getView(String viewId, Class<T> viewType) {
388388
*/
389389
public static Button createIconButton(Composite parent, int style) {
390390
Button result = new Button(parent, style);
391+
final boolean[] mouseEntered = new boolean[1];
391392
result.addPaintListener(e -> {
392393
Rectangle bounds = result.getBounds();
393394
e.gc.fillRectangle(0, 0, bounds.width, bounds.height);
394395

396+
// Draw focus indicator border for accessibility
397+
if (result.isFocusControl() && !mouseEntered[0]) {
398+
Color focusIndicatorColor = CssConstants.getButtonBorderColor(result.getDisplay());
399+
e.gc.setForeground(focusIndicatorColor);
400+
e.gc.setLineWidth(1);
401+
e.gc.drawRectangle(0, 0, bounds.width - 1, bounds.height - 1);
402+
}
403+
395404
// Draw the button's image if it has one
396405
Image image = result.getImage();
397406
if (image != null) {
@@ -415,11 +424,13 @@ public static Button createIconButton(Composite parent, int style) {
415424
public void focusGained(org.eclipse.swt.events.FocusEvent e) {
416425
background = result.getBackground();
417426
result.setBackground(focusBackground);
427+
result.redraw(); // Ensure the focus border is drawn
418428
}
419429

420430
@Override
421431
public void focusLost(org.eclipse.swt.events.FocusEvent e) {
422432
result.setBackground(background);
433+
result.redraw(); // Ensure the focus border is removed
423434
}
424435
});
425436

@@ -433,11 +444,13 @@ public void mouseEnter(org.eclipse.swt.events.MouseEvent e) {
433444
// the color when the mouse enters.
434445
background = result.getBackground();
435446
result.setBackground(hoverBackground);
447+
mouseEntered[0] = true;
436448
}
437449

438450
@Override
439451
public void mouseExit(org.eclipse.swt.events.MouseEvent e) {
440452
result.setBackground(background);
453+
mouseEntered[0] = false;
441454
}
442455
});
443456
return result;

0 commit comments

Comments
 (0)