2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Peter Kelly (pmk@post.com)
5 * (C) 2001 Dirk Mueller (mueller@kde.org)
6 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2013 Apple Inc. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
28 #include "Attribute.h"
29 #include "CollectionType.h"
31 #include "FragmentScriptingPermission.h"
32 #include "HTMLNames.h"
33 #include "ScrollTypes.h"
34 #include "SpaceSplitString.h"
44 class ElementRareData;
46 class ShareableElementData;
49 class UniqueElementData;
53 class StylePropertySet;
55 class ElementData : public RefCounted<ElementData> {
56 WTF_MAKE_FAST_ALLOCATED;
58 // Override RefCounted's deref() to ensure operator delete is called on
59 // the appropriate subclass type.
62 void clearClass() const { m_classNames.clear(); }
63 void setClass(const AtomicString& className, bool shouldFoldCase) const { m_classNames.set(className, shouldFoldCase); }
64 const SpaceSplitString& classNames() const { return m_classNames; }
66 const AtomicString& idForStyleResolution() const { return m_idForStyleResolution; }
67 void setIdForStyleResolution(const AtomicString& newId) const { m_idForStyleResolution = newId; }
69 const StylePropertySet* inlineStyle() const { return m_inlineStyle.get(); }
71 const StylePropertySet* presentationAttributeStyle() const;
73 size_t length() const;
74 bool isEmpty() const { return !length(); }
76 const Attribute* attributeItem(unsigned index) const;
77 const Attribute* getAttributeItem(const QualifiedName&) const;
78 size_t getAttributeItemIndex(const QualifiedName&) const;
79 size_t getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
81 bool hasID() const { return !m_idForStyleResolution.isNull(); }
82 bool hasClass() const { return !m_classNames.isNull(); }
84 bool isEquivalent(const ElementData* other) const;
86 void reportMemoryUsage(MemoryObjectInfo*) const;
88 bool isUnique() const { return m_isUnique; }
92 ElementData(unsigned arraySize);
93 ElementData(const ElementData&, bool isUnique);
95 unsigned m_isUnique : 1;
96 unsigned m_arraySize : 28;
97 mutable unsigned m_presentationAttributeStyleIsDirty : 1;
98 mutable unsigned m_styleAttributeIsDirty : 1;
100 mutable unsigned m_animatedSVGAttributesAreDirty : 1;
103 mutable RefPtr<StylePropertySet> m_inlineStyle;
104 mutable SpaceSplitString m_classNames;
105 mutable AtomicString m_idForStyleResolution;
108 friend class Element;
109 friend class StyledElement;
110 friend class ShareableElementData;
111 friend class UniqueElementData;
113 friend class SVGElement;
116 const Attribute* getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
117 size_t getAttributeItemIndexSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
119 PassRefPtr<UniqueElementData> makeUniqueCopy() const;
123 #pragma warning(push)
124 #pragma warning(disable: 4200) // Disable "zero-sized array in struct/union" warning
127 class ShareableElementData : public ElementData {
129 static PassRefPtr<ShareableElementData> createWithAttributes(const Vector<Attribute>&);
131 explicit ShareableElementData(const Vector<Attribute>&);
132 explicit ShareableElementData(const UniqueElementData&);
133 ~ShareableElementData();
135 Attribute m_attributeArray[0];
142 class UniqueElementData : public ElementData {
144 static PassRefPtr<UniqueElementData> create();
145 PassRefPtr<ShareableElementData> makeShareableCopy() const;
147 // These functions do no error/duplicate checking.
148 void addAttribute(const QualifiedName&, const AtomicString&);
149 void removeAttribute(size_t index);
151 Attribute* attributeItem(unsigned index);
152 Attribute* getAttributeItem(const QualifiedName&);
155 explicit UniqueElementData(const ShareableElementData&);
156 explicit UniqueElementData(const UniqueElementData&);
158 mutable RefPtr<StylePropertySet> m_presentationAttributeStyle;
159 Vector<Attribute, 4> m_attributeVector;
162 enum AffectedSelectorType {
163 AffectedSelectorChecked = 1,
164 AffectedSelectorEnabled = 1 << 1,
165 AffectedSelectorDisabled = 1 << 2,
166 AffectedSelectorIndeterminate = 1 << 3,
167 AffectedSelectorLink = 1 << 4,
168 AffectedSelectorTarget = 1 << 5,
169 AffectedSelectorVisited = 1 << 6
171 typedef int AffectedSelectorMask;
173 enum SpellcheckAttributeState {
174 SpellcheckAttributeTrue,
175 SpellcheckAttributeFalse,
176 SpellcheckAttributeDefault
179 class Element : public ContainerNode {
181 static PassRefPtr<Element> create(const QualifiedName&, Document*);
184 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
185 DEFINE_ATTRIBUTE_EVENT_LISTENER(change);
186 DEFINE_ATTRIBUTE_EVENT_LISTENER(click);
187 DEFINE_ATTRIBUTE_EVENT_LISTENER(contextmenu);
188 DEFINE_ATTRIBUTE_EVENT_LISTENER(dblclick);
189 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragenter);
190 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragover);
191 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragleave);
192 DEFINE_ATTRIBUTE_EVENT_LISTENER(drop);
193 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragstart);
194 DEFINE_ATTRIBUTE_EVENT_LISTENER(drag);
195 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragend);
196 DEFINE_ATTRIBUTE_EVENT_LISTENER(input);
197 DEFINE_ATTRIBUTE_EVENT_LISTENER(invalid);
198 DEFINE_ATTRIBUTE_EVENT_LISTENER(keydown);
199 DEFINE_ATTRIBUTE_EVENT_LISTENER(keypress);
200 DEFINE_ATTRIBUTE_EVENT_LISTENER(keyup);
201 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousedown);
202 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousemove);
203 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseout);
204 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseover);
205 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseup);
206 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousewheel);
207 DEFINE_ATTRIBUTE_EVENT_LISTENER(scroll);
208 DEFINE_ATTRIBUTE_EVENT_LISTENER(select);
209 DEFINE_ATTRIBUTE_EVENT_LISTENER(submit);
211 // These four attribute event handler attributes are overridden by HTMLBodyElement
212 // and HTMLFrameSetElement to forward to the DOMWindow.
213 DECLARE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(blur);
214 DECLARE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(error);
215 DECLARE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(focus);
216 DECLARE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(load);
219 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecut);
220 DEFINE_ATTRIBUTE_EVENT_LISTENER(cut);
221 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecopy);
222 DEFINE_ATTRIBUTE_EVENT_LISTENER(copy);
223 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforepaste);
224 DEFINE_ATTRIBUTE_EVENT_LISTENER(paste);
225 DEFINE_ATTRIBUTE_EVENT_LISTENER(reset);
226 DEFINE_ATTRIBUTE_EVENT_LISTENER(search);
227 DEFINE_ATTRIBUTE_EVENT_LISTENER(selectstart);
228 #if ENABLE(TOUCH_EVENTS)
229 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchstart);
230 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchmove);
231 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchend);
232 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchcancel);
234 #if ENABLE(FULLSCREEN_API)
235 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenchange);
236 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenerror);
239 bool hasAttribute(const QualifiedName&) const;
240 const AtomicString& getAttribute(const QualifiedName&) const;
241 void setAttribute(const QualifiedName&, const AtomicString& value);
242 void setSynchronizedLazyAttribute(const QualifiedName&, const AtomicString& value);
243 void removeAttribute(const QualifiedName&);
245 // Typed getters and setters for language bindings.
246 int getIntegralAttribute(const QualifiedName& attributeName) const;
247 void setIntegralAttribute(const QualifiedName& attributeName, int value);
248 unsigned getUnsignedIntegralAttribute(const QualifiedName& attributeName) const;
249 void setUnsignedIntegralAttribute(const QualifiedName& attributeName, unsigned value);
251 // Call this to get the value of an attribute that is known not to be the style
252 // attribute or one of the SVG animatable attributes.
253 bool fastHasAttribute(const QualifiedName&) const;
254 const AtomicString& fastGetAttribute(const QualifiedName&) const;
256 bool fastAttributeLookupAllowed(const QualifiedName&) const;
259 #ifdef DUMP_NODE_STATISTICS
260 bool hasNamedNodeMap() const;
262 bool hasAttributes() const;
263 // This variant will not update the potentially invalid attributes. To be used when not interested
264 // in style attribute or one of the SVG animation attributes.
265 bool hasAttributesWithoutUpdate() const;
267 bool hasAttribute(const AtomicString& name) const;
268 bool hasAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const;
270 const AtomicString& getAttribute(const AtomicString& name) const;
271 const AtomicString& getAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const;
273 void setAttribute(const AtomicString& name, const AtomicString& value, ExceptionCode&);
274 static bool parseAttributeName(QualifiedName&, const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionCode&);
275 void setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionCode&);
277 bool isIdAttributeName(const QualifiedName&) const;
278 const AtomicString& getIdAttribute() const;
279 void setIdAttribute(const AtomicString&);
281 const AtomicString& getNameAttribute() const;
283 // Call this to get the value of the id attribute for style resolution purposes.
284 // The value will already be lowercased if the document is in compatibility mode,
285 // so this function is not suitable for non-style uses.
286 const AtomicString& idForStyleResolution() const;
288 // Internal methods that assume the existence of attribute storage, one should use hasAttributes()
289 // before calling them.
290 size_t attributeCount() const;
291 const Attribute* attributeItem(unsigned index) const;
292 const Attribute* getAttributeItem(const QualifiedName&) const;
293 size_t getAttributeItemIndex(const QualifiedName& name) const { return elementData()->getAttributeItemIndex(name); }
294 size_t getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const { return elementData()->getAttributeItemIndex(name, shouldIgnoreAttributeCase); }
296 void scrollIntoView(bool alignToTop = true);
297 void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
299 void scrollByLines(int lines);
300 void scrollByPages(int pages);
306 Element* offsetParent();
311 virtual int scrollLeft();
312 virtual int scrollTop();
313 virtual void setScrollLeft(int);
314 virtual void setScrollTop(int);
315 virtual int scrollWidth();
316 virtual int scrollHeight();
318 IntRect boundsInRootViewSpace();
320 PassRefPtr<ClientRectList> getClientRects();
321 PassRefPtr<ClientRect> getBoundingClientRect();
323 // Returns the absolute bounding box translated into screen coordinates:
324 IntRect screenRect() const;
326 void removeAttribute(const AtomicString& name);
327 void removeAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName);
329 PassRefPtr<Attr> detachAttribute(size_t index);
331 PassRefPtr<Attr> getAttributeNode(const AtomicString& name);
332 PassRefPtr<Attr> getAttributeNodeNS(const AtomicString& namespaceURI, const AtomicString& localName);
333 PassRefPtr<Attr> setAttributeNode(Attr*, ExceptionCode&);
334 PassRefPtr<Attr> setAttributeNodeNS(Attr*, ExceptionCode&);
335 PassRefPtr<Attr> removeAttributeNode(Attr*, ExceptionCode&);
337 PassRefPtr<Attr> attrIfExists(const QualifiedName&);
338 PassRefPtr<Attr> ensureAttr(const QualifiedName&);
340 const Vector<RefPtr<Attr> >& attrNodeList();
342 virtual CSSStyleDeclaration* style();
344 const QualifiedName& tagQName() const { return m_tagName; }
345 String tagName() const { return nodeName(); }
346 bool hasTagName(const QualifiedName& tagName) const { return m_tagName.matches(tagName); }
348 // A fast function for checking the local name against another atomic string.
349 bool hasLocalName(const AtomicString& other) const { return m_tagName.localName() == other; }
350 bool hasLocalName(const QualifiedName& other) const { return m_tagName.localName() == other.localName(); }
352 const AtomicString& localName() const { return m_tagName.localName(); }
353 const AtomicString& prefix() const { return m_tagName.prefix(); }
354 const AtomicString& namespaceURI() const { return m_tagName.namespaceURI(); }
356 virtual KURL baseURI() const;
358 virtual String nodeName() const;
360 PassRefPtr<Element> cloneElementWithChildren();
361 PassRefPtr<Element> cloneElementWithoutChildren();
363 void normalizeAttributes();
364 String nodeNamePreservingCase() const;
366 void setBooleanAttribute(const QualifiedName& name, bool);
368 // For exposing to DOM only.
369 NamedNodeMap* attributes() const;
371 // This method is called whenever an attribute is added, changed or removed.
372 virtual void attributeChanged(const QualifiedName&, const AtomicString&);
373 virtual void parseAttribute(const QualifiedName&, const AtomicString&) { }
375 // Only called by the parser immediately after element construction.
376 void parserSetAttributes(const Vector<Attribute>&, FragmentScriptingPermission);
378 const ElementData* elementData() const { return m_elementData.get(); }
379 const ElementData* elementDataWithSynchronizedAttributes() const;
380 const ElementData* ensureElementDataWithSynchronizedAttributes() const;
381 UniqueElementData* ensureUniqueElementData();
383 // Clones attributes only.
384 void cloneAttributesFromElement(const Element&);
386 // Clones all attribute-derived data, including subclass specifics (through copyNonAttributeProperties.)
387 void cloneDataFromElement(const Element&);
389 bool hasEquivalentAttributes(const Element* other) const;
391 virtual void copyNonAttributePropertiesFromElement(const Element&) { }
393 virtual void attach();
394 virtual void detach();
395 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
396 virtual bool rendererIsNeeded(const NodeRenderingContext&);
397 void recalcStyle(StyleChange = NoChange);
398 void didAffectSelector(AffectedSelectorMask);
400 ElementShadow* shadow() const;
401 ElementShadow* ensureShadow();
402 PassRefPtr<ShadowRoot> createShadowRoot(ExceptionCode&);
403 ShadowRoot* shadowRoot() const;
405 bool hasAuthorShadowRoot() const { return shadowRoot(); }
406 virtual void willAddAuthorShadowRoot() { }
408 ShadowRoot* userAgentShadowRoot() const;
409 ShadowRoot* ensureUserAgentShadowRoot();
411 virtual const AtomicString& shadowPseudoId() const;
413 RenderStyle* computedStyle(PseudoId = NOPSEUDO);
415 // Methods for indicating the style is affected by dynamic updates (e.g., children changing, our position changing in our sibling list, etc.)
416 bool styleAffectedByEmpty() const { return hasRareData() && rareDataStyleAffectedByEmpty(); }
417 bool childrenAffectedByHover() const { return hasRareData() && rareDataChildrenAffectedByHover(); }
418 bool childrenAffectedByActive() const { return hasRareData() && rareDataChildrenAffectedByActive(); }
419 bool childrenAffectedByDrag() const { return hasRareData() && rareDataChildrenAffectedByDrag(); }
420 bool childrenAffectedByPositionalRules() const { return hasRareData() && (rareDataChildrenAffectedByForwardPositionalRules() || rareDataChildrenAffectedByBackwardPositionalRules()); }
421 bool childrenAffectedByFirstChildRules() const { return hasRareData() && rareDataChildrenAffectedByFirstChildRules(); }
422 bool childrenAffectedByLastChildRules() const { return hasRareData() && rareDataChildrenAffectedByLastChildRules(); }
423 bool childrenAffectedByDirectAdjacentRules() const { return hasRareData() && rareDataChildrenAffectedByDirectAdjacentRules(); }
424 bool childrenAffectedByForwardPositionalRules() const { return hasRareData() && rareDataChildrenAffectedByForwardPositionalRules(); }
425 bool childrenAffectedByBackwardPositionalRules() const { return hasRareData() && rareDataChildrenAffectedByBackwardPositionalRules(); }
426 unsigned childIndex() const { return hasRareData() ? rareDataChildIndex() : 0; }
428 bool hasFlagsSetDuringStylingOfChildren() const;
430 void setStyleAffectedByEmpty();
431 void setChildrenAffectedByHover(bool);
432 void setChildrenAffectedByActive(bool);
433 void setChildrenAffectedByDrag(bool);
434 void setChildrenAffectedByFirstChildRules();
435 void setChildrenAffectedByLastChildRules();
436 void setChildrenAffectedByDirectAdjacentRules();
437 void setChildrenAffectedByForwardPositionalRules();
438 void setChildrenAffectedByBackwardPositionalRules();
439 void setChildIndex(unsigned);
441 void setIsInCanvasSubtree(bool);
442 bool isInCanvasSubtree() const;
444 AtomicString computeInheritedLanguage() const;
445 Locale& locale() const;
447 virtual void accessKeyAction(bool /*sendToAnyEvent*/) { }
449 virtual bool isURLAttribute(const Attribute&) const { return false; }
451 KURL getURLAttribute(const QualifiedName&) const;
452 KURL getNonEmptyURLAttribute(const QualifiedName&) const;
454 virtual const QualifiedName& imageSourceAttributeName() const;
455 virtual String target() const { return String(); }
457 virtual void focus(bool restorePreviousSelection = true, FocusDirection = FocusDirectionNone);
458 virtual void updateFocusAppearance(bool restorePreviousSelection);
464 virtual String title() const;
466 const AtomicString& pseudo() const;
467 void setPseudo(const AtomicString&);
469 void updateId(const AtomicString& oldId, const AtomicString& newId);
470 void updateId(TreeScope*, const AtomicString& oldId, const AtomicString& newId);
471 void updateName(const AtomicString& oldName, const AtomicString& newName);
472 void updateLabel(TreeScope*, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue);
474 void removeCachedHTMLCollection(HTMLCollection*, CollectionType);
476 LayoutSize minimumSizeForResizing() const;
477 void setMinimumSizeForResizing(const LayoutSize&);
479 // Use Document::registerForDocumentActivationCallbacks() to subscribe to these
480 virtual void documentWillSuspendForPageCache() { }
481 virtual void documentDidResumeFromPageCache() { }
483 // Use Document::registerForMediaVolumeCallbacks() to subscribe to this
484 virtual void mediaVolumeDidChange() { }
486 // Use Document::registerForPrivateBrowsingStateChangedCallbacks() to subscribe to this.
487 virtual void privateBrowsingStateDidChange() { }
489 virtual void didBecomeFullscreenElement() { }
490 virtual void willStopBeingFullscreenElement() { }
492 bool isFinishedParsingChildren() const { return isParsingChildrenFinished(); }
493 virtual void finishParsingChildren();
494 virtual void beginParsingChildren();
496 bool hasPseudoElements() const;
497 PseudoElement* pseudoElement(PseudoId) const;
498 RenderObject* pseudoElementRenderer(PseudoId) const;
499 bool childNeedsShadowWalker() const;
500 void didShadowTreeAwareChildrenChange();
502 // ElementTraversal API
503 Element* firstElementChild() const;
504 Element* lastElementChild() const;
505 Element* previousElementSibling() const;
506 Element* nextElementSibling() const;
507 unsigned childElementCount() const;
509 virtual bool matchesReadOnlyPseudoClass() const;
510 virtual bool matchesReadWritePseudoClass() const;
511 bool webkitMatchesSelector(const String& selectors, ExceptionCode&);
513 DOMTokenList* classList();
515 DOMStringMap* dataset();
518 virtual bool isMathMLElement() const { return false; }
520 static bool isMathMLElement() { return false; }
524 virtual bool isMediaElement() const { return false; }
527 #if ENABLE(INPUT_SPEECH)
528 virtual bool isInputFieldSpeechButtonElement() const { return false; }
530 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
531 virtual bool isDateTimeFieldElement() const;
534 virtual bool isFormControlElement() const { return false; }
535 virtual bool isEnabledFormControl() const { return true; }
536 virtual bool isSpinButtonElement() const { return false; }
537 virtual bool isTextFormControl() const { return false; }
538 virtual bool isOptionalFormControl() const { return false; }
539 virtual bool isRequiredFormControl() const { return false; }
540 virtual bool isDefaultButtonForForm() const { return false; }
541 virtual bool willValidate() const { return false; }
542 virtual bool isValidFormControlElement() { return false; }
543 virtual bool isInRange() const { return false; }
544 virtual bool isOutOfRange() const { return false; }
545 virtual bool isFrameElementBase() const { return false; }
546 virtual bool isTextFieldDecoration() const { return false; }
548 virtual bool canContainRangeEndPoint() const { return true; }
550 virtual const AtomicString& formControlType() const { return nullAtom; }
552 virtual bool wasChangedSinceLastFormControlChangeEvent() const;
553 virtual void setChangedSinceLastFormControlChangeEvent(bool);
554 virtual void dispatchFormControlChangeEvent() { }
557 virtual bool childShouldCreateRenderer(const NodeRenderingContext&) const;
558 bool hasPendingResources() const;
559 void setHasPendingResources();
560 void clearHasPendingResources();
561 virtual void buildPendingResource() { };
564 #if ENABLE(FULLSCREEN_API)
566 ALLOW_KEYBOARD_INPUT = 1 << 0,
567 LEGACY_MOZILLA_REQUEST = 1 << 1,
570 void webkitRequestFullScreen(unsigned short flags);
571 virtual bool containsFullScreenElement() const;
572 virtual void setContainsFullScreenElement(bool);
573 virtual void setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(bool);
576 void webkitRequestFullscreen();
579 #if ENABLE(DIALOG_ELEMENT)
580 bool isInTopLayer() const;
581 void setIsInTopLayer(bool);
584 #if ENABLE(POINTER_LOCK)
585 void webkitRequestPointerLock();
588 virtual bool isSpellCheckingEnabled() const;
590 PassRefPtr<RenderStyle> styleForRenderer();
592 RenderRegion* renderRegion() const;
593 #if ENABLE(CSS_REGIONS)
594 const AtomicString& webkitRegionOverset() const;
595 Vector<RefPtr<Range> > webkitGetRegionFlowRanges() const;
599 bool hasClass() const;
600 const SpaceSplitString& classNames() const;
602 IntSize savedLayerScrollOffset() const;
603 void setSavedLayerScrollOffset(const IntSize&);
605 virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
608 Element(const QualifiedName& tagName, Document* document, ConstructionType type)
609 : ContainerNode(document, type)
614 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
615 virtual void removedFrom(ContainerNode*) OVERRIDE;
616 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
618 virtual bool willRecalcStyle(StyleChange);
619 virtual void didRecalcStyle(StyleChange);
620 virtual PassRefPtr<RenderStyle> customStyleForRenderer();
622 virtual bool shouldRegisterAsNamedItem() const { return false; }
623 virtual bool shouldRegisterAsExtraNamedItem() const { return false; }
625 void clearTabIndexExplicitlyIfNeeded();
626 void setTabIndexExplicitly(short);
627 virtual bool supportsFocus() const OVERRIDE;
628 virtual short tabIndex() const OVERRIDE;
630 PassRefPtr<HTMLCollection> ensureCachedHTMLCollection(CollectionType);
631 HTMLCollection* cachedHTMLCollection(CollectionType);
633 // classAttributeChanged() exists to share code between
634 // parseAttribute (called via setAttribute()) and
635 // svgAttributeChanged (called when element.className.baseValue is set)
636 void classAttributeChanged(const AtomicString& newClassString);
639 void updatePseudoElement(PseudoId, StyleChange = NoChange);
640 PassRefPtr<PseudoElement> createPseudoElementIfNeeded(PseudoId);
641 void setPseudoElement(PseudoId, PassRefPtr<PseudoElement>);
643 virtual bool areAuthorShadowsAllowed() const { return true; }
644 virtual void didAddUserAgentShadowRoot(ShadowRoot*) { }
645 virtual bool alwaysCreateUserAgentShadowRoot() const { return false; }
647 // FIXME: Remove the need for Attr to call willModifyAttribute/didModifyAttribute.
650 enum SynchronizationOfLazyAttribute { NotInSynchronizationOfLazyAttribute = 0, InSynchronizationOfLazyAttribute };
652 void didAddAttribute(const QualifiedName&, const AtomicString&);
653 void willModifyAttribute(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue);
654 void didModifyAttribute(const QualifiedName&, const AtomicString&);
655 void didRemoveAttribute(const QualifiedName&);
657 void updateInvalidAttributes() const;
659 void scrollByUnits(int units, ScrollGranularity);
661 virtual void setPrefix(const AtomicString&, ExceptionCode&);
662 virtual NodeType nodeType() const;
663 virtual bool childTypeAllowed(NodeType) const;
665 void setAttributeInternal(size_t index, const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
666 void addAttributeInternal(const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
667 void removeAttributeInternal(size_t index, SynchronizationOfLazyAttribute);
670 virtual void formatForDebugger(char* buffer, unsigned length) const;
673 bool pseudoStyleCacheIsInvalid(const RenderStyle* currentStyle, RenderStyle* newStyle);
675 virtual void updateStyleAttribute() const { }
678 virtual void updateAnimatedSVGAttribute(const QualifiedName&) const { }
681 void cancelFocusAppearanceUpdate();
683 virtual const AtomicString& virtualPrefix() const { return prefix(); }
684 virtual const AtomicString& virtualLocalName() const { return localName(); }
685 virtual const AtomicString& virtualNamespaceURI() const { return namespaceURI(); }
686 virtual RenderStyle* virtualComputedStyle(PseudoId pseudoElementSpecifier = NOPSEUDO) { return computedStyle(pseudoElementSpecifier); }
688 // cloneNode is private so that non-virtual cloneElementWithChildren and cloneElementWithoutChildren
690 virtual PassRefPtr<Node> cloneNode(bool deep) OVERRIDE;
691 virtual PassRefPtr<Element> cloneElementWithoutAttributesAndChildren();
693 QualifiedName m_tagName;
694 bool rareDataStyleAffectedByEmpty() const;
695 bool rareDataChildrenAffectedByHover() const;
696 bool rareDataChildrenAffectedByActive() const;
697 bool rareDataChildrenAffectedByDrag() const;
698 bool rareDataChildrenAffectedByFirstChildRules() const;
699 bool rareDataChildrenAffectedByLastChildRules() const;
700 bool rareDataChildrenAffectedByDirectAdjacentRules() const;
701 bool rareDataChildrenAffectedByForwardPositionalRules() const;
702 bool rareDataChildrenAffectedByBackwardPositionalRules() const;
703 unsigned rareDataChildIndex() const;
705 SpellcheckAttributeState spellcheckAttributeState() const;
707 void updateNamedItemRegistration(const AtomicString& oldName, const AtomicString& newName);
708 void updateExtraNamedItemRegistration(const AtomicString& oldName, const AtomicString& newName);
710 void unregisterNamedFlowContentNode();
712 void createUniqueElementData();
714 bool shouldInvalidateDistributionWhenAttributeChanged(ElementShadow*, const QualifiedName&, const AtomicString&);
716 ElementRareData* elementRareData() const;
717 ElementRareData* ensureElementRareData();
719 void detachAllAttrNodesFromElement();
720 void detachAttrNodeFromElementWithValue(Attr*, const AtomicString& value);
722 void createRendererIfNeeded();
724 RefPtr<ElementData> m_elementData;
727 inline Element* toElement(Node* node)
729 ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isElementNode());
730 return static_cast<Element*>(node);
733 inline const Element* toElement(const Node* node)
735 ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isElementNode());
736 return static_cast<const Element*>(node);
739 // This will catch anyone doing an unnecessary cast.
740 void toElement(const Element*);
742 inline bool Node::hasTagName(const QualifiedName& name) const
744 return isElementNode() && toElement(this)->hasTagName(name);
747 inline bool Node::hasLocalName(const AtomicString& name) const
749 return isElementNode() && toElement(this)->hasLocalName(name);
752 inline bool Node::hasAttributes() const
754 return isElementNode() && toElement(this)->hasAttributes();
757 inline NamedNodeMap* Node::attributes() const
759 return isElementNode() ? toElement(this)->attributes() : 0;
762 inline Element* Node::parentElement() const
764 ContainerNode* parent = parentNode();
765 return parent && parent->isElementNode() ? toElement(parent) : 0;
768 inline Element* Element::previousElementSibling() const
770 Node* n = previousSibling();
771 while (n && !n->isElementNode())
772 n = n->previousSibling();
773 return static_cast<Element*>(n);
776 inline Element* Element::nextElementSibling() const
778 Node* n = nextSibling();
779 while (n && !n->isElementNode())
780 n = n->nextSibling();
781 return static_cast<Element*>(n);
784 inline const ElementData* Element::elementDataWithSynchronizedAttributes() const
786 updateInvalidAttributes();
787 return elementData();
790 inline const ElementData* Element::ensureElementDataWithSynchronizedAttributes() const
792 updateInvalidAttributes();
794 return elementData();
795 return const_cast<Element*>(this)->ensureUniqueElementData();
798 inline void Element::updateName(const AtomicString& oldName, const AtomicString& newName)
800 if (!inDocument() || isInShadowTree())
803 if (oldName == newName)
806 if (shouldRegisterAsNamedItem())
807 updateNamedItemRegistration(oldName, newName);
810 inline void Element::updateId(const AtomicString& oldId, const AtomicString& newId)
812 if (!isInTreeScope())
818 updateId(treeScope(), oldId, newId);
821 inline void Element::updateId(TreeScope* scope, const AtomicString& oldId, const AtomicString& newId)
823 ASSERT(isInTreeScope());
824 ASSERT(oldId != newId);
826 if (!oldId.isEmpty())
827 scope->removeElementById(oldId, this);
828 if (!newId.isEmpty())
829 scope->addElementById(newId, this);
831 if (shouldRegisterAsExtraNamedItem())
832 updateExtraNamedItemRegistration(oldId, newId);
835 inline bool Element::fastHasAttribute(const QualifiedName& name) const
837 ASSERT(fastAttributeLookupAllowed(name));
838 return elementData() && getAttributeItem(name);
841 inline const AtomicString& Element::fastGetAttribute(const QualifiedName& name) const
843 ASSERT(fastAttributeLookupAllowed(name));
845 if (const Attribute* attribute = getAttributeItem(name))
846 return attribute->value();
851 inline bool Element::hasAttributesWithoutUpdate() const
853 return elementData() && !elementData()->isEmpty();
856 inline const AtomicString& Element::idForStyleResolution() const
859 return elementData()->idForStyleResolution();
862 inline bool Element::isIdAttributeName(const QualifiedName& attributeName) const
864 // FIXME: This check is probably not correct for the case where the document has an id attribute
865 // with a non-null namespace, because it will return false, a false negative, if the prefixes
866 // don't match but the local name and namespace both do. However, since this has been like this
867 // for a while and the code paths may be hot, we'll have to measure performance if we fix it.
868 return attributeName == document()->idAttributeName();
871 inline const AtomicString& Element::getIdAttribute() const
873 return hasID() ? fastGetAttribute(document()->idAttributeName()) : nullAtom;
876 inline const AtomicString& Element::getNameAttribute() const
878 return hasName() ? fastGetAttribute(HTMLNames::nameAttr) : nullAtom;
881 inline void Element::setIdAttribute(const AtomicString& value)
883 setAttribute(document()->idAttributeName(), value);
886 inline const SpaceSplitString& Element::classNames() const
889 ASSERT(elementData());
890 return elementData()->classNames();
893 inline size_t Element::attributeCount() const
895 ASSERT(elementData());
896 return elementData()->length();
899 inline const Attribute* Element::attributeItem(unsigned index) const
901 ASSERT(elementData());
902 return elementData()->attributeItem(index);
905 inline const Attribute* Element::getAttributeItem(const QualifiedName& name) const
907 ASSERT(elementData());
908 return elementData()->getAttributeItem(name);
911 inline void Element::updateInvalidAttributes() const
916 if (elementData()->m_styleAttributeIsDirty)
917 updateStyleAttribute();
920 if (elementData()->m_animatedSVGAttributesAreDirty)
921 updateAnimatedSVGAttribute(anyQName());
925 inline bool Element::hasID() const
927 return elementData() && elementData()->hasID();
930 inline bool Element::hasClass() const
932 return elementData() && elementData()->hasClass();
935 inline UniqueElementData* Element::ensureUniqueElementData()
937 if (!elementData() || !elementData()->isUnique())
938 createUniqueElementData();
939 return static_cast<UniqueElementData*>(m_elementData.get());
942 // Put here to make them inline.
943 inline bool Node::hasID() const
945 return isElementNode() && toElement(this)->hasID();
948 inline bool Node::hasClass() const
950 return isElementNode() && toElement(this)->hasClass();
953 inline Node::InsertionNotificationRequest Node::insertedInto(ContainerNode* insertionPoint)
955 ASSERT(insertionPoint->inDocument() || isContainerNode());
956 if (insertionPoint->inDocument())
957 setFlag(InDocumentFlag);
958 if (parentOrShadowHostNode()->isInShadowTree())
959 setFlag(IsInShadowTreeFlag);
960 return InsertionDone;
963 inline void Node::removedFrom(ContainerNode* insertionPoint)
965 ASSERT(insertionPoint->inDocument() || isContainerNode());
966 if (insertionPoint->inDocument())
967 clearFlag(InDocumentFlag);
968 if (isInShadowTree() && !treeScope()->rootNode()->isShadowRoot())
969 clearFlag(IsInShadowTreeFlag);
972 inline bool isShadowHost(const Node* node)
974 return node && node->isElementNode() && toElement(node)->shadow();
977 inline size_t ElementData::length() const
980 return static_cast<const UniqueElementData*>(this)->m_attributeVector.size();
984 inline const StylePropertySet* ElementData::presentationAttributeStyle() const
988 return static_cast<const UniqueElementData*>(this)->m_presentationAttributeStyle.get();
991 inline const Attribute* ElementData::getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase) const
993 size_t index = getAttributeItemIndex(name, shouldIgnoreAttributeCase);
994 if (index != notFound)
995 return attributeItem(index);
999 inline size_t ElementData::getAttributeItemIndex(const QualifiedName& name) const
1001 for (unsigned i = 0; i < length(); ++i) {
1002 if (attributeItem(i)->name().matches(name))
1008 // We use a boolean parameter instead of calling shouldIgnoreAttributeCase so that the caller
1009 // can tune the behavior (hasAttribute is case sensitive whereas getAttribute is not).
1010 inline size_t ElementData::getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const
1012 unsigned len = length();
1013 bool doSlowCheck = shouldIgnoreAttributeCase;
1015 // Optimize for the case where the attribute exists and its name exactly matches.
1016 for (unsigned i = 0; i < len; ++i) {
1017 const Attribute* attribute = attributeItem(i);
1018 if (!attribute->name().hasPrefix()) {
1019 if (name == attribute->localName())
1026 return getAttributeItemIndexSlowCase(name, shouldIgnoreAttributeCase);
1030 inline const Attribute* ElementData::getAttributeItem(const QualifiedName& name) const
1032 for (unsigned i = 0; i < length(); ++i) {
1033 if (attributeItem(i)->name().matches(name))
1034 return attributeItem(i);
1039 inline const Attribute* ElementData::attributeItem(unsigned index) const
1041 ASSERT_WITH_SECURITY_IMPLICATION(index < length());
1043 return &static_cast<const UniqueElementData*>(this)->m_attributeVector.at(index);
1044 return &static_cast<const ShareableElementData*>(this)->m_attributeArray[index];