void RenderTextControlSingleLine::forwardEvent(Event* event) { RenderBox* innerTextRenderer = innerTextElement()->renderBox(); if (event->type() == eventNames().blurEvent) { if (innerTextRenderer) { if (RenderLayer* innerLayer = innerTextRenderer->layer()) innerLayer->scrollToOffset(style()->direction() == RTL ? innerLayer->scrollWidth() : 0, 0); } capsLockStateMayHaveChanged(); } else if (event->type() == eventNames().focusEvent) capsLockStateMayHaveChanged(); if (!event->isMouseEvent()) { RenderTextControl::forwardEvent(event); return; } FloatPoint localPoint = innerTextRenderer->absoluteToLocal(FloatPoint(static_cast<MouseEvent*>(event)->pageX(), static_cast<MouseEvent*>(event)->pageY()), false, true); if (m_resultsButton && localPoint.x() < innerTextRenderer->borderBoxRect().x()) m_resultsButton->defaultEventHandler(event); else if (m_cancelButton && localPoint.x() > innerTextRenderer->borderBoxRect().right()) m_cancelButton->defaultEventHandler(event); else RenderTextControl::forwardEvent(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; } 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); }
void RenderTextControlSingleLine::forwardEvent(Event* event) { RenderBox* innerTextRenderer = innerTextElement()->renderBox(); if (event->type() == eventNames().blurEvent) { if (innerTextRenderer) { if (RenderLayer* innerLayer = innerTextRenderer->layer()) innerLayer->scrollToOffset(!style()->isLeftToRightDirection() ? innerLayer->scrollWidth() : 0, 0); } capsLockStateMayHaveChanged(); } else if (event->type() == eventNames().focusEvent) capsLockStateMayHaveChanged(); if (!event->isMouseEvent()) { RenderTextControl::forwardEvent(event); return; } #if ENABLE(INPUT_SPEECH) if (RenderBox* speechBox = speechButtonElement() ? speechButtonElement()->renderBox() : 0) { RenderBox* parent = innerTextRenderer ? innerTextRenderer : this; FloatPoint pointInTextControlCoords = parent->absoluteToLocal(static_cast<MouseEvent*>(event)->absoluteLocation(), false, true); if (speechBox->frameRect().contains(roundedIntPoint(pointInTextControlCoords))) { speechButtonElement()->defaultEventHandler(event); return; } } #endif FloatPoint localPoint = innerTextRenderer->absoluteToLocal(static_cast<MouseEvent*>(event)->absoluteLocation(), false, true); int textRight = innerTextRenderer->borderBoxRect().maxX(); HTMLElement* resultsButton = resultsButtonElement(); HTMLElement* cancelButton = cancelButtonElement(); if (resultsButton && localPoint.x() < innerTextRenderer->borderBoxRect().x()) resultsButton->defaultEventHandler(event); else if (cancelButton && localPoint.x() > textRight) cancelButton->defaultEventHandler(event); else RenderTextControl::forwardEvent(event); }
static inline void appendZoomableSubtargets(Node* node, SubtargetGeometryList& subtargets) { RenderBox* renderer = toRenderBox(node->renderer()); ASSERT(renderer); Vector<FloatQuad> quads; FloatRect borderBoxRect = renderer->borderBoxRect(); FloatRect contentBoxRect = renderer->contentBoxRect(); quads.append(renderer->localToAbsoluteQuad(borderBoxRect)); if (borderBoxRect != contentBoxRect) quads.append(renderer->localToAbsoluteQuad(contentBoxRect)); // FIXME: For RenderBlocks, add column boxes and content boxes cleared for floats. Vector<FloatQuad>::const_iterator it = quads.begin(); const Vector<FloatQuad>::const_iterator end = quads.end(); for (; it != end; ++it) subtargets.append(SubtargetGeometry(node, *it)); }
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 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 SpinButtonElement::defaultEventHandler(Event* event) { if (!is<MouseEvent>(*event)) { 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 = downcast<MouseEvent>(*event); IntPoint local = roundedIntPoint(box->absoluteToLocal(mouseEvent.absoluteLocation(), UseTransforms)); 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. Ref<SpinButtonElement> protectedThis(*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); } } mouseEvent.setDefaultHandled(); } } else if (mouseEvent.type() == eventNames().mouseupEvent && mouseEvent.button() == LeftButton) stopRepeatingTimer(); else if (mouseEvent.type() == eventNames().mousemoveEvent) { if (box->borderBoxRect().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; switch (renderer()->theme().innerSpinButtonLayout(*renderer())) { case RenderTheme::InnerSpinButtonLayout::Vertical: m_upDownState = local.y() < box->height() / 2 ? Up : Down; break; case RenderTheme::InnerSpinButtonLayout::HorizontalUpLeft: m_upDownState = local.x() < box->width() / 2 ? Up : Down; break; case RenderTheme::InnerSpinButtonLayout::HorizontalUpRight: m_upDownState = local.x() > box->width() / 2 ? Up : Down; break; } if (m_upDownState != oldUpDownState) renderer()->repaint(); } else { releaseCapture(); m_upDownState = Indeterminate; } } if (!mouseEvent.defaultHandled()) HTMLDivElement::defaultEventHandler(&mouseEvent); }