1/* 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 4 * (C) 2000 Dirk Mueller (mueller@kde.org) 5 * Copyright (C) 2004, 2005, 2006, 2010, 2011 Apple Inc. All rights reserved. 6 * Copyright (C) 2010 Google 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 HTMLOptionElement_h 26#define HTMLOptionElement_h 27 28#include "HTMLElement.h" 29 30namespace WebCore { 31 32class HTMLDataListElement; 33class HTMLSelectElement; 34 35class HTMLOptionElement FINAL : public HTMLElement { 36public: 37 static PassRefPtr<HTMLOptionElement> create(Document*); 38 static PassRefPtr<HTMLOptionElement> create(const QualifiedName&, Document*); 39 static PassRefPtr<HTMLOptionElement> createForJSConstructor(Document*, const String& data, const String& value, 40 bool defaultSelected, bool selected, ExceptionCode&); 41 42 virtual String text() const; 43 void setText(const String&, ExceptionCode&); 44 45 int index() const; 46 47 String value() const; 48 void setValue(const String&); 49 50 bool selected(); 51 void setSelected(bool); 52 53#if ENABLE(DATALIST_ELEMENT) 54 HTMLDataListElement* ownerDataListElement() const; 55#endif 56 HTMLSelectElement* ownerSelectElement() const; 57 58 String label() const; 59 void setLabel(const String&); 60 61 bool ownElementDisabled() const { return m_disabled; } 62 63 virtual bool isDisabledFormControl() const OVERRIDE; 64 65 String textIndentedToRespectGroupLabel() const; 66 67 void setSelectedState(bool); 68 69private: 70 HTMLOptionElement(const QualifiedName&, Document*); 71 72 virtual bool supportsFocus() const OVERRIDE; 73 virtual bool isFocusable() const OVERRIDE; 74 virtual bool rendererIsNeeded(const NodeRenderingContext&) { return false; } 75 virtual void attach(const AttachContext& = AttachContext()) OVERRIDE; 76 virtual void detach(const AttachContext& = AttachContext()) OVERRIDE; 77 78 virtual void parseAttribute(const QualifiedName&, const AtomicString&) OVERRIDE; 79 80 virtual InsertionNotificationRequest insertedInto(ContainerNode*) OVERRIDE; 81 virtual void accessKeyAction(bool); 82 83 virtual void childrenChanged(bool changedByParser = false, Node* beforeChange = 0, Node* afterChange = 0, int childCountDelta = 0); 84 85 // <option> never has a renderer so we manually manage a cached style. 86 void updateNonRenderStyle(); 87 virtual RenderStyle* nonRendererStyle() const OVERRIDE; 88 virtual PassRefPtr<RenderStyle> customStyleForRenderer() OVERRIDE; 89 90 void didRecalcStyle(StyleChange) OVERRIDE; 91 92 String collectOptionInnerText() const; 93 94 bool m_disabled; 95 bool m_isSelected; 96 RefPtr<RenderStyle> m_style; 97}; 98 99HTMLOptionElement* toHTMLOptionElement(Node*); 100const HTMLOptionElement* toHTMLOptionElement(const Node*); 101void toHTMLOptionElement(const HTMLOptionElement*); // This overload will catch anyone doing an unnecessary cast. 102 103#ifdef NDEBUG 104 105// The debug versions of these, with assertions, are not inlined. 106 107inline HTMLOptionElement* toHTMLOptionElement(Node* node) 108{ 109 return static_cast<HTMLOptionElement*>(node); 110} 111 112inline const HTMLOptionElement* toHTMLOptionElement(const Node* node) 113{ 114 return static_cast<const HTMLOptionElement*>(node); 115} 116 117#endif 118 119} // namespace 120 121#endif 122