1 /* 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. 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 void setInnerText(const String&, ExceptionState&); 51 void setOuterText(const String&, ExceptionState&); 52 53 Element* insertAdjacentElement(const String& where, Element* newChild, ExceptionState&); 54 void insertAdjacentText(const String& where, const String& text, ExceptionState&); 55 56 virtual bool hasCustomFocusLogic() const; 57 virtual bool supportsFocus() const; 58 59 String contentEditable() const; 60 void setContentEditable(const String&, ExceptionState&); 61 62 virtual bool draggable() const; 63 void setDraggable(bool); 64 65 bool spellcheck() const; 66 void setSpellcheck(bool); 67 68 bool translate() const; 69 void setTranslate(bool); 70 71 void click(); 72 73 virtual void accessKeyAction(bool sendMouseEvents); 74 75 bool ieForbidsInsertHTML() const; 76 77 virtual bool rendererIsNeeded(const RenderStyle&); 78 virtual RenderObject* createRenderer(RenderStyle*); 79 formOwner()80 virtual HTMLFormElement* formOwner() const { return 0; } 81 82 HTMLFormElement* findFormAncestor() const; 83 84 bool hasDirectionAuto() const; 85 TextDirection directionalityIfhasDirAutoAttribute(bool& isAuto) const; 86 isHTMLUnknownElement()87 virtual bool isHTMLUnknownElement() const { return false; } 88 isLabelable()89 virtual bool isLabelable() const { return false; } 90 // http://www.whatwg.org/specs/web-apps/current-work/multipage/elements.html#interactive-content 91 virtual bool isInteractiveContent() const; 92 virtual void defaultEventHandler(Event*) OVERRIDE; 93 94 protected: 95 HTMLElement(const QualifiedName& tagName, Document&, ConstructionType); 96 97 void addHTMLLengthToStyle(MutableStylePropertySet*, CSSPropertyID, const String& value); 98 void addHTMLColorToStyle(MutableStylePropertySet*, CSSPropertyID, const String& color); 99 100 void applyAlignmentAttributeToStyle(const AtomicString&, MutableStylePropertySet*); 101 void applyBorderAttributeToStyle(const AtomicString&, MutableStylePropertySet*); 102 103 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE; 104 virtual bool isPresentationAttribute(const QualifiedName&) const OVERRIDE; 105 virtual void collectStyleForPresentationAttribute(const QualifiedName&, const AtomicString&, MutableStylePropertySet*) OVERRIDE; 106 unsigned parseBorderWidthAttribute(const AtomicString&) const; 107 108 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); 109 void calculateAndAdjustDirectionality(); 110 111 private: 112 virtual String nodeName() const OVERRIDE FINAL; 113 114 void mapLanguageAttributeToLocale(const AtomicString&, MutableStylePropertySet*); 115 116 PassRefPtr<DocumentFragment> textToFragment(const String&, ExceptionState&); 117 118 void dirAttributeChanged(const AtomicString&); 119 void adjustDirectionalityIfNeededAfterChildAttributeChanged(Element* child); 120 void adjustDirectionalityIfNeededAfterChildrenChanged(Node* beforeChange, int childCountDelta); 121 TextDirection directionality(Node** strongDirectionalityTextNode= 0) const; 122 123 TranslateAttributeMode translateAttributeMode() const; 124 125 const AtomicString& eventNameForAttributeName(const QualifiedName& attrName) const; 126 127 void handleKeypressEvent(KeyboardEvent*); 128 bool supportsSpatialNavigationFocus() const; 129 }; 130 131 DEFINE_NODE_TYPE_CASTS(HTMLElement, isHTMLElement()); 132 133 inline HTMLElement::HTMLElement(const QualifiedName& tagName, Document& document, ConstructionType type = CreateHTMLElement) 134 : Element(tagName, &document, type) 135 { 136 ASSERT(!tagName.localName().isNull()); 137 ScriptWrappable::init(this); 138 } 139 140 } // namespace WebCore 141 142 #endif // HTMLElement_h 143