Accessible Scrollbar: Remove virtual children, value interface
Change-Id: I3a8e74130eb79d289143cb7ac7b8c47cdd3db90c Reviewed-on: http://codereview.qt-project.org/4819 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Jan-Arve Sæther <jan-arve.saether@nokia.com>
This commit is contained in:
parent
4ed5f2600f
commit
4f1e2aa27a
@ -497,121 +497,14 @@ QScrollBar *QAccessibleScrollBar::scrollBar() const
|
||||
return qobject_cast<QScrollBar*>(object());
|
||||
}
|
||||
|
||||
/*! \reimp */
|
||||
QRect QAccessibleScrollBar::rect(int child) const
|
||||
{
|
||||
if (!scrollBar()->isVisible())
|
||||
return QRect();
|
||||
|
||||
QStyle::SubControl subControl;
|
||||
switch (child) {
|
||||
case LineUp:
|
||||
subControl = QStyle ::SC_ScrollBarSubLine;
|
||||
break;
|
||||
case PageUp:
|
||||
subControl = QStyle::SC_ScrollBarSubPage;
|
||||
break;
|
||||
case Position:
|
||||
subControl = QStyle::SC_ScrollBarSlider;
|
||||
break;
|
||||
case PageDown:
|
||||
subControl = QStyle::SC_ScrollBarAddPage;
|
||||
break;
|
||||
case LineDown:
|
||||
subControl = QStyle::SC_ScrollBarAddLine;
|
||||
break;
|
||||
default:
|
||||
return QAccessibleAbstractSlider::rect(child);
|
||||
}
|
||||
|
||||
const QStyleOptionSlider option = qt_qscrollbarStyleOption(scrollBar());
|
||||
const QRect rect = scrollBar()->style()->subControlRect(QStyle::CC_ScrollBar, &option,
|
||||
subControl, scrollBar());
|
||||
const QPoint tp = scrollBar()->mapToGlobal(QPoint(0,0));
|
||||
return QRect(tp.x() + rect.x(), tp.y() + rect.y(), rect.width(), rect.height());
|
||||
}
|
||||
|
||||
/*! \reimp */
|
||||
int QAccessibleScrollBar::childCount() const
|
||||
{
|
||||
return LineDown;
|
||||
}
|
||||
|
||||
/*! \reimp */
|
||||
QString QAccessibleScrollBar::text(Text t, int child) const
|
||||
{
|
||||
switch (t) {
|
||||
case Value:
|
||||
if (!child || child == Position)
|
||||
return QString::number(scrollBar()->value());
|
||||
return QString();
|
||||
case Name:
|
||||
switch (child) {
|
||||
case LineUp:
|
||||
return QScrollBar::tr("Line up");
|
||||
case PageUp:
|
||||
return QScrollBar::tr("Page up");
|
||||
case Position:
|
||||
return QScrollBar::tr("Position");
|
||||
case PageDown:
|
||||
return QScrollBar::tr("Page down");
|
||||
case LineDown:
|
||||
return QScrollBar::tr("Line down");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (t == Value)
|
||||
return QString::number(scrollBar()->value());
|
||||
return QAccessibleAbstractSlider::text(t, child);
|
||||
}
|
||||
|
||||
/*! \reimp */
|
||||
QAccessible::Role QAccessibleScrollBar::role(int child) const
|
||||
{
|
||||
switch (child) {
|
||||
case LineUp:
|
||||
case PageUp:
|
||||
case PageDown:
|
||||
case LineDown:
|
||||
return PushButton;
|
||||
case Position:
|
||||
return Indicator;
|
||||
default:
|
||||
return ScrollBar;
|
||||
}
|
||||
}
|
||||
|
||||
/*! \reimp */
|
||||
QAccessible::State QAccessibleScrollBar::state(int child) const
|
||||
{
|
||||
const State parentState = QAccessibleAbstractSlider::state(0);
|
||||
|
||||
if (child == 0)
|
||||
return parentState;
|
||||
|
||||
// Inherit the Invisible state from parent.
|
||||
State state = parentState & QAccessible::Invisible;
|
||||
|
||||
// Disable left/right if we are at the minimum/maximum.
|
||||
const QScrollBar * const scrollBar = QAccessibleScrollBar::scrollBar();
|
||||
switch (child) {
|
||||
case LineUp:
|
||||
case PageUp:
|
||||
if (scrollBar->value() <= scrollBar->minimum())
|
||||
state |= Unavailable;
|
||||
break;
|
||||
case LineDown:
|
||||
case PageDown:
|
||||
if (scrollBar->value() >= scrollBar->maximum())
|
||||
state |= Unavailable;
|
||||
break;
|
||||
case Position:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
||||
#endif // QT_NO_SCROLLBAR
|
||||
|
||||
#ifndef QT_NO_SLIDER
|
||||
|
@ -154,22 +154,7 @@ class QAccessibleScrollBar : public QAccessibleAbstractSlider
|
||||
{
|
||||
public:
|
||||
explicit QAccessibleScrollBar(QWidget *w);
|
||||
|
||||
enum ScrollBarElements {
|
||||
ScrollBarSelf = 0,
|
||||
LineUp,
|
||||
PageUp,
|
||||
Position,
|
||||
PageDown,
|
||||
LineDown
|
||||
};
|
||||
|
||||
int childCount() const;
|
||||
|
||||
QRect rect(int child) const;
|
||||
QString text(Text t, int child) const;
|
||||
Role role(int child) const;
|
||||
State state(int child) const;
|
||||
|
||||
protected:
|
||||
QScrollBar *scrollBar() const;
|
||||
|
@ -1214,47 +1214,34 @@ void tst_QAccessibility::scrollBarTest()
|
||||
QScrollBar *scrollBar = new QScrollBar();
|
||||
QAccessibleInterface * const scrollBarInterface = QAccessible::queryAccessibleInterface(scrollBar);
|
||||
QVERIFY(scrollBarInterface);
|
||||
|
||||
QVERIFY(scrollBarInterface->state(0) & QAccessible::Invisible);
|
||||
QVERIFY(scrollBarInterface->state(PageUp) & QAccessible::Invisible);
|
||||
QVERIFY(scrollBarInterface->state(Position) & QAccessible::Invisible);
|
||||
QVERIFY(scrollBarInterface->state(PageDown) & QAccessible::Invisible);
|
||||
|
||||
QVERIFY(scrollBarInterface->state() & QAccessible::Invisible);
|
||||
scrollBar->show();
|
||||
QVERIFY(scrollBarInterface->state(0) ^ QAccessible::Invisible);
|
||||
QVERIFY(scrollBarInterface->state(PageUp) ^ QAccessible::Invisible);
|
||||
QVERIFY(scrollBarInterface->state(Position) ^ QAccessible::Invisible);
|
||||
QVERIFY(scrollBarInterface->state(PageDown) ^ QAccessible::Invisible);
|
||||
QVERIFY(scrollBarInterface->state() ^ QAccessible::Invisible);
|
||||
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(scrollBar, 0, QAccessible::ObjectShow)));
|
||||
QTestAccessibility::clearEvents();
|
||||
|
||||
scrollBar->hide();
|
||||
QVERIFY(scrollBarInterface->state(0) & QAccessible::Invisible);
|
||||
QVERIFY(scrollBarInterface->state(PageUp) & QAccessible::Invisible);
|
||||
QVERIFY(scrollBarInterface->state(Position) & QAccessible::Invisible);
|
||||
QVERIFY(scrollBarInterface->state(PageDown) & QAccessible::Invisible);
|
||||
QVERIFY(scrollBarInterface->state() & QAccessible::Invisible);
|
||||
QVERIFY(QTestAccessibility::events().contains(QTestAccessibilityEvent(scrollBar, 0, QAccessible::ObjectHide)));
|
||||
QTestAccessibility::clearEvents();
|
||||
|
||||
// Test that the left/right subcontrols are set to unavailable when the scrollBar is at the minimum/maximum.
|
||||
scrollBar->show();
|
||||
scrollBar->setMinimum(0);
|
||||
scrollBar->setMaximum(100);
|
||||
scrollBar->setMinimum(11);
|
||||
scrollBar->setMaximum(111);
|
||||
|
||||
QAccessibleValueInterface *valueIface = scrollBarInterface->valueInterface();
|
||||
QVERIFY(valueIface != 0);
|
||||
QCOMPARE(valueIface->minimumValue().toInt(), scrollBar->minimum());
|
||||
QCOMPARE(valueIface->maximumValue().toInt(), scrollBar->maximum());
|
||||
scrollBar->setValue(50);
|
||||
QVERIFY(scrollBarInterface->state(PageUp) ^ QAccessible::Unavailable);
|
||||
QVERIFY(scrollBarInterface->state(Position) ^ QAccessible::Unavailable);
|
||||
QVERIFY(scrollBarInterface->state(PageDown) ^ QAccessible::Unavailable);
|
||||
|
||||
QCOMPARE(valueIface->currentValue().toInt(), scrollBar->value());
|
||||
scrollBar->setValue(0);
|
||||
QVERIFY(scrollBarInterface->state(PageUp) & QAccessible::Unavailable);
|
||||
QVERIFY(scrollBarInterface->state(Position) ^ QAccessible::Unavailable);
|
||||
QVERIFY(scrollBarInterface->state(PageDown) ^ QAccessible::Unavailable);
|
||||
|
||||
QCOMPARE(valueIface->currentValue().toInt(), scrollBar->value());
|
||||
scrollBar->setValue(100);
|
||||
QVERIFY(scrollBarInterface->state(PageUp) ^ QAccessible::Unavailable);
|
||||
QVERIFY(scrollBarInterface->state(Position) ^ QAccessible::Unavailable);
|
||||
QVERIFY(scrollBarInterface->state(PageDown) & QAccessible::Unavailable);
|
||||
QCOMPARE(valueIface->currentValue().toInt(), scrollBar->value());
|
||||
valueIface->setCurrentValue(77);
|
||||
QCOMPARE(77, scrollBar->value());
|
||||
|
||||
delete scrollBarInterface;
|
||||
delete scrollBar;
|
||||
|
Loading…
Reference in New Issue
Block a user