| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014, Google Inc. All rights reserved. | 2 * Copyright (C) 2014, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 */ | 27 */ |
| 28 | 28 |
| 29 #ifndef AXObjectCacheImpl_h | 29 #ifndef AXObjectCacheImpl_h |
| 30 #define AXObjectCacheImpl_h | 30 #define AXObjectCacheImpl_h |
| 31 | 31 |
| 32 #include <memory> | 32 #include <memory> |
| 33 #include "core/dom/AXObjectCache.h" | 33 #include "core/dom/AXObjectCache.h" |
| 34 #include "modules/ModulesExport.h" | 34 #include "modules/ModulesExport.h" |
| 35 #include "modules/accessibility/AXObject.h" | 35 #include "modules/accessibility/AXObjectImpl.h" |
| 36 #include "platform/wtf/Forward.h" | 36 #include "platform/wtf/Forward.h" |
| 37 #include "platform/wtf/HashMap.h" | 37 #include "platform/wtf/HashMap.h" |
| 38 #include "platform/wtf/HashSet.h" | 38 #include "platform/wtf/HashSet.h" |
| 39 | 39 |
| 40 namespace blink { | 40 namespace blink { |
| 41 | 41 |
| 42 class AbstractInlineTextBox; | 42 class AbstractInlineTextBox; |
| 43 class HTMLAreaElement; | 43 class HTMLAreaElement; |
| 44 class FrameView; | 44 class FrameView; |
| 45 | 45 |
| 46 // This class should only be used from inside the accessibility directory. | 46 // This class should only be used from inside the accessibility directory. |
| 47 class MODULES_EXPORT AXObjectCacheImpl : public AXObjectCache { | 47 class MODULES_EXPORT AXObjectCacheImpl : public AXObjectCache { |
| 48 WTF_MAKE_NONCOPYABLE(AXObjectCacheImpl); | 48 WTF_MAKE_NONCOPYABLE(AXObjectCacheImpl); |
| 49 | 49 |
| 50 public: | 50 public: |
| 51 static AXObjectCache* Create(Document&); | 51 static AXObjectCache* Create(Document&); |
| 52 | 52 |
| 53 explicit AXObjectCacheImpl(Document&); | 53 explicit AXObjectCacheImpl(Document&); |
| 54 ~AXObjectCacheImpl(); | 54 ~AXObjectCacheImpl(); |
| 55 DECLARE_VIRTUAL_TRACE(); | 55 DECLARE_VIRTUAL_TRACE(); |
| 56 | 56 |
| 57 AXObject* FocusedObject(); | 57 AXObjectImpl* FocusedObject(); |
| 58 | 58 |
| 59 void Dispose() override; | 59 void Dispose() override; |
| 60 | 60 |
| 61 void SelectionChanged(Node*) override; | 61 void SelectionChanged(Node*) override; |
| 62 void ChildrenChanged(Node*) override; | 62 void ChildrenChanged(Node*) override; |
| 63 void ChildrenChanged(LayoutObject*) override; | 63 void ChildrenChanged(LayoutObject*) override; |
| 64 void CheckedStateChanged(Node*) override; | 64 void CheckedStateChanged(Node*) override; |
| 65 virtual void ListboxOptionStateChanged(HTMLOptionElement*); | 65 virtual void ListboxOptionStateChanged(HTMLOptionElement*); |
| 66 virtual void ListboxSelectedChildrenChanged(HTMLSelectElement*); | 66 virtual void ListboxSelectedChildrenChanged(HTMLSelectElement*); |
| 67 virtual void ListboxActiveIndexChanged(HTMLSelectElement*); | 67 virtual void ListboxActiveIndexChanged(HTMLSelectElement*); |
| 68 virtual void RadiobuttonRemovedFromGroup(HTMLInputElement*); | 68 virtual void RadiobuttonRemovedFromGroup(HTMLInputElement*); |
| 69 | 69 |
| 70 void Remove(LayoutObject*) override; | 70 void Remove(LayoutObject*) override; |
| 71 void Remove(Node*) override; | 71 void Remove(Node*) override; |
| 72 void Remove(AbstractInlineTextBox*) override; | 72 void Remove(AbstractInlineTextBox*) override; |
| 73 | 73 |
| 74 const Element* RootAXEditableElement(const Node*) override; | 74 const Element* RootAXEditableElement(const Node*) override; |
| 75 | 75 |
| 76 // Called by a node when text or a text equivalent (e.g. alt) attribute is | 76 // Called by a node when text or a text equivalent (e.g. alt) attribute is |
| 77 // changed. | 77 // changed. |
| 78 void TextChanged(LayoutObject*) override; | 78 void TextChanged(LayoutObject*) override; |
| 79 void TextChanged(AXObject*); | 79 void TextChanged(AXObjectImpl*); |
| 80 // Called when a node has just been attached, so we can make sure we have the | 80 // Called when a node has just been attached, so we can make sure we have the |
| 81 // right subclass of AXObject. | 81 // right subclass of AXObjectImpl. |
| 82 void UpdateCacheAfterNodeIsAttached(Node*) override; | 82 void UpdateCacheAfterNodeIsAttached(Node*) override; |
| 83 | 83 |
| 84 void HandleAttributeChanged(const QualifiedName& attr_name, | 84 void HandleAttributeChanged(const QualifiedName& attr_name, |
| 85 Element*) override; | 85 Element*) override; |
| 86 void HandleFocusedUIElementChanged(Node* old_focused_node, | 86 void HandleFocusedUIElementChanged(Node* old_focused_node, |
| 87 Node* new_focused_node) override; | 87 Node* new_focused_node) override; |
| 88 void HandleInitialFocus() override; | 88 void HandleInitialFocus() override; |
| 89 void HandleTextFormControlChanged(Node*) override; | 89 void HandleTextFormControlChanged(Node*) override; |
| 90 void HandleEditableTextContentChanged(Node*) override; | 90 void HandleEditableTextContentChanged(Node*) override; |
| 91 void HandleValueChanged(Node*) override; | 91 void HandleValueChanged(Node*) override; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 109 // Called when scroll bars are added / removed (as the view resizes). | 109 // Called when scroll bars are added / removed (as the view resizes). |
| 110 void HandleLayoutComplete(LayoutObject*) override; | 110 void HandleLayoutComplete(LayoutObject*) override; |
| 111 void HandleScrolledToAnchor(const Node* anchor_node) override; | 111 void HandleScrolledToAnchor(const Node* anchor_node) override; |
| 112 | 112 |
| 113 const AtomicString& ComputedRoleForNode(Node*) override; | 113 const AtomicString& ComputedRoleForNode(Node*) override; |
| 114 String ComputedNameForNode(Node*) override; | 114 String ComputedNameForNode(Node*) override; |
| 115 | 115 |
| 116 void OnTouchAccessibilityHover(const IntPoint&) override; | 116 void OnTouchAccessibilityHover(const IntPoint&) override; |
| 117 | 117 |
| 118 // Returns the root object for the entire document. | 118 // Returns the root object for the entire document. |
| 119 AXObject* RootObject(); | 119 AXObjectImpl* RootObject(); |
| 120 | 120 |
| 121 AXObject* ObjectFromAXID(AXID id) const { return objects_.at(id); } | 121 AXObjectImpl* ObjectFromAXID(AXID id) const { return objects_.at(id); } |
| 122 AXObject* Root(); | 122 AXObjectImpl* Root(); |
| 123 | 123 |
| 124 // used for objects without backing elements | 124 // used for objects without backing elements |
| 125 AXObject* GetOrCreate(AccessibilityRole); | 125 AXObjectImpl* GetOrCreate(AccessibilityRole); |
| 126 AXObject* GetOrCreate(LayoutObject*); | 126 AXObjectImpl* GetOrCreate(LayoutObject*); |
| 127 AXObject* GetOrCreate(Node*); | 127 AXObjectImpl* GetOrCreate(Node*); |
| 128 AXObject* GetOrCreate(AbstractInlineTextBox*); | 128 AXObjectImpl* GetOrCreate(AbstractInlineTextBox*); |
| 129 | 129 |
| 130 // will only return the AXObject if it already exists | 130 // will only return the AXObjectImpl if it already exists |
| 131 AXObject* Get(Node*); | 131 AXObjectImpl* Get(Node*); |
| 132 AXObject* Get(LayoutObject*); | 132 AXObjectImpl* Get(LayoutObject*); |
| 133 AXObject* Get(AbstractInlineTextBox*); | 133 AXObjectImpl* Get(AbstractInlineTextBox*); |
| 134 | 134 |
| 135 AXObject* FirstAccessibleObjectFromNode(const Node*); | 135 AXObjectImpl* FirstAccessibleObjectFromNode(const Node*); |
| 136 | 136 |
| 137 void Remove(AXID); | 137 void Remove(AXID); |
| 138 | 138 |
| 139 void ChildrenChanged(AXObject*); | 139 void ChildrenChanged(AXObjectImpl*); |
| 140 | 140 |
| 141 void HandleActiveDescendantChanged(Node*); | 141 void HandleActiveDescendantChanged(Node*); |
| 142 void HandleAriaRoleChanged(Node*); | 142 void HandleAriaRoleChanged(Node*); |
| 143 void HandleAriaExpandedChange(Node*); | 143 void HandleAriaExpandedChange(Node*); |
| 144 void HandleAriaSelectedChanged(Node*); | 144 void HandleAriaSelectedChanged(Node*); |
| 145 | 145 |
| 146 bool AccessibilityEnabled(); | 146 bool AccessibilityEnabled(); |
| 147 bool InlineTextBoxAccessibilityEnabled(); | 147 bool InlineTextBoxAccessibilityEnabled(); |
| 148 | 148 |
| 149 void RemoveAXID(AXObject*); | 149 void RemoveAXID(AXObjectImpl*); |
| 150 | 150 |
| 151 AXID GenerateAXID() const; | 151 AXID GenerateAXID() const; |
| 152 | 152 |
| 153 // Counts the number of times the document has been modified. Some attribute | 153 // Counts the number of times the document has been modified. Some attribute |
| 154 // values are cached as long as the modification count hasn't changed. | 154 // values are cached as long as the modification count hasn't changed. |
| 155 int ModificationCount() const { return modification_count_; } | 155 int ModificationCount() const { return modification_count_; } |
| 156 | 156 |
| 157 void PostNotification(LayoutObject*, AXNotification); | 157 void PostNotification(LayoutObject*, AXNotification); |
| 158 void PostNotification(Node*, AXNotification); | 158 void PostNotification(Node*, AXNotification); |
| 159 void PostNotification(AXObject*, AXNotification); | 159 void PostNotification(AXObjectImpl*, AXNotification); |
| 160 | 160 |
| 161 // | 161 // |
| 162 // Aria-owns support. | 162 // Aria-owns support. |
| 163 // | 163 // |
| 164 | 164 |
| 165 // Returns true if the given object's position in the tree was due to | 165 // Returns true if the given object's position in the tree was due to |
| 166 // aria-owns. | 166 // aria-owns. |
| 167 bool IsAriaOwned(const AXObject*) const; | 167 bool IsAriaOwned(const AXObjectImpl*) const; |
| 168 | 168 |
| 169 // Returns the parent of the given object due to aria-owns. | 169 // Returns the parent of the given object due to aria-owns. |
| 170 AXObject* GetAriaOwnedParent(const AXObject*) const; | 170 AXObjectImpl* GetAriaOwnedParent(const AXObjectImpl*) const; |
| 171 | 171 |
| 172 // Given an object that has an aria-owns attributes, and a vector of ids from | 172 // Given an object that has an aria-owns attributes, and a vector of ids from |
| 173 // the value of that attribute, updates the internal state to reflect the new | 173 // the value of that attribute, updates the internal state to reflect the new |
| 174 // set of children owned by this object, returning the result in | 174 // set of children owned by this object, returning the result in |
| 175 // |ownedChildren|. The result is validated - illegal, duplicate, or cyclical | 175 // |ownedChildren|. The result is validated - illegal, duplicate, or cyclical |
| 176 // references have been removed. | 176 // references have been removed. |
| 177 // | 177 // |
| 178 // If one or more ids aren't found, they're added to a lookup table so that if | 178 // If one or more ids aren't found, they're added to a lookup table so that if |
| 179 // an element with that id appears later, it can be added when you call | 179 // an element with that id appears later, it can be added when you call |
| 180 // updateTreeIfElementIdIsAriaOwned. | 180 // updateTreeIfElementIdIsAriaOwned. |
| 181 void UpdateAriaOwns(const AXObject* owner, | 181 void UpdateAriaOwns(const AXObjectImpl* owner, |
| 182 const Vector<String>& id_vector, | 182 const Vector<String>& id_vector, |
| 183 HeapVector<Member<AXObject>>& owned_children); | 183 HeapVector<Member<AXObjectImpl>>& owned_children); |
| 184 | 184 |
| 185 // Given an element in the DOM tree that was either just added or whose id | 185 // Given an element in the DOM tree that was either just added or whose id |
| 186 // just changed, check to see if another object wants to be its parent due to | 186 // just changed, check to see if another object wants to be its parent due to |
| 187 // aria-owns. If so, update the tree by calling childrenChanged() on the | 187 // aria-owns. If so, update the tree by calling childrenChanged() on the |
| 188 // potential owner, possibly reparenting this element. | 188 // potential owner, possibly reparenting this element. |
| 189 void UpdateTreeIfElementIdIsAriaOwned(Element*); | 189 void UpdateTreeIfElementIdIsAriaOwned(Element*); |
| 190 | 190 |
| 191 protected: | 191 protected: |
| 192 void PostPlatformNotification(AXObject*, AXNotification); | 192 void PostPlatformNotification(AXObjectImpl*, AXNotification); |
| 193 void LabelChanged(Element*); | 193 void LabelChanged(Element*); |
| 194 | 194 |
| 195 AXObject* CreateFromRenderer(LayoutObject*); | 195 AXObjectImpl* CreateFromRenderer(LayoutObject*); |
| 196 AXObject* CreateFromNode(Node*); | 196 AXObjectImpl* CreateFromNode(Node*); |
| 197 AXObject* CreateFromInlineTextBox(AbstractInlineTextBox*); | 197 AXObjectImpl* CreateFromInlineTextBox(AbstractInlineTextBox*); |
| 198 | 198 |
| 199 private: | 199 private: |
| 200 Member<Document> document_; | 200 Member<Document> document_; |
| 201 HeapHashMap<AXID, Member<AXObject>> objects_; | 201 HeapHashMap<AXID, Member<AXObjectImpl>> objects_; |
| 202 // LayoutObject and AbstractInlineTextBox are not on the Oilpan heap so we | 202 // LayoutObject and AbstractInlineTextBox are not on the Oilpan heap so we |
| 203 // do not use HeapHashMap for those mappings. | 203 // do not use HeapHashMap for those mappings. |
| 204 HashMap<LayoutObject*, AXID> layout_object_mapping_; | 204 HashMap<LayoutObject*, AXID> layout_object_mapping_; |
| 205 HeapHashMap<Member<Node>, AXID> node_object_mapping_; | 205 HeapHashMap<Member<Node>, AXID> node_object_mapping_; |
| 206 HashMap<AbstractInlineTextBox*, AXID> inline_text_box_object_mapping_; | 206 HashMap<AbstractInlineTextBox*, AXID> inline_text_box_object_mapping_; |
| 207 int modification_count_; | 207 int modification_count_; |
| 208 | 208 |
| 209 HashSet<AXID> ids_in_use_; | 209 HashSet<AXID> ids_in_use_; |
| 210 | 210 |
| 211 #if DCHECK_IS_ON() | 211 #if DCHECK_IS_ON() |
| (...skipping 24 matching lines...) Expand all Loading... |
| 236 HashMap<AXID, HashSet<String>> aria_owner_to_ids_mapping_; | 236 HashMap<AXID, HashSet<String>> aria_owner_to_ids_mapping_; |
| 237 | 237 |
| 238 // Map from an ID (the ID attribute of a DOM element) to the set of elements | 238 // Map from an ID (the ID attribute of a DOM element) to the set of elements |
| 239 // that want to own that ID. This is *unvalidated*, it includes possible | 239 // that want to own that ID. This is *unvalidated*, it includes possible |
| 240 // duplicates. This is used so that when an element with an ID is added to | 240 // duplicates. This is used so that when an element with an ID is added to |
| 241 // the tree or changes its ID, we can quickly determine if it affects an | 241 // the tree or changes its ID, we can quickly determine if it affects an |
| 242 // aria-owns relationship. | 242 // aria-owns relationship. |
| 243 HashMap<String, std::unique_ptr<HashSet<AXID>>> id_to_aria_owners_mapping_; | 243 HashMap<String, std::unique_ptr<HashSet<AXID>>> id_to_aria_owners_mapping_; |
| 244 | 244 |
| 245 TaskRunnerTimer<AXObjectCacheImpl> notification_post_timer_; | 245 TaskRunnerTimer<AXObjectCacheImpl> notification_post_timer_; |
| 246 HeapVector<std::pair<Member<AXObject>, AXNotification>> | 246 HeapVector<std::pair<Member<AXObjectImpl>, AXNotification>> |
| 247 notifications_to_post_; | 247 notifications_to_post_; |
| 248 void NotificationPostTimerFired(TimerBase*); | 248 void NotificationPostTimerFired(TimerBase*); |
| 249 | 249 |
| 250 AXObject* FocusedImageMapUIElement(HTMLAreaElement*); | 250 AXObjectImpl* FocusedImageMapUIElement(HTMLAreaElement*); |
| 251 | 251 |
| 252 AXID GetOrCreateAXID(AXObject*); | 252 AXID GetOrCreateAXID(AXObjectImpl*); |
| 253 | 253 |
| 254 void TextChanged(Node*); | 254 void TextChanged(Node*); |
| 255 bool NodeIsTextControl(const Node*); | 255 bool NodeIsTextControl(const Node*); |
| 256 | 256 |
| 257 Settings* GetSettings(); | 257 Settings* GetSettings(); |
| 258 }; | 258 }; |
| 259 | 259 |
| 260 // This is the only subclass of AXObjectCache. | 260 // This is the only subclass of AXObjectCache. |
| 261 DEFINE_TYPE_CASTS(AXObjectCacheImpl, AXObjectCache, cache, true, true); | 261 DEFINE_TYPE_CASTS(AXObjectCacheImpl, AXObjectCache, cache, true, true); |
| 262 | 262 |
| 263 bool NodeHasRole(Node*, const String& role); | 263 bool NodeHasRole(Node*, const String& role); |
| 264 // This will let you know if aria-hidden was explicitly set to false. | 264 // This will let you know if aria-hidden was explicitly set to false. |
| 265 bool IsNodeAriaVisible(Node*); | 265 bool IsNodeAriaVisible(Node*); |
| 266 | 266 |
| 267 } // namespace blink | 267 } // namespace blink |
| 268 | 268 |
| 269 #endif | 269 #endif |
| OLD | NEW |