2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2009 Apple Inc. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
26 #include "core/dom/Element.h"
30 class DocumentFragment;
32 class HTMLFormElement;
35 enum TranslateAttributeMode {
36 TranslateAttributeYes,
38 TranslateAttributeInherit
41 class HTMLElement : public Element {
43 DECLARE_ELEMENT_FACTORY_WITH_TAGNAME(HTMLElement);
45 virtual String title() const OVERRIDE FINAL;
46 virtual short tabIndex() const OVERRIDE;
48 void setInnerText(const String&, ExceptionState&);
49 void setOuterText(const String&, ExceptionState&);
51 virtual bool hasCustomFocusLogic() const;
53 String contentEditable() const;
54 void setContentEditable(const String&, ExceptionState&);
56 virtual bool draggable() const;
57 void setDraggable(bool);
59 bool spellcheck() const;
60 void setSpellcheck(bool);
62 bool translate() const;
63 void setTranslate(bool);
65 const AtomicString& dir();
66 void setDir(const AtomicString&);
70 virtual void accessKeyAction(bool sendMouseEvents) OVERRIDE;
72 bool ieForbidsInsertHTML() const;
74 virtual HTMLFormElement* formOwner() const { return 0; }
76 HTMLFormElement* findFormAncestor() const;
78 bool hasDirectionAuto() const;
79 TextDirection directionalityIfhasDirAutoAttribute(bool& isAuto) const;
81 virtual bool isHTMLUnknownElement() const { return false; }
82 virtual bool isPluginElement() const { return false; }
84 virtual bool isLabelable() const { return false; }
85 // http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#interactive-content
86 virtual bool isInteractiveContent() const;
87 virtual void defaultEventHandler(Event*) OVERRIDE;
89 static const AtomicString& eventNameForAttributeName(const QualifiedName& attrName);
91 virtual bool matchesReadOnlyPseudoClass() const OVERRIDE;
92 virtual bool matchesReadWritePseudoClass() const OVERRIDE;
94 static const AtomicString& eventParameterName();
97 HTMLElement(const QualifiedName& tagName, Document&, ConstructionType);
99 void addHTMLLengthToStyle(MutableStylePropertySet*, CSSPropertyID, const String& value);
100 void addHTMLColorToStyle(MutableStylePropertySet*, CSSPropertyID, const String& color);
102 void applyAlignmentAttributeToStyle(const AtomicString&, MutableStylePropertySet*);
103 void applyBorderAttributeToStyle(const AtomicString&, MutableStylePropertySet*);
105 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE;
106 virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE;
107 virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE;
108 unsigned parseBorderWidthAttribute(const AtomicString&) const;
110 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0) OVERRIDE;
111 void calculateAndAdjustDirectionality();
114 virtual String nodeName() const OVERRIDE FINAL;
116 void mapLanguageAttributeToLocale(const AtomicString&, MutableStylePropertySet*);
118 PassRefPtrWillBeRawPtr<DocumentFragment> textToFragment(const String&, ExceptionState&);
120 void dirAttributeChanged(const AtomicString&);
121 void adjustDirectionalityIfNeededAfterChildAttributeChanged(Element* child);
122 void adjustDirectionalityIfNeededAfterChildrenChanged(Node* beforeChange, int childCountDelta);
123 TextDirection directionality(Node** strongDirectionalityTextNode= 0) const;
125 TranslateAttributeMode translateAttributeMode() const;
127 void handleKeypressEvent(KeyboardEvent*);
130 DEFINE_ELEMENT_TYPE_CASTS(HTMLElement, isHTMLElement());
132 template <> inline bool isElementOfType<const HTMLElement>(const Node& node) { return node.isHTMLElement(); }
133 template <typename T> bool isElementOfType(const HTMLElement&);
134 template <> inline bool isElementOfType<const HTMLElement>(const HTMLElement&) { return true; }
136 inline HTMLElement::HTMLElement(const QualifiedName& tagName, Document& document, ConstructionType type = CreateHTMLElement)
137 : Element(tagName, &document, type)
139 ASSERT(!tagName.localName().isNull());
140 ScriptWrappable::init(this);
143 // This requires isHTML*Element(const Element&) and isHTML*Element(const HTMLElement&).
144 // When the input element is an HTMLElement, we don't need to check the namespace URI, just the local name.
145 #define DEFINE_HTMLELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType) \
146 inline bool is##thisType(const thisType* element); \
147 inline bool is##thisType(const thisType& element); \
148 inline bool is##thisType(const HTMLElement* element) { return element && is##thisType(*element); } \
149 inline bool is##thisType(const Element* element) { return element && is##thisType(*element); } \
150 inline bool is##thisType(const Node& node) { return node.isElementNode() ? is##thisType(toElement(node)) : false; } \
151 inline bool is##thisType(const Node* node) { return node && node->isElementNode() ? is##thisType(*toElement(node)) : false; } \
152 template<typename T> inline bool is##thisType(const PassRefPtr<T>& node) { return is##thisType(node.get()); } \
153 template<typename T> inline bool is##thisType(const RefPtr<T>& node) { return is##thisType(node.get()); } \
154 template <> inline bool isElementOfType<const thisType>(const HTMLElement& element) { return is##thisType(element); } \
155 DEFINE_ELEMENT_TYPE_CASTS_WITH_FUNCTION(thisType)
157 } // namespace WebCore
159 #include "core/HTMLElementTypeHelpers.h"
161 #endif // HTMLElement_h