UserActionElementSet.h [plain text]
#ifndef UserActionElementSet_h
#define UserActionElementSet_h
#include <wtf/HashMap.h>
#include <wtf/PassRefPtr.h>
#include <wtf/RefPtr.h>
namespace WebCore {
class Element;
class UserActionElementSet {
public:
bool isFocused(const Element* element) { return hasFlags(element, IsFocusedFlag); }
bool isActive(const Element* element) { return hasFlags(element, IsActiveFlag); }
bool isInActiveChain(const Element* element) { return hasFlags(element, InActiveChainFlag); }
bool isHovered(const Element* element) { return hasFlags(element, IsHoveredFlag); }
void setFocused(Element* element, bool enable) { setFlags(element, enable, IsFocusedFlag); }
void setActive(Element* element, bool enable) { setFlags(element, enable, IsActiveFlag); }
void setInActiveChain(Element* element, bool enable) { setFlags(element, enable, InActiveChainFlag); }
void setHovered(Element* element, bool enable) { setFlags(element, enable, IsHoveredFlag); }
void didDetach(Element*);
void documentDidRemoveLastRef();
private:
enum ElementFlags {
IsActiveFlag = 1 ,
InActiveChainFlag = 1 << 1,
IsHoveredFlag = 1 << 2,
IsFocusedFlag = 1 << 3
};
void setFlags(Element* element, bool enable, unsigned flags) { enable ? setFlags(element, flags) : clearFlags(element, flags); }
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 // UserActionElementSet_h