void BaseMultipleFieldsDateAndTimeInputType::updateView()
{
    DateTimeEditElement* edit = dateTimeEditElement();
    if (!edit)
        return;

    DateTimeEditElement::LayoutParameters layoutParameters(element().locale(), createStepRange(AnyIsDefaultStep));

    DateComponents date;
    bool hasValue = false;
    if (!element().suggestedValue().isNull())
        hasValue = parseToDateComponents(element().suggestedValue(), &date);
    else
        hasValue = parseToDateComponents(element().value(), &date);
    if (!hasValue)
        setMillisecondToDateComponents(layoutParameters.stepRange.minimum().toDouble(), &date);

    setupLayoutParameters(layoutParameters, date);

    DEFINE_STATIC_LOCAL(AtomicString, datetimeformatAttr, ("datetimeformat", AtomicString::ConstructFromLiteral));
    edit->setAttribute(datetimeformatAttr, AtomicString(layoutParameters.dateTimeFormat), ASSERT_NO_EXCEPTION);
    const AtomicString pattern = edit->fastGetAttribute(HTMLNames::patternAttr);
    if (!pattern.isEmpty())
        layoutParameters.dateTimeFormat = pattern;

    if (!DateTimeFormatValidator().validateFormat(layoutParameters.dateTimeFormat, *this))
        layoutParameters.dateTimeFormat = layoutParameters.fallbackDateTimeFormat;

    if (hasValue)
        edit->setValueAsDate(layoutParameters, date);
    else
        edit->setEmptyValue(layoutParameters, date);
    updateClearButtonVisibility();
}
void BaseMultipleFieldsDateAndTimeInputType::readonlyAttributeChanged()
{
    EventQueueScope scope;
    spinButtonElement()->releaseCapture();
    if (DateTimeEditElement* edit = dateTimeEditElement())
        edit->readOnlyStateChanged();
}
Ejemplo n.º 3
0
void BaseMultipleFieldsDateAndTimeInputType::createShadowSubtree()
{
    ASSERT(element()->shadow());

    Document* document = element()->document();
    ContainerNode* container = element()->userAgentShadowRoot();

    RefPtr<DateTimeEditElement> dateTimeEditElement(DateTimeEditElement::create(document, *this));
    m_dateTimeEditElement = dateTimeEditElement.get();
    container->appendChild(m_dateTimeEditElement);
    updateInnerTextValue();

    RefPtr<SpinButtonElement> spinButton = SpinButtonElement::create(document, *this);
    m_spinButtonElement = spinButton.get();
    container->appendChild(spinButton);

    bool shouldAddPickerIndicator = false;
#if ENABLE(DATALIST_ELEMENT)
    if (InputType::themeSupportsDataListUI(this))
        shouldAddPickerIndicator = true;
#endif
    RefPtr<RenderTheme> theme = document->page() ? document->page()->theme() : RenderTheme::defaultTheme();
    if (theme->supportsCalendarPicker(formControlType())) {
        shouldAddPickerIndicator = true;
        m_pickerIndicatorIsAlwaysVisible = true;
    }
    if (shouldAddPickerIndicator) {
        RefPtr<PickerIndicatorElement> pickerElement = PickerIndicatorElement::create(document, *this);
        m_pickerIndicatorElement = pickerElement.get();
        container->appendChild(m_pickerIndicatorElement);
        m_pickerIndicatorIsVisible = true;
        updatePickerIndicatorVisibility();
    }
}
bool MultipleFieldsTemporalInputTypeView::
    shouldSpinButtonRespondToWheelEvents() {
  if (!shouldSpinButtonRespondToMouseEvents())
    return false;
  if (DateTimeEditElement* edit = dateTimeEditElement())
    return edit->hasFocusedField();
  return false;
}
void BaseMultipleFieldsDateAndTimeInputType::setValue(const String& sanitizedValue, bool valueChanged, TextFieldEventBehavior eventBehavior)
{
    InputType::setValue(sanitizedValue, valueChanged, eventBehavior);
    DateTimeEditElement* edit = dateTimeEditElement();
    if (valueChanged || (sanitizedValue.isEmpty() && edit && edit->anyEditableFieldsHaveValues())) {
        element().updateView();
        element().setNeedsValidityCheck();
    }
}
void MultipleFieldsTemporalInputTypeView::didSetValue(
    const String& sanitizedValue,
    bool valueChanged) {
  DateTimeEditElement* edit = dateTimeEditElement();
  if (valueChanged || (sanitizedValue.isEmpty() && edit &&
                       edit->anyEditableFieldsHaveValues())) {
    element().updateView();
    element().setNeedsValidityCheck();
  }
}
void MultipleFieldsTemporalInputTypeView::forwardEvent(Event* event) {
  if (SpinButtonElement* element = spinButtonElement()) {
    element->forwardEvent(event);
    if (event->defaultHandled())
      return;
  }

  if (DateTimeEditElement* edit = dateTimeEditElement())
    edit->defaultEventHandler(event);
}
void BaseMultipleFieldsDateAndTimeInputType::restoreFormControlState(const FormControlState& state)
{
    DateTimeEditElement* edit = dateTimeEditElement();
    if (!edit)
        return;
    DateTimeFieldsState dateTimeFieldsState = DateTimeFieldsState::restoreFormControlState(state);
    edit->setValueAsDateTimeFieldsState(dateTimeFieldsState);
    element().setValueInternal(sanitizeValue(edit->value()), DispatchNoEvent);
    updateClearButtonVisibility();
}
void BaseMultipleFieldsDateAndTimeInputType::forwardEvent(Event* event)
{
    if (SpinButtonElement* element = spinButtonElement()) {
        element->forwardEvent(event);
        if (event->defaultHandled())
            return;
    }

    if (DateTimeEditElement* edit = dateTimeEditElement())
        edit->defaultEventHandler(event);
}
BaseMultipleFieldsDateAndTimeInputType::~BaseMultipleFieldsDateAndTimeInputType()
{
#if !ENABLE(OILPAN)
    if (SpinButtonElement* element = spinButtonElement())
        element->removeSpinButtonOwner();
    if (ClearButtonElement* element = clearButtonElement())
        element->removeClearButtonOwner();
    if (DateTimeEditElement* element = dateTimeEditElement())
        element->removeEditControlOwner();
    if (PickerIndicatorElement* element = pickerIndicatorElement())
        element->removePickerIndicatorOwner();
#endif
}
void BaseMultipleFieldsDateAndTimeInputType::handleFocusInEvent(Element* oldFocusedElement, FocusType type)
{
    DateTimeEditElement* edit = dateTimeEditElement();
    if (!edit || m_isDestroyingShadowSubtree)
        return;
    if (type == FocusTypeBackward) {
        if (element().document().page())
            element().document().page()->focusController().advanceFocus(type);
    } else if (type == FocusTypeNone || type == FocusTypeMouse || type == FocusTypePage) {
        edit->focusByOwner(oldFocusedElement);
    } else {
        edit->focusByOwner();
    }
}
void BaseMultipleFieldsDateAndTimeInputType::updateClearButtonVisibility()
{
    ClearButtonElement* clearButton = clearButtonElement();
    if (!clearButton)
        return;

    if (element().isRequired() || !dateTimeEditElement()->anyEditableFieldsHaveValues()) {
        clearButton->setInlineStyleProperty(CSSPropertyOpacity, 0.0, CSSPrimitiveValue::CSS_NUMBER);
        clearButton->setInlineStyleProperty(CSSPropertyPointerEvents, CSSValueNone);
    } else {
        clearButton->removeInlineStyleProperty(CSSPropertyOpacity);
        clearButton->removeInlineStyleProperty(CSSPropertyPointerEvents);
    }
}
void BaseMultipleFieldsDateAndTimeInputType::editControlValueChanged()
{
    RefPtrWillBeRawPtr<HTMLInputElement> input(element());
    String oldValue = input->value();
    String newValue = sanitizeValue(dateTimeEditElement()->value());
    // Even if oldValue is null and newValue is "", we should assume they are same.
    if ((oldValue.isEmpty() && newValue.isEmpty()) || oldValue == newValue) {
        input->setNeedsValidityCheck();
    } else {
        input->setValueInternal(newValue, DispatchNoEvent);
        input->setNeedsStyleRecalc(SubtreeStyleChange, StyleChangeReasonForTracing::create(StyleChangeReason::ControlValue));
        input->dispatchFormControlInputEvent();
    }
    input->notifyFormStateChanged();
    input->updateClearButtonVisibility();
}
void MultipleFieldsTemporalInputTypeView::editControlValueChanged() {
  String oldValue = element().value();
  String newValue = m_inputType->sanitizeValue(dateTimeEditElement()->value());
  // Even if oldValue is null and newValue is "", we should assume they are
  // same.
  if ((oldValue.isEmpty() && newValue.isEmpty()) || oldValue == newValue) {
    element().setNeedsValidityCheck();
  } else {
    element().setValueInternal(newValue, DispatchNoEvent);
    element().setNeedsStyleRecalc(
        SubtreeStyleChange,
        StyleChangeReasonForTracing::create(StyleChangeReason::ControlValue));
    element().dispatchFormControlInputEvent();
  }
  element().notifyFormStateChanged();
  element().updateClearButtonVisibility();
}
Ejemplo n.º 15
0
void BaseMultipleFieldsDateAndTimeInputType::createShadowSubtree()
{
    DEFINE_STATIC_LOCAL(AtomicString, dateAndTimeInputContainerPseudoId, ("-webkit-date-and-time-container", AtomicString::ConstructFromLiteral));

    ASSERT(element()->shadow());

    Document* document = element()->document();
    RefPtr<HTMLDivElement> container = HTMLDivElement::create(document);
    element()->userAgentShadowRoot()->appendChild(container);
    container->setShadowPseudoId(dateAndTimeInputContainerPseudoId);

    RefPtr<DateTimeEditElement> dateTimeEditElement(DateTimeEditElement::create(document, *this));
    m_dateTimeEditElement = dateTimeEditElement.get();
    container->appendChild(m_dateTimeEditElement);
    updateInnerTextValue();

    RefPtr<SpinButtonElement> spinButton = SpinButtonElement::create(document, *this);
    m_spinButtonElement = spinButton.get();
    container->appendChild(spinButton);

#if ENABLE(DATALIST_ELEMENT) || ENABLE(CALENDAR_PICKER)
    bool shouldAddPickerIndicator = false;
#if ENABLE(DATALIST_ELEMENT)
    if (InputType::themeSupportsDataListUI(this))
        shouldAddPickerIndicator = true;
#endif
#if ENABLE(CALENDAR_PICKER)
    RefPtr<RenderTheme> theme = document->page() ? document->page()->theme() : RenderTheme::defaultTheme();
    if (theme->supportsCalendarPicker(formControlType())) {
        shouldAddPickerIndicator = true;
        m_pickerIndicatorIsAlwaysVisible = true;
    }
#endif
    if (shouldAddPickerIndicator) {
        RefPtr<PickerIndicatorElement> pickerElement = PickerIndicatorElement::create(document);
        m_pickerIndicatorElement = pickerElement.get();
        container->appendChild(m_pickerIndicatorElement);
        m_pickerIndicatorIsVisible = true;
        updatePickerIndicatorVisibility();
    }
#endif // ENABLE(DATALIST_ELEMENT) || ENABLE(CALENDAR_PICKER)
}
void MultipleFieldsTemporalInputTypeView::destroyShadowSubtree() {
  DCHECK(!m_isDestroyingShadowSubtree);
  m_isDestroyingShadowSubtree = true;
  if (SpinButtonElement* element = spinButtonElement())
    element->removeSpinButtonOwner();
  if (ClearButtonElement* element = clearButtonElement())
    element->removeClearButtonOwner();
  if (DateTimeEditElement* element = dateTimeEditElement())
    element->removeEditControlOwner();
  if (PickerIndicatorElement* element = pickerIndicatorElement())
    element->removePickerIndicatorOwner();

  // If a field element has focus, set focus back to the <input> itself before
  // deleting the field. This prevents unnecessary focusout/blur events.
  if (containsFocusedShadowElement())
    element().focus();

  InputTypeView::destroyShadowSubtree();
  m_isDestroyingShadowSubtree = false;
}
FormControlState MultipleFieldsTemporalInputTypeView::saveFormControlState()
    const {
  if (DateTimeEditElement* edit = dateTimeEditElement())
    return edit->valueAsDateTimeFieldsState().saveFormControlState();
  return FormControlState();
}
bool MultipleFieldsTemporalInputTypeView::hasBadInput() const {
  DateTimeEditElement* edit = dateTimeEditElement();
  return element().value().isEmpty() && edit &&
         edit->anyEditableFieldsHaveValues();
}
void MultipleFieldsTemporalInputTypeView::disabledAttributeChanged() {
  EventQueueScope scope;
  spinButtonElement()->releaseCapture();
  if (DateTimeEditElement* edit = dateTimeEditElement())
    edit->disabledStateChanged();
}
void BaseMultipleFieldsDateAndTimeInputType::disabledAttributeChanged()
{
    spinButtonElement()->releaseCapture();
    if (DateTimeEditElement* edit = dateTimeEditElement())
        edit->disabledStateChanged();
}
void MultipleFieldsTemporalInputTypeView::blur() {
  if (DateTimeEditElement* edit = dateTimeEditElement())
    edit->blurByOwner();
}
bool BaseMultipleFieldsDateAndTimeInputType::hasBadInput() const
{
    DateTimeEditElement* edit = dateTimeEditElement();
    return element().value().isEmpty() && edit && edit->anyEditableFieldsHaveValues();
}
void MultipleFieldsTemporalInputTypeView::spinButtonStepUp() {
  if (DateTimeEditElement* edit = dateTimeEditElement())
    edit->stepUp();
}
void MultipleFieldsTemporalInputTypeView::focusAndSelectSpinButtonOwner() {
  if (DateTimeEditElement* edit = dateTimeEditElement())
    edit->focusIfNoFocus();
}
void BaseMultipleFieldsDateAndTimeInputType::blur()
{
    if (DateTimeEditElement* edit = dateTimeEditElement())
        edit->blurByOwner();
}
FormControlState BaseMultipleFieldsDateAndTimeInputType::saveFormControlState() const
{
    if (DateTimeEditElement* edit = dateTimeEditElement())
        return edit->valueAsDateTimeFieldsState().saveFormControlState();
    return FormControlState();
}
void BaseMultipleFieldsDateAndTimeInputType::focusAndSelectSpinButtonOwner()
{
    if (DateTimeEditElement* edit = dateTimeEditElement())
        edit->focusIfNoFocus();
}
void BaseMultipleFieldsDateAndTimeInputType::spinButtonStepUp()
{
    if (DateTimeEditElement* edit = dateTimeEditElement())
        edit->stepUp();
}