This source file includes following definitions.
- emptyValueAXText
- m_fieldOwner
- defaultEventHandler
- defaultKeyboardEventHandler
- setFocus
- focusOnNextField
- initialize
- isDateTimeFieldElement
- isFieldOwnerDisabled
- isFieldOwnerReadOnly
- isDisabled
- localeForOwner
- localeIdentifier
- maximumWidth
- setDisabled
- supportsFocus
- updateVisibleValue
- valueForARIAValueNow
#include "config.h"
#if ENABLE(INPUT_MULTIPLE_FIELDS_UI)
#include "core/html/shadow/DateTimeFieldElement.h"
#include "HTMLNames.h"
#include "core/dom/Text.h"
#include "core/events/KeyboardEvent.h"
#include "platform/text/PlatformLocale.h"
#include "wtf/text/WTFString.h"
namespace WebCore {
using namespace HTMLNames;
static String emptyValueAXText()
{
return Locale::defaultLocale().queryString(blink::WebLocalizedString::AXDateTimeFieldEmptyValueText);
}
DateTimeFieldElement::FieldOwner::~FieldOwner()
{
}
DateTimeFieldElement::DateTimeFieldElement(Document& document, FieldOwner& fieldOwner)
: HTMLSpanElement(document)
, m_fieldOwner(&fieldOwner)
{
}
void DateTimeFieldElement::defaultEventHandler(Event* event)
{
if (event->isKeyboardEvent()) {
KeyboardEvent* keyboardEvent = toKeyboardEvent(event);
if (!isDisabled() && !isFieldOwnerDisabled() && !isFieldOwnerReadOnly()) {
handleKeyboardEvent(keyboardEvent);
if (keyboardEvent->defaultHandled())
return;
}
defaultKeyboardEventHandler(keyboardEvent);
if (keyboardEvent->defaultHandled())
return;
}
HTMLElement::defaultEventHandler(event);
}
void DateTimeFieldElement::defaultKeyboardEventHandler(KeyboardEvent* keyboardEvent)
{
if (keyboardEvent->type() != EventTypeNames::keydown)
return;
if (isDisabled() || isFieldOwnerDisabled())
return;
const String& keyIdentifier = keyboardEvent->keyIdentifier();
if (keyIdentifier == "Left") {
if (!m_fieldOwner)
return;
if (!localeForOwner().isRTL() && m_fieldOwner->focusOnPreviousField(*this))
keyboardEvent->setDefaultHandled();
return;
}
if (keyIdentifier == "Right") {
if (!m_fieldOwner)
return;
if (!localeForOwner().isRTL() && m_fieldOwner->focusOnNextField(*this))
keyboardEvent->setDefaultHandled();
return;
}
if (isFieldOwnerReadOnly())
return;
if (keyIdentifier == "Down") {
if (keyboardEvent->getModifierState("Alt"))
return;
keyboardEvent->setDefaultHandled();
stepDown();
return;
}
if (keyIdentifier == "Up") {
keyboardEvent->setDefaultHandled();
stepUp();
return;
}
if (keyIdentifier == "U+0008" || keyIdentifier == "U+007F") {
keyboardEvent->setDefaultHandled();
setEmptyValue(DispatchEvent);
return;
}
}
void DateTimeFieldElement::setFocus(bool value)
{
if (m_fieldOwner)
value ? m_fieldOwner->didFocusOnField() : m_fieldOwner->didBlurFromField();
ContainerNode::setFocus(value);
}
void DateTimeFieldElement::focusOnNextField()
{
if (!m_fieldOwner)
return;
m_fieldOwner->focusOnNextField(*this);
}
void DateTimeFieldElement::initialize(const AtomicString& pseudo, const String& axHelpText, int axMinimum, int axMaximum)
{
setAttribute(roleAttr, AtomicString("spinbutton", AtomicString::ConstructFromLiteral));
setAttribute(aria_valuetextAttr, AtomicString(emptyValueAXText()));
setAttribute(aria_valueminAttr, AtomicString::number(axMinimum));
setAttribute(aria_valuemaxAttr, AtomicString::number(axMaximum));
setAttribute(aria_helpAttr, AtomicString(axHelpText));
setShadowPseudoId(pseudo);
appendChild(Text::create(document(), visibleValue()));
}
bool DateTimeFieldElement::isDateTimeFieldElement() const
{
return true;
}
bool DateTimeFieldElement::isFieldOwnerDisabled() const
{
return m_fieldOwner && m_fieldOwner->isFieldOwnerDisabled();
}
bool DateTimeFieldElement::isFieldOwnerReadOnly() const
{
return m_fieldOwner && m_fieldOwner->isFieldOwnerReadOnly();
}
bool DateTimeFieldElement::isDisabled() const
{
return fastHasAttribute(disabledAttr);
}
Locale& DateTimeFieldElement::localeForOwner() const
{
return document().getCachedLocale(localeIdentifier());
}
AtomicString DateTimeFieldElement::localeIdentifier() const
{
return m_fieldOwner ? m_fieldOwner->localeIdentifier() : nullAtom;
}
float DateTimeFieldElement::maximumWidth(const Font&)
{
const float paddingLeftAndRight = 2;
return paddingLeftAndRight;
}
void DateTimeFieldElement::setDisabled()
{
setBooleanAttribute(disabledAttr, true);
setNeedsStyleRecalc(SubtreeStyleChange);
}
bool DateTimeFieldElement::supportsFocus() const
{
return !isDisabled() && !isFieldOwnerDisabled();
}
void DateTimeFieldElement::updateVisibleValue(EventBehavior eventBehavior)
{
Text* const textNode = toText(firstChild());
const String newVisibleValue = visibleValue();
ASSERT(newVisibleValue.length() > 0);
if (textNode->wholeText() == newVisibleValue)
return;
textNode->replaceWholeText(newVisibleValue);
if (hasValue()) {
setAttribute(aria_valuetextAttr, AtomicString(newVisibleValue));
setAttribute(aria_valuenowAttr, AtomicString::number(valueForARIAValueNow()));
} else {
setAttribute(aria_valuetextAttr, AtomicString(emptyValueAXText()));
removeAttribute(aria_valuenowAttr);
}
if (eventBehavior == DispatchEvent && m_fieldOwner)
m_fieldOwner->fieldValueChanged();
}
int DateTimeFieldElement::valueForARIAValueNow() const
{
return valueAsInteger();
}
}
#endif