Commit 5b01920e authored by tkent@chromium.org's avatar tkent@chromium.org

Remove HTMLInputElement::isText and isTextType.

They are same and very confusing.
isText is used outside of HTMLInputElement.  It can be replaced with
|isTextField() && type() != InputTypeNames::number|.
isTextType is used only in HTMLInputElement. Its callsites should be
replaced with virtual function dispatches.

BUG=

Review URL: https://codereview.chromium.org/551283002

git-svn-id: svn://svn.chromium.org/blink/trunk@181614 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 11e01dd2
......@@ -580,10 +580,8 @@ bool AXNodeObject::isNativeTextControl() const
if (isHTMLTextAreaElement(*node))
return true;
if (isHTMLInputElement(*node)) {
HTMLInputElement* input = toHTMLInputElement(node);
return input->isText() || input->type() == InputTypeNames::number;
}
if (isHTMLInputElement(*node))
return toHTMLInputElement(node)->isTextField();
return false;
}
......
......@@ -241,20 +241,7 @@ bool HTMLInputElement::patternMismatch() const
bool HTMLInputElement::tooLong(const String& value, NeedsToCheckDirtyFlag check) const
{
// We use isTextType() instead of supportsMaxLength() because of the
// 'virtual' overhead.
if (!isTextType())
return false;
int max = maxLength();
if (max < 0)
return false;
if (check == CheckDirtyFlag) {
// Return false for the default value or a value set by a script even if
// it is longer than maxLength.
if (!hasDirtyValue() || !lastChangeWasUserEdit())
return false;
}
return value.length() > static_cast<unsigned>(max);
return m_inputType->tooLong(value, check);
}
bool HTMLInputElement::rangeUnderflow() const
......@@ -844,11 +831,6 @@ bool HTMLInputElement::isTextField() const
return m_inputType->isTextField();
}
bool HTMLInputElement::isTextType() const
{
return m_inputType->isTextType();
}
void HTMLInputElement::setChecked(bool nowChecked, TextFieldEventBehavior eventBehavior)
{
if (checked() == nowChecked)
......@@ -1565,11 +1547,6 @@ bool HTMLInputElement::isTextButton() const
return m_inputType->isTextButton();
}
bool HTMLInputElement::isText() const
{
return m_inputType->isTextType();
}
bool HTMLInputElement::isEnumeratable() const
{
return m_inputType->isEnumeratable();
......
......@@ -90,12 +90,6 @@ public:
// Returns true if the type is email, number, password, search, tel, text,
// or url.
bool isTextField() const;
// Returns true if the type is email, password, search, tel, text, or url.
// FIXME: It's highly likely that any call site calling this function should instead
// be using a different one. Many input elements behave like text fields, and in addition
// any unknown input type is treated as text. Consider, for example, isTextField or
// isTextField && !isPasswordField.
bool isText() const;
bool checked() const { return m_isChecked; }
void setChecked(bool, TextFieldEventBehavior = DispatchNoEvent);
......@@ -321,7 +315,6 @@ private:
virtual bool isInRange() const OVERRIDE FINAL;
virtual bool isOutOfRange() const OVERRIDE FINAL;
bool isTextType() const;
bool tooLong(const String&, NeedsToCheckDirtyFlag) const;
virtual bool supportsPlaceholder() const OVERRIDE FINAL;
......
......@@ -32,9 +32,23 @@ namespace blink {
using namespace HTMLNames;
bool BaseTextInputType::isTextType() const
int BaseTextInputType::maxLength() const
{
return true;
return element().maxLength();
}
bool BaseTextInputType::tooLong(const String& value, HTMLTextFormControlElement::NeedsToCheckDirtyFlag check) const
{
int max = element().maxLength();
if (max < 0)
return false;
if (check == HTMLTextFormControlElement::CheckDirtyFlag) {
// Return false for the default value or a value set by a script even if
// it is longer than maxLength.
if (!element().hasDirtyValue() || !element().lastChangeWasUserEdit())
return false;
}
return value.length() > static_cast<unsigned>(max);
}
bool BaseTextInputType::patternMismatch(const String& value) const
......
......@@ -42,7 +42,8 @@ protected:
BaseTextInputType(HTMLInputElement& element) : TextFieldInputType(element) { }
private:
virtual bool isTextType() const OVERRIDE FINAL;
virtual bool tooLong(const String&, HTMLTextFormControlElement::NeedsToCheckDirtyFlag) const OVERRIDE FINAL;
virtual int maxLength() const OVERRIDE FINAL;
virtual bool patternMismatch(const String&) const OVERRIDE FINAL;
virtual bool supportsPlaceholder() const OVERRIDE FINAL;
virtual bool supportsSelectionAPI() const OVERRIDE;
......
......@@ -142,11 +142,6 @@ bool InputType::isTextField() const
return false;
}
bool InputType::isTextType() const
{
return false;
}
bool InputType::shouldSaveAndRestoreFormControlState() const
{
return true;
......@@ -239,6 +234,11 @@ bool InputType::hasBadInput() const
return false;
}
bool InputType::tooLong(const String&, HTMLTextFormControlElement::NeedsToCheckDirtyFlag) const
{
return false;
}
bool InputType::patternMismatch(const String&) const
{
return false;
......@@ -645,6 +645,11 @@ bool InputType::shouldRespectHeightAndWidthAttributes()
return false;
}
int InputType::maxLength() const
{
return HTMLInputElement::maximumLength;
}
bool InputType::supportsPlaceholder() const
{
return false;
......
......@@ -77,7 +77,6 @@ public:
virtual bool isInteractiveContent() const;
virtual bool isTextButton() const;
virtual bool isTextField() const;
virtual bool isTextType() const;
// Form value functions
......@@ -111,6 +110,7 @@ public:
virtual bool valueMissing(const String&) const;
virtual bool hasBadInput() const;
virtual bool patternMismatch(const String&) const;
virtual bool tooLong(const String&, HTMLTextFormControlElement::NeedsToCheckDirtyFlag) const;
bool rangeUnderflow(const String&) const;
bool rangeOverflow(const String&) const;
bool isInRange(const String&) const;
......@@ -167,6 +167,7 @@ public:
virtual bool isCheckable();
virtual bool isSteppable() const;
virtual bool shouldRespectHeightAndWidthAttributes();
virtual int maxLength() const;
virtual bool supportsPlaceholder() const;
virtual bool supportsReadOnly() const;
virtual String defaultToolTip() const;
......
......@@ -419,7 +419,7 @@ void TextFieldInputType::handleBeforeTextInsertedEvent(BeforeTextInsertedEvent*
// Selected characters will be removed by the next text event.
unsigned baseLength = oldLength - selectionLength;
unsigned maxLength = static_cast<unsigned>(isTextType() ? element().maxLength() : HTMLInputElement::maximumLength); // maxLength can never be negative.
unsigned maxLength = static_cast<unsigned>(this->maxLength()); // maxLength can never be negative.
unsigned appendableLength = maxLength > baseLength ? maxLength - baseLength : 0;
// Truncate the inserted text to avoid violating the maxLength and other constraints.
......
......@@ -54,7 +54,7 @@ bool WebInputElement::isTextField() const
bool WebInputElement::isText() const
{
return constUnwrap<HTMLInputElement>()->isText();
return constUnwrap<HTMLInputElement>()->isTextField() && constUnwrap<HTMLInputElement>()->type() != InputTypeNames::number;
}
bool WebInputElement::isEmailField() const
......
......@@ -905,8 +905,7 @@ void WebViewImpl::getSelectionRootBounds(WebRect& bounds) const
Element* shadowHost = root->shadowHost();
if (shadowHost
&& (isHTMLTextAreaElement(*shadowHost)
|| (isHTMLInputElement(*shadowHost)
&& toHTMLInputElement(*shadowHost).isText())))
|| (isHTMLInputElement(*shadowHost) && toHTMLInputElement(*shadowHost).isTextField())))
root = shadowHost;
IntRect boundingBox = isHTMLHtmlElement(root)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment