Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Unified Diff: third_party/WebKit/Source/core/html/shadow/SliderThumbElement.cpp

Issue 2209773002: Remove the blocking touch handlers for the input[type=range] and add touch-action instead (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed 'id=container' to pass more tests Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..90b60a122fbfc7132034dad87eea6983b44198c3 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,39 @@ 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);
+ m_hasTouchEventHandler = true;
+ }
+}
+
+void SliderContainerElement::didMoveToNewDocument(Document& oldDocument)
+{
+ updateTouchEventHandlerRegistry();
+ HTMLElement::didMoveToNewDocument(oldDocument);
+}
+
+void SliderContainerElement::parserDidSetAttributes()
tkent 2016/08/17 01:32:00 Why is it necessary though parseAttribute() calls
+{
+ updateTouchEventHandlerRegistry();
+}
+
+void SliderContainerElement::parseAttribute(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& value)
+{
+ HTMLElement::parseAttribute(name, oldValue, value);
+ updateTouchEventHandlerRegistry();
tkent 2016/08/17 01:32:00 Why do we need to call updateTouchEventHandlerRegi
+}
+
+void SliderContainerElement::removeAllEventListeners()
+{
+ Node::removeAllEventListeners();
+ m_hasTouchEventHandler = false;
+}
+
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698