Index: third_party/WebKit/Source/core/html/HTMLInputElement.cpp |
diff --git a/third_party/WebKit/Source/core/html/HTMLInputElement.cpp b/third_party/WebKit/Source/core/html/HTMLInputElement.cpp |
index f8d7bcbe059cf33dd3cf7080c13333b6acbb3047..a86c04f8d736b33a95bd5eaee16deb66029462fb 100644 |
--- a/third_party/WebKit/Source/core/html/HTMLInputElement.cpp |
+++ b/third_party/WebKit/Source/core/html/HTMLInputElement.cpp |
@@ -47,7 +47,9 @@ |
#include "core/events/KeyboardEvent.h" |
#include "core/events/MouseEvent.h" |
#include "core/events/ScopedEventQueue.h" |
+#include "core/events/TouchEvent.h" |
#include "core/frame/Deprecation.h" |
+#include "core/frame/EventHandlerRegistry.h" |
#include "core/frame/FrameHost.h" |
#include "core/frame/FrameView.h" |
#include "core/frame/LocalFrame.h" |
@@ -111,6 +113,7 @@ |
, m_parsingInProgress(createdByParser) |
, m_valueAttributeWasUpdatedAfterParsing(false) |
, m_canReceiveDroppedFiles(false) |
+ , m_hasTouchEventHandler(false) |
, m_shouldRevealPassword(false) |
, m_needsToUpdateViewValue(true) |
, m_isPlaceholderVisible(false) |
@@ -398,6 +401,25 @@ |
setAttribute(typeAttr, type); |
} |
+void HTMLInputElement::updateTouchEventHandlerRegistry() |
+{ |
+ DCHECK(m_inputTypeView); |
+ |
+ bool hasTouchEventHandler = m_inputTypeView->hasTouchEventHandler(); |
+ if (hasTouchEventHandler == !!m_hasTouchEventHandler) |
+ return; |
+ // If the Document is being or has been stopped, don't register any handlers. |
+ if (document().frameHost() && document().lifecycle().state() < DocumentLifecycle::Stopping) { |
+ EventHandlerRegistry& registry = document().frameHost()->eventHandlerRegistry(); |
+ // TODO(dtapuska): Make this passive touch listener see crbug.com/584438 |
+ if (hasTouchEventHandler) |
+ registry.didAddEventHandler(*this, EventHandlerRegistry::TouchStartOrMoveEventBlocking); |
+ else |
+ registry.didRemoveEventHandler(*this, EventHandlerRegistry::TouchStartOrMoveEventBlocking); |
+ m_hasTouchEventHandler = hasTouchEventHandler; |
+ } |
+} |
+ |
void HTMLInputElement::initializeTypeInParsing() |
{ |
DCHECK(m_parsingInProgress); |
@@ -409,6 +431,8 @@ |
m_inputTypeView = m_inputType->createView(); |
ensureUserAgentShadowRoot(); |
+ updateTouchEventHandlerRegistry(); |
+ |
setNeedsWillValidateCheck(); |
m_inputType->warnIfValueIsInvalid(fastGetAttribute(valueAttr).getString()); |
@@ -440,6 +464,8 @@ |
m_inputType = newType; |
m_inputTypeView = m_inputType->createView(); |
m_inputTypeView->createShadowSubtree(); |
+ |
+ updateTouchEventHandlerRegistry(); |
setNeedsWillValidateCheck(); |
@@ -1135,6 +1161,12 @@ |
return; |
} |
+ if (evt->isTouchEvent() && m_inputTypeView->hasTouchEventHandler()) { |
+ m_inputTypeView->handleTouchEvent(toTouchEvent(evt)); |
+ if (evt->defaultHandled()) |
+ return; |
+ } |
+ |
if (evt->isKeyboardEvent() && evt->type() == EventTypeNames::keydown) { |
m_inputTypeView->handleKeydownEvent(toKeyboardEvent(evt)); |
if (evt->defaultHandled()) |
@@ -1474,7 +1506,15 @@ |
if (type() == InputTypeNames::radio) |
treeScope().radioButtonGroupScope().removeButton(this); |
+ updateTouchEventHandlerRegistry(); |
+ |
HTMLTextFormControlElement::didMoveToNewDocument(oldDocument); |
+} |
+ |
+void HTMLInputElement::removeAllEventListeners() |
+{ |
+ HTMLTextFormControlElement::removeAllEventListeners(); |
+ m_hasTouchEventHandler = false; |
} |
bool HTMLInputElement::recalcWillValidate() const |