HTMLOutputElement.cpp [plain text]
#include "config.h"
#include "HTMLOutputElement.h"
#include "HTMLFormElement.h"
#include "HTMLNames.h"
namespace WebCore {
inline HTMLOutputElement::HTMLOutputElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form)
: HTMLFormControlElement(tagName, document, form)
, m_isDefaultValueMode(true)
, m_isSetTextContentInProgress(false)
, m_defaultValue("")
, m_tokens(DOMSettableTokenList::create())
{
}
PassRefPtr<HTMLOutputElement> HTMLOutputElement::create(const QualifiedName& tagName, Document* document, HTMLFormElement* form)
{
return adoptRef(new HTMLOutputElement(tagName, document, form));
}
const AtomicString& HTMLOutputElement::formControlType() const
{
DEFINE_STATIC_LOCAL(const AtomicString, output, ("output"));
return output;
}
bool HTMLOutputElement::supportsFocus() const
{
return Node::supportsFocus() && !disabled();
}
void HTMLOutputElement::parseAttribute(Attribute* attr)
{
if (attr->name() == HTMLNames::forAttr)
setFor(attr->value());
else
HTMLFormControlElement::parseAttribute(attr);
}
DOMSettableTokenList* HTMLOutputElement::htmlFor() const
{
return m_tokens.get();
}
void HTMLOutputElement::setFor(const String& value)
{
m_tokens->setValue(value);
}
void HTMLOutputElement::childrenChanged(bool createdByParser, Node* beforeChange, Node* afterChange, int childCountDelta)
{
HTMLFormControlElement::childrenChanged(createdByParser, beforeChange, afterChange, childCountDelta);
if (createdByParser || m_isSetTextContentInProgress) {
m_isSetTextContentInProgress = false;
return;
}
if (m_isDefaultValueMode)
m_defaultValue = textContent();
}
void HTMLOutputElement::reset()
{
m_isDefaultValueMode = true;
if (m_defaultValue == value())
return;
setTextContentInternal(m_defaultValue);
}
String HTMLOutputElement::value() const
{
return textContent();
}
void HTMLOutputElement::setValue(const String& value)
{
m_isDefaultValueMode = false;
if (value == this->value())
return;
setTextContentInternal(value);
}
String HTMLOutputElement::defaultValue() const
{
return m_defaultValue;
}
void HTMLOutputElement::setDefaultValue(const String& value)
{
if (m_defaultValue == value)
return;
m_defaultValue = value;
if (m_isDefaultValueMode)
setTextContentInternal(value);
}
void HTMLOutputElement::setTextContentInternal(const String& value)
{
ASSERT(!m_isSetTextContentInProgress);
ExceptionCode ec;
m_isSetTextContentInProgress = true;
setTextContent(value, ec);
}
}