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 c359033399174ee455fdd2d4ab7f5754a5e2b987..2fcf7572845238b7b1fe17f45ca7e514e7789510 100644 |
| --- a/third_party/WebKit/Source/core/html/shadow/SliderThumbElement.cpp |
| +++ b/third_party/WebKit/Source/core/html/shadow/SliderThumbElement.cpp |
| @@ -34,6 +34,7 @@ |
| #include "core/dom/shadow/ShadowRoot.h" |
| #include "core/events/Event.h" |
| #include "core/events/MouseEvent.h" |
| +#include "core/events/PointerEvent.h" |
| #include "core/events/TouchEvent.h" |
| #include "core/frame/EventHandlerRegistry.h" |
| #include "core/frame/LocalFrame.h" |
| @@ -95,9 +96,9 @@ Node* SliderThumbElement::focusDelegate() { |
| return hostInput(); |
| } |
| -void SliderThumbElement::dragFrom(const LayoutPoint& point) { |
| - startDragging(); |
| - setPositionFromPoint(point); |
| +void SliderThumbElement::dragFrom(const PointerEvent* event) { |
|
mustaq
2017/03/15 18:15:41
Please rename |dragFrom| to something like |initia
|
| + requestPointerCapture(event->pointerId()); |
| + setPositionFromPoint(LayoutPoint(event->absoluteLocation())); |
| } |
| void SliderThumbElement::setPositionFromPoint(const LayoutPoint& point) { |
| @@ -115,7 +116,7 @@ void SliderThumbElement::setPositionFromPoint(const LayoutPoint& point) { |
| LayoutUnit trackSize; |
| LayoutUnit position; |
| LayoutUnit currentPosition; |
| - // We need to calculate currentPosition from absolute points becaue the |
| + // We need to calculate currentPosition from absolute points because the |
| // layoutObject for this node is usually on a layer and layoutBox()->x() and |
| // y() are unusable. |
| // FIXME: This should probably respect transforms. |
| @@ -175,19 +176,13 @@ void SliderThumbElement::setPositionFromPoint(const LayoutPoint& point) { |
| LayoutInvalidationReason::SliderValueChanged); |
| } |
| -void SliderThumbElement::startDragging() { |
| - if (LocalFrame* frame = document().frame()) { |
| - frame->eventHandler().setCapturingMouseEventsNode(this); |
| - m_inDragMode = true; |
| - } |
| +inline void SliderThumbElement::startDragging() { |
| + m_inDragMode = true; |
| } |
| void SliderThumbElement::stopDragging() { |
| if (!m_inDragMode) |
| return; |
| - |
| - if (LocalFrame* frame = document().frame()) |
| - frame->eventHandler().setCapturingMouseEventsNode(nullptr); |
| m_inDragMode = false; |
| if (layoutObject()) |
| layoutObject()->setNeedsLayoutAndFullPaintInvalidation( |
| @@ -196,11 +191,37 @@ void SliderThumbElement::stopDragging() { |
| hostInput()->dispatchFormControlChangeEvent(); |
| } |
| +void SliderThumbElement::requestPointerCapture(int pointerId) { |
| + if (LocalFrame* frame = document().frame()) { |
| + frame->eventHandler().setPointerCapture(pointerId, this); |
| + m_requestedPointerIdToCapture = pointerId; |
| + } |
| +} |
| + |
| +void SliderThumbElement::releasePointerCapture() { |
| + if (LocalFrame* frame = document().frame()) { |
| + frame->eventHandler().releasePointerCapture(m_requestedPointerIdToCapture, |
| + this); |
| + } |
| +} |
| + |
| void SliderThumbElement::defaultEventHandler(Event* event) { |
| - if (!event->isMouseEvent()) { |
| + if (!event->isPointerEvent()) { |
| HTMLDivElement::defaultEventHandler(event); |
| return; |
| } |
| + PointerEvent* pointerEvent = toPointerEvent(event); |
| + |
| + if (pointerEvent->type() == EventTypeNames::gotpointercapture && |
| + m_requestedPointerIdToCapture == pointerEvent->pointerId()) { |
| + startDragging(); |
| + return; |
| + } |
| + |
| + if (pointerEvent->type() == EventTypeNames::lostpointercapture) { |
| + stopDragging(); |
| + return; |
| + } |
| // FIXME: Should handle this readonly/disabled check in more general way. |
| // Missing this kind of check is likely to occur elsewhere if adding it in |
| @@ -212,25 +233,31 @@ void SliderThumbElement::defaultEventHandler(Event* event) { |
| return; |
| } |
| - MouseEvent* mouseEvent = toMouseEvent(event); |
| - bool isLeftButton = mouseEvent->button() == |
| + bool isLeftButton = pointerEvent->button() == |
| static_cast<short>(WebPointerProperties::Button::Left); |
| + bool isLeftButtonActive = |
| + pointerEvent->buttons() & |
| + static_cast<short>(WebPointerProperties::Button::Left); |
| const AtomicString& eventType = event->type(); |
| // We intentionally do not call event->setDefaultHandled() here because |
| // MediaControlTimelineElement::defaultEventHandler() wants to handle these |
| // mouse events. |
| - if (eventType == EventTypeNames::mousedown && isLeftButton) { |
| - startDragging(); |
| + if ((eventType == EventTypeNames::pointerdown || |
| + eventType == EventTypeNames::pointermove) && |
| + isLeftButton && isLeftButtonActive) { |
| + requestPointerCapture(pointerEvent->pointerId()); |
|
mustaq
2017/03/15 18:15:41
So a chorded L-down would start dragging here, rig
|
| return; |
| } |
| - if (eventType == EventTypeNames::mouseup && isLeftButton) { |
| - stopDragging(); |
| + if ((eventType == EventTypeNames::pointerup || |
|
mustaq
2017/03/15 18:15:41
May be just |if (!isLeftButtonActive) {} |?
|
| + eventType == EventTypeNames::pointermove) && |
| + isLeftButton && !isLeftButtonActive) { |
| + releasePointerCapture(); |
| return; |
| } |
| - if (eventType == EventTypeNames::mousemove) { |
| + if (eventType == EventTypeNames::pointermove) { |
| if (m_inDragMode) |
| - setPositionFromPoint(LayoutPoint(mouseEvent->absoluteLocation())); |
| + setPositionFromPoint(LayoutPoint(pointerEvent->absoluteLocation())); |
| return; |
| } |