mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 20:35:50 +00:00
Bug 1345767 - Part 3: Factor IsValueMissing() out of HTMLInputElement. r=smaug
MozReview-Commit-ID: AE6SSA43Vx5 --HG-- extra : rebase_source : b51483419c3a0804871f78842b576406790bd8fc
This commit is contained in:
parent
b15f522fed
commit
ee7fa8727c
@ -7544,31 +7544,7 @@ HTMLInputElement::IsValueMissing() const
|
||||
// Should use UpdateValueMissingValidityStateForRadio() for type radio.
|
||||
MOZ_ASSERT(mType != NS_FORM_INPUT_RADIO);
|
||||
|
||||
if (!HasAttr(kNameSpaceID_None, nsGkAtoms::required) ||
|
||||
!DoesRequiredApply()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsMutable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (GetValueMode()) {
|
||||
case VALUE_MODE_VALUE:
|
||||
return IsValueEmpty();
|
||||
|
||||
case VALUE_MODE_FILENAME:
|
||||
return GetFilesOrDirectoriesInternal().IsEmpty();
|
||||
|
||||
case VALUE_MODE_DEFAULT_ON:
|
||||
// This should not be used for type radio.
|
||||
// See the MOZ_ASSERT at the beginning of the method.
|
||||
return !mChecked;
|
||||
|
||||
case VALUE_MODE_DEFAULT:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return mInputType->IsValueMissing();
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -134,6 +134,7 @@ class HTMLInputElement final : public nsGenericHTMLFormElementWithState,
|
||||
{
|
||||
friend class AfterSetFilesOrDirectoriesCallback;
|
||||
friend class DispatchChangeEventCallback;
|
||||
friend class ::InputType;
|
||||
|
||||
public:
|
||||
using nsIConstraintValidation::GetValidationMessage;
|
||||
|
23
dom/html/input/CheckableInputTypes.cpp
Normal file
23
dom/html/input/CheckableInputTypes.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "CheckableInputTypes.h"
|
||||
|
||||
#include "mozilla/dom/HTMLInputElement.h"
|
||||
|
||||
bool
|
||||
CheckboxInputType::IsValueMissing() const
|
||||
{
|
||||
if (!mInputElement->HasAttr(kNameSpaceID_None, nsGkAtoms::required)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsMutable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !mInputElement->Checked();
|
||||
}
|
@ -30,6 +30,8 @@ public:
|
||||
return new (aMemory) CheckboxInputType(aInputElement);
|
||||
}
|
||||
|
||||
bool IsValueMissing() const override;
|
||||
|
||||
private:
|
||||
explicit CheckboxInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
: CheckableInputTypeBase(aInputElement)
|
||||
|
30
dom/html/input/DateTimeInputTypes.cpp
Normal file
30
dom/html/input/DateTimeInputTypes.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "DateTimeInputTypes.h"
|
||||
|
||||
#include "mozilla/dom/HTMLInputElement.h"
|
||||
|
||||
bool
|
||||
DateTimeInputTypeBase::IsMutable() const
|
||||
{
|
||||
return !mInputElement->IsDisabled() &&
|
||||
!mInputElement->HasAttr(kNameSpaceID_None, nsGkAtoms::readonly);
|
||||
}
|
||||
|
||||
bool
|
||||
DateTimeInputTypeBase::IsValueMissing() const
|
||||
{
|
||||
if (!mInputElement->HasAttr(kNameSpaceID_None, nsGkAtoms::required)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsMutable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return IsValueEmpty();
|
||||
}
|
@ -14,10 +14,14 @@ class DateTimeInputTypeBase : public ::InputType
|
||||
public:
|
||||
~DateTimeInputTypeBase() override {}
|
||||
|
||||
bool IsValueMissing() const override;
|
||||
|
||||
protected:
|
||||
explicit DateTimeInputTypeBase(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
: InputType(aInputElement)
|
||||
{}
|
||||
|
||||
bool IsMutable() const override;
|
||||
};
|
||||
|
||||
// input type=date
|
||||
|
23
dom/html/input/FileInputType.cpp
Normal file
23
dom/html/input/FileInputType.cpp
Normal file
@ -0,0 +1,23 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "FileInputType.h"
|
||||
|
||||
#include "mozilla/dom/HTMLInputElement.h"
|
||||
|
||||
bool
|
||||
FileInputType::IsValueMissing() const
|
||||
{
|
||||
if (!mInputElement->HasAttr(kNameSpaceID_None, nsGkAtoms::required)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsMutable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return mInputElement->GetFilesOrDirectoriesInternal().IsEmpty();
|
||||
}
|
@ -19,6 +19,8 @@ public:
|
||||
return new (aMemory) FileInputType(aInputElement);
|
||||
}
|
||||
|
||||
bool IsValueMissing() const override;
|
||||
|
||||
private:
|
||||
explicit FileInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
: InputType(aInputElement)
|
||||
|
@ -102,6 +102,18 @@ InputType::Create(mozilla::dom::HTMLInputElement* aInputElement, uint8_t aType,
|
||||
return inputType;
|
||||
}
|
||||
|
||||
bool
|
||||
InputType::IsMutable() const
|
||||
{
|
||||
return !mInputElement->IsDisabled();
|
||||
}
|
||||
|
||||
bool
|
||||
InputType::IsValueEmpty() const
|
||||
{
|
||||
return mInputElement->IsValueEmpty();
|
||||
}
|
||||
|
||||
void
|
||||
InputType::DropReference()
|
||||
{
|
||||
@ -120,3 +132,9 @@ InputType::IsTooShort() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
InputType::IsValueMissing() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -37,12 +37,31 @@ public:
|
||||
|
||||
virtual bool IsTooLong() const;
|
||||
virtual bool IsTooShort() const;
|
||||
virtual bool IsValueMissing() const;
|
||||
|
||||
protected:
|
||||
explicit InputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
: mInputElement(aInputElement)
|
||||
{}
|
||||
|
||||
/**
|
||||
* Get the mutable state of the element.
|
||||
* When the element isn't mutable (immutable), the value or checkedness
|
||||
* should not be changed by the user.
|
||||
*
|
||||
* See: https://html.spec.whatwg.org/multipage/forms.html#the-input-element:concept-fe-mutable
|
||||
*/
|
||||
virtual bool IsMutable() const;
|
||||
|
||||
/**
|
||||
* Returns whether the input element's current value is the empty string.
|
||||
* This only makes sense for some input types; does NOT make sense for file
|
||||
* inputs.
|
||||
*
|
||||
* @return whether the input element's current value is the empty string.
|
||||
*/
|
||||
bool IsValueEmpty() const;
|
||||
|
||||
mozilla::dom::HTMLInputElement* mInputElement;
|
||||
};
|
||||
|
||||
|
30
dom/html/input/NumericInputTypes.cpp
Normal file
30
dom/html/input/NumericInputTypes.cpp
Normal file
@ -0,0 +1,30 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "NumericInputTypes.h"
|
||||
|
||||
#include "mozilla/dom/HTMLInputElement.h"
|
||||
|
||||
bool
|
||||
NumberInputType::IsMutable() const
|
||||
{
|
||||
return !mInputElement->IsDisabled() &&
|
||||
!mInputElement->HasAttr(kNameSpaceID_None, nsGkAtoms::readonly);
|
||||
}
|
||||
|
||||
bool
|
||||
NumberInputType::IsValueMissing() const
|
||||
{
|
||||
if (!mInputElement->HasAttr(kNameSpaceID_None, nsGkAtoms::required)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsMutable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return IsValueEmpty();
|
||||
}
|
@ -30,10 +30,14 @@ public:
|
||||
return new (aMemory) NumberInputType(aInputElement);
|
||||
}
|
||||
|
||||
bool IsValueMissing() const override;
|
||||
|
||||
private:
|
||||
explicit NumberInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
: NumericInputTypeBase(aInputElement)
|
||||
{}
|
||||
|
||||
bool IsMutable() const override;
|
||||
};
|
||||
|
||||
// input type=range
|
||||
|
@ -9,6 +9,13 @@
|
||||
#include "mozilla/dom/HTMLInputElement.h"
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
|
||||
bool
|
||||
SingleLineTextInputTypeBase::IsMutable() const
|
||||
{
|
||||
return !mInputElement->IsDisabled() &&
|
||||
!mInputElement->HasAttr(kNameSpaceID_None, nsGkAtoms::readonly);
|
||||
}
|
||||
|
||||
bool
|
||||
SingleLineTextInputTypeBase::IsTooLong() const
|
||||
{
|
||||
@ -40,3 +47,17 @@ SingleLineTextInputTypeBase::IsTooShort() const
|
||||
|
||||
return textLength && textLength < minLength;
|
||||
}
|
||||
|
||||
bool
|
||||
SingleLineTextInputTypeBase::IsValueMissing() const
|
||||
{
|
||||
if (!mInputElement->HasAttr(kNameSpaceID_None, nsGkAtoms::required)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!IsMutable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return IsValueEmpty();
|
||||
}
|
||||
|
@ -16,12 +16,15 @@ public:
|
||||
|
||||
bool IsTooLong() const override;
|
||||
bool IsTooShort() const override;
|
||||
bool IsValueMissing() const override;
|
||||
|
||||
protected:
|
||||
explicit SingleLineTextInputTypeBase(
|
||||
mozilla::dom::HTMLInputElement* aInputElement)
|
||||
: InputType(aInputElement)
|
||||
{}
|
||||
|
||||
bool IsMutable() const override;
|
||||
};
|
||||
|
||||
// input type=text
|
||||
|
@ -17,7 +17,11 @@ EXPORTS += [
|
||||
]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'CheckableInputTypes.cpp',
|
||||
'DateTimeInputTypes.cpp',
|
||||
'FileInputType.cpp',
|
||||
'InputType.cpp',
|
||||
'NumericInputTypes.cpp',
|
||||
'SingleLineTextInputTypes.cpp',
|
||||
]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user