2009-01-23 David Hyatt <hyatt@apple.com>
[WebKit-https.git] / WebCore / rendering / RenderForeignObject.cpp
index 12cc228..fc12570 100644 (file)
  *
  * You should have received a copy of the GNU Library General Public License
  * along with this library; see the file COPYING.LIB.  If not, write to
- * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 02111-1307, USA.
+ * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
  *
  */
 
 #include "config.h"
-#ifdef SVG_SUPPORT
+
+#if ENABLE(SVG) && ENABLE(SVG_FOREIGN_OBJECT)
 #include "RenderForeignObject.h"
 
 #include "GraphicsContext.h"
-#include "KRenderingDevice.h"
-#include "SVGLength.h"
+#include "RenderView.h"
 #include "SVGForeignObjectElement.h"
+#include "SVGLength.h"
+#include "SVGTransformList.h"
 
 namespace WebCore {
 
-RenderForeignObject::RenderForeignObject(SVGForeignObjectElement *node) 
-    : RenderBlock(node)
+RenderForeignObject::RenderForeignObject(SVGForeignObjectElementnode) 
+    : RenderSVGBlock(node)
 {
 }
 
-AffineTransform RenderForeignObject::translationForAttributes()
+TransformationMatrix RenderForeignObject::translationForAttributes()
 {
     SVGForeignObjectElement* foreign = static_cast<SVGForeignObjectElement*>(element());
-    return AffineTransform().translate(foreign->x()->value(), foreign->y()->value());
+    return TransformationMatrix().translate(foreign->x().value(foreign), foreign->y().value(foreign));
 }
 
 void RenderForeignObject::paint(PaintInfo& paintInfo, int parentX, int parentY)
 {
-    if (paintInfo.p->paintingDisabled())
+    if (paintInfo.context->paintingDisabled())
         return;
 
-    KRenderingDevice *device = renderingDevice();
-    KRenderingDeviceContext* context = device->currentContext();
-    bool shouldPopContext = false;
-    if (!context) {
-        // Only need to setup for KCanvas rendering if it hasn't already been done.
-        context = paintInfo.p->createRenderingDeviceContext();
-        device->pushContext(context);
-        shouldPopContext = true;
-    }
-
-    paintInfo.p->save();
-
-    context->concatCTM(AffineTransform().translate(parentX, parentY));
-    context->concatCTM(localTransform());
-    context->concatCTM(translationForAttributes());
-
-    paintInfo.p->clip(getClipRect(parentX, parentY));
+    paintInfo.context->save();
+    paintInfo.context->concatCTM(TransformationMatrix().translate(parentX, parentY));
+    paintInfo.context->concatCTM(localTransform());
+    paintInfo.context->concatCTM(translationForAttributes());
+    paintInfo.context->clip(getClipRect(parentX, parentY));
 
     float opacity = style()->opacity();
     if (opacity < 1.0f)
         // FIXME: Possible optimization by clipping to bbox here, once relativeBBox is implemented & clip, mask and filter support added.
-        paintInfo.p->beginTransparencyLayer(opacity);
+        paintInfo.context->beginTransparencyLayer(opacity);
 
     PaintInfo pi(paintInfo);
-    pi.r = absoluteTransform().invert().mapRect(paintInfo.r);
+    pi.rect = absoluteTransform().inverse().mapRect(paintInfo.rect);
     RenderBlock::paint(pi, 0, 0);
 
     if (opacity < 1.0f)
-        paintInfo.p->endTransparencyLayer();
-    
-    if (shouldPopContext) {
-        device->popContext();
-        delete context;
-    }
+        paintInfo.context->endTransparencyLayer();
 
-    paintInfo.p->restore();
+    paintInfo.context->restore();
 }
 
 void RenderForeignObject::computeAbsoluteRepaintRect(IntRect& r, bool f)
 {
-    AffineTransform transform = translationForAttributes() * localTransform();
+    TransformationMatrix transform = translationForAttributes() * localTransform();
     r = transform.mapRect(r);
-    
+
     RenderBlock::computeAbsoluteRepaintRect(r, f);
 }
 
-bool RenderForeignObject::requiresLayer()
+bool RenderForeignObject::calculateLocalTransform()
 {
-    return false;
+    TransformationMatrix oldTransform = m_localTransform;
+    m_localTransform = static_cast<SVGForeignObjectElement*>(element())->animatedLocalTransform();
+    return (oldTransform != m_localTransform);
 }
 
 void RenderForeignObject::layout()
 {
     ASSERT(needsLayout());
-    ASSERT(minMaxKnown());
+
+    // Arbitrary affine transforms are incompatible with LayoutState.
+    view()->disableLayoutState();
 
     IntRect oldBounds;
+    IntRect oldOutlineBox;
     bool checkForRepaint = checkForRepaintDuringLayout();
-    if (checkForRepaint)
+    if (checkForRepaint) {
         oldBounds = m_absoluteBounds;
-
+        oldOutlineBox = absoluteOutlineBounds();
+    }
+    
+    calculateLocalTransform();
+    
     RenderBlock::layout();
 
-    m_absoluteBounds = getAbsoluteRepaintRect();
+    m_absoluteBounds = absoluteClippedOverflowRect();
 
     if (checkForRepaint)
-        repaintAfterLayoutIfNeeded(oldBounds, oldBounds);
-    
+        repaintAfterLayoutIfNeeded(oldBounds, oldOutlineBox);
+
+    view()->enableLayoutState();
     setNeedsLayout(false);
 }
 
-bool RenderForeignObject::nodeAtPoint(HitTestResult& result, int x, int y, int tx, int ty, HitTestAction hitTestAction)
+bool RenderForeignObject::nodeAtPoint(const HitTestRequest& request, HitTestResult& result, int x, int y, int tx, int ty, HitTestAction hitTestAction)
 {
-    AffineTransform totalTransform = absoluteTransform();
+    TransformationMatrix totalTransform = absoluteTransform();
     totalTransform *= translationForAttributes();
     double localX, localY;
-    totalTransform.invert().map(x, y, &localX, &localY);
-    return RenderBlock::nodeAtPoint(result, (int)localX, (int)localY, tx, ty, hitTestAction);
+    totalTransform.inverse().map(x, y, &localX, &localY);
+    return RenderBlock::nodeAtPoint(request, result, static_cast<int>(localX), static_cast<int>(localY), tx, ty, hitTestAction);
 }
 
-}
+} // namespace WebCore
 
-#endif // SVG_SUPPORT
+#endif // ENABLE(SVG) && ENABLE(SVG_FOREIGN_OBJECT)