Changeset 112091 in webkit


Ignore:
Timestamp:
Mar 26, 2012 7:36:59 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Add invalid bounding box concept to SVG containers
https://bugs.webkit.org/show_bug.cgi?id=81104

Patch by Philip Rogers <pdr@google.com> on 2012-03-26
Reviewed by Nikolas Zimmermann.

Source/WebCore:

An empty <g> element needs to use an invalid bounding box because
an empty bounding box isn't the default state. This change
introduces the concept of an invalid object bounding box for
both RenderSVGContainer and RenderSVGRoot. Code that
does not explicitly check that the bounding box is valid
should be unaffected by this change. We use this new invalid
flag in computeContainerBoundingBoxes so that we do not
include invalid bounding boxes.

This change also contains a small fix in
RenderSVGContainer::toRenderSVGContainer which depended on
RenderSVGViewportContainer not inheriting from RenderSVGContainer,
which it now does.

Test: svg/custom/getBBox-empty-container.html

  • rendering/svg/RenderSVGContainer.cpp:

(WebCore::RenderSVGContainer::RenderSVGContainer):
(WebCore::RenderSVGContainer::updateCachedBoundaries):

  • rendering/svg/RenderSVGContainer.h:

(WebCore::RenderSVGContainer::isObjectBoundingBoxValid):
(RenderSVGContainer):
(WebCore::toRenderSVGContainer):

  • rendering/svg/RenderSVGRoot.cpp:

(WebCore::RenderSVGRoot::RenderSVGRoot):
(WebCore::RenderSVGRoot::updateCachedBoundaries):

  • rendering/svg/RenderSVGRoot.h:

(RenderSVGRoot):

  • rendering/svg/SVGRenderSupport.cpp:

(WebCore):
(WebCore::updateObjectBoundingBox):
(WebCore::SVGRenderSupport::computeContainerBoundingBoxes):

  • rendering/svg/SVGRenderSupport.h:

(SVGRenderSupport):

LayoutTests:

  • svg/custom/getBBox-empty-container-expected.txt: Added.
  • svg/custom/getBBox-empty-container.html: Added.
Location:
trunk
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r112086 r112091  
     12012-03-26  Philip Rogers  <pdr@google.com>
     2
     3        Add invalid bounding box concept to SVG containers
     4        https://bugs.webkit.org/show_bug.cgi?id=81104
     5
     6        Reviewed by Nikolas Zimmermann.
     7
     8        * svg/custom/getBBox-empty-container-expected.txt: Added.
     9        * svg/custom/getBBox-empty-container.html: Added.
     10
    1112012-03-26  Pavel Feldman  <pfeldman@chromium.org>
    212
  • trunk/Source/WebCore/ChangeLog

    r112090 r112091  
     12012-03-26  Philip Rogers  <pdr@google.com>
     2
     3        Add invalid bounding box concept to SVG containers
     4        https://bugs.webkit.org/show_bug.cgi?id=81104
     5
     6        Reviewed by Nikolas Zimmermann.
     7
     8        An empty <g> element needs to use an invalid bounding box because
     9        an empty bounding box isn't the default state. This change
     10        introduces the concept of an invalid object bounding box for
     11        both RenderSVGContainer and RenderSVGRoot. Code that
     12        does not explicitly check that the bounding box is valid
     13        should be unaffected by this change. We use this new invalid
     14        flag in computeContainerBoundingBoxes so that we do not
     15        include invalid bounding boxes.
     16
     17        This change also contains a small fix in
     18        RenderSVGContainer::toRenderSVGContainer which depended on
     19        RenderSVGViewportContainer not inheriting from RenderSVGContainer,
     20        which it now does.
     21
     22        Test: svg/custom/getBBox-empty-container.html
     23
     24        * rendering/svg/RenderSVGContainer.cpp:
     25        (WebCore::RenderSVGContainer::RenderSVGContainer):
     26        (WebCore::RenderSVGContainer::updateCachedBoundaries):
     27        * rendering/svg/RenderSVGContainer.h:
     28        (WebCore::RenderSVGContainer::isObjectBoundingBoxValid):
     29        (RenderSVGContainer):
     30        (WebCore::toRenderSVGContainer):
     31        * rendering/svg/RenderSVGRoot.cpp:
     32        (WebCore::RenderSVGRoot::RenderSVGRoot):
     33        (WebCore::RenderSVGRoot::updateCachedBoundaries):
     34        * rendering/svg/RenderSVGRoot.h:
     35        (RenderSVGRoot):
     36        * rendering/svg/SVGRenderSupport.cpp:
     37        (WebCore):
     38        (WebCore::updateObjectBoundingBox):
     39        (WebCore::SVGRenderSupport::computeContainerBoundingBoxes):
     40        * rendering/svg/SVGRenderSupport.h:
     41        (SVGRenderSupport):
     42
    1432012-03-26  Alexei Filippov  <alexeif@chromium.org>
    244
  • trunk/Source/WebCore/rendering/svg/RenderSVGContainer.cpp

    r110285 r112091  
    4141RenderSVGContainer::RenderSVGContainer(SVGStyledElement* node)
    4242    : RenderSVGModelObject(node)
     43    , m_objectBoundingBoxValid(false)
    4344    , m_needsBoundariesUpdate(true)
    4445{
     
    151152{
    152153    m_objectBoundingBox = FloatRect();
     154    m_objectBoundingBoxValid = false;
    153155    m_strokeBoundingBox = FloatRect();
    154156    m_repaintBoundingBox = FloatRect();
    155157
    156     SVGRenderSupport::computeContainerBoundingBoxes(this, m_objectBoundingBox, m_strokeBoundingBox, m_repaintBoundingBox);
     158    SVGRenderSupport::computeContainerBoundingBoxes(this, m_objectBoundingBox, m_objectBoundingBoxValid, m_strokeBoundingBox, m_repaintBoundingBox);
    157159    SVGRenderSupport::intersectRepaintRectWithResources(this, m_repaintBoundingBox);
    158160}
  • trunk/Source/WebCore/rendering/svg/RenderSVGContainer.h

    r110224 r112091  
    4343    virtual void setNeedsBoundariesUpdate() { m_needsBoundariesUpdate = true; }
    4444    virtual bool didTransformToRootUpdate() { return false; }
     45    bool isObjectBoundingBoxValid() const { return m_objectBoundingBoxValid; }
    4546
    4647protected:
     
    7778    RenderObjectChildList m_children;
    7879    FloatRect m_objectBoundingBox;
     80    bool m_objectBoundingBoxValid;
    7981    FloatRect m_strokeBoundingBox;
    8082    FloatRect m_repaintBoundingBox;
     
    8486inline RenderSVGContainer* toRenderSVGContainer(RenderObject* object)
    8587{
    86     // Note: isSVGContainer is also true for RenderSVGViewportContainer, which is not derived from this.
    87     ASSERT(!object || (object->isSVGContainer() && strcmp(object->renderName(), "RenderSVGViewportContainer")));
     88    ASSERT(!object || object->isSVGContainer());
    8889    return static_cast<RenderSVGContainer*>(object);
    8990}
     
    9192inline const RenderSVGContainer* toRenderSVGContainer(const RenderObject* object)
    9293{
    93     // Note: isSVGContainer is also true for RenderSVGViewportContainer, which is not derived from this.
    94     ASSERT(!object || (object->isSVGContainer() && strcmp(object->renderName(), "RenderSVGViewportContainer")));
     94    ASSERT(!object || object->isSVGContainer());
    9595    return static_cast<const RenderSVGContainer*>(object);
    9696}
  • trunk/Source/WebCore/rendering/svg/RenderSVGRoot.cpp

    r111626 r112091  
    5858RenderSVGRoot::RenderSVGRoot(SVGStyledElement* node)
    5959    : RenderReplaced(node)
     60    , m_objectBoundingBoxValid(false)
    6061    , m_isLayoutSizeChanged(false)
    6162    , m_needsBoundariesOrTransformUpdate(true)
     
    393394{
    394395    m_objectBoundingBox = FloatRect();
     396    m_objectBoundingBoxValid = false;
    395397    m_strokeBoundingBox = FloatRect();
    396398    m_repaintBoundingBox = FloatRect();
    397399
    398     SVGRenderSupport::computeContainerBoundingBoxes(this, m_objectBoundingBox, m_strokeBoundingBox, m_repaintBoundingBox);
     400    SVGRenderSupport::computeContainerBoundingBoxes(this, m_objectBoundingBox, m_objectBoundingBoxValid, m_strokeBoundingBox, m_repaintBoundingBox);
    399401    SVGRenderSupport::intersectRepaintRectWithResources(this, m_repaintBoundingBox);
    400402    m_repaintBoundingBox.inflate(borderAndPaddingWidth());
  • trunk/Source/WebCore/rendering/svg/RenderSVGRoot.h

    r111601 r112091  
    105105    IntSize m_containerSize;
    106106    FloatRect m_objectBoundingBox;
     107    bool m_objectBoundingBoxValid;
    107108    FloatRect m_strokeBoundingBox;
    108109    FloatRect m_repaintBoundingBox;
  • trunk/Source/WebCore/rendering/svg/SVGRenderSupport.cpp

    r111176 r112091  
    8686}
    8787
    88 void SVGRenderSupport::computeContainerBoundingBoxes(const RenderObject* container, FloatRect& objectBoundingBox, FloatRect& strokeBoundingBox, FloatRect& repaintBoundingBox)
    89 {
    90     bool isFirstChild = true;
    91 
     88// Update a bounding box taking into account the validity of the other bounding box.
     89static inline void updateObjectBoundingBox(FloatRect& objectBoundingBox, bool& objectBoundingBoxValid, RenderObject* other, FloatRect otherBoundingBox)
     90{
     91    bool otherValid = other->isSVGContainer() ? toRenderSVGContainer(other)->isObjectBoundingBoxValid() : true;
     92    if (!otherValid)
     93        return;
     94
     95    if (!objectBoundingBoxValid) {
     96        objectBoundingBox = otherBoundingBox;
     97        objectBoundingBoxValid = true;
     98        return;
     99    }
     100
     101    objectBoundingBox.uniteEvenIfEmpty(otherBoundingBox);
     102}
     103
     104void SVGRenderSupport::computeContainerBoundingBoxes(const RenderObject* container, FloatRect& objectBoundingBox, bool& objectBoundingBoxValid, FloatRect& strokeBoundingBox, FloatRect& repaintBoundingBox)
     105{
    92106    for (RenderObject* current = container->firstChild(); current; current = current->nextSibling()) {
    93107        if (current->isSVGHiddenContainer())
     
    96110        const AffineTransform& transform = current->localToParentTransform();
    97111        if (transform.isIdentity()) {
    98             if (isFirstChild)
    99                 objectBoundingBox = current->objectBoundingBox();
    100             else
    101                 objectBoundingBox.uniteEvenIfEmpty(current->objectBoundingBox());
     112            updateObjectBoundingBox(objectBoundingBox, objectBoundingBoxValid, current, current->objectBoundingBox());
    102113            strokeBoundingBox.unite(current->strokeBoundingBox());
    103114            repaintBoundingBox.unite(current->repaintRectInLocalCoordinates());
    104115        } else {
    105             if (isFirstChild)
    106                 objectBoundingBox = transform.mapRect(current->objectBoundingBox());
    107             else
    108                 objectBoundingBox.uniteEvenIfEmpty(transform.mapRect(current->objectBoundingBox()));
     116            updateObjectBoundingBox(objectBoundingBox, objectBoundingBoxValid, current, transform.mapRect(current->objectBoundingBox()));
    109117            strokeBoundingBox.unite(transform.mapRect(current->strokeBoundingBox()));
    110118            repaintBoundingBox.unite(transform.mapRect(current->repaintRectInLocalCoordinates()));
    111119        }
    112 
    113         isFirstChild = false;
    114120    }
    115121}
  • trunk/Source/WebCore/rendering/svg/SVGRenderSupport.h

    r110285 r112091  
    5858    static bool pointInClippingArea(RenderObject*, const FloatPoint&);
    5959
    60     static void computeContainerBoundingBoxes(const RenderObject* container, FloatRect& objectBoundingBox, FloatRect& strokeBoundingBox, FloatRect& repaintBoundingBox);
     60    static void computeContainerBoundingBoxes(const RenderObject* container, FloatRect& objectBoundingBox, bool& objectBoundingBoxValid, FloatRect& strokeBoundingBox, FloatRect& repaintBoundingBox);
    6161    static bool paintInfoIntersectsRepaintRect(const FloatRect& localRepaintRect, const AffineTransform& localTransform, const PaintInfo&);
    6262
Note: See TracChangeset for help on using the changeset viewer.