/* * Copyright (C) 1999 Lars Knoll (knoll@kde.org) * (C) 1999 Antti Koivisto (koivisto@kde.org) * (C) 2001 Dirk Mueller (mueller@kde.org) * (C) 2006 Alexey Proskuryakov (ap@nypop.com) * Copyright (C) 2004, 2005, 2006, 2010 Apple Inc. All rights reserved. * Copyright (C) 2010 Google Inc. All rights reserved. * Copyright (C) 2011 Motorola Mobility, Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public License * along with this library; see the file COPYING.LIB. If not, write to * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301, USA. * */ #include "config.h" #include "HTMLOptionElement.h" #include "Attribute.h" #include "Document.h" #include "ExceptionCode.h" #include "HTMLDataListElement.h" #include "HTMLNames.h" #include "HTMLParserIdioms.h" #include "HTMLSelectElement.h" #include "NodeRenderStyle.h" #include "NodeRenderingContext.h" #include "RenderMenuList.h" #include "RenderTheme.h" #include "ScriptElement.h" #include "StyleResolver.h" #include "Text.h" #include #include #include namespace WebCore { using namespace HTMLNames; HTMLOptionElement::HTMLOptionElement(const QualifiedName& tagName, Document* document) : HTMLElement(tagName, document) , m_disabled(false) , m_isSelected(false) { ASSERT(hasTagName(optionTag)); setHasCustomCallbacks(); } PassRefPtr HTMLOptionElement::create(Document* document) { return adoptRef(new HTMLOptionElement(optionTag, document)); } PassRefPtr HTMLOptionElement::create(const QualifiedName& tagName, Document* document) { return adoptRef(new HTMLOptionElement(tagName, document)); } PassRefPtr HTMLOptionElement::createForJSConstructor(Document* document, const String& data, const String& value, bool defaultSelected, bool selected, ExceptionCode& ec) { RefPtr element = adoptRef(new HTMLOptionElement(optionTag, document)); RefPtr text = Text::create(document, data.isNull() ? "" : data); ec = 0; element->appendChild(text.release(), ec); if (ec) return 0; if (!value.isNull()) element->setValue(value); if (defaultSelected) element->setAttribute(selectedAttr, emptyAtom); element->setSelected(selected); return element.release(); } void HTMLOptionElement::attach() { HTMLElement::attach(); // If after attaching nothing called styleForRenderer() on this node we // manually cache the value. This happens if our parent doesn't have a // renderer like or if it doesn't allow children like