mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-16 00:34:19 +00:00
Accessibility: Use AccessibilityTextValueInterface for read-only text in Label, TextEditor and CodeEditorComponent
This commit is contained in:
parent
1634d9f428
commit
13e7ffbdfb
3 changed files with 70 additions and 20 deletions
|
|
@ -524,14 +524,34 @@ public:
|
|||
explicit LabelAccessibilityHandler (Label& labelToWrap)
|
||||
: AccessibilityHandler (labelToWrap,
|
||||
AccessibilityRole::staticText,
|
||||
getAccessibilityActions (labelToWrap)),
|
||||
getAccessibilityActions (labelToWrap),
|
||||
{ std::make_unique<LabelValueInterface> (labelToWrap) }),
|
||||
label (labelToWrap)
|
||||
{
|
||||
}
|
||||
|
||||
String getTitle() const override { return label.getText(); }
|
||||
String getTitle() const override
|
||||
{
|
||||
return label.getText();
|
||||
}
|
||||
|
||||
private:
|
||||
class LabelValueInterface : public AccessibilityTextValueInterface
|
||||
{
|
||||
public:
|
||||
explicit LabelValueInterface (Label& labelToWrap)
|
||||
: label (labelToWrap)
|
||||
{
|
||||
}
|
||||
|
||||
bool isReadOnly() const override { return true; }
|
||||
String getCurrentValueAsString() const override { return label.getText(); }
|
||||
void setValueAsString (const String&) override {}
|
||||
|
||||
private:
|
||||
Label& label;
|
||||
};
|
||||
|
||||
static AccessibilityActions getAccessibilityActions (Label& label)
|
||||
{
|
||||
if (label.isEditable())
|
||||
|
|
|
|||
|
|
@ -2697,17 +2697,27 @@ public:
|
|||
: AccessibilityHandler (textEditorToWrap,
|
||||
textEditorToWrap.isReadOnly() ? AccessibilityRole::staticText : AccessibilityRole::editableText,
|
||||
{},
|
||||
{ textEditorToWrap.isReadOnly() ? nullptr : std::make_unique<TextEditorTextInterface> (textEditorToWrap) }),
|
||||
textEditor (textEditorToWrap)
|
||||
makeInterfaces (textEditorToWrap))
|
||||
{
|
||||
}
|
||||
|
||||
String getTitle() const override
|
||||
{
|
||||
return textEditor.isReadOnly() ? textEditor.getText() : textEditor.getTitle();
|
||||
}
|
||||
|
||||
private:
|
||||
class TextEditorValueInterface : public AccessibilityTextValueInterface
|
||||
{
|
||||
public:
|
||||
explicit TextEditorValueInterface (TextEditor& textEditorToWrap)
|
||||
: textEditor (textEditorToWrap)
|
||||
{
|
||||
}
|
||||
|
||||
bool isReadOnly() const override { return true; }
|
||||
String getCurrentValueAsString() const override { return textEditor.getText(); }
|
||||
void setValueAsString (const String&) override {}
|
||||
|
||||
private:
|
||||
TextEditor& textEditor;
|
||||
};
|
||||
|
||||
class TextEditorTextInterface : public AccessibilityTextInterface
|
||||
{
|
||||
public:
|
||||
|
|
@ -2759,7 +2769,13 @@ private:
|
|||
TextEditor& textEditor;
|
||||
};
|
||||
|
||||
TextEditor& textEditor;
|
||||
static AccessibilityHandler::Interfaces makeInterfaces (TextEditor& textEditor)
|
||||
{
|
||||
if (textEditor.isReadOnly())
|
||||
return { std::make_unique<TextEditorValueInterface> (textEditor) };
|
||||
|
||||
return { std::make_unique<TextEditorTextInterface> (textEditor) };
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextEditorAccessibilityHandler)
|
||||
|
|
|
|||
|
|
@ -35,19 +35,27 @@ public:
|
|||
codeEditorComponentToWrap.isReadOnly() ? AccessibilityRole::staticText
|
||||
: AccessibilityRole::editableText,
|
||||
{},
|
||||
{ codeEditorComponentToWrap.isReadOnly() ? nullptr
|
||||
: std::make_unique<CodeEditorComponentTextInterface> (codeEditorComponentToWrap) }),
|
||||
codeEditorComponent (codeEditorComponentToWrap)
|
||||
makeInterfaces (codeEditorComponentToWrap))
|
||||
{
|
||||
}
|
||||
|
||||
String getTitle() const override
|
||||
{
|
||||
return codeEditorComponent.isReadOnly() ? codeEditorComponent.document.getAllContent()
|
||||
: codeEditorComponent.getTitle();
|
||||
}
|
||||
|
||||
private:
|
||||
class CodeEditorComponentValueInterface : public AccessibilityTextValueInterface
|
||||
{
|
||||
public:
|
||||
explicit CodeEditorComponentValueInterface (CodeEditorComponent& codeEditorComponentToWrap)
|
||||
: codeEditorComponent (codeEditorComponentToWrap)
|
||||
{
|
||||
}
|
||||
|
||||
bool isReadOnly() const override { return true; }
|
||||
String getCurrentValueAsString() const override { return codeEditorComponent.document.getAllContent(); }
|
||||
void setValueAsString (const String&) override {}
|
||||
|
||||
private:
|
||||
CodeEditorComponent& codeEditorComponent;
|
||||
};
|
||||
|
||||
class CodeEditorComponentTextInterface : public AccessibilityTextInterface
|
||||
{
|
||||
public:
|
||||
|
|
@ -144,7 +152,13 @@ private:
|
|||
CodeEditorComponent& codeEditorComponent;
|
||||
};
|
||||
|
||||
CodeEditorComponent& codeEditorComponent;
|
||||
static AccessibilityHandler::Interfaces makeInterfaces (CodeEditorComponent& codeEditorComponent)
|
||||
{
|
||||
if (codeEditorComponent.isReadOnly())
|
||||
return { std::make_unique<CodeEditorComponentValueInterface> (codeEditorComponent) };
|
||||
|
||||
return { std::make_unique<CodeEditorComponentTextInterface> (codeEditorComponent) };
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (CodeEditorAccessibilityHandler)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue