Changeset 203104 in webkit


Ignore:
Timestamp:
Jul 11, 2016 9:28:16 PM (8 years ago)
Author:
fred.wang@free.fr
Message:

Add support for @href attribute in MathML
https://bugs.webkit.org/show_bug.cgi?id=85733

Patch by Frederic Wang <fwang@igalia.com> on 2016-07-11
Reviewed by Brent Fulgham.

Source/WebCore:

We add support for the href attribute from MathML 3 but ignore the deprecated XLink version.
We also use the code from HTMLAnchorElement SVGAElement to make MathMLElement with a href
attribute behave as a link.
Finally, we adjust mathml.css based on rules from the html and svg user agent stylesheets.

Tests: mathml/mathml-in-html5/href-click-1.html

mathml/mathml-in-html5/href-click-2.html
mathml/presentation/href-enter.html
mathml/presentation/href-style.html
mathml/presentation/maction-toggle-href.html
mathml/presentation/semantics-href.html

  • css/mathml.css:

(:any-link): Set color and mouse cursor of links.
(:any-link:active): Set color of active links.
(:focus): Set outline of focused links.

  • mathml/MathMLElement.cpp:

(WebCore::MathMLElement::parseAttribute): Parse the href attribute.
(WebCore::MathMLElement::willRespondToMouseClickEvents): Based on HTMLAnchorElement/SVGAElement.
(WebCore::MathMLElement::defaultEventHandler): Based on HTMLAnchorElement/SVGAElement.
(WebCore::MathMLElement::canStartSelection): Based on HTMLAnchorElement/SVGAElement.
(WebCore::MathMLElement::isFocusable): Based on HTMLAnchorElement/SVGAElement.
(WebCore::MathMLElement::isKeyboardFocusable): Based on HTMLAnchorElement/SVGAElement.
(WebCore::MathMLElement::isMouseFocusable): Based on HTMLAnchorElement/SVGAElement.
(WebCore::MathMLElement::isURLAttribute): Based on HTMLAnchorElement/SVGAElement.
(WebCore::MathMLElement::supportsFocus): Based on HTMLAnchorElement/SVGAElement.
(WebCore::MathMLElement::tabIndex): Based on HTMLAnchorElement/SVGAElement.

  • mathml/MathMLElement.h: Define new members.
  • mathml/MathMLSelectElement.cpp:

(WebCore::MathMLSelectElement::willRespondToMouseClickEvents): We also verify whether
the parent class will respond.

  • mathml/mathattrs.in: Add href attribute.

LayoutTests:

We import some tests from the MathML in HTML5 test suite to
test clicks on href attributes and write similar tests.
We also test tab/enter keys and user agent style with links.

  • mathml/mathml-in-html5/href-click-1.html: Added. Verify mouse click on a MathML link.
  • mathml/mathml-in-html5/href-click-1-expected.html: Added.
  • mathml/mathml-in-html5/href-click-2.html: Added.

Verify mouse click on a descendant of a MathML link.

  • mathml/mathml-in-html5/href-click-2-expected.html: Added.
  • mathml/presentation/href-enter.html: Added.

Verify tab navigation and activing link with enter.

  • mathml/presentation/href-enter-expected.html: Added.
  • mathml/presentation/href-style.html: Added.

Verify default style of links and of focused links.

  • mathml/presentation/href-style-expected.html: Added.
  • mathml/presentation/maction-toggle-href.html: Added.

Verify conflicts between maction toggle and href link.

  • mathml/presentation/maction-toggle-href-expected.html: Added.
  • mathml/presentation/semantics-href.html: Added. Verify mouse click on a <semantics> link.
  • mathml/presentation/semantics-href-expected.html: Added.
  • platform/mac/TestExpectations: Disable MathML link tests that rely on keyboard events.
  • platform/ios-simulator/TestExpectations: Ditto.
Location:
trunk
Files:
13 added
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r203103 r203104  
     12016-07-11  Frederic Wang  <fwang@igalia.com>
     2
     3        Add support for @href attribute in MathML
     4        https://bugs.webkit.org/show_bug.cgi?id=85733
     5
     6        Reviewed by Brent Fulgham.
     7
     8        We import some tests from the MathML in HTML5 test suite to
     9        test clicks on href attributes and write similar tests.
     10        We also test tab/enter keys and user agent style with links.
     11
     12        * mathml/mathml-in-html5/href-click-1.html: Added. Verify mouse click on a MathML link.
     13        * mathml/mathml-in-html5/href-click-1-expected.html: Added.
     14        * mathml/mathml-in-html5/href-click-2.html: Added.
     15        Verify mouse click on a descendant of a MathML link.
     16        * mathml/mathml-in-html5/href-click-2-expected.html: Added.
     17        * mathml/presentation/href-enter.html: Added.
     18        Verify tab navigation and activing link with enter.
     19        * mathml/presentation/href-enter-expected.html: Added.
     20        * mathml/presentation/href-style.html: Added.
     21        Verify default style of links and of focused links.
     22        * mathml/presentation/href-style-expected.html: Added.
     23        * mathml/presentation/maction-toggle-href.html: Added.
     24        Verify conflicts between maction toggle and href link.
     25        * mathml/presentation/maction-toggle-href-expected.html: Added.
     26        * mathml/presentation/semantics-href.html: Added. Verify mouse click on a <semantics> link.
     27        * mathml/presentation/semantics-href-expected.html: Added.
     28        * platform/mac/TestExpectations: Disable MathML link tests that rely on keyboard events.
     29        * platform/ios-simulator/TestExpectations: Ditto.
     30
    1312016-07-11  Frederic Wang  <fwang@igalia.com>
    232
  • trunk/LayoutTests/platform/ios-simulator/TestExpectations

    r203072 r203104  
    680680# The web font loading & relayout seems to be performed too late.
    681681imported/mathml-in-html5/mathml/relations/css-styling/mathvariant-transforms-1.html [ Pass ImageOnlyFailure ]
     682
     683# These tests use key navigation to test MathML links but do not seem to work on iOS simulator.
     684webkit.org/b/159662 mathml/presentation/href-enter.html [ Skip ]
     685webkit.org/b/159662 mathml/presentation/href-style.html [ Skip ]
    682686
    683687# <rdar://problem/19215305> ASSERT(m_cgFont.get()) fails in FontPlatformData::ctFont()
  • trunk/LayoutTests/platform/mac/TestExpectations

    r203071 r203104  
    805805mathml/presentation/fractions-linethickness.html [ Skip ]
    806806mathml/opentype/large-operators-italic-correction.html [ Skip ]
     807
     808# These tests use key navigation to test MathML links but do not seem to work on Mac.
     809webkit.org/b/159662 mathml/presentation/href-enter.html [ Skip ]
     810webkit.org/b/159662 mathml/presentation/href-style.html [ Skip ]
    807811
    808812webkit.org/b/128255 compositing/columns/composited-lr-paginated-repaint.html [ Pass Failure ]
  • trunk/Source/WebCore/ChangeLog

    r203099 r203104  
     12016-07-11  Frederic Wang  <fwang@igalia.com>
     2
     3        Add support for @href attribute in MathML
     4        https://bugs.webkit.org/show_bug.cgi?id=85733
     5
     6        Reviewed by Brent Fulgham.
     7
     8        We add support for the href attribute from MathML 3 but ignore the deprecated XLink version.
     9        We also use the code from HTMLAnchorElement SVGAElement to make MathMLElement with a href
     10        attribute behave as a link.
     11        Finally, we adjust mathml.css based on rules from the html and svg user agent stylesheets.
     12
     13        Tests: mathml/mathml-in-html5/href-click-1.html
     14               mathml/mathml-in-html5/href-click-2.html
     15               mathml/presentation/href-enter.html
     16               mathml/presentation/href-style.html
     17               mathml/presentation/maction-toggle-href.html
     18               mathml/presentation/semantics-href.html
     19
     20        * css/mathml.css:
     21        (:any-link): Set color and mouse cursor of links.
     22        (:any-link:active): Set color of active links.
     23        (:focus): Set outline of focused links.
     24        * mathml/MathMLElement.cpp:
     25        (WebCore::MathMLElement::parseAttribute): Parse the href attribute.
     26        (WebCore::MathMLElement::willRespondToMouseClickEvents): Based on HTMLAnchorElement/SVGAElement.
     27        (WebCore::MathMLElement::defaultEventHandler): Based on HTMLAnchorElement/SVGAElement.
     28        (WebCore::MathMLElement::canStartSelection): Based on HTMLAnchorElement/SVGAElement.
     29        (WebCore::MathMLElement::isFocusable): Based on HTMLAnchorElement/SVGAElement.
     30        (WebCore::MathMLElement::isKeyboardFocusable): Based on HTMLAnchorElement/SVGAElement.
     31        (WebCore::MathMLElement::isMouseFocusable): Based on HTMLAnchorElement/SVGAElement.
     32        (WebCore::MathMLElement::isURLAttribute): Based on HTMLAnchorElement/SVGAElement.
     33        (WebCore::MathMLElement::supportsFocus): Based on HTMLAnchorElement/SVGAElement.
     34        (WebCore::MathMLElement::tabIndex): Based on HTMLAnchorElement/SVGAElement.
     35        * mathml/MathMLElement.h: Define new members.
     36        * mathml/MathMLSelectElement.cpp:
     37        (WebCore::MathMLSelectElement::willRespondToMouseClickEvents): We also verify whether
     38        the parent class will respond.
     39        * mathml/mathattrs.in: Add href attribute.
     40
    1412016-07-11  Sam Weinig  <sam@webkit.org>
    242
  • trunk/Source/WebCore/css/mathml.css

    r203072 r203104  
    11@namespace "http://www.w3.org/1998/Math/MathML";
     2
     3:any-link {
     4    color: -webkit-link;
     5    cursor: auto;
     6}
     7
     8:any-link:active {
     9    color: -webkit-activelink;
     10}
     11
     12:focus {
     13    outline: auto 5px -webkit-focus-ring-color
     14}
    215
    316math {
  • trunk/Source/WebCore/mathml/MathMLElement.cpp

    r202727 r203104  
    3333
    3434#include "ElementIterator.h"
     35#include "Event.h"
     36#include "EventHandler.h"
     37#include "HTMLAnchorElement.h"
    3538#include "HTMLElement.h"
    3639#include "HTMLHtmlElement.h"
     
    4144#include "MathMLNames.h"
    4245#include "MathMLSelectElement.h"
     46#include "MouseEvent.h"
    4347#include "RenderTableCell.h"
    4448#include "SVGElement.h"
    4549#include "SVGNames.h"
    4650#include "SVGSVGElement.h"
     51#include "XLinkNames.h"
    4752
    4853namespace WebCore {
     
    217222void MathMLElement::parseAttribute(const QualifiedName& name, const AtomicString& value)
    218223{
    219     if (name == rowspanAttr) {
     224    if (name == hrefAttr) {
     225        bool wasLink = isLink();
     226        setIsLink(!value.isNull() && !shouldProhibitLinks(this));
     227        if (wasLink != isLink())
     228            setNeedsStyleRecalc();
     229    } else if (name == rowspanAttr) {
    220230        if (is<RenderTableCell>(renderer()) && hasTagName(mtdTag))
    221231            downcast<RenderTableCell>(*renderer()).colSpanOrRowSpanChanged();
     
    306316}
    307317
     318bool MathMLElement::willRespondToMouseClickEvents()
     319{
     320    return isLink() || StyledElement::willRespondToMouseClickEvents();
     321}
     322
     323void MathMLElement::defaultEventHandler(Event* event)
     324{
     325    if (isLink()) {
     326        if (focused() && isEnterKeyKeydownEvent(event)) {
     327            event->setDefaultHandled();
     328            dispatchSimulatedClick(event);
     329            return;
     330        }
     331        if (MouseEvent::canTriggerActivationBehavior(*event)) {
     332            const AtomicString& href = fastGetAttribute(hrefAttr);
     333            String url = stripLeadingAndTrailingHTMLSpaces(href);
     334            event->setDefaultHandled();
     335            if (Frame* frame = document().frame())
     336                frame->loader().urlSelected(document().completeURL(url), "_self", event, LockHistory::No, LockBackForwardList::No, MaybeSendReferrer, document().shouldOpenExternalURLsPolicyToPropagate());
     337            return;
     338        }
     339    }
     340
     341    StyledElement::defaultEventHandler(event);
     342}
     343
     344bool MathMLElement::canStartSelection() const
     345{
     346    if (!isLink())
     347        return StyledElement::canStartSelection();
     348
     349    return hasEditableStyle();
     350}
     351
     352bool MathMLElement::isFocusable() const
     353{
     354    if (renderer() && renderer()->absoluteClippedOverflowRect().isEmpty())
     355        return false;
     356
     357    return StyledElement::isFocusable();
     358}
     359
     360bool MathMLElement::isKeyboardFocusable(KeyboardEvent* event) const
     361{
     362    if (isFocusable() && StyledElement::supportsFocus())
     363        return StyledElement::isKeyboardFocusable(event);
     364
     365    if (isLink())
     366        return document().frame()->eventHandler().tabsToLinks(event);
     367
     368    return StyledElement::isKeyboardFocusable(event);
     369}
     370
     371bool MathMLElement::isMouseFocusable() const
     372{
     373    // Links are focusable by default, but only allow links with tabindex or contenteditable to be mouse focusable.
     374    // https://bugs.webkit.org/show_bug.cgi?id=26856
     375    if (isLink())
     376        return StyledElement::supportsFocus();
     377
     378    return StyledElement::isMouseFocusable();
     379}
     380
     381bool MathMLElement::isURLAttribute(const Attribute& attribute) const
     382{
     383    return attribute.name().localName() == hrefAttr || StyledElement::isURLAttribute(attribute);
     384}
     385
     386bool MathMLElement::supportsFocus() const
     387{
     388    if (hasEditableStyle())
     389        return StyledElement::supportsFocus();
     390    // If not a link we should still be able to focus the element if it has tabIndex.
     391    return isLink() || StyledElement::supportsFocus();
     392}
     393
     394int MathMLElement::tabIndex() const
     395{
     396    // Skip the supportsFocus check in StyledElement.
     397    return Element::tabIndex();
     398}
     399
    308400}
    309401
  • trunk/Source/WebCore/mathml/MathMLElement.h

    r198129 r203104  
    7070    bool isFlowContent(const Node&) const;
    7171
     72    bool willRespondToMouseClickEvents() override;
     73    void defaultEventHandler(Event*) override;
     74
    7275private:
    7376    virtual void updateSelectedChild() { }
     77
     78    bool canStartSelection() const final;
     79    bool isFocusable() const final;
     80    bool isKeyboardFocusable(KeyboardEvent*) const final;
     81    bool isMouseFocusable() const final;
     82    bool isURLAttribute(const Attribute&) const final;
     83    bool supportsFocus() const final;
     84    int tabIndex() const final;
    7485};
    7586
  • trunk/Source/WebCore/mathml/MathMLSelectElement.cpp

    r202441 r203104  
    225225bool MathMLSelectElement::willRespondToMouseClickEvents()
    226226{
    227     return fastGetAttribute(MathMLNames::actiontypeAttr) == "toggle";
     227    return fastGetAttribute(MathMLNames::actiontypeAttr) == "toggle" || MathMLInlineContainerElement::willRespondToMouseClickEvents();
    228228}
    229229
  • trunk/Source/WebCore/mathml/mathattrs.in

    r203074 r203104  
    2626form
    2727height
     28href
    2829largeop
    2930linethickness
Note: See TracChangeset for help on using the changeset viewer.