1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Accessibility: Removed widget_handlers

This commit is contained in:
ed 2021-05-20 17:48:41 +01:00
parent 88313c26b6
commit 333983947e
17 changed files with 321 additions and 623 deletions

View file

@ -1,96 +0,0 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
/** Basic accessible interface for a Button that can be clicked or toggled.
@tags{Accessibility}
*/
class JUCE_API ButtonAccessibilityHandler : public AccessibilityHandler
{
public:
explicit ButtonAccessibilityHandler (Button& buttonToWrap)
: AccessibilityHandler (buttonToWrap,
getButtonRole (buttonToWrap),
getAccessibilityActions (buttonToWrap)),
button (buttonToWrap)
{
}
AccessibleState getCurrentState() const override
{
auto state = AccessibilityHandler::getCurrentState();
if (button.getClickingTogglesState())
{
state = state.withCheckable();
if (button.getToggleState())
state = state.withChecked();
}
return state;
}
String getTitle() const override
{
auto title = AccessibilityHandler::getTitle();
if (title.isEmpty())
return button.getButtonText();
return title;
}
private:
static AccessibilityRole getButtonRole (const Button& b)
{
if (b.getRadioGroupId() != 0) return AccessibilityRole::radioButton;
if (b.getClickingTogglesState()) return AccessibilityRole::toggleButton;
return AccessibilityRole::button;
}
static AccessibilityActions getAccessibilityActions (Button& button)
{
auto actions = AccessibilityActions().addAction (AccessibilityActionType::press,
[&button] { button.triggerClick(); });
if (button.getClickingTogglesState())
actions = actions.addAction (AccessibilityActionType::toggle,
[&button] { button.setToggleState (! button.getToggleState(), sendNotification); });
return actions;
}
Button& button;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ButtonAccessibilityHandler)
};
} // namespace juce

View file

@ -1,66 +0,0 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
/** Basic accessible interface for a ComboBox that can show a menu.
@tags{Accessibility}
*/
class JUCE_API ComboBoxAccessibilityHandler : public AccessibilityHandler
{
public:
explicit ComboBoxAccessibilityHandler (ComboBox& comboBoxToWrap)
: AccessibilityHandler (comboBoxToWrap,
AccessibilityRole::comboBox,
getAccessibilityActions (comboBoxToWrap)),
comboBox (comboBoxToWrap)
{
}
AccessibleState getCurrentState() const override
{
auto state = AccessibilityHandler::getCurrentState().withExpandable();
return comboBox.isPopupActive() ? state.withExpanded() : state.withCollapsed();
}
String getTitle() const override { return comboBox.getText(); }
private:
static AccessibilityActions getAccessibilityActions (ComboBox& comboBox)
{
return AccessibilityActions().addAction (AccessibilityActionType::press, [&comboBox] { comboBox.showPopup(); })
.addAction (AccessibilityActionType::showMenu, [&comboBox] { comboBox.showPopup(); });
}
ComboBox& comboBox;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ComboBoxAccessibilityHandler)
};
} // namespace juce

View file

@ -1,62 +0,0 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
/** Basic accessible interface for a Label that can also show a TextEditor
when clicked.
@tags{Accessibility}
*/
class JUCE_API LabelAccessibilityHandler : public AccessibilityHandler
{
public:
explicit LabelAccessibilityHandler (Label& labelToWrap)
: AccessibilityHandler (labelToWrap,
AccessibilityRole::staticText,
getAccessibilityActions (labelToWrap)),
label (labelToWrap)
{
}
String getTitle() const override { return label.getText(); }
private:
static AccessibilityActions getAccessibilityActions (Label& label)
{
if (label.isEditable())
return AccessibilityActions().addAction (AccessibilityActionType::press, [&label] { label.showEditor(); });
return {};
}
Label& label;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (LabelAccessibilityHandler)
};
} // namespace juce

View file

@ -1,100 +0,0 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
/** Basic accessible interface for a Slider.
@tags{Accessibility}
*/
class JUCE_API SliderAccessibilityHandler : public AccessibilityHandler
{
public:
explicit SliderAccessibilityHandler (Slider& sliderToWrap)
: AccessibilityHandler (sliderToWrap,
AccessibilityRole::slider,
{},
{ std::make_unique<SliderValueInterface> (sliderToWrap) })
{
}
private:
class SliderValueInterface : public AccessibilityValueInterface
{
public:
explicit SliderValueInterface (Slider& sliderToWrap)
: slider (sliderToWrap)
{
}
bool isReadOnly() const override { return false; }
double getCurrentValue() const override
{
return slider.isTwoValue() ? slider.getMaxValue() : slider.getValue();
}
void setValue (double newValue) override
{
if (slider.isTwoValue())
slider.setMaxValue (newValue, sendNotification);
else
slider.setValue (newValue, sendNotification);
}
String getCurrentValueAsString() const override
{
return slider.getTextFromValue (getCurrentValue());
}
void setValueAsString (const String& newValue) override
{
setValue (slider.getValueFromText (newValue));
}
AccessibleValueRange getRange() const override
{
return { { slider.getMinimum(), slider.getMaximum() },
getStepSize() };
}
private:
double getStepSize() const
{
auto interval = slider.getInterval();
return interval != 0.0 ? interval
: slider.proportionOfLengthToValue (0.01);
}
Slider& slider;
};
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (SliderAccessibilityHandler)
};
} // namespace juce

View file

@ -1,83 +0,0 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
/** Basic accessible interface for a TableListBox.
@tags{Accessibility}
*/
class JUCE_API TableListBoxAccessibilityHandler : public AccessibilityHandler
{
public:
explicit TableListBoxAccessibilityHandler (TableListBox& tableListBoxToWrap)
: AccessibilityHandler (tableListBoxToWrap,
AccessibilityRole::list,
{},
{ std::make_unique<TableListBoxTableInterface> (tableListBoxToWrap) })
{
}
private:
class TableListBoxTableInterface : public AccessibilityTableInterface
{
public:
explicit TableListBoxTableInterface (TableListBox& tableListBoxToWrap)
: tableListBox (tableListBoxToWrap)
{
}
int getNumRows() const override
{
if (auto* model = tableListBox.getModel())
return model->getNumRows();
return 0;
}
int getNumColumns() const override
{
return tableListBox.getHeader().getNumColumns (false);
}
const AccessibilityHandler* getCellHandler (int row, int column) const override
{
if (isPositiveAndBelow (row, getNumRows()) && isPositiveAndBelow (column, getNumColumns()))
if (auto* cellComponent = tableListBox.getCellComponent (tableListBox.getHeader().getColumnIdOfIndex (column, false), row))
return cellComponent->getAccessibilityHandler();
return nullptr;
}
private:
TableListBox& tableListBox;
};
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TableListBoxAccessibilityHandler)
};
} // namespace juce

View file

@ -1,108 +0,0 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
/** Basic accessible interface for a TextEditor.
@tags{Accessibility}
*/
class JUCE_API TextEditorAccessibilityHandler : public AccessibilityHandler
{
public:
explicit TextEditorAccessibilityHandler (TextEditor& textEditorToWrap)
: AccessibilityHandler (textEditorToWrap,
textEditorToWrap.isReadOnly() ? AccessibilityRole::staticText : AccessibilityRole::editableText,
{},
{ textEditorToWrap.isReadOnly() ? nullptr : std::make_unique<TextEditorTextInterface> (textEditorToWrap) }),
textEditor (textEditorToWrap)
{
}
String getTitle() const override
{
return textEditor.isReadOnly() ? textEditor.getText() : textEditor.getTitle();
}
private:
class TextEditorTextInterface : public AccessibilityTextInterface
{
public:
explicit TextEditorTextInterface (TextEditor& editor)
: textEditor (editor)
{
}
bool isDisplayingProtectedText() const override { return textEditor.getPasswordCharacter() != 0; }
int getTotalNumCharacters() const override { return textEditor.getText().length(); }
Range<int> getSelection() const override { return textEditor.getHighlightedRegion(); }
void setSelection (Range<int> r) override { textEditor.setHighlightedRegion (r); }
String getText (Range<int> r) const override
{
if (isDisplayingProtectedText())
return String::repeatedString (String::charToString (textEditor.getPasswordCharacter()),
getTotalNumCharacters());
return textEditor.getTextInRange (r);
}
void setText (const String& newText) override
{
textEditor.setText (newText);
}
int getTextInsertionOffset() const override { return textEditor.getCaretPosition(); }
RectangleList<int> getTextBounds (Range<int> textRange) const override
{
auto localRects = textEditor.getTextBounds (textRange);
RectangleList<int> globalRects;
std::for_each (localRects.begin(), localRects.end(),
[&] (const Rectangle<int>& r) { globalRects.add (textEditor.localAreaToGlobal (r)); });
return globalRects;
}
int getOffsetAtPoint (Point<int> point) const override
{
auto localPoint = textEditor.getLocalPoint (nullptr, point);
return textEditor.getTextIndexAt (localPoint.x, localPoint.y);
}
private:
TextEditor& textEditor;
};
TextEditor& textEditor;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TextEditorAccessibilityHandler)
};
} // namespace juce

View file

@ -1,79 +0,0 @@
/*
==============================================================================
This file is part of the JUCE library.
Copyright (c) 2020 - Raw Material Software Limited
JUCE is an open source library subject to commercial or open-source
licensing.
By using JUCE, you agree to the terms of both the JUCE 6 End-User License
Agreement and JUCE Privacy Policy (both effective as of the 16th June 2020).
End User License Agreement: www.juce.com/juce-6-licence
Privacy Policy: www.juce.com/juce-privacy-policy
Or: You may also use this code under the terms of the GPL v3 (see
www.gnu.org/licenses).
JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
DISCLAIMED.
==============================================================================
*/
namespace juce
{
/** Basic accessible interface for a TreeView.
@tags{Accessibility}
*/
class JUCE_API TreeViewAccessibilityHandler : public AccessibilityHandler
{
public:
explicit TreeViewAccessibilityHandler (TreeView& treeViewToWrap)
: AccessibilityHandler (treeViewToWrap,
AccessibilityRole::tree,
{},
{ std::make_unique<TreeViewTableInterface> (treeViewToWrap) })
{
}
private:
class TreeViewTableInterface : public AccessibilityTableInterface
{
public:
explicit TreeViewTableInterface (TreeView& treeViewToWrap)
: treeView (treeViewToWrap)
{
}
int getNumRows() const override
{
return treeView.getNumRowsInTree();
}
int getNumColumns() const override
{
return 1;
}
const AccessibilityHandler* getCellHandler (int row, int) const override
{
if (auto* itemComp = treeView.getItemComponent (treeView.getItemOnRow (row)))
return itemComp->getAccessibilityHandler();
return nullptr;
}
private:
TreeView& treeView;
};
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TreeViewAccessibilityHandler)
};
} // namespace juce