Chromium Code Reviews| Index: third_party/WebKit/Source/core/html/shadow/SliderThumbElement.cpp |
| diff --git a/third_party/WebKit/Source/core/html/shadow/SliderThumbElement.cpp b/third_party/WebKit/Source/core/html/shadow/SliderThumbElement.cpp |
| index 8d9d3f157686106527291c1d3c1f15c6a4c3c210..399c248d0d33418c5df7bee88f217945a66b2f64 100644 |
| --- a/third_party/WebKit/Source/core/html/shadow/SliderThumbElement.cpp |
| +++ b/third_party/WebKit/Source/core/html/shadow/SliderThumbElement.cpp |
| @@ -31,9 +31,11 @@ |
| #include "core/html/shadow/SliderThumbElement.h" |
| +#include "core/dom/shadow/ShadowRoot.h" |
| #include "core/events/Event.h" |
| #include "core/events/MouseEvent.h" |
| -#include "core/dom/shadow/ShadowRoot.h" |
| +#include "core/events/TouchEvent.h" |
| +#include "core/frame/EventHandlerRegistry.h" |
| #include "core/frame/LocalFrame.h" |
| #include "core/html/HTMLInputElement.h" |
| #include "core/html/forms/StepRange.h" |
| @@ -297,6 +299,7 @@ const AtomicString& SliderThumbElement::shadowPseudoId() const |
| inline SliderContainerElement::SliderContainerElement(Document& document) |
| : HTMLDivElement(document) |
| + , m_hasTouchEventHandler(false) |
| { |
| } |
| @@ -307,6 +310,33 @@ LayoutObject* SliderContainerElement::createLayoutObject(const ComputedStyle&) |
| return new LayoutSliderContainer(this); |
| } |
| +void SliderContainerElement::defaultEventHandler(Event* event) |
| +{ |
| + if (event->isTouchEvent()) { |
| + handleTouchEvent(toTouchEvent(event)); |
| + return; |
| + } |
| +} |
| + |
| +void SliderContainerElement::handleTouchEvent(TouchEvent* event) |
| +{ |
| + HTMLInputElement* input = toHTMLInputElement(shadowHost()); |
| + if (input->isDisabledOrReadOnly()) |
| + return; |
| + |
| + if (event->type() == EventTypeNames::touchend) { |
| + input->dispatchFormControlChangeEvent(); |
| + event->setDefaultHandled(); |
| + return; |
| + } |
| + |
| + TouchList* touches = event->targetTouches(); |
| + SliderThumbElement* thumb = toSliderThumbElement(input->userAgentShadowRoot()->getElementById(ShadowElementNames::sliderThumb())); |
| + if (touches->length() == 1) { |
| + thumb->setPositionFromPoint(touches->item(0)->absoluteLocation()); |
| + } |
| +} |
| + |
| const AtomicString& SliderContainerElement::shadowPseudoId() const |
| { |
| DEFINE_STATIC_LOCAL(const AtomicString, mediaSliderContainer, ("-webkit-media-slider-container")); |
| @@ -329,4 +359,34 @@ const AtomicString& SliderContainerElement::shadowPseudoId() const |
| } |
| } |
| +void SliderContainerElement::updateTouchEventHandlerRegistry() |
| +{ |
| + if (m_hasTouchEventHandler) { |
| + return; |
| + } |
| + if (document().frameHost() && document().lifecycle().state() < DocumentLifecycle::Stopping) { |
| + EventHandlerRegistry& registry = document().frameHost()->eventHandlerRegistry(); |
| + registry.didAddEventHandler(*this, EventHandlerRegistry::TouchStartOrMoveEventPassive); |
|
tkent
2016/08/18 05:13:49
didRemoveEventHandler() isn't called for *this. I
|
| + m_hasTouchEventHandler = true; |
| + } |
| +} |
| + |
| +void SliderContainerElement::didMoveToNewDocument(Document& oldDocument) |
| +{ |
| + updateTouchEventHandlerRegistry(); |
| + HTMLElement::didMoveToNewDocument(oldDocument); |
| +} |
| + |
| +void SliderContainerElement::parseAttribute(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& value) |
| +{ |
| + HTMLElement::parseAttribute(name, oldValue, value); |
| + updateTouchEventHandlerRegistry(); |
| +} |
| + |
| +void SliderContainerElement::removeAllEventListeners() |
| +{ |
| + Node::removeAllEventListeners(); |
| + m_hasTouchEventHandler = false; |
| +} |
| + |
| } // namespace blink |