qaccessible.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2016 The Qt Company Ltd.
  4. ** Contact: https://www.qt.io/licensing/
  5. **
  6. ** This file is part of the QtGui module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and The Qt Company. For licensing terms
  14. ** and conditions see https://www.qt.io/terms-conditions. For further
  15. ** information use the contact form at https://www.qt.io/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 3 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL3 included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 3 requirements
  23. ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
  24. **
  25. ** GNU General Public License Usage
  26. ** Alternatively, this file may be used under the terms of the GNU
  27. ** General Public License version 2.0 or (at your option) the GNU General
  28. ** Public license version 3 or any later version approved by the KDE Free
  29. ** Qt Foundation. The licenses are as published by the Free Software
  30. ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
  31. ** included in the packaging of this file. Please review the following
  32. ** information to ensure the GNU General Public License requirements will
  33. ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
  34. ** https://www.gnu.org/licenses/gpl-3.0.html.
  35. **
  36. ** $QT_END_LICENSE$
  37. **
  38. ****************************************************************************/
  39. #include <QtCore/qglobal.h>
  40. #ifndef QT_NO_ACCESSIBILITY
  41. #ifndef QACCESSIBLE_H
  42. #define QACCESSIBLE_H
  43. #include <QtCore/qcoreapplication.h>
  44. #include <QtCore/qdebug.h>
  45. #include <QtCore/qglobal.h>
  46. #include <QtCore/qobject.h>
  47. #include <QtCore/qrect.h>
  48. #include <QtCore/qset.h>
  49. #include <QtCore/qvector.h>
  50. #include <QtCore/qvariant.h>
  51. #include <QtGui/qcolor.h>
  52. #include <QtGui/qevent.h>
  53. #include <stdlib.h>
  54. QT_BEGIN_NAMESPACE
  55. class QAccessibleInterface;
  56. class QAccessibleEvent;
  57. class QWindow;
  58. class QTextCursor;
  59. class Q_GUI_EXPORT QAccessible
  60. {
  61. Q_GADGET
  62. public:
  63. enum Event {
  64. SoundPlayed = 0x0001,
  65. Alert = 0x0002,
  66. ForegroundChanged = 0x0003,
  67. MenuStart = 0x0004,
  68. MenuEnd = 0x0005,
  69. PopupMenuStart = 0x0006,
  70. PopupMenuEnd = 0x0007,
  71. ContextHelpStart = 0x000C,
  72. ContextHelpEnd = 0x000D,
  73. DragDropStart = 0x000E,
  74. DragDropEnd = 0x000F,
  75. DialogStart = 0x0010,
  76. DialogEnd = 0x0011,
  77. ScrollingStart = 0x0012,
  78. ScrollingEnd = 0x0013,
  79. MenuCommand = 0x0018,
  80. // Values from IAccessible2
  81. ActionChanged = 0x0101,
  82. ActiveDescendantChanged = 0x0102,
  83. AttributeChanged = 0x0103,
  84. DocumentContentChanged = 0x0104,
  85. DocumentLoadComplete = 0x0105,
  86. DocumentLoadStopped = 0x0106,
  87. DocumentReload = 0x0107,
  88. HyperlinkEndIndexChanged = 0x0108,
  89. HyperlinkNumberOfAnchorsChanged = 0x0109,
  90. HyperlinkSelectedLinkChanged = 0x010A,
  91. HypertextLinkActivated = 0x010B,
  92. HypertextLinkSelected = 0x010C,
  93. HyperlinkStartIndexChanged = 0x010D,
  94. HypertextChanged = 0x010E,
  95. HypertextNLinksChanged = 0x010F,
  96. ObjectAttributeChanged = 0x0110,
  97. PageChanged = 0x0111,
  98. SectionChanged = 0x0112,
  99. TableCaptionChanged = 0x0113,
  100. TableColumnDescriptionChanged = 0x0114,
  101. TableColumnHeaderChanged = 0x0115,
  102. TableModelChanged = 0x0116,
  103. TableRowDescriptionChanged = 0x0117,
  104. TableRowHeaderChanged = 0x0118,
  105. TableSummaryChanged = 0x0119,
  106. TextAttributeChanged = 0x011A,
  107. TextCaretMoved = 0x011B,
  108. // TextChanged = 0x011C, is deprecated in IA2, use TextUpdated
  109. TextColumnChanged = 0x011D,
  110. TextInserted = 0x011E,
  111. TextRemoved = 0x011F,
  112. TextUpdated = 0x0120,
  113. TextSelectionChanged = 0x0121,
  114. VisibleDataChanged = 0x0122,
  115. ObjectCreated = 0x8000,
  116. ObjectDestroyed = 0x8001,
  117. ObjectShow = 0x8002,
  118. ObjectHide = 0x8003,
  119. ObjectReorder = 0x8004,
  120. Focus = 0x8005,
  121. Selection = 0x8006,
  122. SelectionAdd = 0x8007,
  123. SelectionRemove = 0x8008,
  124. SelectionWithin = 0x8009,
  125. StateChanged = 0x800A,
  126. LocationChanged = 0x800B,
  127. NameChanged = 0x800C,
  128. DescriptionChanged = 0x800D,
  129. ValueChanged = 0x800E,
  130. ParentChanged = 0x800F,
  131. HelpChanged = 0x80A0,
  132. DefaultActionChanged = 0x80B0,
  133. AcceleratorChanged = 0x80C0,
  134. InvalidEvent
  135. };
  136. Q_ENUM(Event)
  137. // 64 bit enums seem hard on some platforms (windows...)
  138. // which makes using a bit field a sensible alternative
  139. struct State {
  140. // http://msdn.microsoft.com/en-us/library/ms697270.aspx
  141. quint64 disabled : 1; // used to be Unavailable
  142. quint64 selected : 1;
  143. quint64 focusable : 1;
  144. quint64 focused : 1;
  145. quint64 pressed : 1;
  146. quint64 checkable : 1;
  147. quint64 checked : 1;
  148. quint64 checkStateMixed : 1; // used to be Mixed
  149. quint64 readOnly : 1;
  150. quint64 hotTracked : 1;
  151. quint64 defaultButton : 1;
  152. quint64 expanded : 1;
  153. quint64 collapsed : 1;
  154. quint64 busy : 1;
  155. quint64 expandable : 1;
  156. quint64 marqueed : 1;
  157. quint64 animated : 1;
  158. quint64 invisible : 1;
  159. quint64 offscreen : 1;
  160. quint64 sizeable : 1;
  161. quint64 movable : 1;
  162. quint64 selfVoicing : 1;
  163. quint64 selectable : 1;
  164. quint64 linked : 1;
  165. quint64 traversed : 1;
  166. quint64 multiSelectable : 1;
  167. quint64 extSelectable : 1;
  168. quint64 passwordEdit : 1; // used to be Protected
  169. quint64 hasPopup : 1;
  170. quint64 modal : 1;
  171. // IA2 - we chose to not add some IA2 states for now
  172. // Below the ones that seem helpful
  173. quint64 active : 1;
  174. quint64 invalid : 1; // = defunct
  175. quint64 editable : 1;
  176. quint64 multiLine : 1;
  177. quint64 selectableText : 1;
  178. quint64 supportsAutoCompletion : 1;
  179. quint64 searchEdit : 1;
  180. // quint64 horizontal : 1;
  181. // quint64 vertical : 1;
  182. // quint64 invalidEntry : 1;
  183. // quint64 managesDescendants : 1;
  184. // quint64 singleLine : 1; // we have multi line, this is redundant.
  185. // quint64 stale : 1;
  186. // quint64 transient : 1;
  187. // quint64 pinned : 1;
  188. // Apple - see http://mattgemmell.com/2010/12/19/accessibility-for-iphone-and-ipad-apps/
  189. // quint64 playsSound : 1;
  190. // quint64 summaryElement : 1;
  191. // quint64 updatesFrequently : 1;
  192. // quint64 adjustable : 1;
  193. // more and not included here: http://developer.apple.com/library/mac/#documentation/UserExperience/Reference/Accessibility_RoleAttribute_Ref/Attributes.html
  194. // MSAA
  195. // quint64 alertLow : 1;
  196. // quint64 alertMedium : 1;
  197. // quint64 alertHigh : 1;
  198. State() {
  199. memset(this, 0, sizeof(State));
  200. }
  201. };
  202. enum Role {
  203. NoRole = 0x00000000,
  204. TitleBar = 0x00000001,
  205. MenuBar = 0x00000002,
  206. ScrollBar = 0x00000003,
  207. Grip = 0x00000004,
  208. Sound = 0x00000005,
  209. Cursor = 0x00000006,
  210. Caret = 0x00000007,
  211. AlertMessage = 0x00000008,
  212. Window = 0x00000009,
  213. Client = 0x0000000A,
  214. PopupMenu = 0x0000000B,
  215. MenuItem = 0x0000000C,
  216. ToolTip = 0x0000000D,
  217. Application = 0x0000000E,
  218. Document = 0x0000000F,
  219. Pane = 0x00000010,
  220. Chart = 0x00000011,
  221. Dialog = 0x00000012,
  222. Border = 0x00000013,
  223. Grouping = 0x00000014,
  224. Separator = 0x00000015,
  225. ToolBar = 0x00000016,
  226. StatusBar = 0x00000017,
  227. Table = 0x00000018,
  228. ColumnHeader = 0x00000019,
  229. RowHeader = 0x0000001A,
  230. Column = 0x0000001B,
  231. Row = 0x0000001C,
  232. Cell = 0x0000001D,
  233. Link = 0x0000001E,
  234. HelpBalloon = 0x0000001F,
  235. Assistant = 0x00000020,
  236. List = 0x00000021,
  237. ListItem = 0x00000022,
  238. Tree = 0x00000023,
  239. TreeItem = 0x00000024,
  240. PageTab = 0x00000025,
  241. PropertyPage = 0x00000026,
  242. Indicator = 0x00000027,
  243. Graphic = 0x00000028,
  244. StaticText = 0x00000029,
  245. EditableText = 0x0000002A, // Editable, selectable, etc.
  246. Button = 0x0000002B,
  247. #ifndef Q_QDOC
  248. PushButton = Button, // deprecated
  249. #endif
  250. CheckBox = 0x0000002C,
  251. RadioButton = 0x0000002D,
  252. ComboBox = 0x0000002E,
  253. // DropList = 0x0000002F,
  254. ProgressBar = 0x00000030,
  255. Dial = 0x00000031,
  256. HotkeyField = 0x00000032,
  257. Slider = 0x00000033,
  258. SpinBox = 0x00000034,
  259. Canvas = 0x00000035, // Diagram for MSAA
  260. Animation = 0x00000036,
  261. Equation = 0x00000037,
  262. ButtonDropDown = 0x00000038, // The object represents a button that expands a grid.
  263. ButtonMenu = 0x00000039,
  264. ButtonDropGrid = 0x0000003A,
  265. Whitespace = 0x0000003B, // The object represents blank space between other objects.
  266. PageTabList = 0x0000003C,
  267. Clock = 0x0000003D,
  268. Splitter = 0x0000003E,
  269. // Reserved space in case MSAA roles needs to be added
  270. // Additional Qt roles where enum value does not map directly to MSAA:
  271. LayeredPane = 0x00000080,
  272. Terminal = 0x00000081,
  273. Desktop = 0x00000082,
  274. Paragraph = 0x00000083,
  275. WebDocument = 0x00000084,
  276. Section = 0x00000085,
  277. // IAccessible2 roles
  278. // IA2_ROLE_CANVAS = 0x401, ### Qt 6 use this one instead of Canvas above
  279. // IA2_ROLE_CAPTION = 0x402,
  280. // IA2_ROLE_CHECK_MENU_ITEM = 0x403,
  281. ColorChooser = 0x404,
  282. // IA2_ROLE_DATE_EDITOR = 0x405,
  283. // IA2_ROLE_DESKTOP_ICON = 0x406,
  284. // IA2_ROLE_DESKTOP_PANE = 0x407,
  285. // IA2_ROLE_DIRECTORY_PANE = 0x408,
  286. // IA2_ROLE_EDITBAR = 0x409,
  287. // IA2_ROLE_EMBEDDED_OBJECT = 0x40A,
  288. // IA2_ROLE_ENDNOTE = 0x40B,
  289. // IA2_ROLE_FILE_CHOOSER = 0x40C,
  290. // IA2_ROLE_FONT_CHOOSER = 0x40D,
  291. Footer = 0x40E,
  292. // IA2_ROLE_FOOTNOTE = 0x40F,
  293. Form = 0x410,
  294. // some platforms (windows and at-spi) use Frame for regular windows
  295. // because window was taken for tool/dock windows by MSAA
  296. // Frame = 0x411,
  297. // IA2_ROLE_GLASS_PANE = 0x412,
  298. // IA2_ROLE_HEADER = 0x413,
  299. Heading = 0x414,
  300. // IA2_ROLE_ICON = 0x415,
  301. // IA2_ROLE_IMAGE_MAP = 0x416,
  302. // IA2_ROLE_INPUT_METHOD_WINDOW = 0x417,
  303. // IA2_ROLE_INTERNAL_FRAME = 0x418,
  304. // IA2_ROLE_LABEL = 0x419,
  305. // IA2_ROLE_LAYERED_PANE = 0x41A,
  306. Note = 0x41B,
  307. // IA2_ROLE_OPTION_PANE = 0x41C,
  308. // IA2_ROLE_PAGE = 0x41D,
  309. // IA2_ROLE_PARAGRAPH = 0x42E,
  310. // IA2_ROLE_RADIO_MENU_ITEM = 0x41F,
  311. // IA2_ROLE_REDUNDANT_OBJECT = 0x420,
  312. // IA2_ROLE_ROOT_PANE = 0x421,
  313. // IA2_ROLE_RULER = 0x422,
  314. // IA2_ROLE_SCROLL_PANE = 0x423,
  315. // IA2_ROLE_SECTION = 0x424,
  316. // IA2_ROLE_SHAPE = 0x425,
  317. // IA2_ROLE_SPLIT_PANE = 0x426,
  318. // IA2_ROLE_TEAR_OFF_MENU = 0x427,
  319. // IA2_ROLE_TERMINAL = 0x428,
  320. // IA2_ROLE_TEXT_FRAME = 0x429,
  321. // IA2_ROLE_TOGGLE_BUTTON = 0x42A,
  322. // IA2_ROLE_VIEW_PORT = 0x42B,
  323. ComplementaryContent = 0x42C,
  324. UserRole = 0x0000ffff
  325. };
  326. Q_ENUM(Role)
  327. enum Text {
  328. Name = 0,
  329. Description,
  330. Value,
  331. Help,
  332. Accelerator,
  333. DebugDescription,
  334. UserText = 0x0000ffff
  335. };
  336. enum RelationFlag {
  337. Label = 0x00000001,
  338. Labelled = 0x00000002,
  339. Controller = 0x00000004,
  340. Controlled = 0x00000008,
  341. AllRelations = 0xffffffff
  342. };
  343. Q_DECLARE_FLAGS(Relation, RelationFlag)
  344. enum InterfaceType
  345. {
  346. TextInterface,
  347. EditableTextInterface,
  348. ValueInterface,
  349. ActionInterface,
  350. ImageInterface,
  351. TableInterface,
  352. TableCellInterface
  353. };
  354. enum TextBoundaryType {
  355. CharBoundary,
  356. WordBoundary,
  357. SentenceBoundary,
  358. ParagraphBoundary,
  359. LineBoundary,
  360. NoBoundary
  361. };
  362. typedef QAccessibleInterface*(*InterfaceFactory)(const QString &key, QObject*);
  363. typedef void(*UpdateHandler)(QAccessibleEvent *event);
  364. typedef void(*RootObjectHandler)(QObject*);
  365. typedef unsigned Id;
  366. static void installFactory(InterfaceFactory);
  367. static void removeFactory(InterfaceFactory);
  368. static UpdateHandler installUpdateHandler(UpdateHandler);
  369. static RootObjectHandler installRootObjectHandler(RootObjectHandler);
  370. class Q_GUI_EXPORT ActivationObserver
  371. {
  372. public:
  373. virtual ~ActivationObserver();
  374. virtual void accessibilityActiveChanged(bool active) = 0;
  375. };
  376. static void installActivationObserver(ActivationObserver *);
  377. static void removeActivationObserver(ActivationObserver *);
  378. static QAccessibleInterface *queryAccessibleInterface(QObject *);
  379. static Id uniqueId(QAccessibleInterface *iface);
  380. static QAccessibleInterface *accessibleInterface(Id uniqueId);
  381. static Id registerAccessibleInterface(QAccessibleInterface *iface);
  382. static void deleteAccessibleInterface(Id uniqueId);
  383. #if QT_DEPRECATED_SINCE(5, 0)
  384. QT_DEPRECATED static inline void updateAccessibility(QObject *object, int child, Event reason);
  385. #endif
  386. static void updateAccessibility(QAccessibleEvent *event);
  387. static bool isActive();
  388. static void setActive(bool active);
  389. static void setRootObject(QObject *object);
  390. static void cleanup();
  391. static QPair< int, int > qAccessibleTextBoundaryHelper(const QTextCursor &cursor, TextBoundaryType boundaryType);
  392. private:
  393. static UpdateHandler updateHandler;
  394. static RootObjectHandler rootObjectHandler;
  395. QAccessible() {}
  396. friend class QAccessibleCache;
  397. };
  398. Q_GUI_EXPORT bool operator==(const QAccessible::State &first, const QAccessible::State &second);
  399. Q_DECLARE_OPERATORS_FOR_FLAGS(QAccessible::Relation)
  400. class QAccessible2Interface;
  401. class QAccessibleTextInterface;
  402. class QAccessibleEditableTextInterface;
  403. class QAccessibleValueInterface;
  404. class QAccessibleActionInterface;
  405. class QAccessibleImageInterface;
  406. class QAccessibleTableInterface;
  407. class QAccessibleTableCellInterface;
  408. class QAccessibleTableModelChangeEvent;
  409. class Q_GUI_EXPORT QAccessibleInterface
  410. {
  411. protected:
  412. virtual ~QAccessibleInterface();
  413. public:
  414. // check for valid pointers
  415. virtual bool isValid() const = 0;
  416. virtual QObject *object() const = 0;
  417. virtual QWindow *window() const;
  418. // relations
  419. virtual QVector<QPair<QAccessibleInterface*, QAccessible::Relation> > relations(QAccessible::Relation match = QAccessible::AllRelations) const;
  420. virtual QAccessibleInterface *focusChild() const;
  421. virtual QAccessibleInterface *childAt(int x, int y) const = 0;
  422. // navigation, hierarchy
  423. virtual QAccessibleInterface *parent() const = 0;
  424. virtual QAccessibleInterface *child(int index) const = 0;
  425. virtual int childCount() const = 0;
  426. virtual int indexOfChild(const QAccessibleInterface *) const = 0;
  427. // properties and state
  428. virtual QString text(QAccessible::Text t) const = 0;
  429. virtual void setText(QAccessible::Text t, const QString &text) = 0;
  430. virtual QRect rect() const = 0;
  431. virtual QAccessible::Role role() const = 0;
  432. virtual QAccessible::State state() const = 0;
  433. virtual QColor foregroundColor() const;
  434. virtual QColor backgroundColor() const;
  435. inline QAccessibleTextInterface *textInterface()
  436. { return reinterpret_cast<QAccessibleTextInterface *>(interface_cast(QAccessible::TextInterface)); }
  437. inline QAccessibleEditableTextInterface *editableTextInterface()
  438. { return reinterpret_cast<QAccessibleEditableTextInterface *>(interface_cast(QAccessible::EditableTextInterface)); }
  439. inline QAccessibleValueInterface *valueInterface()
  440. { return reinterpret_cast<QAccessibleValueInterface *>(interface_cast(QAccessible::ValueInterface)); }
  441. inline QAccessibleActionInterface *actionInterface()
  442. { return reinterpret_cast<QAccessibleActionInterface *>(interface_cast(QAccessible::ActionInterface)); }
  443. inline QAccessibleImageInterface *imageInterface()
  444. { return reinterpret_cast<QAccessibleImageInterface *>(interface_cast(QAccessible::ImageInterface)); }
  445. inline QAccessibleTableInterface *tableInterface()
  446. { return reinterpret_cast<QAccessibleTableInterface *>(interface_cast(QAccessible::TableInterface)); }
  447. inline QAccessibleTableCellInterface *tableCellInterface()
  448. { return reinterpret_cast<QAccessibleTableCellInterface *>(interface_cast(QAccessible::TableCellInterface)); }
  449. virtual void virtual_hook(int id, void *data);
  450. virtual void *interface_cast(QAccessible::InterfaceType)
  451. { return Q_NULLPTR; }
  452. protected:
  453. friend class QAccessibleCache;
  454. };
  455. class Q_GUI_EXPORT QAccessibleTextInterface
  456. {
  457. public:
  458. virtual ~QAccessibleTextInterface();
  459. // selection
  460. virtual void selection(int selectionIndex, int *startOffset, int *endOffset) const = 0;
  461. virtual int selectionCount() const = 0;
  462. virtual void addSelection(int startOffset, int endOffset) = 0;
  463. virtual void removeSelection(int selectionIndex) = 0;
  464. virtual void setSelection(int selectionIndex, int startOffset, int endOffset) = 0;
  465. // cursor
  466. virtual int cursorPosition() const = 0;
  467. virtual void setCursorPosition(int position) = 0;
  468. // text
  469. virtual QString text(int startOffset, int endOffset) const = 0;
  470. virtual QString textBeforeOffset(int offset, QAccessible::TextBoundaryType boundaryType,
  471. int *startOffset, int *endOffset) const;
  472. virtual QString textAfterOffset(int offset, QAccessible::TextBoundaryType boundaryType,
  473. int *startOffset, int *endOffset) const;
  474. virtual QString textAtOffset(int offset, QAccessible::TextBoundaryType boundaryType,
  475. int *startOffset, int *endOffset) const;
  476. virtual int characterCount() const = 0;
  477. // character <-> geometry
  478. virtual QRect characterRect(int offset) const = 0;
  479. virtual int offsetAtPoint(const QPoint &point) const = 0;
  480. virtual void scrollToSubstring(int startIndex, int endIndex) = 0;
  481. virtual QString attributes(int offset, int *startOffset, int *endOffset) const = 0;
  482. };
  483. class Q_GUI_EXPORT QAccessibleEditableTextInterface
  484. {
  485. public:
  486. virtual ~QAccessibleEditableTextInterface();
  487. virtual void deleteText(int startOffset, int endOffset) = 0;
  488. virtual void insertText(int offset, const QString &text) = 0;
  489. virtual void replaceText(int startOffset, int endOffset, const QString &text) = 0;
  490. };
  491. class Q_GUI_EXPORT QAccessibleValueInterface
  492. {
  493. public:
  494. virtual ~QAccessibleValueInterface();
  495. virtual QVariant currentValue() const = 0;
  496. virtual void setCurrentValue(const QVariant &value) = 0;
  497. virtual QVariant maximumValue() const = 0;
  498. virtual QVariant minimumValue() const = 0;
  499. virtual QVariant minimumStepSize() const = 0;
  500. };
  501. class Q_GUI_EXPORT QAccessibleTableCellInterface
  502. {
  503. public:
  504. virtual ~QAccessibleTableCellInterface();
  505. virtual bool isSelected() const = 0;
  506. virtual QList<QAccessibleInterface*> columnHeaderCells() const = 0;
  507. virtual QList<QAccessibleInterface*> rowHeaderCells() const = 0;
  508. virtual int columnIndex() const = 0;
  509. virtual int rowIndex() const = 0;
  510. virtual int columnExtent() const = 0;
  511. virtual int rowExtent() const = 0;
  512. virtual QAccessibleInterface* table() const = 0;
  513. };
  514. class Q_GUI_EXPORT QAccessibleTableInterface
  515. {
  516. public:
  517. virtual ~QAccessibleTableInterface();
  518. virtual QAccessibleInterface *caption() const = 0;
  519. virtual QAccessibleInterface *summary() const = 0;
  520. virtual QAccessibleInterface *cellAt (int row, int column) const = 0;
  521. virtual int selectedCellCount() const = 0;
  522. virtual QList<QAccessibleInterface*> selectedCells() const = 0;
  523. virtual QString columnDescription(int column) const = 0;
  524. virtual QString rowDescription(int row) const = 0;
  525. virtual int selectedColumnCount() const = 0;
  526. virtual int selectedRowCount() const = 0;
  527. virtual int columnCount() const = 0;
  528. virtual int rowCount() const = 0;
  529. virtual QList<int> selectedColumns() const = 0;
  530. virtual QList<int> selectedRows() const = 0;
  531. virtual bool isColumnSelected(int column) const = 0;
  532. virtual bool isRowSelected(int row) const = 0;
  533. virtual bool selectRow(int row) = 0;
  534. virtual bool selectColumn(int column) = 0;
  535. virtual bool unselectRow(int row) = 0;
  536. virtual bool unselectColumn(int column) = 0;
  537. virtual void modelChange(QAccessibleTableModelChangeEvent *event) = 0;
  538. protected:
  539. friend class QAbstractItemView;
  540. friend class QAbstractItemViewPrivate;
  541. };
  542. class Q_GUI_EXPORT QAccessibleActionInterface
  543. {
  544. Q_DECLARE_TR_FUNCTIONS(QAccessibleActionInterface)
  545. public:
  546. virtual ~QAccessibleActionInterface();
  547. virtual QStringList actionNames() const = 0;
  548. virtual QString localizedActionName(const QString &name) const;
  549. virtual QString localizedActionDescription(const QString &name) const;
  550. virtual void doAction(const QString &actionName) = 0;
  551. virtual QStringList keyBindingsForAction(const QString &actionName) const = 0;
  552. static const QString &pressAction();
  553. static const QString &increaseAction();
  554. static const QString &decreaseAction();
  555. static const QString &showMenuAction();
  556. static const QString &setFocusAction();
  557. static const QString &toggleAction();
  558. static QString scrollLeftAction();
  559. static QString scrollRightAction();
  560. static QString scrollUpAction();
  561. static QString scrollDownAction();
  562. static QString nextPageAction();
  563. static QString previousPageAction();
  564. };
  565. class Q_GUI_EXPORT QAccessibleImageInterface
  566. {
  567. public:
  568. virtual ~QAccessibleImageInterface();
  569. virtual QString imageDescription() const = 0;
  570. virtual QSize imageSize() const = 0;
  571. virtual QPoint imagePosition() const = 0;
  572. };
  573. class Q_GUI_EXPORT QAccessibleEvent
  574. {
  575. Q_DISABLE_COPY(QAccessibleEvent)
  576. public:
  577. inline QAccessibleEvent(QObject *obj, QAccessible::Event typ)
  578. : m_type(typ), m_object(obj), m_child(-1)
  579. {
  580. Q_ASSERT(obj);
  581. // All events below have a subclass of QAccessibleEvent.
  582. // Use the subclass, since it's expected that it's possible to cast to that.
  583. Q_ASSERT(m_type != QAccessible::ValueChanged);
  584. Q_ASSERT(m_type != QAccessible::StateChanged);
  585. Q_ASSERT(m_type != QAccessible::TextCaretMoved);
  586. Q_ASSERT(m_type != QAccessible::TextSelectionChanged);
  587. Q_ASSERT(m_type != QAccessible::TextInserted);
  588. Q_ASSERT(m_type != QAccessible::TextRemoved);
  589. Q_ASSERT(m_type != QAccessible::TextUpdated);
  590. Q_ASSERT(m_type != QAccessible::TableModelChanged);
  591. }
  592. inline QAccessibleEvent(QAccessibleInterface *iface, QAccessible::Event typ)
  593. : m_type(typ), m_object(Q_NULLPTR)
  594. {
  595. Q_ASSERT(iface);
  596. Q_ASSERT(m_type != QAccessible::ValueChanged);
  597. Q_ASSERT(m_type != QAccessible::StateChanged);
  598. Q_ASSERT(m_type != QAccessible::TextCaretMoved);
  599. Q_ASSERT(m_type != QAccessible::TextSelectionChanged);
  600. Q_ASSERT(m_type != QAccessible::TextInserted);
  601. Q_ASSERT(m_type != QAccessible::TextRemoved);
  602. Q_ASSERT(m_type != QAccessible::TextUpdated);
  603. Q_ASSERT(m_type != QAccessible::TableModelChanged);
  604. m_uniqueId = QAccessible::uniqueId(iface);
  605. }
  606. virtual ~QAccessibleEvent();
  607. QAccessible::Event type() const { return m_type; }
  608. QObject *object() const { return m_object; }
  609. QAccessible::Id uniqueId() const;
  610. void setChild(int chld) { m_child = chld; }
  611. int child() const { return m_child; }
  612. virtual QAccessibleInterface *accessibleInterface() const;
  613. protected:
  614. QAccessible::Event m_type;
  615. QObject *m_object;
  616. union {
  617. int m_child;
  618. QAccessible::Id m_uniqueId;
  619. };
  620. };
  621. class Q_GUI_EXPORT QAccessibleStateChangeEvent :public QAccessibleEvent
  622. {
  623. public:
  624. inline QAccessibleStateChangeEvent(QObject *obj, QAccessible::State state)
  625. : QAccessibleEvent(obj, QAccessible::InvalidEvent), m_changedStates(state)
  626. {
  627. m_type = QAccessible::StateChanged;
  628. }
  629. inline QAccessibleStateChangeEvent(QAccessibleInterface *iface, QAccessible::State state)
  630. : QAccessibleEvent(iface, QAccessible::InvalidEvent), m_changedStates(state)
  631. {
  632. m_type = QAccessible::StateChanged;
  633. }
  634. ~QAccessibleStateChangeEvent();
  635. QAccessible::State changedStates() const {
  636. return m_changedStates;
  637. }
  638. protected:
  639. QAccessible::State m_changedStates;
  640. };
  641. // Update the cursor and optionally the selection.
  642. class Q_GUI_EXPORT QAccessibleTextCursorEvent : public QAccessibleEvent
  643. {
  644. public:
  645. inline QAccessibleTextCursorEvent(QObject *obj, int cursorPos)
  646. : QAccessibleEvent(obj, QAccessible::InvalidEvent)
  647. , m_cursorPosition(cursorPos)
  648. {
  649. m_type = QAccessible::TextCaretMoved;
  650. }
  651. inline QAccessibleTextCursorEvent(QAccessibleInterface *iface, int cursorPos)
  652. : QAccessibleEvent(iface, QAccessible::InvalidEvent)
  653. , m_cursorPosition(cursorPos)
  654. {
  655. m_type = QAccessible::TextCaretMoved;
  656. }
  657. ~QAccessibleTextCursorEvent();
  658. void setCursorPosition(int position) { m_cursorPosition = position; }
  659. int cursorPosition() const { return m_cursorPosition; }
  660. protected:
  661. int m_cursorPosition;
  662. };
  663. // Updates the cursor position simultaneously. By default the cursor is set to the end of the selection.
  664. class Q_GUI_EXPORT QAccessibleTextSelectionEvent : public QAccessibleTextCursorEvent
  665. {
  666. public:
  667. inline QAccessibleTextSelectionEvent(QObject *obj, int start, int end)
  668. : QAccessibleTextCursorEvent(obj, (start == -1) ? 0 : end)
  669. , m_selectionStart(start), m_selectionEnd(end)
  670. {
  671. m_type = QAccessible::TextSelectionChanged;
  672. }
  673. inline QAccessibleTextSelectionEvent(QAccessibleInterface *iface, int start, int end)
  674. : QAccessibleTextCursorEvent(iface, (start == -1) ? 0 : end)
  675. , m_selectionStart(start), m_selectionEnd(end)
  676. {
  677. m_type = QAccessible::TextSelectionChanged;
  678. }
  679. ~QAccessibleTextSelectionEvent();
  680. void setSelection(int start, int end) {
  681. m_selectionStart = start;
  682. m_selectionEnd = end;
  683. }
  684. int selectionStart() const { return m_selectionStart; }
  685. int selectionEnd() const { return m_selectionEnd; }
  686. protected:
  687. int m_selectionStart;
  688. int m_selectionEnd;
  689. };
  690. class Q_GUI_EXPORT QAccessibleTextInsertEvent : public QAccessibleTextCursorEvent
  691. {
  692. public:
  693. inline QAccessibleTextInsertEvent(QObject *obj, int position, const QString &text)
  694. : QAccessibleTextCursorEvent(obj, position + text.length())
  695. , m_position(position), m_text(text)
  696. {
  697. m_type = QAccessible::TextInserted;
  698. }
  699. inline QAccessibleTextInsertEvent(QAccessibleInterface *iface, int position, const QString &text)
  700. : QAccessibleTextCursorEvent(iface, position + text.length())
  701. , m_position(position), m_text(text)
  702. {
  703. m_type = QAccessible::TextInserted;
  704. }
  705. ~QAccessibleTextInsertEvent();
  706. QString textInserted() const {
  707. return m_text;
  708. }
  709. int changePosition() const {
  710. return m_position;
  711. }
  712. protected:
  713. int m_position;
  714. QString m_text;
  715. };
  716. class Q_GUI_EXPORT QAccessibleTextRemoveEvent : public QAccessibleTextCursorEvent
  717. {
  718. public:
  719. inline QAccessibleTextRemoveEvent(QObject *obj, int position, const QString &text)
  720. : QAccessibleTextCursorEvent(obj, position)
  721. , m_position(position), m_text(text)
  722. {
  723. m_type = QAccessible::TextRemoved;
  724. }
  725. inline QAccessibleTextRemoveEvent(QAccessibleInterface *iface, int position, const QString &text)
  726. : QAccessibleTextCursorEvent(iface, position)
  727. , m_position(position), m_text(text)
  728. {
  729. m_type = QAccessible::TextRemoved;
  730. }
  731. ~QAccessibleTextRemoveEvent();
  732. QString textRemoved() const {
  733. return m_text;
  734. }
  735. int changePosition() const {
  736. return m_position;
  737. }
  738. protected:
  739. int m_position;
  740. QString m_text;
  741. };
  742. class Q_GUI_EXPORT QAccessibleTextUpdateEvent : public QAccessibleTextCursorEvent
  743. {
  744. public:
  745. inline QAccessibleTextUpdateEvent(QObject *obj, int position, const QString &oldText, const QString &text)
  746. : QAccessibleTextCursorEvent(obj, position + text.length())
  747. , m_position(position), m_oldText(oldText), m_text(text)
  748. {
  749. m_type = QAccessible::TextUpdated;
  750. }
  751. inline QAccessibleTextUpdateEvent(QAccessibleInterface *iface, int position, const QString &oldText, const QString &text)
  752. : QAccessibleTextCursorEvent(iface, position + text.length())
  753. , m_position(position), m_oldText(oldText), m_text(text)
  754. {
  755. m_type = QAccessible::TextUpdated;
  756. }
  757. ~QAccessibleTextUpdateEvent();
  758. QString textRemoved() const {
  759. return m_oldText;
  760. }
  761. QString textInserted() const {
  762. return m_text;
  763. }
  764. int changePosition() const {
  765. return m_position;
  766. }
  767. protected:
  768. int m_position;
  769. QString m_oldText;
  770. QString m_text;
  771. };
  772. class Q_GUI_EXPORT QAccessibleValueChangeEvent : public QAccessibleEvent
  773. {
  774. public:
  775. inline QAccessibleValueChangeEvent(QObject *obj, const QVariant &val)
  776. : QAccessibleEvent(obj, QAccessible::InvalidEvent)
  777. , m_value(val)
  778. {
  779. m_type = QAccessible::ValueChanged;
  780. }
  781. inline QAccessibleValueChangeEvent(QAccessibleInterface *iface, const QVariant &val)
  782. : QAccessibleEvent(iface, QAccessible::InvalidEvent)
  783. , m_value(val)
  784. {
  785. m_type = QAccessible::ValueChanged;
  786. }
  787. ~QAccessibleValueChangeEvent();
  788. void setValue(const QVariant & val) { m_value= val; }
  789. QVariant value() const { return m_value; }
  790. protected:
  791. QVariant m_value;
  792. };
  793. class Q_GUI_EXPORT QAccessibleTableModelChangeEvent : public QAccessibleEvent
  794. {
  795. public:
  796. enum ModelChangeType {
  797. ModelReset,
  798. DataChanged,
  799. RowsInserted,
  800. ColumnsInserted,
  801. RowsRemoved,
  802. ColumnsRemoved
  803. };
  804. inline QAccessibleTableModelChangeEvent(QObject *obj, ModelChangeType changeType)
  805. : QAccessibleEvent(obj, QAccessible::InvalidEvent)
  806. , m_modelChangeType(changeType)
  807. , m_firstRow(-1), m_firstColumn(-1), m_lastRow(-1), m_lastColumn(-1)
  808. {
  809. m_type = QAccessible::TableModelChanged;
  810. }
  811. inline QAccessibleTableModelChangeEvent(QAccessibleInterface *iface, ModelChangeType changeType)
  812. : QAccessibleEvent(iface, QAccessible::InvalidEvent)
  813. , m_modelChangeType(changeType)
  814. , m_firstRow(-1), m_firstColumn(-1), m_lastRow(-1), m_lastColumn(-1)
  815. {
  816. m_type = QAccessible::TableModelChanged;
  817. }
  818. ~QAccessibleTableModelChangeEvent();
  819. void setModelChangeType(ModelChangeType changeType) { m_modelChangeType = changeType; }
  820. ModelChangeType modelChangeType() const { return m_modelChangeType; }
  821. void setFirstRow(int row) { m_firstRow = row; }
  822. void setFirstColumn(int col) { m_firstColumn = col; }
  823. void setLastRow(int row) { m_lastRow = row; }
  824. void setLastColumn(int col) { m_lastColumn = col; }
  825. int firstRow() const { return m_firstRow; }
  826. int firstColumn() const { return m_firstColumn; }
  827. int lastRow() const { return m_lastRow; }
  828. int lastColumn() const { return m_lastColumn; }
  829. protected:
  830. ModelChangeType m_modelChangeType;
  831. int m_firstRow;
  832. int m_firstColumn;
  833. int m_lastRow;
  834. int m_lastColumn;
  835. };
  836. #define QAccessibleInterface_iid "org.qt-project.Qt.QAccessibleInterface"
  837. Q_DECLARE_INTERFACE(QAccessibleInterface, QAccessibleInterface_iid)
  838. Q_GUI_EXPORT const char *qAccessibleRoleString(QAccessible::Role role);
  839. Q_GUI_EXPORT const char *qAccessibleEventString(QAccessible::Event event);
  840. Q_GUI_EXPORT QString qAccessibleLocalizedActionDescription(const QString &actionName);
  841. #ifndef QT_NO_DEBUG_STREAM
  842. Q_GUI_EXPORT QDebug operator<<(QDebug d, const QAccessibleInterface *iface);
  843. Q_GUI_EXPORT QDebug operator<<(QDebug d, const QAccessibleEvent &ev);
  844. #endif
  845. #if QT_DEPRECATED_SINCE(5, 0)
  846. inline void QAccessible::updateAccessibility(QObject *object, int child, Event reason)
  847. {
  848. Q_ASSERT(object);
  849. QAccessibleEvent ev(object, reason);
  850. ev.setChild(child);
  851. updateAccessibility(&ev);
  852. }
  853. #endif
  854. QT_END_NAMESPACE
  855. #endif // QACCESSIBLE_H
  856. #endif //!QT_NO_ACCESSIBILITY