Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "sky/engine/config.h" | |
| 6 #include "sky/engine/core/frame/NewEventHandler.h" | |
| 7 | |
| 8 #include "sky/engine/core/dom/Document.h" | |
| 9 #include "sky/engine/core/dom/NodeRenderingTraversal.h" | |
| 10 #include "sky/engine/core/dom/TouchList.h" | |
| 11 #include "sky/engine/core/editing/Editor.h" | |
| 12 #include "sky/engine/core/editing/FrameSelection.h" | |
| 13 #include "sky/engine/core/editing/htmlediting.h" | |
| 14 #include "sky/engine/core/events/PointerEvent.h" | |
| 15 #include "sky/engine/core/frame/LocalFrame.h" | |
| 16 #include "sky/engine/core/frame/FrameView.h" | |
| 17 #include "sky/engine/core/page/EventWithHitTestResults.h" | |
| 18 #include "sky/engine/core/rendering/RenderObject.h" | |
| 19 #include "sky/engine/core/rendering/RenderView.h" | |
| 20 #include "sky/engine/platform/geometry/FloatPoint.h" | |
| 21 #include "sky/engine/public/platform/WebInputEvent.h" | |
| 22 | |
| 23 namespace blink { | |
| 24 | |
| 25 static VisiblePosition visiblePositionForHitTestResult(const HitTestResult& hitT estResult) | |
| 26 { | |
| 27 Node* innerNode = hitTestResult.innerNode(); | |
| 28 VisiblePosition position(innerNode->renderer()->positionForPoint(hitTestResu lt.localPoint())); | |
| 29 if (!position.isNull()) | |
| 30 return position; | |
| 31 return VisiblePosition(firstPositionInOrBeforeNode(innerNode), DOWNSTREAM); | |
| 32 } | |
| 33 | |
| 34 static LayoutPoint positionForEvent(const WebPointerEvent& event) | |
| 35 { | |
| 36 return roundedLayoutPoint(FloatPoint(event.x, event.y)); | |
| 37 } | |
| 38 | |
| 39 NewEventHandler::NewEventHandler(LocalFrame* frame) | |
| 40 : m_frame(frame) | |
| 41 { | |
| 42 } | |
| 43 | |
| 44 NewEventHandler::~NewEventHandler() | |
| 45 { | |
| 46 } | |
| 47 | |
| 48 Node* NewEventHandler::targetForHitTestResult(const HitTestResult& hitTestResult ) | |
|
esprehn
2015/01/20 18:14:33
This can really be far more specific, we can fix i
abarth-chromium
2015/01/20 18:26:54
You're saying we can change the return type to Con
esprehn
2015/01/21 02:47:51
Yes.
| |
| 49 { | |
| 50 Node* node = hitTestResult.innerNode(); | |
| 51 if (!node) | |
| 52 return m_frame->document(); | |
| 53 if (node->isTextNode()) | |
| 54 return NodeRenderingTraversal::parent(node); | |
| 55 return node; | |
| 56 } | |
| 57 | |
| 58 HitTestResult NewEventHandler::performHitTest(const LayoutPoint& point) | |
| 59 { | |
| 60 HitTestResult result(point); | |
| 61 if (!m_frame->contentRenderer() || (m_frame->view() && !m_frame->view()->vis ibleContentRect().contains(roundedIntPoint(point)))) | |
|
esprehn
2015/01/20 18:14:33
view() and RenderView (contentRenderer) should liv
abarth-chromium
2015/01/20 18:26:54
Ok. I cargo culted this from the old code. Will
abarth-chromium
2015/01/20 21:37:55
Done.
| |
| 62 return result; | |
| 63 m_frame->contentRenderer()->hitTest(HitTestRequest(HitTestRequest::ReadOnly) , result); | |
|
esprehn
2015/01/20 18:14:33
Why doesn't hitTest() should do the above contains
abarth-chromium
2015/01/20 18:26:54
It looks like it doesn't do this because it's not
esprehn
2015/01/21 02:47:51
RenderView::hitTest is special, it's not a virtual
abarth-chromium
2015/01/21 07:03:26
Ah! Will do.
| |
| 64 return result; | |
| 65 } | |
| 66 | |
| 67 bool NewEventHandler::dispatchPointerEvent(Node* target, const WebPointerEvent& event) | |
| 68 { | |
| 69 RefPtr<PointerEvent> pointerEvent = PointerEvent::create(event); | |
| 70 // TODO(abarth): Keep track of how many pointers are targeting the same node | |
| 71 // and only mark the first one as primary. | |
| 72 pointerEvent->setPrimary(true); | |
| 73 return target->dispatchEvent(pointerEvent.release()); | |
| 74 } | |
| 75 | |
| 76 bool NewEventHandler::dispatchClickEvent(Node* capturingTarget, const WebPointer Event& event) | |
| 77 { | |
| 78 ASSERT(event.type == WebInputEvent::PointerUp); | |
| 79 HitTestResult hitTestResult = performHitTest(positionForEvent(event)); | |
| 80 Node* releaseTarget = targetForHitTestResult(hitTestResult); | |
| 81 Node* clickTarget = NodeRenderingTraversal::commonAncestor(*releaseTarget, * capturingTarget); | |
| 82 if (!clickTarget) | |
| 83 return true; | |
| 84 // TODO(abarth): Make a proper gesture event that includes information from the event. | |
| 85 return clickTarget->dispatchEvent(Event::createCancelableBubble(EventTypeNam es::click)); | |
| 86 } | |
| 87 | |
| 88 void NewEventHandler::updateSelectionForPointerDown(const HitTestResult& hitTest Result, const WebPointerEvent& event) | |
| 89 { | |
| 90 Node* innerNode = hitTestResult.innerNode(); | |
| 91 if (!innerNode->renderer()) | |
| 92 return; | |
| 93 if (Position::nodeIsUserSelectNone(innerNode)) | |
| 94 return; | |
| 95 if (!innerNode->dispatchEvent(Event::createCancelableBubble(EventTypeNames:: selectstart))) | |
| 96 return; | |
| 97 VisiblePosition position = visiblePositionForHitTestResult(hitTestResult); | |
| 98 m_frame->selection().setNonDirectionalSelectionIfNeeded(VisibleSelection(pos ition), CharacterGranularity); | |
| 99 } | |
| 100 | |
| 101 bool NewEventHandler::handlePointerEvent(const WebPointerEvent& event) | |
| 102 { | |
| 103 if (event.type == WebInputEvent::PointerDown) | |
| 104 return handlePointerDownEvent(event); | |
| 105 if (event.type == WebInputEvent::PointerUp) | |
| 106 return handlePointerUpEvent(event); | |
| 107 if (event.type == WebInputEvent::PointerMove) | |
|
esprehn
2015/01/20 18:14:32
switch() then the compiler will shout if you miss
abarth-chromium
2015/01/20 18:26:54
Here |type| comes from the base class WebInputEven
esprehn
2015/01/21 02:47:51
There's no default cases in this function though,
abarth-chromium
2015/01/21 07:03:26
I can do that, but if we don't use |default| the s
| |
| 108 return handlePointerMoveEvent(event); | |
| 109 ASSERT(event.type == WebInputEvent::PointerCancel); | |
| 110 return handlePointerCancelEvent(event); | |
| 111 } | |
| 112 | |
| 113 bool NewEventHandler::handlePointerDownEvent(const WebPointerEvent& event) | |
| 114 { | |
| 115 ASSERT(!m_targetForPointer.contains(event.pointer)); | |
| 116 HitTestResult hitTestResult = performHitTest(positionForEvent(event)); | |
| 117 RefPtr<Node> target = targetForHitTestResult(hitTestResult); | |
| 118 m_targetForPointer.set(event.pointer, target); | |
| 119 bool eventSwallowed = !dispatchPointerEvent(target.get(), event); | |
| 120 // TODO(abarth): Set the target for the pointer to something determined when | |
| 121 // dispatching the event. | |
| 122 updateSelectionForPointerDown(hitTestResult, event); | |
| 123 return eventSwallowed; | |
| 124 } | |
| 125 | |
| 126 bool NewEventHandler::handlePointerUpEvent(const WebPointerEvent& event) | |
| 127 { | |
| 128 RefPtr<Node> target = m_targetForPointer.take(event.pointer); | |
| 129 if (!target) | |
| 130 return false; | |
| 131 bool eventSwallowed = !dispatchPointerEvent(target.get(), event); | |
| 132 // When the user releases the primary pointer, we need to dispatch a tap | |
| 133 // event to the common ancestor for where the pointer went down and where | |
| 134 // it came up. | |
| 135 eventSwallowed |= !dispatchClickEvent(target.get(), event); | |
|
esprehn
2015/01/20 18:14:33
I find |= really hard to catch when reading the co
abarth-chromium
2015/01/20 18:26:54
Sure!
esprehn
2015/01/21 02:47:51
Follow up cl.
| |
| 136 return eventSwallowed; | |
| 137 } | |
| 138 | |
| 139 bool NewEventHandler::handlePointerMoveEvent(const WebPointerEvent& event) | |
| 140 { | |
| 141 RefPtr<Node> target = m_targetForPointer.get(event.pointer); | |
| 142 return target && dispatchPointerEvent(target.get(), event); | |
| 143 } | |
| 144 | |
| 145 bool NewEventHandler::handlePointerCancelEvent(const WebPointerEvent& event) | |
| 146 { | |
| 147 RefPtr<Node> target = m_targetForPointer.take(event.pointer); | |
| 148 return target && dispatchPointerEvent(target.get(), event); | |
| 149 } | |
| 150 | |
| 151 } | |
| OLD | NEW |