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);
307 // FIXME: Replace uses of offsetParent in the platform with calls
308 // to the render layer and merge bindingsOffsetParent and offsetParent.
309 Element* bindingsOffsetParent();
311 Element* offsetParent();
316 virtual int scrollLeft();
317 virtual int scrollTop();
318 virtual void setScrollLeft(int);
319 virtual void setScrollTop(int);
320 virtual int scrollWidth();
321 virtual int scrollHeight();
323 IntRect boundsInRootViewSpace();
325 PassRefPtr<ClientRectList> getClientRects();
326 PassRefPtr<ClientRect> getBoundingClientRect();
328 // Returns the absolute bounding box translated into screen coordinates:
329 IntRect screenRect() const;
331 void removeAttribute(const AtomicString& name);
332 void removeAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName);
334 PassRefPtr<Attr> detachAttribute(size_t index);
336 PassRefPtr<Attr> getAttributeNode(const AtomicString& name);
337 PassRefPtr<Attr> getAttributeNodeNS(const AtomicString& namespaceURI, const AtomicString& localName);
338 PassRefPtr<Attr> setAttributeNode(Attr*, ExceptionCode&);
339 PassRefPtr<Attr> setAttributeNodeNS(Attr*, ExceptionCode&);
340 PassRefPtr<Attr> removeAttributeNode(Attr*, ExceptionCode&);
342 PassRefPtr<Attr> attrIfExists(const QualifiedName&);
343 PassRefPtr<Attr> ensureAttr(const QualifiedName&);
345 const Vector<RefPtr<Attr> >& attrNodeList();
347 virtual CSSStyleDeclaration* style();
349 const QualifiedName& tagQName() const { return m_tagName; }
350 String tagName() const { return nodeName(); }
351 bool hasTagName(const QualifiedName& tagName) const { return m_tagName.matches(tagName); }
353 // A fast function for checking the local name against another atomic string.
354 bool hasLocalName(const AtomicString& other) const { return m_tagName.localName() == other; }
355 bool hasLocalName(const QualifiedName& other) const { return m_tagName.localName() == other.localName(); }
357 const AtomicString& localName() const { return m_tagName.localName(); }
358 const AtomicString& prefix() const { return m_tagName.prefix(); }
359 const AtomicString& namespaceURI() const { return m_tagName.namespaceURI(); }
361 virtual KURL baseURI() const;
363 virtual String nodeName() const;
365 PassRefPtr<Element> cloneElementWithChildren();
366 PassRefPtr<Element> cloneElementWithoutChildren();
368 void normalizeAttributes();
369 String nodeNamePreservingCase() const;
371 void setBooleanAttribute(const QualifiedName& name, bool);
373 // For exposing to DOM only.
374 NamedNodeMap* attributes() const;
376 enum AttributeModificationReason {
381 // This method is called whenever an attribute is added, changed or removed.
382 virtual void attributeChanged(const QualifiedName&, const AtomicString&, AttributeModificationReason = ModifiedDirectly);
383 virtual void parseAttribute(const QualifiedName&, const AtomicString&) { }
385 // Only called by the parser immediately after element construction.
386 void parserSetAttributes(const Vector<Attribute>&);
388 // Remove attributes that might introduce scripting from the vector leaving the element unchanged.
389 void stripScriptingAttributes(Vector<Attribute>&) const;
391 const ElementData* elementData() const { return m_elementData.get(); }
392 UniqueElementData* ensureUniqueElementData();
394 void synchronizeAllAttributes() const;
396 // Clones attributes only.
397 void cloneAttributesFromElement(const Element&);
399 // Clones all attribute-derived data, including subclass specifics (through copyNonAttributeProperties.)
400 void cloneDataFromElement(const Element&);
402 bool hasEquivalentAttributes(const Element* other) const;
404 virtual void copyNonAttributePropertiesFromElement(const Element&) { }
406 virtual void attach();
407 virtual void detach();
408 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
409 virtual bool rendererIsNeeded(const NodeRenderingContext&);
410 void recalcStyle(StyleChange = NoChange);
411 void didAffectSelector(AffectedSelectorMask);
413 ElementShadow* shadow() const;
414 ElementShadow* ensureShadow();
415 PassRefPtr<ShadowRoot> createShadowRoot(ExceptionCode&);
416 ShadowRoot* shadowRoot() const;
418 bool hasAuthorShadowRoot() const { return shadowRoot(); }
419 virtual void willAddAuthorShadowRoot() { }
421 ShadowRoot* userAgentShadowRoot() const;
422 ShadowRoot* ensureUserAgentShadowRoot();
424 virtual const AtomicString& shadowPseudoId() const;
426 RenderStyle* computedStyle(PseudoId = NOPSEUDO);
428 // Methods for indicating the style is affected by dynamic updates (e.g., children changing, our position changing in our sibling list, etc.)
429 bool styleAffectedByEmpty() const { return hasRareData() && rareDataStyleAffectedByEmpty(); }
430 bool childrenAffectedByHover() const { return hasRareData() && rareDataChildrenAffectedByHover(); }
431 bool childrenAffectedByActive() const { return hasRareData() && rareDataChildrenAffectedByActive(); }
432 bool childrenAffectedByDrag() const { return hasRareData() && rareDataChildrenAffectedByDrag(); }
433 bool childrenAffectedByPositionalRules() const { return hasRareData() && (rareDataChildrenAffectedByForwardPositionalRules() || rareDataChildrenAffectedByBackwardPositionalRules()); }
434 bool childrenAffectedByFirstChildRules() const { return hasRareData() && rareDataChildrenAffectedByFirstChildRules(); }
435 bool childrenAffectedByLastChildRules() const { return hasRareData() && rareDataChildrenAffectedByLastChildRules(); }
436 bool childrenAffectedByDirectAdjacentRules() const { return hasRareData() && rareDataChildrenAffectedByDirectAdjacentRules(); }
437 bool childrenAffectedByForwardPositionalRules() const { return hasRareData() && rareDataChildrenAffectedByForwardPositionalRules(); }
438 bool childrenAffectedByBackwardPositionalRules() const { return hasRareData() && rareDataChildrenAffectedByBackwardPositionalRules(); }
439 unsigned childIndex() const { return hasRareData() ? rareDataChildIndex() : 0; }
441 bool hasFlagsSetDuringStylingOfChildren() const;
443 void setStyleAffectedByEmpty();
444 void setChildrenAffectedByHover(bool);
445 void setChildrenAffectedByActive(bool);
446 void setChildrenAffectedByDrag(bool);
447 void setChildrenAffectedByFirstChildRules();
448 void setChildrenAffectedByLastChildRules();
449 void setChildrenAffectedByDirectAdjacentRules();
450 void setChildrenAffectedByForwardPositionalRules();
451 void setChildrenAffectedByBackwardPositionalRules();
452 void setChildIndex(unsigned);
454 void setIsInCanvasSubtree(bool);
455 bool isInCanvasSubtree() const;
457 AtomicString computeInheritedLanguage() const;
458 Locale& locale() const;
460 virtual void accessKeyAction(bool /*sendToAnyEvent*/) { }
462 virtual bool isURLAttribute(const Attribute&) const { return false; }
463 virtual bool isHTMLContentAttribute(const Attribute&) const { return false; }
465 KURL getURLAttribute(const QualifiedName&) const;
466 KURL getNonEmptyURLAttribute(const QualifiedName&) const;
468 virtual const AtomicString& imageSourceURL() const;
469 virtual String target() const { return String(); }
471 virtual void focus(bool restorePreviousSelection = true, FocusDirection = FocusDirectionNone);
472 virtual void updateFocusAppearance(bool restorePreviousSelection);
478 virtual String title() const;
480 const AtomicString& pseudo() const;
481 void setPseudo(const AtomicString&);
483 LayoutSize minimumSizeForResizing() const;
484 void setMinimumSizeForResizing(const LayoutSize&);
486 // Use Document::registerForDocumentActivationCallbacks() to subscribe to these
487 virtual void documentWillSuspendForPageCache() { }
488 virtual void documentDidResumeFromPageCache() { }
490 // Use Document::registerForMediaVolumeCallbacks() to subscribe to this
491 virtual void mediaVolumeDidChange() { }
493 // Use Document::registerForPrivateBrowsingStateChangedCallbacks() to subscribe to this.
494 virtual void privateBrowsingStateDidChange() { }
496 virtual void didBecomeFullscreenElement() { }
497 virtual void willStopBeingFullscreenElement() { }
499 #if ENABLE(VIDEO_TRACK)
500 virtual void captionPreferencesChanged() { }
503 bool isFinishedParsingChildren() const { return isParsingChildrenFinished(); }
504 virtual void finishParsingChildren();
505 virtual void beginParsingChildren();
507 bool hasPseudoElements() const;
508 PseudoElement* pseudoElement(PseudoId) const;
509 RenderObject* pseudoElementRenderer(PseudoId) const;
510 bool childNeedsShadowWalker() const;
511 void didShadowTreeAwareChildrenChange();
513 // ElementTraversal API
514 Element* firstElementChild() const;
515 Element* lastElementChild() const;
516 Element* previousElementSibling() const;
517 Element* nextElementSibling() const;
518 unsigned childElementCount() const;
520 virtual bool matchesReadOnlyPseudoClass() const;
521 virtual bool matchesReadWritePseudoClass() const;
522 bool webkitMatchesSelector(const String& selectors, ExceptionCode&);
523 virtual bool shouldAppearIndeterminate() const;
525 DOMTokenList* classList();
527 DOMStringMap* dataset();
530 virtual bool isMathMLElement() const { return false; }
532 static bool isMathMLElement() { return false; }
536 virtual bool isMediaElement() const { return false; }
539 #if ENABLE(INPUT_SPEECH)
540 virtual bool isInputFieldSpeechButtonElement() const { return false; }
542 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
543 virtual bool isDateTimeFieldElement() const;
546 virtual bool isFormControlElement() const { return false; }
547 virtual bool isSpinButtonElement() const { return false; }
548 virtual bool isTextFormControl() const { return false; }
549 virtual bool isOptionalFormControl() const { return false; }
550 virtual bool isRequiredFormControl() const { return false; }
551 virtual bool isDefaultButtonForForm() const { return false; }
552 virtual bool willValidate() const { return false; }
553 virtual bool isValidFormControlElement() { return false; }
554 virtual bool isInRange() const { return false; }
555 virtual bool isOutOfRange() const { return false; }
556 virtual bool isFrameElementBase() const { return false; }
557 virtual bool isTextFieldDecoration() const { return false; }
559 virtual bool canContainRangeEndPoint() const { return true; }
561 virtual const AtomicString& formControlType() const { return nullAtom; }
563 virtual bool wasChangedSinceLastFormControlChangeEvent() const;
564 virtual void setChangedSinceLastFormControlChangeEvent(bool);
565 virtual void dispatchFormControlChangeEvent() { }
567 // Used for disabled form elements; if true, prevents mouse events from being dispatched
568 // to event listeners, and prevents DOMActivate events from being sent at all.
569 virtual bool isDisabledFormControl() const;
571 #if ENABLE(DIALOG_ELEMENT)
572 bool isInert() const;
576 virtual bool childShouldCreateRenderer(const NodeRenderingContext&) const;
577 bool hasPendingResources() const;
578 void setHasPendingResources();
579 void clearHasPendingResources();
580 virtual void buildPendingResource() { };
583 #if ENABLE(FULLSCREEN_API)
585 ALLOW_KEYBOARD_INPUT = 1 << 0,
586 LEGACY_MOZILLA_REQUEST = 1 << 1,
589 void webkitRequestFullScreen(unsigned short flags);
590 virtual bool containsFullScreenElement() const;
591 virtual void setContainsFullScreenElement(bool);
592 virtual void setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(bool);
595 void webkitRequestFullscreen();
598 #if ENABLE(DIALOG_ELEMENT)
599 bool isInTopLayer() const;
600 void setIsInTopLayer(bool);
603 #if ENABLE(POINTER_LOCK)
604 void webkitRequestPointerLock();
607 virtual bool isSpellCheckingEnabled() const;
609 PassRefPtr<RenderStyle> styleForRenderer();
611 RenderRegion* renderRegion() const;
612 virtual bool moveToFlowThreadIsNeeded(RefPtr<RenderStyle>& cachedStyle);
613 #if ENABLE(CSS_REGIONS)
614 const AtomicString& webkitRegionOverset() const;
615 Vector<RefPtr<Range> > webkitGetRegionFlowRanges() const;
619 bool hasClass() const;
620 const SpaceSplitString& classNames() const;
622 IntSize savedLayerScrollOffset() const;
623 void setSavedLayerScrollOffset(const IntSize&);
625 virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
628 Element(const QualifiedName& tagName, Document* document, ConstructionType type)
629 : ContainerNode(document, type)
634 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
635 virtual void removedFrom(ContainerNode*) OVERRIDE;
636 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
637 virtual void removeAllEventListeners() OVERRIDE;
639 virtual bool willRecalcStyle(StyleChange);
640 virtual void didRecalcStyle(StyleChange);
641 virtual PassRefPtr<RenderStyle> customStyleForRenderer();
643 virtual bool shouldRegisterAsNamedItem() const { return false; }
644 virtual bool shouldRegisterAsExtraNamedItem() const { return false; }
646 void clearTabIndexExplicitlyIfNeeded();
647 void setTabIndexExplicitly(short);
648 virtual bool supportsFocus() const OVERRIDE;
649 virtual short tabIndex() const OVERRIDE;
651 PassRefPtr<HTMLCollection> ensureCachedHTMLCollection(CollectionType);
652 HTMLCollection* cachedHTMLCollection(CollectionType);
654 // classAttributeChanged() exists to share code between
655 // parseAttribute (called via setAttribute()) and
656 // svgAttributeChanged (called when element.className.baseValue is set)
657 void classAttributeChanged(const AtomicString& newClassString);
660 void updatePseudoElement(PseudoId, StyleChange = NoChange);
661 PassRefPtr<PseudoElement> createPseudoElementIfNeeded(PseudoId);
662 void setPseudoElement(PseudoId, PassRefPtr<PseudoElement>);
664 virtual bool areAuthorShadowsAllowed() const { return true; }
665 virtual void didAddUserAgentShadowRoot(ShadowRoot*) { }
666 virtual bool alwaysCreateUserAgentShadowRoot() const { return false; }
668 // FIXME: Remove the need for Attr to call willModifyAttribute/didModifyAttribute.
671 enum SynchronizationOfLazyAttribute { NotInSynchronizationOfLazyAttribute = 0, InSynchronizationOfLazyAttribute };
673 void didAddAttribute(const QualifiedName&, const AtomicString&);
674 void willModifyAttribute(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue);
675 void didModifyAttribute(const QualifiedName&, const AtomicString&);
676 void didRemoveAttribute(const QualifiedName&);
678 void synchronizeAttribute(const QualifiedName&) const;
679 void synchronizeAttribute(const AtomicString& localName) const;
681 void updateId(const AtomicString& oldId, const AtomicString& newId);
682 void updateId(TreeScope*, const AtomicString& oldId, const AtomicString& newId);
683 void updateName(const AtomicString& oldName, const AtomicString& newName);
684 void updateLabel(TreeScope*, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue);
686 void scrollByUnits(int units, ScrollGranularity);
688 virtual void setPrefix(const AtomicString&, ExceptionCode&);
689 virtual NodeType nodeType() const;
690 virtual bool childTypeAllowed(NodeType) const;
692 void setAttributeInternal(size_t index, const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
693 void addAttributeInternal(const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
694 void removeAttributeInternal(size_t index, SynchronizationOfLazyAttribute);
695 void attributeChangedFromParserOrByCloning(const QualifiedName&, const AtomicString&, AttributeModificationReason);
698 virtual void formatForDebugger(char* buffer, unsigned length) const;
701 bool pseudoStyleCacheIsInvalid(const RenderStyle* currentStyle, RenderStyle* newStyle);
703 void cancelFocusAppearanceUpdate();
705 virtual const AtomicString& virtualPrefix() const { return prefix(); }
706 virtual const AtomicString& virtualLocalName() const { return localName(); }
707 virtual const AtomicString& virtualNamespaceURI() const { return namespaceURI(); }
708 virtual RenderStyle* virtualComputedStyle(PseudoId pseudoElementSpecifier = NOPSEUDO) { return computedStyle(pseudoElementSpecifier); }
710 // cloneNode is private so that non-virtual cloneElementWithChildren and cloneElementWithoutChildren
712 virtual PassRefPtr<Node> cloneNode(bool deep) OVERRIDE;
713 virtual PassRefPtr<Element> cloneElementWithoutAttributesAndChildren();
715 QualifiedName m_tagName;
716 bool rareDataStyleAffectedByEmpty() const;
717 bool rareDataChildrenAffectedByHover() const;
718 bool rareDataChildrenAffectedByActive() const;
719 bool rareDataChildrenAffectedByDrag() const;
720 bool rareDataChildrenAffectedByFirstChildRules() const;
721 bool rareDataChildrenAffectedByLastChildRules() const;
722 bool rareDataChildrenAffectedByDirectAdjacentRules() const;
723 bool rareDataChildrenAffectedByForwardPositionalRules() const;
724 bool rareDataChildrenAffectedByBackwardPositionalRules() const;
725 unsigned rareDataChildIndex() const;
727 SpellcheckAttributeState spellcheckAttributeState() const;
729 void updateNamedItemRegistration(const AtomicString& oldName, const AtomicString& newName);
730 void updateExtraNamedItemRegistration(const AtomicString& oldName, const AtomicString& newName);
732 void unregisterNamedFlowContentNode();
734 void createUniqueElementData();
736 bool shouldInvalidateDistributionWhenAttributeChanged(ElementShadow*, const QualifiedName&, const AtomicString&);
738 ElementRareData* elementRareData() const;
739 ElementRareData* ensureElementRareData();
741 void detachAllAttrNodesFromElement();
742 void detachAttrNodeFromElementWithValue(Attr*, const AtomicString& value);
744 void createRendererIfNeeded();
746 bool isJavaScriptURLAttribute(const Attribute&) const;
748 RefPtr<ElementData> m_elementData;
751 inline Element* toElement(Node* node)
753 ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isElementNode());
754 return static_cast<Element*>(node);
757 inline const Element* toElement(const Node* node)
759 ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isElementNode());
760 return static_cast<const Element*>(node);
763 // This will catch anyone doing an unnecessary cast.
764 void toElement(const Element*);
766 inline bool isDisabledFormControl(const Node* node)
768 return node->isElementNode() && toElement(node)->isDisabledFormControl();
771 inline bool Node::hasTagName(const QualifiedName& name) const
773 return isElementNode() && toElement(this)->hasTagName(name);
776 inline bool Node::hasLocalName(const AtomicString& name) const
778 return isElementNode() && toElement(this)->hasLocalName(name);
781 inline bool Node::hasAttributes() const
783 return isElementNode() && toElement(this)->hasAttributes();
786 inline NamedNodeMap* Node::attributes() const
788 return isElementNode() ? toElement(this)->attributes() : 0;
791 inline Element* Node::parentElement() const
793 ContainerNode* parent = parentNode();
794 return parent && parent->isElementNode() ? toElement(parent) : 0;
797 inline Element* Element::previousElementSibling() const
799 Node* n = previousSibling();
800 while (n && !n->isElementNode())
801 n = n->previousSibling();
802 return static_cast<Element*>(n);
805 inline Element* Element::nextElementSibling() const
807 Node* n = nextSibling();
808 while (n && !n->isElementNode())
809 n = n->nextSibling();
810 return static_cast<Element*>(n);
813 inline bool Element::fastHasAttribute(const QualifiedName& name) const
815 ASSERT(fastAttributeLookupAllowed(name));
816 return elementData() && getAttributeItem(name);
819 inline const AtomicString& Element::fastGetAttribute(const QualifiedName& name) const
821 ASSERT(fastAttributeLookupAllowed(name));
823 if (const Attribute* attribute = getAttributeItem(name))
824 return attribute->value();
829 inline bool Element::hasAttributesWithoutUpdate() const
831 return elementData() && !elementData()->isEmpty();
834 inline const AtomicString& Element::idForStyleResolution() const
837 return elementData()->idForStyleResolution();
840 inline bool Element::isIdAttributeName(const QualifiedName& attributeName) const
842 // FIXME: This check is probably not correct for the case where the document has an id attribute
843 // with a non-null namespace, because it will return false, a false negative, if the prefixes
844 // don't match but the local name and namespace both do. However, since this has been like this
845 // for a while and the code paths may be hot, we'll have to measure performance if we fix it.
846 return attributeName == document()->idAttributeName();
849 inline const AtomicString& Element::getIdAttribute() const
851 return hasID() ? fastGetAttribute(document()->idAttributeName()) : nullAtom;
854 inline const AtomicString& Element::getNameAttribute() const
856 return hasName() ? fastGetAttribute(HTMLNames::nameAttr) : nullAtom;
859 inline void Element::setIdAttribute(const AtomicString& value)
861 setAttribute(document()->idAttributeName(), value);
864 inline const SpaceSplitString& Element::classNames() const
867 ASSERT(elementData());
868 return elementData()->classNames();
871 inline size_t Element::attributeCount() const
873 ASSERT(elementData());
874 return elementData()->length();
877 inline const Attribute* Element::attributeItem(unsigned index) const
879 ASSERT(elementData());
880 return elementData()->attributeItem(index);
883 inline const Attribute* Element::getAttributeItem(const QualifiedName& name) const
885 ASSERT(elementData());
886 return elementData()->getAttributeItem(name);
889 inline bool Element::hasID() const
891 return elementData() && elementData()->hasID();
894 inline bool Element::hasClass() const
896 return elementData() && elementData()->hasClass();
899 inline UniqueElementData* Element::ensureUniqueElementData()
901 if (!elementData() || !elementData()->isUnique())
902 createUniqueElementData();
903 return static_cast<UniqueElementData*>(m_elementData.get());
906 // Put here to make them inline.
907 inline bool Node::hasID() const
909 return isElementNode() && toElement(this)->hasID();
912 inline bool Node::hasClass() const
914 return isElementNode() && toElement(this)->hasClass();
917 inline Node::InsertionNotificationRequest Node::insertedInto(ContainerNode* insertionPoint)
919 ASSERT(insertionPoint->inDocument() || isContainerNode());
920 if (insertionPoint->inDocument())
921 setFlag(InDocumentFlag);
922 if (parentOrShadowHostNode()->isInShadowTree())
923 setFlag(IsInShadowTreeFlag);
924 return InsertionDone;
927 inline void Node::removedFrom(ContainerNode* insertionPoint)
929 ASSERT(insertionPoint->inDocument() || isContainerNode());
930 if (insertionPoint->inDocument())
931 clearFlag(InDocumentFlag);
932 if (isInShadowTree() && !treeScope()->rootNode()->isShadowRoot())
933 clearFlag(IsInShadowTreeFlag);
936 inline bool isShadowHost(const Node* node)
938 return node && node->isElementNode() && toElement(node)->shadow();
941 inline size_t ElementData::length() const
944 return static_cast<const UniqueElementData*>(this)->m_attributeVector.size();
948 inline const StylePropertySet* ElementData::presentationAttributeStyle() const
952 return static_cast<const UniqueElementData*>(this)->m_presentationAttributeStyle.get();
955 inline const Attribute* ElementData::getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase) const
957 size_t index = getAttributeItemIndex(name, shouldIgnoreAttributeCase);
958 if (index != notFound)
959 return attributeItem(index);
963 inline size_t ElementData::getAttributeItemIndex(const QualifiedName& name) const
965 for (unsigned i = 0; i < length(); ++i) {
966 if (attributeItem(i)->name().matches(name))
972 // We use a boolean parameter instead of calling shouldIgnoreAttributeCase so that the caller
973 // can tune the behavior (hasAttribute is case sensitive whereas getAttribute is not).
974 inline size_t ElementData::getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const
976 unsigned len = length();
977 bool doSlowCheck = shouldIgnoreAttributeCase;
979 // Optimize for the case where the attribute exists and its name exactly matches.
980 for (unsigned i = 0; i < len; ++i) {
981 const Attribute* attribute = attributeItem(i);
982 if (!attribute->name().hasPrefix()) {
983 if (name == attribute->localName())
990 return getAttributeItemIndexSlowCase(name, shouldIgnoreAttributeCase);
994 inline const Attribute* ElementData::getAttributeItem(const QualifiedName& name) const
996 for (unsigned i = 0; i < length(); ++i) {
997 if (attributeItem(i)->name().matches(name))
998 return attributeItem(i);
1003 inline const Attribute* ElementData::attributeItem(unsigned index) const
1005 ASSERT_WITH_SECURITY_IMPLICATION(index < length());
1007 return &static_cast<const UniqueElementData*>(this)->m_attributeVector.at(index);
1008 return &static_cast<const ShareableElementData*>(this)->m_attributeArray[index];