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
|
/*
* 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 "core/rendering/RenderText.h"
#include "modules/accessibility/AXObject.h"
#include "platform/Timer.h"
#include "wtf/Forward.h"
#include "wtf/HashMap.h"
#include "wtf/HashSet.h"
#include "wtf/RefPtr.h"
namespace blink {
class AbstractInlineTextBox;
class HTMLAreaElement;
class FrameView;
class Widget;
struct TextMarkerData {
AXID axID;
Node* node;
int offset;
EAffinity affinity;
};
// This class should only be used from inside the accessibility directory.
class AXObjectCacheImpl : public AXObjectCache {
WTF_MAKE_NONCOPYABLE(AXObjectCacheImpl); WTF_MAKE_FAST_ALLOCATED;
public:
explicit AXObjectCacheImpl(Document&);
~AXObjectCacheImpl();
AXObject* focusedUIElementForPage(const Page*);
virtual void selectionChanged(Node*) override;
virtual void childrenChanged(Node*) override;
virtual void childrenChanged(RenderObject*) override;
virtual void checkedStateChanged(Node*) override;
virtual void selectedChildrenChanged(Node*) override;
virtual void remove(RenderObject*) override;
virtual void remove(Node*) override;
virtual void remove(Widget*) override;
virtual const Element* rootAXEditableElement(const Node*) override;
// Called by a node when text or a text equivalent (e.g. alt) attribute is changed.
virtual void textChanged(RenderObject*) override;
// Called when a node has just been attached, so we can make sure we have the right subclass of AXObject.
virtual void updateCacheAfterNodeIsAttached(Node*) override;
virtual void handleAttributeChanged(const QualifiedName& attrName, Element*) override;
virtual void handleFocusedUIElementChanged(Node* oldFocusedNode, Node* newFocusedNode) override;
virtual void handleInitialFocus() override;
virtual void handleTextFormControlChanged(Node*) override;
virtual void handleEditableTextContentChanged(Node*) override;
virtual void handleValueChanged(Node*) override;
virtual void handleUpdateActiveMenuOption(RenderMenuList*, int optionIndex) override;
virtual void handleLoadComplete(Document*) override;
virtual void handleLayoutComplete(Document*) override;
virtual void setCanvasObjectBounds(Element*, const LayoutRect&) override;
virtual void clearWeakMembers(Visitor*) override;
virtual void inlineTextBoxesUpdated(RenderObject* renderer) override;
// Called when the scroll offset changes.
virtual void handleScrollPositionChanged(FrameView*) override;
virtual void handleScrollPositionChanged(RenderObject*) override;
// Called when scroll bars are added / removed (as the view resizes).
void handleScrollbarUpdate(FrameView*) override;
void handleLayoutComplete(RenderObject*) override;
void handleScrolledToAnchor(const Node* anchorNode) override;
virtual const AtomicString& computedRoleForNode(Node*) override;
virtual String computedNameForNode(Node*) 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(RenderObject*);
AXObject* getOrCreate(Widget*);
AXObject* getOrCreate(Node*);
AXObject* getOrCreate(AbstractInlineTextBox*);
// will only return the AXObject if it already exists
AXObject* get(Node*);
AXObject* get(RenderObject*);
AXObject* get(Widget*);
AXObject* get(AbstractInlineTextBox*);
AXObject* firstAccessibleObjectFromNode(const Node*);
void remove(AXID);
void remove(AbstractInlineTextBox*);
void childrenChanged(AXObject*);
void selectedChildrenChanged(RenderObject*);
void handleActiveDescendantChanged(Node*);
void handleAriaRoleChanged(Node*);
void handleAriaExpandedChange(Node*);
void recomputeIsIgnored(RenderObject* renderer);
bool accessibilityEnabled();
bool inlineTextBoxAccessibilityEnabled();
void removeAXID(AXObject*);
bool isIDinUse(AXID id) const { return m_idsInUse.contains(id); }
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(RenderObject*, AXNotification, bool postToElement);
void postNotification(Node*, AXNotification, bool postToElement);
void postNotification(AXObject*, Document*, AXNotification, bool postToElement);
protected:
void postPlatformNotification(AXObject*, AXNotification);
void textChanged(AXObject*);
void labelChanged(Element*);
// This is a weak reference cache for knowing if Nodes used by TextMarkers are valid.
void setNodeInUse(Node* n) { m_textMarkerNodes.add(n); }
void removeNodeForUse(Node* n) { m_textMarkerNodes.remove(n); }
bool isNodeInUse(Node* n) { return m_textMarkerNodes.contains(n); }
PassRefPtr<AXObject> createFromRenderer(RenderObject*);
PassRefPtr<AXObject> createFromNode(Node*);
PassRefPtr<AXObject> createFromInlineTextBox(AbstractInlineTextBox*);
private:
Document& m_document;
HashMap<AXID, RefPtr<AXObject> > m_objects;
HashMap<RenderObject*, AXID> m_renderObjectMapping;
HashMap<Widget*, AXID> m_widgetObjectMapping;
HashMap<Node*, AXID> m_nodeObjectMapping;
HashMap<AbstractInlineTextBox*, AXID> m_inlineTextBoxObjectMapping;
HashSet<Node*> m_textMarkerNodes;
int m_modificationCount;
HashSet<AXID> m_idsInUse;
Timer<AXObjectCacheImpl> m_notificationPostTimer;
Vector<pair<RefPtr<AXObject>, AXNotification> > m_notificationsToPost;
void notificationPostTimerFired(Timer<AXObjectCacheImpl>*);
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*);
}
#endif
|