This source file includes following definitions.
- create
- formControlType
- valueMissing
- valueMissingText
- handleKeyupEvent
- willDispatchClick
- didDispatchClick
- isCheckbox
- supportsIndeterminateAppearance
#include "config.h"
#include "core/html/forms/CheckboxInputType.h"
#include "InputTypeNames.h"
#include "core/events/KeyboardEvent.h"
#include "core/html/HTMLInputElement.h"
#include "platform/text/PlatformLocale.h"
#include "wtf/PassOwnPtr.h"
namespace WebCore {
PassRefPtr<InputType> CheckboxInputType::create(HTMLInputElement& element)
{
return adoptRef(new CheckboxInputType(element));
}
const AtomicString& CheckboxInputType::formControlType() const
{
return InputTypeNames::checkbox;
}
bool CheckboxInputType::valueMissing(const String&) const
{
return element().isRequired() && !element().checked();
}
String CheckboxInputType::valueMissingText() const
{
return locale().queryString(blink::WebLocalizedString::ValidationValueMissingForCheckbox);
}
void CheckboxInputType::handleKeyupEvent(KeyboardEvent* event)
{
const String& key = event->keyIdentifier();
if (key != "U+0020")
return;
dispatchSimulatedClickIfActive(event);
}
PassOwnPtr<ClickHandlingState> CheckboxInputType::willDispatchClick()
{
OwnPtr<ClickHandlingState> state = adoptPtr(new ClickHandlingState);
state->checked = element().checked();
state->indeterminate = element().indeterminate();
if (state->indeterminate)
element().setIndeterminate(false);
element().setChecked(!state->checked, DispatchChangeEvent);
return state.release();
}
void CheckboxInputType::didDispatchClick(Event* event, const ClickHandlingState& state)
{
if (event->defaultPrevented() || event->defaultHandled()) {
element().setIndeterminate(state.indeterminate);
element().setChecked(state.checked);
}
event->setDefaultHandled();
}
bool CheckboxInputType::isCheckbox() const
{
return true;
}
bool CheckboxInputType::supportsIndeterminateAppearance() const
{
return true;
}
}