MouseEvent* MouseEvent::create(const AtomicString& eventType, AbstractView* view, Event* underlyingEvent, SimulatedClickCreationScope creationScope) { PlatformEvent::Modifiers modifiers = PlatformEvent::NoModifiers; if (UIEventWithKeyState* keyStateEvent = findEventWithKeyState(underlyingEvent)) { modifiers = keyStateEvent->modifiers(); } PlatformMouseEvent::SyntheticEventType syntheticType = PlatformMouseEvent::Positionless; int screenX = 0; int screenY = 0; if (underlyingEvent && underlyingEvent->isMouseEvent()) { syntheticType = PlatformMouseEvent::RealOrIndistinguishable; MouseEvent* mouseEvent = toMouseEvent(underlyingEvent); screenX = mouseEvent->screenLocation().x(); screenY = mouseEvent->screenLocation().y(); } double timestamp = underlyingEvent ? underlyingEvent->platformTimeStamp() : monotonicallyIncreasingTime(); MouseEvent* createdEvent = MouseEvent::create(eventType, true, true, view, 0, screenX, screenY, 0, 0, 0, 0, modifiers, 0, 0, nullptr, timestamp, syntheticType, String()); createdEvent->setTrusted(creationScope == SimulatedClickCreationScope::FromUserAgent); createdEvent->setUnderlyingEvent(underlyingEvent); if (syntheticType == PlatformMouseEvent::RealOrIndistinguishable) { MouseEvent* mouseEvent = toMouseEvent(createdEvent->underlyingEvent()); createdEvent->initCoordinates(mouseEvent->clientLocation()); } return createdEvent; }
static void appendServerMapMousePosition(StringBuilder& url, Event* event) { if (!event->isMouseEvent()) return; ASSERT(event->target()); Node* target = event->target()->toNode(); ASSERT(target); if (!isHTMLImageElement(target)) return; HTMLImageElement* imageElement = toHTMLImageElement(target); if (!imageElement || !imageElement->isServerMap()) return; if (!imageElement->renderer() || !imageElement->renderer()->isRenderImage()) return; RenderImage* renderer = toRenderImage(imageElement->renderer()); // FIXME: This should probably pass true for useTransforms. FloatPoint absolutePosition = renderer->absoluteToLocal(FloatPoint(toMouseEvent(event)->pageX(), toMouseEvent(event)->pageY())); int x = absolutePosition.x(); int y = absolutePosition.y(); url.append('?'); url.appendNumber(x); url.append(','); url.appendNumber(y); }
void HTMLAnchorElement::defaultEventHandler(Event* event) { if (isLink()) { if (focused() && isEnterKeyKeydownEvent(event) && treatLinkAsLiveForEventType(NonMouseEvent)) { event->setDefaultHandled(); dispatchSimulatedClick(event); return; } if (isLinkClick(event) && treatLinkAsLiveForEventType(eventType(event))) { handleClick(event); return; } if (hasEditableStyle()) { // This keeps track of the editable block that the selection was in (if it was in one) just before the link was clicked // for the LiveWhenNotFocused editable link behavior if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && toMouseEvent(event)->button() != RightButton && document().frame()) { setRootEditableElementForSelectionOnMouseDown(document().frame()->selection().selection().rootEditableElement()); m_wasShiftKeyDownOnMouseDown = toMouseEvent(event)->shiftKey(); } else if (event->type() == eventNames().mouseoverEvent) { // These are cleared on mouseover and not mouseout because their values are needed for drag events, // but drag events happen after mouse out events. clearRootEditableElementForSelectionOnMouseDown(); m_wasShiftKeyDownOnMouseDown = false; } } } HTMLElement::defaultEventHandler(event); }
bool MediaControls::containsRelatedTarget(Event* event) { if (!event->isMouseEvent()) return false; EventTarget* relatedTarget = toMouseEvent(event)->relatedTarget(); if (!relatedTarget) return false; return contains(relatedTarget->toNode()); }
void MouseOrFocusEventContext::handleLocalEvents(Event* event) const { ASSERT(event->isMouseEvent() || event->isFocusEvent()); if (m_relatedTarget.get() && event->isMouseEvent()) toMouseEvent(event)->setRelatedTarget(m_relatedTarget.get()); else if (m_relatedTarget.get() && event->isFocusEvent()) toFocusEvent(event)->setRelatedTarget(m_relatedTarget.get()); EventContext::handleLocalEvents(event); }
void MouseOrFocusEventContext::handleLocalEvents(Event& event) const { ASSERT(event.isMouseEvent() || event.isFocusEvent()); if (m_relatedTarget) { if (event.isMouseEvent()) toMouseEvent(event).setRelatedTarget(m_relatedTarget.get()); else if (event.isFocusEvent()) toFocusEvent(event).setRelatedTarget(m_relatedTarget.get()); } EventContext::handleLocalEvents(event); }
void EventContext::handleLocalEvents(Event* event) const { if (m_touchEventContext) { m_touchEventContext->handleLocalEvents(event); } else if (m_relatedTarget && event->isMouseEvent()) { toMouseEvent(event)->setRelatedTarget(m_relatedTarget.get()); } else if (m_relatedTarget && event->isFocusEvent()) { toFocusEvent(event)->setRelatedTarget(m_relatedTarget.get()); } event->setTarget(m_target); event->setCurrentTarget(m_currentTarget.get()); m_node->handleLocalEvents(event); }
void InspectorFrontendHost::dispatchEventAsContextMenuEvent(Event* event) { #if USE(ACCESSIBILITY_CONTEXT_MENUS) if (!event || !event->isMouseEvent()) return; Frame* frame = event->target()->toNode()->document().frame(); MouseEvent* mouseEvent = toMouseEvent(event); IntPoint mousePoint = IntPoint(mouseEvent->clientX(), mouseEvent->clientY()); m_frontendPage->contextMenuController().showContextMenuAt(frame, mousePoint); #else UNUSED_PARAM(event); #endif }
SimulatedMouseEvent::SimulatedMouseEvent(const AtomicString& eventType, PassRefPtrWillBeRawPtr<AbstractView> view, PassRefPtrWillBeRawPtr<Event> underlyingEvent) : MouseEvent(eventType, true, true, view, 0, 0, 0, 0, 0, 0, 0, false, false, false, false, 0, 0, nullptr, nullptr, true, PlatformMouseEvent::RealOrIndistinguishable) { if (UIEventWithKeyState* keyStateEvent = findEventWithKeyState(underlyingEvent.get())) { m_ctrlKey = keyStateEvent->ctrlKey(); m_altKey = keyStateEvent->altKey(); m_shiftKey = keyStateEvent->shiftKey(); m_metaKey = keyStateEvent->metaKey(); } setUnderlyingEvent(underlyingEvent); if (this->underlyingEvent() && this->underlyingEvent()->isMouseEvent()) { MouseEvent* mouseEvent = toMouseEvent(this->underlyingEvent()); m_screenLocation = mouseEvent->screenLocation(); initCoordinates(mouseEvent->clientLocation()); } }
inline void EventDispatcher::dispatchEventPostProcess(void* preDispatchEventHandlerResult) { m_event->setTarget(EventPath::eventTargetRespectingTargetRules(*m_node)); m_event->setCurrentTarget(nullptr); m_event->setEventPhase(0); // Pass the data from the preDispatchEventHandler to the postDispatchEventHandler. m_node->postDispatchEventHandler(m_event.get(), preDispatchEventHandlerResult); bool isClick = m_event->isMouseEvent() && toMouseEvent(*m_event).type() == EventTypeNames::click; if (isClick) { // Fire an accessibility event indicating a node was clicked on. This is safe if m_event->target()->toNode() returns null. if (AXObjectCache* cache = m_node->document().existingAXObjectCache()) cache->handleClicked(m_event->target()->toNode()); } // The DOM Events spec says that events dispatched by JS (other than "click") // should not have their default handlers invoked. bool isTrustedOrClick = !RuntimeEnabledFeatures::trustedEventsDefaultActionEnabled() || m_event->isTrusted() || isClick; // Call default event handlers. While the DOM does have a concept of preventing // default handling, the detail of which handlers are called is an internal // implementation detail and not part of the DOM. if (!m_event->defaultPrevented() && !m_event->defaultHandled() && isTrustedOrClick) { // Non-bubbling events call only one default event handler, the one for the target. m_node->willCallDefaultEventHandler(*m_event); m_node->defaultEventHandler(m_event.get()); ASSERT(!m_event->defaultPrevented()); if (m_event->defaultHandled()) return; // For bubbling events, call default event handlers on the same targets in the // same order as the bubbling phase. if (m_event->bubbles()) { size_t size = m_event->eventPath().size(); for (size_t i = 1; i < size; ++i) { m_event->eventPath()[i].node()->willCallDefaultEventHandler(*m_event); m_event->eventPath()[i].node()->defaultEventHandler(m_event.get()); ASSERT(!m_event->defaultPrevented()); if (m_event->defaultHandled()) return; } } } }
void HTMLLabelElement::defaultEventHandler(Event* evt) { static bool processingClick = false; if (evt->type() == EventTypeNames::click && !processingClick) { // If the click is not simulated and the text of label element is // selected, do not pass the event to control element. // Note: a click event may be not a mouse event if created by // document.createEvent(). if (evt->isMouseEvent() && !toMouseEvent(evt)->isSimulated()) { if (LocalFrame* frame = document().frame()) { if (frame->selection().selection().isRange()) return; } } RefPtrWillBeRawPtr<HTMLElement> element = control(); // If we can't find a control or if the control received the click // event, then there's no need for us to do anything. if (!element || (evt->target() && element->containsIncludingShadowDOM(evt->target()->toNode()))) return; if (evt->target() && isInInteractiveContent(evt->target()->toNode())) return; processingClick = true; document().updateLayoutIgnorePendingStylesheets(); if (element->isMouseFocusable()) element->focus(true, FocusTypeMouse); // Click the corresponding control. element->dispatchSimulatedClick(evt); processingClick = false; evt->setDefaultHandled(); } HTMLElement::defaultEventHandler(evt); }
void MediaControls::defaultEventHandler(Event* event) { HTMLDivElement::defaultEventHandler(event); // Add IgnoreControlsHover to m_hideTimerBehaviorFlags when we see a touch event, // to allow the hide-timer to do the right thing when it fires. // FIXME: Preferably we would only do this when we're actually handling the event // here ourselves. bool wasLastEventTouch = event->isTouchEvent() || event->isGestureEvent() || (event->isMouseEvent() && toMouseEvent(event)->fromTouch()); m_hideTimerBehaviorFlags |= wasLastEventTouch ? IgnoreControlsHover : IgnoreNone; if (event->type() == EventTypeNames::mouseover) { if (!containsRelatedTarget(event)) { m_isMouseOverControls = true; if (!mediaElement().togglePlayStateWillPlay()) { makeOpaque(); if (shouldHideMediaControls()) startHideMediaControlsTimer(); } } return; } if (event->type() == EventTypeNames::mouseout) { if (!containsRelatedTarget(event)) { m_isMouseOverControls = false; stopHideMediaControlsTimer(); } return; } if (event->type() == EventTypeNames::mousemove) { // When we get a mouse move, show the media controls, and start a timer // that will hide the media controls after a 3 seconds without a mouse move. makeOpaque(); refreshCastButtonVisibility(); if (shouldHideMediaControls(IgnoreVideoHover)) startHideMediaControlsTimer(); return; } }
PassOwnPtr<ContextMenu> ContextMenuController::createContextMenu(Event* event) { ASSERT(event); if (!event->isMouseEvent()) return nullptr; MouseEvent* mouseEvent = toMouseEvent(event); HitTestResult result(mouseEvent->absoluteLocation()); if (Frame* frame = event->target()->toNode()->document().frame()) result = frame->eventHandler()->hitTestResultAtPoint(mouseEvent->absoluteLocation(), HitTestRequest::ReadOnly | HitTestRequest::Active | HitTestRequest::DisallowShadowContent); if (!result.innerNonSharedNode()) return nullptr; m_hitTestResult = result; return adoptPtr(new ContextMenu); }
void SliderThumbElement::defaultEventHandler(Event* event) { if (!event->isMouseEvent()) { HTMLDivElement::defaultEventHandler(event); 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 // each shadow element. HTMLInputElement* input = hostInput(); if (!input || input->isDisabledOrReadOnly()) { stopDragging(); HTMLDivElement::defaultEventHandler(event); return; } MouseEvent* mouseEvent = toMouseEvent(event); bool isLeftButton = mouseEvent->button() == 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(); return; } if (eventType == EventTypeNames::mouseup && isLeftButton) { stopDragging(); return; } if (eventType == EventTypeNames::mousemove) { if (m_inDragMode) setPositionFromPoint(LayoutPoint(mouseEvent->absoluteLocation())); return; } HTMLDivElement::defaultEventHandler(event); }
HTMLAnchorElement::EventType HTMLAnchorElement::eventType(Event* event) { if (!event->isMouseEvent()) return NonMouseEvent; return toMouseEvent(event)->shiftKey() ? MouseEventWithShiftKey : MouseEventWithoutShiftKey; }
void MediaControls::defaultEventHandler(Event* event) { HTMLDivElement::defaultEventHandler(event); // Add IgnoreControlsHover to m_hideTimerBehaviorFlags when we see a touch // event, to allow the hide-timer to do the right thing when it fires. // FIXME: Preferably we would only do this when we're actually handling the // event here ourselves. bool isTouchEvent = event->isTouchEvent() || event->isGestureEvent() || (event->isMouseEvent() && toMouseEvent(event)->fromTouch()); m_hideTimerBehaviorFlags |= isTouchEvent ? IgnoreControlsHover : IgnoreNone; // Touch events are treated differently to avoid fake mouse events to trigger // random behavior. The expect behaviour for touch is that a tap will show the // controls and they will hide when the timer to hide fires. if (isTouchEvent) { if (event->type() != EventTypeNames::gesturetap) return; if (!containsRelatedTarget(event)) { if (!mediaElement().paused()) { if (!isVisible()) { makeOpaque(); // When the panel switches from invisible to visible, we need to mark // the event handled to avoid buttons below the tap to be activated. event->setDefaultHandled(); } if (shouldHideMediaControls(IgnoreWaitForTimer)) { m_keepShowingUntilTimerFires = true; startHideMediaControlsTimer(); } } } return; } if (event->type() == EventTypeNames::mouseover) { if (!containsRelatedTarget(event)) { m_isMouseOverControls = true; if (!mediaElement().paused()) { makeOpaque(); if (shouldHideMediaControls()) startHideMediaControlsTimer(); } } return; } if (event->type() == EventTypeNames::mouseout) { if (!containsRelatedTarget(event)) { m_isMouseOverControls = false; stopHideMediaControlsTimer(); } return; } if (event->type() == EventTypeNames::mousemove) { // When we get a mouse move, show the media controls, and start a timer // that will hide the media controls after a 3 seconds without a mouse move. makeOpaque(); refreshCastButtonVisibility(); if (shouldHideMediaControls(IgnoreVideoHover)) startHideMediaControlsTimer(); return; } }
bool isLinkClick(Event* event) { return event->type() == eventNames().clickEvent && (!event->isMouseEvent() || toMouseEvent(event)->button() != RightButton); }
MouseEvent* MouseEventDispatchMediator::event() const { return toMouseEvent(EventDispatchMediator::event()); }
static bool isLinkClick(Event* event) { return event->type() == EventTypeNames::click && (!event->isMouseEvent() || toMouseEvent(event)->button() != RightButton); }