diff options
author | Teng-Hui Zhu <ztenghui@google.com> | 2011-05-03 09:55:46 -0700 |
---|---|---|
committer | Teng-Hui Zhu <ztenghui@google.com> | 2011-05-04 16:13:44 -0700 |
commit | f528fe407ddb4168b95f347b27ecc9a6cc40d69f (patch) | |
tree | bd5ea4ebcd22d4c95e12a8dbcf405ceb6d92c6fd | |
parent | cb3b95731fe488eda71bb6644ed0faf3beab4b1b (diff) | |
download | external_webkit-f528fe407ddb4168b95f347b27ecc9a6cc40d69f.zip external_webkit-f528fe407ddb4168b95f347b27ecc9a6cc40d69f.tar.gz external_webkit-f528fe407ddb4168b95f347b27ecc9a6cc40d69f.tar.bz2 |
Add the touch event handling for the slider.
bug:4232704
Change-Id: Ia3ac8a6003c1ff7b06d2a226b3206a3be0f8c6b5
-rw-r--r-- | WebCore/html/HTMLInputElement.cpp | 9 | ||||
-rw-r--r-- | WebCore/html/HTMLMediaElement.cpp | 4 | ||||
-rw-r--r-- | WebCore/rendering/MediaControlElements.cpp | 6 | ||||
-rw-r--r-- | WebCore/rendering/RenderMedia.cpp | 13 | ||||
-rw-r--r-- | WebCore/rendering/RenderMedia.h | 3 | ||||
-rw-r--r-- | WebCore/rendering/RenderSlider.cpp | 41 |
6 files changed, 69 insertions, 7 deletions
diff --git a/WebCore/html/HTMLInputElement.cpp b/WebCore/html/HTMLInputElement.cpp index 7449098..e4c253e 100644 --- a/WebCore/html/HTMLInputElement.cpp +++ b/WebCore/html/HTMLInputElement.cpp @@ -1554,7 +1554,14 @@ void HTMLInputElement::defaultEventHandler(Event* evt) if (isTextField() && renderer() && (evt->isMouseEvent() || evt->isDragEvent() || evt->isWheelEvent() || evt->type() == eventNames().blurEvent || evt->type() == eventNames().focusEvent)) toRenderTextControlSingleLine(renderer())->forwardEvent(evt); - if (deprecatedInputType() == RANGE && renderer() && (evt->isMouseEvent() || evt->isDragEvent() || evt->isWheelEvent())) + if (deprecatedInputType() == RANGE + && renderer() + && (evt->isMouseEvent() +#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) + || evt->isTouchEvent() +#endif + || evt->isDragEvent() + || evt->isWheelEvent())) toRenderSlider(renderer())->forwardEvent(evt); if (!callBaseClassEarly && !evt->defaultHandled()) diff --git a/WebCore/html/HTMLMediaElement.cpp b/WebCore/html/HTMLMediaElement.cpp index 7c061d0..8af8927 100644 --- a/WebCore/html/HTMLMediaElement.cpp +++ b/WebCore/html/HTMLMediaElement.cpp @@ -170,6 +170,10 @@ HTMLMediaElement::HTMLMediaElement(const QualifiedName& tagName, Document* docum LOG(Media, "HTMLMediaElement::HTMLMediaElement"); document->registerForDocumentActivationCallbacks(this); document->registerForMediaVolumeCallbacks(this); +#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) + // Enable the Media Element to listen to all the touch events + document->addListenerTypeIfNeeded(eventNames().touchstartEvent); +#endif } HTMLMediaElement::~HTMLMediaElement() diff --git a/WebCore/rendering/MediaControlElements.cpp b/WebCore/rendering/MediaControlElements.cpp index 1af1b80..25b5a12 100644 --- a/WebCore/rendering/MediaControlElements.cpp +++ b/WebCore/rendering/MediaControlElements.cpp @@ -719,8 +719,12 @@ void MediaControlTimelineElement::defaultEventHandler(Event* event) } RenderSlider* slider = toRenderSlider(renderer()); - if (slider && slider->inDragMode()) + if (slider && slider->inDragMode()) { toRenderMedia(mediaElement()->renderer())->updateTimeDisplay(); +#if PLATFORM(ANDROID) + toRenderMedia(mediaElement()->renderer())->updateLastTouch(); +#endif + } if (event->type() == eventNames().mouseupEvent) mediaElement()->endScrubbing(); diff --git a/WebCore/rendering/RenderMedia.cpp b/WebCore/rendering/RenderMedia.cpp index f19ca96..6fe0337 100644 --- a/WebCore/rendering/RenderMedia.cpp +++ b/WebCore/rendering/RenderMedia.cpp @@ -550,11 +550,22 @@ void RenderMedia::updateVolumeSliderContainer(bool visible) } } +#if PLATFORM(ANDROID) +void RenderMedia::updateLastTouch() +{ + m_lastTouch = WTF::currentTime(); +} +#endif + void RenderMedia::forwardEvent(Event* event) { #if PLATFORM(ANDROID) if (event->isMouseEvent()) - m_lastTouch = WTF::currentTime(); + updateLastTouch(); +#if ENABLE(TOUCH_EVENTS) + if (event->isTouchEvent()) + updateLastTouch(); +#endif #endif if (event->isMouseEvent() && m_controlsShadowRoot) { diff --git a/WebCore/rendering/RenderMedia.h b/WebCore/rendering/RenderMedia.h index 65fdc7d..a3b5c5c 100644 --- a/WebCore/rendering/RenderMedia.h +++ b/WebCore/rendering/RenderMedia.h @@ -71,6 +71,9 @@ public: void updateTimeDisplay(); void forwardEvent(Event*); +#if PLATFORM(ANDROID) + void updateLastTouch(); +#endif protected: virtual void layout(); diff --git a/WebCore/rendering/RenderSlider.cpp b/WebCore/rendering/RenderSlider.cpp index d680bc7..f00b586 100644 --- a/WebCore/rendering/RenderSlider.cpp +++ b/WebCore/rendering/RenderSlider.cpp @@ -43,6 +43,10 @@ #include "Settings.h" #endif +#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) +#include "TouchEvent.h" +#endif + using std::min; namespace WebCore { @@ -85,7 +89,11 @@ inline PassRefPtr<SliderThumbElement> SliderThumbElement::create(HTMLElement* sh void SliderThumbElement::defaultEventHandler(Event* event) { - if (!event->isMouseEvent()) { + if (!event->isMouseEvent() +#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) + && !event->isTouchEvent() +#endif + ) { ShadowBlockElement::defaultEventHandler(event); return; } @@ -94,7 +102,11 @@ void SliderThumbElement::defaultEventHandler(Event* event) bool isLeftButton = mouseEvent->button() == LeftButton; const AtomicString& eventType = event->type(); - if (eventType == eventNames().mousedownEvent && isLeftButton) { + if (eventType == eventNames().mousedownEvent && isLeftButton +#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) + || eventType == eventNames().touchstartEvent +#endif + ) { if (document()->frame() && renderer()) { RenderSlider* slider = toRenderSlider(renderer()->parent()); if (slider) { @@ -115,7 +127,11 @@ void SliderThumbElement::defaultEventHandler(Event* event) return; } } - } else if (eventType == eventNames().mouseupEvent && isLeftButton) { + } else if (eventType == eventNames().mouseupEvent && isLeftButton +#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) + || eventType == eventNames().touchendEvent +#endif + ) { if (m_inDragMode) { if (Frame* frame = document()->frame()) frame->eventHandler()->setCapturingMouseEventsNode(0); @@ -123,11 +139,28 @@ void SliderThumbElement::defaultEventHandler(Event* event) event->setDefaultHandled(); return; } - } else if (eventType == eventNames().mousemoveEvent) { + } else if (eventType == eventNames().mousemoveEvent +#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) + || eventType == eventNames().touchmoveEvent +#endif + ) { if (m_inDragMode && renderer() && renderer()->parent()) { RenderSlider* slider = toRenderSlider(renderer()->parent()); if (slider) { FloatPoint curPoint = slider->absoluteToLocal(mouseEvent->absoluteLocation(), false, true); +#if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) + // Update the position when it is a touch event + if (event->isTouchEvent()) { + TouchEvent* touchEvent = static_cast<TouchEvent*>(event); + if (touchEvent && touchEvent->touches() && touchEvent->touches()->item(0)) { + curPoint.setX(touchEvent->touches()->item(0)->pageX()); + curPoint.setY(touchEvent->touches()->item(0)->pageY()); + curPoint = slider->absoluteToLocal(curPoint, false, true); + } + } + // Tell the webview that webkit will handle the following move events + event->setDefaultPrevented(true); +#endif IntPoint eventOffset(curPoint.x() + m_offsetToThumb.x(), curPoint.y() + m_offsetToThumb.y()); slider->setValueForPosition(slider->positionForOffset(eventOffset)); event->setDefaultHandled(); |