[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

tkent at chromium.org tkent at chromium.org
Wed Dec 22 15:53:24 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit 3b9277b482efd27a373ffb1f251e8cf66ed85d42
Author: tkent at chromium.org <tkent at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Nov 16 05:13:20 2010 +0000

    Refactor HTMLInputElement: Move a part of HTMLInputElement::
    defaultEventHandler() to InputTypes.
    https://bugs.webkit.org/show_bug.cgi?id=48317
    
    Reviewed by Darin Adler.
    
    Move out the followings to InputTypes:
     - click event processing,
     - the first keydown event processing, and
     - DOMActivate event processing.
    
    Move m_xPos and m_yPos from HTMLInputElement to ImageInputType as
    m_clickLocation. It's ok to move them because they should be valid only
    when HTMLInputElement::m_activeSubmit is true. For type=image,
    m_activeSubmit is true only in DOMActivate event handling. So we reset
    m_clickLocation in handleDOMActivateEvent() with Event::underlyingEvent().
    
    No new tests because this is just a refactoring.
    
    * html/BaseDateAndTimeInputType.cpp:
    (WebCore::BaseDateAndTimeInputType::handleKeydownEvent):
    * html/BaseDateAndTimeInputType.h:
    * html/FileInputType.cpp:
    (WebCore::FileInputType::handleDOMActivateEvent):
    * html/FileInputType.h:
    * html/HTMLInputElement.cpp:
    (WebCore::HTMLInputElement::HTMLInputElement):
    (WebCore::HTMLInputElement::defaultEventHandler):
    * html/HTMLInputElement.h:
    * html/ImageInputType.cpp:
    (WebCore::ImageInputType::appendFormData):
    (WebCore::ImageInputType::handleDOMActivateEvent):
    * html/ImageInputType.h:
    * html/InputType.cpp:
    (WebCore::InputType::handleClickEvent):
    (WebCore::InputType::handleDOMActivateEvent):
    (WebCore::InputType::handleKeydownEvent):
    * html/InputType.h:
    * html/NumberInputType.cpp:
    (WebCore::NumberInputType::handleKeydownEvent):
    * html/NumberInputType.h:
    * html/RadioInputType.cpp:
    (WebCore::RadioInputType::handleClickEvent):
    * html/RadioInputType.h:
    * html/RangeInputType.cpp:
    (WebCore::RangeInputType::handleKeydownEvent):
    * html/RangeInputType.h:
    * html/ResetInputType.cpp:
    (WebCore::ResetInputType::handleDOMActivateEvent):
    * html/ResetInputType.h:
    * html/SubmitInputType.cpp:
    (WebCore::SubmitInputType::handleDOMActivateEvent):
    * html/SubmitInputType.h:
    * html/TextFieldInputType.cpp:
    (WebCore::TextFieldInputType::handleKeydownEvent):
    (WebCore::TextFieldInputType::handleKeydownEventForSpinButton):
    * html/TextFieldInputType.h:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@72059 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 8eca34a..2dead1d 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,63 @@
+2010-11-15  Kent Tamura  <tkent at chromium.org>
+
+        Reviewed by Darin Adler.
+
+        Refactor HTMLInputElement: Move a part of HTMLInputElement::
+        defaultEventHandler() to InputTypes.
+        https://bugs.webkit.org/show_bug.cgi?id=48317
+
+        Move out the followings to InputTypes:
+         - click event processing,
+         - the first keydown event processing, and
+         - DOMActivate event processing.
+
+        Move m_xPos and m_yPos from HTMLInputElement to ImageInputType as
+        m_clickLocation. It's ok to move them because they should be valid only
+        when HTMLInputElement::m_activeSubmit is true. For type=image,
+        m_activeSubmit is true only in DOMActivate event handling. So we reset
+        m_clickLocation in handleDOMActivateEvent() with Event::underlyingEvent().
+
+        No new tests because this is just a refactoring.
+
+        * html/BaseDateAndTimeInputType.cpp:
+        (WebCore::BaseDateAndTimeInputType::handleKeydownEvent):
+        * html/BaseDateAndTimeInputType.h:
+        * html/FileInputType.cpp:
+        (WebCore::FileInputType::handleDOMActivateEvent):
+        * html/FileInputType.h:
+        * html/HTMLInputElement.cpp:
+        (WebCore::HTMLInputElement::HTMLInputElement):
+        (WebCore::HTMLInputElement::defaultEventHandler):
+        * html/HTMLInputElement.h:
+        * html/ImageInputType.cpp:
+        (WebCore::ImageInputType::appendFormData):
+        (WebCore::ImageInputType::handleDOMActivateEvent):
+        * html/ImageInputType.h:
+        * html/InputType.cpp:
+        (WebCore::InputType::handleClickEvent):
+        (WebCore::InputType::handleDOMActivateEvent):
+        (WebCore::InputType::handleKeydownEvent):
+        * html/InputType.h:
+        * html/NumberInputType.cpp:
+        (WebCore::NumberInputType::handleKeydownEvent):
+        * html/NumberInputType.h:
+        * html/RadioInputType.cpp:
+        (WebCore::RadioInputType::handleClickEvent):
+        * html/RadioInputType.h:
+        * html/RangeInputType.cpp:
+        (WebCore::RangeInputType::handleKeydownEvent):
+        * html/RangeInputType.h:
+        * html/ResetInputType.cpp:
+        (WebCore::ResetInputType::handleDOMActivateEvent):
+        * html/ResetInputType.h:
+        * html/SubmitInputType.cpp:
+        (WebCore::SubmitInputType::handleDOMActivateEvent):
+        * html/SubmitInputType.h:
+        * html/TextFieldInputType.cpp:
+        (WebCore::TextFieldInputType::handleKeydownEvent):
+        (WebCore::TextFieldInputType::handleKeydownEventForSpinButton):
+        * html/TextFieldInputType.h:
+
 2010-11-15  Chris Rogers  <crogers at google.com>
 
         Reviewed by Kenneth Russell.
diff --git a/WebCore/html/BaseDateAndTimeInputType.cpp b/WebCore/html/BaseDateAndTimeInputType.cpp
index e1126d4..e780ed6 100644
--- a/WebCore/html/BaseDateAndTimeInputType.cpp
+++ b/WebCore/html/BaseDateAndTimeInputType.cpp
@@ -108,6 +108,11 @@ double BaseDateAndTimeInputType::stepBase() const
     return parseToDouble(element()->fastGetAttribute(minAttr), defaultStepBase());
 }
 
+bool BaseDateAndTimeInputType::handleKeydownEvent(KeyboardEvent* event)
+{
+    return handleKeydownEventForSpinButton(event) || TextFieldInputType::handleKeydownEvent(event);
+}
+
 double BaseDateAndTimeInputType::parseToDouble(const String& src, double defaultValue) const
 {
     DateComponents date;
diff --git a/WebCore/html/BaseDateAndTimeInputType.h b/WebCore/html/BaseDateAndTimeInputType.h
index 83c1e93..11c60af 100644
--- a/WebCore/html/BaseDateAndTimeInputType.h
+++ b/WebCore/html/BaseDateAndTimeInputType.h
@@ -57,6 +57,7 @@ private:
     virtual bool rangeOverflow(const String&) const;
     virtual bool stepMismatch(const String&, double) const;
     virtual double stepBase() const;
+    virtual bool handleKeydownEvent(KeyboardEvent*);
     virtual String serialize(double) const;
 };
 
diff --git a/WebCore/html/FileInputType.cpp b/WebCore/html/FileInputType.cpp
index d98d3b6..e9d0b5e 100644
--- a/WebCore/html/FileInputType.cpp
+++ b/WebCore/html/FileInputType.cpp
@@ -22,6 +22,7 @@
 #include "config.h"
 #include "FileInputType.h"
 
+#include "Event.h"
 #include "File.h"
 #include "FileList.h"
 #include "FormDataList.h"
@@ -76,6 +77,15 @@ bool FileInputType::valueMissing(const String& value) const
     return value.isEmpty();
 }
 
+bool FileInputType::handleDOMActivateEvent(Event* event)
+{
+    if (element()->disabled() || !element()->renderer())
+        return false;
+    toRenderFileUploadControl(element()->renderer())->click();
+    event->setDefaultHandled();
+    return true;
+}
+
 RenderObject* FileInputType::createRenderer(RenderArena* arena, RenderStyle*) const
 {
     return new (arena) RenderFileUploadControl(element());
diff --git a/WebCore/html/FileInputType.h b/WebCore/html/FileInputType.h
index 24430fb..142afaf 100644
--- a/WebCore/html/FileInputType.h
+++ b/WebCore/html/FileInputType.h
@@ -44,6 +44,7 @@ private:
     virtual const AtomicString& formControlType() const;
     virtual bool appendFormData(FormDataList&, bool) const;
     virtual bool valueMissing(const String&) const;
+    virtual bool handleDOMActivateEvent(Event*);
     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) const;
 };
 
diff --git a/WebCore/html/HTMLInputElement.cpp b/WebCore/html/HTMLInputElement.cpp
index e79069d..af4e7d0 100644
--- a/WebCore/html/HTMLInputElement.cpp
+++ b/WebCore/html/HTMLInputElement.cpp
@@ -88,8 +88,6 @@ static bool isNumberCharacter(UChar ch)
 
 HTMLInputElement::HTMLInputElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form)
     : HTMLTextFormControlElement(tagName, document, form)
-    , m_xPos(0)
-    , m_yPos(0)
     , m_maxResults(-1)
     , m_deprecatedTypeNumber(TEXT)
     , m_checked(false)
@@ -1289,57 +1287,12 @@ void HTMLInputElement::defaultEventHandler(Event* evt)
     if (isTextField() && evt->type() == eventNames().textInputEvent && evt->isTextEvent() && static_cast<TextEvent*>(evt)->data() == "\n")
         implicitSubmission = true;
 
-    if (deprecatedInputType() == IMAGE && evt->isMouseEvent() && evt->type() == eventNames().clickEvent) {
-        // record the mouse position for when we get the DOMActivate event
-        MouseEvent* me = static_cast<MouseEvent*>(evt);
-        // FIXME: We could just call offsetX() and offsetY() on the event,
-        // but that's currently broken, so for now do the computation here.
-        if (me->isSimulated() || !renderer()) {
-            m_xPos = 0;
-            m_yPos = 0;
-        } else {
-            // FIXME: This doesn't work correctly with transforms.
-            // FIXME: pageX/pageY need adjusting for pageZoomFactor(). Use actualPageLocation()?
-            IntPoint absOffset = roundedIntPoint(renderer()->localToAbsolute());
-            m_xPos = me->pageX() - absOffset.x();
-            m_yPos = me->pageY() - absOffset.y();
-        }
-    }
-
-    if (hasSpinButton() && evt->type() == eventNames().keydownEvent && evt->isKeyboardEvent()) {
-        const String& key = static_cast<KeyboardEvent*>(evt)->keyIdentifier();
-        int step = 0;
-        if (key == "Up")
-            step = 1;
-        else if (key == "Down")
-            step = -1;
-        if (step) {
-            stepUpFromRenderer(step);
-            evt->setDefaultHandled();
-            return;
-        }
-    }
-    if (deprecatedInputType() == RANGE && evt->isKeyboardEvent()) {
-        handleKeyEventForRange(static_cast<KeyboardEvent*>(evt));
-        if (evt->defaultHandled())
-            return;
-    }
- 
-   if (isTextField()
-            && evt->type() == eventNames().keydownEvent
-            && evt->isKeyboardEvent()
-            && focused()
-            && document()->frame()
-            && document()->frame()->editor()->doTextFieldCommandFromEvent(this, static_cast<KeyboardEvent*>(evt))) {
-        evt->setDefaultHandled();
+    if (evt->isMouseEvent() && evt->type() == eventNames().clickEvent && m_inputType->handleClickEvent(static_cast<MouseEvent*>(evt)))
         return;
-    }
 
-    if (deprecatedInputType() == RADIO && evt->type() == eventNames().clickEvent) {
-        evt->setDefaultHandled();
+    if (evt->isKeyboardEvent() && evt->type() == eventNames().keydownEvent && m_inputType->handleKeydownEvent(static_cast<KeyboardEvent*>(evt)))
         return;
-    }
-    
+
     // Call the base event handler before any of our own event handling for almost all events in text fields.
     // Makes editing keyboard handling take precedence over the keydown and keypress handling in this function.
     bool callBaseClassEarly = isTextField() && !implicitSubmission
@@ -1354,27 +1307,8 @@ void HTMLInputElement::defaultEventHandler(Event* evt)
     // actually submitting the form. For reset inputs, the form is reset. These events are sent when the user clicks
     // on the element, or presses enter while it is the active element. JavaScript code wishing to activate the element
     // must dispatch a DOMActivate event - a click event will not do the job.
-    if (evt->type() == eventNames().DOMActivateEvent && !disabled()) {
-        if (deprecatedInputType() == IMAGE || deprecatedInputType() == SUBMIT || deprecatedInputType() == RESET) {
-            if (!form())
-                return;
-            if (deprecatedInputType() == RESET)
-                form()->reset();
-            else {
-                m_activeSubmit = true;
-                // FIXME: Would be cleaner to get m_xPos and m_yPos out of the underlying mouse
-                // event (if any) here instead of relying on the variables set above when
-                // processing the click event. Even better, appendFormData could pass the
-                // event in, and then we could get rid of m_xPos and m_yPos altogether!
-                if (!form()->prepareSubmit(evt)) {
-                    m_xPos = 0;
-                    m_yPos = 0;
-                }
-                m_activeSubmit = false;
-            }
-        } else if (deprecatedInputType() == FILE && renderer())
-            toRenderFileUploadControl(renderer())->click();
-    }
+    if (evt->type() == eventNames().DOMActivateEvent && m_inputType->handleDOMActivateEvent(evt))
+        return;
 
     // Use key press event here since sending simulated mouse events
     // on key down blocks the proper sending of the key press event.
@@ -1633,47 +1567,6 @@ void HTMLInputElement::handleBeforeTextInsertedEvent(Event* event)
     InputElement::handleBeforeTextInsertedEvent(m_data, this, this, event);
 }
 
-void HTMLInputElement::handleKeyEventForRange(KeyboardEvent* event)
-{
-    if (event->type() != eventNames().keydownEvent)
-        return;
-    const String& key = event->keyIdentifier();
-    if (key != "Up" && key != "Right" && key != "Down" && key != "Left")
-        return;
-
-    ExceptionCode ec;
-    if (equalIgnoringCase(getAttribute(stepAttr), "any")) {
-        double min = m_inputType->minimum();
-        double max = m_inputType->maximum();
-        // FIXME: Is 1/100 reasonable?
-        double step = (max - min) / 100;
-        double current = m_inputType->parseToDouble(value(), numeric_limits<double>::quiet_NaN());
-        ASSERT(isfinite(current));
-        double newValue;
-        if (key == "Up" || key == "Right") {
-            newValue = current + step;
-            if (newValue > max)
-                newValue = max;
-        } else {
-            newValue = current - step;
-            if (newValue < min)
-                newValue = min;
-        }
-        if (newValue != current) {
-            setValueAsNumber(newValue, ec);
-            dispatchFormControlChangeEvent();
-        }
-    } else {
-        int stepMagnification = (key == "Up" || key == "Right") ? 1 : -1;
-        String lastStringValue = value();
-        stepUp(stepMagnification, ec);
-        if (lastStringValue != value())
-            dispatchFormControlChangeEvent();
-    }
-    event->setDefaultHandled();
-    return;
-}
-
 PassRefPtr<HTMLFormElement> HTMLInputElement::createTemporaryFormForIsIndex()
 {
     RefPtr<HTMLFormElement> form = HTMLFormElement::create(document());
diff --git a/WebCore/html/HTMLInputElement.h b/WebCore/html/HTMLInputElement.h
index e9907d2..9884117 100644
--- a/WebCore/html/HTMLInputElement.h
+++ b/WebCore/html/HTMLInputElement.h
@@ -209,10 +209,6 @@ public:
         return document()->checkedRadioButtons();
     }
 
-    // FIXME: We should move m_xPos and m_yPos to ImageInputType class.
-    int xPosition() const { return m_xPos; }
-    int yPosition() const { return m_yPos; }
-
 protected:
     HTMLInputElement(const QualifiedName&, Document*, HTMLFormElement* = 0);
 
@@ -342,7 +338,6 @@ private:
     void updateCheckedRadioButtons();
     
     void handleBeforeTextInsertedEvent(Event*);
-    void handleKeyEventForRange(KeyboardEvent*);
     PassRefPtr<HTMLFormElement> createTemporaryFormForIsIndex();
     // Helper for stepUp()/stepDown().  Adds step value * count to the current value.
     void applyStep(double count, ExceptionCode&);
@@ -356,8 +351,6 @@ private:
 #endif
 
     InputElementData m_data;
-    int m_xPos;
-    int m_yPos;
     short m_maxResults;
     OwnPtr<HTMLImageLoader> m_imageLoader;
     RefPtr<FileList> m_fileList;
diff --git a/WebCore/html/ImageInputType.cpp b/WebCore/html/ImageInputType.cpp
index de24188..7a76174 100644
--- a/WebCore/html/ImageInputType.cpp
+++ b/WebCore/html/ImageInputType.cpp
@@ -24,6 +24,7 @@
 
 #include "FormDataList.h"
 #include "HTMLInputElement.h"
+#include "MouseEvent.h"
 #include "RenderImage.h"
 #include <wtf/PassOwnPtr.h>
 
@@ -49,8 +50,8 @@ bool ImageInputType::appendFormData(FormDataList& encoding, bool) const
     if (!element()->isActivatedSubmit())
         return false;
     const AtomicString& name = element()->name();
-    encoding.appendData(name.isEmpty() ? "x" : (name + ".x"), element()->xPosition());
-    encoding.appendData(name.isEmpty() ? "y" : (name + ".y"), element()->yPosition());
+    encoding.appendData(name.isEmpty() ? "x" : (name + ".x"), m_clickLocation.x());
+    encoding.appendData(name.isEmpty() ? "y" : (name + ".y"), m_clickLocation.y());
     if (!name.isEmpty() && !element()->value().isEmpty())
         encoding.appendData(name, element()->value());
     return true;
@@ -61,6 +62,23 @@ bool ImageInputType::supportsValidation() const
     return false;
 }
 
+bool ImageInputType::handleDOMActivateEvent(Event* event)
+{
+    RefPtr<HTMLInputElement> element = this->element();
+    if (element->disabled() || !element->form())
+        return false;
+    element->setActivatedSubmit(true);
+    if (event->underlyingEvent() && event->underlyingEvent()->isMouseEvent()) {
+        MouseEvent* mouseEvent = static_cast<MouseEvent*>(event->underlyingEvent());
+        m_clickLocation = IntPoint(mouseEvent->offsetX(), mouseEvent->offsetY());
+    } else
+        m_clickLocation = IntPoint();
+    element->form()->prepareSubmit(event); // Event handlers can run.
+    element->setActivatedSubmit(false);
+    event->setDefaultHandled();
+    return true;
+}
+
 RenderObject* ImageInputType::createRenderer(RenderArena* arena, RenderStyle*) const
 {
     RenderImage* image = new (arena) RenderImage(element());
diff --git a/WebCore/html/ImageInputType.h b/WebCore/html/ImageInputType.h
index cd76e72..61abf9d 100644
--- a/WebCore/html/ImageInputType.h
+++ b/WebCore/html/ImageInputType.h
@@ -32,6 +32,7 @@
 #define ImageInputType_h
 
 #include "BaseButtonInputType.h"
+#include "IntPoint.h"
 
 namespace WebCore {
 
@@ -46,6 +47,10 @@ private:
     virtual bool appendFormData(FormDataList&, bool) const;
     virtual bool supportsValidation() const;
     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) const;
+    virtual bool handleDOMActivateEvent(Event*);
+
+    // This is valid only during HTMLFormElement::prepareSubmit().
+    IntPoint m_clickLocation;
 };
 
 } // namespace WebCore
diff --git a/WebCore/html/InputType.cpp b/WebCore/html/InputType.cpp
index a0ea110..6dd002c 100644
--- a/WebCore/html/InputType.cpp
+++ b/WebCore/html/InputType.cpp
@@ -275,6 +275,21 @@ String InputType::typeMismatchText() const
     return validationMessageTypeMismatchText();
 }
 
+bool InputType::handleClickEvent(MouseEvent*)
+{
+    return false;
+}
+
+bool InputType::handleDOMActivateEvent(Event*)
+{
+    return false;
+}
+
+bool InputType::handleKeydownEvent(KeyboardEvent*)
+{
+    return false;
+}
+
 RenderObject* InputType::createRenderer(RenderArena*, RenderStyle* style) const
 {
     return RenderObject::createObject(element(), style);
diff --git a/WebCore/html/InputType.h b/WebCore/html/InputType.h
index dfa4fb0..f1a5b6d 100644
--- a/WebCore/html/InputType.h
+++ b/WebCore/html/InputType.h
@@ -38,8 +38,11 @@
 namespace WebCore {
 
 class DateComponents;
+class Event;
 class FormDataList;
 class HTMLInputElement;
+class KeyboardEvent;
+class MouseEvent;
 class RenderArena;
 class RenderObject;
 class RenderStyle;
@@ -98,6 +101,15 @@ public:
     virtual double acceptableError(double) const;
     virtual String typeMismatchText() const;
 
+    // Event handlers
+    // If the return value is true, do no further default event handling in the
+    // default event handler. If an event handler calls Event::setDefaultHandled(),
+    // its return value must be true.
+
+    virtual bool handleClickEvent(MouseEvent*);
+    virtual bool handleDOMActivateEvent(Event*);
+    virtual bool handleKeydownEvent(KeyboardEvent*);
+
     // Miscellaneous functions
 
     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) const;
diff --git a/WebCore/html/NumberInputType.cpp b/WebCore/html/NumberInputType.cpp
index 7a4d504..e290e50 100644
--- a/WebCore/html/NumberInputType.cpp
+++ b/WebCore/html/NumberInputType.cpp
@@ -155,6 +155,11 @@ double NumberInputType::stepScaleFactor() const
     return numberStepScaleFactor;
 }
 
+bool NumberInputType::handleKeydownEvent(KeyboardEvent* event)
+{
+    return handleKeydownEventForSpinButton(event) || TextFieldInputType::handleKeydownEventForSpinButton(event);
+}
+
 double NumberInputType::parseToDouble(const String& src, double defaultValue) const
 {
     double numberValue;
diff --git a/WebCore/html/NumberInputType.h b/WebCore/html/NumberInputType.h
index 1f0b881..dc6e020 100644
--- a/WebCore/html/NumberInputType.h
+++ b/WebCore/html/NumberInputType.h
@@ -55,6 +55,7 @@ private:
     virtual double stepBaseWithDecimalPlaces(unsigned*) const;
     virtual double defaultStep() const;
     virtual double stepScaleFactor() const;
+    virtual bool handleKeydownEvent(KeyboardEvent*);
     virtual double parseToDouble(const String&, double) const;
     virtual double parseToDoubleWithDecimalPlaces(const String&, double, unsigned*) const;
     virtual String serialize(double) const;
diff --git a/WebCore/html/RadioInputType.cpp b/WebCore/html/RadioInputType.cpp
index 5df4bbc..a6c4707 100644
--- a/WebCore/html/RadioInputType.cpp
+++ b/WebCore/html/RadioInputType.cpp
@@ -32,6 +32,7 @@
 #include "RadioInputType.h"
 
 #include "HTMLInputElement.h"
+#include "MouseEvent.h"
 #include <wtf/PassOwnPtr.h>
 
 namespace WebCore {
@@ -51,4 +52,10 @@ bool RadioInputType::valueMissing(const String&) const
     return !element()->checkedRadioButtons().checkedButtonForGroup(element()->name());
 }
 
+bool RadioInputType::handleClickEvent(MouseEvent* event)
+{
+    event->setDefaultHandled();
+    return true;
+}
+
 } // namespace WebCore
diff --git a/WebCore/html/RadioInputType.h b/WebCore/html/RadioInputType.h
index 9e7ab00..2798010 100644
--- a/WebCore/html/RadioInputType.h
+++ b/WebCore/html/RadioInputType.h
@@ -43,6 +43,7 @@ private:
     RadioInputType(HTMLInputElement* element) : BaseCheckableInputType(element) { }
     virtual const AtomicString& formControlType() const;
     virtual bool valueMissing(const String&) const;
+    virtual bool handleClickEvent(MouseEvent*);
 };
 
 } // namespace WebCore
diff --git a/WebCore/html/RangeInputType.cpp b/WebCore/html/RangeInputType.cpp
index 176d73b..ad47f14 100644
--- a/WebCore/html/RangeInputType.cpp
+++ b/WebCore/html/RangeInputType.cpp
@@ -34,6 +34,7 @@
 #include "HTMLInputElement.h"
 #include "HTMLNames.h"
 #include "HTMLParserIdioms.h"
+#include "KeyboardEvent.h"
 #include "RenderSlider.h"
 #include <limits>
 #include <wtf/MathExtras.h>
@@ -127,6 +128,46 @@ double RangeInputType::stepScaleFactor() const
     return rangeStepScaleFactor;
 }
 
+bool RangeInputType::handleKeydownEvent(KeyboardEvent* event)
+{
+    const String& key = event->keyIdentifier();
+    if (key != "Up" && key != "Right" && key != "Down" && key != "Left")
+        return false;
+
+    ExceptionCode ec;
+    if (equalIgnoringCase(element()->fastGetAttribute(stepAttr), "any")) {
+        double min = minimum();
+        double max = maximum();
+        // FIXME: We can't use stepUp() for the step value "any". So, we increase
+        // or decrease the value by 1/100 of the value range. Is it reasonable?
+        double step = (max - min) / 100;
+        double current = parseToDouble(element()->value(), numeric_limits<double>::quiet_NaN());
+        ASSERT(isfinite(current));
+        double newValue;
+        if (key == "Up" || key == "Right") {
+            newValue = current + step;
+            if (newValue > max)
+                newValue = max;
+        } else {
+            newValue = current - step;
+            if (newValue < min)
+                newValue = min;
+        }
+        if (newValue != current) {
+            setValueAsNumber(newValue, ec);
+            element()->dispatchFormControlChangeEvent();
+        }
+    } else {
+        int stepMagnification = (key == "Up" || key == "Right") ? 1 : -1;
+        String lastStringValue = element()->value();
+        element()->stepUp(stepMagnification, ec);
+        if (lastStringValue != element()->value())
+            element()->dispatchFormControlChangeEvent();
+    }
+    event->setDefaultHandled();
+    return true;
+}
+
 RenderObject* RangeInputType::createRenderer(RenderArena* arena, RenderStyle*) const
 {
     return new (arena) RenderSlider(element());
diff --git a/WebCore/html/RangeInputType.h b/WebCore/html/RangeInputType.h
index 64548f6..c2bbb0f 100644
--- a/WebCore/html/RangeInputType.h
+++ b/WebCore/html/RangeInputType.h
@@ -53,6 +53,7 @@ private:
     virtual double stepBase() const;
     virtual double defaultStep() const;
     virtual double stepScaleFactor() const;
+    virtual bool handleKeydownEvent(KeyboardEvent*);
     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) const;
     virtual double parseToDouble(const String&, double) const;
     virtual String serialize(double) const;
diff --git a/WebCore/html/ResetInputType.cpp b/WebCore/html/ResetInputType.cpp
index 1db7592..b911dee 100644
--- a/WebCore/html/ResetInputType.cpp
+++ b/WebCore/html/ResetInputType.cpp
@@ -31,6 +31,8 @@
 #include "config.h"
 #include "ResetInputType.h"
 
+#include "Event.h"
+#include "HTMLInputElement.h"
 #include <wtf/PassOwnPtr.h>
 
 namespace WebCore {
@@ -50,4 +52,13 @@ bool ResetInputType::supportsValidation() const
     return false;
 }
 
+bool ResetInputType::handleDOMActivateEvent(Event* event)
+{
+    if (element()->disabled() || !element()->form())
+        return false;
+    element()->form()->reset();
+    event->setDefaultHandled();
+    return true;
+}
+
 } // namespace WebCore
diff --git a/WebCore/html/ResetInputType.h b/WebCore/html/ResetInputType.h
index ad940b4..153afac 100644
--- a/WebCore/html/ResetInputType.h
+++ b/WebCore/html/ResetInputType.h
@@ -43,6 +43,7 @@ private:
     ResetInputType(HTMLInputElement* element) : BaseButtonInputType(element) { }
     virtual const AtomicString& formControlType() const;
     virtual bool supportsValidation() const;
+    virtual bool handleDOMActivateEvent(Event*);
 };
 
 } // namespace WebCore
diff --git a/WebCore/html/SubmitInputType.cpp b/WebCore/html/SubmitInputType.cpp
index 99c808e..2f7d97e 100644
--- a/WebCore/html/SubmitInputType.cpp
+++ b/WebCore/html/SubmitInputType.cpp
@@ -31,6 +31,7 @@
 #include "config.h"
 #include "SubmitInputType.h"
 
+#include "Event.h"
 #include "FormDataList.h"
 #include "HTMLInputElement.h"
 #include <wtf/PassOwnPtr.h>
@@ -60,4 +61,16 @@ bool SubmitInputType::supportsValidation() const
     return false;
 }
 
+bool SubmitInputType::handleDOMActivateEvent(Event* event)
+{
+    RefPtr<HTMLInputElement> element = this->element();
+    if (element->disabled() || !element->form())
+        return false;
+    element->setActivatedSubmit(true);
+    element->form()->prepareSubmit(event); // Event handlers can run.
+    element->setActivatedSubmit(false);
+    event->setDefaultHandled();
+    return true;
+}
+
 } // namespace WebCore
diff --git a/WebCore/html/SubmitInputType.h b/WebCore/html/SubmitInputType.h
index 2fe7ace..d03219c 100644
--- a/WebCore/html/SubmitInputType.h
+++ b/WebCore/html/SubmitInputType.h
@@ -44,6 +44,7 @@ private:
     virtual const AtomicString& formControlType() const;
     virtual bool appendFormData(FormDataList&, bool) const;
     virtual bool supportsValidation() const;
+    virtual bool handleDOMActivateEvent(Event*);
 };
 
 } // namespace WebCore
diff --git a/WebCore/html/TextFieldInputType.cpp b/WebCore/html/TextFieldInputType.cpp
index 926d0ac..d93f972 100644
--- a/WebCore/html/TextFieldInputType.cpp
+++ b/WebCore/html/TextFieldInputType.cpp
@@ -31,7 +31,9 @@
 #include "config.h"
 #include "TextFieldInputType.h"
 
+#include "Frame.h"
 #include "HTMLInputElement.h"
+#include "KeyboardEvent.h"
 #include "RenderTextControlSingleLine.h"
 #include <wtf/text/WTFString.h>
 
@@ -47,6 +49,32 @@ bool TextFieldInputType::valueMissing(const String& value) const
     return value.isEmpty();
 }
 
+bool TextFieldInputType::handleKeydownEvent(KeyboardEvent* event)
+{
+    if (!element()->focused())
+        return false;
+    Frame* frame = element()->document()->frame();
+    if (!frame || !frame->editor()->doTextFieldCommandFromEvent(element(), event))
+        return false;
+    event->setDefaultHandled();
+    return true;
+}
+
+bool TextFieldInputType::handleKeydownEventForSpinButton(KeyboardEvent* event)
+{
+    const String& key = event->keyIdentifier();
+    int step = 0;
+    if (key == "Up")
+        step = 1;
+    else if (key == "Down")
+        step = -1;
+    else
+        return false;
+    element()->stepUpFromRenderer(step);
+    event->setDefaultHandled();
+    return true;
+}
+
 RenderObject* TextFieldInputType::createRenderer(RenderArena* arena, RenderStyle*) const
 {
     return new (arena) RenderTextControlSingleLine(element(), element()->placeholderShouldBeVisible());
diff --git a/WebCore/html/TextFieldInputType.h b/WebCore/html/TextFieldInputType.h
index 78bec1d..50418aa 100644
--- a/WebCore/html/TextFieldInputType.h
+++ b/WebCore/html/TextFieldInputType.h
@@ -42,6 +42,8 @@ protected:
     TextFieldInputType(HTMLInputElement* element) : InputType(element) { }
     virtual bool isTextField() const;
     virtual bool valueMissing(const String&) const;
+    virtual bool handleKeydownEvent(KeyboardEvent*);
+    bool handleKeydownEventForSpinButton(KeyboardEvent*);
     virtual RenderObject* createRenderer(RenderArena*, RenderStyle*) const;
 };
 

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list