1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296
|
/*
* Copyright (C) 2021 Igalia S.L.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#if USE(ATSPI)
#include "AXCoreObject.h"
#include "AccessibilityAtspi.h"
#include "AccessibilityAtspiEnums.h"
#include "AccessibilityRootAtspi.h"
#include "IntRect.h"
#include <wtf/OptionSet.h>
#include <wtf/RefCounted.h>
#include <wtf/text/CString.h>
typedef struct _GDBusInterfaceVTable GDBusInterfaceVTable;
typedef struct _GVariant GVariant;
typedef struct _GVariantBuilder GVariantBuilder;
namespace WebCore {
using RelationMap = UncheckedKeyHashMap<Atspi::Relation, Vector<Ref<AccessibilityObjectAtspi>>, IntHash<Atspi::Relation>, WTF::StrongEnumHashTraits<Atspi::Relation>>;
class AccessibilityObjectAtspi final : public RefCounted<AccessibilityObjectAtspi> {
public:
static Ref<AccessibilityObjectAtspi> create(AXCoreObject*, AccessibilityRootAtspi*);
~AccessibilityObjectAtspi() = default;
bool registerObject();
void didUnregisterObject();
enum class Interface : uint16_t {
Accessible = 1 << 0,
Component = 1 << 1,
Text = 1 << 2,
Value = 1 << 3,
Hyperlink = 1 << 4,
Hypertext = 1 << 5,
Action = 1 << 6,
Document = 1 << 7,
Image = 1 << 8,
Selection = 1 << 9,
Table = 1 << 10,
TableCell = 1 << 11,
Collection = 1 << 12
};
const OptionSet<Interface>& interfaces() const { return m_interfaces; }
void setParent(std::optional<AccessibilityObjectAtspi*>);
WEBCORE_EXPORT std::optional<AccessibilityObjectAtspi*> parent() const;
GVariant* parentReference() const;
WEBCORE_EXPORT void updateBackingStore();
WEBCORE_EXPORT bool isIgnored() const;
void attach(AXCoreObject*);
void detach();
void elementDestroyed();
void cacheDestroyed();
int indexInParent() const;
int indexInParentForChildrenChanged(AccessibilityAtspi::ChildrenChanged);
const String& path();
GVariant* reference();
GVariant* hyperlinkReference();
void serialize(GVariantBuilder*) const;
WEBCORE_EXPORT String id() const;
WEBCORE_EXPORT CString name() const;
WEBCORE_EXPORT CString description() const;
WEBCORE_EXPORT String locale() const;
WEBCORE_EXPORT Atspi::Role role() const;
WEBCORE_EXPORT unsigned childCount() const;
WEBCORE_EXPORT Vector<Ref<AccessibilityObjectAtspi>> children() const;
WEBCORE_EXPORT AccessibilityObjectAtspi* childAt(unsigned) const;
WEBCORE_EXPORT OptionSet<Atspi::State> states() const;
bool isDefunct() const;
void stateChanged(const char*, bool);
WEBCORE_EXPORT UncheckedKeyHashMap<String, String> attributes() const;
WEBCORE_EXPORT RelationMap relationMap() const;
WEBCORE_EXPORT AccessibilityObjectAtspi* hitTest(const IntPoint&, Atspi::CoordinateType) const;
WEBCORE_EXPORT IntRect elementRect(Atspi::CoordinateType) const;
WEBCORE_EXPORT void scrollToMakeVisible(Atspi::ScrollType) const;
WEBCORE_EXPORT void scrollToPoint(const IntPoint&, Atspi::CoordinateType) const;
WEBCORE_EXPORT String text() const;
enum class TextGranularity {
Character,
WordStart,
WordEnd,
SentenceStart,
SentenceEnd,
LineStart,
LineEnd,
Paragraph
};
WEBCORE_EXPORT IntPoint boundaryOffset(unsigned, TextGranularity) const;
WEBCORE_EXPORT IntRect boundsForRange(unsigned, unsigned, Atspi::CoordinateType) const;
struct TextAttributes {
UncheckedKeyHashMap<String, String> attributes;
int startOffset;
int endOffset;
};
WEBCORE_EXPORT TextAttributes textAttributes(std::optional<unsigned> = std::nullopt, bool = false) const;
WEBCORE_EXPORT IntPoint selectedRange() const;
WEBCORE_EXPORT void setSelectedRange(unsigned, unsigned);
void textInserted(const String&, const VisiblePosition&);
void textDeleted(const String&, const VisiblePosition&);
void textAttributesChanged();
void selectionChanged(const VisibleSelection&);
WEBCORE_EXPORT double currentValue() const;
WEBCORE_EXPORT bool setCurrentValue(double);
WEBCORE_EXPORT double minimumValue() const;
WEBCORE_EXPORT double maximumValue() const;
WEBCORE_EXPORT double minimumIncrement() const;
void valueChanged(double);
WEBCORE_EXPORT URL url() const;
WEBCORE_EXPORT String actionName() const;
WEBCORE_EXPORT bool doAction() const;
WEBCORE_EXPORT String documentAttribute(const String&) const;
void loadEvent(const char*);
WEBCORE_EXPORT AccessibilityObjectAtspi* activeDescendant() const;
void activeDescendantChanged();
WEBCORE_EXPORT unsigned selectionCount() const;
WEBCORE_EXPORT Vector<Ref<AccessibilityObjectAtspi>> selectedChildren() const;
WEBCORE_EXPORT AccessibilityObjectAtspi* selectedChild(unsigned) const;
WEBCORE_EXPORT bool setChildSelected(unsigned, bool) const;
WEBCORE_EXPORT bool clearSelection() const;
void selectionChanged();
WEBCORE_EXPORT AccessibilityObjectAtspi* cell(unsigned row, unsigned column) const;
WEBCORE_EXPORT unsigned rowCount() const;
WEBCORE_EXPORT unsigned columnCount() const;
WEBCORE_EXPORT Vector<Ref<AccessibilityObjectAtspi>> cells() const;
WEBCORE_EXPORT Vector<Ref<AccessibilityObjectAtspi>> rows() const;
WEBCORE_EXPORT Vector<Ref<AccessibilityObjectAtspi>> rowHeaders() const;
WEBCORE_EXPORT Vector<Ref<AccessibilityObjectAtspi>> columnHeaders() const;
WEBCORE_EXPORT Vector<Ref<AccessibilityObjectAtspi>> cellRowHeaders() const;
WEBCORE_EXPORT Vector<Ref<AccessibilityObjectAtspi>> cellColumnHeaders() const;
WEBCORE_EXPORT unsigned rowSpan() const;
WEBCORE_EXPORT unsigned columnSpan() const;
WEBCORE_EXPORT std::pair<std::optional<unsigned>, std::optional<unsigned>> cellPosition() const;
private:
AccessibilityObjectAtspi(AXCoreObject*, AccessibilityRootAtspi*);
Vector<Ref<AccessibilityObjectAtspi>> wrapperVector(const Vector<Ref<AXCoreObject>>&) const;
void childAdded(AccessibilityObjectAtspi&);
void childRemoved(AccessibilityObjectAtspi&);
std::optional<Atspi::Role> effectiveRole() const;
String effectiveRoleName() const;
String roleName() const;
const char* effectiveLocalizedRoleName() const;
const char* localizedRoleName() const;
void buildAttributes(GVariantBuilder*) const;
void buildRelationSet(GVariantBuilder*) const;
void buildInterfaces(GVariantBuilder*) const;
void buildStates(GVariantBuilder*) const;
bool focus() const;
float opacity() const;
static TextGranularity atspiBoundaryToTextGranularity(Atspi::TextBoundaryType);
static TextGranularity atspiGranularityToTextGranularity(Atspi::TextGranularityType);
CString text(int, int) const;
CString textAtOffset(int, TextGranularity, int&, int&) const;
int characterAtOffset(int) const;
std::optional<unsigned> characterOffset(UChar, int) const;
std::optional<unsigned> characterIndex(UChar, unsigned) const;
IntRect textExtents(int, int, Atspi::CoordinateType) const;
int offsetAtPoint(const IntPoint&, Atspi::CoordinateType) const;
IntPoint boundsForSelection(const VisibleSelection&) const;
bool selectionBounds(int&, int&) const;
bool selectRange(int, int);
TextAttributes textAttributesWithUTF8Offset(std::optional<int> = std::nullopt, bool = false) const;
bool scrollToMakeVisible(int, int, Atspi::ScrollType) const;
bool scrollToPoint(int, int, Atspi::CoordinateType, int, int) const;
unsigned offsetInParent() const;
unsigned hyperlinkCount() const;
AccessibilityObjectAtspi* hyperlink(unsigned) const;
std::optional<unsigned> hyperlinkIndex(unsigned) const;
String localizedActionName() const;
String actionKeyBinding() const;
UncheckedKeyHashMap<String, String> documentAttributes() const;
String documentLocale() const;
String imageDescription() const;
bool deselectSelectedChild(unsigned) const;
bool isChildSelected(unsigned) const;
bool selectAll() const;
AccessibilityObjectAtspi* rowHeader(unsigned) const;
AccessibilityObjectAtspi* columnHeader(unsigned) const;
unsigned rowExtent(unsigned row, unsigned column) const;
unsigned columnExtent(unsigned row, unsigned column) const;
AccessibilityObjectAtspi* tableCaption() const;
std::optional<unsigned> cellIndex(unsigned row, unsigned column) const;
std::optional<unsigned> rowAtIndex(unsigned) const;
std::optional<unsigned> columnAtIndex(unsigned) const;
String rowDescription(unsigned) const;
String columnDescription(unsigned) const;
struct CollectionMatchRule {
CollectionMatchRule(GVariant*);
bool match(AccessibilityObjectAtspi&);
bool matchInterfaces(AccessibilityObjectAtspi&);
bool matchStates(AccessibilityObjectAtspi&);
bool matchRoles(AccessibilityObjectAtspi&);
bool matchAttributes(AccessibilityObjectAtspi&);
struct {
OptionSet<Atspi::State> value;
Atspi::CollectionMatchType type;
} states;
struct {
UncheckedKeyHashMap<String, Vector<String>> value;
Atspi::CollectionMatchType type;
} attributes;
struct {
Vector<Atspi::Role> value;
Atspi::CollectionMatchType type;
} roles;
struct {
Vector<String> value;
Atspi::CollectionMatchType type;
} interfaces;
};
Vector<Ref<AccessibilityObjectAtspi>> matches(CollectionMatchRule&, Atspi::CollectionSortOrder, uint32_t maxResultCount, bool traverse);
void addMatchesInCanonicalOrder(Vector<Ref<AccessibilityObjectAtspi>>&, CollectionMatchRule&, uint32_t maxResultCount, bool traverse);
static OptionSet<Interface> interfacesForObject(AXCoreObject&);
static GDBusInterfaceVTable s_accessibleFunctions;
static GDBusInterfaceVTable s_componentFunctions;
static GDBusInterfaceVTable s_textFunctions;
static GDBusInterfaceVTable s_valueFunctions;
static GDBusInterfaceVTable s_hyperlinkFunctions;
static GDBusInterfaceVTable s_hypertextFunctions;
static GDBusInterfaceVTable s_actionFunctions;
static GDBusInterfaceVTable s_documentFunctions;
static GDBusInterfaceVTable s_imageFunctions;
static GDBusInterfaceVTable s_selectionFunctions;
static GDBusInterfaceVTable s_tableFunctions;
static GDBusInterfaceVTable s_tableCellFunctions;
static GDBusInterfaceVTable s_collectionFunctions;
RefPtr<AXCoreObject> m_coreObject;
OptionSet<Interface> m_interfaces;
RefPtr<AccessibilityRootAtspi> m_root;
std::optional<RefPtr<AccessibilityObjectAtspi>> m_parent;
bool m_isRegistered { false };
String m_path;
String m_hyperlinkPath;
int64_t m_lastSelectionChangedTime { -1 };
mutable bool m_hasListMarkerAtStart;
mutable int m_indexInParent { -1 };
};
} // namespace WebCore
#endif // USE(ATSPI)
|