2 * Copyright (c) 2010 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "core/html/HTMLOutputElement.h"
34 #include "HTMLNames.h"
35 #include "bindings/v8/ExceptionStatePlaceholder.h"
39 inline HTMLOutputElement::HTMLOutputElement(Document& document, HTMLFormElement* form)
40 : HTMLFormControlElement(HTMLNames::outputTag, document, form)
41 , m_isDefaultValueMode(true)
43 , m_tokens(DOMSettableTokenList::create())
45 ScriptWrappable::init(this);
48 PassRefPtrWillBeRawPtr<HTMLOutputElement> HTMLOutputElement::create(Document& document, HTMLFormElement* form)
50 return adoptRefWillBeRefCountedGarbageCollected(new HTMLOutputElement(document, form));
53 const AtomicString& HTMLOutputElement::formControlType() const
55 DEFINE_STATIC_LOCAL(const AtomicString, output, ("output", AtomicString::ConstructFromLiteral));
59 bool HTMLOutputElement::supportsFocus() const
61 return HTMLElement::supportsFocus();
64 void HTMLOutputElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
66 if (name == HTMLNames::forAttr)
69 HTMLFormControlElement::parseAttribute(name, value);
72 DOMSettableTokenList* HTMLOutputElement::htmlFor() const
74 return m_tokens.get();
77 void HTMLOutputElement::setFor(const AtomicString& value)
79 m_tokens->setValue(value);
82 void HTMLOutputElement::childrenChanged(bool createdByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
84 HTMLFormControlElement::childrenChanged(createdByParser, beforeChange, afterChange, childCountDelta);
86 if (m_isDefaultValueMode)
87 m_defaultValue = textContent();
90 void HTMLOutputElement::resetImpl()
92 // The reset algorithm for output elements is to set the element's
93 // value mode flag to "default" and then to set the element's textContent
94 // attribute to the default value.
95 if (m_defaultValue == value())
97 setTextContent(m_defaultValue);
98 m_isDefaultValueMode = true;
101 String HTMLOutputElement::value() const
103 return textContent();
106 void HTMLOutputElement::setValue(const String& value)
108 // The value mode flag set to "value" when the value attribute is set.
109 m_isDefaultValueMode = false;
110 if (value == this->value())
112 setTextContent(value);
115 String HTMLOutputElement::defaultValue() const
117 return m_defaultValue;
120 void HTMLOutputElement::setDefaultValue(const String& value)
122 if (m_defaultValue == value)
124 m_defaultValue = value;
125 // The spec requires the value attribute set to the default value
126 // when the element's value mode flag to "default".
127 if (m_isDefaultValueMode)
128 setTextContent(value);
132 void HTMLOutputElement::trace(Visitor* visitor)
134 visitor->trace(m_tokens);
135 HTMLFormControlElement::trace(visitor);