An error occurred while loading the file. Please try again.
-
Jocelyn Turcotte authored
NOTE: To build after this you should rerun init-repository.py or run $> git submodule sync $> git submodule update $> git config qtwebengine.chromiumsrcdir src/3rdparty This makes everything build by adjusting paths. Other mixed-in changes: - Rename qtwebengine_src variables in scripts to qtwebengine_root to avoid confusion. - Cleanup the release and debug extra targets that were in lib.pro. This file has also been split into src.pro and core.pro. Change-Id: Ieee9158a65f526b15244eaca59e779b7069d337e Reviewed-by:
Zeno Albisser <zeno.albisser@digia.com> Reviewed-by:
Pierre Rossi <pierre.rossi@gmail.com>
1c5e3092
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
** This file is part of the QtGui module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see http://www.qt.io/terms-conditions. For further
** information use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** As a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qaccessible.h"
#include "qaccessiblecache_p.h"
#include "qaccessibleplugin.h"
#include "qaccessibleobject.h"
#include "qaccessiblebridge.h"
#include <QtCore/qtextboundaryfinder.h>
#include <QtGui/qclipboard.h>
#include <QtGui/qguiapplication.h>
#include <QtGui/qtextcursor.h>
#include <private/qguiapplication_p.h>
#include <qpa/qplatformaccessibility.h>
#include <qpa/qplatformintegration.h>
#include <QtCore/qdebug.h>
#include <QtCore/qmetaobject.h>
#include <QtCore/qhash.h>
#include <private/qfactoryloader_p.h>
QT_BEGIN_NAMESPACE
/*!
\class QAccessible
\brief The QAccessible class provides enums and static functions
related to accessibility.
\ingroup accessibility
\inmodule QtGui
This class is part of \l {Accessibility for QWidget Applications}.
Accessible applications can be used by people who are not able to
use applications by conventional means.
The functions in this class are used for communication between
accessible applications (also called AT Servers) and
accessibility tools (AT Clients), such as screen readers and
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
braille displays. Clients and servers communicate in the following way:
\list
\li \e{AT Servers} notify the clients about events through calls to the
updateAccessibility() function.
\li \e{AT Clients} request information about the objects in the server.
The QAccessibleInterface class is the core interface, and encapsulates
this information in a pure virtual API. Implementations of the interface
are provided by Qt through the queryAccessibleInterface() API.
\endlist
The communication between servers and clients is initialized by
the setRootObject() function. Function pointers can be installed
to replace or extend the default behavior of the static functions
in QAccessible.
Qt supports Microsoft Active Accessibility (MSAA), Mac OS X
Accessibility, and the Unix/X11 AT-SPI standard. Other backends
can be supported using QAccessibleBridge.
In the Unix/X11 AT-SPI implementation, applications become accessible
when two conditions are met:
\list
\li org.a11y.Status.IsEnabled DBus property is true
\li org.a11y.Status.ScreenReaderEnabled DBus property is true
\endlist
An alternative to setting the DBus AT-SPI properties is to set
the QT_LINUX_ACCESSIBILITY_ALWAYS_ON environment variable.
In addition to QAccessible's static functions, Qt offers one
generic interface, QAccessibleInterface, that can be used to wrap
all widgets and objects (e.g., QPushButton). This single
interface provides all the metadata necessary for the assistive
technologies. Qt provides implementations of this interface for
its built-in widgets as plugins.
When you develop custom widgets, you can create custom subclasses
of QAccessibleInterface and distribute them as plugins (using
QAccessiblePlugin) or compile them into the application.
Likewise, Qt's predefined accessibility support can be built as
plugin (the default) or directly into the Qt library. The main
advantage of using plugins is that the accessibility classes are
only loaded into memory if they are actually used; they don't
slow down the common case where no assistive technology is being
used.
Qt also includes two convenience classes, QAccessibleObject and
QAccessibleWidget, that inherit from QAccessibleInterface and
provide the lowest common denominator of metadata (e.g., widget
geometry, window title, basic help text). You can use them as
base classes when wrapping your custom QObject or QWidget
subclasses.
\sa QAccessibleInterface
*/
/*!
\class QAccessible::State
\inmodule QtGui
This structure defines bit flags that indicate
the state of an accessible object. The values are:
\value active The object is the active window or the active sub-element in a container (that would get focus when focusing the container).
\value adjustable The object represents an adjustable value, e.g. sliders.
\value animated The object's appearance changes frequently.
\value busy The object cannot accept input at the moment.
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
\value checkable The object is checkable.
\value checked The object's check box is checked.
\value checkStateMixed The third state of checkboxes (half checked in tri-state check boxes).
\value collapsed The object is collapsed, e.g. a closed listview item, or an iconified window.
\value defaultButton The object represents the default button in a dialog.
\value defunct The object no longer exists.
\value editable The object has a text carret (and often implements the text interface).
\value expandable The object is expandable, mostly used for cells in a tree view.
\value expanded The object is expanded, currently its children are visible.
\value extSelectable The object supports extended selection.
\value focusable The object can receive focus. Only objects in the active window can receive focus.
\value focused The object has keyboard focus.
\value hasPopup The object opens a popup.
\value hotTracked The object's appearance is sensitive to the mouse cursor position.
\value invalid The object is no longer valid (because it has been deleted).
\value invalidEntry Input validation current input invalid.
\value invisible The object is not visible to the user.
\value linked The object is linked to another object, e.g. a hyperlink.
\value marqueed The object displays scrolling contents, e.g. a log view.
\value modal The object blocks input from other objects.
\value movable The object can be moved.
\value multiLine The object has multiple lines of text (word wrap), as opposed to a single line.
\value multiSelectable The object supports multiple selected items.
\value offscreen The object is clipped by the visible area. Objects that are off screen are also invisible.
\value passwordEdit The object is a password field, e.g. a line edit for entering a Password.
\value playsSound The object produces sound when interacted with.
\value pressed The object is pressed.
\value readOnly The object can usually be edited, but is explicitly set to read-only.
\value searchEdit The object is a line edit that is the input for search queries.
\value selectable The object is selectable.
\value selectableText The object has text which can be selected. This is different from selectable which refers to the object's children.
\value selected The object is selected, this is independent of text selection.
\value selfVoicing The object describes itself through speech or sound.
\value sizeable The object can be resized, e.g. top-level windows.
\value summaryElement The object summarizes the state of the window and should be treated with priority.
\value supportsAutoCompletion The object has auto-completion, for example in line edits or combo boxes.
\value traversed The object is linked and has been visited.
\value updatesFrequently The object changes frequently and needs to be refreshed when accessing it.
\value disabled The object is unavailable to the user, e.g. a disabled widget.
Implementations of QAccessibleInterface::state() return a combination
of these flags.
*/
/*!
\fn QAccessible::State::State()
Constructs a new QAccessible::State with all states set to false.
*/
/*!
\enum QAccessible::Event
This enum type defines accessible event types.
\omitvalue InvalidEvent Internal: Used when creating subclasses of QAccessibleEvent.
\value AcceleratorChanged The keyboard accelerator for an action has been changed.
\value ActionChanged An action has been changed.
\value ActiveDescendantChanged
\value Alert A system alert (e.g., a message from a QMessageBox)
\value AttributeChanged
\value ContextHelpEnd Context help (QWhatsThis) for an object is finished.
\value ContextHelpStart Context help (QWhatsThis) for an object is initiated.
\value DefaultActionChanged The default QAccessible::Action for the accessible
object has changed.
\value DescriptionChanged The object's QAccessible::Description changed.
\value DialogEnd A dialog (QDialog) has been hidden
\value DialogStart A dialog (QDialog) has been set visible.
\value DocumentContentChanged The contents of a text document have changed.
\value DocumentLoadComplete A document has been loaded.
211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
\value DocumentLoadStopped A document load has been stopped.
\value DocumentReload A document reload has been initiated.
\value DragDropEnd A drag and drop operation is about to finished.
\value DragDropStart A drag and drop operation is about to be initiated.
\value Focus An object has gained keyboard focus.
\value ForegroundChanged A window has been activated (i.e., a new window has
gained focus on the desktop).
\value HelpChanged The QAccessible::Help text property of an object has
changed.
\value HyperlinkEndIndexChanged The end position of the display text for a hypertext
link has changed.
\value HyperlinkNumberOfAnchorsChanged The number of anchors in a hypertext link has changed,
perhaps because the display text has been split to
provide more than one link.
\value HyperlinkSelectedLinkChanged The link for the selected hypertext link has changed.
\value HyperlinkStartIndexChanged The start position of the display text for a hypertext
link has changed.
\value HypertextChanged The display text for a hypertext link has changed.
\value HypertextLinkActivated A hypertext link has been activated, perhaps by being
clicked or via a key press.
\value HypertextLinkSelected A hypertext link has been selected.
\value HypertextNLinksChanged
\value LocationChanged An object's location on the screen has changed.
\value MenuCommand A menu item is triggered.
\value MenuEnd A menu has been closed (Qt uses PopupMenuEnd for all
menus).
\value MenuStart A menu has been opened on the menubar (Qt uses
PopupMenuStart for all menus).
\value NameChanged The QAccessible::Name property of an object has changed.
\value ObjectAttributeChanged
\value ObjectCreated A new object is created.
\value ObjectDestroyed An object is deleted.
\value ObjectHide An object is hidden; for example, with QWidget::hide().
Any children the object that is hidden has do not send
this event. It is not sent when an object is hidden as
it is being obcured by others.
\value ObjectReorder A layout or item view has added, removed, or moved an
object (Qt does not use this event).
\value ObjectShow An object is displayed; for example, with
QWidget::show().
\value PageChanged
\value ParentChanged An object's parent object changed.
\value PopupMenuEnd A pop-up menu has closed.
\value PopupMenuStart A pop-up menu has opened.
\value ScrollingEnd A scrollbar scroll operation has ended (the mouse has
released the slider handle).
\value ScrollingStart A scrollbar scroll operation is about to start; this may
be caused by a mouse press on the slider handle, for
example.
\value SectionChanged
\value SelectionAdd An item has been added to the selection in an item view.
\value SelectionRemove An item has been removed from an item view selection.
\value Selection The selection has changed in a menu or item view.
\value SelectionWithin Several changes to a selection has occurred in an item
view.
\value SoundPlayed A sound has been played by an object
\omitvalue StateChanged The QAccessible::State of an object has changed.
This value is used internally for the QAccessibleStateChangeEvent.
\value TableCaptionChanged A table caption has been changed.
\value TableColumnDescriptionChanged The description of a table column, typically found in
the column's header, has been changed.
\value TableColumnHeaderChanged A table column header has been changed.
\omitvalue TableModelChanged The model providing data for a table has been changed.
\value TableRowDescriptionChanged The description of a table row, typically found in the
row's header, has been changed.
\value TableRowHeaderChanged A table row header has been changed.
\value TableSummaryChanged The summary of a table has been changed.
\omitvalue TextAttributeChanged
\omitvalue TextCaretMoved The caret has moved in an editable widget.
The caret represents the cursor position in an editable
281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
widget with the input focus.
\value TextColumnChanged A text column has been changed.
\omitvalue TextInserted Text has been inserted into an editable widget.
\omitvalue TextRemoved Text has been removed from an editable widget.
\omitvalue TextSelectionChanged The selected text has changed in an editable widget.
\omitvalue TextUpdated The text has been update in an editable widget.
\omitvalue ValueChanged The QAccessible::Value of an object has changed.
\value VisibleDataChanged
The values for this enum are defined to be the same as those defined in the
\l{AccessibleEventID.idl File Reference}{IAccessible2} and
\l{Microsoft Active Accessibility Event Constants}{MSAA} specifications.
*/
/*!
\enum QAccessible::Role
This enum defines the role of an accessible object. The roles are:
\value AlertMessage An object that is used to alert the user.
\value Animation An object that displays an animation.
\value Application The application's main window.
\value Assistant An object that provids interactive help.
\value Border An object that represents a border.
\value ButtonDropDown A button that drops down a list of items.
\value ButtonDropGrid A button that drops down a grid.
\value ButtonMenu A button that drops down a menu.
\value Canvas An object that displays graphics that the user can interact with.
\value Caret An object that represents the system caret (text cursor).
\value Cell A cell in a table.
\value Chart An object that displays a graphical representation of data.
\value CheckBox An object that represents an option that can be checked or unchecked. Some options provide a "mixed" state, e.g. neither checked nor unchecked.
\value Client The client area in a window.
\value Clock A clock displaying time.
\value ColorChooser A dialog that lets the user choose a color.
\value Column A column of cells, usually within a table.
\value ColumnHeader A header for a column of data.
\value ComboBox A list of choices that the user can select from.
\value ComplementaryContent A part of the document or web page that is complementary to the main content, usually a landmark (see WAI-ARIA).
\value Cursor An object that represents the mouse cursor.
\value Desktop The object represents the desktop or workspace.
\value Dial An object that represents a dial or knob.
\value Dialog A dialog box.
\value Document A document, for example in an office application.
\value EditableText Editable text such as a line or text edit.
\value Equation An object that represents a mathematical equation.
\value Footer A footer in a page (usually in documents).
\value Form A web form containing controls.
\value Graphic A graphic or picture, e.g. an icon.
\value Grip A grip that the user can drag to change the size of widgets.
\value Grouping An object that represents a logical grouping of other objects.
\value Heading A heading in a document.
\value HelpBalloon An object that displays help in a separate, short lived window.
\value HotkeyField A hotkey field that allows the user to enter a key sequence.
\value Indicator An indicator that represents a current value or item.
\value LayeredPane An object that can contain layered children, e.g. in a stack.
\value Link A link to something else.
\value List A list of items, from which the user can select one or more items.
\value ListItem An item in a list of items.
\value MenuBar A menu bar from which menus are opened by the user.
\value MenuItem An item in a menu or menu bar.
\value NoRole The object has no role. This usually indicates an invalid object.
\value Note A section whose content is parenthetic or ancillary to the main content of the resource.
\value PageTab A page tab that the user can select to switch to a different page in a dialog.
\value PageTabList A list of page tabs.
\value Paragraph A paragraph of text (usually found in documents).
\value Pane A generic container.
\value PopupMenu A menu which lists options that the user can select to perform an action.
\value ProgressBar The object displays the progress of an operation in progress.
\value PropertyPage A property page where the user can change options and settings.
351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
\value Button A button.
\value RadioButton An object that represents an option that is mutually exclusive with other options.
\value Row A row of cells, usually within a table.
\value RowHeader A header for a row of data.
\value ScrollBar A scroll bar, which allows the user to scroll the visible area.
\value Section A section (in a document).
\value Separator A separator that divides space into logical areas.
\value Slider A slider that allows the user to select a value within a given range.
\value Sound An object that represents a sound.
\value SpinBox A spin box widget that allows the user to enter a value within a given range.
\value Splitter A splitter distributing available space between its child widgets.
\value StaticText Static text, such as labels for other widgets.
\value StatusBar A status bar.
\value Table A table representing data in a grid of rows and columns.
\value Terminal A terminal or command line interface.
\value TitleBar The title bar caption of a window.
\value ToolBar A tool bar, which groups widgets that the user accesses frequently.
\value ToolTip A tool tip which provides information about other objects.
\value Tree A list of items in a tree structure.
\value TreeItem An item in a tree structure.
\value UserRole The first value to be used for user defined roles.
\value WebDocument HTML document, usually in a browser.
\value Whitespace Blank space between other objects.
\value Window A top level window.
*/
/*!
\enum QAccessible::RelationFlag
This enum type defines bit flags that can be combined to indicate
the relationship between two accessible objects.
\value Label The first object is the label of the second object.
\value Labelled The first object is labelled by the second object.
\value Controller The first object controls the second object.
\value Controlled The first object is controlled by the second object.
\value AllRelations Used as a mask to specify that we are interesting in information
about all relations
Implementations of relations() return a combination of these flags.
Some values are mutually exclusive.
*/
/*!
\enum QAccessible::Text
This enum specifies string information that an accessible object
returns.
\value Name The name of the object. This can be used both
as an identifier or a short description by
accessible clients.
\value Description A short text describing the object.
\value Value The value of the object.
\value Help A longer text giving information about how to use the object.
\value Accelerator The keyboard shortcut that executes the object's default action.
\value UserText The first value to be used for user defined text.
\omitvalue DebugDescription
*/
/*! \enum QAccessible::TextBoundaryType
This enum describes different types of text boundaries. It follows the IAccessible2 API and is used in the \l QAccessibleTextInterface.
\value CharBoundary Use individual characters as boundary.
\value WordBoundary Use words as boundaries.
\value SentenceBoundary Use sentences as boundary.
\value ParagraphBoundary Use paragraphs as boundary.
\value LineBoundary Use newlines as boundary.
\value NoBoundary No boundary (use the whole text).
421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
\sa QAccessibleTextInterface
*/
/*!
\enum QAccessible::InterfaceType
\l QAccessibleInterface supports several sub interfaces.
In order to provide more information about some objects, their accessible
representation should implement one or more of these interfaces.
\note When subclassing one of these interfaces, \l QAccessibleInterface::interface_cast() needs to be implemented.
\value TextInterface For text that supports selections or is more than one line. Simple labels do not need to implement this interface.
\omitvalue EditableTextInterface For text that can be edited by the user.
\value ValueInterface For objects that are used to manipulate a value, for example slider or scroll bar.
\value ActionInterface For interactive objects that allow the user to trigger an action. Basically everything that allows for example mouse interaction.
\omitvalue ImageInterface For objects that represent an image. This interface is generally less important.
\value TableInterface For lists, tables and trees.
\value TableCellInterface For cells in a TableInterface object.
\sa QAccessibleInterface::interface_cast(), QAccessibleTextInterface, QAccessibleValueInterface, QAccessibleActionInterface, QAccessibleTableInterface, QAccessibleTableCellInterface
*/
/*!
\fn QAccessibleInterface::~QAccessibleInterface()
Destroys the object.
*/
/*!
\typedef QAccessible::Id
\relates QAccessible
Synonym for unsigned, used by the QAccessibleInterface cache.
*/
#ifndef QT_NO_ACCESSIBILITY
/* accessible widgets plugin discovery stuff */
#ifndef QT_NO_LIBRARY
Q_GLOBAL_STATIC_WITH_ARGS(QFactoryLoader, loader,
(QAccessibleFactoryInterface_iid, QLatin1String("/accessible")))
#endif
// FIXME turn this into one global static struct
Q_GLOBAL_STATIC(QList<QAccessible::InterfaceFactory>, qAccessibleFactories)
typedef QHash<QString, QAccessiblePlugin*> QAccessiblePluginsHash;
Q_GLOBAL_STATIC(QAccessiblePluginsHash, qAccessiblePlugins)
Q_GLOBAL_STATIC(QList<QAccessible::ActivationObserver *>, qAccessibleActivationObservers)
QAccessible::UpdateHandler QAccessible::updateHandler = 0;
QAccessible::RootObjectHandler QAccessible::rootObjectHandler = 0;
static bool cleanupAdded = false;
static QPlatformAccessibility *platformAccessibility()
{
QPlatformIntegration *pfIntegration = QGuiApplicationPrivate::platformIntegration();
return pfIntegration ? pfIntegration->accessibility() : 0;
}
/*!
\fn QAccessible::QAccessible()
\internal
This class is purely a collection of enums and static functions,
it is not supposed to be instantiated.
*/
491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
/*!
\internal
*/
void QAccessible::cleanup()
{
if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
pfAccessibility->cleanup();
}
static void qAccessibleCleanup()
{
qAccessibleActivationObservers()->clear();
qAccessibleFactories()->clear();
}
/*!
\typedef QAccessible::InterfaceFactory
This is a typedef for a pointer to a function with the following
signature:
\snippet code/src_gui_accessible_qaccessible.cpp 1
The function receives a QString and a QObject pointer, where the
QString is the key identifying the interface. The QObject is used
to pass on to the QAccessibleInterface so that it can hold a reference
to it.
If the key and the QObject does not have a corresponding
QAccessibleInterface, a null-pointer will be returned.
Installed factories are called by queryAccessibilityInterface() until
one provides an interface.
*/
/*!
\typedef QAccessible::UpdateHandler
\internal
A function pointer type. Use a function with this prototype to install
your own update function.
The function is called by updateAccessibility().
*/
/*!
\typedef QAccessible::RootObjectHandler
\internal
A function pointer type. Use a function with this prototype to install
your own root object handler.
The function is called by setRootObject().
*/
/*!
Installs the InterfaceFactory \a factory. The last factory added
is the first one used by queryAccessibleInterface().
*/
void QAccessible::installFactory(InterfaceFactory factory)
{
if (!factory)
return;
if (!cleanupAdded) {
qAddPostRoutine(qAccessibleCleanup);
561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
cleanupAdded = true;
}
if (qAccessibleFactories()->contains(factory))
return;
qAccessibleFactories()->append(factory);
}
/*!
Removes \a factory from the list of installed InterfaceFactories.
*/
void QAccessible::removeFactory(InterfaceFactory factory)
{
qAccessibleFactories()->removeAll(factory);
}
/*!
\internal
Installs the given \a handler as the function to be used by
updateAccessibility(), and returns the previously installed
handler.
*/
QAccessible::UpdateHandler QAccessible::installUpdateHandler(UpdateHandler handler)
{
UpdateHandler old = updateHandler;
updateHandler = handler;
return old;
}
/*!
\internal
Installs the given \a handler as the function to be used by setRootObject(),
and returns the previously installed handler.
*/
QAccessible::RootObjectHandler QAccessible::installRootObjectHandler(RootObjectHandler handler)
{
RootObjectHandler old = rootObjectHandler;
rootObjectHandler = handler;
return old;
}
/*!
\class QAccessible::ActivationObserver
\internal
Interface to listen to activation or deactivation of the accessibility framework.
\sa installActivationObserver()
*/
/*!
\internal
Install \a observer to get notified of activation or deactivation (global accessibility has been enabled or disabled).
*/
void QAccessible::installActivationObserver(QAccessible::ActivationObserver *observer)
{
if (!observer)
return;
if (!cleanupAdded) {
qAddPostRoutine(qAccessibleCleanup);
cleanupAdded = true;
}
if (qAccessibleActivationObservers()->contains(observer))
return;
qAccessibleActivationObservers()->append(observer);
}
/*!
631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700
\internal
Remove an \a observer to no longer get notified of state changes.
\sa installActivationObserver()
*/
void QAccessible::removeActivationObserver(ActivationObserver *observer)
{
qAccessibleActivationObservers()->removeAll(observer);
}
/*!
If a QAccessibleInterface implementation exists for the given \a object,
this function returns a pointer to the implementation; otherwise it
returns 0.
The function calls all installed factory functions (from most
recently installed to least recently installed) until one is found
that provides an interface for the class of \a object. If no
factory can provide an accessibility implementation for the class
the function loads installed accessibility plugins, and tests if
any of the plugins can provide the implementation.
If no implementation for the object's class is available, the
function tries to find an implementation for the object's parent
class, using the above strategy.
All interfaces are managed by an internal cache and should not be deleted.
*/
QAccessibleInterface *QAccessible::queryAccessibleInterface(QObject *object)
{
if (!object)
return 0;
if (Id id = QAccessibleCache::instance()->objectToId.value(object))
return QAccessibleCache::instance()->interfaceForId(id);
// Create a QAccessibleInterface for the object class. Start by the most
// derived class and walk up the class hierarchy.
const QMetaObject *mo = object->metaObject();
while (mo) {
const QString cn = QLatin1String(mo->className());
// Check if the class has a InterfaceFactory installed.
for (int i = qAccessibleFactories()->count(); i > 0; --i) {
InterfaceFactory factory = qAccessibleFactories()->at(i - 1);
if (QAccessibleInterface *iface = factory(cn, object)) {
QAccessibleCache::instance()->insert(object, iface);
Q_ASSERT(QAccessibleCache::instance()->objectToId.contains(object));
return iface;
}
}
#ifndef QT_NO_LIBRARY
// Find a QAccessiblePlugin (factory) for the class name. If there's
// no entry in the cache try to create it using the plugin loader.
if (!qAccessiblePlugins()->contains(cn)) {
QAccessiblePlugin *factory = 0; // 0 means "no plugin found". This is cached as well.
const int index = loader()->indexOf(cn);
if (index != -1)
factory = qobject_cast<QAccessiblePlugin *>(loader()->instance(index));
qAccessiblePlugins()->insert(cn, factory);
}
// At this point the cache should contain a valid factory pointer or 0:
Q_ASSERT(qAccessiblePlugins()->contains(cn));
QAccessiblePlugin *factory = qAccessiblePlugins()->value(cn);
if (factory) {
QAccessibleInterface *result = factory->create(cn, object);
if (result) { // Need this condition because of QDesktopScreenWidget
QAccessibleCache::instance()->insert(object, result);
Q_ASSERT(QAccessibleCache::instance()->objectToId.contains(object));
701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770
}
return result;
}
#endif
mo = mo->superClass();
}
if (object == qApp) {
QAccessibleInterface *appInterface = new QAccessibleApplication;
QAccessibleCache::instance()->insert(object, appInterface);
Q_ASSERT(QAccessibleCache::instance()->objectToId.contains(qApp));
return appInterface;
}
return 0;
}
/*!
\brief Call this function to ensure that manually created interfaces
are properly memory managed.
Must only be called exactly once per interface \a iface.
This is implicitly called when calling queryAccessibleInterface,
calling this function is only required when QAccessibleInterfaces
are instantiated with the "new" operator. This is not recommended,
whenever possible use the default functions and let \l queryAccessibleInterface()
take care of this.
When it is necessary to reimplement the QAccessibleInterface::child() function
and returning the child after constructing it, this function needs to be called.
*/
QAccessible::Id QAccessible::registerAccessibleInterface(QAccessibleInterface *iface)
{
Q_ASSERT(iface);
return QAccessibleCache::instance()->insert(iface->object(), iface);
}
/*!
Removes the interface belonging to this \a id from the cache and
deletes it. The id becomes invalid an may be re-used by the
cache.
*/
void QAccessible::deleteAccessibleInterface(Id id)
{
QAccessibleCache::instance()->deleteInterface(id);
}
/*!
Returns the unique ID for the QAccessibleInterface \a iface.
*/
QAccessible::Id QAccessible::uniqueId(QAccessibleInterface *iface)
{
Id id = QAccessibleCache::instance()->idToInterface.key(iface);
if (!id)
id = registerAccessibleInterface(iface);
return id;
}
/*!
Returns the QAccessibleInterface belonging to the \a id.
Returns 0 if the id is invalid.
*/
QAccessibleInterface *QAccessible::accessibleInterface(Id id)
{
return QAccessibleCache::instance()->idToInterface.value(id);
}
/*!
771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
Returns \c true if the platform requested accessibility information.
This function will return false until a tool such as a screen reader
accessed the accessibility framework. It is still possible to use
\l QAccessible::queryAccessibleInterface() even if accessibility is not
active. But there will be no notifications sent to the platform.
It is recommended to use this function to prevent expensive notifications
via updateAccessibility() when they are not needed.
*/
bool QAccessible::isActive()
{
if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
return pfAccessibility->isActive();
return false;
}
/*!
\internal
*/
void QAccessible::setActive(bool active)
{
for (int i = 0; i < qAccessibleActivationObservers()->count() ;++i)
qAccessibleActivationObservers()->at(i)->accessibilityActiveChanged(active);
}
/*!
Sets the root object of the accessible objects of this application
to \a object. All other accessible objects are reachable using object
navigation from the root object.
Normally, it isn't necessary to call this function, because Qt sets
the QApplication object as the root object immediately before the
event loop is entered in QApplication::exec().
Use QAccessible::installRootObjectHandler() to redirect the function
call to a customized handler function.
\sa queryAccessibleInterface()
*/
void QAccessible::setRootObject(QObject *object)
{
if (rootObjectHandler) {
rootObjectHandler(object);
return;
}
if (QPlatformAccessibility *pfAccessibility = platformAccessibility())
pfAccessibility->setRootObject(object);
}
/*!
Notifies about a change that might be relevant for accessibility clients.
\a event provides details about the change. These include the source
of the change and the nature of the change. The \a event should
contain enough information give meaningful notifications.
For example, the type \c ValueChange indicates that the position of
a slider has been changed.
Call this function whenever the state of your accessible object or
one of its sub-elements has been changed either programmatically
(e.g. by calling QLabel::setText()) or by user interaction.
If there are no accessibility tools listening to this event, the
performance penalty for calling this function is small, but if
determining the parameters of the call is expensive you can test
QAccessible::isActive() to avoid unnecessary computation.