File: AXObjectCacheImpl.h

package info (click to toggle)
chromium-browser 57.0.2987.98-1~deb8u1
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 2,637,852 kB
  • ctags: 2,544,394
  • sloc: cpp: 12,815,961; ansic: 3,676,222; python: 1,147,112; asm: 526,608; java: 523,212; xml: 286,794; perl: 92,654; sh: 86,408; objc: 73,271; makefile: 27,698; cs: 18,487; yacc: 13,031; tcl: 12,957; pascal: 4,875; ml: 4,716; lex: 3,904; sql: 3,862; ruby: 1,982; lisp: 1,508; php: 1,368; exp: 404; awk: 325; csh: 117; jsp: 39; sed: 37
file content (268 lines) | stat: -rw-r--r-- 10,166 bytes parent folder | download
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
/*
 * Copyright (C) 2014, Google Inc. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1.  Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 * 2.  Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution.
 * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
 *     its contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef AXObjectCacheImpl_h
#define AXObjectCacheImpl_h

#include "core/dom/AXObjectCache.h"
#include "modules/ModulesExport.h"
#include "modules/accessibility/AXObject.h"
#include "platform/Timer.h"
#include "wtf/Forward.h"
#include "wtf/HashMap.h"
#include "wtf/HashSet.h"
#include <memory>

namespace blink {

class AbstractInlineTextBox;
class HTMLAreaElement;
class FrameView;

// This class should only be used from inside the accessibility directory.
class MODULES_EXPORT AXObjectCacheImpl : public AXObjectCache {
  WTF_MAKE_NONCOPYABLE(AXObjectCacheImpl);

 public:
  static AXObjectCache* create(Document&);

  explicit AXObjectCacheImpl(Document&);
  ~AXObjectCacheImpl();
  DECLARE_VIRTUAL_TRACE();

  AXObject* focusedObject();

  void dispose() override;

  void selectionChanged(Node*) override;
  void childrenChanged(Node*) override;
  void childrenChanged(LayoutObject*) override;
  void checkedStateChanged(Node*) override;
  virtual void listboxOptionStateChanged(HTMLOptionElement*);
  virtual void listboxSelectedChildrenChanged(HTMLSelectElement*);
  virtual void listboxActiveIndexChanged(HTMLSelectElement*);
  virtual void radiobuttonRemovedFromGroup(HTMLInputElement*);

  void remove(LayoutObject*) override;
  void remove(Node*) override;
  void remove(AbstractInlineTextBox*) override;

  const Element* rootAXEditableElement(const Node*) override;

  // Called by a node when text or a text equivalent (e.g. alt) attribute is
  // changed.
  void textChanged(LayoutObject*) override;
  // Called when a node has just been attached, so we can make sure we have the
  // right subclass of AXObject.
  void updateCacheAfterNodeIsAttached(Node*) override;

  void handleAttributeChanged(const QualifiedName& attrName, Element*) override;
  void handleFocusedUIElementChanged(Node* oldFocusedNode,
                                     Node* newFocusedNode) override;
  void handleInitialFocus() override;
  void handleTextFormControlChanged(Node*) override;
  void handleEditableTextContentChanged(Node*) override;
  void handleValueChanged(Node*) override;
  void handleUpdateActiveMenuOption(LayoutMenuList*, int optionIndex) override;
  void didShowMenuListPopup(LayoutMenuList*) override;
  void didHideMenuListPopup(LayoutMenuList*) override;
  void handleLoadComplete(Document*) override;
  void handleLayoutComplete(Document*) override;
  void handleClicked(Node*) override;

  void setCanvasObjectBounds(HTMLCanvasElement*,
                             Element*,
                             const LayoutRect&) override;

  void inlineTextBoxesUpdated(LineLayoutItem) override;

  // Called when the scroll offset changes.
  void handleScrollPositionChanged(FrameView*) override;
  void handleScrollPositionChanged(LayoutObject*) override;

  // Called when scroll bars are added / removed (as the view resizes).
  void handleLayoutComplete(LayoutObject*) override;
  void handleScrolledToAnchor(const Node* anchorNode) override;

  const AtomicString& computedRoleForNode(Node*) override;
  String computedNameForNode(Node*) override;

  void onTouchAccessibilityHover(const IntPoint&) override;

  // Returns the root object for the entire document.
  AXObject* rootObject();

  AXObject* objectFromAXID(AXID id) const { return m_objects.get(id); }
  AXObject* root();

  // used for objects without backing elements
  AXObject* getOrCreate(AccessibilityRole);
  AXObject* getOrCreate(LayoutObject*);
  AXObject* getOrCreate(Node*);
  AXObject* getOrCreate(AbstractInlineTextBox*);

  // will only return the AXObject if it already exists
  AXObject* get(Node*);
  AXObject* get(LayoutObject*);
  AXObject* get(AbstractInlineTextBox*);

  AXObject* firstAccessibleObjectFromNode(const Node*);

  void remove(AXID);

  void childrenChanged(AXObject*);

  void handleActiveDescendantChanged(Node*);
  void handleAriaRoleChanged(Node*);
  void handleAriaExpandedChange(Node*);
  void handleAriaSelectedChanged(Node*);

  bool accessibilityEnabled();
  bool inlineTextBoxAccessibilityEnabled();

  void removeAXID(AXObject*);

  AXID platformGenerateAXID() const;

  // Counts the number of times the document has been modified. Some attribute
  // values are cached as long as the modification count hasn't changed.
  int modificationCount() const { return m_modificationCount; }

  void postNotification(LayoutObject*, AXNotification);
  void postNotification(Node*, AXNotification);
  void postNotification(AXObject*, AXNotification);

  //
  // Aria-owns support.
  //

  // Returns true if the given object's position in the tree was due to
  // aria-owns.
  bool isAriaOwned(const AXObject*) const;

  // Returns the parent of the given object due to aria-owns.
  AXObject* getAriaOwnedParent(const AXObject*) const;

  // Given an object that has an aria-owns attributes, and a vector of ids from
  // the value of that attribute, updates the internal state to reflect the new
  // set of children owned by this object, returning the result in
  // |ownedChildren|. The result is validated - illegal, duplicate, or cyclical
  // references have been removed.
  //
  // If one or more ids aren't found, they're added to a lookup table so that if
  // an element with that id appears later, it can be added when you call
  // updateTreeIfElementIdIsAriaOwned.
  void updateAriaOwns(const AXObject* owner,
                      const Vector<String>& idVector,
                      HeapVector<Member<AXObject>>& ownedChildren);

  // Given an element in the DOM tree that was either just added or whose id
  // just changed, check to see if another object wants to be its parent due to
  // aria-owns. If so, update the tree by calling childrenChanged() on the
  // potential owner, possibly reparenting this element.
  void updateTreeIfElementIdIsAriaOwned(Element*);

 protected:
  void postPlatformNotification(AXObject*, AXNotification);
  void textChanged(AXObject*);
  void labelChanged(Element*);

  AXObject* createFromRenderer(LayoutObject*);
  AXObject* createFromNode(Node*);
  AXObject* createFromInlineTextBox(AbstractInlineTextBox*);

 private:
  Member<Document> m_document;
  HeapHashMap<AXID, Member<AXObject>> m_objects;
  // LayoutObject and AbstractInlineTextBox are not on the Oilpan heap so we
  // do not use HeapHashMap for those mappings.
  HashMap<LayoutObject*, AXID> m_layoutObjectMapping;
  HeapHashMap<Member<Node>, AXID> m_nodeObjectMapping;
  HashMap<AbstractInlineTextBox*, AXID> m_inlineTextBoxObjectMapping;
  int m_modificationCount;

  HashSet<AXID> m_idsInUse;

#if DCHECK_IS_ON()
  // Verified when finalizing.
  bool m_hasBeenDisposed = false;
#endif

  //
  // Aria-owns
  //

  // Map from the AXID of the owner to the AXIDs of the children.
  // This is a validated map, it doesn't contain illegal, duplicate,
  // or cyclical matches, or references to IDs that don't exist.
  HashMap<AXID, Vector<AXID>> m_ariaOwnerToChildrenMapping;

  // Map from the AXID of a child to the AXID of the parent that owns it.
  HashMap<AXID, AXID> m_ariaOwnedChildToOwnerMapping;

  // Map from the AXID of a child to the AXID of its real parent in the tree if
  // we ignored aria-owns. This is needed in case the owner no longer wants to
  // own it.
  HashMap<AXID, AXID> m_ariaOwnedChildToRealParentMapping;

  // Map from the AXID of any object with an aria-owns attribute to the set of
  // ids of its children. This is *unvalidated*, it includes ids that may not
  // currently exist in the tree.
  HashMap<AXID, HashSet<String>> m_ariaOwnerToIdsMapping;

  // Map from an ID (the ID attribute of a DOM element) to the set of elements
  // that want to own that ID. This is *unvalidated*, it includes possible
  // duplicates.  This is used so that when an element with an ID is added to
  // the tree or changes its ID, we can quickly determine if it affects an
  // aria-owns relationship.
  HashMap<String, std::unique_ptr<HashSet<AXID>>> m_idToAriaOwnersMapping;

  Timer<AXObjectCacheImpl> m_notificationPostTimer;
  HeapVector<std::pair<Member<AXObject>, AXNotification>> m_notificationsToPost;
  void notificationPostTimerFired(TimerBase*);

  AXObject* focusedImageMapUIElement(HTMLAreaElement*);

  AXID getAXID(AXObject*);

  void textChanged(Node*);
  bool nodeIsTextControl(const Node*);

  Settings* settings();
};

// This is the only subclass of AXObjectCache.
DEFINE_TYPE_CASTS(AXObjectCacheImpl, AXObjectCache, cache, true, true);

bool nodeHasRole(Node*, const String& role);
// This will let you know if aria-hidden was explicitly set to false.
bool isNodeAriaVisible(Node*);

}  // namespace blink

#endif