2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Neither the name of Google Inc. nor the names of its
11 * contributors may be used to endorse or promote products derived from
12 * this software without specific prior written permission.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 #include "core/dom/UserActionElementSet.h"
30 #include "core/dom/Element.h"
31 #include "core/dom/Node.h"
35 UserActionElementSet::UserActionElementSet()
39 UserActionElementSet::~UserActionElementSet()
43 void UserActionElementSet::didDetach(Element
& element
)
45 ASSERT(element
.isUserActionElement());
46 clearFlags(&element
, IsActiveFlag
| InActiveChainFlag
| IsHoveredFlag
);
50 void UserActionElementSet::documentDidRemoveLastRef()
56 bool UserActionElementSet::hasFlags(const Node
* node
, unsigned flags
) const
58 ASSERT(node
->isUserActionElement() && node
->isElementNode());
59 return hasFlags(toElement(node
), flags
);
62 void UserActionElementSet::setFlags(Node
* node
, unsigned flags
)
64 if (!node
->isElementNode())
66 return setFlags(toElement(node
), flags
);
69 void UserActionElementSet::clearFlags(Node
* node
, unsigned flags
)
71 if (!node
->isElementNode())
73 return clearFlags(toElement(node
), flags
);
76 inline bool UserActionElementSet::hasFlags(const Element
* element
, unsigned flags
) const
78 ASSERT(element
->isUserActionElement());
79 ElementFlagMap::const_iterator found
= m_elements
.find(const_cast<Element
*>(element
));
80 if (found
== m_elements
.end())
82 return found
->value
& flags
;
85 inline void UserActionElementSet::clearFlags(Element
* element
, unsigned flags
)
87 if (!element
->isUserActionElement()) {
88 ASSERT(m_elements
.end() == m_elements
.find(element
));
92 ElementFlagMap::iterator found
= m_elements
.find(element
);
93 if (found
== m_elements
.end()) {
94 element
->setUserActionElement(false);
98 unsigned updated
= found
->value
& ~flags
;
100 element
->setUserActionElement(false);
101 m_elements
.remove(found
);
105 found
->value
= updated
;
108 inline void UserActionElementSet::setFlags(Element
* element
, unsigned flags
)
110 ElementFlagMap::iterator result
= m_elements
.find(element
);
111 if (result
!= m_elements
.end()) {
112 ASSERT(element
->isUserActionElement());
113 result
->value
|= flags
;
117 element
->setUserActionElement(true);
118 m_elements
.add(element
, flags
);
121 DEFINE_TRACE(UserActionElementSet
)
124 visitor
->trace(m_elements
);