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 ImmutableElementAttributeData;
49 class MutableElementAttributeData;
53 class StylePropertySet;
55 class ElementAttributeData : public RefCounted<ElementAttributeData> {
56 WTF_MAKE_FAST_ALLOCATED;
58 static PassRefPtr<ElementAttributeData> create();
59 static PassRefPtr<ElementAttributeData> createImmutable(const Vector<Attribute>&);
61 // Override RefCounted's deref() to ensure operator delete is called on
62 // the appropriate subclass type.
65 void clearClass() const { m_classNames.clear(); }
66 void setClass(const AtomicString& className, bool shouldFoldCase) const { m_classNames.set(className, shouldFoldCase); }
67 const SpaceSplitString& classNames() const { return m_classNames; }
69 const AtomicString& idForStyleResolution() const { return m_idForStyleResolution; }
70 void setIdForStyleResolution(const AtomicString& newId) const { m_idForStyleResolution = newId; }
72 const StylePropertySet* inlineStyle() const { return m_inlineStyle.get(); }
74 const StylePropertySet* presentationAttributeStyle() const;
75 void setPresentationAttributeStyle(PassRefPtr<StylePropertySet>) const;
77 size_t length() const;
78 bool isEmpty() const { return !length(); }
80 const Attribute* attributeItem(unsigned index) const;
81 const Attribute* getAttributeItem(const QualifiedName&) const;
82 Attribute* attributeItem(unsigned index);
83 Attribute* getAttributeItem(const QualifiedName&);
84 size_t getAttributeItemIndex(const QualifiedName&) const;
85 size_t getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
87 // These functions do no error checking.
88 void addAttribute(const Attribute&);
89 void removeAttribute(size_t index);
91 bool hasID() const { return !m_idForStyleResolution.isNull(); }
92 bool hasClass() const { return !m_classNames.isNull(); }
94 bool isEquivalent(const ElementAttributeData* other) const;
96 void reportMemoryUsage(MemoryObjectInfo*) const;
98 bool isMutable() const { return m_isMutable; }
99 const Attribute* immutableAttributeArray() const;
102 ElementAttributeData();
103 ElementAttributeData(unsigned arraySize);
104 ElementAttributeData(const ElementAttributeData&, bool isMutable);
106 unsigned m_isMutable : 1;
107 unsigned m_arraySize : 28;
108 mutable unsigned m_presentationAttributeStyleIsDirty : 1;
109 mutable unsigned m_styleAttributeIsDirty : 1;
111 mutable unsigned m_animatedSVGAttributesAreDirty : 1;
114 mutable RefPtr<StylePropertySet> m_inlineStyle;
115 mutable SpaceSplitString m_classNames;
116 mutable AtomicString m_idForStyleResolution;
119 friend class Element;
120 friend class StyledElement;
121 friend class ImmutableElementAttributeData;
122 friend class MutableElementAttributeData;
124 friend class SVGElement;
127 Attribute* getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase);
128 const Attribute* getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
129 size_t getAttributeItemIndexSlowCase(const AtomicString& name, bool shouldIgnoreAttributeCase) const;
131 PassRefPtr<ElementAttributeData> makeMutableCopy() const;
132 PassRefPtr<ElementAttributeData> makeImmutableCopy() const;
134 Vector<Attribute, 4>& mutableAttributeVector();
135 const Vector<Attribute, 4>& mutableAttributeVector() const;
138 class ImmutableElementAttributeData : public ElementAttributeData {
140 ImmutableElementAttributeData(const Vector<Attribute>&);
141 ImmutableElementAttributeData(const MutableElementAttributeData&);
142 ~ImmutableElementAttributeData();
144 void* m_attributeArray;
147 class MutableElementAttributeData : public ElementAttributeData {
149 MutableElementAttributeData();
150 MutableElementAttributeData(const ImmutableElementAttributeData&);
151 MutableElementAttributeData(const MutableElementAttributeData&);
153 mutable RefPtr<StylePropertySet> m_presentationAttributeStyle;
154 Vector<Attribute, 4> m_attributeVector;
157 enum AffectedSelectorType {
158 AffectedSelectorChecked = 1,
159 AffectedSelectorEnabled = 1 << 1,
160 AffectedSelectorDisabled = 1 << 2,
161 AffectedSelectorIndeterminate = 1 << 3,
162 AffectedSelectorLink = 1 << 4,
163 AffectedSelectorTarget = 1 << 5,
164 AffectedSelectorVisited = 1 << 6
166 typedef int AffectedSelectorMask;
168 enum SpellcheckAttributeState {
169 SpellcheckAttributeTrue,
170 SpellcheckAttributeFalse,
171 SpellcheckAttributeDefault
174 class Element : public ContainerNode {
176 static PassRefPtr<Element> create(const QualifiedName&, Document*);
179 DEFINE_ATTRIBUTE_EVENT_LISTENER(abort);
180 DEFINE_ATTRIBUTE_EVENT_LISTENER(change);
181 DEFINE_ATTRIBUTE_EVENT_LISTENER(click);
182 DEFINE_ATTRIBUTE_EVENT_LISTENER(contextmenu);
183 DEFINE_ATTRIBUTE_EVENT_LISTENER(dblclick);
184 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragenter);
185 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragover);
186 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragleave);
187 DEFINE_ATTRIBUTE_EVENT_LISTENER(drop);
188 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragstart);
189 DEFINE_ATTRIBUTE_EVENT_LISTENER(drag);
190 DEFINE_ATTRIBUTE_EVENT_LISTENER(dragend);
191 DEFINE_ATTRIBUTE_EVENT_LISTENER(input);
192 DEFINE_ATTRIBUTE_EVENT_LISTENER(invalid);
193 DEFINE_ATTRIBUTE_EVENT_LISTENER(keydown);
194 DEFINE_ATTRIBUTE_EVENT_LISTENER(keypress);
195 DEFINE_ATTRIBUTE_EVENT_LISTENER(keyup);
196 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousedown);
197 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousemove);
198 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseout);
199 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseover);
200 DEFINE_ATTRIBUTE_EVENT_LISTENER(mouseup);
201 DEFINE_ATTRIBUTE_EVENT_LISTENER(mousewheel);
202 DEFINE_ATTRIBUTE_EVENT_LISTENER(scroll);
203 DEFINE_ATTRIBUTE_EVENT_LISTENER(select);
204 DEFINE_ATTRIBUTE_EVENT_LISTENER(submit);
206 // These four attribute event handler attributes are overridden by HTMLBodyElement
207 // and HTMLFrameSetElement to forward to the DOMWindow.
208 DECLARE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(blur);
209 DECLARE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(error);
210 DECLARE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(focus);
211 DECLARE_VIRTUAL_ATTRIBUTE_EVENT_LISTENER(load);
214 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecut);
215 DEFINE_ATTRIBUTE_EVENT_LISTENER(cut);
216 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecopy);
217 DEFINE_ATTRIBUTE_EVENT_LISTENER(copy);
218 DEFINE_ATTRIBUTE_EVENT_LISTENER(beforepaste);
219 DEFINE_ATTRIBUTE_EVENT_LISTENER(paste);
220 DEFINE_ATTRIBUTE_EVENT_LISTENER(reset);
221 DEFINE_ATTRIBUTE_EVENT_LISTENER(search);
222 DEFINE_ATTRIBUTE_EVENT_LISTENER(selectstart);
223 #if ENABLE(TOUCH_EVENTS)
224 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchstart);
225 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchmove);
226 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchend);
227 DEFINE_ATTRIBUTE_EVENT_LISTENER(touchcancel);
229 #if ENABLE(FULLSCREEN_API)
230 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenchange);
231 DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenerror);
234 bool hasAttribute(const QualifiedName&) const;
235 const AtomicString& getAttribute(const QualifiedName&) const;
236 void setAttribute(const QualifiedName&, const AtomicString& value);
237 void setSynchronizedLazyAttribute(const QualifiedName&, const AtomicString& value);
238 void removeAttribute(const QualifiedName&);
240 // Typed getters and setters for language bindings.
241 int getIntegralAttribute(const QualifiedName& attributeName) const;
242 void setIntegralAttribute(const QualifiedName& attributeName, int value);
243 unsigned getUnsignedIntegralAttribute(const QualifiedName& attributeName) const;
244 void setUnsignedIntegralAttribute(const QualifiedName& attributeName, unsigned value);
246 // Call this to get the value of an attribute that is known not to be the style
247 // attribute or one of the SVG animatable attributes.
248 bool fastHasAttribute(const QualifiedName&) const;
249 const AtomicString& fastGetAttribute(const QualifiedName&) const;
251 bool fastAttributeLookupAllowed(const QualifiedName&) const;
254 #ifdef DUMP_NODE_STATISTICS
255 bool hasNamedNodeMap() const;
257 bool hasAttributes() const;
258 // This variant will not update the potentially invalid attributes. To be used when not interested
259 // in style attribute or one of the SVG animation attributes.
260 bool hasAttributesWithoutUpdate() const;
262 bool hasAttribute(const AtomicString& name) const;
263 bool hasAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const;
265 const AtomicString& getAttribute(const AtomicString& name) const;
266 const AtomicString& getAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const;
268 void setAttribute(const AtomicString& name, const AtomicString& value, ExceptionCode&);
269 static bool parseAttributeName(QualifiedName&, const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionCode&);
270 void setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionCode&);
272 bool isIdAttributeName(const QualifiedName&) const;
273 const AtomicString& getIdAttribute() const;
274 void setIdAttribute(const AtomicString&);
276 const AtomicString& getNameAttribute() const;
278 // Call this to get the value of the id attribute for style resolution purposes.
279 // The value will already be lowercased if the document is in compatibility mode,
280 // so this function is not suitable for non-style uses.
281 const AtomicString& idForStyleResolution() const;
283 // Internal methods that assume the existence of attribute storage, one should use hasAttributes()
284 // before calling them.
285 size_t attributeCount() const;
286 const Attribute* attributeItem(unsigned index) const;
287 const Attribute* getAttributeItem(const QualifiedName&) const;
288 Attribute* getAttributeItem(const QualifiedName&);
289 size_t getAttributeItemIndex(const QualifiedName& name) const { return attributeData()->getAttributeItemIndex(name); }
290 size_t getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const { return attributeData()->getAttributeItemIndex(name, shouldIgnoreAttributeCase); }
292 void scrollIntoView(bool alignToTop = true);
293 void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
295 void scrollByLines(int lines);
296 void scrollByPages(int pages);
302 Element* offsetParent();
307 virtual int scrollLeft();
308 virtual int scrollTop();
309 virtual void setScrollLeft(int);
310 virtual void setScrollTop(int);
311 virtual int scrollWidth();
312 virtual int scrollHeight();
314 IntRect boundsInRootViewSpace();
316 PassRefPtr<ClientRectList> getClientRects();
317 PassRefPtr<ClientRect> getBoundingClientRect();
319 // Returns the absolute bounding box translated into screen coordinates:
320 IntRect screenRect() const;
322 void removeAttribute(const AtomicString& name);
323 void removeAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName);
325 PassRefPtr<Attr> detachAttribute(size_t index);
327 PassRefPtr<Attr> getAttributeNode(const AtomicString& name);
328 PassRefPtr<Attr> getAttributeNodeNS(const AtomicString& namespaceURI, const AtomicString& localName);
329 PassRefPtr<Attr> setAttributeNode(Attr*, ExceptionCode&);
330 PassRefPtr<Attr> setAttributeNodeNS(Attr*, ExceptionCode&);
331 PassRefPtr<Attr> removeAttributeNode(Attr*, ExceptionCode&);
333 PassRefPtr<Attr> attrIfExists(const QualifiedName&);
334 PassRefPtr<Attr> ensureAttr(const QualifiedName&);
336 const Vector<RefPtr<Attr> >& attrNodeList();
338 virtual CSSStyleDeclaration* style();
340 const QualifiedName& tagQName() const { return m_tagName; }
341 String tagName() const { return nodeName(); }
342 bool hasTagName(const QualifiedName& tagName) const { return m_tagName.matches(tagName); }
344 // A fast function for checking the local name against another atomic string.
345 bool hasLocalName(const AtomicString& other) const { return m_tagName.localName() == other; }
346 bool hasLocalName(const QualifiedName& other) const { return m_tagName.localName() == other.localName(); }
348 const AtomicString& localName() const { return m_tagName.localName(); }
349 const AtomicString& prefix() const { return m_tagName.prefix(); }
350 const AtomicString& namespaceURI() const { return m_tagName.namespaceURI(); }
352 virtual KURL baseURI() const;
354 virtual String nodeName() const;
356 PassRefPtr<Element> cloneElementWithChildren();
357 PassRefPtr<Element> cloneElementWithoutChildren();
359 void normalizeAttributes();
360 String nodeNamePreservingCase() const;
362 void setBooleanAttribute(const QualifiedName& name, bool);
364 // For exposing to DOM only.
365 NamedNodeMap* attributes() const;
367 // This method is called whenever an attribute is added, changed or removed.
368 virtual void attributeChanged(const QualifiedName&, const AtomicString&);
369 virtual void parseAttribute(const QualifiedName&, const AtomicString&) { }
371 // Only called by the parser immediately after element construction.
372 void parserSetAttributes(const Vector<Attribute>&, FragmentScriptingPermission);
374 const ElementAttributeData* attributeData() const { return m_attributeData.get(); }
375 ElementAttributeData* mutableAttributeData();
376 const ElementAttributeData* updatedAttributeData() const;
377 const ElementAttributeData* ensureUpdatedAttributeData() const;
379 // Clones attributes only.
380 void cloneAttributesFromElement(const Element&);
382 // Clones all attribute-derived data, including subclass specifics (through copyNonAttributeProperties.)
383 void cloneDataFromElement(const Element&);
385 bool hasEquivalentAttributes(const Element* other) const;
387 virtual void copyNonAttributePropertiesFromElement(const Element&) { }
389 virtual void attach();
390 virtual void detach();
391 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*);
392 virtual bool rendererIsNeeded(const NodeRenderingContext&);
393 void recalcStyle(StyleChange = NoChange);
394 void didAffectSelector(AffectedSelectorMask);
396 ElementShadow* shadow() const;
397 ElementShadow* ensureShadow();
398 PassRefPtr<ShadowRoot> createShadowRoot(ExceptionCode&);
399 ShadowRoot* shadowRoot() const;
401 bool hasAuthorShadowRoot() const { return shadowRoot(); }
402 virtual void willAddAuthorShadowRoot() { }
404 ShadowRoot* userAgentShadowRoot() const;
405 ShadowRoot* ensureUserAgentShadowRoot();
407 virtual const AtomicString& shadowPseudoId() const;
409 RenderStyle* computedStyle(PseudoId = NOPSEUDO);
411 // Methods for indicating the style is affected by dynamic updates (e.g., children changing, our position changing in our sibling list, etc.)
412 bool styleAffectedByEmpty() const { return hasRareData() && rareDataStyleAffectedByEmpty(); }
413 bool childrenAffectedByHover() const { return hasRareData() && rareDataChildrenAffectedByHover(); }
414 bool childrenAffectedByActive() const { return hasRareData() && rareDataChildrenAffectedByActive(); }
415 bool childrenAffectedByDrag() const { return hasRareData() && rareDataChildrenAffectedByDrag(); }
416 bool childrenAffectedByPositionalRules() const { return hasRareData() && (rareDataChildrenAffectedByForwardPositionalRules() || rareDataChildrenAffectedByBackwardPositionalRules()); }
417 bool childrenAffectedByFirstChildRules() const { return hasRareData() && rareDataChildrenAffectedByFirstChildRules(); }
418 bool childrenAffectedByLastChildRules() const { return hasRareData() && rareDataChildrenAffectedByLastChildRules(); }
419 bool childrenAffectedByDirectAdjacentRules() const { return hasRareData() && rareDataChildrenAffectedByDirectAdjacentRules(); }
420 bool childrenAffectedByForwardPositionalRules() const { return hasRareData() && rareDataChildrenAffectedByForwardPositionalRules(); }
421 bool childrenAffectedByBackwardPositionalRules() const { return hasRareData() && rareDataChildrenAffectedByBackwardPositionalRules(); }
422 unsigned childIndex() const { return hasRareData() ? rareDataChildIndex() : 0; }
424 bool hasFlagsSetDuringStylingOfChildren() const;
426 void setStyleAffectedByEmpty();
427 void setChildrenAffectedByHover(bool);
428 void setChildrenAffectedByActive(bool);
429 void setChildrenAffectedByDrag(bool);
430 void setChildrenAffectedByFirstChildRules();
431 void setChildrenAffectedByLastChildRules();
432 void setChildrenAffectedByDirectAdjacentRules();
433 void setChildrenAffectedByForwardPositionalRules();
434 void setChildrenAffectedByBackwardPositionalRules();
435 void setChildIndex(unsigned);
437 void setIsInCanvasSubtree(bool);
438 bool isInCanvasSubtree() const;
440 AtomicString computeInheritedLanguage() const;
441 Locale& locale() const;
443 virtual void accessKeyAction(bool /*sendToAnyEvent*/) { }
445 virtual bool isURLAttribute(const Attribute&) const { return false; }
447 KURL getURLAttribute(const QualifiedName&) const;
448 KURL getNonEmptyURLAttribute(const QualifiedName&) const;
450 virtual const QualifiedName& imageSourceAttributeName() const;
451 virtual String target() const { return String(); }
453 virtual void focus(bool restorePreviousSelection = true, FocusDirection = FocusDirectionNone);
454 virtual void updateFocusAppearance(bool restorePreviousSelection);
460 virtual String title() const;
462 const AtomicString& pseudo() const;
463 void setPseudo(const AtomicString&);
465 void updateId(const AtomicString& oldId, const AtomicString& newId);
466 void updateId(TreeScope*, const AtomicString& oldId, const AtomicString& newId);
467 void updateName(const AtomicString& oldName, const AtomicString& newName);
468 void updateLabel(TreeScope*, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue);
470 void removeCachedHTMLCollection(HTMLCollection*, CollectionType);
472 LayoutSize minimumSizeForResizing() const;
473 void setMinimumSizeForResizing(const LayoutSize&);
475 // Use Document::registerForDocumentActivationCallbacks() to subscribe to these
476 virtual void documentWillSuspendForPageCache() { }
477 virtual void documentDidResumeFromPageCache() { }
479 // Use Document::registerForMediaVolumeCallbacks() to subscribe to this
480 virtual void mediaVolumeDidChange() { }
482 // Use Document::registerForPrivateBrowsingStateChangedCallbacks() to subscribe to this.
483 virtual void privateBrowsingStateDidChange() { }
485 virtual void didBecomeFullscreenElement() { }
486 virtual void willStopBeingFullscreenElement() { }
488 bool isFinishedParsingChildren() const { return isParsingChildrenFinished(); }
489 virtual void finishParsingChildren();
490 virtual void beginParsingChildren();
492 bool hasPseudoElements() const;
493 PseudoElement* pseudoElement(PseudoId) const;
494 RenderObject* pseudoElementRenderer(PseudoId) const;
495 bool childNeedsShadowWalker() const;
496 void didShadowTreeAwareChildrenChange();
498 // ElementTraversal API
499 Element* firstElementChild() const;
500 Element* lastElementChild() const;
501 Element* previousElementSibling() const;
502 Element* nextElementSibling() const;
503 unsigned childElementCount() const;
505 virtual bool matchesReadOnlyPseudoClass() const;
506 virtual bool matchesReadWritePseudoClass() const;
507 bool webkitMatchesSelector(const String& selectors, ExceptionCode&);
509 DOMTokenList* classList();
511 DOMStringMap* dataset();
514 virtual bool isMathMLElement() const { return false; }
516 static bool isMathMLElement() { return false; }
520 virtual bool isMediaElement() const { return false; }
523 #if ENABLE(INPUT_SPEECH)
524 virtual bool isInputFieldSpeechButtonElement() const { return false; }
526 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
527 virtual bool isDateTimeFieldElement() const;
530 virtual bool isFormControlElement() const { return false; }
531 virtual bool isEnabledFormControl() const { return true; }
532 virtual bool isSpinButtonElement() const { return false; }
533 virtual bool isTextFormControl() const { return false; }
534 virtual bool isOptionalFormControl() const { return false; }
535 virtual bool isRequiredFormControl() const { return false; }
536 virtual bool isDefaultButtonForForm() const { return false; }
537 virtual bool willValidate() const { return false; }
538 virtual bool isValidFormControlElement() { return false; }
539 virtual bool isInRange() const { return false; }
540 virtual bool isOutOfRange() const { return false; }
541 virtual bool isFrameElementBase() const { return false; }
542 virtual bool isTextFieldDecoration() const { return false; }
544 virtual bool canContainRangeEndPoint() const { return true; }
546 virtual const AtomicString& formControlType() const { return nullAtom; }
548 virtual bool wasChangedSinceLastFormControlChangeEvent() const;
549 virtual void setChangedSinceLastFormControlChangeEvent(bool);
550 virtual void dispatchFormControlChangeEvent() { }
553 virtual bool childShouldCreateRenderer(const NodeRenderingContext&) const;
554 bool hasPendingResources() const;
555 void setHasPendingResources();
556 void clearHasPendingResources();
557 virtual void buildPendingResource() { };
560 #if ENABLE(FULLSCREEN_API)
562 ALLOW_KEYBOARD_INPUT = 1 << 0,
563 LEGACY_MOZILLA_REQUEST = 1 << 1,
566 void webkitRequestFullScreen(unsigned short flags);
567 virtual bool containsFullScreenElement() const;
568 virtual void setContainsFullScreenElement(bool);
569 virtual void setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(bool);
572 void webkitRequestFullscreen();
575 #if ENABLE(DIALOG_ELEMENT)
576 bool isInTopLayer() const;
577 void setIsInTopLayer(bool);
580 #if ENABLE(POINTER_LOCK)
581 void webkitRequestPointerLock();
584 virtual bool isSpellCheckingEnabled() const;
586 PassRefPtr<RenderStyle> styleForRenderer();
588 RenderRegion* renderRegion() const;
589 #if ENABLE(CSS_REGIONS)
590 const AtomicString& webkitRegionOverset() const;
591 Vector<RefPtr<Range> > webkitGetRegionFlowRanges() const;
595 bool hasClass() const;
596 const SpaceSplitString& classNames() const;
598 IntSize savedLayerScrollOffset() const;
599 void setSavedLayerScrollOffset(const IntSize&);
601 virtual void reportMemoryUsage(MemoryObjectInfo*) const OVERRIDE;
604 Element(const QualifiedName& tagName, Document* document, ConstructionType type)
605 : ContainerNode(document, type)
610 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
611 virtual void removedFrom(ContainerNode*) OVERRIDE;
612 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0);
614 virtual bool willRecalcStyle(StyleChange);
615 virtual void didRecalcStyle(StyleChange);
616 virtual PassRefPtr<RenderStyle> customStyleForRenderer();
618 virtual bool shouldRegisterAsNamedItem() const { return false; }
619 virtual bool shouldRegisterAsExtraNamedItem() const { return false; }
621 void clearTabIndexExplicitlyIfNeeded();
622 void setTabIndexExplicitly(short);
623 virtual bool supportsFocus() const OVERRIDE;
624 virtual short tabIndex() const OVERRIDE;
626 PassRefPtr<HTMLCollection> ensureCachedHTMLCollection(CollectionType);
627 HTMLCollection* cachedHTMLCollection(CollectionType);
629 // classAttributeChanged() exists to share code between
630 // parseAttribute (called via setAttribute()) and
631 // svgAttributeChanged (called when element.className.baseValue is set)
632 void classAttributeChanged(const AtomicString& newClassString);
635 void updatePseudoElement(PseudoId, StyleChange = NoChange);
636 PassRefPtr<PseudoElement> createPseudoElementIfNeeded(PseudoId);
637 void setPseudoElement(PseudoId, PassRefPtr<PseudoElement>);
639 virtual bool areAuthorShadowsAllowed() const { return true; }
640 virtual void didAddUserAgentShadowRoot(ShadowRoot*) { }
641 virtual bool alwaysCreateUserAgentShadowRoot() const { return false; }
643 // FIXME: Remove the need for Attr to call willModifyAttribute/didModifyAttribute.
646 enum SynchronizationOfLazyAttribute { NotInSynchronizationOfLazyAttribute = 0, InSynchronizationOfLazyAttribute };
648 void didAddAttribute(const QualifiedName&, const AtomicString&);
649 void willModifyAttribute(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue);
650 void didModifyAttribute(const QualifiedName&, const AtomicString&);
651 void didRemoveAttribute(const QualifiedName&);
653 void updateInvalidAttributes() const;
655 void scrollByUnits(int units, ScrollGranularity);
657 virtual void setPrefix(const AtomicString&, ExceptionCode&);
658 virtual NodeType nodeType() const;
659 virtual bool childTypeAllowed(NodeType) const;
661 void setAttributeInternal(size_t index, const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
662 void addAttributeInternal(const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
663 void removeAttributeInternal(size_t index, SynchronizationOfLazyAttribute);
666 virtual void formatForDebugger(char* buffer, unsigned length) const;
669 bool pseudoStyleCacheIsInvalid(const RenderStyle* currentStyle, RenderStyle* newStyle);
671 virtual void updateStyleAttribute() const { }
674 virtual void updateAnimatedSVGAttribute(const QualifiedName&) const { }
677 void cancelFocusAppearanceUpdate();
679 virtual const AtomicString& virtualPrefix() const { return prefix(); }
680 virtual const AtomicString& virtualLocalName() const { return localName(); }
681 virtual const AtomicString& virtualNamespaceURI() const { return namespaceURI(); }
682 virtual RenderStyle* virtualComputedStyle(PseudoId pseudoElementSpecifier = NOPSEUDO) { return computedStyle(pseudoElementSpecifier); }
684 // cloneNode is private so that non-virtual cloneElementWithChildren and cloneElementWithoutChildren
686 virtual PassRefPtr<Node> cloneNode(bool deep) OVERRIDE;
687 virtual PassRefPtr<Element> cloneElementWithoutAttributesAndChildren();
689 QualifiedName m_tagName;
690 bool rareDataStyleAffectedByEmpty() const;
691 bool rareDataChildrenAffectedByHover() const;
692 bool rareDataChildrenAffectedByActive() const;
693 bool rareDataChildrenAffectedByDrag() const;
694 bool rareDataChildrenAffectedByFirstChildRules() const;
695 bool rareDataChildrenAffectedByLastChildRules() const;
696 bool rareDataChildrenAffectedByDirectAdjacentRules() const;
697 bool rareDataChildrenAffectedByForwardPositionalRules() const;
698 bool rareDataChildrenAffectedByBackwardPositionalRules() const;
699 unsigned rareDataChildIndex() const;
701 SpellcheckAttributeState spellcheckAttributeState() const;
703 void updateNamedItemRegistration(const AtomicString& oldName, const AtomicString& newName);
704 void updateExtraNamedItemRegistration(const AtomicString& oldName, const AtomicString& newName);
706 void unregisterNamedFlowContentNode();
708 void createMutableAttributeData();
710 bool shouldInvalidateDistributionWhenAttributeChanged(ElementShadow*, const QualifiedName&, const AtomicString&);
712 ElementRareData* elementRareData() const;
713 ElementRareData* ensureElementRareData();
715 void detachAllAttrNodesFromElement();
716 void detachAttrNodeFromElementWithValue(Attr*, const AtomicString& value);
718 void createRendererIfNeeded();
720 RefPtr<ElementAttributeData> m_attributeData;
723 inline Element* toElement(Node* node)
725 ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isElementNode());
726 return static_cast<Element*>(node);
729 inline const Element* toElement(const Node* node)
731 ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isElementNode());
732 return static_cast<const Element*>(node);
735 // This will catch anyone doing an unnecessary cast.
736 void toElement(const Element*);
738 inline bool Node::hasTagName(const QualifiedName& name) const
740 return isElementNode() && toElement(this)->hasTagName(name);
743 inline bool Node::hasLocalName(const AtomicString& name) const
745 return isElementNode() && toElement(this)->hasLocalName(name);
748 inline bool Node::hasAttributes() const
750 return isElementNode() && toElement(this)->hasAttributes();
753 inline NamedNodeMap* Node::attributes() const
755 return isElementNode() ? toElement(this)->attributes() : 0;
758 inline Element* Node::parentElement() const
760 ContainerNode* parent = parentNode();
761 return parent && parent->isElementNode() ? toElement(parent) : 0;
764 inline Element* Element::previousElementSibling() const
766 Node* n = previousSibling();
767 while (n && !n->isElementNode())
768 n = n->previousSibling();
769 return static_cast<Element*>(n);
772 inline Element* Element::nextElementSibling() const
774 Node* n = nextSibling();
775 while (n && !n->isElementNode())
776 n = n->nextSibling();
777 return static_cast<Element*>(n);
780 inline const ElementAttributeData* Element::updatedAttributeData() const
782 updateInvalidAttributes();
783 return attributeData();
786 inline const ElementAttributeData* Element::ensureUpdatedAttributeData() const
788 updateInvalidAttributes();
790 return attributeData();
791 return const_cast<Element*>(this)->mutableAttributeData();
794 inline void Element::updateName(const AtomicString& oldName, const AtomicString& newName)
796 if (!inDocument() || isInShadowTree())
799 if (oldName == newName)
802 if (shouldRegisterAsNamedItem())
803 updateNamedItemRegistration(oldName, newName);
806 inline void Element::updateId(const AtomicString& oldId, const AtomicString& newId)
808 if (!isInTreeScope())
814 updateId(treeScope(), oldId, newId);
817 inline void Element::updateId(TreeScope* scope, const AtomicString& oldId, const AtomicString& newId)
819 ASSERT(isInTreeScope());
820 ASSERT(oldId != newId);
822 if (!oldId.isEmpty())
823 scope->removeElementById(oldId, this);
824 if (!newId.isEmpty())
825 scope->addElementById(newId, this);
827 if (shouldRegisterAsExtraNamedItem())
828 updateExtraNamedItemRegistration(oldId, newId);
831 inline bool Element::fastHasAttribute(const QualifiedName& name) const
833 ASSERT(fastAttributeLookupAllowed(name));
834 return attributeData() && getAttributeItem(name);
837 inline const AtomicString& Element::fastGetAttribute(const QualifiedName& name) const
839 ASSERT(fastAttributeLookupAllowed(name));
840 if (attributeData()) {
841 if (const Attribute* attribute = getAttributeItem(name))
842 return attribute->value();
847 inline bool Element::hasAttributesWithoutUpdate() const
849 return attributeData() && !attributeData()->isEmpty();
852 inline const AtomicString& Element::idForStyleResolution() const
855 return attributeData()->idForStyleResolution();
858 inline bool Element::isIdAttributeName(const QualifiedName& attributeName) const
860 // FIXME: This check is probably not correct for the case where the document has an id attribute
861 // with a non-null namespace, because it will return false, a false negative, if the prefixes
862 // don't match but the local name and namespace both do. However, since this has been like this
863 // for a while and the code paths may be hot, we'll have to measure performance if we fix it.
864 return attributeName == document()->idAttributeName();
867 inline const AtomicString& Element::getIdAttribute() const
869 return hasID() ? fastGetAttribute(document()->idAttributeName()) : nullAtom;
872 inline const AtomicString& Element::getNameAttribute() const
874 return hasName() ? fastGetAttribute(HTMLNames::nameAttr) : nullAtom;
877 inline void Element::setIdAttribute(const AtomicString& value)
879 setAttribute(document()->idAttributeName(), value);
882 inline const SpaceSplitString& Element::classNames() const
885 ASSERT(attributeData());
886 return attributeData()->classNames();
889 inline size_t Element::attributeCount() const
891 ASSERT(attributeData());
892 return attributeData()->length();
895 inline const Attribute* Element::attributeItem(unsigned index) const
897 ASSERT(attributeData());
898 return attributeData()->attributeItem(index);
901 inline const Attribute* Element::getAttributeItem(const QualifiedName& name) const
903 ASSERT(attributeData());
904 return attributeData()->getAttributeItem(name);
907 inline Attribute* Element::getAttributeItem(const QualifiedName& name)
909 ASSERT(attributeData());
910 return mutableAttributeData()->getAttributeItem(name);
913 inline void Element::updateInvalidAttributes() const
915 if (!attributeData())
918 if (attributeData()->m_styleAttributeIsDirty)
919 updateStyleAttribute();
922 if (attributeData()->m_animatedSVGAttributesAreDirty)
923 updateAnimatedSVGAttribute(anyQName());
927 inline bool Element::hasID() const
929 return attributeData() && attributeData()->hasID();
932 inline bool Element::hasClass() const
934 return attributeData() && attributeData()->hasClass();
937 inline ElementAttributeData* Element::mutableAttributeData()
939 if (!attributeData() || !attributeData()->isMutable())
940 createMutableAttributeData();
941 return m_attributeData.get();
944 // Put here to make them inline.
945 inline bool Node::hasID() const
947 return isElementNode() && toElement(this)->hasID();
950 inline bool Node::hasClass() const
952 return isElementNode() && toElement(this)->hasClass();
955 inline Node::InsertionNotificationRequest Node::insertedInto(ContainerNode* insertionPoint)
957 ASSERT(insertionPoint->inDocument() || isContainerNode());
958 if (insertionPoint->inDocument())
959 setFlag(InDocumentFlag);
960 if (parentOrShadowHostNode()->isInShadowTree())
961 setFlag(IsInShadowTreeFlag);
962 return InsertionDone;
965 inline void Node::removedFrom(ContainerNode* insertionPoint)
967 ASSERT(insertionPoint->inDocument() || isContainerNode());
968 if (insertionPoint->inDocument())
969 clearFlag(InDocumentFlag);
970 if (isInShadowTree() && !treeScope()->rootNode()->isShadowRoot())
971 clearFlag(IsInShadowTreeFlag);
974 inline bool isShadowHost(const Node* node)
976 return node && node->isElementNode() && toElement(node)->shadow();
978 inline Vector<Attribute, 4>& ElementAttributeData::mutableAttributeVector()
981 return static_cast<MutableElementAttributeData*>(this)->m_attributeVector;
984 inline const Vector<Attribute, 4>& ElementAttributeData::mutableAttributeVector() const
987 return static_cast<const MutableElementAttributeData*>(this)->m_attributeVector;
990 inline const Attribute* ElementAttributeData::immutableAttributeArray() const
992 ASSERT(!m_isMutable);
993 return reinterpret_cast<const Attribute*>(&static_cast<const ImmutableElementAttributeData*>(this)->m_attributeArray);
996 inline size_t ElementAttributeData::length() const
999 return mutableAttributeVector().size();
1003 inline const StylePropertySet* ElementAttributeData::presentationAttributeStyle() const
1007 return static_cast<const MutableElementAttributeData*>(this)->m_presentationAttributeStyle.get();
1010 inline Attribute* ElementAttributeData::getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase)
1012 size_t index = getAttributeItemIndex(name, shouldIgnoreAttributeCase);
1013 if (index != notFound)
1014 return attributeItem(index);
1018 inline const Attribute* ElementAttributeData::getAttributeItem(const AtomicString& name, bool shouldIgnoreAttributeCase) const
1020 size_t index = getAttributeItemIndex(name, shouldIgnoreAttributeCase);
1021 if (index != notFound)
1022 return attributeItem(index);
1026 inline size_t ElementAttributeData::getAttributeItemIndex(const QualifiedName& name) const
1028 for (unsigned i = 0; i < length(); ++i) {
1029 if (attributeItem(i)->name().matches(name))
1035 // We use a boolean parameter instead of calling shouldIgnoreAttributeCase so that the caller
1036 // can tune the behavior (hasAttribute is case sensitive whereas getAttribute is not).
1037 inline size_t ElementAttributeData::getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const
1039 unsigned len = length();
1040 bool doSlowCheck = shouldIgnoreAttributeCase;
1042 // Optimize for the case where the attribute exists and its name exactly matches.
1043 for (unsigned i = 0; i < len; ++i) {
1044 const Attribute* attribute = attributeItem(i);
1045 if (!attribute->name().hasPrefix()) {
1046 if (name == attribute->localName())
1053 return getAttributeItemIndexSlowCase(name, shouldIgnoreAttributeCase);
1057 inline const Attribute* ElementAttributeData::getAttributeItem(const QualifiedName& name) const
1059 for (unsigned i = 0; i < length(); ++i) {
1060 if (attributeItem(i)->name().matches(name))
1061 return attributeItem(i);
1066 inline Attribute* ElementAttributeData::getAttributeItem(const QualifiedName& name)
1068 for (unsigned i = 0; i < length(); ++i) {
1069 if (attributeItem(i)->name().matches(name))
1070 return attributeItem(i);
1075 inline const Attribute* ElementAttributeData::attributeItem(unsigned index) const
1077 ASSERT_WITH_SECURITY_IMPLICATION(index < length());
1079 return &mutableAttributeVector().at(index);
1080 return &immutableAttributeArray()[index];
1083 inline Attribute* ElementAttributeData::attributeItem(unsigned index)
1085 ASSERT_WITH_SECURITY_IMPLICATION(index < length());
1086 return &mutableAttributeVector().at(index);