BaseCheckableInputType.cpp [plain text]
#include "config.h"
#include "BaseCheckableInputType.h"
#include "FormController.h"
#include "FormDataList.h"
#include "HTMLInputElement.h"
#include "HTMLNames.h"
#include "KeyboardEvent.h"
#include <wtf/NeverDestroyed.h>
namespace WebCore {
using namespace HTMLNames;
FormControlState BaseCheckableInputType::saveFormControlState() const
{
return FormControlState(element().checked() ? ASCIILiteral("on") : ASCIILiteral("off"));
}
void BaseCheckableInputType::restoreFormControlState(const FormControlState& state)
{
element().setChecked(state[0] == "on");
}
bool BaseCheckableInputType::appendFormData(FormDataList& encoding, bool) const
{
if (!element().checked())
return false;
encoding.appendData(element().name(), element().value());
return true;
}
void BaseCheckableInputType::handleKeydownEvent(KeyboardEvent& event)
{
const String& key = event.keyIdentifier();
if (key == "U+0020") {
element().setActive(true, true);
}
}
void BaseCheckableInputType::handleKeypressEvent(KeyboardEvent& event)
{
if (event.charCode() == ' ') {
event.setDefaultHandled();
}
}
bool BaseCheckableInputType::canSetStringValue() const
{
return false;
}
void BaseCheckableInputType::accessKeyAction(bool sendMouseEvents)
{
InputType::accessKeyAction(sendMouseEvents);
element().dispatchSimulatedClick(0, sendMouseEvents ? SendMouseUpDownEvents : SendNoEvents);
}
String BaseCheckableInputType::fallbackValue() const
{
static NeverDestroyed<const AtomicString> on("on", AtomicString::ConstructFromLiteral);
return on.get();
}
bool BaseCheckableInputType::storesValueSeparateFromAttribute()
{
return false;
}
void BaseCheckableInputType::setValue(const String& sanitizedValue, bool, TextFieldEventBehavior)
{
element().setAttributeWithoutSynchronization(valueAttr, sanitizedValue);
}
bool BaseCheckableInputType::isCheckable()
{
return true;
}
}