#ifndef AXObjectCache_h
#define AXObjectCache_h
#include "core/accessibility/AXObject.h"
#include "core/rendering/RenderText.h"
#include "platform/Timer.h"
#include "wtf/Forward.h"
#include "wtf/HashMap.h"
#include "wtf/HashSet.h"
#include "wtf/RefPtr.h"
namespace WebCore {
class AbstractInlineTextBox;
class Document;
class HTMLAreaElement;
class Node;
class Page;
class RenderObject;
class ScrollView;
class VisiblePosition;
class Widget;
struct TextMarkerData {
AXID axID;
Node* node;
int offset;
EAffinity affinity;
};
class AXComputedObjectAttributeCache {
public:
static PassOwnPtr<AXComputedObjectAttributeCache> create() { return adoptPtr(new AXComputedObjectAttributeCache()); }
AXObjectInclusion getIgnored(AXID) const;
void setIgnored(AXID, AXObjectInclusion);
void clear();
private:
AXComputedObjectAttributeCache() { }
struct CachedAXObjectAttributes {
CachedAXObjectAttributes() : ignored(DefaultBehavior) { }
AXObjectInclusion ignored;
};
HashMap<AXID, CachedAXObjectAttributes> m_idMapping;
};
enum PostType { PostSynchronously, PostAsynchronously };
class AXObjectCache {
WTF_MAKE_NONCOPYABLE(AXObjectCache); WTF_MAKE_FAST_ALLOCATED;
public:
explicit AXObjectCache(Document&);
~AXObjectCache();
static AXObject* focusedUIElementForPage(const Page*);
AXObject* rootObject();
AXObject* getOrCreate(RenderObject*);
AXObject* getOrCreate(Widget*);
AXObject* getOrCreate(Node*);
AXObject* getOrCreate(AbstractInlineTextBox*);
AXObject* getOrCreate(AccessibilityRole);
AXObject* get(RenderObject*);
AXObject* get(Widget*);
AXObject* get(Node*);
AXObject* get(AbstractInlineTextBox*);
void remove(RenderObject*);
void remove(Node*);
void remove(Widget*);
void remove(AbstractInlineTextBox*);
void remove(AXID);
void detachWrapper(AXObject*);
void attachWrapper(AXObject*);
void childrenChanged(Node*);
void childrenChanged(RenderObject*);
void childrenChanged(AXObject*);
void checkedStateChanged(Node*);
void selectedChildrenChanged(Node*);
void selectedChildrenChanged(RenderObject*);
void selectionChanged(Node*);
void textChanged(Node*);
void textChanged(RenderObject*);
void updateCacheAfterNodeIsAttached(Node*);
void handleActiveDescendantChanged(Node*);
void handleAriaRoleChanged(Node*);
void handleFocusedUIElementChanged(Node* oldFocusedNode, Node* newFocusedNode);
void handleScrolledToAnchor(const Node* anchorNode);
void handleAriaExpandedChange(Node*);
void handleScrollbarUpdate(ScrollView*);
void handleLayoutComplete(RenderObject*);
void handleScrollPositionChanged(ScrollView*);
void handleScrollPositionChanged(RenderObject*);
void handleAttributeChanged(const QualifiedName& attrName, Element*);
void recomputeIsIgnored(RenderObject* renderer);
void inlineTextBoxesUpdated(RenderObject* renderer);
static void enableAccessibility() { gAccessibilityEnabled = true; }
static bool accessibilityEnabled() { return gAccessibilityEnabled; }
static void setInlineTextBoxAccessibility(bool flag) { gInlineTextBoxAccessibility = flag; }
static bool inlineTextBoxAccessibility() { return gInlineTextBoxAccessibility; }
void removeAXID(AXObject*);
bool isIDinUse(AXID id) const { return m_idsInUse.contains(id); }
Element* rootAXEditableElement(Node*);
const Element* rootAXEditableElement(const Node*);
bool nodeIsTextControl(const Node*);
AXID platformGenerateAXID() const;
AXObject* objectFromAXID(AXID id) const { return m_objects.get(id); }
void textMarkerDataForVisiblePosition(TextMarkerData&, const VisiblePosition&);
VisiblePosition visiblePositionForTextMarkerData(TextMarkerData&);
enum AXNotification {
AXActiveDescendantChanged,
AXAlert,
AXAriaAttributeChanged,
AXAutocorrectionOccured,
AXBlur,
AXCheckedStateChanged,
AXChildrenChanged,
AXFocusedUIElementChanged,
AXHide,
AXInvalidStatusChanged,
AXLayoutComplete,
AXLiveRegionChanged,
AXLoadComplete,
AXLocationChanged,
AXMenuListItemSelected,
AXMenuListValueChanged,
AXRowCollapsed,
AXRowCountChanged,
AXRowExpanded,
AXScrollPositionChanged,
AXScrolledToAnchor,
AXSelectedChildrenChanged,
AXSelectedTextChanged,
AXShow,
AXTextChanged,
AXTextInserted,
AXTextRemoved,
AXValueChanged
};
void postNotification(RenderObject*, AXNotification, bool postToElement, PostType = PostAsynchronously);
void postNotification(Node*, AXNotification, bool postToElement, PostType = PostAsynchronously);
void postNotification(AXObject*, Document*, AXNotification, bool postToElement, PostType = PostAsynchronously);
bool nodeHasRole(Node*, const AtomicString& role);
void startCachingComputedObjectAttributesUntilTreeMutates();
void stopCachingComputedObjectAttributes();
AXComputedObjectAttributeCache* computedObjectAttributeCache() { return m_computedObjectAttributeCache.get(); }
protected:
void postPlatformNotification(AXObject*, AXNotification);
void textChanged(AXObject*);
void labelChanged(Element*);
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); }
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;
OwnPtr<AXComputedObjectAttributeCache> m_computedObjectAttributeCache;
static bool gAccessibilityEnabled;
static bool gInlineTextBoxAccessibility;
HashSet<AXID> m_idsInUse;
Timer<AXObjectCache> m_notificationPostTimer;
Vector<pair<RefPtr<AXObject>, AXNotification> > m_notificationsToPost;
void notificationPostTimerFired(Timer<AXObjectCache>*);
static AXObject* focusedImageMapUIElement(HTMLAreaElement*);
AXID getAXID(AXObject*);
};
bool nodeHasRole(Node*, const String& role);
bool isNodeAriaVisible(Node*);
}
#endif