1 /* 2 * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org) 3 * (C) 1999 Antti Koivisto (koivisto (at) kde.org) 4 * Copyright (C) 2004, 2005, 2006, 2007, 2009 Apple Inc. All rights reserved. 5 * 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. 10 * 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. 15 * 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. 20 * 21 */ 22 23 #ifndef HTMLElement_h 24 #define HTMLElement_h 25 26 #include "core/dom/Element.h" 27 28 namespace WebCore { 29 30 class DocumentFragment; 31 class HTMLCollection; 32 class HTMLFormElement; 33 class ExceptionState; 34 35 enum TranslateAttributeMode { 36 TranslateAttributeYes, 37 TranslateAttributeNo, 38 TranslateAttributeInherit 39 }; 40 41 class HTMLElement : public Element { 42 public: 43 static PassRefPtr<HTMLElement> create(const QualifiedName& tagName, Document*); 44 45 virtual String title() const OVERRIDE FINAL; 46 47 virtual short tabIndex() const; 48 void setTabIndex(int); 49 50 String innerHTML() const; 51 String outerHTML() const; 52 void setInnerHTML(const String&, ExceptionState&); 53 void setOuterHTML(const String&, ExceptionState&); 54 void setInnerText(const String&, ExceptionState&); 55 void setOuterText(const String&, ExceptionState&); 56 57 Element* insertAdjacentElement(const String& where, Element* newChild, ExceptionState&); 58 void insertAdjacentHTML(const String& where, const String& html, ExceptionState&); 59 void insertAdjacentText(const String& where, const String& text, ExceptionState&); 60 61 virtual bool hasCustomFocusLogic() const; 62 virtual bool supportsFocus() const; 63 64 String contentEditable() const; 65 void setContentEditable(const String&, ExceptionState&); 66 67 virtual bool draggable() const; 68 void setDraggable(bool); 69 70 bool spellcheck() const; 71 void setSpellcheck(bool); 72 73 bool translate() const; 74 void setTranslate(bool); 75 76 void click(); 77 78 virtual void accessKeyAction(bool sendMouseEvents); 79 80 bool ieForbidsInsertHTML() const; 81 82 virtual bool rendererIsNeeded(const NodeRenderingContext&); 83 virtual RenderObject* createRenderer(RenderStyle*); 84 85 HTMLFormElement* form() const { return virtualForm(); } 86 87 HTMLFormElement* findFormAncestor() const; 88 89 bool hasDirectionAuto() const; 90 TextDirection directionalityIfhasDirAutoAttribute(bool& isAuto) const; 91 92 virtual bool isHTMLUnknownElement() const { return false; } 93 94 virtual bool isLabelable() const { return false; } 95 96 virtual void defaultEventHandler(Event*) OVERRIDE; 97 98 protected: 99 HTMLElement(const QualifiedName& tagName, Document*, ConstructionType); 100 101 void addHTMLLengthToStyle(MutableStylePropertySet*, CSSPropertyID, const String& value); 102 void addHTMLColorToStyle(MutableStylePropertySet*, CSSPropertyID, const String& color); 103 104 void applyAlignmentAttributeToStyle(const AtomicString&, MutableStylePropertySet*); 105 void applyBorderAttributeToStyle(const AtomicString&, MutableStylePropertySet*); 106 107 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE; 108 virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE; 109 virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE; 110 unsigned parseBorderWidthAttribute(const AtomicString&) const; 111 112 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); 113 void calculateAndAdjustDirectionality(); 114 115 private: 116 virtual String nodeName() const OVERRIDE FINAL; 117 118 void mapLanguageAttributeToLocale(const AtomicString&, MutableStylePropertySet*); 119 120 virtual HTMLFormElement* virtualForm() const; 121 122 Node* insertAdjacent(const String& where, Node* newChild, ExceptionState&); 123 PassRefPtr<DocumentFragment> textToFragment(const String&, ExceptionState&); 124 125 void dirAttributeChanged(const AtomicString&); 126 void adjustDirectionalityIfNeededAfterChildAttributeChanged(Element* child); 127 void adjustDirectionalityIfNeededAfterChildrenChanged(Node* beforeChange, int childCountDelta); 128 TextDirection directionality(Node** strongDirectionalityTextNode= 0) const; 129 130 TranslateAttributeMode translateAttributeMode() const; 131 132 AtomicString eventNameForAttributeName(const QualifiedName& attrName) const; 133 134 void handleKeypressEvent(KeyboardEvent*); 135 bool supportsSpatialNavigationFocus() const; 136 }; 137 138 inline HTMLElement* toHTMLElement(Node* node) 139 { 140 ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isHTMLElement()); 141 return static_cast<HTMLElement*>(node); 142 } 143 144 inline const HTMLElement* toHTMLElement(const Node* node) 145 { 146 ASSERT_WITH_SECURITY_IMPLICATION(!node || node->isHTMLElement()); 147 return static_cast<const HTMLElement*>(node); 148 } 149 150 // This will catch anyone doing an unnecessary cast. 151 void toHTMLElement(const HTMLElement*); 152 153 inline HTMLElement::HTMLElement(const QualifiedName& tagName, Document* document, ConstructionType type = CreateHTMLElement) 154 : Element(tagName, document, type) 155 { 156 ASSERT(tagName.localName().impl()); 157 ScriptWrappable::init(this); 158 } 159 160 } // namespace WebCore 161 162 #endif // HTMLElement_h 163