static void appendServerMapMousePosition(String& url, Event* event) { if (!event->isMouseEvent()) return; ASSERT(event->target()); Node* target = event->target()->toNode(); ASSERT(target); if (!target->hasTagName(imgTag)) return; HTMLImageElement* imageElement = static_cast<HTMLImageElement*>(event->target()->toNode()); if (!imageElement || !imageElement->isServerMap()) return; RenderImage* renderer = toRenderImage(imageElement->renderer()); if (!renderer) return; // FIXME: This should probably pass true for useTransforms. FloatPoint absolutePosition = renderer->absoluteToLocal(FloatPoint(static_cast<MouseEvent*>(event)->pageX(), static_cast<MouseEvent*>(event)->pageY())); int x = absolutePosition.x(); int y = absolutePosition.y(); url += "?"; url += String::number(x); url += ","; url += String::number(y); }
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* evt) { // React on clicks and on keypresses. // Don't make this KEYUP_EVENT again, it makes khtml follow links it shouldn't, // when pressing Enter in the combo. if (isLink() && (evt->type() == eventNames().clickEvent || (evt->type() == eventNames().keydownEvent && focused()))) { MouseEvent* e = 0; if (evt->type() == eventNames().clickEvent && evt->isMouseEvent()) e = static_cast<MouseEvent*>(evt); KeyboardEvent* k = 0; if (evt->type() == eventNames().keydownEvent && evt->isKeyboardEvent()) k = static_cast<KeyboardEvent*>(evt); if (e && e->button() == RightButton) { HTMLElement::defaultEventHandler(evt); return; } // If the link is editable, then we need to check the settings to see whether or not to follow the link if (isContentEditable()) { EditableLinkBehavior editableLinkBehavior = EditableLinkDefaultBehavior; if (Settings* settings = document()->settings()) editableLinkBehavior = settings->editableLinkBehavior(); switch (editableLinkBehavior) { // Always follow the link (Safari 2.0 behavior) default: case EditableLinkDefaultBehavior: case EditableLinkAlwaysLive: break; case EditableLinkNeverLive: HTMLElement::defaultEventHandler(evt); return; // If the selection prior to clicking on this link resided in the same editable block as this link, // and the shift key isn't pressed, we don't want to follow the link case EditableLinkLiveWhenNotFocused: if (e && !e->shiftKey() && m_rootEditableElementForSelectionOnMouseDown == rootEditableElement()) { HTMLElement::defaultEventHandler(evt); return; } break; // Only follow the link if the shift key is down (WinIE/Firefox behavior) case EditableLinkOnlyLiveWithShiftKey: if (e && !e->shiftKey()) { HTMLElement::defaultEventHandler(evt); return; } break; } } if (k) { if (k->keyIdentifier() != "Enter") { HTMLElement::defaultEventHandler(evt); return; } evt->setDefaultHandled(); dispatchSimulatedClick(evt); return; } String url = parseURL(getAttribute(hrefAttr)); ASSERT(evt->target()); ASSERT(evt->target()->toNode()); if (evt->target()->toNode()->hasTagName(imgTag)) { HTMLImageElement* img = static_cast<HTMLImageElement*>(evt->target()->toNode()); if (img && img->isServerMap()) { RenderImage* r = static_cast<RenderImage*>(img->renderer()); if (r && e) { // FIXME: broken with transforms FloatPoint absPos = r->localToAbsolute(); int x = e->pageX() - absPos.x(); int y = e->pageY() - absPos.y(); url += "?"; url += String::number(x); url += ","; url += String::number(y); } else { evt->setDefaultHandled(); HTMLElement::defaultEventHandler(evt); return; } } } if (!evt->defaultPrevented() && document()->frame()) document()->frame()->loader()->urlSelected(document()->completeURL(url), getAttribute(targetAttr), evt, false, false, true); evt->setDefaultHandled(); } else if (isLink() && isContentEditable()) { // 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 (evt->type() == eventNames().mousedownEvent && evt->isMouseEvent() && static_cast<MouseEvent*>(evt)->button() != RightButton && document()->frame() && document()->frame()->selection()) { MouseEvent* e = static_cast<MouseEvent*>(evt); m_rootEditableElementForSelectionOnMouseDown = document()->frame()->selection()->rootEditableElement(); m_wasShiftKeyDownOnMouseDown = e && e->shiftKey(); } else if (evt->type() == eventNames().mouseoverEvent) { // These are cleared on mouseover and not mouseout because their values are needed for drag events, but these happen // after mouse out events. m_rootEditableElementForSelectionOnMouseDown = 0; m_wasShiftKeyDownOnMouseDown = false; } } HTMLElement::defaultEventHandler(evt); }