darin@apple.com | faced26 | 2009-01-12 07:44:27 +0000 | [diff] [blame] | 1 | /* |
darin@apple.com | f5247d1 | 2010-06-13 17:29:10 +0000 | [diff] [blame] | 2 | * Copyright (C) 2008, 2009, 2010 Apple Inc. All rights reserved. |
dsmith@webkit.org | bee65b5 | 2008-09-26 02:36:38 +0000 | [diff] [blame] | 3 | * 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.org | 691d04f | 2010-10-29 09:32:14 +0000 | [diff] [blame] | 25 | #include "ClassList.h" |
weinig@apple.com | 96a2cf9 | 2010-06-30 23:15:15 +0000 | [diff] [blame] | 26 | #include "DatasetDOMStringMap.h" |
morrita@google.com | 948bd53 | 2012-05-07 06:05:42 +0000 | [diff] [blame] | 27 | #include "ElementShadow.h" |
caio.oliveira@openbossa.org | 26b85d3 | 2012-03-08 17:42:28 +0000 | [diff] [blame] | 28 | #include "NamedNodeMap.h" |
dsmith@webkit.org | bee65b5 | 2008-09-26 02:36:38 +0000 | [diff] [blame] | 29 | #include "NodeRareData.h" |
commit-queue@webkit.org | fb6d226 | 2012-12-05 21:00:54 +0000 | [diff] [blame] | 30 | #include "PseudoElement.h" |
commit-queue@webkit.org | d0c076d | 2012-08-22 22:25:59 +0000 | [diff] [blame] | 31 | #include "StyleInheritedData.h" |
weinig@apple.com | 96a2cf9 | 2010-06-30 23:15:15 +0000 | [diff] [blame] | 32 | #include <wtf/OwnPtr.h> |
dsmith@webkit.org | bee65b5 | 2008-09-26 02:36:38 +0000 | [diff] [blame] | 33 | |
| 34 | namespace WebCore { |
alp@webkit.org | 2122a04 | 2008-10-03 12:38:12 +0000 | [diff] [blame] | 35 | |
dsmith@webkit.org | bee65b5 | 2008-09-26 02:36:38 +0000 | [diff] [blame] | 36 | class ElementRareData : public NodeRareData { |
| 37 | public: |
rniwa@webkit.org | fdb7fa2 | 2013-01-16 07:36:55 +0000 | [diff] [blame] | 38 | static PassOwnPtr<ElementRareData> create(RenderObject* renderer) { return adoptPtr(new ElementRareData(renderer)); } |
| 39 | |
rniwa@webkit.org | c311c02 | 2013-01-16 05:23:04 +0000 | [diff] [blame] | 40 | ~ElementRareData(); |
darin@apple.com | 929b907 | 2008-12-13 22:53:55 +0000 | [diff] [blame] | 41 | |
commit-queue@webkit.org | fb6d226 | 2012-12-05 21:00:54 +0000 | [diff] [blame] | 42 | void setPseudoElement(PseudoId, PassRefPtr<PseudoElement>); |
| 43 | PseudoElement* pseudoElement(PseudoId) const; |
morrita@google.com | 98dfec2 | 2012-12-14 06:50:52 +0000 | [diff] [blame] | 44 | bool hasPseudoElements() const { return m_generatedBefore || m_generatedAfter; } |
commit-queue@webkit.org | fb6d226 | 2012-12-05 21:00:54 +0000 | [diff] [blame] | 45 | |
darin@apple.com | faced26 | 2009-01-12 07:44:27 +0000 | [diff] [blame] | 46 | void resetComputedStyle(); |
allan.jensen@digia.com | 44ec64e | 2012-11-28 13:09:40 +0000 | [diff] [blame] | 47 | void resetDynamicRestyleObservations(); |
rniwa@webkit.org | 2015feb | 2013-01-14 23:57:39 +0000 | [diff] [blame] | 48 | |
| 49 | short tabIndex() const { return m_tabIndex; } |
| 50 | void setTabIndexExplicitly(short index) { m_tabIndex = index; m_tabIndexWasSetExplicitly = true; } |
| 51 | bool tabIndexSetExplicitly() const { return m_tabIndexWasSetExplicitly; } |
| 52 | void clearTabIndexExplicitly() { m_tabIndex = 0; m_tabIndexWasSetExplicitly = false; } |
alp@webkit.org | 2122a04 | 2008-10-03 12:38:12 +0000 | [diff] [blame] | 53 | |
commit-queue@webkit.org | 63be935 | 2012-12-05 20:43:40 +0000 | [diff] [blame] | 54 | bool needsFocusAppearanceUpdateSoonAfterAttach() const { return m_needsFocusAppearanceUpdateSoonAfterAttach; } |
| 55 | void setNeedsFocusAppearanceUpdateSoonAfterAttach(bool needs) { m_needsFocusAppearanceUpdateSoonAfterAttach = needs; } |
| 56 | |
| 57 | bool styleAffectedByEmpty() const { return m_styleAffectedByEmpty; } |
| 58 | void setStyleAffectedByEmpty(bool value) { m_styleAffectedByEmpty = value; } |
| 59 | |
| 60 | bool isInCanvasSubtree() const { return m_isInCanvasSubtree; } |
| 61 | void setIsInCanvasSubtree(bool value) { m_isInCanvasSubtree = value; } |
| 62 | |
kling@webkit.org | c7b06df | 2012-10-03 12:55:24 +0000 | [diff] [blame] | 63 | #if ENABLE(FULLSCREEN_API) |
commit-queue@webkit.org | 63be935 | 2012-12-05 20:43:40 +0000 | [diff] [blame] | 64 | bool containsFullScreenElement() { return m_containsFullScreenElement; } |
| 65 | void setContainsFullScreenElement(bool value) { m_containsFullScreenElement = value; } |
kling@webkit.org | c7b06df | 2012-10-03 12:55:24 +0000 | [diff] [blame] | 66 | #endif |
commit-queue@webkit.org | 63be935 | 2012-12-05 20:43:40 +0000 | [diff] [blame] | 67 | |
commit-queue@webkit.org | 8040314 | 2013-01-23 18:25:06 +0000 | [diff] [blame] | 68 | #if ENABLE(DIALOG_ELEMENT) |
| 69 | bool isInTopLayer() const { return m_isInTopLayer; } |
| 70 | void setIsInTopLayer(bool value) { m_isInTopLayer = value; } |
| 71 | #endif |
| 72 | |
commit-queue@webkit.org | 63be935 | 2012-12-05 20:43:40 +0000 | [diff] [blame] | 73 | bool childrenAffectedByHover() const { return m_childrenAffectedByHover; } |
| 74 | void setChildrenAffectedByHover(bool value) { m_childrenAffectedByHover = value; } |
| 75 | bool childrenAffectedByActive() const { return m_childrenAffectedByActive; } |
| 76 | void setChildrenAffectedByActive(bool value) { m_childrenAffectedByActive = value; } |
| 77 | bool childrenAffectedByDrag() const { return m_childrenAffectedByDrag; } |
| 78 | void setChildrenAffectedByDrag(bool value) { m_childrenAffectedByDrag = value; } |
| 79 | |
| 80 | bool childrenAffectedByFirstChildRules() const { return m_childrenAffectedByFirstChildRules; } |
| 81 | void setChildrenAffectedByFirstChildRules(bool value) { m_childrenAffectedByFirstChildRules = value; } |
| 82 | bool childrenAffectedByLastChildRules() const { return m_childrenAffectedByLastChildRules; } |
| 83 | void setChildrenAffectedByLastChildRules(bool value) { m_childrenAffectedByLastChildRules = value; } |
| 84 | bool childrenAffectedByDirectAdjacentRules() const { return m_childrenAffectedByDirectAdjacentRules; } |
| 85 | void setChildrenAffectedByDirectAdjacentRules(bool value) { m_childrenAffectedByDirectAdjacentRules = value; } |
| 86 | bool childrenAffectedByForwardPositionalRules() const { return m_childrenAffectedByForwardPositionalRules; } |
| 87 | void setChildrenAffectedByForwardPositionalRules(bool value) { m_childrenAffectedByForwardPositionalRules = value; } |
| 88 | bool childrenAffectedByBackwardPositionalRules() const { return m_childrenAffectedByBackwardPositionalRules; } |
| 89 | void setChildrenAffectedByBackwardPositionalRules(bool value) { m_childrenAffectedByBackwardPositionalRules = value; } |
| 90 | unsigned childIndex() const { return m_childIndex; } |
| 91 | void setChildIndex(unsigned index) { m_childIndex = index; } |
darin@apple.com | 929b907 | 2008-12-13 22:53:55 +0000 | [diff] [blame] | 92 | |
rniwa@webkit.org | c311c02 | 2013-01-16 05:23:04 +0000 | [diff] [blame] | 93 | // Manually called by Node::reportMemoryUsage. |
| 94 | void reportMemoryUsage(MemoryObjectInfo*) const; |
loislo@chromium.org | edc2201 | 2012-11-02 09:11:19 +0000 | [diff] [blame] | 95 | |
esprehn@chromium.org | c5b4522 | 2013-01-29 18:22:03 +0000 | [diff] [blame] | 96 | void clearShadow() { m_shadow = nullptr; } |
commit-queue@webkit.org | 63be935 | 2012-12-05 20:43:40 +0000 | [diff] [blame] | 97 | ElementShadow* shadow() const { return m_shadow.get(); } |
esprehn@chromium.org | c5b4522 | 2013-01-29 18:22:03 +0000 | [diff] [blame] | 98 | ElementShadow* ensureShadow() |
| 99 | { |
| 100 | if (!m_shadow) |
| 101 | m_shadow = ElementShadow::create(); |
| 102 | return m_shadow.get(); |
| 103 | } |
commit-queue@webkit.org | 63be935 | 2012-12-05 20:43:40 +0000 | [diff] [blame] | 104 | |
| 105 | NamedNodeMap* attributeMap() const { return m_attributeMap.get(); } |
| 106 | void setAttributeMap(PassOwnPtr<NamedNodeMap> attributeMap) { m_attributeMap = attributeMap; } |
| 107 | |
| 108 | RenderStyle* computedStyle() const { return m_computedStyle.get(); } |
| 109 | void setComputedStyle(PassRefPtr<RenderStyle> computedStyle) { m_computedStyle = computedStyle; } |
| 110 | |
| 111 | ClassList* classList() const { return m_classList.get(); } |
| 112 | void setClassList(PassOwnPtr<ClassList> classList) { m_classList = classList; } |
esprehn@chromium.org | fbc22e5 | 2013-01-03 02:59:32 +0000 | [diff] [blame] | 113 | void clearClassListValueForQuirksMode() |
| 114 | { |
| 115 | if (!m_classList) |
| 116 | return; |
| 117 | m_classList->clearValueForQuirksMode(); |
| 118 | } |
commit-queue@webkit.org | 63be935 | 2012-12-05 20:43:40 +0000 | [diff] [blame] | 119 | |
| 120 | DatasetDOMStringMap* dataset() const { return m_dataset.get(); } |
| 121 | void setDataset(PassOwnPtr<DatasetDOMStringMap> dataset) { m_dataset = dataset; } |
| 122 | |
| 123 | LayoutSize minimumSizeForResizing() const { return m_minimumSizeForResizing; } |
| 124 | void setMinimumSizeForResizing(LayoutSize size) { m_minimumSizeForResizing = size; } |
| 125 | |
| 126 | IntSize savedLayerScrollOffset() const { return m_savedLayerScrollOffset; } |
| 127 | void setSavedLayerScrollOffset(IntSize size) { m_savedLayerScrollOffset = size; } |
| 128 | |
senorblanco@chromium.org | 7b6792b | 2013-01-04 19:48:10 +0000 | [diff] [blame] | 129 | #if ENABLE(SVG) |
| 130 | bool hasPendingResources() const { return m_hasPendingResources; } |
| 131 | void setHasPendingResources(bool has) { m_hasPendingResources = has; } |
| 132 | #endif |
| 133 | |
commit-queue@webkit.org | 63be935 | 2012-12-05 20:43:40 +0000 | [diff] [blame] | 134 | private: |
rniwa@webkit.org | 2015feb | 2013-01-14 23:57:39 +0000 | [diff] [blame] | 135 | short m_tabIndex; |
| 136 | unsigned short m_childIndex; |
| 137 | unsigned m_tabIndexWasSetExplicitly : 1; |
| 138 | unsigned m_needsFocusAppearanceUpdateSoonAfterAttach : 1; |
| 139 | unsigned m_styleAffectedByEmpty : 1; |
| 140 | unsigned m_isInCanvasSubtree : 1; |
| 141 | #if ENABLE(FULLSCREEN_API) |
| 142 | unsigned m_containsFullScreenElement : 1; |
| 143 | #endif |
commit-queue@webkit.org | 8040314 | 2013-01-23 18:25:06 +0000 | [diff] [blame] | 144 | #if ENABLE(DIALOG_ELEMENT) |
| 145 | unsigned m_isInTopLayer : 1; |
| 146 | #endif |
rniwa@webkit.org | 2015feb | 2013-01-14 23:57:39 +0000 | [diff] [blame] | 147 | #if ENABLE(SVG) |
| 148 | unsigned m_hasPendingResources : 1; |
| 149 | #endif |
| 150 | unsigned m_childrenAffectedByHover : 1; |
| 151 | unsigned m_childrenAffectedByActive : 1; |
| 152 | unsigned m_childrenAffectedByDrag : 1; |
| 153 | // Bits for dynamic child matching. |
| 154 | // We optimize for :first-child and :last-child. The other positional child selectors like nth-child or |
| 155 | // *-child-of-type, we will just give up and re-evaluate whenever children change at all. |
| 156 | unsigned m_childrenAffectedByFirstChildRules : 1; |
| 157 | unsigned m_childrenAffectedByLastChildRules : 1; |
| 158 | unsigned m_childrenAffectedByDirectAdjacentRules : 1; |
| 159 | unsigned m_childrenAffectedByForwardPositionalRules : 1; |
| 160 | unsigned m_childrenAffectedByBackwardPositionalRules : 1; |
rniwa@webkit.org | 2015feb | 2013-01-14 23:57:39 +0000 | [diff] [blame] | 161 | |
eae@chromium.org | 5b93f41 | 2011-08-15 23:51:21 +0000 | [diff] [blame] | 162 | LayoutSize m_minimumSizeForResizing; |
rniwa@webkit.org | c311c02 | 2013-01-16 05:23:04 +0000 | [diff] [blame] | 163 | IntSize m_savedLayerScrollOffset; |
hyatt@apple.com | dec0cbf2 | 2008-10-17 00:25:33 +0000 | [diff] [blame] | 164 | RefPtr<RenderStyle> m_computedStyle; |
weinig@apple.com | 96a2cf9 | 2010-06-30 23:15:15 +0000 | [diff] [blame] | 165 | |
commit-queue@webkit.org | 63be935 | 2012-12-05 20:43:40 +0000 | [diff] [blame] | 166 | OwnPtr<DatasetDOMStringMap> m_dataset; |
commit-queue@webkit.org | 691d04f | 2010-10-29 09:32:14 +0000 | [diff] [blame] | 167 | OwnPtr<ClassList> m_classList; |
morrita@google.com | 948bd53 | 2012-05-07 06:05:42 +0000 | [diff] [blame] | 168 | OwnPtr<ElementShadow> m_shadow; |
caio.oliveira@openbossa.org | 26b85d3 | 2012-03-08 17:42:28 +0000 | [diff] [blame] | 169 | OwnPtr<NamedNodeMap> m_attributeMap; |
jer.noble@apple.com | 366ebb0 | 2011-05-30 02:05:30 +0000 | [diff] [blame] | 170 | |
commit-queue@webkit.org | fb6d226 | 2012-12-05 21:00:54 +0000 | [diff] [blame] | 171 | RefPtr<PseudoElement> m_generatedBefore; |
| 172 | RefPtr<PseudoElement> m_generatedAfter; |
| 173 | |
rniwa@webkit.org | fdb7fa2 | 2013-01-16 07:36:55 +0000 | [diff] [blame] | 174 | ElementRareData(RenderObject*); |
commit-queue@webkit.org | fb6d226 | 2012-12-05 21:00:54 +0000 | [diff] [blame] | 175 | void releasePseudoElement(PseudoElement*); |
dsmith@webkit.org | bee65b5 | 2008-09-26 02:36:38 +0000 | [diff] [blame] | 176 | }; |
| 177 | |
| 178 | inline IntSize defaultMinimumSizeForResizing() |
| 179 | { |
eae@chromium.org | 9717cd8 | 2012-11-07 18:33:44 +0000 | [diff] [blame] | 180 | return IntSize(LayoutUnit::max(), LayoutUnit::max()); |
dsmith@webkit.org | bee65b5 | 2008-09-26 02:36:38 +0000 | [diff] [blame] | 181 | } |
| 182 | |
rniwa@webkit.org | fdb7fa2 | 2013-01-16 07:36:55 +0000 | [diff] [blame] | 183 | inline ElementRareData::ElementRareData(RenderObject* renderer) |
| 184 | : NodeRareData(renderer) |
| 185 | , m_tabIndex(0) |
rniwa@webkit.org | 2015feb | 2013-01-14 23:57:39 +0000 | [diff] [blame] | 186 | , m_childIndex(0) |
| 187 | , m_tabIndexWasSetExplicitly(false) |
| 188 | , m_needsFocusAppearanceUpdateSoonAfterAttach(false) |
| 189 | , m_styleAffectedByEmpty(false) |
| 190 | , m_isInCanvasSubtree(false) |
| 191 | #if ENABLE(FULLSCREEN_API) |
| 192 | , m_containsFullScreenElement(false) |
| 193 | #endif |
commit-queue@webkit.org | 8040314 | 2013-01-23 18:25:06 +0000 | [diff] [blame] | 194 | #if ENABLE(DIALOG_ELEMENT) |
| 195 | , m_isInTopLayer(false) |
| 196 | #endif |
rniwa@webkit.org | 2015feb | 2013-01-14 23:57:39 +0000 | [diff] [blame] | 197 | #if ENABLE(SVG) |
| 198 | , m_hasPendingResources(false) |
| 199 | #endif |
| 200 | , m_childrenAffectedByHover(false) |
| 201 | , m_childrenAffectedByActive(false) |
| 202 | , m_childrenAffectedByDrag(false) |
| 203 | , m_childrenAffectedByFirstChildRules(false) |
| 204 | , m_childrenAffectedByLastChildRules(false) |
| 205 | , m_childrenAffectedByDirectAdjacentRules(false) |
| 206 | , m_childrenAffectedByForwardPositionalRules(false) |
| 207 | , m_childrenAffectedByBackwardPositionalRules(false) |
rniwa@webkit.org | 2015feb | 2013-01-14 23:57:39 +0000 | [diff] [blame] | 208 | , m_minimumSizeForResizing(defaultMinimumSizeForResizing()) |
dsmith@webkit.org | bee65b5 | 2008-09-26 02:36:38 +0000 | [diff] [blame] | 209 | { |
| 210 | } |
| 211 | |
morrita@google.com | d75075c | 2011-01-20 01:24:40 +0000 | [diff] [blame] | 212 | inline ElementRareData::~ElementRareData() |
| 213 | { |
morrita@google.com | 948bd53 | 2012-05-07 06:05:42 +0000 | [diff] [blame] | 214 | ASSERT(!m_shadow); |
commit-queue@webkit.org | fb6d226 | 2012-12-05 21:00:54 +0000 | [diff] [blame] | 215 | ASSERT(!m_generatedBefore); |
| 216 | ASSERT(!m_generatedAfter); |
| 217 | } |
| 218 | |
| 219 | inline void ElementRareData::setPseudoElement(PseudoId pseudoId, PassRefPtr<PseudoElement> element) |
| 220 | { |
| 221 | switch (pseudoId) { |
| 222 | case BEFORE: |
| 223 | releasePseudoElement(m_generatedBefore.get()); |
| 224 | m_generatedBefore = element; |
| 225 | break; |
| 226 | case AFTER: |
| 227 | releasePseudoElement(m_generatedAfter.get()); |
| 228 | m_generatedAfter = element; |
| 229 | break; |
| 230 | default: |
| 231 | ASSERT_NOT_REACHED(); |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | inline PseudoElement* ElementRareData::pseudoElement(PseudoId pseudoId) const |
| 236 | { |
| 237 | switch (pseudoId) { |
| 238 | case BEFORE: |
| 239 | return m_generatedBefore.get(); |
| 240 | case AFTER: |
| 241 | return m_generatedAfter.get(); |
| 242 | default: |
commit-queue@webkit.org | fb6d226 | 2012-12-05 21:00:54 +0000 | [diff] [blame] | 243 | return 0; |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | inline void ElementRareData::releasePseudoElement(PseudoElement* element) |
| 248 | { |
| 249 | if (!element) |
| 250 | return; |
| 251 | |
| 252 | if (element->attached()) |
| 253 | element->detach(); |
| 254 | |
| 255 | ASSERT(!element->nextSibling()); |
| 256 | ASSERT(!element->previousSibling()); |
| 257 | |
commit-queue@webkit.org | 632b532 | 2013-02-01 03:17:19 +0000 | [diff] [blame] | 258 | element->setParentOrShadowHostNode(0); |
morrita@google.com | d75075c | 2011-01-20 01:24:40 +0000 | [diff] [blame] | 259 | } |
| 260 | |
darin@apple.com | faced26 | 2009-01-12 07:44:27 +0000 | [diff] [blame] | 261 | inline void ElementRareData::resetComputedStyle() |
dsmith@webkit.org | bee65b5 | 2008-09-26 02:36:38 +0000 | [diff] [blame] | 262 | { |
commit-queue@webkit.org | 63be935 | 2012-12-05 20:43:40 +0000 | [diff] [blame] | 263 | setComputedStyle(0); |
allan.jensen@digia.com | 44ec64e | 2012-11-28 13:09:40 +0000 | [diff] [blame] | 264 | setStyleAffectedByEmpty(false); |
| 265 | setChildIndex(0); |
dsmith@webkit.org | bee65b5 | 2008-09-26 02:36:38 +0000 | [diff] [blame] | 266 | } |
| 267 | |
allan.jensen@digia.com | 44ec64e | 2012-11-28 13:09:40 +0000 | [diff] [blame] | 268 | inline void ElementRareData::resetDynamicRestyleObservations() |
| 269 | { |
| 270 | setChildrenAffectedByHover(false); |
| 271 | setChildrenAffectedByActive(false); |
| 272 | setChildrenAffectedByDrag(false); |
| 273 | setChildrenAffectedByFirstChildRules(false); |
| 274 | setChildrenAffectedByLastChildRules(false); |
| 275 | setChildrenAffectedByDirectAdjacentRules(false); |
| 276 | setChildrenAffectedByForwardPositionalRules(false); |
| 277 | setChildrenAffectedByBackwardPositionalRules(false); |
dsmith@webkit.org | bee65b5 | 2008-09-26 02:36:38 +0000 | [diff] [blame] | 278 | } |
allan.jensen@digia.com | 44ec64e | 2012-11-28 13:09:40 +0000 | [diff] [blame] | 279 | |
| 280 | } // namespace |
| 281 | |
alp@webkit.org | 2122a04 | 2008-10-03 12:38:12 +0000 | [diff] [blame] | 282 | #endif // ElementRareData_h |