From f69f52d221a8c9bdd5a391caa055580d888e97d5 Mon Sep 17 00:00:00 2001 From: David Kocher Date: Tue, 3 Sep 2024 12:40:00 +0200 Subject: [PATCH] Fix #16247. --- .../binding/AbstractTableDelegate.java | 9 ++-- .../binding/application/NSAccessibility.java | 49 +++++++++++++++++++ .../cyberduck/binding/application/NSCell.java | 2 +- .../binding/application/NSOutlineView.java | 2 +- .../binding/application/NSTableView.java | 2 +- .../cocoa/controller/BrowserController.java | 47 +++++++++++++++--- .../ui/cocoa/controller/InfoController.java | 3 +- .../ProfilesPreferencesController.java | 2 +- 8 files changed, 99 insertions(+), 17 deletions(-) create mode 100644 binding/src/main/java/ch/cyberduck/binding/application/NSAccessibility.java diff --git a/binding/src/main/java/ch/cyberduck/binding/AbstractTableDelegate.java b/binding/src/main/java/ch/cyberduck/binding/AbstractTableDelegate.java index 28847aed4f6..dfc2cd639fe 100644 --- a/binding/src/main/java/ch/cyberduck/binding/AbstractTableDelegate.java +++ b/binding/src/main/java/ch/cyberduck/binding/AbstractTableDelegate.java @@ -20,7 +20,6 @@ import ch.cyberduck.binding.application.NSOutlineView; import ch.cyberduck.binding.application.NSTableColumn; import ch.cyberduck.binding.application.NSTableView; -import ch.cyberduck.binding.application.NSTextFieldCell; import ch.cyberduck.binding.foundation.NSNotification; import ch.cyberduck.binding.foundation.NSObject; import ch.cyberduck.core.NullComparator; @@ -92,13 +91,13 @@ public boolean outlineView_shouldEditTableColumn_item(final NSOutlineView view, /** * @see NSOutlineView.Delegate */ - public void outlineView_willDisplayCell_forTableColumn_item(final NSOutlineView view, final NSTextFieldCell cell, final NSTableColumn tableColumn, final NSObject item) { + public void outlineView_willDisplayCell_forTableColumn_item(final NSOutlineView view, final NSCell cell, final NSTableColumn tableColumn, final NSObject item) { } /** * @see NSTableView.Delegate */ - public void tableView_willDisplayCell_forTableColumn_row(NSTableView view, NSTextFieldCell cell, NSTableColumn c, NSInteger row) { + public void tableView_willDisplayCell_forTableColumn_row(final NSTableView view, final NSCell cell, final NSTableColumn c, final NSInteger row) { } public boolean selectionShouldChange() { @@ -215,12 +214,12 @@ public boolean isSortedAscending() { } public boolean tableView_shouldTypeSelectForEvent_withCurrentSearchString( - final NSTableView view, final NSEvent event, final String searchString) { + final NSTableView view, final NSEvent event, final String searchString) { return this.isTypeSelectSupported(); } public boolean outlineView_shouldTypeSelectForEvent_withCurrentSearchString( - final NSOutlineView view, final NSEvent event, final String searchString) { + final NSOutlineView view, final NSEvent event, final String searchString) { return this.isTypeSelectSupported(); } diff --git a/binding/src/main/java/ch/cyberduck/binding/application/NSAccessibility.java b/binding/src/main/java/ch/cyberduck/binding/application/NSAccessibility.java new file mode 100644 index 00000000000..582832f6879 --- /dev/null +++ b/binding/src/main/java/ch/cyberduck/binding/application/NSAccessibility.java @@ -0,0 +1,49 @@ +package ch.cyberduck.binding.application; + +/* + * Copyright (c) 2002-2024 iterate GmbH. All rights reserved. + * https://cyberduck.io/ + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program 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 for more details. + */ + +public interface NSAccessibility { + + /** + * The title of the accessibility element—for example, a button’s visible text. + * + * @param title + * @since macOS 10.10+ + */ + void setAccessibilityTitle(String title); + + /** + * Use this property only when the results of activating this element are not obvious from the element’s label. + * This string functions as a tooltip. For example, VoiceOver reads this string when you pause over a control. + * To help ensure that accessibility clients like VoiceOver read the help text with the proper inflection, begin + * this string with a verb, capitalize the first letter, and end the string with a period. Always localize this + * string. The default value is nil. + * + * @param help The help text for the accessibility element. + */ + void setAccessibilityHelp(String help); + + /** + * Do not include the accessibility element’s type in the label (for example, write Play, not Play button.). + * If possible, use a single word. To help ensure that accessibility clients such as VoiceOver read the label + * with the correct intonation, start this label with a capital letter. Do not put a period at the end. + * Always localize the label. + * + * @param label A short description of the accessibility element. + * @since macOS 10.10+ + */ + void setAccessibilityLabel(String label); +} diff --git a/binding/src/main/java/ch/cyberduck/binding/application/NSCell.java b/binding/src/main/java/ch/cyberduck/binding/application/NSCell.java index 02ae3349253..1ef28fdf7c5 100644 --- a/binding/src/main/java/ch/cyberduck/binding/application/NSCell.java +++ b/binding/src/main/java/ch/cyberduck/binding/application/NSCell.java @@ -31,7 +31,7 @@ import org.rococoa.cocoa.foundation.NSSize; import org.rococoa.cocoa.foundation.NSUInteger; -public abstract class NSCell extends NSObject implements NSCopying { +public abstract class NSCell extends NSObject implements NSCopying, NSAccessibility { /// native declaration : :11 public static final int NSAnyType = 0; diff --git a/binding/src/main/java/ch/cyberduck/binding/application/NSOutlineView.java b/binding/src/main/java/ch/cyberduck/binding/application/NSOutlineView.java index cc47eed0fe4..b31f0efd49a 100644 --- a/binding/src/main/java/ch/cyberduck/binding/application/NSOutlineView.java +++ b/binding/src/main/java/ch/cyberduck/binding/application/NSOutlineView.java @@ -55,7 +55,7 @@ void outlineView_setObjectValue_forTableColumn_byItem(NSOutlineView outlineView, } public interface Delegate { - void outlineView_willDisplayCell_forTableColumn_item(NSOutlineView view, NSTextFieldCell cell, NSTableColumn tableColumn, NSObject item); + void outlineView_willDisplayCell_forTableColumn_item(NSOutlineView view, NSCell cell, NSTableColumn tableColumn, NSObject item); boolean outlineView_shouldExpandItem(NSOutlineView view, NSObject item); diff --git a/binding/src/main/java/ch/cyberduck/binding/application/NSTableView.java b/binding/src/main/java/ch/cyberduck/binding/application/NSTableView.java index 23d0ef2ff9d..7dcdec1755c 100644 --- a/binding/src/main/java/ch/cyberduck/binding/application/NSTableView.java +++ b/binding/src/main/java/ch/cyberduck/binding/application/NSTableView.java @@ -90,7 +90,7 @@ public interface DataSource { } public interface Delegate { - void tableView_willDisplayCell_forTableColumn_row(NSTableView view, NSTextFieldCell cell, NSTableColumn tableColumn, NSInteger row); + void tableView_willDisplayCell_forTableColumn_row(NSTableView view, NSCell cell, NSTableColumn tableColumn, NSInteger row); } /** diff --git a/osx/src/main/java/ch/cyberduck/ui/cocoa/controller/BrowserController.java b/osx/src/main/java/ch/cyberduck/ui/cocoa/controller/BrowserController.java index ba81bd89ea2..e6c181669f8 100644 --- a/osx/src/main/java/ch/cyberduck/ui/cocoa/controller/BrowserController.java +++ b/osx/src/main/java/ch/cyberduck/ui/cocoa/controller/BrowserController.java @@ -1141,7 +1141,7 @@ public void enterKeyPressed(final ID sender) { * @see NSOutlineView.Delegate */ @Override - public void outlineView_willDisplayCell_forTableColumn_item(final NSOutlineView view, final NSTextFieldCell cell, final NSTableColumn tableColumn, final NSObject item) { + public void outlineView_willDisplayCell_forTableColumn_item(final NSOutlineView view, final NSCell cell, final NSTableColumn tableColumn, final NSObject item) { if(null == item) { return; } @@ -1153,10 +1153,10 @@ public void outlineView_willDisplayCell_forTableColumn_item(final NSOutlineView (Rococoa.cast(cell, OutlineCell.class)).setIcon(browserOutlineModel.iconForPath(file)); } if(!BrowserController.this.isConnected() || !SearchFilterFactory.HIDDEN_FILTER.accept(file)) { - cell.setTextColor(NSColor.disabledControlTextColor()); + Rococoa.cast(cell, NSTextFieldCell.class).setTextColor(NSColor.disabledControlTextColor()); } else { - cell.setTextColor(NSColor.controlTextColor()); + Rococoa.cast(cell, NSTextFieldCell.class).setTextColor(NSColor.controlTextColor()); } } @@ -1299,14 +1299,14 @@ public void enterKeyPressed(final ID sender) { } @Override - public void tableView_willDisplayCell_forTableColumn_row(final NSTableView view, final NSTextFieldCell cell, final NSTableColumn tableColumn, final NSInteger row) { + public void tableView_willDisplayCell_forTableColumn_row(final NSTableView view, final NSCell cell, final NSTableColumn tableColumn, final NSInteger row) { final Path file = browserListModel.get(workdir).get(row.intValue()); if(cell.isKindOfClass(Foundation.getClass(NSTextFieldCell.class.getSimpleName()))) { if(!BrowserController.this.isConnected() || !SearchFilterFactory.HIDDEN_FILTER.accept(file)) { - cell.setTextColor(NSColor.disabledControlTextColor()); + Rococoa.cast(cell, NSTextFieldCell.class).setTextColor(NSColor.disabledControlTextColor()); } else { - cell.setTextColor(NSColor.controlTextColor()); + Rococoa.cast(cell, NSTextFieldCell.class).setTextColor(NSColor.controlTextColor()); } } } @@ -1674,6 +1674,41 @@ else if(event.deltaY().doubleValue() == kSwipeGestureDown) { NSIndexSet.indexSetWithIndex(next), false); } } + + @Override + public void tableView_willDisplayCell_forTableColumn_row(final NSTableView view, final NSCell cell, final NSTableColumn c, final NSInteger row) { + cell.setAccessibilityLabel(LocaleFactory.localizedString("Connect to server")); + if(c.identifier().equals(BookmarkColumn.icon.name())) { + cell.setAccessibilityTitle(bookmarkModel.getSource().get(row.intValue()).getProtocol().getName()); + } + if(c.identifier().equals(BookmarkColumn.bookmark.name())) { + cell.setAccessibilityTitle(BookmarkNameProvider.toString(bookmarkModel.getSource().get(row.intValue()))); + } + if(c.identifier().equals(BookmarkColumn.status.name())) { + final Host host = bookmarkModel.getSource().get(row.intValue()); + if(host.equals(pool.getHost())) { + switch(pool.getState()) { + case open: + cell.setAccessibilityTitle(LocaleFactory.localizedString("Idle", "Status")); + break; + case closed: + cell.setAccessibilityTitle(LocaleFactory.localizedString("Disconnected", "Status")); + break; + case opening: + cell.setAccessibilityTitle(MessageFormat.format(LocaleFactory.localizedString("Mounting {0}", "Status"), + BookmarkNameProvider.toString(host))); + break; + case closing: + cell.setAccessibilityTitle(MessageFormat.format(LocaleFactory.localizedString("Disconnecting {0}", "Status"), + BookmarkNameProvider.toString(host))); + break; + } + } + else { + cell.setAccessibilityTitle(LocaleFactory.localizedString("Disconnected", "Status")); + } + } + } }).id()); // receive drag events from types bookmarkTable.registerForDraggedTypes(NSArray.arrayWithObjects( diff --git a/osx/src/main/java/ch/cyberduck/ui/cocoa/controller/InfoController.java b/osx/src/main/java/ch/cyberduck/ui/cocoa/controller/InfoController.java index 1d924ff5e21..5bcd279aa46 100644 --- a/osx/src/main/java/ch/cyberduck/ui/cocoa/controller/InfoController.java +++ b/osx/src/main/java/ch/cyberduck/ui/cocoa/controller/InfoController.java @@ -1354,8 +1354,7 @@ protected boolean isTypeSelectSupported() { return false; } - public void tableView_willDisplayCell_forTableColumn_row(NSTableView view, NSTextFieldCell cell, - NSTableColumn c, NSInteger row) { + public void tableView_willDisplayCell_forTableColumn_row(final NSTableView view, final NSTextFieldCell cell, final NSTableColumn c, final NSInteger row) { if(c.identifier().equals(MetadataColumn.VALUE.name())) { final String value = metadata.get(row.intValue()).getValue(); if(null == value) { diff --git a/osx/src/main/java/ch/cyberduck/ui/cocoa/controller/ProfilesPreferencesController.java b/osx/src/main/java/ch/cyberduck/ui/cocoa/controller/ProfilesPreferencesController.java index 1f3929d9d9f..c7f338c53f3 100644 --- a/osx/src/main/java/ch/cyberduck/ui/cocoa/controller/ProfilesPreferencesController.java +++ b/osx/src/main/java/ch/cyberduck/ui/cocoa/controller/ProfilesPreferencesController.java @@ -244,7 +244,7 @@ public String tooltip(final Protocol item, final Void unused) { } @Override - public void outlineView_willDisplayCell_forTableColumn_item(final NSOutlineView view, final NSTextFieldCell cell, final NSTableColumn tableColumn, final NSObject item) { + public void outlineView_willDisplayCell_forTableColumn_item(final NSOutlineView view, final NSCell cell, final NSTableColumn tableColumn, final NSObject item) { // }