blob: 11dd7a011ba1259cf2ee41cce39f08624f02c742 [file] [log] [blame]
morrita@google.com85d3bff2012-12-11 10:36:24 +00001/*
2 * Copyright (C) 2012 Google Inc. All rights reserved.
akling@apple.comf40c8682013-05-26 14:29:15 +00003 * Copyright (C) 2013 Apple Inc. All rights reserved.
morrita@google.com85d3bff2012-12-11 10:36:24 +00004 *
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/OwnPtr.h>
33#include <wtf/PassOwnPtr.h>
34#include <wtf/PassRefPtr.h>
35#include <wtf/RefPtr.h>
36
37namespace WebCore {
38
morrita@google.com85d3bff2012-12-11 10:36:24 +000039class Element;
40
41class UserActionElementSet {
42public:
43 static PassOwnPtr<UserActionElementSet> create() { return adoptPtr(new UserActionElementSet()); }
44
akling@apple.com1508ce82013-05-25 10:27:37 +000045 bool isFocused(const Element* element) { return hasFlags(element, IsFocusedFlag); }
akling@apple.comf40c8682013-05-26 14:29:15 +000046 bool isActive(const Element* element) { return hasFlags(element, IsActiveFlag); }
akling@apple.comf1896742013-05-26 22:23:18 +000047 bool isInActiveChain(const Element* element) { return hasFlags(element, InActiveChainFlag); }
akling@apple.com1508ce82013-05-25 10:27:37 +000048 bool isHovered(const Element* element) { return hasFlags(element, IsHoveredFlag); }
49 void setFocused(Element* element, bool enable) { setFlags(element, enable, IsFocusedFlag); }
akling@apple.comf40c8682013-05-26 14:29:15 +000050 void setActive(Element* element, bool enable) { setFlags(element, enable, IsActiveFlag); }
akling@apple.comf1896742013-05-26 22:23:18 +000051 void setInActiveChain(Element* element, bool enable) { setFlags(element, enable, InActiveChainFlag); }
akling@apple.comb532ed82013-05-25 09:16:30 +000052 void setHovered(Element* element, bool enable) { setFlags(element, enable, IsHoveredFlag); }
morrita@google.com85d3bff2012-12-11 10:36:24 +000053
54 UserActionElementSet();
55 ~UserActionElementSet();
56
akling@apple.comf1896742013-05-26 22:23:18 +000057 void didDetach(Element*);
morrita@google.com85d3bff2012-12-11 10:36:24 +000058 void documentDidRemoveLastRef();
59
60private:
61 enum ElementFlags {
62 IsActiveFlag = 1 ,
63 InActiveChainFlag = 1 << 1,
64 IsHoveredFlag = 1 << 2,
65 IsFocusedFlag = 1 << 3
66 };
67
akling@apple.comb532ed82013-05-25 09:16:30 +000068 void setFlags(Element* element, bool enable, unsigned flags) { enable ? setFlags(element, flags) : clearFlags(element, flags); }
morrita@google.com85d3bff2012-12-11 10:36:24 +000069 void setFlags(Element*, unsigned);
70 void clearFlags(Element*, unsigned);
71 bool hasFlags(const Element*, unsigned flags) const;
72
73 typedef HashMap<RefPtr<Element>, unsigned> ElementFlagMap;
74 ElementFlagMap m_elements;
75};
76
77} // namespace
78
79#endif // UserActionElementSet_h