зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1620867 - Move all InputTypes into mozilla::dom namespace. r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D65918 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
45bbeae4cc
Коммит
42615abfc2
|
@ -12,9 +12,10 @@
|
|||
#include "mozilla/DebugOnly.h"
|
||||
#include "mozilla/dom/Directory.h"
|
||||
#include "mozilla/dom/DocumentOrShadowRoot.h"
|
||||
#include "mozilla/dom/HTMLFormSubmission.h"
|
||||
#include "mozilla/dom/FileSystemUtils.h"
|
||||
#include "mozilla/dom/GetFilesHelper.h"
|
||||
#include "mozilla/dom/HTMLFormSubmission.h"
|
||||
#include "mozilla/dom/InputType.h"
|
||||
#include "mozilla/dom/UserActivation.h"
|
||||
#include "mozilla/dom/WheelEventBinding.h"
|
||||
#include "mozilla/PresShell.h"
|
||||
|
@ -25,7 +26,6 @@
|
|||
#include "nsQueryObject.h"
|
||||
|
||||
#include "nsIRadioVisitor.h"
|
||||
#include "InputType.h"
|
||||
|
||||
#include "HTMLFormSubmissionConstants.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
|
|
|
@ -18,6 +18,14 @@
|
|||
#include "mozilla/dom/HTMLInputElementBinding.h"
|
||||
#include "mozilla/dom/Promise.h"
|
||||
#include "mozilla/dom/UnionTypes.h"
|
||||
#include "mozilla/dom/SingleLineTextInputTypes.h"
|
||||
#include "mozilla/dom/NumericInputTypes.h"
|
||||
#include "mozilla/dom/CheckableInputTypes.h"
|
||||
#include "mozilla/dom/ButtonInputTypes.h"
|
||||
#include "mozilla/dom/DateTimeInputTypes.h"
|
||||
#include "mozilla/dom/ColorInputType.h"
|
||||
#include "mozilla/dom/FileInputType.h"
|
||||
#include "mozilla/dom/HiddenInputType.h"
|
||||
#include "nsGenericHTMLElement.h"
|
||||
#include "nsImageLoadingContent.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
@ -25,26 +33,7 @@
|
|||
#include "nsIFilePicker.h"
|
||||
#include "nsIContentPrefService2.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "SingleLineTextInputTypes.h"
|
||||
#include "NumericInputTypes.h"
|
||||
#include "CheckableInputTypes.h"
|
||||
#include "ButtonInputTypes.h"
|
||||
#include "DateTimeInputTypes.h"
|
||||
#include "ColorInputType.h"
|
||||
#include "FileInputType.h"
|
||||
#include "HiddenInputType.h"
|
||||
|
||||
static constexpr size_t INPUT_TYPE_SIZE = sizeof(
|
||||
mozilla::Variant<TextInputType, SearchInputType, TelInputType, URLInputType,
|
||||
EmailInputType, PasswordInputType, NumberInputType,
|
||||
RangeInputType, RadioInputType, CheckboxInputType,
|
||||
ButtonInputType, ImageInputType, ResetInputType,
|
||||
SubmitInputType, DateInputType, TimeInputType,
|
||||
WeekInputType, MonthInputType, DateTimeLocalInputType,
|
||||
FileInputType, ColorInputType, HiddenInputType>);
|
||||
|
||||
class InputType;
|
||||
struct DoNotDelete;
|
||||
class nsIRadioGroupContainer;
|
||||
class nsIRadioVisitor;
|
||||
|
||||
|
@ -62,6 +51,7 @@ class File;
|
|||
class FileList;
|
||||
class FileSystemEntry;
|
||||
class GetFilesHelper;
|
||||
class InputType;
|
||||
|
||||
/**
|
||||
* A class we use to create a singleton object that is used to keep track of
|
||||
|
@ -121,7 +111,7 @@ class HTMLInputElement final : public TextControlElement,
|
|||
public nsIConstraintValidation {
|
||||
friend class AfterSetFilesOrDirectoriesCallback;
|
||||
friend class DispatchChangeEventCallback;
|
||||
friend class ::InputType;
|
||||
friend class InputType;
|
||||
|
||||
public:
|
||||
using nsGenericHTMLFormElementWithState::GetForm;
|
||||
|
@ -1496,7 +1486,16 @@ class HTMLInputElement final : public TextControlElement,
|
|||
/*
|
||||
* InputType object created based on input type.
|
||||
*/
|
||||
UniquePtr<::InputType, DoNotDelete> mInputType;
|
||||
UniquePtr<InputType, InputType::DoNotDelete> mInputType;
|
||||
|
||||
static constexpr size_t INPUT_TYPE_SIZE =
|
||||
sizeof(mozilla::Variant<
|
||||
TextInputType, SearchInputType, TelInputType, URLInputType,
|
||||
EmailInputType, PasswordInputType, NumberInputType, RangeInputType,
|
||||
RadioInputType, CheckboxInputType, ButtonInputType, ImageInputType,
|
||||
ResetInputType, SubmitInputType, DateInputType, TimeInputType,
|
||||
WeekInputType, MonthInputType, DateTimeLocalInputType,
|
||||
FileInputType, ColorInputType, HiddenInputType>);
|
||||
|
||||
// Memory allocated for mInputType, reused when type changes.
|
||||
char mInputTypeMem[INPUT_TYPE_SIZE];
|
||||
|
|
|
@ -4,70 +4,72 @@
|
|||
* 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/. */
|
||||
|
||||
#ifndef ButtonInputTypes_h__
|
||||
#define ButtonInputTypes_h__
|
||||
#ifndef mozilla_dom_ButtonInputTypes_h__
|
||||
#define mozilla_dom_ButtonInputTypes_h__
|
||||
|
||||
#include "InputType.h"
|
||||
#include "mozilla/dom/InputType.h"
|
||||
|
||||
class ButtonInputTypeBase : public ::InputType {
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class ButtonInputTypeBase : public InputType {
|
||||
public:
|
||||
~ButtonInputTypeBase() override = default;
|
||||
|
||||
protected:
|
||||
explicit ButtonInputTypeBase(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit ButtonInputTypeBase(HTMLInputElement* aInputElement)
|
||||
: InputType(aInputElement) {}
|
||||
};
|
||||
|
||||
// input type=button
|
||||
class ButtonInputType : public ButtonInputTypeBase {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) ButtonInputType(aInputElement);
|
||||
}
|
||||
|
||||
private:
|
||||
explicit ButtonInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit ButtonInputType(HTMLInputElement* aInputElement)
|
||||
: ButtonInputTypeBase(aInputElement) {}
|
||||
};
|
||||
|
||||
// input type=image
|
||||
class ImageInputType : public ButtonInputTypeBase {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) ImageInputType(aInputElement);
|
||||
}
|
||||
|
||||
private:
|
||||
explicit ImageInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit ImageInputType(HTMLInputElement* aInputElement)
|
||||
: ButtonInputTypeBase(aInputElement) {}
|
||||
};
|
||||
|
||||
// input type=reset
|
||||
class ResetInputType : public ButtonInputTypeBase {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) ResetInputType(aInputElement);
|
||||
}
|
||||
|
||||
private:
|
||||
explicit ResetInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit ResetInputType(HTMLInputElement* aInputElement)
|
||||
: ButtonInputTypeBase(aInputElement) {}
|
||||
};
|
||||
|
||||
// input type=submit
|
||||
class SubmitInputType : public ButtonInputTypeBase {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) SubmitInputType(aInputElement);
|
||||
}
|
||||
|
||||
private:
|
||||
explicit SubmitInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit SubmitInputType(HTMLInputElement* aInputElement)
|
||||
: ButtonInputTypeBase(aInputElement) {}
|
||||
};
|
||||
|
||||
#endif /* ButtonInputTypes_h__ */
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* mozilla_dom_ButtonInputTypes_h__ */
|
||||
|
|
|
@ -4,10 +4,13 @@
|
|||
* 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/CheckableInputTypes.h"
|
||||
|
||||
#include "mozilla/dom/HTMLInputElement.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
/* input type=checkbox */
|
||||
|
||||
bool CheckboxInputType::IsValueMissing() const {
|
||||
|
|
|
@ -4,25 +4,27 @@
|
|||
* 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/. */
|
||||
|
||||
#ifndef CheckableInputTypes_h__
|
||||
#define CheckableInputTypes_h__
|
||||
#ifndef mozilla_dom_CheckableInputTypes_h__
|
||||
#define mozilla_dom_CheckableInputTypes_h__
|
||||
|
||||
#include "InputType.h"
|
||||
#include "mozilla/dom/InputType.h"
|
||||
|
||||
class CheckableInputTypeBase : public ::InputType {
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class CheckableInputTypeBase : public InputType {
|
||||
public:
|
||||
~CheckableInputTypeBase() override = default;
|
||||
|
||||
protected:
|
||||
explicit CheckableInputTypeBase(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit CheckableInputTypeBase(HTMLInputElement* aInputElement)
|
||||
: InputType(aInputElement) {}
|
||||
};
|
||||
|
||||
// input type=checkbox
|
||||
class CheckboxInputType : public CheckableInputTypeBase {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) CheckboxInputType(aInputElement);
|
||||
}
|
||||
|
||||
|
@ -31,23 +33,25 @@ class CheckboxInputType : public CheckableInputTypeBase {
|
|||
nsresult GetValueMissingMessage(nsAString& aMessage) override;
|
||||
|
||||
private:
|
||||
explicit CheckboxInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit CheckboxInputType(HTMLInputElement* aInputElement)
|
||||
: CheckableInputTypeBase(aInputElement) {}
|
||||
};
|
||||
|
||||
// input type=radio
|
||||
class RadioInputType : public CheckableInputTypeBase {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) RadioInputType(aInputElement);
|
||||
}
|
||||
|
||||
nsresult GetValueMissingMessage(nsAString& aMessage) override;
|
||||
|
||||
private:
|
||||
explicit RadioInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit RadioInputType(HTMLInputElement* aInputElement)
|
||||
: CheckableInputTypeBase(aInputElement) {}
|
||||
};
|
||||
|
||||
#endif /* CheckableInputTypes_h__ */
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* mozilla_dom_CheckableInputTypes_h__ */
|
||||
|
|
|
@ -4,22 +4,27 @@
|
|||
* 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/. */
|
||||
|
||||
#ifndef ColorInputType_h__
|
||||
#define ColorInputType_h__
|
||||
#ifndef mozilla_dom_ColorInputType_h__
|
||||
#define mozilla_dom_ColorInputType_h__
|
||||
|
||||
#include "InputType.h"
|
||||
#include "mozilla/dom/InputType.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
// input type=color
|
||||
class ColorInputType : public ::InputType {
|
||||
class ColorInputType : public InputType {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) ColorInputType(aInputElement);
|
||||
}
|
||||
|
||||
private:
|
||||
explicit ColorInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit ColorInputType(HTMLInputElement* aInputElement)
|
||||
: InputType(aInputElement) {}
|
||||
};
|
||||
|
||||
#endif /* ColorInputType_h__ */
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* mozilla_dom_ColorInputType_h__ */
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* 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/DateTimeInputTypes.h"
|
||||
|
||||
#include "js/Date.h"
|
||||
#include "mozilla/AsyncEventDispatcher.h"
|
||||
|
@ -39,12 +39,12 @@ bool DateTimeInputTypeBase::IsValueMissing() const {
|
|||
}
|
||||
|
||||
bool DateTimeInputTypeBase::IsRangeOverflow() const {
|
||||
mozilla::Decimal maximum = mInputElement->GetMaximum();
|
||||
Decimal maximum = mInputElement->GetMaximum();
|
||||
if (maximum.isNaN()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mozilla::Decimal value = mInputElement->GetValueAsDecimal();
|
||||
Decimal value = mInputElement->GetValueAsDecimal();
|
||||
if (value.isNaN()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -53,12 +53,12 @@ bool DateTimeInputTypeBase::IsRangeOverflow() const {
|
|||
}
|
||||
|
||||
bool DateTimeInputTypeBase::IsRangeUnderflow() const {
|
||||
mozilla::Decimal minimum = mInputElement->GetMinimum();
|
||||
Decimal minimum = mInputElement->GetMinimum();
|
||||
if (minimum.isNaN()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mozilla::Decimal value = mInputElement->GetValueAsDecimal();
|
||||
Decimal value = mInputElement->GetValueAsDecimal();
|
||||
if (value.isNaN()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -67,10 +67,10 @@ bool DateTimeInputTypeBase::IsRangeUnderflow() const {
|
|||
}
|
||||
|
||||
bool DateTimeInputTypeBase::HasStepMismatch(bool aUseZeroIfValueNaN) const {
|
||||
mozilla::Decimal value = mInputElement->GetValueAsDecimal();
|
||||
Decimal value = mInputElement->GetValueAsDecimal();
|
||||
if (value.isNaN()) {
|
||||
if (aUseZeroIfValueNaN) {
|
||||
value = mozilla::Decimal(0);
|
||||
value = Decimal(0);
|
||||
} else {
|
||||
// The element can't suffer from step mismatch if it's value isn't a
|
||||
// number.
|
||||
|
@ -78,13 +78,13 @@ bool DateTimeInputTypeBase::HasStepMismatch(bool aUseZeroIfValueNaN) const {
|
|||
}
|
||||
}
|
||||
|
||||
mozilla::Decimal step = mInputElement->GetStep();
|
||||
Decimal step = mInputElement->GetStep();
|
||||
if (step == kStepAny) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Value has to be an integral multiple of step.
|
||||
return NS_floorModulo(value - GetStepBase(), step) != mozilla::Decimal(0);
|
||||
return NS_floorModulo(value - GetStepBase(), step) != Decimal(0);
|
||||
}
|
||||
|
||||
bool DateTimeInputTypeBase::HasBadInput() const {
|
||||
|
@ -185,8 +185,8 @@ nsresult DateInputType::GetBadInputMessage(nsAString& aMessage) {
|
|||
mInputElement->OwnerDoc(), aMessage);
|
||||
}
|
||||
|
||||
bool DateInputType::ConvertStringToNumber(
|
||||
nsAString& aValue, mozilla::Decimal& aResultValue) const {
|
||||
bool DateInputType::ConvertStringToNumber(nsAString& aValue,
|
||||
Decimal& aResultValue) const {
|
||||
uint32_t year, month, day;
|
||||
if (!ParseDate(aValue, &year, &month, &day)) {
|
||||
return false;
|
||||
|
@ -197,11 +197,11 @@ bool DateInputType::ConvertStringToNumber(
|
|||
return false;
|
||||
}
|
||||
|
||||
aResultValue = mozilla::Decimal::fromDouble(time.toDouble());
|
||||
aResultValue = Decimal::fromDouble(time.toDouble());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DateInputType::ConvertNumberToString(mozilla::Decimal aValue,
|
||||
bool DateInputType::ConvertNumberToString(Decimal aValue,
|
||||
nsAString& aResultString) const {
|
||||
MOZ_ASSERT(aValue.isFinite(), "aValue must be a valid non-Infinite number.");
|
||||
|
||||
|
@ -214,7 +214,7 @@ bool DateInputType::ConvertNumberToString(mozilla::Decimal aValue,
|
|||
double month = JS::MonthFromTime(aValue.toDouble());
|
||||
double day = JS::DayFromTime(aValue.toDouble());
|
||||
|
||||
if (mozilla::IsNaN(year) || mozilla::IsNaN(month) || mozilla::IsNaN(day)) {
|
||||
if (IsNaN(year) || IsNaN(month) || IsNaN(day)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -224,18 +224,18 @@ bool DateInputType::ConvertNumberToString(mozilla::Decimal aValue,
|
|||
|
||||
// input type=time
|
||||
|
||||
bool TimeInputType::ConvertStringToNumber(
|
||||
nsAString& aValue, mozilla::Decimal& aResultValue) const {
|
||||
bool TimeInputType::ConvertStringToNumber(nsAString& aValue,
|
||||
Decimal& aResultValue) const {
|
||||
uint32_t milliseconds;
|
||||
if (!ParseTime(aValue, &milliseconds)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
aResultValue = mozilla::Decimal(int32_t(milliseconds));
|
||||
aResultValue = Decimal(int32_t(milliseconds));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool TimeInputType::ConvertNumberToString(mozilla::Decimal aValue,
|
||||
bool TimeInputType::ConvertNumberToString(Decimal aValue,
|
||||
nsAString& aResultString) const {
|
||||
MOZ_ASSERT(aValue.isFinite(), "aValue must be a valid non-Infinite number.");
|
||||
|
||||
|
@ -246,8 +246,7 @@ bool TimeInputType::ConvertNumberToString(mozilla::Decimal aValue,
|
|||
// times inside a day [00:00, 24:00[, which means that we should do a
|
||||
// modulo on |aValue| using the number of milliseconds in a day (86400000).
|
||||
uint32_t value =
|
||||
NS_floorModulo(aValue, mozilla::Decimal::fromDouble(kMsPerDay))
|
||||
.toDouble();
|
||||
NS_floorModulo(aValue, Decimal::fromDouble(kMsPerDay)).toDouble();
|
||||
|
||||
uint16_t milliseconds, seconds, minutes, hours;
|
||||
if (!GetTimeFromMs(value, &hours, &minutes, &seconds, &milliseconds)) {
|
||||
|
@ -335,8 +334,8 @@ nsresult TimeInputType::GetRangeUnderflowMessage(nsAString& aMessage) {
|
|||
|
||||
// input type=week
|
||||
|
||||
bool WeekInputType::ConvertStringToNumber(
|
||||
nsAString& aValue, mozilla::Decimal& aResultValue) const {
|
||||
bool WeekInputType::ConvertStringToNumber(nsAString& aValue,
|
||||
Decimal& aResultValue) const {
|
||||
uint32_t year, week;
|
||||
if (!ParseWeek(aValue, &year, &week)) {
|
||||
return false;
|
||||
|
@ -352,11 +351,11 @@ bool WeekInputType::ConvertStringToNumber(
|
|||
}
|
||||
|
||||
double days = DaysSinceEpochFromWeek(year, week);
|
||||
aResultValue = mozilla::Decimal::fromDouble(days * kMsPerDay);
|
||||
aResultValue = Decimal::fromDouble(days * kMsPerDay);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WeekInputType::ConvertNumberToString(mozilla::Decimal aValue,
|
||||
bool WeekInputType::ConvertNumberToString(Decimal aValue,
|
||||
nsAString& aResultString) const {
|
||||
MOZ_ASSERT(aValue.isFinite(), "aValue must be a valid non-Infinite number.");
|
||||
|
||||
|
@ -398,8 +397,8 @@ bool WeekInputType::ConvertNumberToString(mozilla::Decimal aValue,
|
|||
|
||||
// input type=month
|
||||
|
||||
bool MonthInputType::ConvertStringToNumber(
|
||||
nsAString& aValue, mozilla::Decimal& aResultValue) const {
|
||||
bool MonthInputType::ConvertStringToNumber(nsAString& aValue,
|
||||
Decimal& aResultValue) const {
|
||||
uint32_t year, month;
|
||||
if (!ParseMonth(aValue, &year, &month)) {
|
||||
return false;
|
||||
|
@ -415,11 +414,11 @@ bool MonthInputType::ConvertStringToNumber(
|
|||
}
|
||||
|
||||
int32_t months = MonthsSinceJan1970(year, month);
|
||||
aResultValue = mozilla::Decimal(int32_t(months));
|
||||
aResultValue = Decimal(int32_t(months));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MonthInputType::ConvertNumberToString(mozilla::Decimal aValue,
|
||||
bool MonthInputType::ConvertNumberToString(Decimal aValue,
|
||||
nsAString& aResultString) const {
|
||||
MOZ_ASSERT(aValue.isFinite(), "aValue must be a valid non-Infinite number.");
|
||||
|
||||
|
@ -427,7 +426,7 @@ bool MonthInputType::ConvertNumberToString(mozilla::Decimal aValue,
|
|||
|
||||
aValue = aValue.floor();
|
||||
|
||||
double month = NS_floorModulo(aValue, mozilla::Decimal(12)).toDouble();
|
||||
double month = NS_floorModulo(aValue, Decimal(12)).toDouble();
|
||||
month = (month < 0 ? month + 12 : month);
|
||||
|
||||
double year = 1970 + (aValue.toDouble() - month) / 12;
|
||||
|
@ -448,7 +447,7 @@ bool MonthInputType::ConvertNumberToString(mozilla::Decimal aValue,
|
|||
// input type=datetime-local
|
||||
|
||||
bool DateTimeLocalInputType::ConvertStringToNumber(
|
||||
nsAString& aValue, mozilla::Decimal& aResultValue) const {
|
||||
nsAString& aValue, Decimal& aResultValue) const {
|
||||
uint32_t year, month, day, timeInMs;
|
||||
if (!ParseDateTimeLocal(aValue, &year, &month, &day, &timeInMs)) {
|
||||
return false;
|
||||
|
@ -460,12 +459,12 @@ bool DateTimeLocalInputType::ConvertStringToNumber(
|
|||
return false;
|
||||
}
|
||||
|
||||
aResultValue = mozilla::Decimal::fromDouble(time.toDouble());
|
||||
aResultValue = Decimal::fromDouble(time.toDouble());
|
||||
return true;
|
||||
}
|
||||
|
||||
bool DateTimeLocalInputType::ConvertNumberToString(
|
||||
mozilla::Decimal aValue, nsAString& aResultString) const {
|
||||
Decimal aValue, nsAString& aResultString) const {
|
||||
MOZ_ASSERT(aValue.isFinite(), "aValue must be a valid non-Infinite number.");
|
||||
|
||||
aResultString.Truncate();
|
||||
|
@ -473,8 +472,7 @@ bool DateTimeLocalInputType::ConvertNumberToString(
|
|||
aValue = aValue.floor();
|
||||
|
||||
uint32_t timeValue =
|
||||
NS_floorModulo(aValue, mozilla::Decimal::fromDouble(kMsPerDay))
|
||||
.toDouble();
|
||||
NS_floorModulo(aValue, Decimal::fromDouble(kMsPerDay)).toDouble();
|
||||
|
||||
uint16_t milliseconds, seconds, minutes, hours;
|
||||
if (!GetTimeFromMs(timeValue, &hours, &minutes, &seconds, &milliseconds)) {
|
||||
|
@ -485,7 +483,7 @@ bool DateTimeLocalInputType::ConvertNumberToString(
|
|||
double month = JS::MonthFromTime(aValue.toDouble());
|
||||
double day = JS::DayFromTime(aValue.toDouble());
|
||||
|
||||
if (mozilla::IsNaN(year) || mozilla::IsNaN(month) || mozilla::IsNaN(day)) {
|
||||
if (IsNaN(year) || IsNaN(month) || IsNaN(day)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,12 +4,15 @@
|
|||
* 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/. */
|
||||
|
||||
#ifndef DateTimeInputTypes_h__
|
||||
#define DateTimeInputTypes_h__
|
||||
#ifndef mozilla_dom_DateTimeInputTypes_h__
|
||||
#define mozilla_dom_DateTimeInputTypes_h__
|
||||
|
||||
#include "InputType.h"
|
||||
#include "mozilla/dom/InputType.h"
|
||||
|
||||
class DateTimeInputTypeBase : public ::InputType {
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class DateTimeInputTypeBase : public InputType {
|
||||
public:
|
||||
~DateTimeInputTypeBase() override = default;
|
||||
|
||||
|
@ -25,7 +28,7 @@ class DateTimeInputTypeBase : public ::InputType {
|
|||
nsresult MinMaxStepAttrChanged() override;
|
||||
|
||||
protected:
|
||||
explicit DateTimeInputTypeBase(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit DateTimeInputTypeBase(HTMLInputElement* aInputElement)
|
||||
: InputType(aInputElement) {}
|
||||
|
||||
bool IsMutable() const override;
|
||||
|
@ -52,8 +55,7 @@ class DateTimeInputTypeBase : public ::InputType {
|
|||
// input type=date
|
||||
class DateInputType : public DateTimeInputTypeBase {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) DateInputType(aInputElement);
|
||||
}
|
||||
|
||||
|
@ -64,26 +66,25 @@ class DateInputType : public DateTimeInputTypeBase {
|
|||
nsresult GetBadInputMessage(nsAString& aMessage) override;
|
||||
|
||||
bool ConvertStringToNumber(nsAString& aValue,
|
||||
mozilla::Decimal& aResultValue) const override;
|
||||
bool ConvertNumberToString(mozilla::Decimal aValue,
|
||||
Decimal& aResultValue) const override;
|
||||
bool ConvertNumberToString(Decimal aValue,
|
||||
nsAString& aResultString) const override;
|
||||
|
||||
private:
|
||||
explicit DateInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit DateInputType(HTMLInputElement* aInputElement)
|
||||
: DateTimeInputTypeBase(aInputElement) {}
|
||||
};
|
||||
|
||||
// input type=time
|
||||
class TimeInputType : public DateTimeInputTypeBase {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) TimeInputType(aInputElement);
|
||||
}
|
||||
|
||||
bool ConvertStringToNumber(nsAString& aValue,
|
||||
mozilla::Decimal& aResultValue) const override;
|
||||
bool ConvertNumberToString(mozilla::Decimal aValue,
|
||||
Decimal& aResultValue) const override;
|
||||
bool ConvertNumberToString(Decimal aValue,
|
||||
nsAString& aResultString) const override;
|
||||
bool IsRangeOverflow() const override;
|
||||
bool IsRangeUnderflow() const override;
|
||||
|
@ -91,7 +92,7 @@ class TimeInputType : public DateTimeInputTypeBase {
|
|||
nsresult GetRangeUnderflowMessage(nsAString& aMessage) override;
|
||||
|
||||
private:
|
||||
explicit TimeInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit TimeInputType(HTMLInputElement* aInputElement)
|
||||
: DateTimeInputTypeBase(aInputElement) {}
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/input.html#has-a-reversed-range
|
||||
|
@ -103,55 +104,55 @@ class TimeInputType : public DateTimeInputTypeBase {
|
|||
// input type=week
|
||||
class WeekInputType : public DateTimeInputTypeBase {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) WeekInputType(aInputElement);
|
||||
}
|
||||
|
||||
bool ConvertStringToNumber(nsAString& aValue,
|
||||
mozilla::Decimal& aResultValue) const override;
|
||||
bool ConvertNumberToString(mozilla::Decimal aValue,
|
||||
Decimal& aResultValue) const override;
|
||||
bool ConvertNumberToString(Decimal aValue,
|
||||
nsAString& aResultString) const override;
|
||||
|
||||
private:
|
||||
explicit WeekInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit WeekInputType(HTMLInputElement* aInputElement)
|
||||
: DateTimeInputTypeBase(aInputElement) {}
|
||||
};
|
||||
|
||||
// input type=month
|
||||
class MonthInputType : public DateTimeInputTypeBase {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) MonthInputType(aInputElement);
|
||||
}
|
||||
|
||||
bool ConvertStringToNumber(nsAString& aValue,
|
||||
mozilla::Decimal& aResultValue) const override;
|
||||
bool ConvertNumberToString(mozilla::Decimal aValue,
|
||||
Decimal& aResultValue) const override;
|
||||
bool ConvertNumberToString(Decimal aValue,
|
||||
nsAString& aResultString) const override;
|
||||
|
||||
private:
|
||||
explicit MonthInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit MonthInputType(HTMLInputElement* aInputElement)
|
||||
: DateTimeInputTypeBase(aInputElement) {}
|
||||
};
|
||||
|
||||
// input type=datetime-local
|
||||
class DateTimeLocalInputType : public DateTimeInputTypeBase {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) DateTimeLocalInputType(aInputElement);
|
||||
}
|
||||
|
||||
bool ConvertStringToNumber(nsAString& aValue,
|
||||
mozilla::Decimal& aResultValue) const override;
|
||||
bool ConvertNumberToString(mozilla::Decimal aValue,
|
||||
Decimal& aResultValue) const override;
|
||||
bool ConvertNumberToString(Decimal aValue,
|
||||
nsAString& aResultString) const override;
|
||||
|
||||
private:
|
||||
explicit DateTimeLocalInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit DateTimeLocalInputType(HTMLInputElement* aInputElement)
|
||||
: DateTimeInputTypeBase(aInputElement) {}
|
||||
};
|
||||
|
||||
#endif /* DateTimeInputTypes_h__ */
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* mozilla_dom_DateTimeInputTypes_h__ */
|
||||
|
|
|
@ -4,10 +4,13 @@
|
|||
* 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/FileInputType.h"
|
||||
|
||||
#include "mozilla/dom/HTMLInputElement.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
bool FileInputType::IsValueMissing() const {
|
||||
if (!mInputElement->IsRequired()) {
|
||||
return false;
|
||||
|
|
|
@ -4,16 +4,18 @@
|
|||
* 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/. */
|
||||
|
||||
#ifndef FileInputType_h__
|
||||
#define FileInputType_h__
|
||||
#ifndef mozilla_dom_FileInputType_h__
|
||||
#define mozilla_dom_FileInputType_h__
|
||||
|
||||
#include "InputType.h"
|
||||
#include "mozilla/dom/InputType.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
// input type=file
|
||||
class FileInputType : public ::InputType {
|
||||
class FileInputType : public InputType {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) FileInputType(aInputElement);
|
||||
}
|
||||
|
||||
|
@ -22,8 +24,11 @@ class FileInputType : public ::InputType {
|
|||
nsresult GetValueMissingMessage(nsAString& aMessage) override;
|
||||
|
||||
private:
|
||||
explicit FileInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit FileInputType(HTMLInputElement* aInputElement)
|
||||
: InputType(aInputElement) {}
|
||||
};
|
||||
|
||||
#endif /* FileInputType_h__ */
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* mozilla_dom_FileInputType_h__ */
|
||||
|
|
|
@ -4,22 +4,27 @@
|
|||
* 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/. */
|
||||
|
||||
#ifndef HiddenInputType_h__
|
||||
#define HiddenInputType_h__
|
||||
#ifndef mozilla_dom_HiddenInputType_h__
|
||||
#define mozilla_dom_HiddenInputType_h__
|
||||
|
||||
#include "InputType.h"
|
||||
#include "mozilla/dom/InputType.h"
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
// input type=hidden
|
||||
class HiddenInputType : public ::InputType {
|
||||
class HiddenInputType : public InputType {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) HiddenInputType(aInputElement);
|
||||
}
|
||||
|
||||
private:
|
||||
explicit HiddenInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit HiddenInputType(HTMLInputElement* aInputElement)
|
||||
: InputType(aInputElement) {}
|
||||
};
|
||||
|
||||
#endif /* HiddenInputType_h__ */
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* mozilla_dom_HiddenInputType_h__ */
|
||||
|
|
|
@ -4,26 +4,28 @@
|
|||
* 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 "InputType.h"
|
||||
#include "mozilla/dom/InputType.h"
|
||||
|
||||
#include "nsIFormControl.h"
|
||||
#include "ButtonInputTypes.h"
|
||||
#include "CheckableInputTypes.h"
|
||||
#include "ColorInputType.h"
|
||||
#include "DateTimeInputTypes.h"
|
||||
#include "FileInputType.h"
|
||||
#include "HiddenInputType.h"
|
||||
#include "NumericInputTypes.h"
|
||||
#include "SingleLineTextInputTypes.h"
|
||||
#include "mozilla/dom/ButtonInputTypes.h"
|
||||
#include "mozilla/dom/CheckableInputTypes.h"
|
||||
#include "mozilla/dom/ColorInputType.h"
|
||||
#include "mozilla/dom/DateTimeInputTypes.h"
|
||||
#include "mozilla/dom/FileInputType.h"
|
||||
#include "mozilla/dom/HiddenInputType.h"
|
||||
#include "mozilla/dom/NumericInputTypes.h"
|
||||
#include "mozilla/dom/SingleLineTextInputTypes.h"
|
||||
|
||||
#include "nsContentUtils.h"
|
||||
|
||||
const mozilla::Decimal InputType::kStepAny = mozilla::Decimal(0);
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
/* static */ mozilla::UniquePtr<InputType, DoNotDelete> InputType::Create(
|
||||
mozilla::dom::HTMLInputElement* aInputElement, uint8_t aType,
|
||||
void* aMemory) {
|
||||
mozilla::UniquePtr<InputType, DoNotDelete> inputType;
|
||||
const Decimal InputType::kStepAny = Decimal(0);
|
||||
|
||||
/* static */ UniquePtr<InputType, InputType::DoNotDelete> InputType::Create(
|
||||
HTMLInputElement* aInputElement, uint8_t aType, void* aMemory) {
|
||||
UniquePtr<InputType, InputType::DoNotDelete> inputType;
|
||||
switch (aType) {
|
||||
// Single line text
|
||||
case NS_FORM_INPUT_TEXT:
|
||||
|
@ -113,13 +115,11 @@ void InputType::GetNonFileValueInternal(nsAString& aValue) const {
|
|||
}
|
||||
|
||||
nsresult InputType::SetValueInternal(const nsAString& aValue, uint32_t aFlags) {
|
||||
RefPtr<mozilla::dom::HTMLInputElement> inputElement(mInputElement);
|
||||
RefPtr<HTMLInputElement> inputElement(mInputElement);
|
||||
return inputElement->SetValueInternal(aValue, aFlags);
|
||||
}
|
||||
|
||||
mozilla::Decimal InputType::GetStepBase() const {
|
||||
return mInputElement->GetStepBase();
|
||||
}
|
||||
Decimal InputType::GetStepBase() const { return mInputElement->GetStepBase(); }
|
||||
|
||||
nsIFrame* InputType::GetPrimaryFrame() const {
|
||||
return mInputElement->GetPrimaryFrame();
|
||||
|
@ -157,8 +157,7 @@ nsresult InputType::GetValidationMessage(
|
|||
case nsIConstraintValidation::VALIDITY_STATE_TOO_LONG: {
|
||||
nsAutoString message;
|
||||
int32_t maxLength = mInputElement->MaxLength();
|
||||
int32_t textLength =
|
||||
mInputElement->InputTextLength(mozilla::dom::CallerType::System);
|
||||
int32_t textLength = mInputElement->InputTextLength(CallerType::System);
|
||||
nsAutoString strMaxLength;
|
||||
nsAutoString strTextLength;
|
||||
|
||||
|
@ -174,8 +173,7 @@ nsresult InputType::GetValidationMessage(
|
|||
case nsIConstraintValidation::VALIDITY_STATE_TOO_SHORT: {
|
||||
nsAutoString message;
|
||||
int32_t minLength = mInputElement->MinLength();
|
||||
int32_t textLength =
|
||||
mInputElement->InputTextLength(mozilla::dom::CallerType::System);
|
||||
int32_t textLength = mInputElement->InputTextLength(CallerType::System);
|
||||
nsAutoString strMinLength;
|
||||
nsAutoString strTextLength;
|
||||
|
||||
|
@ -255,20 +253,18 @@ nsresult InputType::GetValidationMessage(
|
|||
case nsIConstraintValidation::VALIDITY_STATE_STEP_MISMATCH: {
|
||||
nsAutoString message;
|
||||
|
||||
mozilla::Decimal value = mInputElement->GetValueAsDecimal();
|
||||
Decimal value = mInputElement->GetValueAsDecimal();
|
||||
MOZ_ASSERT(!value.isNaN());
|
||||
|
||||
mozilla::Decimal step = mInputElement->GetStep();
|
||||
MOZ_ASSERT(step != kStepAny && step > mozilla::Decimal(0));
|
||||
Decimal step = mInputElement->GetStep();
|
||||
MOZ_ASSERT(step != kStepAny && step > Decimal(0));
|
||||
|
||||
mozilla::Decimal stepBase = mInputElement->GetStepBase();
|
||||
Decimal stepBase = mInputElement->GetStepBase();
|
||||
|
||||
mozilla::Decimal valueLow =
|
||||
value - NS_floorModulo(value - stepBase, step);
|
||||
mozilla::Decimal valueHigh =
|
||||
value + step - NS_floorModulo(value - stepBase, step);
|
||||
Decimal valueLow = value - NS_floorModulo(value - stepBase, step);
|
||||
Decimal valueHigh = value + step - NS_floorModulo(value - stepBase, step);
|
||||
|
||||
mozilla::Decimal maximum = mInputElement->GetMaximum();
|
||||
Decimal maximum = mInputElement->GetMaximum();
|
||||
|
||||
if (maximum.isNaN() || valueHigh <= maximum) {
|
||||
nsAutoString valueLowStr, valueHighStr;
|
||||
|
@ -341,13 +337,13 @@ nsresult InputType::GetBadInputMessage(nsAString& aMessage) {
|
|||
nsresult InputType::MinMaxStepAttrChanged() { return NS_OK; }
|
||||
|
||||
bool InputType::ConvertStringToNumber(nsAString& aValue,
|
||||
mozilla::Decimal& aResultValue) const {
|
||||
Decimal& aResultValue) const {
|
||||
NS_WARNING("InputType::ConvertStringToNumber called");
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool InputType::ConvertNumberToString(mozilla::Decimal aValue,
|
||||
bool InputType::ConvertNumberToString(Decimal aValue,
|
||||
nsAString& aResultString) const {
|
||||
NS_WARNING("InputType::ConvertNumberToString called");
|
||||
|
||||
|
@ -365,7 +361,7 @@ bool InputType::ParseDate(const nsAString& aValue, uint32_t* aYear,
|
|||
|
||||
bool InputType::ParseTime(const nsAString& aValue, uint32_t* aResult) const {
|
||||
// see comment in InputType::ParseDate().
|
||||
return mozilla::dom::HTMLInputElement::ParseTime(aValue, aResult);
|
||||
return HTMLInputElement::ParseTime(aValue, aResult);
|
||||
}
|
||||
|
||||
bool InputType::ParseMonth(const nsAString& aValue, uint32_t* aYear,
|
||||
|
|
|
@ -4,8 +4,8 @@
|
|||
* 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/. */
|
||||
|
||||
#ifndef InputType_h__
|
||||
#define InputType_h__
|
||||
#ifndef mozilla_dom_InputType_h__
|
||||
#define mozilla_dom_InputType_h__
|
||||
|
||||
#include <stdint.h>
|
||||
#include "mozilla/Decimal.h"
|
||||
|
@ -21,28 +21,31 @@ inline mozilla::Decimal NS_floorModulo(mozilla::Decimal x, mozilla::Decimal y) {
|
|||
return (x - y * (x / y).floor());
|
||||
}
|
||||
|
||||
class nsIFrame;
|
||||
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
class HTMLInputElement;
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
struct DoNotDelete;
|
||||
class nsIFrame;
|
||||
|
||||
/**
|
||||
* A common superclass for different types of a HTMLInputElement.
|
||||
*/
|
||||
class InputType {
|
||||
public:
|
||||
static mozilla::UniquePtr<InputType, DoNotDelete> Create(
|
||||
mozilla::dom::HTMLInputElement* aInputElement, uint8_t aType,
|
||||
void* aMemory);
|
||||
// Custom deleter for UniquePtr<InputType> to avoid freeing memory
|
||||
// pre-allocated for InputType, but we still need to call the destructor
|
||||
// explictly.
|
||||
struct DoNotDelete {
|
||||
void operator()(InputType* p) { p->~InputType(); }
|
||||
};
|
||||
|
||||
static UniquePtr<InputType, DoNotDelete> Create(
|
||||
HTMLInputElement* aInputElement, uint8_t aType, void* aMemory);
|
||||
|
||||
virtual ~InputType() = default;
|
||||
|
||||
// Float value returned by GetStep() when the step attribute is set to 'any'.
|
||||
static const mozilla::Decimal kStepAny;
|
||||
static const Decimal kStepAny;
|
||||
|
||||
/**
|
||||
* Drop the reference to the input element.
|
||||
|
@ -55,7 +58,7 @@ class InputType {
|
|||
virtual bool IsValueMissing() const;
|
||||
virtual bool HasTypeMismatch() const;
|
||||
// May return Nothing() if the JS engine failed to evaluate the regex.
|
||||
virtual mozilla::Maybe<bool> HasPatternMismatch() const;
|
||||
virtual Maybe<bool> HasPatternMismatch() const;
|
||||
virtual bool IsRangeOverflow() const;
|
||||
virtual bool IsRangeUnderflow() const;
|
||||
virtual bool HasStepMismatch(bool aUseZeroIfValueNaN) const;
|
||||
|
@ -82,7 +85,7 @@ class InputType {
|
|||
* @result whether the parsing was successful.
|
||||
*/
|
||||
virtual bool ConvertStringToNumber(nsAString& aValue,
|
||||
mozilla::Decimal& aResultValue) const;
|
||||
Decimal& aResultValue) const;
|
||||
|
||||
/**
|
||||
* Convert a Decimal to a string in a type specific way, ie convert a
|
||||
|
@ -95,11 +98,11 @@ class InputType {
|
|||
* type is not supported or the number can't be converted to a string
|
||||
* as expected by the type.
|
||||
*/
|
||||
virtual bool ConvertNumberToString(mozilla::Decimal aValue,
|
||||
virtual bool ConvertNumberToString(Decimal aValue,
|
||||
nsAString& aResultString) const;
|
||||
|
||||
protected:
|
||||
explicit InputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit InputType(HTMLInputElement* aInputElement)
|
||||
: mInputElement(aInputElement) {}
|
||||
|
||||
/**
|
||||
|
@ -140,7 +143,7 @@ class InputType {
|
|||
*
|
||||
* @return The step base.
|
||||
*/
|
||||
mozilla::Decimal GetStepBase() const;
|
||||
Decimal GetStepBase() const;
|
||||
|
||||
/**
|
||||
* Get the primary frame for the input element.
|
||||
|
@ -229,13 +232,10 @@ class InputType {
|
|||
*/
|
||||
uint32_t MaximumWeekInYear(uint32_t aYear) const;
|
||||
|
||||
mozilla::dom::HTMLInputElement* mInputElement;
|
||||
HTMLInputElement* mInputElement;
|
||||
};
|
||||
|
||||
// Custom deleter for UniquePtr<InputType> to avoid freeing memory pre-allocated
|
||||
// for InputType, but we still need to call the destructor explictly.
|
||||
struct DoNotDelete {
|
||||
void operator()(::InputType* p) { p->~InputType(); }
|
||||
};
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* InputType_h__ */
|
||||
#endif /* mozilla_dom_InputType_h__ */
|
||||
|
|
|
@ -4,19 +4,22 @@
|
|||
* 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/NumericInputTypes.h"
|
||||
|
||||
#include "mozilla/TextControlState.h"
|
||||
#include "mozilla/dom/HTMLInputElement.h"
|
||||
#include "ICUUtils.h"
|
||||
|
||||
using namespace mozilla;
|
||||
using namespace mozilla::dom;
|
||||
|
||||
bool NumericInputTypeBase::IsRangeOverflow() const {
|
||||
mozilla::Decimal maximum = mInputElement->GetMaximum();
|
||||
Decimal maximum = mInputElement->GetMaximum();
|
||||
if (maximum.isNaN()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mozilla::Decimal value = mInputElement->GetValueAsDecimal();
|
||||
Decimal value = mInputElement->GetValueAsDecimal();
|
||||
if (value.isNaN()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -25,12 +28,12 @@ bool NumericInputTypeBase::IsRangeOverflow() const {
|
|||
}
|
||||
|
||||
bool NumericInputTypeBase::IsRangeUnderflow() const {
|
||||
mozilla::Decimal minimum = mInputElement->GetMinimum();
|
||||
Decimal minimum = mInputElement->GetMinimum();
|
||||
if (minimum.isNaN()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
mozilla::Decimal value = mInputElement->GetValueAsDecimal();
|
||||
Decimal value = mInputElement->GetValueAsDecimal();
|
||||
if (value.isNaN()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -39,10 +42,10 @@ bool NumericInputTypeBase::IsRangeUnderflow() const {
|
|||
}
|
||||
|
||||
bool NumericInputTypeBase::HasStepMismatch(bool aUseZeroIfValueNaN) const {
|
||||
mozilla::Decimal value = mInputElement->GetValueAsDecimal();
|
||||
Decimal value = mInputElement->GetValueAsDecimal();
|
||||
if (value.isNaN()) {
|
||||
if (aUseZeroIfValueNaN) {
|
||||
value = mozilla::Decimal(0);
|
||||
value = Decimal(0);
|
||||
} else {
|
||||
// The element can't suffer from step mismatch if it's value isn't a
|
||||
// number.
|
||||
|
@ -50,24 +53,23 @@ bool NumericInputTypeBase::HasStepMismatch(bool aUseZeroIfValueNaN) const {
|
|||
}
|
||||
}
|
||||
|
||||
mozilla::Decimal step = mInputElement->GetStep();
|
||||
Decimal step = mInputElement->GetStep();
|
||||
if (step == kStepAny) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Value has to be an integral multiple of step.
|
||||
return NS_floorModulo(value - GetStepBase(), step) != mozilla::Decimal(0);
|
||||
return NS_floorModulo(value - GetStepBase(), step) != Decimal(0);
|
||||
}
|
||||
|
||||
nsresult NumericInputTypeBase::GetRangeOverflowMessage(nsAString& aMessage) {
|
||||
// We want to show the value as parsed when it's a number
|
||||
mozilla::Decimal maximum = mInputElement->GetMaximum();
|
||||
Decimal maximum = mInputElement->GetMaximum();
|
||||
MOZ_ASSERT(!maximum.isNaN());
|
||||
|
||||
nsAutoString maxStr;
|
||||
char buf[32];
|
||||
mozilla::DebugOnly<bool> ok =
|
||||
maximum.toString(buf, mozilla::ArrayLength(buf));
|
||||
DebugOnly<bool> ok = maximum.toString(buf, ArrayLength(buf));
|
||||
maxStr.AssignASCII(buf);
|
||||
MOZ_ASSERT(ok, "buf not big enough");
|
||||
|
||||
|
@ -77,13 +79,12 @@ nsresult NumericInputTypeBase::GetRangeOverflowMessage(nsAString& aMessage) {
|
|||
}
|
||||
|
||||
nsresult NumericInputTypeBase::GetRangeUnderflowMessage(nsAString& aMessage) {
|
||||
mozilla::Decimal minimum = mInputElement->GetMinimum();
|
||||
Decimal minimum = mInputElement->GetMinimum();
|
||||
MOZ_ASSERT(!minimum.isNaN());
|
||||
|
||||
nsAutoString minStr;
|
||||
char buf[32];
|
||||
mozilla::DebugOnly<bool> ok =
|
||||
minimum.toString(buf, mozilla::ArrayLength(buf));
|
||||
DebugOnly<bool> ok = minimum.toString(buf, ArrayLength(buf));
|
||||
minStr.AssignASCII(buf);
|
||||
MOZ_ASSERT(ok, "buf not big enough");
|
||||
|
||||
|
@ -92,27 +93,27 @@ nsresult NumericInputTypeBase::GetRangeUnderflowMessage(nsAString& aMessage) {
|
|||
"FormValidationNumberRangeUnderflow", mInputElement->OwnerDoc(), minStr);
|
||||
}
|
||||
|
||||
bool NumericInputTypeBase::ConvertStringToNumber(
|
||||
nsAString& aValue, mozilla::Decimal& aResultValue) const {
|
||||
bool NumericInputTypeBase::ConvertStringToNumber(nsAString& aValue,
|
||||
Decimal& aResultValue) const {
|
||||
// FIXME(emilio, bug 1605158): This should really just be
|
||||
// StringToDecimal(aValue).
|
||||
ICUUtils::LanguageTagIterForContent langTagIter(mInputElement);
|
||||
aResultValue =
|
||||
mozilla::Decimal::fromDouble(ICUUtils::ParseNumber(aValue, langTagIter));
|
||||
Decimal::fromDouble(ICUUtils::ParseNumber(aValue, langTagIter));
|
||||
if (!aResultValue.isFinite()) {
|
||||
aResultValue = mozilla::dom::HTMLInputElement::StringToDecimal(aValue);
|
||||
aResultValue = HTMLInputElement::StringToDecimal(aValue);
|
||||
}
|
||||
return aResultValue.isFinite();
|
||||
}
|
||||
|
||||
bool NumericInputTypeBase::ConvertNumberToString(
|
||||
mozilla::Decimal aValue, nsAString& aResultString) const {
|
||||
Decimal aValue, nsAString& aResultString) const {
|
||||
MOZ_ASSERT(aValue.isFinite(), "aValue must be a valid non-Infinite number.");
|
||||
|
||||
aResultString.Truncate();
|
||||
|
||||
char buf[32];
|
||||
bool ok = aValue.toString(buf, mozilla::ArrayLength(buf));
|
||||
bool ok = aValue.toString(buf, ArrayLength(buf));
|
||||
aResultString.AssignASCII(buf);
|
||||
MOZ_ASSERT(ok, "buf not big enough");
|
||||
|
||||
|
@ -170,5 +171,5 @@ nsresult RangeInputType::MinMaxStepAttrChanged() {
|
|||
// example above were to change from 1 to -1.
|
||||
nsAutoString value;
|
||||
GetNonFileValueInternal(value);
|
||||
return SetValueInternal(value, mozilla::TextControlState::eSetValue_Internal);
|
||||
return SetValueInternal(value, TextControlState::eSetValue_Internal);
|
||||
}
|
||||
|
|
|
@ -4,12 +4,15 @@
|
|||
* 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/. */
|
||||
|
||||
#ifndef NumericInputTypes_h__
|
||||
#define NumericInputTypes_h__
|
||||
#ifndef mozilla_dom_NumericInputTypes_h__
|
||||
#define mozilla_dom_NumericInputTypes_h__
|
||||
|
||||
#include "InputType.h"
|
||||
#include "mozilla/dom/InputType.h"
|
||||
|
||||
class NumericInputTypeBase : public ::InputType {
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class NumericInputTypeBase : public InputType {
|
||||
public:
|
||||
~NumericInputTypeBase() override = default;
|
||||
|
||||
|
@ -21,20 +24,19 @@ class NumericInputTypeBase : public ::InputType {
|
|||
nsresult GetRangeUnderflowMessage(nsAString& aMessage) override;
|
||||
|
||||
bool ConvertStringToNumber(nsAString& aValue,
|
||||
mozilla::Decimal& aResultValue) const override;
|
||||
bool ConvertNumberToString(mozilla::Decimal aValue,
|
||||
Decimal& aResultValue) const override;
|
||||
bool ConvertNumberToString(Decimal aValue,
|
||||
nsAString& aResultString) const override;
|
||||
|
||||
protected:
|
||||
explicit NumericInputTypeBase(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit NumericInputTypeBase(HTMLInputElement* aInputElement)
|
||||
: InputType(aInputElement) {}
|
||||
};
|
||||
|
||||
// input type=number
|
||||
class NumberInputType : public NumericInputTypeBase {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) NumberInputType(aInputElement);
|
||||
}
|
||||
|
||||
|
@ -48,15 +50,14 @@ class NumberInputType : public NumericInputTypeBase {
|
|||
bool IsMutable() const override;
|
||||
|
||||
private:
|
||||
explicit NumberInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit NumberInputType(HTMLInputElement* aInputElement)
|
||||
: NumericInputTypeBase(aInputElement) {}
|
||||
};
|
||||
|
||||
// input type=range
|
||||
class RangeInputType : public NumericInputTypeBase {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) RangeInputType(aInputElement);
|
||||
}
|
||||
|
||||
|
@ -64,8 +65,11 @@ class RangeInputType : public NumericInputTypeBase {
|
|||
nsresult MinMaxStepAttrChanged() override;
|
||||
|
||||
private:
|
||||
explicit RangeInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit RangeInputType(HTMLInputElement* aInputElement)
|
||||
: NumericInputTypeBase(aInputElement) {}
|
||||
};
|
||||
|
||||
#endif /* NumericInputTypes_h__ */
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* mozilla_dom_NumericInputTypes_h__ */
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
* 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 "SingleLineTextInputTypes.h"
|
||||
#include "mozilla/dom/SingleLineTextInputTypes.h"
|
||||
|
||||
#include "mozilla/dom/HTMLInputElement.h"
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
|
@ -33,8 +33,7 @@ bool SingleLineTextInputTypeBase::IsTooLong() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
int32_t textLength =
|
||||
mInputElement->InputTextLength(mozilla::dom::CallerType::System);
|
||||
int32_t textLength = mInputElement->InputTextLength(CallerType::System);
|
||||
|
||||
return textLength > maxLength;
|
||||
}
|
||||
|
@ -47,8 +46,7 @@ bool SingleLineTextInputTypeBase::IsTooShort() const {
|
|||
return false;
|
||||
}
|
||||
|
||||
int32_t textLength =
|
||||
mInputElement->InputTextLength(mozilla::dom::CallerType::System);
|
||||
int32_t textLength = mInputElement->InputTextLength(CallerType::System);
|
||||
|
||||
return textLength && textLength < minLength;
|
||||
}
|
||||
|
|
|
@ -4,12 +4,15 @@
|
|||
* 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/. */
|
||||
|
||||
#ifndef SingleLineTextInputTypes_h__
|
||||
#define SingleLineTextInputTypes_h__
|
||||
#ifndef mozilla_dom_SingleLineTextInputTypes_h__
|
||||
#define mozilla_dom_SingleLineTextInputTypes_h__
|
||||
|
||||
#include "InputType.h"
|
||||
#include "mozilla/dom/InputType.h"
|
||||
|
||||
class SingleLineTextInputTypeBase : public ::InputType {
|
||||
namespace mozilla {
|
||||
namespace dom {
|
||||
|
||||
class SingleLineTextInputTypeBase : public InputType {
|
||||
public:
|
||||
~SingleLineTextInputTypeBase() override = default;
|
||||
|
||||
|
@ -18,11 +21,10 @@ class SingleLineTextInputTypeBase : public ::InputType {
|
|||
bool IsTooShort() const final;
|
||||
bool IsValueMissing() const final;
|
||||
// Can return Nothing() if the JS engine failed to evaluate the pattern.
|
||||
mozilla::Maybe<bool> HasPatternMismatch() const final;
|
||||
Maybe<bool> HasPatternMismatch() const final;
|
||||
|
||||
protected:
|
||||
explicit SingleLineTextInputTypeBase(
|
||||
mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit SingleLineTextInputTypeBase(HTMLInputElement* aInputElement)
|
||||
: InputType(aInputElement) {}
|
||||
|
||||
bool IsMutable() const override;
|
||||
|
@ -31,47 +33,43 @@ class SingleLineTextInputTypeBase : public ::InputType {
|
|||
// input type=text
|
||||
class TextInputType : public SingleLineTextInputTypeBase {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) TextInputType(aInputElement);
|
||||
}
|
||||
|
||||
private:
|
||||
explicit TextInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit TextInputType(HTMLInputElement* aInputElement)
|
||||
: SingleLineTextInputTypeBase(aInputElement) {}
|
||||
};
|
||||
|
||||
// input type=search
|
||||
class SearchInputType : public SingleLineTextInputTypeBase {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) SearchInputType(aInputElement);
|
||||
}
|
||||
|
||||
private:
|
||||
explicit SearchInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit SearchInputType(HTMLInputElement* aInputElement)
|
||||
: SingleLineTextInputTypeBase(aInputElement) {}
|
||||
};
|
||||
|
||||
// input type=tel
|
||||
class TelInputType : public SingleLineTextInputTypeBase {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) TelInputType(aInputElement);
|
||||
}
|
||||
|
||||
private:
|
||||
explicit TelInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit TelInputType(HTMLInputElement* aInputElement)
|
||||
: SingleLineTextInputTypeBase(aInputElement) {}
|
||||
};
|
||||
|
||||
// input type=url
|
||||
class URLInputType : public SingleLineTextInputTypeBase {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) URLInputType(aInputElement);
|
||||
}
|
||||
|
||||
|
@ -80,15 +78,14 @@ class URLInputType : public SingleLineTextInputTypeBase {
|
|||
nsresult GetTypeMismatchMessage(nsAString& aMessage) override;
|
||||
|
||||
private:
|
||||
explicit URLInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit URLInputType(HTMLInputElement* aInputElement)
|
||||
: SingleLineTextInputTypeBase(aInputElement) {}
|
||||
};
|
||||
|
||||
// input type=email
|
||||
class EmailInputType : public SingleLineTextInputTypeBase {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) EmailInputType(aInputElement);
|
||||
}
|
||||
|
||||
|
@ -99,7 +96,7 @@ class EmailInputType : public SingleLineTextInputTypeBase {
|
|||
nsresult GetBadInputMessage(nsAString& aMessage) override;
|
||||
|
||||
private:
|
||||
explicit EmailInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit EmailInputType(HTMLInputElement* aInputElement)
|
||||
: SingleLineTextInputTypeBase(aInputElement) {}
|
||||
|
||||
/**
|
||||
|
@ -148,14 +145,16 @@ class EmailInputType : public SingleLineTextInputTypeBase {
|
|||
// input type=password
|
||||
class PasswordInputType : public SingleLineTextInputTypeBase {
|
||||
public:
|
||||
static InputType* Create(mozilla::dom::HTMLInputElement* aInputElement,
|
||||
void* aMemory) {
|
||||
static InputType* Create(HTMLInputElement* aInputElement, void* aMemory) {
|
||||
return new (aMemory) PasswordInputType(aInputElement);
|
||||
}
|
||||
|
||||
private:
|
||||
explicit PasswordInputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
explicit PasswordInputType(HTMLInputElement* aInputElement)
|
||||
: SingleLineTextInputTypeBase(aInputElement) {}
|
||||
};
|
||||
|
||||
#endif /* SingleLineTextInputTypes_h__ */
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
#endif /* mozilla_dom_SingleLineTextInputTypes_h__ */
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
# 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/.
|
||||
|
||||
EXPORTS += [
|
||||
EXPORTS.mozilla.dom += [
|
||||
'ButtonInputTypes.h',
|
||||
'CheckableInputTypes.h',
|
||||
'ColorInputType.h',
|
||||
|
|
Загрузка…
Ссылка в новой задаче