Commit bf110973 authored by rniwa@webkit.org's avatar rniwa@webkit.org

Push more code from HTMLInputElement::setValue to TextFieldInputType::setValue

https://bugs.webkit.org/show_bug.cgi?id=67742

Reviewed by Darin Adler.

Moved more code in HTMLInputElement::setValue to TextFieldInputType::setValue, and merged
InputType::valueChanged into InputType::setValue. Also introduced
InputType::dispatchChangeEventInResponseToSetValue to be overridden by TextFieldInputType.

* html/BaseButtonInputType.cpp:
(WebCore::BaseButtonInputType::setValue):
* html/BaseButtonInputType.h:
* html/BaseCheckableInputType.cpp:
(WebCore::BaseCheckableInputType::setValue):
* html/BaseCheckableInputType.h:
* html/ColorInputType.cpp:
* html/ColorInputType.h:
* html/FileInputType.cpp:
(WebCore::FileInputType::setValue):
* html/FileInputType.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::setValue):
* html/HTMLInputElement.h:
(WebCore::HTMLInputElement::cacheSelectionInResponseToSetValue):
* html/HiddenInputType.cpp:
(WebCore::HiddenInputType::setValue):
* html/HiddenInputType.h:
* html/InputType.cpp:
(WebCore::InputType::setValue):
(WebCore::InputType::dispatchChangeEventInResponseToSetValue):
* html/InputType.h:
* html/RangeInputType.cpp:
(WebCore::RangeInputType::setValue):
* html/RangeInputType.h:
* html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::setValue):
(WebCore::TextFieldInputType::dispatchChangeEventInResponseToSetValue):
* html/TextFieldInputType.h:


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@94836 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 3db7d55c
2011-09-07 Ryosuke Niwa <rniwa@webkit.org>
Push more code from HTMLInputElement::setValue to TextFieldInputType::setValue
https://bugs.webkit.org/show_bug.cgi?id=67742
Reviewed by Darin Adler.
Moved more code in HTMLInputElement::setValue to TextFieldInputType::setValue, and merged
InputType::valueChanged into InputType::setValue. Also introduced
InputType::dispatchChangeEventInResponseToSetValue to be overridden by TextFieldInputType.
* html/BaseButtonInputType.cpp:
(WebCore::BaseButtonInputType::setValue):
* html/BaseButtonInputType.h:
* html/BaseCheckableInputType.cpp:
(WebCore::BaseCheckableInputType::setValue):
* html/BaseCheckableInputType.h:
* html/ColorInputType.cpp:
* html/ColorInputType.h:
* html/FileInputType.cpp:
(WebCore::FileInputType::setValue):
* html/FileInputType.h:
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::setValue):
* html/HTMLInputElement.h:
(WebCore::HTMLInputElement::cacheSelectionInResponseToSetValue):
* html/HiddenInputType.cpp:
(WebCore::HiddenInputType::setValue):
* html/HiddenInputType.h:
* html/InputType.cpp:
(WebCore::InputType::setValue):
(WebCore::InputType::dispatchChangeEventInResponseToSetValue):
* html/InputType.h:
* html/RangeInputType.cpp:
(WebCore::RangeInputType::setValue):
* html/RangeInputType.h:
* html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::setValue):
(WebCore::TextFieldInputType::dispatchChangeEventInResponseToSetValue):
* html/TextFieldInputType.h:
2011-09-08 Annie Sullivan <sullivan@chromium.org>
Crashes in WebCore::InsertNodeBeforeCommand constructor.
......@@ -100,7 +100,7 @@ bool BaseButtonInputType::storesValueSeparateFromAttribute()
return false;
}
void BaseButtonInputType::setValue(const String& sanitizedValue, bool)
void BaseButtonInputType::setValue(const String& sanitizedValue, bool, bool)
{
element()->setAttribute(valueAttr, sanitizedValue);
}
......
......@@ -48,7 +48,7 @@ private:
virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) const;
virtual void accessKeyAction(bool sendToAnyElement);
virtual bool storesValueSeparateFromAttribute();
virtual void setValue(const String&, bool);
virtual void setValue(const String&, bool, bool);
};
} // namespace WebCore
......
......@@ -104,7 +104,7 @@ bool BaseCheckableInputType::storesValueSeparateFromAttribute()
return false;
}
void BaseCheckableInputType::setValue(const String& sanitizedValue, bool)
void BaseCheckableInputType::setValue(const String& sanitizedValue, bool, bool)
{
element()->setAttribute(valueAttr, sanitizedValue);
}
......
......@@ -50,7 +50,7 @@ private:
virtual void accessKeyAction(bool sendToAnyElement);
virtual String fallbackValue();
virtual bool storesValueSeparateFromAttribute();
virtual void setValue(const String&, bool);
virtual void setValue(const String&, bool, bool);
virtual bool isCheckable();
};
......
......@@ -121,8 +121,13 @@ void ColorInputType::createShadowSubtree()
updateColorSwatch();
}
void ColorInputType::valueChanged()
void ColorInputType::setValue(const String& value, bool valueChanged, bool sendChangeEvent);
{
InputType::setValue(value, valueChanged, sendChangeEvent);
if (!valueChanged)
return;
updateColorSwatch();
if (ColorChooser::chooser()->client() == this) {
if (Chrome* chrome = this->chrome())
......
......@@ -52,7 +52,7 @@ private:
virtual String sanitizeValue(const String&);
virtual Color valueAsColor() const;
virtual void createShadowSubtree();
virtual void valueChanged();
virtual void setValue(const String&, bool valueChanged, bool sendChangeEvent);
virtual void handleClickEvent(MouseEvent*);
virtual void handleDOMActivateEvent(Event*);
virtual void detach();
......
......@@ -216,7 +216,7 @@ bool FileInputType::storesValueSeparateFromAttribute()
return true;
}
void FileInputType::setValue(const String&, bool)
void FileInputType::setValue(const String&, bool, bool)
{
m_fileList->clear();
m_icon.clear();
......
......@@ -59,7 +59,7 @@ private:
virtual bool canSetValue(const String&);
virtual bool getTypeSpecificValue(String&); // Checked first, before internal storage or the value attribute.
virtual bool storesValueSeparateFromAttribute();
virtual void setValue(const String&, bool sendChangeEvent);
virtual void setValue(const String&, bool valueChanged, bool sendChangeEvent);
virtual void receiveDroppedFiles(const Vector<String>&);
virtual Icon* icon() const;
virtual bool isFileUpload() const;
......
......@@ -1084,41 +1084,24 @@ void HTMLInputElement::setValue(const String& value, bool sendChangeEvent)
if (!m_inputType->canSetValue(value))
return;
RefPtr<HTMLInputElement> protector(this);
String sanitizedValue = sanitizeValue(value);
bool valueChanged = sanitizedValue != this->value();
setLastChangeWasNotUserEdit();
setFormControlValueMatchesRenderer(false);
m_inputType->setValue(sanitizedValue, sendChangeEvent);
m_suggestedValue = String(); // Prevent TextFieldInputType::setValue from using the suggested value.
m_inputType->setValue(sanitizedValue, valueChanged, sendChangeEvent);
setNeedsValidityCheck();
m_suggestedValue = String(); // updateInnerTextValue uses the suggested value.
if (valueChanged)
updateInnerTextValue();
if (isTextField()) {
unsigned max = visibleValue().length();
if (document()->focusedNode() == this)
setSelectionRange(max, max);
else
cacheSelection(max, max, SelectionHasNoDirection);
}
if (!valueChanged)
return;
m_inputType->valueChanged();
if (sendChangeEvent) {
// If the user is still editing this field, dispatch an input event rather than a change event.
// The change event will be dispatched when editing finishes.
if (isTextField() && focused())
dispatchFormControlInputEvent();
else
dispatchFormControlChangeEvent();
}
if (sendChangeEvent)
m_inputType->dispatchChangeEventInResponseToSetValue();
// FIXME: Why do we do this when !sendChangeEvent?
if (isTextField() && (!focused() || !sendChangeEvent))
setTextAsOfLastFormControlChangeEvent(value);
......
......@@ -231,6 +231,8 @@ public:
bool isConformToInputMask(const String&) const;
#endif
void cacheSelectionInResponseToSetValue(int caretOffset) { cacheSelection(caretOffset, caretOffset, SelectionHasNoDirection); }
#if ENABLE(INPUT_COLOR)
// For test purposes.
bool connectToColorChooser();
......
......@@ -74,7 +74,7 @@ bool HiddenInputType::storesValueSeparateFromAttribute()
return false;
}
void HiddenInputType::setValue(const String& sanitizedValue, bool)
void HiddenInputType::setValue(const String& sanitizedValue, bool, bool)
{
element()->setAttribute(valueAttr, sanitizedValue);
}
......
......@@ -49,7 +49,7 @@ private:
virtual bool storesValueSeparateFromAttribute();
virtual bool isHiddenType() const;
virtual bool shouldRespectHeightAndWidthAttributes();
virtual void setValue(const String&, bool);
virtual void setValue(const String&, bool, bool);
};
} // namespace WebCore
......
......@@ -449,10 +449,6 @@ void InputType::srcAttributeChanged()
{
}
void InputType::valueChanged()
{
}
void InputType::willMoveToNewOwnerDocument()
{
}
......@@ -525,12 +521,17 @@ bool InputType::storesValueSeparateFromAttribute()
return true;
}
void InputType::setValue(const String& sanitizedValue, bool sendChangeEvent)
void InputType::setValue(const String& sanitizedValue, bool, bool sendChangeEvent)
{
element()->setValueInternal(sanitizedValue, sendChangeEvent);
element()->setNeedsStyleRecalc();
}
void InputType::dispatchChangeEventInResponseToSetValue()
{
element()->dispatchFormControlChangeEvent();
}
bool InputType::canSetValue(const String&)
{
return true;
......
......@@ -213,7 +213,6 @@ public:
virtual void stepAttributeChanged();
virtual void altAttributeChanged();
virtual void srcAttributeChanged();
virtual void valueChanged();
virtual void willMoveToNewOwnerDocument();
virtual bool shouldRespectAlignAttribute();
virtual FileList* files();
......@@ -224,7 +223,8 @@ public:
virtual bool shouldSendChangeEventAfterCheckedChanged();
virtual bool canSetValue(const String&);
virtual bool storesValueSeparateFromAttribute();
virtual void setValue(const String&, bool sendChangeEvent);
virtual void setValue(const String&, bool valueChanged, bool sendChangeEvent);
virtual void dispatchChangeEventInResponseToSetValue();
virtual bool shouldResetOnDocumentActivation();
virtual bool shouldRespectListAttribute();
virtual bool shouldRespectSpeechAttribute();
......
......@@ -285,8 +285,13 @@ void RangeInputType::minOrMaxAttributeChanged()
element()->setNeedsStyleRecalc();
}
void RangeInputType::valueChanged()
void RangeInputType::setValue(const String& value, bool valueChanged, bool sendChangeEvent)
{
InputType::setValue(value, valueChanged, sendChangeEvent);
if (!valueChanged)
return;
sliderThumbElementOf(element())->setPositionFromValue();
}
......
......@@ -66,7 +66,7 @@ private:
virtual String serialize(double) const;
virtual void accessKeyAction(bool sendToAnyElement);
virtual void minOrMaxAttributeChanged();
virtual void valueChanged();
virtual void setValue(const String&, bool valueChanged, bool sendChangeEvent);
virtual String fallbackValue();
virtual String sanitizeValue(const String& proposedValue);
virtual bool shouldRespectListAttribute();
......
......@@ -73,10 +73,30 @@ bool TextFieldInputType::canSetSuggestedValue()
return true;
}
void TextFieldInputType::setValue(const String& sanitizedValue, bool sendChangeEvent)
void TextFieldInputType::setValue(const String& sanitizedValue, bool valueChanged, bool sendChangeEvent)
{
InputType::setValue(sanitizedValue, sendChangeEvent);
InputType::setValue(sanitizedValue, valueChanged, sendChangeEvent);
element()->updatePlaceholderVisibility(false);
if (valueChanged)
element()->updateInnerTextValue();
unsigned max = visibleValue().length();
if (element()->focused())
element()->setSelectionRange(max, max);
else
element()->cacheSelectionInResponseToSetValue(max);
}
void TextFieldInputType::dispatchChangeEventInResponseToSetValue()
{
// If the user is still editing this field, dispatch an input event rather than a change event.
// The change event will be dispatched when editing finishes.
if (element()->focused()) {
element()->dispatchFormControlInputEvent();
return;
}
InputType::dispatchChangeEventInResponseToSetValue();
}
void TextFieldInputType::handleKeydownEvent(KeyboardEvent* event)
......
......@@ -71,7 +71,8 @@ private:
virtual bool shouldSubmitImplicitly(Event*);
virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) const;
virtual bool shouldUseInputMethod() const;
virtual void setValue(const String&, bool sendChangeEvent);
virtual void setValue(const String&, bool valueChanged, bool sendChangeEvent);
virtual void dispatchChangeEventInResponseToSetValue();
virtual String sanitizeValue(const String&);
virtual bool shouldRespectListAttribute();
virtual HTMLElement* placeholderElement() const;
......
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