diff options
author | George Mount <mount@google.com> | 2012-04-25 07:16:49 -0700 |
---|---|---|
committer | George Mount <mount@google.com> | 2012-04-25 10:55:16 -0700 |
commit | ab116239e825f4571a4665cee1f3cf92fd8d304c (patch) | |
tree | c3fd9fafa37cb607c7114111417f96e81d23f5b3 /Source/WebCore/html | |
parent | 2ad54828a335c8e7337ab1f1077253689630a6d2 (diff) | |
download | external_webkit-ab116239e825f4571a4665cee1f3cf92fd8d304c.zip external_webkit-ab116239e825f4571a4665cee1f3cf92fd8d304c.tar.gz external_webkit-ab116239e825f4571a4665cee1f3cf92fd8d304c.tar.bz2 |
Make input="range" visible and react to touch events.
Bug 6257532
Change-Id: I1d1ae457c50fe5b9627df7edb4f11d8245b5bdbf
Diffstat (limited to 'Source/WebCore/html')
-rw-r--r-- | Source/WebCore/html/HTMLInputElement.cpp | 8 | ||||
-rw-r--r-- | Source/WebCore/html/InputType.cpp | 6 | ||||
-rw-r--r-- | Source/WebCore/html/InputType.h | 4 | ||||
-rw-r--r-- | Source/WebCore/html/RangeInputType.cpp | 16 | ||||
-rw-r--r-- | Source/WebCore/html/RangeInputType.h | 4 | ||||
-rw-r--r-- | Source/WebCore/html/shadow/SliderThumbElement.cpp | 114 | ||||
-rw-r--r-- | Source/WebCore/html/shadow/SliderThumbElement.h | 10 |
7 files changed, 69 insertions, 93 deletions
diff --git a/Source/WebCore/html/HTMLInputElement.cpp b/Source/WebCore/html/HTMLInputElement.cpp index 36cdf51..51b87cb 100644 --- a/Source/WebCore/html/HTMLInputElement.cpp +++ b/Source/WebCore/html/HTMLInputElement.cpp @@ -1102,14 +1102,6 @@ void HTMLInputElement::defaultEventHandler(Event* evt) return; } -#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) - if (evt->isTouchEvent() && evt->type() == eventNames().touchstartEvent) { - m_inputType->handleTouchStartEvent(static_cast<TouchEvent*>(evt)); - if (evt->defaultHandled()) - return; - } -#endif - m_inputType->forwardEvent(evt); if (!callBaseClassEarly && !evt->defaultHandled()) diff --git a/Source/WebCore/html/InputType.cpp b/Source/WebCore/html/InputType.cpp index 9756313..ba27408 100644 --- a/Source/WebCore/html/InputType.cpp +++ b/Source/WebCore/html/InputType.cpp @@ -310,12 +310,6 @@ void InputType::handleMouseDownEvent(MouseEvent*) { } -#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) -void InputType::handleTouchStartEvent(TouchEvent*) -{ -} -#endif - void InputType::handleDOMActivateEvent(Event*) { } diff --git a/Source/WebCore/html/InputType.h b/Source/WebCore/html/InputType.h index 1b34717..ed69883 100644 --- a/Source/WebCore/html/InputType.h +++ b/Source/WebCore/html/InputType.h @@ -173,10 +173,6 @@ public: virtual void handleWheelEvent(WheelEvent*); virtual void forwardEvent(Event*); -#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) - virtual void handleTouchStartEvent(TouchEvent*); -#endif - // Helpers for event handlers. virtual bool shouldSubmitImplicitly(Event*); virtual PassRefPtr<HTMLFormElement> formForSubmission() const; diff --git a/Source/WebCore/html/RangeInputType.cpp b/Source/WebCore/html/RangeInputType.cpp index 783eabc..88563c7 100644 --- a/Source/WebCore/html/RangeInputType.cpp +++ b/Source/WebCore/html/RangeInputType.cpp @@ -199,22 +199,6 @@ void RangeInputType::handleKeydownEvent(KeyboardEvent* event) event->setDefaultHandled(); } -#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) -void RangeInputType::handleTouchStartEvent(TouchEvent* touchEvent) -{ - if (SliderThumbElement* thumb = shadowSliderThumb()) { - if (touchEvent->touches() && touchEvent->touches()->item(0)) { - IntPoint curPoint; - curPoint.setX(touchEvent->touches()->item(0)->pageX()); - curPoint.setY(touchEvent->touches()->item(0)->pageY()); - thumb->dragFrom(curPoint); - touchEvent->setDefaultHandled(); - touchEvent->setDefaultPrevented(true); - } - } -} -#endif - void RangeInputType::createShadowSubtree() { ExceptionCode ec = 0; diff --git a/Source/WebCore/html/RangeInputType.h b/Source/WebCore/html/RangeInputType.h index 358a638..75e7a17 100644 --- a/Source/WebCore/html/RangeInputType.h +++ b/Source/WebCore/html/RangeInputType.h @@ -71,10 +71,6 @@ private: virtual bool shouldRespectListAttribute(); SliderThumbElement* shadowSliderThumb() const; - -#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) - virtual void handleTouchStartEvent(TouchEvent*); -#endif }; } // namespace WebCore diff --git a/Source/WebCore/html/shadow/SliderThumbElement.cpp b/Source/WebCore/html/shadow/SliderThumbElement.cpp index e68ab00..6f4fedb 100644 --- a/Source/WebCore/html/shadow/SliderThumbElement.cpp +++ b/Source/WebCore/html/shadow/SliderThumbElement.cpp @@ -87,6 +87,39 @@ void RenderSliderThumb::layout() RenderBlock::layout(); } +#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) +class SliderTouchEventListener : public EventListener { +public: + static PassRefPtr<SliderTouchEventListener> create(SliderThumbElement* slider) + { + return adoptRef(new SliderTouchEventListener(slider)); + } + virtual bool operator==(const EventListener& other) { + return this == &other; + } + virtual void handleEvent(ScriptExecutionContext*, Event* event) + { + if (!event || !event->isTouchEvent()) + return; + TouchEvent* touchEvent = static_cast<TouchEvent*>(event); + if (touchEvent->touches() && touchEvent->touches()->item(0)) { + IntPoint curPoint; + curPoint.setX(touchEvent->touches()->item(0)->pageX()); + curPoint.setY(touchEvent->touches()->item(0)->pageY()); + m_slider->setPositionFromPoint(curPoint); + touchEvent->setDefaultHandled(); + touchEvent->setDefaultPrevented(true); + } + } +private: + SliderTouchEventListener(SliderThumbElement* slider) + : EventListener(NativeEventListenerType) + , m_slider(slider) + {} + SliderThumbElement* m_slider; +}; +#endif + void SliderThumbElement::setPositionFromValue() { // Since today the code to calculate position is in the RenderSlider layout @@ -170,10 +203,6 @@ void SliderThumbElement::stopDragging() if (Frame* frame = document()->frame()) frame->eventHandler()->setCapturingMouseEventsNode(0); -#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) - if (Frame* frame = document()->frame()) - frame->page()->mainFrame()->eventHandler()->setCapturingTouchEventsNode(0); -#endif m_inDragMode = false; if (renderer()) renderer()->setNeedsLayout(true); @@ -181,82 +210,57 @@ void SliderThumbElement::stopDragging() void SliderThumbElement::defaultEventHandler(Event* event) { - if (!event->isMouseEvent() -#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) - && !event->isTouchEvent() -#endif - ) { + if (!event->isMouseEvent()) { HTMLDivElement::defaultEventHandler(event); return; } - -#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) - bool isLeftButton = false; - - if (event->isMouseEvent()) { - MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); - isLeftButton = mouseEvent->button() == LeftButton; - } -#else MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); bool isLeftButton = mouseEvent->button() == LeftButton; -#endif const AtomicString& eventType = event->type(); - if (eventType == eventNames().mousedownEvent && isLeftButton -#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) - || eventType == eventNames().touchstartEvent -#endif - ) { + if (eventType == eventNames().mousedownEvent && isLeftButton) { startDragging(); return; - } else if (eventType == eventNames().mouseupEvent && isLeftButton -#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) - || eventType == eventNames().touchendEvent - || eventType == eventNames().touchcancelEvent -#endif - ) { + } else if (eventType == eventNames().mouseupEvent && isLeftButton) { stopDragging(); return; - } else if (eventType == eventNames().mousemoveEvent -#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) - || eventType == eventNames().touchmoveEvent -#endif - ) { + } else if (eventType == eventNames().mousemoveEvent) { if (m_inDragMode) -#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) - { - if (event->isMouseEvent()) { - MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); -#endif setPositionFromPoint(mouseEvent->absoluteLocation()); -#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) - } else if (event->isTouchEvent()) { - TouchEvent* touchEvent = static_cast<TouchEvent*>(event); - if (touchEvent->touches() && touchEvent->touches()->item(0)) { - IntPoint curPoint; - curPoint.setX(touchEvent->touches()->item(0)->pageX()); - curPoint.setY(touchEvent->touches()->item(0)->pageY()); - setPositionFromPoint(curPoint); - // Tell the webview that webkit will handle the following move events - event->setDefaultPrevented(true); - } - } - - } -#endif return; } HTMLDivElement::defaultEventHandler(event); } +#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) +void SliderThumbElement::attach() +{ + HTMLDivElement::attach(); + // Add a touch event handler to ensure we get touch events. + if (!m_touchListener) + m_touchListener = SliderTouchEventListener::create(this); + addEventListener(eventNames().touchstartEvent, + m_touchListener, false); + addEventListener(eventNames().touchmoveEvent, + m_touchListener, false); +} +#endif + void SliderThumbElement::detach() { if (m_inDragMode) { if (Frame* frame = document()->frame()) frame->eventHandler()->setCapturingMouseEventsNode(0); } +#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) + if (m_touchListener) { + removeEventListener(eventNames().touchstartEvent, + m_touchListener.get(), false); + removeEventListener(eventNames().touchmoveEvent, + m_touchListener.get(), false); + } +#endif HTMLDivElement::detach(); } diff --git a/Source/WebCore/html/shadow/SliderThumbElement.h b/Source/WebCore/html/shadow/SliderThumbElement.h index 2fa60cb..47e12f1 100644 --- a/Source/WebCore/html/shadow/SliderThumbElement.h +++ b/Source/WebCore/html/shadow/SliderThumbElement.h @@ -44,6 +44,9 @@ class HTMLElement; class HTMLInputElement; class Event; class FloatPoint; +#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) +class SliderTouchEventListener; +#endif class SliderThumbElement : public HTMLDivElement { public: @@ -54,6 +57,9 @@ public: void dragFrom(const IntPoint&); virtual void defaultEventHandler(Event*); +#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) + virtual void attach(); +#endif virtual void detach(); virtual const AtomicString& shadowPseudoId() const; @@ -67,6 +73,10 @@ private: FloatPoint m_offsetToThumb; bool m_inDragMode; +#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) + RefPtr<EventListener> m_touchListener; + friend class SliderTouchEventListener; +#endif }; inline SliderThumbElement::SliderThumbElement(Document* document) |