#ifndef UserActionElementSet_h
#define UserActionElementSet_h
#include "wtf/HashMap.h"
#include "wtf/PassOwnPtr.h"
#include "wtf/RefPtr.h"
namespace WebCore {
class Node;
class Element;
class UserActionElementSet {
public:
static PassOwnPtr<UserActionElementSet> create() { return adoptPtr(new UserActionElementSet()); }
bool isFocused(const Node* node) { return hasFlags(node, IsFocusedFlag); }
bool isActive(const Node* node) { return hasFlags(node, IsActiveFlag); }
bool isInActiveChain(const Node* node) { return hasFlags(node, InActiveChainFlag); }
bool isHovered(const Node* node) { return hasFlags(node, IsHoveredFlag); }
void setFocused(Node* node, bool enable) { setFlags(node, enable, IsFocusedFlag); }
void setActive(Node* node, bool enable) { setFlags(node, enable, IsActiveFlag); }
void setInActiveChain(Node* node, bool enable) { setFlags(node, enable, InActiveChainFlag); }
void setHovered(Node* node, bool enable) { setFlags(node, enable, IsHoveredFlag); }
UserActionElementSet();
~UserActionElementSet();
void didDetach(Node*);
void documentDidRemoveLastRef();
private:
enum ElementFlags {
IsActiveFlag = 1 ,
InActiveChainFlag = 1 << 1,
IsHoveredFlag = 1 << 2,
IsFocusedFlag = 1 << 3
};
void setFlags(Node* node, bool enable, unsigned flags) { enable ? setFlags(node, flags) : clearFlags(node, flags); }
void setFlags(Node*, unsigned);
void clearFlags(Node*, unsigned);
bool hasFlags(const Node*, unsigned flags) const;
void setFlags(Element*, unsigned);
void clearFlags(Element*, unsigned);
bool hasFlags(const Element*, unsigned flags) const;
typedef HashMap<RefPtr<Element>, unsigned> ElementFlagMap;
ElementFlagMap m_elements;
};
}
#endif