HTMLOutputElement.cpp [plain text]
#include "config.h"
#include "HTMLOutputElement.h"
#include "HTMLFormElement.h"
#include "HTMLNames.h"
#include <wtf/IsoMallocInlines.h>
#include <wtf/NeverDestroyed.h>
namespace WebCore {
WTF_MAKE_ISO_ALLOCATED_IMPL(HTMLOutputElement);
using namespace HTMLNames;
inline HTMLOutputElement::HTMLOutputElement(const QualifiedName& tagName, Document& document, HTMLFormElement* form)
: HTMLFormControlElement(tagName, document, form)
, m_isDefaultValueMode(true)
, m_isSetTextContentInProgress(false)
, m_defaultValue(emptyString())
{
}
Ref<HTMLOutputElement> HTMLOutputElement::create(const QualifiedName& tagName, Document& document, HTMLFormElement* form)
{
return adoptRef(*new HTMLOutputElement(tagName, document, form));
}
const AtomString& HTMLOutputElement::formControlType() const
{
static MainThreadNeverDestroyed<const AtomString> output("output", AtomString::ConstructFromLiteral);
return output;
}
bool HTMLOutputElement::supportsFocus() const
{
return HTMLElement::supportsFocus();
}
void HTMLOutputElement::parseAttribute(const QualifiedName& name, const AtomString& value)
{
if (name == forAttr) {
if (m_tokens)
m_tokens->associatedAttributeValueChanged(value);
} else
HTMLFormControlElement::parseAttribute(name, value);
}
void HTMLOutputElement::childrenChanged(const ChildChange& change)
{
HTMLFormControlElement::childrenChanged(change);
if (change.source == ChildChangeSource::Parser || 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);
}
DOMTokenList& HTMLOutputElement::htmlFor()
{
if (!m_tokens)
m_tokens = makeUnique<DOMTokenList>(*this, forAttr);
return *m_tokens;
}
void HTMLOutputElement::setTextContentInternal(const String& value)
{
ASSERT(!m_isSetTextContentInProgress);
m_isSetTextContentInProgress = true;
setTextContent(value);
}
}