#ifndef AXObjectCache_h
#define AXObjectCache_h
#include "AccessibilityObject.h"
#include "EventHandler.h"
#include "Timer.h"
#include <limits.h>
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/RefPtr.h>
#include <wtf/UnusedParam.h>
#ifdef __OBJC__
@class WebCoreTextMarker;
#else
class WebCoreTextMarker;
#endif
namespace WebCore {
class HTMLAreaElement;
class Node;
class Page;
class RenderObject;
class String;
class VisiblePosition;
struct TextMarkerData {
AXID axID;
Node* node;
int offset;
EAffinity affinity;
};
enum PostType { PostSynchronously, PostAsynchronously };
class AXObjectCache : public Noncopyable {
public:
AXObjectCache();
~AXObjectCache();
static AccessibilityObject* focusedUIElementForPage(const Page*);
AccessibilityObject* getOrCreate(RenderObject*);
AccessibilityObject* getOrCreate(AccessibilityRole);
AccessibilityObject* get(RenderObject*);
void remove(RenderObject*);
void remove(AXID);
void detachWrapper(AccessibilityObject*);
void attachWrapper(AccessibilityObject*);
void childrenChanged(RenderObject*);
void selectedChildrenChanged(RenderObject*);
void contentChanged(RenderObject*);
void handleActiveDescendantChanged(RenderObject*);
void handleAriaRoleChanged(RenderObject*);
void handleFocusedUIElementChanged(RenderObject* oldFocusedRenderer, RenderObject* newFocusedRenderer);
void handleScrolledToAnchor(const Node* anchorNode);
static void enableAccessibility() { gAccessibilityEnabled = true; }
static void enableEnhancedUserInterfaceAccessibility() { gAccessibilityEnhancedUserInterfaceEnabled = true; }
static bool accessibilityEnabled() { return gAccessibilityEnabled; }
static bool accessibilityEnhancedUserInterfaceEnabled() { return gAccessibilityEnhancedUserInterfaceEnabled; }
void removeAXID(AccessibilityObject*);
bool isIDinUse(AXID id) const { return m_idsInUse.contains(id); }
AXID platformGenerateAXID() const;
AccessibilityObject* objectFromAXID(AXID id) const { return m_objects.get(id).get(); }
static void textMarkerDataForVisiblePosition(TextMarkerData&, const VisiblePosition&);
static VisiblePosition visiblePositionForTextMarkerData(TextMarkerData&);
enum AXNotification {
AXActiveDescendantChanged,
AXCheckedStateChanged,
AXFocusedUIElementChanged,
AXLayoutComplete,
AXLoadComplete,
AXSelectedChildrenChanged,
AXSelectedTextChanged,
AXValueChanged,
AXScrolledToAnchor,
AXLiveRegionChanged,
AXMenuListValueChanged,
};
void postNotification(RenderObject*, AXNotification, bool postToElement, PostType = PostAsynchronously);
void postNotification(AccessibilityObject*, Document*, AXNotification, bool postToElement, PostType = PostAsynchronously);
bool nodeHasRole(Node*, const AtomicString& role);
protected:
void postPlatformNotification(AccessibilityObject*, AXNotification);
private:
HashMap<AXID, RefPtr<AccessibilityObject> > m_objects;
HashMap<RenderObject*, AXID> m_renderObjectMapping;
static bool gAccessibilityEnabled;
static bool gAccessibilityEnhancedUserInterfaceEnabled;
HashSet<AXID> m_idsInUse;
Timer<AXObjectCache> m_notificationPostTimer;
Vector<pair<RefPtr<AccessibilityObject>, AXNotification> > m_notificationsToPost;
void notificationPostTimerFired(Timer<AXObjectCache>*);
static AccessibilityObject* focusedImageMapUIElement(HTMLAreaElement*);
AXID getAXID(AccessibilityObject*);
};
#if !HAVE(ACCESSIBILITY)
inline void AXObjectCache::handleActiveDescendantChanged(RenderObject*) { }
inline void AXObjectCache::handleAriaRoleChanged(RenderObject*) { }
inline void AXObjectCache::detachWrapper(AccessibilityObject*) { }
inline void AXObjectCache::attachWrapper(AccessibilityObject*) { }
inline void AXObjectCache::selectedChildrenChanged(RenderObject*) { }
inline void AXObjectCache::postNotification(RenderObject*, AXNotification, bool postToElement, PostType) { UNUSED_PARAM(postToElement); }
inline void AXObjectCache::postPlatformNotification(AccessibilityObject*, AXNotification) { }
inline void AXObjectCache::handleFocusedUIElementChanged(RenderObject*, RenderObject*) { }
inline void AXObjectCache::handleScrolledToAnchor(const Node*) { }
inline void AXObjectCache::contentChanged(RenderObject*) { }
#endif
}
#endif