Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / core / dom / Element.h
1 /*
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.
7  *
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.
12  *
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.
17  *
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.
22  *
23  */
24
25 #ifndef Element_h
26 #define Element_h
27
28 #include "CSSPropertyNames.h"
29 #include "HTMLNames.h"
30 #include "core/css/CSSPrimitiveValue.h"
31 #include "core/dom/Attribute.h"
32 #include "core/dom/Document.h"
33 #include "core/dom/ElementData.h"
34 #include "core/dom/SpaceSplitString.h"
35 #include "core/html/CollectionType.h"
36 #include "core/page/FocusType.h"
37 #include "platform/scroll/ScrollTypes.h"
38
39 namespace WebCore {
40
41 class ActiveAnimations;
42 class Attr;
43 class Attribute;
44 class ClientRect;
45 class ClientRectList;
46 class DOMStringMap;
47 class DOMTokenList;
48 class ElementRareData;
49 class ElementShadow;
50 class ExceptionState;
51 class Image;
52 class InputMethodContext;
53 class IntSize;
54 class Locale;
55 class MutableStylePropertySet;
56 class PropertySetCSSStyleDeclaration;
57 class PseudoElement;
58 class ShadowRoot;
59 class StylePropertySet;
60
61 enum AffectedSelectorType {
62     AffectedSelectorChecked = 1,
63     AffectedSelectorEnabled = 1 << 1,
64     AffectedSelectorDisabled = 1 << 2,
65     AffectedSelectorIndeterminate = 1 << 3,
66     AffectedSelectorLink = 1 << 4,
67     AffectedSelectorTarget = 1 << 5,
68     AffectedSelectorVisited = 1 << 6
69 };
70 typedef int AffectedSelectorMask;
71
72 enum SpellcheckAttributeState {
73     SpellcheckAttributeTrue,
74     SpellcheckAttributeFalse,
75     SpellcheckAttributeDefault
76 };
77
78 class Element : public ContainerNode {
79 public:
80     static PassRefPtr<Element> create(const QualifiedName&, Document*);
81     virtual ~Element();
82
83     DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecopy);
84     DEFINE_ATTRIBUTE_EVENT_LISTENER(beforecut);
85     DEFINE_ATTRIBUTE_EVENT_LISTENER(beforepaste);
86     DEFINE_ATTRIBUTE_EVENT_LISTENER(copy);
87     DEFINE_ATTRIBUTE_EVENT_LISTENER(cut);
88     DEFINE_ATTRIBUTE_EVENT_LISTENER(paste);
89     DEFINE_ATTRIBUTE_EVENT_LISTENER(search);
90     DEFINE_ATTRIBUTE_EVENT_LISTENER(selectstart);
91     DEFINE_ATTRIBUTE_EVENT_LISTENER(touchcancel);
92     DEFINE_ATTRIBUTE_EVENT_LISTENER(touchend);
93     DEFINE_ATTRIBUTE_EVENT_LISTENER(touchmove);
94     DEFINE_ATTRIBUTE_EVENT_LISTENER(touchstart);
95     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenchange);
96     DEFINE_ATTRIBUTE_EVENT_LISTENER(webkitfullscreenerror);
97     DEFINE_ATTRIBUTE_EVENT_LISTENER(wheel);
98
99     bool hasAttribute(const QualifiedName&) const;
100     const AtomicString& getAttribute(const QualifiedName&) const;
101
102     // Passing nullAtom as the second parameter removes the attribute when calling either of these set methods.
103     void setAttribute(const QualifiedName&, const AtomicString& value);
104     void setSynchronizedLazyAttribute(const QualifiedName&, const AtomicString& value);
105
106     void removeAttribute(const QualifiedName&);
107
108     // Typed getters and setters for language bindings.
109     int getIntegralAttribute(const QualifiedName& attributeName) const;
110     void setIntegralAttribute(const QualifiedName& attributeName, int value);
111     unsigned getUnsignedIntegralAttribute(const QualifiedName& attributeName) const;
112     void setUnsignedIntegralAttribute(const QualifiedName& attributeName, unsigned value);
113     double getFloatingPointAttribute(const QualifiedName& attributeName, double fallbackValue = std::numeric_limits<double>::quiet_NaN()) const;
114     void setFloatingPointAttribute(const QualifiedName& attributeName, double value);
115
116     // Call this to get the value of an attribute that is known not to be the style
117     // attribute or one of the SVG animatable attributes.
118     bool fastHasAttribute(const QualifiedName&) const;
119     const AtomicString& fastGetAttribute(const QualifiedName&) const;
120 #ifndef NDEBUG
121     bool fastAttributeLookupAllowed(const QualifiedName&) const;
122 #endif
123
124 #ifdef DUMP_NODE_STATISTICS
125     bool hasNamedNodeMap() const;
126 #endif
127     bool hasAttributes() const;
128     // This variant will not update the potentially invalid attributes. To be used when not interested
129     // in style attribute or one of the SVG animation attributes.
130     bool hasAttributesWithoutUpdate() const;
131
132     bool hasAttribute(const AtomicString& name) const;
133     bool hasAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const;
134
135     const AtomicString& getAttribute(const AtomicString& name) const;
136     const AtomicString& getAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName) const;
137
138     void setAttribute(const AtomicString& name, const AtomicString& value, ExceptionState&);
139     static bool parseAttributeName(QualifiedName&, const AtomicString& namespaceURI, const AtomicString& qualifiedName, ExceptionState&);
140     void setAttributeNS(const AtomicString& namespaceURI, const AtomicString& qualifiedName, const AtomicString& value, ExceptionState&);
141
142     bool isIdAttributeName(const QualifiedName&) const;
143     const AtomicString& getIdAttribute() const;
144     void setIdAttribute(const AtomicString&);
145
146     const AtomicString& getNameAttribute() const;
147     const AtomicString& getClassAttribute() const;
148
149     bool shouldIgnoreAttributeCase() const;
150
151     // Call this to get the value of the id attribute for style resolution purposes.
152     // The value will already be lowercased if the document is in compatibility mode,
153     // so this function is not suitable for non-style uses.
154     const AtomicString& idForStyleResolution() const;
155
156     // Internal methods that assume the existence of attribute storage, one should use hasAttributes()
157     // before calling them.
158     size_t attributeCount() const;
159     const Attribute* attributeItem(unsigned index) const;
160     const Attribute* getAttributeItem(const QualifiedName&) const;
161     size_t getAttributeItemIndex(const QualifiedName& name) const { return elementData()->getAttributeItemIndex(name); }
162     size_t getAttributeItemIndex(const AtomicString& name, bool shouldIgnoreAttributeCase) const { return elementData()->getAttributeItemIndex(name, shouldIgnoreAttributeCase); }
163
164     void scrollIntoView(bool alignToTop = true);
165     void scrollIntoViewIfNeeded(bool centerIfNeeded = true);
166
167     void scrollByLines(int lines);
168     void scrollByPages(int pages);
169
170     int offsetLeft();
171     int offsetTop();
172     int offsetWidth();
173     int offsetHeight();
174
175     // FIXME: Replace uses of offsetParent in the platform with calls
176     // to the render layer and merge offsetParentForBindings and offsetParent.
177     Element* offsetParentForBindings();
178
179     Element* offsetParent();
180     int clientLeft();
181     int clientTop();
182     int clientWidth();
183     int clientHeight();
184     virtual int scrollLeft();
185     virtual int scrollTop();
186     virtual void setScrollLeft(int);
187     virtual void setScrollLeft(const Dictionary& scrollOptionsHorizontal, ExceptionState&);
188     virtual void setScrollTop(int);
189     virtual void setScrollTop(const Dictionary& scrollOptionsVertical, ExceptionState&);
190     virtual int scrollWidth();
191     virtual int scrollHeight();
192
193     IntRect boundsInRootViewSpace();
194
195     PassRefPtr<ClientRectList> getClientRects();
196     PassRefPtr<ClientRect> getBoundingClientRect();
197
198     // Returns the absolute bounding box translated into screen coordinates:
199     IntRect screenRect() const;
200
201     virtual void didMoveToNewDocument(Document&) OVERRIDE;
202
203     void removeAttribute(const AtomicString& name);
204     void removeAttributeNS(const AtomicString& namespaceURI, const AtomicString& localName);
205
206     PassRefPtr<Attr> detachAttribute(size_t index);
207
208     PassRefPtr<Attr> getAttributeNode(const AtomicString& name);
209     PassRefPtr<Attr> getAttributeNodeNS(const AtomicString& namespaceURI, const AtomicString& localName);
210     PassRefPtr<Attr> setAttributeNode(Attr*, ExceptionState&);
211     PassRefPtr<Attr> removeAttributeNode(Attr*, ExceptionState&);
212
213     PassRefPtr<Attr> attrIfExists(const QualifiedName&);
214     PassRefPtr<Attr> ensureAttr(const QualifiedName&);
215
216     const Vector<RefPtr<Attr> >& attrNodeList();
217
218     CSSStyleDeclaration* style();
219
220     const QualifiedName& tagQName() const { return m_tagName; }
221     String tagName() const { return nodeName(); }
222     bool hasTagName(const QualifiedName& tagName) const { return m_tagName.matches(tagName); }
223
224     // Should be called only by Document::createElementNS to fix up m_tagName immediately after construction.
225     void setTagNameForCreateElementNS(const QualifiedName&);
226
227     // A fast function for checking the local name against another atomic string.
228     bool hasLocalName(const AtomicString& other) const { return m_tagName.localName() == other; }
229     bool hasLocalName(const QualifiedName& other) const { return m_tagName.localName() == other.localName(); }
230
231     virtual const AtomicString& localName() const OVERRIDE FINAL { return m_tagName.localName(); }
232     const AtomicString& prefix() const { return m_tagName.prefix(); }
233     virtual const AtomicString& namespaceURI() const OVERRIDE FINAL { return m_tagName.namespaceURI(); }
234
235     const AtomicString& locateNamespacePrefix(const AtomicString& namespaceURI) const;
236
237     virtual KURL baseURI() const OVERRIDE FINAL;
238
239     virtual String nodeName() const OVERRIDE;
240
241     PassRefPtr<Element> cloneElementWithChildren();
242     PassRefPtr<Element> cloneElementWithoutChildren();
243
244     void scheduleLayerUpdate();
245
246     void normalizeAttributes();
247
248     void setBooleanAttribute(const QualifiedName& name, bool);
249
250     virtual const StylePropertySet* additionalPresentationAttributeStyle() { return 0; }
251     void invalidateStyleAttribute();
252
253     const StylePropertySet* inlineStyle() const { return elementData() ? elementData()->m_inlineStyle.get() : 0; }
254
255     bool setInlineStyleProperty(CSSPropertyID, CSSValueID identifier, bool important = false);
256     bool setInlineStyleProperty(CSSPropertyID, CSSPropertyID identifier, bool important = false);
257     bool setInlineStyleProperty(CSSPropertyID, double value, CSSPrimitiveValue::UnitTypes, bool important = false);
258     bool setInlineStyleProperty(CSSPropertyID, const String& value, bool important = false);
259     bool removeInlineStyleProperty(CSSPropertyID);
260     void removeAllInlineStyleProperties();
261
262     void synchronizeStyleAttributeInternal() const;
263
264     const StylePropertySet* presentationAttributeStyle();
265     virtual bool isPresentationAttribute(const QualifiedName&) const { return false; }
266     virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) { }
267
268     // For exposing to DOM only.
269     NamedNodeMap* attributes() const;
270
271     enum AttributeModificationReason {
272         ModifiedDirectly,
273         ModifiedByCloning
274     };
275
276     // This method is called whenever an attribute is added, changed or removed.
277     virtual void attributeChanged(const QualifiedName&, const AtomicString&, AttributeModificationReason = ModifiedDirectly);
278     virtual void parseAttribute(const QualifiedName&, const AtomicString&) { }
279
280     // Only called by the parser immediately after element construction.
281     void parserSetAttributes(const Vector<Attribute>&);
282
283     // Remove attributes that might introduce scripting from the vector leaving the element unchanged.
284     void stripScriptingAttributes(Vector<Attribute>&) const;
285
286     const ElementData* elementData() const { return m_elementData.get(); }
287     UniqueElementData* ensureUniqueElementData();
288
289     void synchronizeAllAttributes() const;
290
291     // Clones attributes only.
292     void cloneAttributesFromElement(const Element&);
293
294     // Clones all attribute-derived data, including subclass specifics (through copyNonAttributeProperties.)
295     void cloneDataFromElement(const Element&);
296
297     bool hasEquivalentAttributes(const Element* other) const;
298
299     virtual void copyNonAttributePropertiesFromElement(const Element&) { }
300
301     virtual void attach(const AttachContext& = AttachContext()) OVERRIDE;
302     virtual void detach(const AttachContext& = AttachContext()) OVERRIDE;
303     virtual RenderObject* createRenderer(RenderStyle*);
304     virtual bool rendererIsNeeded(const RenderStyle&);
305     void recalcStyle(StyleRecalcChange, Text* nextTextSibling = 0);
306     void didAffectSelector(AffectedSelectorMask);
307     void setAnimationStyleChange(bool);
308     void setNeedsAnimationStyleRecalc();
309
310     bool supportsStyleSharing() const;
311
312     ElementShadow* shadow() const;
313     ElementShadow& ensureShadow();
314     PassRefPtr<ShadowRoot> createShadowRoot(ExceptionState&);
315     ShadowRoot* shadowRoot() const;
316     ShadowRoot* youngestShadowRoot() const;
317
318     bool hasAuthorShadowRoot() const { return shadowRoot(); }
319     virtual void didAddShadowRoot(ShadowRoot&);
320     ShadowRoot* userAgentShadowRoot() const;
321     ShadowRoot& ensureUserAgentShadowRoot();
322     bool isInDescendantTreeOf(const Element* shadowHost) const;
323
324     RenderStyle* computedStyle(PseudoId = NOPSEUDO);
325
326     // Methods for indicating the style is affected by dynamic updates (e.g., children changing, our position changing in our sibling list, etc.)
327     bool styleAffectedByEmpty() const { return hasRareData() && rareDataStyleAffectedByEmpty(); }
328     bool childrenAffectedByFocus() const { return hasRareData() && rareDataChildrenAffectedByFocus(); }
329     bool childrenAffectedByHover() const { return hasRareData() && rareDataChildrenAffectedByHover(); }
330     bool childrenAffectedByActive() const { return hasRareData() && rareDataChildrenAffectedByActive(); }
331     bool childrenAffectedByDrag() const { return hasRareData() && rareDataChildrenAffectedByDrag(); }
332     bool childrenAffectedByPositionalRules() const { return hasRareData() && (rareDataChildrenAffectedByForwardPositionalRules() || rareDataChildrenAffectedByBackwardPositionalRules()); }
333     bool childrenAffectedByFirstChildRules() const { return hasRareData() && rareDataChildrenAffectedByFirstChildRules(); }
334     bool childrenAffectedByLastChildRules() const { return hasRareData() && rareDataChildrenAffectedByLastChildRules(); }
335     bool childrenAffectedByDirectAdjacentRules() const { return hasRareData() && rareDataChildrenAffectedByDirectAdjacentRules(); }
336     bool childrenAffectedByForwardPositionalRules() const { return hasRareData() && rareDataChildrenAffectedByForwardPositionalRules(); }
337     bool childrenAffectedByBackwardPositionalRules() const { return hasRareData() && rareDataChildrenAffectedByBackwardPositionalRules(); }
338     unsigned childIndex() const { return hasRareData() ? rareDataChildIndex() : 0; }
339
340     bool childrenSupportStyleSharing() const;
341
342     void setStyleAffectedByEmpty();
343     void setChildrenAffectedByFocus();
344     void setChildrenAffectedByHover();
345     void setChildrenAffectedByActive();
346     void setChildrenAffectedByDrag();
347     void setChildrenAffectedByFirstChildRules();
348     void setChildrenAffectedByLastChildRules();
349     void setChildrenAffectedByDirectAdjacentRules();
350     void setChildrenAffectedByForwardPositionalRules();
351     void setChildrenAffectedByBackwardPositionalRules();
352     void setChildIndex(unsigned);
353
354     void setIsInCanvasSubtree(bool);
355     bool isInCanvasSubtree() const;
356
357     bool isUpgradedCustomElement() { return customElementState() == Upgraded; }
358     bool isUnresolvedCustomElement() { return customElementState() == WaitingForUpgrade; }
359
360     AtomicString computeInheritedLanguage() const;
361     Locale& locale() const;
362
363     virtual void accessKeyAction(bool /*sendToAnyEvent*/) { }
364
365     virtual bool isURLAttribute(const Attribute&) const { return false; }
366     virtual bool isHTMLContentAttribute(const Attribute&) const { return false; }
367
368     KURL getURLAttribute(const QualifiedName&) const;
369     KURL getNonEmptyURLAttribute(const QualifiedName&) const;
370
371     virtual const AtomicString imageSourceURL() const;
372     virtual Image* imageContents() { return 0; }
373
374     virtual void focus(bool restorePreviousSelection = true, FocusType = FocusTypeNone);
375     virtual void updateFocusAppearance(bool restorePreviousSelection);
376     virtual void blur();
377     // Whether this element can receive focus at all. Most elements are not
378     // focusable but some elements, such as form controls and links, are. Unlike
379     // rendererIsFocusable(), this method may be called when layout is not up to
380     // date, so it must not use the renderer to determine focusability.
381     virtual bool supportsFocus() const;
382     // Whether the node can actually be focused.
383     bool isFocusable() const;
384     virtual bool isKeyboardFocusable() const;
385     virtual bool isMouseFocusable() const;
386     virtual void dispatchFocusEvent(Element* oldFocusedElement, FocusType);
387     virtual void dispatchBlurEvent(Element* newFocusedElement);
388     void dispatchFocusInEvent(const AtomicString& eventType, Element* oldFocusedElement);
389     void dispatchFocusOutEvent(const AtomicString& eventType, Element* newFocusedElement);
390
391     String innerText();
392     String outerText();
393     String innerHTML() const;
394     String outerHTML() const;
395     void setInnerHTML(const String&, ExceptionState&);
396     void setOuterHTML(const String&, ExceptionState&);
397
398     Element* insertAdjacentElement(const String& where, Element* newChild, ExceptionState&);
399     void insertAdjacentText(const String& where, const String& text, ExceptionState&);
400     void insertAdjacentHTML(const String& where, const String& html, ExceptionState&);
401
402     String textFromChildren();
403
404     virtual String title() const { return String(); }
405
406     virtual const AtomicString& shadowPseudoId() const;
407     void setShadowPseudoId(const AtomicString&);
408
409     LayoutSize minimumSizeForResizing() const;
410     void setMinimumSizeForResizing(const LayoutSize&);
411
412     virtual void didBecomeFullscreenElement() { }
413     virtual void willStopBeingFullscreenElement() { }
414
415     using Node::isFinishedParsingChildren; // make public for SelectorChecker
416
417     // Called by the parser when this element's close tag is reached,
418     // signaling that all child tags have been parsed and added.
419     // This is needed for <applet> and <object> elements, which can't lay themselves out
420     // until they know all of their nested <param>s. [Radar 3603191, 4040848].
421     // Also used for script elements and some SVG elements for similar purposes,
422     // but making parsing a special case in this respect should be avoided if possible.
423     virtual void finishParsingChildren();
424
425     void beginParsingChildren() { setIsFinishedParsingChildren(false); }
426
427     PseudoElement* pseudoElement(PseudoId) const;
428     RenderObject* pseudoElementRenderer(PseudoId) const;
429
430     virtual bool matchesReadOnlyPseudoClass() const { return false; }
431     virtual bool matchesReadWritePseudoClass() const { return false; }
432     bool matches(const String& selectors, ExceptionState&);
433     virtual bool shouldAppearIndeterminate() const { return false; }
434
435     DOMTokenList* classList();
436
437     DOMStringMap* dataset();
438
439     virtual bool isMediaElement() const { return false; }
440
441 #if ENABLE(INPUT_SPEECH)
442     virtual bool isInputFieldSpeechButtonElement() const { return false; }
443 #endif
444 #if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
445     virtual bool isDateTimeEditElement() const { return false; }
446     virtual bool isDateTimeFieldElement() const { return false; }
447     virtual bool isPickerIndicatorElement() const { return false; }
448 #endif
449
450     virtual bool isFormControlElement() const { return false; }
451     virtual bool isSpinButtonElement() const { return false; }
452     virtual bool isTextFormControl() const { return false; }
453     virtual bool isOptionalFormControl() const { return false; }
454     virtual bool isRequiredFormControl() const { return false; }
455     virtual bool isDefaultButtonForForm() const { return false; }
456     virtual bool willValidate() const { return false; }
457     virtual bool isValidFormControlElement() { return false; }
458     virtual bool isInRange() const { return false; }
459     virtual bool isOutOfRange() const { return false; }
460     virtual bool isFrameElementBase() const { return false; }
461     virtual bool isPasswordGeneratorButtonElement() const { return false; }
462     virtual bool isClearButtonElement() const { return false; }
463
464     virtual bool canContainRangeEndPoint() const OVERRIDE { return true; }
465
466     // Used for disabled form elements; if true, prevents mouse events from being dispatched
467     // to event listeners, and prevents DOMActivate events from being sent at all.
468     virtual bool isDisabledFormControl() const { return false; }
469
470     bool hasPendingResources() const;
471     void setHasPendingResources();
472     void clearHasPendingResources();
473     virtual void buildPendingResource() { };
474
475     enum {
476         ALLOW_KEYBOARD_INPUT = 1 << 0,
477         LEGACY_MOZILLA_REQUEST = 1 << 1,
478     };
479
480     void webkitRequestFullScreen(unsigned short flags);
481     bool containsFullScreenElement() const;
482     void setContainsFullScreenElement(bool);
483     void setContainsFullScreenElementOnAncestorsCrossingFrameBoundaries(bool);
484
485     // W3C API
486     void webkitRequestFullscreen();
487
488     bool isInTopLayer() const;
489     void setIsInTopLayer(bool);
490
491     void webkitRequestPointerLock();
492
493     bool isSpellCheckingEnabled() const;
494
495     // FIXME: public for RenderTreeBuilder, we shouldn't expose this though.
496     PassRefPtr<RenderStyle> styleForRenderer();
497
498     bool hasID() const;
499     bool hasClass() const;
500     const SpaceSplitString& classNames() const;
501
502     IntSize savedLayerScrollOffset() const;
503     void setSavedLayerScrollOffset(const IntSize&);
504
505     ActiveAnimations* activeAnimations() const;
506     ActiveAnimations* ensureActiveAnimations();
507     bool hasActiveAnimations() const;
508
509     InputMethodContext* inputMethodContext();
510     bool hasInputMethodContext() const;
511
512     void setPrefix(const AtomicString&, ExceptionState&);
513
514     void synchronizeAttribute(const AtomicString& localName) const;
515
516     MutableStylePropertySet* ensureMutableInlineStyle();
517     void clearMutableInlineStyleIfEmpty();
518
519 protected:
520     Element(const QualifiedName& tagName, Document* document, ConstructionType type)
521         : ContainerNode(document, type)
522         , m_tagName(tagName)
523     {
524         ScriptWrappable::init(this);
525     }
526
527     void addPropertyToPresentationAttributeStyle(MutableStylePropertySet*, CSSPropertyID, CSSValueID identifier);
528     void addPropertyToPresentationAttributeStyle(MutableStylePropertySet*, CSSPropertyID, double value, CSSPrimitiveValue::UnitTypes);
529     void addPropertyToPresentationAttributeStyle(MutableStylePropertySet*, CSSPropertyID, const String& value);
530
531     virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE;
532     virtual void removedFrom(ContainerNode*) OVERRIDE;
533     virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0) OVERRIDE;
534     virtual void removeAllEventListeners() OVERRIDE;
535
536     virtual void willRecalcStyle(StyleRecalcChange);
537     virtual void didRecalcStyle(StyleRecalcChange);
538     virtual PassRefPtr<RenderStyle> customStyleForRenderer();
539
540     virtual bool shouldRegisterAsNamedItem() const { return false; }
541     virtual bool shouldRegisterAsExtraNamedItem() const { return false; }
542
543     void clearTabIndexExplicitlyIfNeeded();
544     void setTabIndexExplicitly(short);
545     virtual short tabIndex() const OVERRIDE;
546     // Subclasses may override this method to affect focusability. Unlike
547     // supportsFocus, this method must be called on an up-to-date layout, so it
548     // may use the renderer to reason about focusability. This method cannot be
549     // moved to RenderObject because some focusable nodes don't have renderers,
550     // e.g., HTMLOptionElement.
551     virtual bool rendererIsFocusable() const;
552     PassRefPtr<HTMLCollection> ensureCachedHTMLCollection(CollectionType);
553     HTMLCollection* cachedHTMLCollection(CollectionType);
554
555     // classAttributeChanged() exists to share code between
556     // parseAttribute (called via setAttribute()) and
557     // svgAttributeChanged (called when element.className.baseValue is set)
558     void classAttributeChanged(const AtomicString& newClassString);
559
560     PassRefPtr<RenderStyle> originalStyleForRenderer();
561
562     Node* insertAdjacent(const String& where, Node* newChild, ExceptionState&);
563
564 private:
565     void styleAttributeChanged(const AtomicString& newStyleString, AttributeModificationReason);
566
567     void updatePresentationAttributeStyle();
568
569     void inlineStyleChanged();
570     PropertySetCSSStyleDeclaration* inlineStyleCSSOMWrapper();
571     void setInlineStyleFromString(const AtomicString&);
572
573     StyleRecalcChange recalcOwnStyle(StyleRecalcChange);
574     void recalcChildStyle(StyleRecalcChange);
575
576     // FIXME: These methods should all be renamed to something better than "check",
577     // since it's not clear that they alter the style bits of siblings and children.
578     void checkForChildrenAdjacentRuleChanges();
579     void checkForSiblingStyleChanges(bool finishedParsingCallback, Node* beforeChange, Node* afterChange, int childCountDelta);
580     inline void checkForEmptyStyleChange(RenderStyle*);
581
582     void updatePseudoElement(PseudoId, StyleRecalcChange);
583
584     inline void createPseudoElementIfNeeded(PseudoId);
585
586     // FIXME: Everyone should allow author shadows.
587     virtual bool areAuthorShadowsAllowed() const { return true; }
588     virtual void didAddUserAgentShadowRoot(ShadowRoot&) { }
589     virtual bool alwaysCreateUserAgentShadowRoot() const { return false; }
590
591     // FIXME: Remove the need for Attr to call willModifyAttribute/didModifyAttribute.
592     friend class Attr;
593
594     enum SynchronizationOfLazyAttribute { NotInSynchronizationOfLazyAttribute = 0, InSynchronizationOfLazyAttribute };
595
596     void didAddAttribute(const QualifiedName&, const AtomicString&);
597     void willModifyAttribute(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue);
598     void didModifyAttribute(const QualifiedName&, const AtomicString&);
599     void didRemoveAttribute(const QualifiedName&);
600
601     void synchronizeAttribute(const QualifiedName&) const;
602
603     void updateId(const AtomicString& oldId, const AtomicString& newId);
604     void updateId(TreeScope&, const AtomicString& oldId, const AtomicString& newId);
605     void updateName(const AtomicString& oldName, const AtomicString& newName);
606     void updateLabel(TreeScope&, const AtomicString& oldForAttributeValue, const AtomicString& newForAttributeValue);
607
608     void scrollByUnits(int units, ScrollGranularity);
609
610     virtual NodeType nodeType() const OVERRIDE FINAL;
611     virtual bool childTypeAllowed(NodeType) const OVERRIDE FINAL;
612
613     void setAttributeInternal(size_t index, const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
614     void addAttributeInternal(const QualifiedName&, const AtomicString& value, SynchronizationOfLazyAttribute);
615     void removeAttributeInternal(size_t index, SynchronizationOfLazyAttribute);
616     void attributeChangedFromParserOrByCloning(const QualifiedName&, const AtomicString&, AttributeModificationReason);
617
618 #ifndef NDEBUG
619     virtual void formatForDebugger(char* buffer, unsigned length) const OVERRIDE;
620 #endif
621
622     bool pseudoStyleCacheIsInvalid(const RenderStyle* currentStyle, RenderStyle* newStyle);
623
624     void cancelFocusAppearanceUpdate();
625
626     virtual RenderStyle* virtualComputedStyle(PseudoId pseudoElementSpecifier = NOPSEUDO) OVERRIDE { return computedStyle(pseudoElementSpecifier); }
627
628     inline void updateCallbackSelectors(RenderStyle* oldStyle, RenderStyle* newStyle);
629     inline void removeCallbackSelectors();
630     inline void addCallbackSelectors();
631
632     // cloneNode is private so that non-virtual cloneElementWithChildren and cloneElementWithoutChildren
633     // are used instead.
634     virtual PassRefPtr<Node> cloneNode(bool deep) OVERRIDE;
635     virtual PassRefPtr<Element> cloneElementWithoutAttributesAndChildren();
636
637     QualifiedName m_tagName;
638     bool rareDataStyleAffectedByEmpty() const;
639     bool rareDataChildrenAffectedByFocus() const;
640     bool rareDataChildrenAffectedByHover() const;
641     bool rareDataChildrenAffectedByActive() const;
642     bool rareDataChildrenAffectedByDrag() const;
643     bool rareDataChildrenAffectedByFirstChildRules() const;
644     bool rareDataChildrenAffectedByLastChildRules() const;
645     bool rareDataChildrenAffectedByDirectAdjacentRules() const;
646     bool rareDataChildrenAffectedByForwardPositionalRules() const;
647     bool rareDataChildrenAffectedByBackwardPositionalRules() const;
648     unsigned rareDataChildIndex() const;
649
650     SpellcheckAttributeState spellcheckAttributeState() const;
651
652     void updateNamedItemRegistration(const AtomicString& oldName, const AtomicString& newName);
653     void updateExtraNamedItemRegistration(const AtomicString& oldName, const AtomicString& newName);
654
655     void createUniqueElementData();
656
657     bool shouldInvalidateDistributionWhenAttributeChanged(ElementShadow*, const QualifiedName&, const AtomicString&);
658
659     ElementRareData* elementRareData() const;
660     ElementRareData& ensureElementRareData();
661
662     void detachAllAttrNodesFromElement();
663     void detachAttrNodeFromElementWithValue(Attr*, const AtomicString& value);
664     void detachAttrNodeAtIndex(Attr*, size_t index);
665
666     bool isJavaScriptURLAttribute(const Attribute&) const;
667
668     RefPtr<ElementData> m_elementData;
669 };
670
671 DEFINE_NODE_TYPE_CASTS(Element, isElementNode());
672
673 inline bool isDisabledFormControl(const Node* node)
674 {
675     return node->isElementNode() && toElement(node)->isDisabledFormControl();
676 }
677
678 inline bool Node::hasTagName(const QualifiedName& name) const
679 {
680     return isElementNode() && toElement(this)->hasTagName(name);
681 }
682
683 inline Element* Node::parentElement() const
684 {
685     ContainerNode* parent = parentNode();
686     return parent && parent->isElementNode() ? toElement(parent) : 0;
687 }
688
689 inline bool Element::fastHasAttribute(const QualifiedName& name) const
690 {
691     ASSERT(fastAttributeLookupAllowed(name));
692     return elementData() && getAttributeItem(name);
693 }
694
695 inline const AtomicString& Element::fastGetAttribute(const QualifiedName& name) const
696 {
697     ASSERT(fastAttributeLookupAllowed(name));
698     if (elementData()) {
699         if (const Attribute* attribute = getAttributeItem(name))
700             return attribute->value();
701     }
702     return nullAtom;
703 }
704
705 inline bool Element::hasAttributesWithoutUpdate() const
706 {
707     return elementData() && !elementData()->isEmpty();
708 }
709
710 inline const AtomicString& Element::idForStyleResolution() const
711 {
712     ASSERT(hasID());
713     return elementData()->idForStyleResolution();
714 }
715
716 inline bool Element::isIdAttributeName(const QualifiedName& attributeName) const
717 {
718     // FIXME: This check is probably not correct for the case where the document has an id attribute
719     // with a non-null namespace, because it will return false, a false negative, if the prefixes
720     // don't match but the local name and namespace both do. However, since this has been like this
721     // for a while and the code paths may be hot, we'll have to measure performance if we fix it.
722     return attributeName == HTMLNames::idAttr;
723 }
724
725 inline const AtomicString& Element::getIdAttribute() const
726 {
727     return hasID() ? fastGetAttribute(HTMLNames::idAttr) : nullAtom;
728 }
729
730 inline const AtomicString& Element::getNameAttribute() const
731 {
732     return hasName() ? fastGetAttribute(HTMLNames::nameAttr) : nullAtom;
733 }
734
735 inline const AtomicString& Element::getClassAttribute() const
736 {
737     if (!hasClass())
738         return nullAtom;
739     if (isSVGElement())
740         return getAttribute(HTMLNames::classAttr);
741     return fastGetAttribute(HTMLNames::classAttr);
742 }
743
744 inline bool Element::shouldIgnoreAttributeCase() const
745 {
746     return isHTMLElement() && document().isHTMLDocument();
747 }
748
749 inline void Element::setIdAttribute(const AtomicString& value)
750 {
751     setAttribute(HTMLNames::idAttr, value);
752 }
753
754 inline const SpaceSplitString& Element::classNames() const
755 {
756     ASSERT(hasClass());
757     ASSERT(elementData());
758     return elementData()->classNames();
759 }
760
761 inline size_t Element::attributeCount() const
762 {
763     ASSERT(elementData());
764     return elementData()->length();
765 }
766
767 inline const Attribute* Element::attributeItem(unsigned index) const
768 {
769     ASSERT(elementData());
770     return elementData()->attributeItem(index);
771 }
772
773 inline const Attribute* Element::getAttributeItem(const QualifiedName& name) const
774 {
775     ASSERT(elementData());
776     return elementData()->getAttributeItem(name);
777 }
778
779 inline bool Element::hasID() const
780 {
781     return elementData() && elementData()->hasID();
782 }
783
784 inline bool Element::hasClass() const
785 {
786     return elementData() && elementData()->hasClass();
787 }
788
789 inline UniqueElementData* Element::ensureUniqueElementData()
790 {
791     if (!elementData() || !elementData()->isUnique())
792         createUniqueElementData();
793     return static_cast<UniqueElementData*>(m_elementData.get());
794 }
795
796 // Put here to make them inline.
797 inline bool Node::hasID() const
798 {
799     return isElementNode() && toElement(this)->hasID();
800 }
801
802 inline bool Node::hasClass() const
803 {
804     return isElementNode() && toElement(this)->hasClass();
805 }
806
807 inline Node::InsertionNotificationRequest Node::insertedInto(ContainerNode* insertionPoint)
808 {
809     ASSERT(insertionPoint->inDocument() || isContainerNode());
810     if (insertionPoint->inDocument())
811         setFlag(InDocumentFlag);
812     if (parentOrShadowHostNode()->isInShadowTree())
813         setFlag(IsInShadowTreeFlag);
814     if (childNeedsDistributionRecalc() && !insertionPoint->childNeedsDistributionRecalc())
815         insertionPoint->markAncestorsWithChildNeedsDistributionRecalc();
816     return InsertionDone;
817 }
818
819 inline void Node::removedFrom(ContainerNode* insertionPoint)
820 {
821     ASSERT(insertionPoint->inDocument() || isContainerNode());
822     if (insertionPoint->inDocument())
823         clearFlag(InDocumentFlag);
824     if (isInShadowTree() && !treeScope().rootNode().isShadowRoot())
825         clearFlag(IsInShadowTreeFlag);
826 }
827
828 inline void Element::invalidateStyleAttribute()
829 {
830     ASSERT(elementData());
831     elementData()->m_styleAttributeIsDirty = true;
832 }
833
834 inline const StylePropertySet* Element::presentationAttributeStyle()
835 {
836     if (!elementData())
837         return 0;
838     if (elementData()->m_presentationAttributeStyleIsDirty)
839         updatePresentationAttributeStyle();
840     // Need to call elementData() again since updatePresentationAttributeStyle()
841     // might swap it with a UniqueElementData.
842     return elementData()->presentationAttributeStyle();
843 }
844
845 inline void Element::setTagNameForCreateElementNS(const QualifiedName& tagName)
846 {
847     // We expect this method to be called only to reset the prefix.
848     ASSERT(tagName.localName() == m_tagName.localName());
849     ASSERT(tagName.namespaceURI() == m_tagName.namespaceURI());
850     m_tagName = tagName;
851 }
852
853 inline bool isShadowHost(const Node* node)
854 {
855     return node && node->isElementNode() && toElement(node)->shadow();
856 }
857
858 inline bool isShadowHost(const Element* element)
859 {
860     return element && element->shadow();
861 }
862
863 } // namespace
864
865 #endif