315bool MathMLElement::willRespondToMouseClickEvents()
316{
317 return isLink() || StyledElement::willRespondToMouseClickEvents();
318}
319
320void MathMLElement::defaultEventHandler(Event* event)
321{
322 if (isLink()) {
323 if (focused() && isEnterKeyKeydownEvent(event)) {
324 event->setDefaultHandled();
325 dispatchSimulatedClick(event);
326 return;
327 }
328 if (MouseEvent::canTriggerActivationBehavior(*event)) {
329 const AtomicString& href = fastGetAttribute(hrefAttr);
330 String url = stripLeadingAndTrailingHTMLSpaces(href);
331 event->setDefaultHandled();
332 Frame* frame = document().frame();
333 if (!frame)
334 return;
335 frame->loader().urlSelected(document().completeURL(url), "_self", event, LockHistory::No, LockBackForwardList::No, MaybeSendReferrer, document().shouldOpenExternalURLsPolicyToPropagate());
336 return;
337 }
338 }
339
340 StyledElement::defaultEventHandler(event);
341}
342
343bool MathMLElement::canStartSelection() const
344{
345 if (!isLink())
346 return StyledElement::canStartSelection();
347
348 return hasEditableStyle();
349}
350
351bool MathMLElement::isFocusable() const
352{
353 if (renderer() && renderer()->absoluteClippedOverflowRect().isEmpty())
354 return false;
355
356 return StyledElement::isFocusable();
357}
358
359bool MathMLElement::isKeyboardFocusable(KeyboardEvent* event) const
360{
361 if (isFocusable() && StyledElement::supportsFocus())
362 return StyledElement::isKeyboardFocusable(event);
363
364 if (isLink())
365 return document().frame()->eventHandler().tabsToLinks(event);
366
367 return StyledElement::isKeyboardFocusable(event);
368}
369
370bool MathMLElement::isMouseFocusable() const
371{
372 // Links are focusable by default, but only allow links with tabindex or contenteditable to be mouse focusable.
373 // https://bugs.webkit.org/show_bug.cgi?id=26856
374 if (isLink())
375 return StyledElement::supportsFocus();
376
377 return StyledElement::isMouseFocusable();
378}
379
380bool MathMLElement::isURLAttribute(const Attribute& attribute) const
381{
382 return attribute.name().localName() == hrefAttr || StyledElement::isURLAttribute(attribute);
383}
384
385bool MathMLElement::supportsFocus() const
386{
387 if (hasEditableStyle())
388 return StyledElement::supportsFocus();
389 // If not a link we should still be able to focus the element if it has tabIndex.
390 return isLink() || StyledElement::supportsFocus();
391}
392
393int MathMLElement::tabIndex() const
394{
395 // Skip the supportsFocus check in StyledElement.
396 return Element::tabIndex();
397}
398