| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006 Apple Computer, Inc. | 2 * Copyright (C) 2006 Apple Computer, Inc. |
| 3 * Copyright (C) 2009 Google, Inc. | 3 * Copyright (C) 2009 Google, Inc. |
| 4 * Copyright (C) Research In Motion Limited 2010. All rights reserved. | 4 * Copyright (C) Research In Motion Limited 2010. All rights reserved. |
| 5 * | 5 * |
| 6 * This library is free software; you can redistribute it and/or | 6 * This library is free software; you can redistribute it and/or |
| 7 * modify it under the terms of the GNU Library General Public | 7 * modify it under the terms of the GNU Library General Public |
| 8 * License as published by the Free Software Foundation; either | 8 * License as published by the Free Software Foundation; either |
| 9 * version 2 of the License, or (at your option) any later version. | 9 * version 2 of the License, or (at your option) any later version. |
| 10 * | 10 * |
| 11 * This library is distributed in the hope that it will be useful, | 11 * This library is distributed in the hope that it will be useful, |
| 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 * Library General Public License for more details. | 14 * Library General Public License for more details. |
| 15 * | 15 * |
| 16 * You should have received a copy of the GNU Library General Public License | 16 * You should have received a copy of the GNU Library General Public License |
| 17 * along with this library; see the file COPYING.LIB. If not, write to | 17 * along with this library; see the file COPYING.LIB. If not, write to |
| 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 19 * Boston, MA 02110-1301, USA. | 19 * Boston, MA 02110-1301, USA. |
| 20 */ | 20 */ |
| 21 | 21 |
| 22 #include "config.h" | 22 #include "config.h" |
| 23 | 23 |
| 24 #include "core/rendering/svg/RenderSVGForeignObject.h" | 24 #include "core/layout/svg/LayoutSVGForeignObject.h" |
| 25 | 25 |
| 26 #include "core/layout/HitTestResult.h" | 26 #include "core/layout/HitTestResult.h" |
| 27 #include "core/layout/svg/SVGLayoutSupport.h" | 27 #include "core/layout/svg/SVGLayoutSupport.h" |
| 28 #include "core/layout/svg/SVGResourcesCache.h" | 28 #include "core/layout/svg/SVGResourcesCache.h" |
| 29 #include "core/paint/SVGForeignObjectPainter.h" | 29 #include "core/paint/SVGForeignObjectPainter.h" |
| 30 #include "core/rendering/RenderView.h" | 30 #include "core/rendering/RenderView.h" |
| 31 #include "core/svg/SVGForeignObjectElement.h" | 31 #include "core/svg/SVGForeignObjectElement.h" |
| 32 | 32 |
| 33 namespace blink { | 33 namespace blink { |
| 34 | 34 |
| 35 RenderSVGForeignObject::RenderSVGForeignObject(SVGForeignObjectElement* node) | 35 LayoutSVGForeignObject::LayoutSVGForeignObject(SVGForeignObjectElement* node) |
| 36 : RenderSVGBlock(node) | 36 : RenderSVGBlock(node) |
| 37 , m_needsTransformUpdate(true) | 37 , m_needsTransformUpdate(true) |
| 38 { | 38 { |
| 39 } | 39 } |
| 40 | 40 |
| 41 RenderSVGForeignObject::~RenderSVGForeignObject() | 41 LayoutSVGForeignObject::~LayoutSVGForeignObject() |
| 42 { | 42 { |
| 43 } | 43 } |
| 44 | 44 |
| 45 bool RenderSVGForeignObject::isChildAllowed(LayoutObject* child, const LayoutSty
le& style) const | 45 bool LayoutSVGForeignObject::isChildAllowed(LayoutObject* child, const LayoutSty
le& style) const |
| 46 { | 46 { |
| 47 // Disallow arbitary SVG content. Only allow proper <svg xmlns="svgNS"> subd
ocuments. | 47 // Disallow arbitary SVG content. Only allow proper <svg xmlns="svgNS"> subd
ocuments. |
| 48 return !child->isSVG() || child->isSVGRoot(); | 48 return !child->isSVG() || child->isSVGRoot(); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void RenderSVGForeignObject::paint(const PaintInfo& paintInfo, const LayoutPoint
&) | 51 void LayoutSVGForeignObject::paint(const PaintInfo& paintInfo, const LayoutPoint
&) |
| 52 { | 52 { |
| 53 SVGForeignObjectPainter(*this).paint(paintInfo); | 53 SVGForeignObjectPainter(*this).paint(paintInfo); |
| 54 } | 54 } |
| 55 | 55 |
| 56 const AffineTransform& RenderSVGForeignObject::localToParentTransform() const | 56 const AffineTransform& LayoutSVGForeignObject::localToParentTransform() const |
| 57 { | 57 { |
| 58 m_localToParentTransform = localTransform(); | 58 m_localToParentTransform = localTransform(); |
| 59 m_localToParentTransform.translate(m_viewport.x(), m_viewport.y()); | 59 m_localToParentTransform.translate(m_viewport.x(), m_viewport.y()); |
| 60 return m_localToParentTransform; | 60 return m_localToParentTransform; |
| 61 } | 61 } |
| 62 | 62 |
| 63 void RenderSVGForeignObject::updateLogicalWidth() | 63 void LayoutSVGForeignObject::updateLogicalWidth() |
| 64 { | 64 { |
| 65 // FIXME: Investigate in size rounding issues | 65 // FIXME: Investigate in size rounding issues |
| 66 // FIXME: Remove unnecessary rounding when layout is off ints: webkit.org/b/
63656 | 66 // FIXME: Remove unnecessary rounding when layout is off ints: webkit.org/b/
63656 |
| 67 setWidth(static_cast<int>(roundf(m_viewport.width()))); | 67 setWidth(static_cast<int>(roundf(m_viewport.width()))); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void RenderSVGForeignObject::computeLogicalHeight(LayoutUnit, LayoutUnit logical
Top, LogicalExtentComputedValues& computedValues) const | 70 void LayoutSVGForeignObject::computeLogicalHeight(LayoutUnit, LayoutUnit logical
Top, LogicalExtentComputedValues& computedValues) const |
| 71 { | 71 { |
| 72 // FIXME: Investigate in size rounding issues | 72 // FIXME: Investigate in size rounding issues |
| 73 // FIXME: Remove unnecessary rounding when layout is off ints: webkit.org/b/
63656 | 73 // FIXME: Remove unnecessary rounding when layout is off ints: webkit.org/b/
63656 |
| 74 // FIXME: Is this correct for vertical writing mode? | 74 // FIXME: Is this correct for vertical writing mode? |
| 75 computedValues.m_extent = static_cast<int>(roundf(m_viewport.height())); | 75 computedValues.m_extent = static_cast<int>(roundf(m_viewport.height())); |
| 76 computedValues.m_position = logicalTop; | 76 computedValues.m_position = logicalTop; |
| 77 } | 77 } |
| 78 | 78 |
| 79 void RenderSVGForeignObject::layout() | 79 void LayoutSVGForeignObject::layout() |
| 80 { | 80 { |
| 81 ASSERT(needsLayout()); | 81 ASSERT(needsLayout()); |
| 82 | 82 |
| 83 SVGForeignObjectElement* foreign = toSVGForeignObjectElement(node()); | 83 SVGForeignObjectElement* foreign = toSVGForeignObjectElement(node()); |
| 84 | 84 |
| 85 bool updateCachedBoundariesInParents = false; | 85 bool updateCachedBoundariesInParents = false; |
| 86 if (m_needsTransformUpdate) { | 86 if (m_needsTransformUpdate) { |
| 87 m_localTransform = foreign->calculateAnimatedLocalTransform(); | 87 m_localTransform = foreign->calculateAnimatedLocalTransform(); |
| 88 m_needsTransformUpdate = false; | 88 m_needsTransformUpdate = false; |
| 89 updateCachedBoundariesInParents = true; | 89 updateCachedBoundariesInParents = true; |
| 90 } | 90 } |
| 91 | 91 |
| 92 FloatRect oldViewport = m_viewport; | 92 FloatRect oldViewport = m_viewport; |
| 93 | 93 |
| 94 // Cache viewport boundaries | 94 // Cache viewport boundaries |
| 95 SVGLengthContext lengthContext(foreign); | 95 SVGLengthContext lengthContext(foreign); |
| 96 FloatPoint viewportLocation(foreign->x()->currentValue()->value(lengthContex
t), foreign->y()->currentValue()->value(lengthContext)); | 96 FloatPoint viewportLocation(foreign->x()->currentValue()->value(lengthContex
t), foreign->y()->currentValue()->value(lengthContext)); |
| 97 m_viewport = FloatRect(viewportLocation, FloatSize(foreign->width()->current
Value()->value(lengthContext), foreign->height()->currentValue()->value(lengthCo
ntext))); | 97 m_viewport = FloatRect(viewportLocation, FloatSize(foreign->width()->current
Value()->value(lengthContext), foreign->height()->currentValue()->value(lengthCo
ntext))); |
| 98 if (!updateCachedBoundariesInParents) | 98 if (!updateCachedBoundariesInParents) |
| 99 updateCachedBoundariesInParents = oldViewport != m_viewport; | 99 updateCachedBoundariesInParents = oldViewport != m_viewport; |
| 100 | 100 |
| 101 // Set box origin to the foreignObject x/y translation, so positioned object
s in XHTML content get correct | 101 // Set box origin to the foreignObject x/y translation, so positioned object
s in XHTML content get correct |
| 102 // positions. A regular RenderBoxModelObject would pull this information fro
m LayoutStyle - in SVG those | 102 // positions. A regular RenderBoxModelObject would pull this information fro
m LayoutStyle - in SVG those |
| 103 // properties are ignored for non <svg> elements, so we mimic what happens w
hen specifying them through CSS. | 103 // properties are ignored for non <svg> elements, so we mimic what happens w
hen specifying them through CSS. |
| 104 | 104 |
| 105 // FIXME: Investigate in location rounding issues - only affects RenderSVGFo
reignObject & LayoutSVGText | 105 // FIXME: Investigate in location rounding issues - only affects LayoutSVGFo
reignObject & LayoutSVGText |
| 106 setLocation(roundedIntPoint(viewportLocation)); | 106 setLocation(roundedIntPoint(viewportLocation)); |
| 107 | 107 |
| 108 bool layoutChanged = everHadLayout() && selfNeedsLayout(); | 108 bool layoutChanged = everHadLayout() && selfNeedsLayout(); |
| 109 RenderBlock::layout(); | 109 RenderBlock::layout(); |
| 110 ASSERT(!needsLayout()); | 110 ASSERT(!needsLayout()); |
| 111 | 111 |
| 112 // If our bounds changed, notify the parents. | 112 // If our bounds changed, notify the parents. |
| 113 if (updateCachedBoundariesInParents) | 113 if (updateCachedBoundariesInParents) |
| 114 RenderSVGBlock::setNeedsBoundariesUpdate(); | 114 RenderSVGBlock::setNeedsBoundariesUpdate(); |
| 115 | 115 |
| 116 // Invalidate all resources of this client if our layout changed. | 116 // Invalidate all resources of this client if our layout changed. |
| 117 if (layoutChanged) | 117 if (layoutChanged) |
| 118 SVGResourcesCache::clientLayoutChanged(this); | 118 SVGResourcesCache::clientLayoutChanged(this); |
| 119 } | 119 } |
| 120 | 120 |
| 121 bool RenderSVGForeignObject::nodeAtFloatPoint(const HitTestRequest& request, Hit
TestResult& result, const FloatPoint& pointInParent, HitTestAction hitTestAction
) | 121 bool LayoutSVGForeignObject::nodeAtFloatPoint(const HitTestRequest& request, Hit
TestResult& result, const FloatPoint& pointInParent, HitTestAction hitTestAction
) |
| 122 { | 122 { |
| 123 // Embedded content is drawn in the foreground phase. | 123 // Embedded content is drawn in the foreground phase. |
| 124 if (hitTestAction != HitTestForeground) | 124 if (hitTestAction != HitTestForeground) |
| 125 return false; | 125 return false; |
| 126 | 126 |
| 127 AffineTransform localTransform = this->localTransform(); | 127 AffineTransform localTransform = this->localTransform(); |
| 128 if (!localTransform.isInvertible()) | 128 if (!localTransform.isInvertible()) |
| 129 return false; | 129 return false; |
| 130 | 130 |
| 131 FloatPoint localPoint = localTransform.inverse().mapPoint(pointInParent); | 131 FloatPoint localPoint = localTransform.inverse().mapPoint(pointInParent); |
| 132 | 132 |
| 133 // Early exit if local point is not contained in clipped viewport area | 133 // Early exit if local point is not contained in clipped viewport area |
| 134 if (SVGLayoutSupport::isOverflowHidden(this) && !m_viewport.contains(localPo
int)) | 134 if (SVGLayoutSupport::isOverflowHidden(this) && !m_viewport.contains(localPo
int)) |
| 135 return false; | 135 return false; |
| 136 | 136 |
| 137 // FOs establish a stacking context, so we need to hit-test all layers. | 137 // FOs establish a stacking context, so we need to hit-test all layers. |
| 138 HitTestLocation hitTestLocation(roundedLayoutPoint(localPoint)); | 138 HitTestLocation hitTestLocation(roundedLayoutPoint(localPoint)); |
| 139 return RenderBlock::nodeAtPoint(request, result, hitTestLocation, LayoutPoin
t(), HitTestForeground) | 139 return RenderBlock::nodeAtPoint(request, result, hitTestLocation, LayoutPoin
t(), HitTestForeground) |
| 140 || RenderBlock::nodeAtPoint(request, result, hitTestLocation, LayoutPoin
t(), HitTestFloat) | 140 || RenderBlock::nodeAtPoint(request, result, hitTestLocation, LayoutPoin
t(), HitTestFloat) |
| 141 || RenderBlock::nodeAtPoint(request, result, hitTestLocation, LayoutPoin
t(), HitTestChildBlockBackgrounds); | 141 || RenderBlock::nodeAtPoint(request, result, hitTestLocation, LayoutPoin
t(), HitTestChildBlockBackgrounds); |
| 142 } | 142 } |
| 143 | 143 |
| 144 } | 144 } |
| OLD | NEW |