This source file includes following definitions.
- saveFormControlState
- restoreFormControlState
- appendFormData
- handleKeydownEvent
- handleKeypressEvent
- canSetStringValue
- accessKeyAction
- fallbackValue
- storesValueSeparateFromAttribute
- setValue
- isCheckable
#include "config.h"
#include "core/html/forms/BaseCheckableInputType.h"
#include "HTMLNames.h"
#include "core/events/KeyboardEvent.h"
#include "core/html/FormDataList.h"
#include "core/html/HTMLInputElement.h"
#include "core/html/forms/FormController.h"
namespace WebCore {
using namespace HTMLNames;
FormControlState BaseCheckableInputType::saveFormControlState() const
{
return FormControlState(element().checked() ? "on" : "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);
}
}
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
{
return "on";
}
bool BaseCheckableInputType::storesValueSeparateFromAttribute()
{
return false;
}
void BaseCheckableInputType::setValue(const String& sanitizedValue, bool, TextFieldEventBehavior)
{
element().setAttribute(valueAttr, AtomicString(sanitizedValue));
}
bool BaseCheckableInputType::isCheckable()
{
return true;
}
}