Changeset 223947 in webkit


Ignore:
Timestamp:
Oct 24, 2017 6:35:45 PM (7 years ago)
Author:
rniwa@webkit.org
Message:

RenderSVGModelObject::checkIntersection triggers layout
https://bugs.webkit.org/show_bug.cgi?id=178710

Reviewed by Simon Fraser.

Source/WebCore:

Fixed the bug that checkIntersection and checkEnclosure no longer updates the layout after r223882.

Test: svg/custom/check-intersection-basic.svg

  • svg/SVGSVGElement.cpp:

(WebCore::SVGSVGElement::collectIntersectionOrEnclosureList):
(WebCore::SVGSVGElement::checkIntersection):
(WebCore::SVGSVGElement::checkEnclosure):

  • svg/SVGSVGElement.h:

LayoutTests:

Added the support for SVG documents to js-test.js, and added a basic test for checkIntersection
and checkEnclosure using it.

  • resources/js-test.js:

(ensureRootElement): Added. Creates a foreignObject element inside a SVG document.
(moveForeignObjectToTopIfNeeded): Added. In SVG, z-index order is determined by the element order.
In order to make the results visible, we move the foreignObject to the top by appending to the end
of the document element.
(getOrCreate):
(debug): Run innerHTML before appendChild as setting namespaceURI before running innerHTML would
result in span's being parsed as SVG elements.
(insertStyleSheet):
(finishJSTest):

  • svg/custom/check-intersection-basic-expected.txt: Added.
  • svg/custom/check-intersection-basic.svg: Added.
Location:
trunk
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r223945 r223947  
     12017-10-24  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        RenderSVGModelObject::checkIntersection triggers layout
     4        https://bugs.webkit.org/show_bug.cgi?id=178710
     5
     6        Reviewed by Simon Fraser.
     7
     8        Added the support for SVG documents to js-test.js, and added a basic test for checkIntersection
     9        and checkEnclosure using it.
     10
     11        * resources/js-test.js:
     12        (ensureRootElement): Added. Creates a foreignObject element inside a SVG document.
     13        (moveForeignObjectToTopIfNeeded): Added. In SVG, z-index order is determined by the element order.
     14        In order to make the results visible, we move the foreignObject to the top by appending to the end
     15        of the document element.
     16        (getOrCreate):
     17        (debug): Run innerHTML before appendChild as setting namespaceURI before running innerHTML would
     18        result in span's being parsed as SVG elements.
     19        (insertStyleSheet):
     20        (finishJSTest):
     21        * svg/custom/check-intersection-basic-expected.txt: Added.
     22        * svg/custom/check-intersection-basic.svg: Added.
     23
    1242017-10-24  Andy Estes  <aestes@apple.com>
    225
  • trunk/LayoutTests/resources/js-test.js

    r217312 r223947  
    3232    }
    3333
     34    var rootElement = null;
     35    function ensureRootElement()
     36    {
     37        if (!rootElement || !rootElement.isConnected) {
     38            rootElement = document.body || document.documentElement;
     39            if (document.documentElement.namespaceURI == 'http://www.w3.org/2000/svg') {
     40                // FIXME: Make the test harness use SVG elements naively.
     41                var foreignObject = document.createElementNS('http://www.w3.org/2000/svg', 'foreignObject');
     42                foreignObject.setAttribute('x', '0px');
     43                foreignObject.setAttribute('y', '0px');
     44                foreignObject.setAttribute('width', '100%');
     45                foreignObject.setAttribute('height', '100%');
     46                foreignObject.setAttribute('style', 'padding: 10px; background-color: rgba(255, 255, 255, 0.5)');
     47                document.documentElement.appendChild(foreignObject);
     48                rootElement = foreignObject;
     49            }
     50        }
     51        return rootElement;
     52    }
     53
     54    moveForeignObjectToTopIfNeeded = function () {
     55        if (rootElement && rootElement.localName == 'foreignObject')
     56            document.documentElement.appendChild(rootElement);
     57    }
     58
    3459    function getOrCreate(id, tagName)
    3560    {
     
    4166        element.id = id;
    4267        var refNode;
    43         var parent = document.body || document.documentElement;
     68        var parent = ensureRootElement();
     69
    4470        if (id == "description")
    4571            refNode = getOrCreate("console", "div");
     
    7096    {
    7197        var span = createHTMLElement("span");
    72         getOrCreate("console", "div").appendChild(span); // insert it first so XHTML knows the namespace
    7398        span.innerHTML = msg + '<br />';
     99        getOrCreate("console", "div").appendChild(span);
    74100    };
    75101
     
    92118        var styleElement = createHTMLElement("style");
    93119        styleElement.textContent = css;
    94         (document.head || document.documentElement).appendChild(styleElement);
     120        (document.head || ensureRootElement()).appendChild(styleElement);
    95121    }
    96122
     
    749775        return;
    750776    isSuccessfullyParsed();
     777    moveForeignObjectToTopIfNeeded();
    751778    if (self.jsTestIsAsync && self.testRunner)
    752779        testRunner.notifyDone();
  • trunk/Source/WebCore/ChangeLog

    r223945 r223947  
     12017-10-24  Ryosuke Niwa  <rniwa@webkit.org>
     2
     3        RenderSVGModelObject::checkIntersection triggers layout
     4        https://bugs.webkit.org/show_bug.cgi?id=178710
     5
     6        Reviewed by Simon Fraser.
     7
     8        Fixed the bug that checkIntersection and checkEnclosure no longer updates the layout after r223882.
     9
     10        Test: svg/custom/check-intersection-basic.svg
     11
     12        * svg/SVGSVGElement.cpp:
     13        (WebCore::SVGSVGElement::collectIntersectionOrEnclosureList):
     14        (WebCore::SVGSVGElement::checkIntersection):
     15        (WebCore::SVGSVGElement::checkEnclosure):
     16        * svg/SVGSVGElement.h:
     17
    1182017-10-24  Andy Estes  <aestes@apple.com>
    219
  • trunk/Source/WebCore/svg/SVGSVGElement.cpp

    r223882 r223947  
    324324}
    325325
    326 Ref<NodeList> SVGSVGElement::collectIntersectionOrEnclosureList(SVGRect& rect, SVGElement* referenceElement, bool (*checkFunction)(const SVGElement*, SVGRect&))
     326Ref<NodeList> SVGSVGElement::collectIntersectionOrEnclosureList(SVGRect& rect, SVGElement* referenceElement, bool (*checkFunction)(RefPtr<SVGElement>&&, SVGRect&))
    327327{
    328328    Vector<Ref<Element>> elements;
     
    346346}
    347347
    348 bool SVGSVGElement::checkIntersection(const SVGElement* element, SVGRect& rect)
    349 {
    350     return element && RenderSVGModelObject::checkIntersection(element->renderer(), rect.propertyReference());
    351 }
    352 
    353 bool SVGSVGElement::checkEnclosure(const SVGElement* element, SVGRect& rect)
    354 {
    355     return element && RenderSVGModelObject::checkEnclosure(element->renderer(), rect.propertyReference());
     348bool SVGSVGElement::checkIntersection(RefPtr<SVGElement>&& element, SVGRect& rect)
     349{
     350    if (!element)
     351        return false;
     352    element->document().updateLayoutIgnorePendingStylesheets();
     353    return RenderSVGModelObject::checkIntersection(element->renderer(), rect.propertyReference());
     354}
     355
     356bool SVGSVGElement::checkEnclosure(RefPtr<SVGElement>&& element, SVGRect& rect)
     357{
     358    if (!element)
     359        return false;
     360    element->document().updateLayoutIgnorePendingStylesheets();
     361    return RenderSVGModelObject::checkEnclosure(element->renderer(), rect.propertyReference());
    356362}
    357363
  • trunk/Source/WebCore/svg/SVGSVGElement.h

    r223802 r223947  
    9393    Ref<NodeList> getIntersectionList(SVGRect&, SVGElement* referenceElement);
    9494    Ref<NodeList> getEnclosureList(SVGRect&, SVGElement* referenceElement);
    95     static bool checkIntersection(const SVGElement*, SVGRect&);
    96     static bool checkEnclosure(const SVGElement*, SVGRect&);
     95    static bool checkIntersection(RefPtr<SVGElement>&&, SVGRect&);
     96    static bool checkEnclosure(RefPtr<SVGElement>&&, SVGRect&);
    9797    void deselectAll();
    9898
     
    154154    Frame* frameForCurrentScale() const;
    155155    void inheritViewAttributes(const SVGViewElement&);
    156     Ref<NodeList> collectIntersectionOrEnclosureList(SVGRect&, SVGElement*, bool (*checkFunction)(const SVGElement*, SVGRect&));
     156    Ref<NodeList> collectIntersectionOrEnclosureList(SVGRect&, SVGElement*, bool (*checkFunction)(RefPtr<SVGElement>&&, SVGRect&));
    157157
    158158    bool m_useCurrentView { false };
Note: See TracChangeset for help on using the changeset viewer.