本文整理汇总了C++中EventTarget::toNode方法的典型用法代码示例。如果您正苦于以下问题:C++ EventTarget::toNode方法的具体用法?C++ EventTarget::toNode怎么用?C++ EventTarget::toNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventTarget
的用法示例。
在下文中一共展示了EventTarget::toNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: shouldStopAtShadowRoot
static inline bool shouldStopAtShadowRoot(Event& event, ShadowRoot& shadowRoot, EventTarget& target)
{
// WebKit never allowed selectstart event to cross the the shadow DOM boundary.
// Changing this breaks existing sites.
// See https://bugs.webkit.org/show_bug.cgi?id=52195 for details.
const AtomicString eventType = event.type();
return target.toNode() && target.toNode()->shadowHost() == shadowRoot.host()
&& event.scoped();
}
示例2: setRelatedTarget
void EventPath::setRelatedTarget(Node& origin, EventTarget& relatedTarget)
{
Node* relatedNode = relatedTarget.toNode();
if (!relatedNode)
return;
EventRelatedNodeResolver resolver(*relatedNode);
bool originIsRelatedTarget = &origin == relatedNode;
Node& rootNodeInOriginTreeScope = origin.treeScope().rootNode();
size_t eventPathSize = m_path.size();
size_t i = 0;
while (i < eventPathSize) {
Node* contextNode = m_path[i]->node();
Node* currentRelatedNode = resolver.moveToParentOrShadowHost(*contextNode);
if (!originIsRelatedTarget && m_path[i]->target() == currentRelatedNode)
break;
toMouseOrFocusEventContext(*m_path[i]).setRelatedTarget(currentRelatedNode);
i++;
if (originIsRelatedTarget && &rootNodeInOriginTreeScope == contextNode)
break;
}
m_path.shrink(i);
}
示例3: defaultEventHandler
void MediaControlVolumeSliderContainerElement::defaultEventHandler(Event* event)
{
if (!event->isMouseEvent() || event->type() != eventNames().mouseoutEvent)
return;
// Poor man's mouseleave event detection.
MouseEvent* mouseEvent = static_cast<MouseEvent*>(event);
EventTarget* relatedTarget = mouseEvent->relatedTarget();
if (!relatedTarget || !relatedTarget->toNode())
return;
if (this->containsIncludingShadowDOM(relatedTarget->toNode()))
return;
hide();
}
示例4: shouldEventCrossShadowBoundary
static inline bool shouldEventCrossShadowBoundary(Event& event, ShadowRoot& shadowRoot, EventTarget& target)
{
Node* targetNode = target.toNode();
#if ENABLE(FULLSCREEN_API) && ENABLE(VIDEO)
// Video-only full screen is a mode where we use the shadow DOM as an implementation
// detail that should not be detectable by the web content.
if (targetNode) {
if (Element* element = targetNode->document().webkitCurrentFullScreenElement()) {
// FIXME: We assume that if the full screen element is a media element that it's
// the video-only full screen. Both here and elsewhere. But that is probably wrong.
if (element->isMediaElement() && shadowRoot.hostElement() == element)
return false;
}
}
#endif
// WebKit never allowed selectstart event to cross the the shadow DOM boundary.
// Changing this breaks existing sites.
// See https://bugs.webkit.org/show_bug.cgi?id=52195 for details.
const AtomicString& eventType = event.type();
bool targetIsInShadowRoot = targetNode && targetNode->treeScope().rootNode() == &shadowRoot;
return !targetIsInShadowRoot
|| !(eventType == eventNames().abortEvent
|| eventType == eventNames().changeEvent
|| eventType == eventNames().errorEvent
|| eventType == eventNames().loadEvent
|| eventType == eventNames().resetEvent
|| eventType == eventNames().resizeEvent
|| eventType == eventNames().scrollEvent
|| eventType == eventNames().selectEvent
|| eventType == eventNames().selectstartEvent);
}
示例5: willDispatchEvent
void ReplayController::willDispatchEvent(const Event& event, Frame* frame)
{
EventTarget* target = event.target();
if (!target && !frame)
return;
Document* document = frame ? frame->document() : nullptr;
// Fetch the document from the event target, because the target could be detached.
if (Node* node = target->toNode())
document = node->inDocument() ? &node->document() : node->ownerDocument();
else if (DOMWindow* window = target->toDOMWindow())
document = window->document();
ASSERT(document);
InputCursor& cursor = document->inputCursor();
#if !LOG_DISABLED
bool eventIsUnrelated = !cursor.isCapturing() && !cursor.isReplaying();
logDispatchedDOMEvent(event, eventIsUnrelated);
#else
UNUSED_PARAM(cursor);
#endif
#if ENABLE_AGGRESSIVE_DETERMINISM_CHECKS
// To ensure deterministic JS execution, all DOM events must be dispatched deterministically.
// If these assertions fail, then this DOM event is being dispatched by a nondeterministic EventLoop
// cycle, and may cause program execution to diverge if any JS code runs because of the DOM event.
if (cursor.isCapturing() || cursor.isReplaying())
ASSERT(cursor.withinEventLoopInputExtent());
else if (cursor.isReplaying())
ASSERT(dispatcher().isDispatching());
#endif
}
示例6: containsRelatedTarget
bool MediaControls::containsRelatedTarget(Event* event) {
if (!event->isMouseEvent())
return false;
EventTarget* relatedTarget = toMouseEvent(event)->relatedTarget();
if (!relatedTarget)
return false;
return contains(relatedTarget->toNode());
}
示例7: containsRelatedTarget
bool MediaControls::containsRelatedTarget(Event* event)
{
if (!is<MouseEvent>(*event))
return false;
EventTarget* relatedTarget = downcast<MouseEvent>(*event).relatedTarget();
if (!relatedTarget)
return false;
return contains(relatedTarget->toNode());
}
示例8: toElement
Node* MouseEvent::toElement() const
{
// MSIE extension - "the object toward which the user is moving the mouse pointer"
if (type() == eventNames().mouseoutEvent || type() == eventNames().mouseleaveEvent) {
EventTarget* relatedTarget = this->relatedTarget();
return relatedTarget ? relatedTarget->toNode() : nullptr;
}
return target() ? target()->toNode() : nullptr;
}
示例9: fromElement
Node* MouseEvent::fromElement() const
{
// MSIE extension - "object from which activation or the mouse pointer is exiting during the event" (huh?)
if (type() != eventNames().mouseoutEvent && type() != eventNames().mouseleaveEvent) {
EventTarget* relatedTarget = this->relatedTarget();
return relatedTarget ? relatedTarget->toNode() : nullptr;
}
return target() ? target()->toNode() : nullptr;
}
示例10: setRelatedTarget
void EventPath::setRelatedTarget(EventTarget& relatedTarget)
{
Node* relatedNode = relatedTarget.toNode();
if (!relatedNode)
return;
EventRelatedNodeResolver resolver(*relatedNode);
size_t eventPathSize = m_path.size();
for (size_t i = 0; i < eventPathSize; i++)
toMouseOrFocusEventContext(*m_path[i]).setRelatedTarget(resolver.moveToParentOrShadowHost(*m_path[i]->node()));
}
示例11: shouldEventCrossShadowBoundary
static inline bool shouldEventCrossShadowBoundary(Event& event, ShadowRoot& shadowRoot, EventTarget& target)
{
Node* targetNode = target.toNode();
#if ENABLE(FULLSCREEN_API) && ENABLE(VIDEO)
// Video-only full screen is a mode where we use the shadow DOM as an implementation
// detail that should not be detectable by the web content.
if (targetNode) {
if (Element* element = targetNode->document().webkitCurrentFullScreenElement()) {
// FIXME: We assume that if the full screen element is a media element that it's
// the video-only full screen. Both here and elsewhere. But that is probably wrong.
if (element->isMediaElement() && shadowRoot.host() == element)
return false;
}
}
#endif
bool targetIsInShadowRoot = targetNode && &targetNode->treeScope().rootNode() == &shadowRoot;
return !targetIsInShadowRoot || !event.scoped();
}
示例12: setRelatedTarget
void EventPath::setRelatedTarget(Node& origin, EventTarget& relatedTarget)
{
UNUSED_PARAM(origin);
Node* relatedNode = relatedTarget.toNode();
if (!relatedNode || m_path.isEmpty())
return;
RelatedNodeRetargeter retargeter(*relatedNode, downcast<MouseOrFocusEventContext>(*m_path[0]).node()->treeScope());
bool originIsRelatedTarget = &origin == relatedNode;
// FIXME: We should add a new flag on Event instead.
bool shouldTrimEventPath = m_event.type() == eventNames().mouseoverEvent
|| m_event.type() == eventNames().mousemoveEvent
|| m_event.type() == eventNames().mouseoutEvent;
Node& rootNodeInOriginTreeScope = origin.treeScope().rootNode();
TreeScope* previousTreeScope = nullptr;
size_t originalEventPathSize = m_path.size();
for (unsigned contextIndex = 0; contextIndex < originalEventPathSize; contextIndex++) {
auto& context = downcast<MouseOrFocusEventContext>(*m_path[contextIndex]);
TreeScope& currentTreeScope = context.node()->treeScope();
if (UNLIKELY(previousTreeScope && ¤tTreeScope != previousTreeScope))
retargeter.moveToNewTreeScope(previousTreeScope, currentTreeScope);
Node* currentRelatedNode = retargeter.currentNode(currentTreeScope);
if (UNLIKELY(shouldTrimEventPath && !originIsRelatedTarget && context.target() == currentRelatedNode)) {
m_path.shrink(contextIndex);
break;
}
context.setRelatedTarget(currentRelatedNode);
if (UNLIKELY(shouldTrimEventPath && originIsRelatedTarget && context.node() == &rootNodeInOriginTreeScope)) {
m_path.shrink(contextIndex + 1);
break;
}
previousTreeScope = ¤tTreeScope;
}
}
示例13: logDispatchedDOMEvent
static void logDispatchedDOMEvent(const Event& event, bool eventIsUnrelated)
{
EventTarget* target = event.target();
if (!target)
return;
// A DOM event is unrelated if it is being dispatched to a document that is neither capturing nor replaying.
if (Node* node = target->toNode()) {
LOG(WebReplay, "%-20s --->%s DOM event: type=%s, target=%u/node[%p] %s\n", "ReplayEvents",
(eventIsUnrelated) ? "Unrelated" : "Dispatching",
event.type().string().utf8().data(),
frameIndexFromDocument((node->inDocument()) ? &node->document() : node->ownerDocument()),
node,
node->nodeName().utf8().data());
} else if (DOMWindow* window = target->toDOMWindow()) {
LOG(WebReplay, "%-20s --->%s DOM event: type=%s, target=%u/window[%p] %s\n", "ReplayEvents",
(eventIsUnrelated) ? "Unrelated" : "Dispatching",
event.type().string().utf8().data(),
frameIndexFromDocument(window->document()),
window,
window->location()->href().utf8().data());
}
}
示例14: setRelatedTarget
void EventPath::setRelatedTarget(Node& origin, EventTarget& relatedTarget)
{
Node* relatedNode = relatedTarget.toNode();
if (!relatedNode || m_path.isEmpty())
return;
RelatedNodeRetargeter retargeter(*relatedNode, *m_path[0]->node());
bool originIsRelatedTarget = &origin == relatedNode;
bool relatedTargetScoped = m_event.relatedTargetScoped();
Node& rootNodeInOriginTreeScope = origin.treeScope().rootNode();
TreeScope* previousTreeScope = nullptr;
size_t originalEventPathSize = m_path.size();
for (unsigned contextIndex = 0; contextIndex < originalEventPathSize; contextIndex++) {
auto& context = downcast<MouseOrFocusEventContext>(*m_path[contextIndex]);
Node& currentTarget = *context.node();
TreeScope& currentTreeScope = currentTarget.treeScope();
if (UNLIKELY(previousTreeScope && ¤tTreeScope != previousTreeScope))
retargeter.moveToNewTreeScope(previousTreeScope, currentTreeScope);
Node* currentRelatedNode = retargeter.currentNode(currentTarget);
if (UNLIKELY(relatedTargetScoped && !originIsRelatedTarget && context.target() == currentRelatedNode)) {
m_path.shrink(contextIndex);
break;
}
context.setRelatedTarget(currentRelatedNode);
if (UNLIKELY(relatedTargetScoped && originIsRelatedTarget && context.node() == &rootNodeInOriginTreeScope)) {
m_path.shrink(contextIndex + 1);
break;
}
previousTreeScope = ¤tTreeScope;
}
}
示例15: retargetTouch
void EventPath::retargetTouch(TouchEventContext::TouchListType touchListType, const Touch& touch)
{
EventTarget* eventTarget = touch.target();
if (!eventTarget)
return;
Node* targetNode = eventTarget->toNode();
if (!targetNode)
return;
RelatedNodeRetargeter retargeter(*targetNode, *m_path[0]->node());
TreeScope* previousTreeScope = nullptr;
for (auto& context : m_path) {
Node& currentTarget = *context->node();
TreeScope& currentTreeScope = currentTarget.treeScope();
if (UNLIKELY(previousTreeScope && ¤tTreeScope != previousTreeScope))
retargeter.moveToNewTreeScope(previousTreeScope, currentTreeScope);
Node* currentRelatedNode = retargeter.currentNode(currentTarget);
downcast<TouchEventContext>(*context).touchList(touchListType)->append(touch.cloneWithNewTarget(currentRelatedNode));
previousTreeScope = ¤tTreeScope;
}
}