blob: dea3accedb7fb23b1836299df7781ca89f7495aa [file] [log] [blame]
darin@apple.comfaced262009-01-12 07:44:27 +00001/*
darin@apple.comf5247d12010-06-13 17:29:10 +00002 * Copyright (C) 2008, 2009, 2010 Apple Inc. All rights reserved.
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +00003 * Copyright (C) 2008 David Smith <catfish.man@gmail.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 */
21
22#ifndef ElementRareData_h
23#define ElementRareData_h
24
commit-queue@webkit.org691d04f2010-10-29 09:32:14 +000025#include "ClassList.h"
weinig@apple.com96a2cf92010-06-30 23:15:15 +000026#include "DatasetDOMStringMap.h"
caio.oliveira@openbossa.org26b85d32012-03-08 17:42:28 +000027#include "NamedNodeMap.h"
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +000028#include "NodeRareData.h"
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +000029#include "PseudoElement.h"
darin@apple.com8cdf7122013-09-30 02:40:50 +000030#include "RenderElement.h"
antti@apple.com64d69392013-08-15 16:52:40 +000031#include "ShadowRoot.h"
commit-queue@webkit.orgd0c076d2012-08-22 22:25:59 +000032#include "StyleInheritedData.h"
commit-queue@webkit.org1e0ed9d2014-02-25 20:42:44 +000033#include <wtf/OwnPtr.h>
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +000034
35namespace WebCore {
alp@webkit.org2122a042008-10-03 12:38:12 +000036
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +000037class ElementRareData : public NodeRareData {
38public:
commit-queue@webkit.org1e0ed9d2014-02-25 20:42:44 +000039 static PassOwnPtr<ElementRareData> create(RenderElement* renderer) { return adoptPtr(new ElementRareData(renderer)); }
40
rniwa@webkit.orgc311c022013-01-16 05:23:04 +000041 ~ElementRareData();
darin@apple.com929b9072008-12-13 22:53:55 +000042
antti@apple.com9426a742013-08-24 11:09:26 +000043 void setBeforePseudoElement(PassRefPtr<PseudoElement>);
44 void setAfterPseudoElement(PassRefPtr<PseudoElement>);
45
46 PseudoElement* beforePseudoElement() const { return m_beforePseudoElement.get(); }
47 PseudoElement* afterPseudoElement() const { return m_afterPseudoElement.get(); }
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +000048
darin@apple.comfaced262009-01-12 07:44:27 +000049 void resetComputedStyle();
allan.jensen@digia.com44ec64e2012-11-28 13:09:40 +000050 void resetDynamicRestyleObservations();
rniwa@webkit.org2015feb2013-01-14 23:57:39 +000051
52 short tabIndex() const { return m_tabIndex; }
53 void setTabIndexExplicitly(short index) { m_tabIndex = index; m_tabIndexWasSetExplicitly = true; }
54 bool tabIndexSetExplicitly() const { return m_tabIndexWasSetExplicitly; }
55 void clearTabIndexExplicitly() { m_tabIndex = 0; m_tabIndexWasSetExplicitly = false; }
alp@webkit.org2122a042008-10-03 12:38:12 +000056
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000057 bool needsFocusAppearanceUpdateSoonAfterAttach() const { return m_needsFocusAppearanceUpdateSoonAfterAttach; }
58 void setNeedsFocusAppearanceUpdateSoonAfterAttach(bool needs) { m_needsFocusAppearanceUpdateSoonAfterAttach = needs; }
59
60 bool styleAffectedByEmpty() const { return m_styleAffectedByEmpty; }
61 void setStyleAffectedByEmpty(bool value) { m_styleAffectedByEmpty = value; }
62
63 bool isInCanvasSubtree() const { return m_isInCanvasSubtree; }
64 void setIsInCanvasSubtree(bool value) { m_isInCanvasSubtree = value; }
65
commit-queue@webkit.org75d76c42013-06-20 16:13:11 +000066 RegionOversetState regionOversetState() const { return m_regionOversetState; }
67 void setRegionOversetState(RegionOversetState state) { m_regionOversetState = state; }
68
kling@webkit.orgc7b06df2012-10-03 12:55:24 +000069#if ENABLE(FULLSCREEN_API)
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000070 bool containsFullScreenElement() { return m_containsFullScreenElement; }
71 void setContainsFullScreenElement(bool value) { m_containsFullScreenElement = value; }
kling@webkit.orgc7b06df2012-10-03 12:55:24 +000072#endif
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000073
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000074 bool childrenAffectedByActive() const { return m_childrenAffectedByActive; }
75 void setChildrenAffectedByActive(bool value) { m_childrenAffectedByActive = value; }
76 bool childrenAffectedByDrag() const { return m_childrenAffectedByDrag; }
77 void setChildrenAffectedByDrag(bool value) { m_childrenAffectedByDrag = value; }
78
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000079 bool childrenAffectedByLastChildRules() const { return m_childrenAffectedByLastChildRules; }
80 void setChildrenAffectedByLastChildRules(bool value) { m_childrenAffectedByLastChildRules = value; }
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000081 bool childrenAffectedByForwardPositionalRules() const { return m_childrenAffectedByForwardPositionalRules; }
82 void setChildrenAffectedByForwardPositionalRules(bool value) { m_childrenAffectedByForwardPositionalRules = value; }
83 bool childrenAffectedByBackwardPositionalRules() const { return m_childrenAffectedByBackwardPositionalRules; }
84 void setChildrenAffectedByBackwardPositionalRules(bool value) { m_childrenAffectedByBackwardPositionalRules = value; }
benjamin@webkit.org9c6a1c62014-04-14 08:42:53 +000085
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000086 unsigned childIndex() const { return m_childIndex; }
87 void setChildIndex(unsigned index) { m_childIndex = index; }
benjamin@webkit.org9c6a1c62014-04-14 08:42:53 +000088 static ptrdiff_t childIndexMemoryOffset() { return OBJECT_OFFSETOF(ElementRareData, m_childIndex); }
darin@apple.com929b9072008-12-13 22:53:55 +000089
antti@apple.com64d69392013-08-15 16:52:40 +000090 void clearShadowRoot() { m_shadowRoot = nullptr; }
91 ShadowRoot* shadowRoot() const { return m_shadowRoot.get(); }
92 void setShadowRoot(PassRefPtr<ShadowRoot> shadowRoot) { m_shadowRoot = shadowRoot; }
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000093
94 NamedNodeMap* attributeMap() const { return m_attributeMap.get(); }
commit-queue@webkit.org1e0ed9d2014-02-25 20:42:44 +000095 void setAttributeMap(PassOwnPtr<NamedNodeMap> attributeMap) { m_attributeMap = attributeMap; }
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000096
97 RenderStyle* computedStyle() const { return m_computedStyle.get(); }
akling@apple.com5bbaebd2013-10-23 10:42:20 +000098 void setComputedStyle(PassRef<RenderStyle> computedStyle) { m_computedStyle = std::move(computedStyle); }
commit-queue@webkit.org63be9352012-12-05 20:43:40 +000099
100 ClassList* classList() const { return m_classList.get(); }
commit-queue@webkit.orgeabb6482013-10-30 05:15:27 +0000101 void setClassList(std::unique_ptr<ClassList> classList) { m_classList = std::move(classList); }
esprehn@chromium.orgfbc22e52013-01-03 02:59:32 +0000102 void clearClassListValueForQuirksMode()
103 {
104 if (!m_classList)
105 return;
106 m_classList->clearValueForQuirksMode();
107 }
commit-queue@webkit.org63be9352012-12-05 20:43:40 +0000108
109 DatasetDOMStringMap* dataset() const { return m_dataset.get(); }
commit-queue@webkit.orgeabb6482013-10-30 05:15:27 +0000110 void setDataset(std::unique_ptr<DatasetDOMStringMap> dataset) { m_dataset = std::move(dataset); }
commit-queue@webkit.org63be9352012-12-05 20:43:40 +0000111
112 LayoutSize minimumSizeForResizing() const { return m_minimumSizeForResizing; }
113 void setMinimumSizeForResizing(LayoutSize size) { m_minimumSizeForResizing = size; }
114
115 IntSize savedLayerScrollOffset() const { return m_savedLayerScrollOffset; }
116 void setSavedLayerScrollOffset(IntSize size) { m_savedLayerScrollOffset = size; }
117
senorblanco@chromium.org7b6792b2013-01-04 19:48:10 +0000118 bool hasPendingResources() const { return m_hasPendingResources; }
119 void setHasPendingResources(bool has) { m_hasPendingResources = has; }
senorblanco@chromium.org7b6792b2013-01-04 19:48:10 +0000120
commit-queue@webkit.org63be9352012-12-05 20:43:40 +0000121private:
rniwa@webkit.org2015feb2013-01-14 23:57:39 +0000122 short m_tabIndex;
123 unsigned short m_childIndex;
124 unsigned m_tabIndexWasSetExplicitly : 1;
125 unsigned m_needsFocusAppearanceUpdateSoonAfterAttach : 1;
126 unsigned m_styleAffectedByEmpty : 1;
127 unsigned m_isInCanvasSubtree : 1;
128#if ENABLE(FULLSCREEN_API)
129 unsigned m_containsFullScreenElement : 1;
130#endif
rniwa@webkit.org2015feb2013-01-14 23:57:39 +0000131 unsigned m_hasPendingResources : 1;
rniwa@webkit.org2015feb2013-01-14 23:57:39 +0000132 unsigned m_childrenAffectedByHover : 1;
133 unsigned m_childrenAffectedByActive : 1;
134 unsigned m_childrenAffectedByDrag : 1;
135 // Bits for dynamic child matching.
136 // We optimize for :first-child and :last-child. The other positional child selectors like nth-child or
137 // *-child-of-type, we will just give up and re-evaluate whenever children change at all.
rniwa@webkit.org2015feb2013-01-14 23:57:39 +0000138 unsigned m_childrenAffectedByLastChildRules : 1;
rniwa@webkit.org2015feb2013-01-14 23:57:39 +0000139 unsigned m_childrenAffectedByForwardPositionalRules : 1;
140 unsigned m_childrenAffectedByBackwardPositionalRules : 1;
rniwa@webkit.org2015feb2013-01-14 23:57:39 +0000141
commit-queue@webkit.org75d76c42013-06-20 16:13:11 +0000142 RegionOversetState m_regionOversetState;
143
eae@chromium.org5b93f412011-08-15 23:51:21 +0000144 LayoutSize m_minimumSizeForResizing;
rniwa@webkit.orgc311c022013-01-16 05:23:04 +0000145 IntSize m_savedLayerScrollOffset;
hyatt@apple.comdec0cbf22008-10-17 00:25:33 +0000146 RefPtr<RenderStyle> m_computedStyle;
weinig@apple.com96a2cf92010-06-30 23:15:15 +0000147
commit-queue@webkit.orgeabb6482013-10-30 05:15:27 +0000148 std::unique_ptr<DatasetDOMStringMap> m_dataset;
149 std::unique_ptr<ClassList> m_classList;
antti@apple.com64d69392013-08-15 16:52:40 +0000150 RefPtr<ShadowRoot> m_shadowRoot;
commit-queue@webkit.org1e0ed9d2014-02-25 20:42:44 +0000151 OwnPtr<NamedNodeMap> m_attributeMap;
jer.noble@apple.com366ebb02011-05-30 02:05:30 +0000152
antti@apple.com9426a742013-08-24 11:09:26 +0000153 RefPtr<PseudoElement> m_beforePseudoElement;
154 RefPtr<PseudoElement> m_afterPseudoElement;
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +0000155
commit-queue@webkit.org1e0ed9d2014-02-25 20:42:44 +0000156 explicit ElementRareData(RenderElement*);
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +0000157 void releasePseudoElement(PseudoElement*);
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000158};
159
160inline IntSize defaultMinimumSizeForResizing()
161{
eae@chromium.org9717cd82012-11-07 18:33:44 +0000162 return IntSize(LayoutUnit::max(), LayoutUnit::max());
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000163}
164
darin@apple.com8cdf7122013-09-30 02:40:50 +0000165inline ElementRareData::ElementRareData(RenderElement* renderer)
rniwa@webkit.orgfdb7fa22013-01-16 07:36:55 +0000166 : NodeRareData(renderer)
167 , m_tabIndex(0)
rniwa@webkit.org2015feb2013-01-14 23:57:39 +0000168 , m_childIndex(0)
169 , m_tabIndexWasSetExplicitly(false)
170 , m_needsFocusAppearanceUpdateSoonAfterAttach(false)
171 , m_styleAffectedByEmpty(false)
172 , m_isInCanvasSubtree(false)
173#if ENABLE(FULLSCREEN_API)
174 , m_containsFullScreenElement(false)
175#endif
rniwa@webkit.org2015feb2013-01-14 23:57:39 +0000176 , m_hasPendingResources(false)
rniwa@webkit.org2015feb2013-01-14 23:57:39 +0000177 , m_childrenAffectedByHover(false)
178 , m_childrenAffectedByActive(false)
179 , m_childrenAffectedByDrag(false)
rniwa@webkit.org2015feb2013-01-14 23:57:39 +0000180 , m_childrenAffectedByLastChildRules(false)
rniwa@webkit.org2015feb2013-01-14 23:57:39 +0000181 , m_childrenAffectedByForwardPositionalRules(false)
182 , m_childrenAffectedByBackwardPositionalRules(false)
commit-queue@webkit.org75d76c42013-06-20 16:13:11 +0000183 , m_regionOversetState(RegionUndefined)
rniwa@webkit.org2015feb2013-01-14 23:57:39 +0000184 , m_minimumSizeForResizing(defaultMinimumSizeForResizing())
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000185{
186}
187
morrita@google.comd75075c2011-01-20 01:24:40 +0000188inline ElementRareData::~ElementRareData()
189{
antti@apple.com64d69392013-08-15 16:52:40 +0000190 ASSERT(!m_shadowRoot);
antti@apple.com9426a742013-08-24 11:09:26 +0000191 ASSERT(!m_beforePseudoElement);
192 ASSERT(!m_afterPseudoElement);
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +0000193}
194
antti@apple.com9426a742013-08-24 11:09:26 +0000195inline void ElementRareData::setBeforePseudoElement(PassRefPtr<PseudoElement> pseudoElement)
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +0000196{
antti@apple.com9426a742013-08-24 11:09:26 +0000197 ASSERT(!m_beforePseudoElement || !pseudoElement);
198 m_beforePseudoElement = pseudoElement;
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +0000199}
200
antti@apple.com9426a742013-08-24 11:09:26 +0000201inline void ElementRareData::setAfterPseudoElement(PassRefPtr<PseudoElement> pseudoElement)
commit-queue@webkit.orgfb6d2262012-12-05 21:00:54 +0000202{
antti@apple.com9426a742013-08-24 11:09:26 +0000203 ASSERT(!m_afterPseudoElement || !pseudoElement);
204 m_afterPseudoElement = pseudoElement;
morrita@google.comd75075c2011-01-20 01:24:40 +0000205}
206
darin@apple.comfaced262009-01-12 07:44:27 +0000207inline void ElementRareData::resetComputedStyle()
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000208{
akling@apple.com5bbaebd2013-10-23 10:42:20 +0000209 m_computedStyle = nullptr;
allan.jensen@digia.com44ec64e2012-11-28 13:09:40 +0000210 setStyleAffectedByEmpty(false);
211 setChildIndex(0);
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000212}
213
allan.jensen@digia.com44ec64e2012-11-28 13:09:40 +0000214inline void ElementRareData::resetDynamicRestyleObservations()
215{
allan.jensen@digia.com44ec64e2012-11-28 13:09:40 +0000216 setChildrenAffectedByActive(false);
217 setChildrenAffectedByDrag(false);
allan.jensen@digia.com44ec64e2012-11-28 13:09:40 +0000218 setChildrenAffectedByLastChildRules(false);
allan.jensen@digia.com44ec64e2012-11-28 13:09:40 +0000219 setChildrenAffectedByForwardPositionalRules(false);
220 setChildrenAffectedByBackwardPositionalRules(false);
dsmith@webkit.orgbee65b52008-09-26 02:36:38 +0000221}
allan.jensen@digia.com44ec64e2012-11-28 13:09:40 +0000222
223} // namespace
224
alp@webkit.org2122a042008-10-03 12:38:12 +0000225#endif // ElementRareData_h