1/* 2 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2013 Apple Inc. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * * Neither the name of Google Inc. nor the names of its 12 * contributors may be used to endorse or promote products derived from 13 * this software without specific prior written permission. 14 * 15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28#ifndef UserActionElementSet_h 29#define UserActionElementSet_h 30 31#include <wtf/HashMap.h> 32#include <wtf/PassRefPtr.h> 33#include <wtf/RefPtr.h> 34 35namespace WebCore { 36 37class Element; 38 39class UserActionElementSet { 40public: 41 bool isFocused(const Element* element) { return hasFlags(element, IsFocusedFlag); } 42 bool isActive(const Element* element) { return hasFlags(element, IsActiveFlag); } 43 bool isInActiveChain(const Element* element) { return hasFlags(element, InActiveChainFlag); } 44 bool isHovered(const Element* element) { return hasFlags(element, IsHoveredFlag); } 45 void setFocused(Element* element, bool enable) { setFlags(element, enable, IsFocusedFlag); } 46 void setActive(Element* element, bool enable) { setFlags(element, enable, IsActiveFlag); } 47 void setInActiveChain(Element* element, bool enable) { setFlags(element, enable, InActiveChainFlag); } 48 void setHovered(Element* element, bool enable) { setFlags(element, enable, IsHoveredFlag); } 49 50 void didDetach(Element*); 51 void documentDidRemoveLastRef(); 52 53private: 54 enum ElementFlags { 55 IsActiveFlag = 1 , 56 InActiveChainFlag = 1 << 1, 57 IsHoveredFlag = 1 << 2, 58 IsFocusedFlag = 1 << 3 59 }; 60 61 void setFlags(Element* element, bool enable, unsigned flags) { enable ? setFlags(element, flags) : clearFlags(element, flags); } 62 void setFlags(Element*, unsigned); 63 void clearFlags(Element*, unsigned); 64 bool hasFlags(const Element*, unsigned flags) const; 65 66 typedef HashMap<RefPtr<Element>, unsigned> ElementFlagMap; 67 ElementFlagMap m_elements; 68}; 69 70} // namespace 71 72#endif // UserActionElementSet_h 73