| 1 | /* |
| 2 | * Copyright (C) 2013 Google Inc. All rights reserved. |
| 3 | * Copyright (C) 2013-2017 Apple Inc. All rights reserved. |
| 4 | * |
| 5 | * This library is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU Library General Public |
| 7 | * License as published by the Free Software Foundation; either |
| 8 | * version 2 of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This library is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * Library General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU Library General Public License |
| 16 | * along with this library; see the file COPYING.LIB. If not, write to |
| 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 18 | * Boston, MA 02110-1301, USA. |
| 19 | */ |
| 20 | |
| 21 | #pragma once |
| 22 | |
| 23 | #include "EventContext.h" |
| 24 | #include "PseudoElement.h" |
| 25 | #include "SVGElement.h" |
| 26 | #include "SVGUseElement.h" |
| 27 | #include <wtf/Forward.h> |
| 28 | #include <wtf/Vector.h> |
| 29 | |
| 30 | namespace WebCore { |
| 31 | |
| 32 | class EventPath { |
| 33 | public: |
| 34 | EventPath(Node& origin, Event&); |
| 35 | explicit EventPath(const Vector<EventTarget*>&); |
| 36 | explicit EventPath(const Vector<Element*>&); |
| 37 | |
| 38 | bool isEmpty() const { return m_path.isEmpty(); } |
| 39 | size_t size() const { return m_path.size(); } |
| 40 | const EventContext& contextAt(size_t i) const { return *m_path[i]; } |
| 41 | EventContext& contextAt(size_t i) { return *m_path[i]; } |
| 42 | |
| 43 | Vector<EventTarget*> computePathUnclosedToTarget(const EventTarget&) const; |
| 44 | |
| 45 | static Node* eventTargetRespectingTargetRules(Node&); |
| 46 | |
| 47 | private: |
| 48 | void buildPath(Node& origin, Event&); |
| 49 | void setRelatedTarget(Node& origin, EventTarget&); |
| 50 | |
| 51 | #if ENABLE(TOUCH_EVENTS) |
| 52 | void retargetTouch(TouchEventContext::TouchListType, const Touch&); |
| 53 | void retargetTouchList(TouchEventContext::TouchListType, const TouchList*); |
| 54 | void retargetTouchLists(const TouchEvent&); |
| 55 | #endif |
| 56 | |
| 57 | Vector<std::unique_ptr<EventContext>, 32> m_path; |
| 58 | }; |
| 59 | |
| 60 | inline Node* EventPath::eventTargetRespectingTargetRules(Node& referenceNode) |
| 61 | { |
| 62 | if (is<PseudoElement>(referenceNode)) |
| 63 | return downcast<PseudoElement>(referenceNode).hostElement(); |
| 64 | |
| 65 | // Events sent to elements inside an SVG use element's shadow tree go to the use element. |
| 66 | if (is<SVGElement>(referenceNode)) { |
| 67 | if (auto useElement = downcast<SVGElement>(referenceNode).correspondingUseElement()) |
| 68 | return useElement.get(); |
| 69 | } |
| 70 | |
| 71 | return &referenceNode; |
| 72 | } |
| 73 | |
| 74 | } // namespace WebCore |
| 75 | |