Title: [94836] trunk/Source/WebCore
Revision
94836
Author
[email protected]
Date
2011-09-08 23:16:49 -0700 (Thu, 08 Sep 2011)

Log Message

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:

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (94835 => 94836)


--- trunk/Source/WebCore/ChangeLog	2011-09-09 06:07:22 UTC (rev 94835)
+++ trunk/Source/WebCore/ChangeLog	2011-09-09 06:16:49 UTC (rev 94836)
@@ -1,3 +1,44 @@
+2011-09-07  Ryosuke Niwa  <[email protected]>
+
+        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  <[email protected]>
 
         Crashes in WebCore::InsertNodeBeforeCommand constructor.

Modified: trunk/Source/WebCore/html/BaseButtonInputType.cpp (94835 => 94836)


--- trunk/Source/WebCore/html/BaseButtonInputType.cpp	2011-09-09 06:07:22 UTC (rev 94835)
+++ trunk/Source/WebCore/html/BaseButtonInputType.cpp	2011-09-09 06:16:49 UTC (rev 94836)
@@ -100,7 +100,7 @@
     return false;
 }
 
-void BaseButtonInputType::setValue(const String& sanitizedValue, bool)
+void BaseButtonInputType::setValue(const String& sanitizedValue, bool, bool)
 {
     element()->setAttribute(valueAttr, sanitizedValue);
 }

Modified: trunk/Source/WebCore/html/BaseButtonInputType.h (94835 => 94836)


--- trunk/Source/WebCore/html/BaseButtonInputType.h	2011-09-09 06:07:22 UTC (rev 94835)
+++ trunk/Source/WebCore/html/BaseButtonInputType.h	2011-09-09 06:16:49 UTC (rev 94836)
@@ -48,7 +48,7 @@
     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

Modified: trunk/Source/WebCore/html/BaseCheckableInputType.cpp (94835 => 94836)


--- trunk/Source/WebCore/html/BaseCheckableInputType.cpp	2011-09-09 06:07:22 UTC (rev 94835)
+++ trunk/Source/WebCore/html/BaseCheckableInputType.cpp	2011-09-09 06:16:49 UTC (rev 94836)
@@ -104,7 +104,7 @@
     return false;
 }
 
-void BaseCheckableInputType::setValue(const String& sanitizedValue, bool)
+void BaseCheckableInputType::setValue(const String& sanitizedValue, bool, bool)
 {
     element()->setAttribute(valueAttr, sanitizedValue);
 }

Modified: trunk/Source/WebCore/html/BaseCheckableInputType.h (94835 => 94836)


--- trunk/Source/WebCore/html/BaseCheckableInputType.h	2011-09-09 06:07:22 UTC (rev 94835)
+++ trunk/Source/WebCore/html/BaseCheckableInputType.h	2011-09-09 06:16:49 UTC (rev 94836)
@@ -50,7 +50,7 @@
     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();
 };
 

Modified: trunk/Source/WebCore/html/ColorInputType.cpp (94835 => 94836)


--- trunk/Source/WebCore/html/ColorInputType.cpp	2011-09-09 06:07:22 UTC (rev 94835)
+++ trunk/Source/WebCore/html/ColorInputType.cpp	2011-09-09 06:16:49 UTC (rev 94836)
@@ -121,8 +121,13 @@
     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())

Modified: trunk/Source/WebCore/html/ColorInputType.h (94835 => 94836)


--- trunk/Source/WebCore/html/ColorInputType.h	2011-09-09 06:07:22 UTC (rev 94835)
+++ trunk/Source/WebCore/html/ColorInputType.h	2011-09-09 06:16:49 UTC (rev 94836)
@@ -52,7 +52,7 @@
     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();

Modified: trunk/Source/WebCore/html/FileInputType.cpp (94835 => 94836)


--- trunk/Source/WebCore/html/FileInputType.cpp	2011-09-09 06:07:22 UTC (rev 94835)
+++ trunk/Source/WebCore/html/FileInputType.cpp	2011-09-09 06:16:49 UTC (rev 94836)
@@ -216,7 +216,7 @@
     return true;
 }
 
-void FileInputType::setValue(const String&, bool)
+void FileInputType::setValue(const String&, bool, bool)
 {
     m_fileList->clear();
     m_icon.clear();

Modified: trunk/Source/WebCore/html/FileInputType.h (94835 => 94836)


--- trunk/Source/WebCore/html/FileInputType.h	2011-09-09 06:07:22 UTC (rev 94835)
+++ trunk/Source/WebCore/html/FileInputType.h	2011-09-09 06:16:49 UTC (rev 94836)
@@ -59,7 +59,7 @@
     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;

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (94835 => 94836)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2011-09-09 06:07:22 UTC (rev 94835)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2011-09-09 06:16:49 UTC (rev 94836)
@@ -1084,41 +1084,24 @@
     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);
 

Modified: trunk/Source/WebCore/html/HTMLInputElement.h (94835 => 94836)


--- trunk/Source/WebCore/html/HTMLInputElement.h	2011-09-09 06:07:22 UTC (rev 94835)
+++ trunk/Source/WebCore/html/HTMLInputElement.h	2011-09-09 06:16:49 UTC (rev 94836)
@@ -231,6 +231,8 @@
     bool isConformToInputMask(const String&) const;
 #endif
 
+    void cacheSelectionInResponseToSetValue(int caretOffset) { cacheSelection(caretOffset, caretOffset, SelectionHasNoDirection); }
+
 #if ENABLE(INPUT_COLOR)
     // For test purposes.
     bool connectToColorChooser();

Modified: trunk/Source/WebCore/html/HiddenInputType.cpp (94835 => 94836)


--- trunk/Source/WebCore/html/HiddenInputType.cpp	2011-09-09 06:07:22 UTC (rev 94835)
+++ trunk/Source/WebCore/html/HiddenInputType.cpp	2011-09-09 06:16:49 UTC (rev 94836)
@@ -74,7 +74,7 @@
     return false;
 }
 
-void HiddenInputType::setValue(const String& sanitizedValue, bool)
+void HiddenInputType::setValue(const String& sanitizedValue, bool, bool)
 {
     element()->setAttribute(valueAttr, sanitizedValue);
 }

Modified: trunk/Source/WebCore/html/HiddenInputType.h (94835 => 94836)


--- trunk/Source/WebCore/html/HiddenInputType.h	2011-09-09 06:07:22 UTC (rev 94835)
+++ trunk/Source/WebCore/html/HiddenInputType.h	2011-09-09 06:16:49 UTC (rev 94836)
@@ -49,7 +49,7 @@
     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

Modified: trunk/Source/WebCore/html/InputType.cpp (94835 => 94836)


--- trunk/Source/WebCore/html/InputType.cpp	2011-09-09 06:07:22 UTC (rev 94835)
+++ trunk/Source/WebCore/html/InputType.cpp	2011-09-09 06:16:49 UTC (rev 94836)
@@ -449,10 +449,6 @@
 {
 }
 
-void InputType::valueChanged()
-{
-}
-
 void InputType::willMoveToNewOwnerDocument()
 {
 }
@@ -525,12 +521,17 @@
     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;

Modified: trunk/Source/WebCore/html/InputType.h (94835 => 94836)


--- trunk/Source/WebCore/html/InputType.h	2011-09-09 06:07:22 UTC (rev 94835)
+++ trunk/Source/WebCore/html/InputType.h	2011-09-09 06:16:49 UTC (rev 94836)
@@ -213,7 +213,6 @@
     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 @@
     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();

Modified: trunk/Source/WebCore/html/RangeInputType.cpp (94835 => 94836)


--- trunk/Source/WebCore/html/RangeInputType.cpp	2011-09-09 06:07:22 UTC (rev 94835)
+++ trunk/Source/WebCore/html/RangeInputType.cpp	2011-09-09 06:16:49 UTC (rev 94836)
@@ -285,8 +285,13 @@
     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();
 }
 

Modified: trunk/Source/WebCore/html/RangeInputType.h (94835 => 94836)


--- trunk/Source/WebCore/html/RangeInputType.h	2011-09-09 06:07:22 UTC (rev 94835)
+++ trunk/Source/WebCore/html/RangeInputType.h	2011-09-09 06:16:49 UTC (rev 94836)
@@ -66,7 +66,7 @@
     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();

Modified: trunk/Source/WebCore/html/TextFieldInputType.cpp (94835 => 94836)


--- trunk/Source/WebCore/html/TextFieldInputType.cpp	2011-09-09 06:07:22 UTC (rev 94835)
+++ trunk/Source/WebCore/html/TextFieldInputType.cpp	2011-09-09 06:16:49 UTC (rev 94836)
@@ -73,12 +73,32 @@
     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)
 {
     if (!element()->focused())

Modified: trunk/Source/WebCore/html/TextFieldInputType.h (94835 => 94836)


--- trunk/Source/WebCore/html/TextFieldInputType.h	2011-09-09 06:07:22 UTC (rev 94835)
+++ trunk/Source/WebCore/html/TextFieldInputType.h	2011-09-09 06:16:49 UTC (rev 94836)
@@ -71,7 +71,8 @@
     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;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to