WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, const MouseEvent& event) { if (event.type() == eventNames().mousemoveEvent) type = WebInputEvent::MouseMove; else if (event.type() == eventNames().mouseoutEvent) type = WebInputEvent::MouseLeave; else if (event.type() == eventNames().mouseoverEvent) type = WebInputEvent::MouseEnter; else if (event.type() == eventNames().mousedownEvent) type = WebInputEvent::MouseDown; else if (event.type() == eventNames().mouseupEvent) type = WebInputEvent::MouseUp; else if (event.type() == eventNames().contextmenuEvent) type = WebInputEvent::ContextMenu; else return; // Skip all other mouse events. timeStampSeconds = event.timeStamp() / millisPerSecond; switch (event.button()) { case LeftButton: button = WebMouseEvent::ButtonLeft; break; case MiddleButton: button = WebMouseEvent::ButtonMiddle; break; case RightButton: button = WebMouseEvent::ButtonRight; break; } modifiers = getWebInputModifiers(event); if (event.buttonDown()) { switch (event.button()) { case LeftButton: modifiers |= WebInputEvent::LeftButtonDown; break; case MiddleButton: modifiers |= WebInputEvent::MiddleButtonDown; break; case RightButton: modifiers |= WebInputEvent::RightButtonDown; break; } } ScrollView* view = widget->parent(); IntPoint p = view->contentsToWindow( IntPoint(event.absoluteLocation().x(), event.absoluteLocation().y())); globalX = event.screenX(); globalY = event.screenY(); windowX = p.x(); windowY = p.y(); x = event.absoluteLocation().x() - widget->location().x(); y = event.absoluteLocation().y() - widget->location().y(); #if ENABLE(POINTER_LOCK) movementX = event.webkitMovementX(); movementY = event.webkitMovementY(); #endif clickCount = event.detail(); }
ContextMenu* ContextMenuController::createContextMenu(Event* event) { if (!event->isMouseEvent()) return 0; MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); HitTestResult result(mouseEvent->absoluteLocation()); if (Frame* frame = event->target()->toNode()->document()->frame()) result = frame->eventHandler()->hitTestResultAtPoint(mouseEvent->absoluteLocation(), false); if (!result.innerNonSharedNode()) return 0; return new ContextMenu(result); }
void SpinButtonElement::defaultEventHandler(Event* event) { if (!event->isMouseEvent()) { if (!event->defaultHandled()) HTMLDivElement::defaultEventHandler(event); return; } RenderBox* box = renderBox(); if (!box) { if (!event->defaultHandled()) HTMLDivElement::defaultEventHandler(event); return; } RefPtr<HTMLInputElement> input(static_cast<HTMLInputElement*>(shadowAncestorNode())); if (input->disabled() || input->isReadOnlyFormControl()) { if (!event->defaultHandled()) HTMLDivElement::defaultEventHandler(event); return; } MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); IntPoint local = roundedIntPoint(box->absoluteToLocal(mouseEvent->absoluteLocation(), false, true)); if (mouseEvent->type() == eventNames().mousedownEvent && mouseEvent->button() == LeftButton) { if (box->borderBoxRect().contains(local)) { // The following functions of HTMLInputElement may run JavaScript // code which detaches this shadow node. We need to take a reference // and check renderer() after such function calls. RefPtr<Node> protector(this); input->focus(); input->select(); if (renderer()) { input->stepUpFromRenderer(m_upDownState == Up ? 1 : -1); if (renderer()) startRepeatingTimer(); } event->setDefaultHandled(); } } else if (mouseEvent->type() == eventNames().mouseupEvent && mouseEvent->button() == LeftButton) stopRepeatingTimer(); else if (event->type() == eventNames().mousemoveEvent) { if (box->borderBoxRect().contains(local)) { if (!m_capturing) { if (Frame* frame = document()->frame()) { frame->eventHandler()->setCapturingMouseEventsNode(this); m_capturing = true; } } UpDownState oldUpDownState = m_upDownState; m_upDownState = local.y() < box->height() / 2 ? Up : Down; if (m_upDownState != oldUpDownState) renderer()->repaint(); } else releaseCapture(); } if (!event->defaultHandled()) HTMLDivElement::defaultEventHandler(event); }
PassOwnPtr<ContextMenu> ContextMenuController::createContextMenu(Event* event) { ASSERT(event); if (!event->isMouseEvent()) return nullptr; MouseEvent* mouseEvent = toMouseEvent(event); return createContextMenu(event->target()->toNode()->document().frame(), mouseEvent->absoluteLocation()); }
void SliderThumbElement::defaultEventHandler(Event* event) { if (!event->isMouseEvent()) { HTMLDivElement::defaultEventHandler(event); return; } MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); bool isLeftButton = mouseEvent->button() == LeftButton; const AtomicString& eventType = event->type(); if (eventType == eventNames().mousedownEvent && isLeftButton) { if (document()->frame() && renderer()) { RenderSlider* slider = toRenderSlider(renderer()->parent()); if (slider) { if (slider->mouseEventIsInThumb(mouseEvent)) { // We selected the thumb, we want the cursor to always stay at // the same position relative to the thumb. m_offsetToThumb = slider->mouseEventOffsetToThumb(mouseEvent); } else { // We are outside the thumb, move the thumb to the point were // we clicked. We'll be exactly at the center of the thumb. m_offsetToThumb.setX(0); m_offsetToThumb.setY(0); } m_inDragMode = true; document()->frame()->eventHandler()->setCapturingMouseEventsNode(m_shadowParent); event->setDefaultHandled(); return; } } } else if (eventType == eventNames().mouseupEvent && isLeftButton) { if (m_inDragMode) { if (Frame* frame = document()->frame()) frame->eventHandler()->setCapturingMouseEventsNode(0); m_inDragMode = false; event->setDefaultHandled(); return; } } else if (eventType == eventNames().mousemoveEvent) { if (m_inDragMode && renderer() && renderer()->parent()) { RenderSlider* slider = toRenderSlider(renderer()->parent()); if (slider) { FloatPoint curPoint = slider->absoluteToLocal(mouseEvent->absoluteLocation(), false, true); IntPoint eventOffset(curPoint.x() + m_offsetToThumb.x(), curPoint.y() + m_offsetToThumb.y()); slider->setValueForPosition(slider->positionForOffset(eventOffset)); event->setDefaultHandled(); return; } } } HTMLDivElement::defaultEventHandler(event); }
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); }
PassOwnPtr<ContextMenu> ContextMenuController::createContextMenu(Event* event) { ASSERT(event); if (!event->isMouseEvent()) return nullptr; MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); HitTestResult result(mouseEvent->absoluteLocation()); if (Frame* frame = event->target()->toNode()->document()->frame()) result = frame->eventHandler()->hitTestResultAtPoint(mouseEvent->absoluteLocation()); if (!result.innerNonSharedNode()) return nullptr; m_hitTestResult = result; return adoptPtr(new ContextMenu); }
void RenderSlider::forwardEvent(Event* event) { if (event->isMouseEvent()) { MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); if (event->type() == eventNames().mousedownEvent && mouseEvent->button() == LeftButton) { if (!mouseEventIsInThumb(mouseEvent)) { IntPoint eventOffset = roundedIntPoint(absoluteToLocal(mouseEvent->absoluteLocation(), false, true)); setValueForPosition(positionForOffset(eventOffset)); } } } m_thumb->defaultEventHandler(event); }
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); }
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->isReadOnlyFormControl() || !input->isEnabledFormControl()) { stopDragging(); HTMLDivElement::defaultEventHandler(event); return; } MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); bool isLeftButton = mouseEvent->button() == LeftButton; const AtomicString& eventType = event->type(); // We intentionally do not call event->setDefaultHandled() here because // MediaControlTimelineElement::defaultEventHandler() wants to handle these // mouse events. if (eventType == eventNames().mousedownEvent && isLeftButton) { startDragging(); return; } else if (eventType == eventNames().mouseupEvent && isLeftButton) { stopDragging(); return; } else if (eventType == eventNames().mousemoveEvent) { if (m_inDragMode) setPositionFromPoint(mouseEvent->absoluteLocation()); return; } HTMLDivElement::defaultEventHandler(event); }
void SpinButtonElement::defaultEventHandler(Event* event) { if (!event->isMouseEvent()) { if (!event->defaultHandled()) HTMLDivElement::defaultEventHandler(event); return; } RenderBox* box = renderBox(); if (!box) { if (!event->defaultHandled()) HTMLDivElement::defaultEventHandler(event); return; } HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowAncestorNode()); if (input->disabled() || input->isReadOnlyFormControl()) { if (!event->defaultHandled()) HTMLDivElement::defaultEventHandler(event); return; } MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); IntPoint local = roundedIntPoint(box->absoluteToLocal(mouseEvent->absoluteLocation(), false, true)); if (mouseEvent->type() == eventNames().mousedownEvent && mouseEvent->button() == LeftButton) { if (box->borderBoxRect().contains(local)) { RefPtr<Node> protector(input); input->focus(); input->select(); input->stepUpFromRenderer(m_upDownState == Up ? 1 : -1); event->setDefaultHandled(); startRepeatingTimer(); } } else if (mouseEvent->type() == eventNames().mouseupEvent && mouseEvent->button() == LeftButton) stopRepeatingTimer(); else if (event->type() == eventNames().mousemoveEvent) { if (box->borderBoxRect().contains(local)) { if (!m_capturing) { if (Frame* frame = document()->frame()) { frame->eventHandler()->setCapturingMouseEventsNode(this); m_capturing = true; } } UpDownState oldUpDownState = m_upDownState; m_upDownState = local.y() < box->height() / 2 ? Up : Down; if (m_upDownState != oldUpDownState) renderer()->repaint(); } else { if (m_capturing) { stopRepeatingTimer(); if (Frame* frame = document()->frame()) { frame->eventHandler()->setCapturingMouseEventsNode(0); m_capturing = false; } } } } if (!event->defaultHandled()) HTMLDivElement::defaultEventHandler(event); }
void SelectElement::listBoxDefaultEventHandler(SelectElementData& data, Element* element, Event* event, HTMLFormElement* htmlForm) { const Vector<Element*>& listItems = data.listItems(element); if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) { element->focus(); // Convert to coords relative to the list box if needed. MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); IntPoint localOffset = roundedIntPoint(element->renderer()->absoluteToLocal(mouseEvent->absoluteLocation(), false, true)); int listIndex = static_cast<RenderListBox*>(element->renderer())->listIndexAtOffset(localOffset.x(), localOffset.y()); if (listIndex >= 0) { // Save the selection so it can be compared to the new selection when dispatching change events during mouseup, or after autoscroll finishes. saveLastSelection(data, element); data.setActiveSelectionState(true); bool multiSelectKeyPressed = false; #if PLATFORM(MAC) multiSelectKeyPressed = mouseEvent->metaKey(); #else multiSelectKeyPressed = mouseEvent->ctrlKey(); #endif bool shiftSelect = data.multiple() && mouseEvent->shiftKey(); bool multiSelect = data.multiple() && multiSelectKeyPressed && !mouseEvent->shiftKey(); Element* clickedElement = listItems[listIndex]; OptionElement* option = toOptionElement(clickedElement); if (option) { // Keep track of whether an active selection (like during drag selection), should select or deselect if (option->selected() && multiSelectKeyPressed) data.setActiveSelectionState(false); if (!data.activeSelectionState()) option->setSelectedState(false); } // If we're not in any special multiple selection mode, then deselect all other items, excluding the clicked option. // If no option was clicked, then this will deselect all items in the list. if (!shiftSelect && !multiSelect) deselectItems(data, element, clickedElement); // If the anchor hasn't been set, and we're doing a single selection or a shift selection, then initialize the anchor to the first selected index. if (data.activeSelectionAnchorIndex() < 0 && !multiSelect) setActiveSelectionAnchorIndex(data, element, selectedIndex(data, element)); // Set the selection state of the clicked option if (option && !clickedElement->disabled()) option->setSelectedState(true); // If there was no selectedIndex() for the previous initialization, or // If we're doing a single selection, or a multiple selection (using cmd or ctrl), then initialize the anchor index to the listIndex that just got clicked. if (listIndex >= 0 && (data.activeSelectionAnchorIndex() < 0 || !shiftSelect)) setActiveSelectionAnchorIndex(data, element, listIndex); setActiveSelectionEndIndex(data, listIndex); updateListBoxSelection(data, element, !multiSelect); if (Frame* frame = element->document()->frame()) frame->eventHandler()->setMouseDownMayStartAutoscroll(); event->setDefaultHandled(); } } else if (event->type() == eventNames().mouseupEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton && element->document()->frame()->eventHandler()->autoscrollRenderer() != element->renderer()) // This makes sure we fire dispatchFormControlChangeEvent for a single click. For drag selection, onChange will fire when the autoscroll timer stops. listBoxOnChange(data, element); else if (event->type() == eventNames().keydownEvent) { if (!event->isKeyboardEvent()) return; String keyIdentifier = static_cast<KeyboardEvent*>(event)->keyIdentifier(); int endIndex = 0; if (data.activeSelectionEndIndex() < 0) { // Initialize the end index if (keyIdentifier == "Down") endIndex = nextSelectableListIndex(data, element, lastSelectedListIndex(data, element)); else if (keyIdentifier == "Up") endIndex = previousSelectableListIndex(data, element, optionToListIndex(data, element, selectedIndex(data, element))); } else { // Set the end index based on the current end index if (keyIdentifier == "Down") endIndex = nextSelectableListIndex(data, element, data.activeSelectionEndIndex()); else if (keyIdentifier == "Up") endIndex = previousSelectableListIndex(data, element, data.activeSelectionEndIndex()); } if (keyIdentifier == "Down" || keyIdentifier == "Up") { // Save the selection so it can be compared to the new selection when dispatching change events immediately after making the new selection. saveLastSelection(data, element); ASSERT(endIndex >= 0 && (unsigned) endIndex < listItems.size()); setActiveSelectionEndIndex(data, endIndex); // If the anchor is unitialized, or if we're going to deselect all other options, then set the anchor index equal to the end index. bool deselectOthers = !data.multiple() || !static_cast<KeyboardEvent*>(event)->shiftKey(); if (data.activeSelectionAnchorIndex() < 0 || deselectOthers) { data.setActiveSelectionState(true); if (deselectOthers) deselectItems(data, element); setActiveSelectionAnchorIndex(data, element, data.activeSelectionEndIndex()); } static_cast<RenderListBox*>(element->renderer())->scrollToRevealElementAtListIndex(endIndex); updateListBoxSelection(data, element, deselectOthers); listBoxOnChange(data, element); event->setDefaultHandled(); } } else if (event->type() == eventNames().keypressEvent) { if (!event->isKeyboardEvent()) return; int keyCode = static_cast<KeyboardEvent*>(event)->keyCode(); if (keyCode == '\r') { if (htmlForm) htmlForm->submitClick(event); event->setDefaultHandled(); return; } } }
void SpinButtonElement::defaultEventHandler(Event* event) { if (!event->isMouseEvent()) { if (!event->defaultHandled()) HTMLDivElement::defaultEventHandler(event); return; } RenderBox* box = renderBox(); if (!box) { if (!event->defaultHandled()) HTMLDivElement::defaultEventHandler(event); return; } if (!shouldRespondToMouseEvents()) { if (!event->defaultHandled()) HTMLDivElement::defaultEventHandler(event); return; } MouseEvent* mouseEvent = toMouseEvent(event); IntPoint local = roundedIntPoint(box->absoluteToLocal(mouseEvent->absoluteLocation(), UseTransforms)); if (mouseEvent->type() == eventNames().mousedownEvent && mouseEvent->button() == LeftButton) { if (box->pixelSnappedBorderBoxRect().contains(local)) { // The following functions of HTMLInputElement may run JavaScript // code which detaches this shadow node. We need to take a reference // and check renderer() after such function calls. Ref<SpinButtonElement> protect(*this); if (m_spinButtonOwner) m_spinButtonOwner->focusAndSelectSpinButtonOwner(); if (renderer()) { if (m_upDownState != Indeterminate) { // A JavaScript event handler called in doStepAction() below // might change the element state and we might need to // cancel the repeating timer by the state change. If we // started the timer after doStepAction(), we would have no // chance to cancel the timer. startRepeatingTimer(); doStepAction(m_upDownState == Up ? 1 : -1); } } event->setDefaultHandled(); } } else if (mouseEvent->type() == eventNames().mouseupEvent && mouseEvent->button() == LeftButton) stopRepeatingTimer(); else if (event->type() == eventNames().mousemoveEvent) { if (box->pixelSnappedBorderBoxRect().contains(local)) { if (!m_capturing) { if (Frame* frame = document().frame()) { frame->eventHandler().setCapturingMouseEventsElement(this); m_capturing = true; if (Page* page = document().page()) page->chrome().registerPopupOpeningObserver(this); } } UpDownState oldUpDownState = m_upDownState; m_upDownState = local.y() < box->height() / 2 ? Up : Down; if (m_upDownState != oldUpDownState) renderer()->repaint(); } else { releaseCapture(); m_upDownState = Indeterminate; } } if (!event->defaultHandled()) HTMLDivElement::defaultEventHandler(event); }
bool RenderEmbeddedObject::isInUnavailablePluginIndicator(const MouseEvent& event) const { return isInUnavailablePluginIndicator(absoluteToLocal(event.absoluteLocation(), UseTransforms)); }
void MediaControls::forwardEvent(Event* event) { ASSERT(m_mediaElement->renderer()); if (event->isMouseEvent() && m_controlsShadowRoot) { MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); IntPoint point(mouseEvent->absoluteLocation()); bool defaultHandled = false; if (m_volumeSliderMuteButton && m_volumeSliderMuteButton->hitTest(point)) { m_volumeSliderMuteButton->defaultEventHandler(event); defaultHandled = event->defaultHandled(); } bool showVolumeSlider = false; if (!defaultHandled && m_muteButton && m_muteButton->hitTest(point)) { m_muteButton->defaultEventHandler(event); if (event->type() != eventNames().mouseoutEvent) showVolumeSlider = true; } if (m_volumeSliderContainer && m_volumeSliderContainer->hitTest(point)) showVolumeSlider = true; if (m_volumeSlider && m_volumeSlider->hitTest(point)) { m_volumeSlider->defaultEventHandler(event); showVolumeSlider = true; } updateVolumeSliderContainer(showVolumeSlider); if (m_playButton && m_playButton->hitTest(point)) m_playButton->defaultEventHandler(event); if (m_seekBackButton && m_seekBackButton->hitTest(point)) m_seekBackButton->defaultEventHandler(event); if (m_seekForwardButton && m_seekForwardButton->hitTest(point)) m_seekForwardButton->defaultEventHandler(event); if (m_rewindButton && m_rewindButton->hitTest(point)) m_rewindButton->defaultEventHandler(event); if (m_returnToRealtimeButton && m_returnToRealtimeButton->hitTest(point)) m_returnToRealtimeButton->defaultEventHandler(event); if (m_toggleClosedCaptionsButton && m_toggleClosedCaptionsButton->hitTest(point)) m_toggleClosedCaptionsButton->defaultEventHandler(event); if (m_timeline && m_timeline->hitTest(point)) m_timeline->defaultEventHandler(event); if (m_fullscreenButton && m_fullscreenButton->hitTest(point)) m_fullscreenButton->defaultEventHandler(event); if (event->type() == eventNames().mouseoverEvent) { m_mouseOver = true; updateControlVisibility(); } if (event->type() == eventNames().mouseoutEvent) { // When the scrollbar thumb captures mouse events, we should treat the mouse as still being over our renderer if the new target is a descendant Node* mouseOverNode = mouseEvent->relatedTarget() ? mouseEvent->relatedTarget()->toNode() : 0; RenderObject* mouseOverRenderer = mouseOverNode ? mouseOverNode->renderer() : 0; m_mouseOver = mouseOverRenderer && mouseOverRenderer->isDescendantOf(m_mediaElement->renderer()); updateControlVisibility(); } } }
WebMouseEventBuilder::WebMouseEventBuilder(const Widget* widget, const MouseEvent& event) { if (event.type() == eventNames().mousemoveEvent) type = WebInputEvent::MouseMove; else if (event.type() == eventNames().mouseoutEvent) type = WebInputEvent::MouseLeave; else if (event.type() == eventNames().mouseoverEvent) type = WebInputEvent::MouseEnter; else if (event.type() == eventNames().mousedownEvent) type = WebInputEvent::MouseDown; else if (event.type() == eventNames().mouseupEvent) type = WebInputEvent::MouseUp; else if (event.type() == eventNames().contextmenuEvent) type = WebInputEvent::ContextMenu; else return; // Skip all other mouse events. timeStampSeconds = event.timeStamp() / millisPerSecond; switch (event.button()) { case LeftButton: button = WebMouseEvent::ButtonLeft; break; case MiddleButton: button = WebMouseEvent::ButtonMiddle; break; case RightButton: button = WebMouseEvent::ButtonRight; break; } modifiers = getWebInputModifiers(event); if (event.buttonDown()) { switch (event.button()) { case LeftButton: modifiers |= WebInputEvent::LeftButtonDown; break; case MiddleButton: modifiers |= WebInputEvent::MiddleButtonDown; break; case RightButton: modifiers |= WebInputEvent::RightButtonDown; break; } } ScrollView* view = widget->parent(); IntPoint p = view->contentsToWindow( IntPoint(event.absoluteLocation().x(), event.absoluteLocation().y())); globalX = event.screenX(); globalY = event.screenY(); windowX = p.x(); windowY = p.y(); #if OS(ANDROID) // absoluteLocation is actually scaled if the widget is inside an Iframe. // Switch to return scaled offsets so that the behaviors are consistent. // TODO (qinmin): maybe we should return adsolute offset in DOM space? IntPoint origin = view->contentsToWindow(widget->location()); x = p.x() - origin.x(); y = p.y() - origin.y(); #else x = event.absoluteLocation().x() - widget->location().x(); y = event.absoluteLocation().y() - widget->location().y(); #endif clickCount = event.detail(); }
void SearchFieldCancelButtonElement::defaultEventHandler(Event* event) { // If the element is visible, on mouseup, clear the value, and set selection HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowAncestorNode()); if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) { if (renderer() && renderer()->visibleToHitTesting()) { if (Frame* frame = document()->frame()) { frame->eventHandler()->setCapturingMouseEventsNode(this); m_capturing = true; } } input->focus(); input->select(); event->setDefaultHandled(); } if (event->type() == eventNames().mouseupEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) { if (m_capturing && renderer() && renderer()->visibleToHitTesting()) { if (Frame* frame = document()->frame()) { frame->eventHandler()->setCapturingMouseEventsNode(0); m_capturing = false; } #if !PLATFORM(OLYMPIA) // FIXME: It's always false on OLYMPIA platform. This problem depends on RIM bug #1067. if (hovered()) { #else if (event->target() == this) { #endif RefPtr<HTMLInputElement> protector(input); String oldValue = input->value(); input->setValue(""); if (!oldValue.isEmpty()) { toRenderTextControl(input->renderer())->setChangedSinceLastChangeEvent(true); input->dispatchEvent(Event::create(eventNames().inputEvent, true, false)); } input->onSearch(); event->setDefaultHandled(); } } } if (!event->defaultHandled()) HTMLDivElement::defaultEventHandler(event); } // ---------------------------- inline SpinButtonElement::SpinButtonElement(HTMLElement* shadowParent) : TextControlInnerElement(shadowParent->document(), shadowParent) , m_capturing(false) , m_upDownState(Indeterminate) , m_pressStartingState(Indeterminate) , m_repeatingTimer(this, &SpinButtonElement::repeatingTimerFired) { } PassRefPtr<SpinButtonElement> SpinButtonElement::create(HTMLElement* shadowParent) { return adoptRef(new SpinButtonElement(shadowParent)); } void SpinButtonElement::defaultEventHandler(Event* event) { if (!event->isMouseEvent()) { if (!event->defaultHandled()) HTMLDivElement::defaultEventHandler(event); return; } RenderBox* box = renderBox(); if (!box) { if (!event->defaultHandled()) HTMLDivElement::defaultEventHandler(event); return; } HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowAncestorNode()); if (input->disabled() || input->isReadOnlyFormControl()) { if (!event->defaultHandled()) HTMLDivElement::defaultEventHandler(event); return; } MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); IntPoint local = roundedIntPoint(box->absoluteToLocal(mouseEvent->absoluteLocation(), false, true)); if (mouseEvent->type() == eventNames().mousedownEvent && mouseEvent->button() == LeftButton) { if (box->borderBoxRect().contains(local)) { RefPtr<Node> protector(input); input->focus(); input->select(); input->stepUpFromRenderer(m_upDownState == Up ? 1 : -1); event->setDefaultHandled(); startRepeatingTimer(); } } else if (mouseEvent->type() == eventNames().mouseupEvent && mouseEvent->button() == LeftButton) stopRepeatingTimer(); else if (event->type() == eventNames().mousemoveEvent) { if (box->borderBoxRect().contains(local)) { if (!m_capturing) { if (Frame* frame = document()->frame()) { frame->eventHandler()->setCapturingMouseEventsNode(this); m_capturing = true; } } UpDownState oldUpDownState = m_upDownState; m_upDownState = local.y() < box->height() / 2 ? Up : Down; if (m_upDownState != oldUpDownState) renderer()->repaint(); } else { if (m_capturing) { stopRepeatingTimer(); if (Frame* frame = document()->frame()) { frame->eventHandler()->setCapturingMouseEventsNode(0); m_capturing = false; } } } } if (!event->defaultHandled()) HTMLDivElement::defaultEventHandler(event); } void SpinButtonElement::startRepeatingTimer() { m_pressStartingState = m_upDownState; ScrollbarTheme* theme = ScrollbarTheme::nativeTheme(); m_repeatingTimer.start(theme->initialAutoscrollTimerDelay(), theme->autoscrollTimerDelay()); }
void SliderThumbElement::defaultEventHandler(Event* event) { if (!event->isMouseEvent() #if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) && !event->isTouchEvent() #endif ) { HTMLDivElement::defaultEventHandler(event); return; } #if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) bool isLeftButton = false; if (event->isMouseEvent()) { MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); isLeftButton = mouseEvent->button() == LeftButton; } #else MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); bool isLeftButton = mouseEvent->button() == LeftButton; #endif const AtomicString& eventType = event->type(); if (eventType == eventNames().mousedownEvent && isLeftButton #if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) || eventType == eventNames().touchstartEvent #endif ) { startDragging(); return; } else if (eventType == eventNames().mouseupEvent && isLeftButton #if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) || eventType == eventNames().touchendEvent || eventType == eventNames().touchcancelEvent #endif ) { stopDragging(); return; } else if (eventType == eventNames().mousemoveEvent #if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) || eventType == eventNames().touchmoveEvent #endif ) { if (m_inDragMode) #if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) { if (event->isMouseEvent()) { MouseEvent* mouseEvent = static_cast<MouseEvent*>(event); #endif setPositionFromPoint(mouseEvent->absoluteLocation()); #if PLATFORM(ANDROID) && ENABLE(TOUCH_EVENTS) } else if (event->isTouchEvent()) { TouchEvent* touchEvent = static_cast<TouchEvent*>(event); if (touchEvent->touches() && touchEvent->touches()->item(0)) { IntPoint curPoint; curPoint.setX(touchEvent->touches()->item(0)->pageX()); curPoint.setY(touchEvent->touches()->item(0)->pageY()); setPositionFromPoint(curPoint); // Tell the webview that webkit will handle the following move events event->setDefaultPrevented(true); } } } #endif return; } HTMLDivElement::defaultEventHandler(event); }