mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-11 20:35:50 +00:00
Bug 1345767 - Part 2: Factor IsTooLong/Short() out of HTMLInputElement. r=smaug
MozReview-Commit-ID: 5svYqBEFgzk --HG-- extra : rebase_source : a8842e76d7ca6c57ccf6c1115832a2a8e4153bb0
This commit is contained in:
parent
606150d6f4
commit
b15f522fed
@ -1466,9 +1466,9 @@ HTMLInputElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
||||
if (aName == nsGkAtoms::readonly || aName == nsGkAtoms::disabled) {
|
||||
UpdateBarredFromConstraintValidation();
|
||||
}
|
||||
} else if (MinOrMaxLengthApplies() && aName == nsGkAtoms::maxlength) {
|
||||
} else if (aName == nsGkAtoms::maxlength) {
|
||||
UpdateTooLongValidityState();
|
||||
} else if (MinOrMaxLengthApplies() && aName == nsGkAtoms::minlength) {
|
||||
} else if (aName == nsGkAtoms::minlength) {
|
||||
UpdateTooShortValidityState();
|
||||
} else if (aName == nsGkAtoms::pattern && mDoneCreating) {
|
||||
UpdatePatternMismatchValidityState();
|
||||
@ -7520,42 +7520,22 @@ bool
|
||||
HTMLInputElement::IsTooLong()
|
||||
{
|
||||
if (!mValueChanged ||
|
||||
!mLastValueChangeWasInteractive ||
|
||||
!MinOrMaxLengthApplies() ||
|
||||
!HasAttr(kNameSpaceID_None, nsGkAtoms::maxlength)) {
|
||||
!mLastValueChangeWasInteractive) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t maxLength = MaxLength();
|
||||
|
||||
// Maxlength of -1 means parsing error.
|
||||
if (maxLength == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return InputTextLength(CallerType::System) > maxLength;
|
||||
return mInputType->IsTooLong();
|
||||
}
|
||||
|
||||
bool
|
||||
HTMLInputElement::IsTooShort()
|
||||
{
|
||||
if (!mValueChanged ||
|
||||
!mLastValueChangeWasInteractive ||
|
||||
!MinOrMaxLengthApplies() ||
|
||||
!HasAttr(kNameSpaceID_None, nsGkAtoms::minlength)) {
|
||||
!mLastValueChangeWasInteractive) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t minLength = MinLength();
|
||||
|
||||
// Minlength of -1 means parsing error.
|
||||
if (minLength == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t textLength = InputTextLength(CallerType::System);
|
||||
|
||||
return textLength && textLength < minLength;
|
||||
return mInputType->IsTooShort();
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -1132,11 +1132,6 @@ protected:
|
||||
*/
|
||||
bool DoesAutocompleteApply() const;
|
||||
|
||||
/**
|
||||
* Returns if the minlength or maxlength attributes apply for the current type.
|
||||
*/
|
||||
bool MinOrMaxLengthApplies() const { return IsSingleLineTextControl(false, mType); }
|
||||
|
||||
void FreeData();
|
||||
nsTextEditorState *GetEditorState() const;
|
||||
|
||||
|
@ -108,3 +108,15 @@ InputType::DropReference()
|
||||
// Drop our (non ref-counted) reference.
|
||||
mInputElement = nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
InputType::IsTooLong() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
InputType::IsTooShort() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -35,6 +35,9 @@ public:
|
||||
*/
|
||||
void DropReference();
|
||||
|
||||
virtual bool IsTooLong() const;
|
||||
virtual bool IsTooShort() const;
|
||||
|
||||
protected:
|
||||
explicit InputType(mozilla::dom::HTMLInputElement* aInputElement)
|
||||
: mInputElement(aInputElement)
|
||||
|
42
dom/html/input/SingleLineTextInputTypes.cpp
Normal file
42
dom/html/input/SingleLineTextInputTypes.cpp
Normal file
@ -0,0 +1,42 @@
|
||||
/* -*- 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 "SingleLineTextInputTypes.h"
|
||||
|
||||
#include "mozilla/dom/HTMLInputElement.h"
|
||||
#include "mozilla/dom/BindingDeclarations.h"
|
||||
|
||||
bool
|
||||
SingleLineTextInputTypeBase::IsTooLong() const
|
||||
{
|
||||
int32_t maxLength = mInputElement->MaxLength();
|
||||
|
||||
// Maxlength of -1 means attribute isn't set or parsing error.
|
||||
if (maxLength == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t textLength =
|
||||
mInputElement->InputTextLength(mozilla::dom::CallerType::System);
|
||||
|
||||
return textLength > maxLength;
|
||||
}
|
||||
|
||||
bool
|
||||
SingleLineTextInputTypeBase::IsTooShort() const
|
||||
{
|
||||
int32_t minLength = mInputElement->MinLength();
|
||||
|
||||
// Minlength of -1 means attribute isn't set or parsing error.
|
||||
if (minLength == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int32_t textLength =
|
||||
mInputElement->InputTextLength(mozilla::dom::CallerType::System);
|
||||
|
||||
return textLength && textLength < minLength;
|
||||
}
|
@ -14,6 +14,9 @@ class SingleLineTextInputTypeBase : public ::InputType
|
||||
public:
|
||||
~SingleLineTextInputTypeBase() override {}
|
||||
|
||||
bool IsTooLong() const override;
|
||||
bool IsTooShort() const override;
|
||||
|
||||
protected:
|
||||
explicit SingleLineTextInputTypeBase(
|
||||
mozilla::dom::HTMLInputElement* aInputElement)
|
||||
|
@ -18,6 +18,7 @@ EXPORTS += [
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
'InputType.cpp',
|
||||
'SingleLineTextInputTypes.cpp',
|
||||
]
|
||||
|
||||
include('/ipc/chromium/chromium-config.mozbuild')
|
||||
|
Loading…
Reference in New Issue
Block a user