Title: [135675] trunk/Source/WebCore
Revision
135675
Author
[email protected]
Date
2012-11-25 16:38:30 -0800 (Sun, 25 Nov 2012)

Log Message

Refactoring: Move the content of HTMLInputElement::subtreeHasChanged to TextFieldInputType
https://bugs.webkit.org/show_bug.cgi?id=103195

Reviewed by Kentaro Hara.

HTMLInputElement::subtreeHasChanged is called only if the input is
a text field. The code should be moved to TextFieldInputType.

No new tests. This should not change any behavior.

* html/HTMLInputElement.cpp:
- Remove unnecessary NumberInputType.h inclusion.
- Remove convertFromVisibleValue. It was used only by subtreeHasChanged.
(WebCore::HTMLInputElement::subtreeHasChanged):
Move the code to TextFieldInputType::subtreeHasChanged except
calculateAndAdjustDirectionality, which is a protected member of
HTMLElement.
* html/HTMLInputElement.h:
(HTMLInputElement): Remove convertFromVisibleValue.

* html/InputType.cpp:
Move convertFromVisibleValue to TextFieldInputType.
(WebCore::InputType::subtreeHasChanged):
Add ASSERT_NOT_REACHED.
* html/InputType.h:
(InputType): Remove convertFromVisibleValue.

* html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::convertFromVisibleValue):
Moved from InputType.
(WebCore::TextFieldInputType::subtreeHasChanged):
Moved from HTMLInputElement. A latter part is moved to
didSetValueByUserEdit to be hooked by SearchInputType.
(WebCore::TextFieldInputType::didSetValueByUserEdit):
Moved from HTMLInputElement::subtreeHasChanged, and clean up the code.
* html/TextFieldInputType.h:
(TextFieldInputType):
- Move convertFromVisibleValue from InputType.
- Add didSetValueByUserEdit and subtreeHasChanged.

* html/SearchInputType.cpp:
(WebCore::SearchInputType::didSetValueByUserEdit):
Renamed from subtreeHasChanged, and calls TextFieldInputType::didSetValueByUserEdit.
* html/SearchInputType.h:
(SearchInputType): Rename subtreeHasChanged to didSetValueByUserEdit.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (135674 => 135675)


--- trunk/Source/WebCore/ChangeLog	2012-11-26 00:21:24 UTC (rev 135674)
+++ trunk/Source/WebCore/ChangeLog	2012-11-26 00:38:30 UTC (rev 135675)
@@ -1,3 +1,51 @@
+2012-11-25  Kent Tamura  <[email protected]>
+
+        Refactoring: Move the content of HTMLInputElement::subtreeHasChanged to TextFieldInputType
+        https://bugs.webkit.org/show_bug.cgi?id=103195
+
+        Reviewed by Kentaro Hara.
+
+        HTMLInputElement::subtreeHasChanged is called only if the input is
+        a text field. The code should be moved to TextFieldInputType.
+
+        No new tests. This should not change any behavior.
+
+        * html/HTMLInputElement.cpp:
+        - Remove unnecessary NumberInputType.h inclusion.
+        - Remove convertFromVisibleValue. It was used only by subtreeHasChanged.
+        (WebCore::HTMLInputElement::subtreeHasChanged):
+        Move the code to TextFieldInputType::subtreeHasChanged except
+        calculateAndAdjustDirectionality, which is a protected member of
+        HTMLElement.
+        * html/HTMLInputElement.h:
+        (HTMLInputElement): Remove convertFromVisibleValue.
+
+        * html/InputType.cpp:
+        Move convertFromVisibleValue to TextFieldInputType.
+        (WebCore::InputType::subtreeHasChanged):
+        Add ASSERT_NOT_REACHED.
+        * html/InputType.h:
+        (InputType): Remove convertFromVisibleValue.
+
+        * html/TextFieldInputType.cpp:
+        (WebCore::TextFieldInputType::convertFromVisibleValue):
+        Moved from InputType.
+        (WebCore::TextFieldInputType::subtreeHasChanged):
+        Moved from HTMLInputElement. A latter part is moved to
+        didSetValueByUserEdit to be hooked by SearchInputType.
+        (WebCore::TextFieldInputType::didSetValueByUserEdit):
+        Moved from HTMLInputElement::subtreeHasChanged, and clean up the code.
+        * html/TextFieldInputType.h:
+        (TextFieldInputType):
+        - Move convertFromVisibleValue from InputType.
+        - Add didSetValueByUserEdit and subtreeHasChanged.
+
+        * html/SearchInputType.cpp:
+        (WebCore::SearchInputType::didSetValueByUserEdit):
+        Renamed from subtreeHasChanged, and calls TextFieldInputType::didSetValueByUserEdit.
+        * html/SearchInputType.h:
+        (SearchInputType): Rename subtreeHasChanged to didSetValueByUserEdit.
+
 2012-11-22  Kentaro Hara  <[email protected]>
 
         [V8] Move WorkerExecutionContextProxy::initializeIfNeeded() to V8Initializer

Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (135674 => 135675)


--- trunk/Source/WebCore/html/HTMLInputElement.cpp	2012-11-26 00:21:24 UTC (rev 135674)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp	2012-11-26 00:38:30 UTC (rev 135675)
@@ -56,7 +56,6 @@
 #include "Language.h"
 #include "LocalizedStrings.h"
 #include "MouseEvent.h"
-#include "NumberInputType.h"
 #include "RenderTextControlSingleLine.h"
 #include "RenderTheme.h"
 #include "RuntimeEnabledFeatures.h"
@@ -545,35 +544,9 @@
 
 void HTMLInputElement::subtreeHasChanged()
 {
-    ASSERT(isTextField());
-    ASSERT(renderer());
-
-    bool wasChanged = wasChangedSinceLastFormControlChangeEvent();
-    setChangedSinceLastFormControlChangeEvent(true);
-
-    // We don't need to call sanitizeUserInputValue() function here because
-    // HTMLInputElement::handleBeforeTextInsertedEvent() has already called
-    // sanitizeUserInputValue().
-    // sanitizeValue() is needed because IME input doesn't dispatch BeforeTextInsertedEvent.
-    setValueFromRenderer(sanitizeValue(convertFromVisibleValue(innerTextValue())));
-    updatePlaceholderVisibility(false);
-    // Recalc for :invalid and hasUnacceptableValue() change.
-    setNeedsStyleRecalc();
-
     m_inputType->subtreeHasChanged();
-
-    if (!wasChanged && focused()) {
-        if (Frame* frame = document()->frame())
-            frame->editor()->textFieldDidBeginEditing(this);
-    }
-
-    if (focused()) {
-        if (Frame* frame = document()->frame())
-            frame->editor()->textDidChangeInTextField(this);
-    }
     // When typing in an input field, childrenChanged is not called, so we need to force the directionality check.
-    if (isTextField())
-        calculateAndAdjustDirectionality();
+    calculateAndAdjustDirectionality();
 }
 
 const AtomicString& HTMLInputElement::formControlType() const
@@ -1404,11 +1377,6 @@
     return m_inputType->visibleValue();
 }
 
-String HTMLInputElement::convertFromVisibleValue(const String& visibleValue) const
-{
-    return m_inputType->convertFromVisibleValue(visibleValue);
-}
-
 String HTMLInputElement::sanitizeValue(const String& proposedValue) const
 {
     if (proposedValue.isNull())

Modified: trunk/Source/WebCore/html/HTMLInputElement.h (135674 => 135675)


--- trunk/Source/WebCore/html/HTMLInputElement.h	2012-11-26 00:21:24 UTC (rev 135674)
+++ trunk/Source/WebCore/html/HTMLInputElement.h	2012-11-26 00:38:30 UTC (rev 135675)
@@ -163,7 +163,6 @@
 
     // The value which is drawn by a renderer.
     String visibleValue() const;
-    String convertFromVisibleValue(const String&) const;
 
     const String& suggestedValue() const;
     void setSuggestedValue(const String&);

Modified: trunk/Source/WebCore/html/InputType.cpp (135674 => 135675)


--- trunk/Source/WebCore/html/InputType.cpp	2012-11-26 00:21:24 UTC (rev 135674)
+++ trunk/Source/WebCore/html/InputType.cpp	2012-11-26 00:38:30 UTC (rev 135675)
@@ -684,11 +684,6 @@
     return element()->value();
 }
 
-String InputType::convertFromVisibleValue(const String& visibleValue) const
-{
-    return visibleValue;
-}
-
 String InputType::sanitizeValue(const String& proposedValue) const
 {
     return proposedValue;
@@ -888,6 +883,7 @@
 
 void InputType::subtreeHasChanged()
 {
+    ASSERT_NOT_REACHED();
 }
 
 #if ENABLE(TOUCH_EVENTS)

Modified: trunk/Source/WebCore/html/InputType.h (135674 => 135675)


--- trunk/Source/WebCore/html/InputType.h	2012-11-26 00:21:24 UTC (rev 135674)
+++ trunk/Source/WebCore/html/InputType.h	2012-11-26 00:38:30 UTC (rev 135675)
@@ -175,7 +175,6 @@
     virtual bool canSetStringValue() const;
     virtual String localizeValue(const String&) const;
     virtual String visibleValue() const;
-    virtual String convertFromVisibleValue(const String&) const;
     // Returing the null string means "use the default value."
     // This function must be called only by HTMLInputElement::sanitizeValue().
     virtual String sanitizeValue(const String&) const;

Modified: trunk/Source/WebCore/html/SearchInputType.cpp (135674 => 135675)


--- trunk/Source/WebCore/html/SearchInputType.cpp	2012-11-26 00:21:24 UTC (rev 135674)
+++ trunk/Source/WebCore/html/SearchInputType.cpp	2012-11-26 00:38:30 UTC (rev 135675)
@@ -175,7 +175,7 @@
     return element()->hasAttribute(incrementalAttr);
 }
 
-void SearchInputType::subtreeHasChanged()
+void SearchInputType::didSetValueByUserEdit(ValueChangeState state)
 {
     if (m_cancelButton)
         toRenderSearchField(element()->renderer())->updateCancelButtonVisibility();
@@ -183,6 +183,8 @@
     // If the incremental attribute is set, then dispatch the search event
     if (searchEventsShouldBeDispatched())
         startSearchEventTimer();
+
+    TextFieldInputType::didSetValueByUserEdit(state);
 }
 
 } // namespace WebCore

Modified: trunk/Source/WebCore/html/SearchInputType.h (135674 => 135675)


--- trunk/Source/WebCore/html/SearchInputType.h	2012-11-26 00:21:24 UTC (rev 135674)
+++ trunk/Source/WebCore/html/SearchInputType.h	2012-11-26 00:38:30 UTC (rev 135675)
@@ -58,7 +58,7 @@
     virtual HTMLElement* resultsButtonElement() const OVERRIDE;
     virtual HTMLElement* cancelButtonElement() const OVERRIDE;
     virtual void handleKeydownEvent(KeyboardEvent*) OVERRIDE;
-    virtual void subtreeHasChanged();
+    virtual void didSetValueByUserEdit(ValueChangeState) OVERRIDE;
 
     void searchEventTimerFired(Timer<SearchInputType>*);
     bool searchEventsShouldBeDispatched() const;

Modified: trunk/Source/WebCore/html/TextFieldInputType.cpp (135674 => 135675)


--- trunk/Source/WebCore/html/TextFieldInputType.cpp	2012-11-26 00:21:24 UTC (rev 135674)
+++ trunk/Source/WebCore/html/TextFieldInputType.cpp	2012-11-26 00:38:30 UTC (rev 135675)
@@ -440,6 +440,41 @@
     return true;
 }
 
+String TextFieldInputType::convertFromVisibleValue(const String& visibleValue) const
+{
+    return visibleValue;
+}
+
+void TextFieldInputType::subtreeHasChanged()
+{
+    ASSERT(element()->renderer());
+
+    bool wasChanged = element()->wasChangedSinceLastFormControlChangeEvent();
+    element()->setChangedSinceLastFormControlChangeEvent(true);
+
+    // We don't need to call sanitizeUserInputValue() function here because
+    // HTMLInputElement::handleBeforeTextInsertedEvent() has already called
+    // sanitizeUserInputValue().
+    // sanitizeValue() is needed because IME input doesn't dispatch BeforeTextInsertedEvent.
+    element()->setValueFromRenderer(sanitizeValue(convertFromVisibleValue(element()->innerTextValue())));
+    element()->updatePlaceholderVisibility(false);
+    // Recalc for :invalid and hasUnacceptableValue() change.
+    element()->setNeedsStyleRecalc();
+
+    didSetValueByUserEdit(wasChanged ? ValueChangeStateChanged : ValueChangeStateNone);
+}
+
+void TextFieldInputType::didSetValueByUserEdit(ValueChangeState state)
+{
+    if (!element()->focused())
+        return;
+    if (Frame* frame = element()->document()->frame()) {
+        if (state == ValueChangeStateNone)
+            frame->editor()->textFieldDidBeginEditing(element());
+        frame->editor()->textDidChangeInTextField(element());
+    }
+}
+
 void TextFieldInputType::spinButtonStepDown()
 {
     stepUpFromRenderer(-1);

Modified: trunk/Source/WebCore/html/TextFieldInputType.h (135674 => 135675)


--- trunk/Source/WebCore/html/TextFieldInputType.h	2012-11-26 00:21:24 UTC (rev 135674)
+++ trunk/Source/WebCore/html/TextFieldInputType.h	2012-11-26 00:38:30 UTC (rev 135675)
@@ -68,6 +68,13 @@
     virtual void setValue(const String&, bool valueChanged, TextFieldEventBehavior) OVERRIDE;
     virtual void updateInnerTextValue() OVERRIDE;
 
+    virtual String convertFromVisibleValue(const String&) const;
+    enum ValueChangeState {
+        ValueChangeStateNone,
+        ValueChangeStateChanged
+    };
+    virtual void didSetValueByUserEdit(ValueChangeState);
+
 private:
     virtual bool isKeyboardFocusable(KeyboardEvent*) const OVERRIDE;
     virtual bool isMouseFocusable() const OVERRIDE;
@@ -84,6 +91,7 @@
     virtual void updatePlaceholderText() OVERRIDE;
     virtual bool appendFormData(FormDataList&, bool multipart) const OVERRIDE;
     virtual void attach() OVERRIDE;
+    virtual void subtreeHasChanged() OVERRIDE;
 
     // SpinButtonElement::SpinButtonOwner functions.
     virtual void focusAndSelectSpinButtonOwner() OVERRIDE;
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to