morrita@google.com | 85d3bff | 2012-12-11 10:36:24 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Google Inc. All rights reserved. |
akling@apple.com | f40c868 | 2013-05-26 14:29:15 +0000 | [diff] [blame] | 3 | * Copyright (C) 2013 Apple Inc. All rights reserved. |
morrita@google.com | 85d3bff | 2012-12-11 10:36:24 +0000 | [diff] [blame] | 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/OwnPtr.h> |
| 33 | #include <wtf/PassOwnPtr.h> |
| 34 | #include <wtf/PassRefPtr.h> |
| 35 | #include <wtf/RefPtr.h> |
| 36 | |
| 37 | namespace WebCore { |
| 38 | |
morrita@google.com | 85d3bff | 2012-12-11 10:36:24 +0000 | [diff] [blame] | 39 | class Element; |
| 40 | |
| 41 | class UserActionElementSet { |
| 42 | public: |
| 43 | static PassOwnPtr<UserActionElementSet> create() { return adoptPtr(new UserActionElementSet()); } |
| 44 | |
akling@apple.com | 1508ce8 | 2013-05-25 10:27:37 +0000 | [diff] [blame] | 45 | bool isFocused(const Element* element) { return hasFlags(element, IsFocusedFlag); } |
akling@apple.com | f40c868 | 2013-05-26 14:29:15 +0000 | [diff] [blame] | 46 | bool isActive(const Element* element) { return hasFlags(element, IsActiveFlag); } |
akling@apple.com | f189674 | 2013-05-26 22:23:18 +0000 | [diff] [blame] | 47 | bool isInActiveChain(const Element* element) { return hasFlags(element, InActiveChainFlag); } |
akling@apple.com | 1508ce8 | 2013-05-25 10:27:37 +0000 | [diff] [blame] | 48 | bool isHovered(const Element* element) { return hasFlags(element, IsHoveredFlag); } |
| 49 | void setFocused(Element* element, bool enable) { setFlags(element, enable, IsFocusedFlag); } |
akling@apple.com | f40c868 | 2013-05-26 14:29:15 +0000 | [diff] [blame] | 50 | void setActive(Element* element, bool enable) { setFlags(element, enable, IsActiveFlag); } |
akling@apple.com | f189674 | 2013-05-26 22:23:18 +0000 | [diff] [blame] | 51 | void setInActiveChain(Element* element, bool enable) { setFlags(element, enable, InActiveChainFlag); } |
akling@apple.com | b532ed8 | 2013-05-25 09:16:30 +0000 | [diff] [blame] | 52 | void setHovered(Element* element, bool enable) { setFlags(element, enable, IsHoveredFlag); } |
morrita@google.com | 85d3bff | 2012-12-11 10:36:24 +0000 | [diff] [blame] | 53 | |
| 54 | UserActionElementSet(); |
| 55 | ~UserActionElementSet(); |
| 56 | |
akling@apple.com | f189674 | 2013-05-26 22:23:18 +0000 | [diff] [blame] | 57 | void didDetach(Element*); |
morrita@google.com | 85d3bff | 2012-12-11 10:36:24 +0000 | [diff] [blame] | 58 | void documentDidRemoveLastRef(); |
| 59 | |
| 60 | private: |
| 61 | enum ElementFlags { |
| 62 | IsActiveFlag = 1 , |
| 63 | InActiveChainFlag = 1 << 1, |
| 64 | IsHoveredFlag = 1 << 2, |
| 65 | IsFocusedFlag = 1 << 3 |
| 66 | }; |
| 67 | |
akling@apple.com | b532ed8 | 2013-05-25 09:16:30 +0000 | [diff] [blame] | 68 | void setFlags(Element* element, bool enable, unsigned flags) { enable ? setFlags(element, flags) : clearFlags(element, flags); } |
morrita@google.com | 85d3bff | 2012-12-11 10:36:24 +0000 | [diff] [blame] | 69 | 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 |