Commit d27d20b0 authored by tkent@chromium.org's avatar tkent@chromium.org

<input type=number>: Support auto-repeat by mouse press

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

Reviewed by Shinichiro Hamaji

WebCore:

Like arrow button of scrollbars, spinbuttons of <input
type=number> should continue to increase/decrease their values
while the mouse button is pressed.

No new tests because the new behavior strongly depends on a timer.

* rendering/TextControlInnerElements.cpp:
(WebCore::SpinButtonElement::SpinButtonElement):
 Initializes the timer.
(WebCore::SpinButtonElement::defaultEventHandler):
 Starts the timer by a mousedown event.
(WebCore::SpinButtonElement::startRepeatingTimer):
(WebCore::SpinButtonElement::stopRepeatingTimer):
(WebCore::SpinButtonElement::repeatingTimerFired):
* rendering/TextControlInnerElements.h:

LayoutTests:

Update existing tests.

* fast/forms/script-tests/input-spinbutton-capturing.js:
* platform/mac/fast/forms/input-appearance-spinbutton-up-expected.checksum:
* platform/mac/fast/forms/input-appearance-spinbutton-up-expected.png:
* platform/mac/fast/forms/input-appearance-spinbutton-up-expected.txt:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@66001 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 1e56d8c5
2010-08-25 Kent Tamura <tkent@chromium.org>
Reviewed by Shinichiro Hamaji
<input type=number>: Support auto-repeat by mouse press
https://bugs.webkit.org/show_bug.cgi?id=44476
Update existing tests.
* fast/forms/script-tests/input-spinbutton-capturing.js:
* platform/mac/fast/forms/input-appearance-spinbutton-up-expected.checksum:
* platform/mac/fast/forms/input-appearance-spinbutton-up-expected.png:
* platform/mac/fast/forms/input-appearance-spinbutton-up-expected.txt:
2010-08-25 Kent Tamura <tkent@chromium.org>
Unreviewed, skip list update.
......@@ -14,6 +14,7 @@ if (window.eventSender) {
// There was a bug that a capturing flag of the first input field was not
// clear and this click didn't work.
eventSender.mouseMoveTo(anotherInput.offsetLeft + anotherInput.offsetWidth - 10, anotherInput.offsetTop + anotherInput.offsetHeight / 4);
eventSender.mouseMoveTo(anotherInput.offsetLeft + anotherInput.offsetWidth - 10, anotherInput.offsetTop + anotherInput.offsetHeight / 4 - 1);
eventSender.mouseDown();
eventSender.mouseUp();
shouldBe('anotherInput.value', '"2"');
......
5c1b34460d03938fffe006161914f725
\ No newline at end of file
00e1de48e3e84449e88ede94e8e11b58
\ No newline at end of file
......@@ -16,5 +16,5 @@ layer at (0,0) size 800x600
layer at (13,47) size 165x21
RenderBlock {DIV} at (3,3) size 165x21
RenderText {#text} at (1,0) size 12x21
text run at (1,0) width 12: "0"
caret: position 0 of child 0 {DIV} of child 5 {INPUT} of body
text run at (1,0) width 12: "1"
caret: position 1 of child 0 {#text} of child 0 {DIV} of child 5 {INPUT} of body
2010-08-25 Kent Tamura <tkent@chromium.org>
Reviewed by Shinichiro Hamaji
<input type=number>: Support auto-repeat by mouse press
https://bugs.webkit.org/show_bug.cgi?id=44476
Like arrow button of scrollbars, spinbuttons of <input
type=number> should continue to increase/decrease their values
while the mouse button is pressed.
No new tests because the new behavior strongly depends on a timer.
* rendering/TextControlInnerElements.cpp:
(WebCore::SpinButtonElement::SpinButtonElement):
Initializes the timer.
(WebCore::SpinButtonElement::defaultEventHandler):
Starts the timer by a mousedown event.
(WebCore::SpinButtonElement::startRepeatingTimer):
(WebCore::SpinButtonElement::stopRepeatingTimer):
(WebCore::SpinButtonElement::repeatingTimerFired):
* rendering/TextControlInnerElements.h:
2010-08-25 Gabor Loki <loki@webkit.org>
Reviewed by Gavin Barraclough.
......@@ -39,6 +39,7 @@
#include "Page.h"
#include "RenderLayer.h"
#include "RenderTextControlSingleLine.h"
#include "ScrollbarTheme.h"
#include "SpeechInput.h"
namespace WebCore {
......@@ -258,6 +259,8 @@ inline SpinButtonElement::SpinButtonElement(HTMLElement* shadowParent)
: TextControlInnerElement(shadowParent->document(), shadowParent)
, m_capturing(false)
, m_upDownState(Indeterminate)
, m_pressStartingState(Indeterminate)
, m_repeatingTimer(this, &SpinButtonElement::repeatingTimerFired)
{
}
......@@ -281,7 +284,6 @@ void SpinButtonElement::defaultEventHandler(Event* event)
return;
}
MouseEvent* mouseEvent = static_cast<MouseEvent*>(event);
HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowAncestorNode());
if (input->disabled() || input->isReadOnlyFormControl()) {
if (!event->defaultHandled())
......@@ -289,19 +291,20 @@ void SpinButtonElement::defaultEventHandler(Event* event)
return;
}
MouseEvent* mouseEvent = static_cast<MouseEvent*>(event);
IntPoint local = roundedIntPoint(box->absoluteToLocal(mouseEvent->absoluteLocation(), false, true));
if (event->type() == eventNames().clickEvent && mouseEvent->button() == LeftButton) {
if (mouseEvent->type() == eventNames().mousedownEvent && mouseEvent->button() == LeftButton) {
if (box->borderBoxRect().contains(local)) {
RefPtr<Node> protector(input);
input->focus();
input->select();
if (local.y() < box->height() / 2)
input->stepUpFromRenderer(1);
else
input->stepUpFromRenderer(-1);
input->stepUpFromRenderer(m_upDownState == Up ? 1 : -1);
event->setDefaultHandled();
startRepeatingTimer();
}
} else if (event->type() == eventNames().mousemoveEvent) {
} else if (mouseEvent->type() == eventNames().mouseupEvent && mouseEvent->button() == LeftButton)
stopRepeatingTimer();
else if (event->type() == eventNames().mousemoveEvent) {
if (box->borderBoxRect().contains(local)) {
if (!m_capturing) {
if (Frame* frame = document()->frame()) {
......@@ -315,6 +318,7 @@ void SpinButtonElement::defaultEventHandler(Event* event)
renderer()->repaint();
} else {
if (m_capturing) {
stopRepeatingTimer();
if (Frame* frame = document()->frame()) {
frame->eventHandler()->setCapturingMouseEventsNode(0);
m_capturing = false;
......@@ -327,6 +331,33 @@ void SpinButtonElement::defaultEventHandler(Event* event)
HTMLDivElement::defaultEventHandler(event);
}
void SpinButtonElement::startRepeatingTimer()
{
m_pressStartingState = m_upDownState;
ScrollbarTheme* theme = ScrollbarTheme::nativeTheme();
m_repeatingTimer.start(theme->initialAutoscrollTimerDelay(), theme->autoscrollTimerDelay());
}
void SpinButtonElement::stopRepeatingTimer()
{
m_repeatingTimer.stop();
}
void SpinButtonElement::repeatingTimerFired(Timer<SpinButtonElement>*)
{
HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowAncestorNode());
if (input->disabled() || input->isReadOnlyFormControl())
return;
// On Mac OS, NSStepper updates the value for the button under the mouse
// cursor regardless of the button pressed at the beginning. So the
// following check is not needed for Mac OS.
#if !OS(MAC_OS_X)
if (m_upDownState != m_pressStartingState)
return;
#endif
input->stepUpFromRenderer(m_upDownState == Up ? 1 : -1);
}
void SpinButtonElement::setHovered(bool flag)
{
if (!hovered() && flag)
......
......@@ -29,6 +29,7 @@
#include "HTMLDivElement.h"
#include "SpeechInputListener.h"
#include "Timer.h"
#include <wtf/Forward.h>
namespace WebCore {
......@@ -107,10 +108,15 @@ private:
virtual bool isEnabledFormControl() const { return static_cast<Element*>(const_cast<SpinButtonElement*>(this)->shadowAncestorNode())->isEnabledFormControl(); }
virtual bool isReadOnlyFormControl() const { return static_cast<Element*>(const_cast<SpinButtonElement*>(this)->shadowAncestorNode())->isReadOnlyFormControl(); }
virtual void defaultEventHandler(Event*);
void startRepeatingTimer();
void stopRepeatingTimer();
void repeatingTimerFired(Timer<SpinButtonElement>*);
virtual void setHovered(bool = true);
bool m_capturing;
UpDownState m_upDownState;
UpDownState m_pressStartingState;
Timer<SpinButtonElement> m_repeatingTimer;
};
#if ENABLE(INPUT_SPEECH)
......
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