- Revision
- 120903
- Author
- [email protected]
- Date
- 2012-06-20 22:11:25 -0700 (Wed, 20 Jun 2012)
Log Message
[Forms] Make step action of SpinButtonElement replaceable
https://bugs.webkit.org/show_bug.cgi?id=89439
Reviewed by Kent Tamura.
This patch introduces SpinButtonElement::Callback to specify step
action by control clients for using SpinButtonElement by
TextFieldInputType and future version of TimeInputField.
In addition to this improving flexibility of SpinButtonElement, we
free HTMLInputElement from SpinButtonElement dependency on
stepUpFromRenderer.
No new tests. This patch doesn't change behavior.
* html/HTMLInputElement.cpp: Removed stepUpFromRenderer().
* html/HTMLInputElement.h: Removed stepUpFromRenderer().
* html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::~TextFieldInputType): Added to call SpinButtonElement::removeStepActionHandler.
(WebCore::TextFieldInputType::handleKeydownEventForSpinButton): Changed to call spinButtonStep{Down,Up}
(WebCore::TextFieldInputType::handleWheelEventForSpinButton): Changed to call spinButtonStep{Down,Up}
(WebCore::TextFieldInputType::createShadowSubtree): Added SpinButtonElement::StepActionHandler parameter.
(WebCore::TextFieldInputType::destroyShadowSubtree): Added to call SpinButtonElement::removeStepActionHandler.
(WebCore::TextFieldInputType::spinButtonStepDown): Added for implementation of SpinButtonElement::StepActionHandler.
(WebCore::TextFieldInputType::spinButtonStepUp): Added for implementation of SpinButtonElement::StepActionHandler.
* html/TextFieldInputType.h:
(TextFieldInputType):
* html/shadow/TextControlInnerElements.cpp:
(WebCore::SpinButtonElement::SpinButtonElement): Added StepActionHandler parameter.
(WebCore::SpinButtonElement::defaultEventHandler): Changed to call doStepAction.
(WebCore::SpinButtonElement::doStepAction): Added to call StepActionHandler if possible.
(WebCore::SpinButtonElement::step): Changed to call doStepAction.
* html/shadow/TextControlInnerElements.h:
(StepActionHandler): Added.
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (120902 => 120903)
--- trunk/Source/WebCore/ChangeLog 2012-06-21 04:46:05 UTC (rev 120902)
+++ trunk/Source/WebCore/ChangeLog 2012-06-21 05:11:25 UTC (rev 120903)
@@ -1,3 +1,40 @@
+2012-06-20 Yoshifumi Inoue <[email protected]>
+
+ [Forms] Make step action of SpinButtonElement replaceable
+ https://bugs.webkit.org/show_bug.cgi?id=89439
+
+ Reviewed by Kent Tamura.
+
+ This patch introduces SpinButtonElement::Callback to specify step
+ action by control clients for using SpinButtonElement by
+ TextFieldInputType and future version of TimeInputField.
+
+ In addition to this improving flexibility of SpinButtonElement, we
+ free HTMLInputElement from SpinButtonElement dependency on
+ stepUpFromRenderer.
+
+ No new tests. This patch doesn't change behavior.
+
+ * html/HTMLInputElement.cpp: Removed stepUpFromRenderer().
+ * html/HTMLInputElement.h: Removed stepUpFromRenderer().
+ * html/TextFieldInputType.cpp:
+ (WebCore::TextFieldInputType::~TextFieldInputType): Added to call SpinButtonElement::removeStepActionHandler.
+ (WebCore::TextFieldInputType::handleKeydownEventForSpinButton): Changed to call spinButtonStep{Down,Up}
+ (WebCore::TextFieldInputType::handleWheelEventForSpinButton): Changed to call spinButtonStep{Down,Up}
+ (WebCore::TextFieldInputType::createShadowSubtree): Added SpinButtonElement::StepActionHandler parameter.
+ (WebCore::TextFieldInputType::destroyShadowSubtree): Added to call SpinButtonElement::removeStepActionHandler.
+ (WebCore::TextFieldInputType::spinButtonStepDown): Added for implementation of SpinButtonElement::StepActionHandler.
+ (WebCore::TextFieldInputType::spinButtonStepUp): Added for implementation of SpinButtonElement::StepActionHandler.
+ * html/TextFieldInputType.h:
+ (TextFieldInputType):
+ * html/shadow/TextControlInnerElements.cpp:
+ (WebCore::SpinButtonElement::SpinButtonElement): Added StepActionHandler parameter.
+ (WebCore::SpinButtonElement::defaultEventHandler): Changed to call doStepAction.
+ (WebCore::SpinButtonElement::doStepAction): Added to call StepActionHandler if possible.
+ (WebCore::SpinButtonElement::step): Changed to call doStepAction.
+ * html/shadow/TextControlInnerElements.h:
+ (StepActionHandler): Added.
+
2012-06-20 Adrienne Walker <[email protected]>
[chromium] Modify CCDamageTracker hash to allow for layer id 0
Modified: trunk/Source/WebCore/html/HTMLInputElement.cpp (120902 => 120903)
--- trunk/Source/WebCore/html/HTMLInputElement.cpp 2012-06-21 04:46:05 UTC (rev 120902)
+++ trunk/Source/WebCore/html/HTMLInputElement.cpp 2012-06-21 05:11:25 UTC (rev 120903)
@@ -1461,11 +1461,6 @@
return m_inputType->isSteppable();
}
-void HTMLInputElement::stepUpFromRenderer(int n)
-{
- m_inputType->stepUpFromRenderer(n);
-}
-
#if ENABLE(INPUT_SPEECH)
bool HTMLInputElement::isSpeechEnabled() const
Modified: trunk/Source/WebCore/html/HTMLInputElement.h (120902 => 120903)
--- trunk/Source/WebCore/html/HTMLInputElement.h 2012-06-21 04:46:05 UTC (rev 120902)
+++ trunk/Source/WebCore/html/HTMLInputElement.h 2012-06-21 05:11:25 UTC (rev 120903)
@@ -77,7 +77,6 @@
void stepDown(ExceptionCode& ec) { stepDown(1, ec); }
// stepUp()/stepDown() for user-interaction.
bool isSteppable() const;
- void stepUpFromRenderer(int);
bool isTextButton() const;
Modified: trunk/Source/WebCore/html/TextFieldInputType.cpp (120902 => 120903)
--- trunk/Source/WebCore/html/TextFieldInputType.cpp 2012-06-21 04:46:05 UTC (rev 120902)
+++ trunk/Source/WebCore/html/TextFieldInputType.cpp 2012-06-21 05:11:25 UTC (rev 120903)
@@ -63,6 +63,8 @@
TextFieldInputType::~TextFieldInputType()
{
+ if (m_innerSpinButton)
+ m_innerSpinButton->removeStepActionHandler();
}
bool TextFieldInputType::isKeyboardFocusable(KeyboardEvent*) const
@@ -152,14 +154,12 @@
if (element()->disabled() || element()->readOnly())
return;
const String& key = event->keyIdentifier();
- int step = 0;
if (key == "Up")
- step = 1;
+ spinButtonStepUp();
else if (key == "Down")
- step = -1;
+ spinButtonStepDown();
else
return;
- element()->stepUpFromRenderer(step);
event->setDefaultHandled();
}
@@ -167,14 +167,12 @@
{
if (element()->disabled() || element()->readOnly() || !element()->focused())
return;
- int step = 0;
if (event->wheelDeltaY() > 0)
- step = 1;
+ spinButtonStepUp();
else if (event->wheelDeltaY() < 0)
- step = -1;
+ spinButtonStepDown();
else
return;
- element()->stepUpFromRenderer(step);
event->setDefaultHandled();
}
@@ -270,7 +268,7 @@
#endif
if (shouldHaveSpinButton) {
- m_innerSpinButton = SpinButtonElement::create(document);
+ m_innerSpinButton = SpinButtonElement::create(document, *this);
m_container->appendChild(m_innerSpinButton, ec);
}
@@ -320,6 +318,8 @@
#if ENABLE(INPUT_SPEECH)
m_speechButton.clear();
#endif
+ if (m_innerSpinButton)
+ m_innerSpinButton->removeStepActionHandler();
m_innerSpinButton.clear();
m_container.clear();
}
@@ -440,4 +440,15 @@
return true;
}
+void TextFieldInputType::spinButtonStepDown()
+{
+ stepUpFromRenderer(-1);
+}
+
+void TextFieldInputType::spinButtonStepUp()
+{
+ stepUpFromRenderer(1);
+}
+
+
} // namespace WebCore
Modified: trunk/Source/WebCore/html/TextFieldInputType.h (120902 => 120903)
--- trunk/Source/WebCore/html/TextFieldInputType.h 2012-06-21 04:46:05 UTC (rev 120902)
+++ trunk/Source/WebCore/html/TextFieldInputType.h 2012-06-21 05:11:25 UTC (rev 120903)
@@ -32,6 +32,7 @@
#define TextFieldInputType_h
#include "InputType.h"
+#include "TextControlInnerElements.h"
namespace WebCore {
@@ -40,7 +41,7 @@
// The class represents types of which UI contain text fields.
// It supports not only the types for BaseTextInputType but also type=number.
-class TextFieldInputType : public InputType {
+class TextFieldInputType : public InputType, private SpinButtonElement::StepActionHandler {
protected:
TextFieldInputType(HTMLInputElement*);
virtual ~TextFieldInputType();
@@ -84,6 +85,10 @@
virtual bool appendFormData(FormDataList&, bool multipart) const OVERRIDE;
virtual void attach() OVERRIDE;
+ // SpinButtonElement::StepActionHandler functions.
+ virtual void spinButtonStepDown() OVERRIDE;
+ virtual void spinButtonStepUp() OVERRIDE;
+
RefPtr<HTMLElement> m_container;
RefPtr<HTMLElement> m_innerBlock;
RefPtr<HTMLElement> m_innerText;
Modified: trunk/Source/WebCore/html/shadow/TextControlInnerElements.cpp (120902 => 120903)
--- trunk/Source/WebCore/html/shadow/TextControlInnerElements.cpp 2012-06-21 04:46:05 UTC (rev 120902)
+++ trunk/Source/WebCore/html/shadow/TextControlInnerElements.cpp 2012-06-21 05:11:25 UTC (rev 120903)
@@ -234,8 +234,9 @@
// ----------------------------
-inline SpinButtonElement::SpinButtonElement(Document* document)
+inline SpinButtonElement::SpinButtonElement(Document* document, StepActionHandler& stepActionHandler)
: HTMLDivElement(divTag, document)
+ , m_stepActionHandler(&stepActionHandler)
, m_capturing(false)
, m_upDownState(Indeterminate)
, m_pressStartingState(Indeterminate)
@@ -243,9 +244,9 @@
{
}
-PassRefPtr<SpinButtonElement> SpinButtonElement::create(Document* document)
+PassRefPtr<SpinButtonElement> SpinButtonElement::create(Document* document, StepActionHandler& stepActionHandler)
{
- return adoptRef(new SpinButtonElement(document));
+ return adoptRef(new SpinButtonElement(document, stepActionHandler));
}
const AtomicString& SpinButtonElement::shadowPseudoId() const
@@ -294,7 +295,7 @@
input->select();
if (renderer()) {
if (m_upDownState != Indeterminate) {
- input->stepUpFromRenderer(m_upDownState == Up ? 1 : -1);
+ doStepAction(m_upDownState == Up ? 1 : -1);
if (renderer())
startRepeatingTimer();
}
@@ -325,6 +326,17 @@
HTMLDivElement::defaultEventHandler(event);
}
+void SpinButtonElement::doStepAction(int amount)
+{
+ if (!m_stepActionHandler)
+ return;
+
+ if (amount > 0)
+ m_stepActionHandler->spinButtonStepUp();
+ else if (amount < 0)
+ m_stepActionHandler->spinButtonStepDown();
+}
+
void SpinButtonElement::releaseCapture()
{
stopRepeatingTimer();
@@ -360,7 +372,7 @@
if (m_upDownState != m_pressStartingState)
return;
#endif
- input->stepUpFromRenderer(amount);
+ doStepAction(amount);
}
void SpinButtonElement::repeatingTimerFired(Timer<SpinButtonElement>*)
Modified: trunk/Source/WebCore/html/shadow/TextControlInnerElements.h (120902 => 120903)
--- trunk/Source/WebCore/html/shadow/TextControlInnerElements.h 2012-06-21 04:46:05 UTC (rev 120902)
+++ trunk/Source/WebCore/html/shadow/TextControlInnerElements.h 2012-06-21 05:11:25 UTC (rev 120903)
@@ -96,14 +96,25 @@
Up,
};
- static PassRefPtr<SpinButtonElement> create(Document*);
+ class StepActionHandler {
+ public:
+ virtual ~StepActionHandler() { }
+ virtual void spinButtonStepDown() = 0;
+ virtual void spinButtonStepUp() = 0;
+ };
+
+ // The owner of SpinButtonElement must call removeStepActionHandler
+ // because SpinButtonElement can be outlive StepActionHandler
+ // implementation, e.g. during event handling.
+ static PassRefPtr<SpinButtonElement> create(Document*, StepActionHandler&);
UpDownState upDownState() const { return m_upDownState; }
virtual void releaseCapture();
+ void removeStepActionHandler() { m_stepActionHandler = 0; }
void step(int amount);
private:
- SpinButtonElement(Document*);
+ SpinButtonElement(Document*, StepActionHandler&);
virtual const AtomicString& shadowPseudoId() const;
virtual void detach();
@@ -111,12 +122,14 @@
virtual bool isEnabledFormControl() const { return static_cast<Element*>(shadowAncestorNode())->isEnabledFormControl(); }
virtual bool isReadOnlyFormControl() const { return static_cast<Element*>(shadowAncestorNode())->isReadOnlyFormControl(); }
virtual void defaultEventHandler(Event*);
+ void doStepAction(int);
void startRepeatingTimer();
void stopRepeatingTimer();
void repeatingTimerFired(Timer<SpinButtonElement>*);
virtual void setHovered(bool = true);
virtual bool isMouseFocusable() const { return false; }
+ StepActionHandler* m_stepActionHandler;
bool m_capturing;
UpDownState m_upDownState;
UpDownState m_pressStartingState;