summaryrefslogtreecommitdiffstats
path: root/WebCore/html/RangeInputType.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/html/RangeInputType.cpp')
-rw-r--r--WebCore/html/RangeInputType.cpp41
1 files changed, 41 insertions, 0 deletions
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());