BaseChooserOnlyDateAndTimeInputType.cpp [plain text]
#include "config.h"
#if ENABLE(DATE_AND_TIME_INPUT_TYPES)
#include "BaseChooserOnlyDateAndTimeInputType.h"
#include "Chrome.h"
#include "HTMLDivElement.h"
#include "HTMLInputElement.h"
#include "Page.h"
#include "ScriptController.h"
#include "ShadowRoot.h"
namespace WebCore {
BaseChooserOnlyDateAndTimeInputType::~BaseChooserOnlyDateAndTimeInputType()
{
closeDateTimeChooser();
}
void BaseChooserOnlyDateAndTimeInputType::handleDOMActivateEvent(Event*)
{
if (element()->isDisabledOrReadOnly() || !element()->renderer() || !ScriptController::processingUserGesture())
return;
if (m_dateTimeChooser)
return;
if (!element()->document()->page())
return;
DateTimeChooserParameters parameters;
if (!element()->setupDateTimeChooserParameters(parameters))
return;
#if !PLATFORM(IOS)
m_dateTimeChooser = element()->document()->page()->chrome().openDateTimeChooser(this, parameters);
#endif
}
void BaseChooserOnlyDateAndTimeInputType::createShadowSubtree()
{
DEFINE_STATIC_LOCAL(AtomicString, valueContainerPseudo, ("-webkit-date-and-time-value", AtomicString::ConstructFromLiteral));
RefPtr<HTMLDivElement> valueContainer = HTMLDivElement::create(element()->document());
valueContainer->setPseudo(valueContainerPseudo);
element()->userAgentShadowRoot()->appendChild(valueContainer.get());
updateAppearance();
}
void BaseChooserOnlyDateAndTimeInputType::updateAppearance()
{
Node* node = element()->userAgentShadowRoot()->firstChild();
if (!node || !node->isHTMLElement())
return;
String displayValue = visibleValue();
if (displayValue.isEmpty()) {
displayValue = ASCIILiteral(" ");
}
toHTMLElement(node)->setInnerText(displayValue, ASSERT_NO_EXCEPTION);
}
void BaseChooserOnlyDateAndTimeInputType::setValue(const String& value, bool valueChanged, TextFieldEventBehavior eventBehavior)
{
BaseDateAndTimeInputType::setValue(value, valueChanged, eventBehavior);
if (valueChanged)
updateAppearance();
}
void BaseChooserOnlyDateAndTimeInputType::detach()
{
closeDateTimeChooser();
}
void BaseChooserOnlyDateAndTimeInputType::didChooseValue(const String& value)
{
element()->setValue(value, DispatchInputAndChangeEvent);
}
void BaseChooserOnlyDateAndTimeInputType::didEndChooser()
{
m_dateTimeChooser.clear();
}
void BaseChooserOnlyDateAndTimeInputType::closeDateTimeChooser()
{
if (m_dateTimeChooser)
m_dateTimeChooser->endChooser();
}
void BaseChooserOnlyDateAndTimeInputType::handleKeydownEvent(KeyboardEvent* event)
{
BaseClickableWithKeyInputType::handleKeydownEvent(element(), event);
}
void BaseChooserOnlyDateAndTimeInputType::handleKeypressEvent(KeyboardEvent* event)
{
BaseClickableWithKeyInputType::handleKeypressEvent(element(), event);
}
void BaseChooserOnlyDateAndTimeInputType::handleKeyupEvent(KeyboardEvent* event)
{
BaseClickableWithKeyInputType::handleKeyupEvent(*this, event);
}
void BaseChooserOnlyDateAndTimeInputType::accessKeyAction(bool sendMouseEvents)
{
BaseDateAndTimeInputType::accessKeyAction(sendMouseEvents);
BaseClickableWithKeyInputType::accessKeyAction(element(), sendMouseEvents);
}
bool BaseChooserOnlyDateAndTimeInputType::isMouseFocusable() const
{
return element()->isTextFormControlFocusable();
}
}
#endif