/*
 * Copyright (C) 2006 Apple Computer, Inc.
 * Copyright (C) 2009 Google, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * 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., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
 */

#pragma once

#if ENABLE(SVG)
#include "AffineTransform.h"
#include "FloatPoint.h"
#include "FloatRect.h"
#include "RenderSVGBlock.h"

namespace WebCore {

class SVGForeignObjectElement;

class RenderSVGForeignObject FINAL : public RenderSVGBlock {
public:
    RenderSVGForeignObject(SVGForeignObjectElement&, PassOwnPtr<RenderStyle>);
    virtual ~RenderSVGForeignObject();

    SVGForeignObjectElement& foreignObjectElement() const;

    virtual const char* renderName() const FINAL { return "RenderSVGForeignObject"; }

    virtual void paint(PaintInfo&, const LayoutPoint&) FINAL;

    virtual LayoutRect clippedOverflowRectForRepaint(RenderLayerModelObject* repaintContainer) const FINAL;
    virtual Optional<FloatRect> computeFloatVisibleRectInContainer(const FloatRect&, const RenderLayerModelObject* container, VisibleRectContext) const override;
    virtual Optional<LayoutRect> computeVisibleRectInContainer(const LayoutRect&, const RenderLayerModelObject* container, VisibleRectContext) const override;

    virtual bool requiresLayer() const FINAL { return false; }
    virtual void layout() FINAL;

    virtual FloatRect objectBoundingBox() const FINAL { return FloatRect(FloatPoint(), m_viewport.size()); }
    virtual FloatRect strokeBoundingBox() const FINAL { return FloatRect(FloatPoint(), m_viewport.size()); }
    virtual FloatRect repaintRectInLocalCoordinates() const FINAL { return FloatRect(FloatPoint(), m_viewport.size()); }

    virtual bool nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint& pointInParent, HitTestAction) FINAL;
    virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) FINAL;

    virtual void mapLocalToContainer(RenderLayerModelObject* repaintContainer, TransformState&, OptionSet<MapCoordinatesMode>, bool* wasFixed) const FINAL;
	virtual const RenderElement* pushMappingToContainer(const RenderLayerModelObject* ancestorToStopAt, RenderGeometryMap&) const FINAL;
    virtual void setNeedsTransformUpdate() { m_needsTransformUpdate = true; }

private:
    virtual void updateLogicalWidth() FINAL;
    virtual LogicalExtentComputedValues computeLogicalHeight(LayoutUnit logicalHeight, LayoutUnit logicalTop) const FINAL;

    virtual const AffineTransform& localToParentTransform() const;
    virtual AffineTransform localTransform() const { return m_localTransform; }

#if ENABLE(LAYER_BASED_SVG_ENGINE)
    LayoutSize offsetFromContainer(RenderElement&, const LayoutPoint&, bool* offsetDependsOnPoint = nullptr) const override;
#endif

    bool m_needsTransformUpdate;
    FloatRect m_viewport;
    AffineTransform m_localTransform;
    mutable AffineTransform m_localToParentTransform;
};

template <> inline bool isRendererOfType<RenderSVGForeignObject>(const RenderObject& renderer) { return renderer.isSVGForeignObject(); }
template <> inline bool isRendererOfType<const RenderSVGForeignObject>(const RenderObject& renderer) { return renderer.isSVGForeignObject(); }
RENDER_OBJECT_TYPE_CASTS(RenderSVGForeignObject, isSVGForeignObject())

}

//SPECIALIZE_TYPE_TRAITS_RENDER_OBJECT(RenderSVGForeignObject, isSVGForeignObject())

#endif
