Changeset 202895 in webkit


Ignore:
Timestamp:
Jul 6, 2016 10:55:30 PM (8 years ago)
Author:
Chris Dumez
Message:

Document.title setter does not work for SVG documents
https://bugs.webkit.org/show_bug.cgi?id=159503
<rdar://problem/27212313>

Reviewed by Ryosuke Niwa.

LayoutTests/imported/w3c:

Rebaseline W3C test now that all checks are passing.

  • web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-09-expected.txt:

Source/WebCore:

Document.title setter should work for SVG documents:

This patch aligns our behavior with the specification
and with Firefox / Chrome.

No new tests, rebaselined existing test.

  • dom/Document.cpp:

(WebCore::Document::setTitle):

  • Reverse the if conditions for clarity.
  • If the document element is an SVG svg element, create a SVGTitleElement and insert it as first child of the document element.
  • Call SVGTitleElement::setText() instead of HTMLTitleElement::setText() at the end of the method if m_titleElement is a SVGTitleElement.

(WebCore::Document::updateTitleElement):

  • If document element is an SVG svg element, use the first child of the document element that is a SVGTitleElement.
  • svg/SVGTitleElement.cpp:

(WebCore::SVGTitleElement::setText):

  • svg/SVGTitleElement.h:

Add SVGTitleElement::setText() method that does the same
thing as HTMLTitleElement::setText().

Location:
trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/imported/w3c/ChangeLog

    r202893 r202895  
     12016-07-06  Chris Dumez  <cdumez@apple.com>
     2
     3        Document.title setter does not work for SVG documents
     4        https://bugs.webkit.org/show_bug.cgi?id=159503
     5        <rdar://problem/27212313>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Rebaseline W3C test now that all checks are passing.
     10
     11        * web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-09-expected.txt:
     12
    1132016-07-06  Chris Dumez  <cdumez@apple.com>
    214
  • trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-09-expected.txt

    r194580 r202895  
    11
    2 FAIL No title element in SVG document assert_equals: expected "title" but got "x-child"
    3 FAIL Title element in SVG document assert_equals: expected "foobar" but got "foo"
    4 FAIL Title element not child of SVG root assert_equals: expected "" but got "foo"
    5 FAIL Title element not in SVG namespace assert_equals: expected "" but got "foo"
    6 FAIL Root element not named "svg" assert_equals: expected "" but got "foo"
     2PASS No title element in SVG document
     3PASS Title element in SVG document
     4PASS Title element not child of SVG root
     5PASS Title element not in SVG namespace
     6PASS Root element not named "svg"
    77
  • trunk/Source/WebCore/ChangeLog

    r202893 r202895  
     12016-07-06  Chris Dumez  <cdumez@apple.com>
     2
     3        Document.title setter does not work for SVG documents
     4        https://bugs.webkit.org/show_bug.cgi?id=159503
     5        <rdar://problem/27212313>
     6
     7        Reviewed by Ryosuke Niwa.
     8
     9        Document.title setter should work for SVG documents:
     10        - https://html.spec.whatwg.org/multipage/dom.html#document.title
     11
     12        This patch aligns our behavior with the specification
     13        and with Firefox / Chrome.
     14
     15        No new tests, rebaselined existing test.
     16
     17        * dom/Document.cpp:
     18        (WebCore::Document::setTitle):
     19        - Reverse the if conditions for clarity.
     20        - If the document element is an SVG svg element, create a
     21          SVGTitleElement and insert it as first child of the
     22          document element.
     23        - Call SVGTitleElement::setText() instead of
     24          HTMLTitleElement::setText() at the end of the method if
     25          m_titleElement is a SVGTitleElement.
     26
     27        (WebCore::Document::updateTitleElement):
     28        - If document element is an SVG svg element, use the first
     29          child of the document element that is a SVGTitleElement.
     30
     31        * svg/SVGTitleElement.cpp:
     32        (WebCore::SVGTitleElement::setText):
     33        * svg/SVGTitleElement.h:
     34        Add SVGTitleElement::setText() method that does the same
     35        thing as HTMLTitleElement::setText().
     36
    1372016-07-06  Chris Dumez  <cdumez@apple.com>
    238
  • trunk/Source/WebCore/dom/Document.cpp

    r202893 r202895  
    44 *           (C) 2001 Dirk Mueller (mueller@kde.org)
    55 *           (C) 2006 Alexey Proskuryakov (ap@webkit.org)
    6  * Copyright (C) 2004-2015 Apple Inc. All rights reserved.
     6 * Copyright (C) 2004-2016 Apple Inc. All rights reserved.
    77 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
    88 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
     
    147147#include "SVGElementFactory.h"
    148148#include "SVGNames.h"
     149#include "SVGSVGElement.h"
    149150#include "SVGTitleElement.h"
    150151#include "SVGZoomEvent.h"
     
    16211622void Document::setTitle(const String& title)
    16221623{
    1623     if (!isHTMLDocument() && !isXHTMLDocument())
     1624    if (!m_titleElement) {
     1625        if (isHTMLDocument() || isXHTMLDocument()) {
     1626            auto* headElement = head();
     1627            if (!headElement)
     1628                return;
     1629            m_titleElement = HTMLTitleElement::create(HTMLNames::titleTag, *this);
     1630            headElement->appendChild(*m_titleElement);
     1631        } else if (isSVGDocument()) {
     1632            auto* element = documentElement();
     1633            if (!is<SVGSVGElement>(element))
     1634                return;
     1635            m_titleElement = SVGTitleElement::create(SVGNames::titleTag, *this);
     1636            element->insertBefore(*m_titleElement, element->firstChild());
     1637        }
     1638    } else if (!isHTMLDocument() && !isXHTMLDocument() && !isSVGDocument())
    16241639        m_titleElement = nullptr;
    1625     else if (!m_titleElement) {
    1626         auto* headElement = head();
    1627         if (!headElement)
    1628             return;
    1629         m_titleElement = createElement(titleTag, false);
    1630         headElement->appendChild(*m_titleElement, ASSERT_NO_EXCEPTION);
    1631     }
    16321640
    16331641    // The DOM API has no method of specifying direction, so assume LTR.
     
    16361644    if (is<HTMLTitleElement>(m_titleElement.get()))
    16371645        downcast<HTMLTitleElement>(*m_titleElement).setText(title);
     1646    else if (is<SVGTitleElement>(m_titleElement.get()))
     1647        downcast<SVGTitleElement>(*m_titleElement).setText(title);
    16381648}
    16391649
    16401650void Document::updateTitleElement(Element* newTitleElement)
    16411651{
    1642     // Only allow the first title element in tree order to change the title -- others have no effect.
    1643     if (m_titleElement) {
    1644         if (isHTMLDocument() || isXHTMLDocument())
    1645             m_titleElement = descendantsOfType<HTMLTitleElement>(*this).first();
    1646         else if (isSVGDocument())
    1647             m_titleElement = descendantsOfType<SVGTitleElement>(*this).first();
    1648     } else
    1649         m_titleElement = newTitleElement;
     1652    if (is<SVGSVGElement>(documentElement()))
     1653        m_titleElement = childrenOfType<SVGTitleElement>(*documentElement()).first();
     1654    else {
     1655        if (m_titleElement) {
     1656            if (isHTMLDocument() || isXHTMLDocument())
     1657                m_titleElement = descendantsOfType<HTMLTitleElement>(*this).first();
     1658        } else
     1659            m_titleElement = newTitleElement;
     1660    }
    16501661
    16511662    updateTitleFromTitleElement();
  • trunk/Source/WebCore/html/HTMLTitleElement.cpp

    r202167 r202895  
    101101    // We make a copy here because entity of "value" argument can be Document::m_title,
    102102    // which goes empty during removeChildren() invocation below,
    103     // which causes HTMLTitleElement::childrenChanged(), which ends up Document::setTitle().
     103    // which causes HTMLTitleElement::childrenChanged(), which ends up calling Document::setTitle().
    104104    String valueCopy(value);
    105105
  • trunk/Source/WebCore/svg/SVGTitleElement.cpp

    r189680 r202895  
    22 * Copyright (C) 2004, 2005 Nikolas Zimmermann <zimmermann@kde.org>
    33 * Copyright (C) 2004, 2005, 2006 Rob Buis <buis@kde.org>
     4 * Copyright (C) 2016 Apple Inc. All rights reserved.
    45 *
    56 * This library is free software; you can redistribute it and/or
     
    2425#include "Document.h"
    2526#include "SVGNames.h"
     27#include "Text.h"
    2628
    2729namespace WebCore {
     
    6264}
    6365
     66void SVGTitleElement::setText(const String& value)
     67{
     68    Ref<SVGTitleElement> protectedThis(*this);
     69
     70    if (!value.isEmpty() && hasOneChild() && is<Text>(*firstChild())) {
     71        downcast<Text>(*firstChild()).setData(value);
     72        return;
     73    }
     74
     75    // We make a copy here because entity of "value" argument can be Document::m_title,
     76    // which goes empty during removeChildren() invocation below,
     77    // which causes SVGTitleElement::childrenChanged(), which ends up calling Document::setTitle().
     78    String valueCopy(value);
     79
     80    if (hasChildNodes())
     81        removeChildren();
     82
     83    if (!valueCopy.isEmpty())
     84        appendChild(document().createTextNode(valueCopy), IGNORE_EXCEPTION);
    6485}
     86
     87}
  • trunk/Source/WebCore/svg/SVGTitleElement.h

    r197563 r202895  
    3131    static Ref<SVGTitleElement> create(const QualifiedName&, Document&);
    3232
     33    void setText(const String&);
     34
    3335private:
    3436    SVGTitleElement(const QualifiedName&, Document&);
Note: See TracChangeset for help on using the changeset viewer.