#include "config.h"
#include "RenderIFrame.h"
#include "Frame.h"
#include "FrameView.h"
#include "HTMLIFrameElement.h"
#include "HTMLNames.h"
#include "Page.h"
#include "RenderView.h"
#include "Settings.h"
#include <wtf/StackStats.h>
namespace WebCore {
using namespace HTMLNames;
RenderIFrame::RenderIFrame(Element* element)
: RenderFrameBase(element)
{
}
bool RenderIFrame::shouldComputeSizeAsReplaced() const
{
return !isSeamless();
}
bool RenderIFrame::isInlineBlockOrInlineTable() const
{
return isSeamless() && isInline();
}
LayoutUnit RenderIFrame::minPreferredLogicalWidth() const
{
if (!isSeamless())
return RenderFrameBase::minPreferredLogicalWidth();
RenderView* childRoot = contentRootRenderer();
if (!childRoot)
return 0;
return childRoot->minPreferredLogicalWidth() + borderAndPaddingLogicalWidth();
}
LayoutUnit RenderIFrame::maxPreferredLogicalWidth() const
{
if (!isSeamless())
return RenderFrameBase::maxPreferredLogicalWidth();
RenderView* childRoot = contentRootRenderer();
if (!childRoot)
return 0;
return childRoot->maxPreferredLogicalWidth() + borderAndPaddingLogicalWidth();
}
bool RenderIFrame::isSeamless() const
{
return node() && node()->hasTagName(iframeTag) && static_cast<HTMLIFrameElement*>(node())->shouldDisplaySeamlessly();
}
bool RenderIFrame::requiresLayer() const
{
return RenderFrameBase::requiresLayer() || style()->resize() != RESIZE_NONE;
}
RenderView* RenderIFrame::contentRootRenderer() const
{
ASSERT(!widget() || widget()->isFrameView());
FrameView* childFrameView = toFrameView(widget());
return childFrameView ? childFrameView->frame()->contentRenderer() : 0;
}
bool RenderIFrame::flattenFrame() const
{
if (!node() || !node()->hasTagName(iframeTag))
return false;
HTMLIFrameElement* element = static_cast<HTMLIFrameElement*>(node());
Frame* frame = element->document()->frame();
if (isSeamless())
return false;
bool enabled = frame && frame->settings() && frame->settings()->frameFlatteningEnabled();
if (!enabled || !frame->page())
return false;
if (style()->width().isFixed() && style()->height().isFixed()) {
if (element->scrollingMode() == ScrollbarAlwaysOff)
return false;
if (style()->width().value() <= 0 || style()->height().value() <= 0)
return false;
}
IntRect boundingRect = absoluteBoundingBoxRectIgnoringTransforms();
return boundingRect.maxX() > 0 && boundingRect.maxY() > 0;
}
void RenderIFrame::layoutSeamlessly()
{
updateLogicalWidth();
setLogicalHeight(0);
updateWidgetPosition();
FrameView* childFrameView = toFrameView(widget());
if (childFrameView) setLogicalHeight(childFrameView->contentsHeight() + borderTop() + borderBottom() + paddingTop() + paddingBottom());
updateLogicalHeight();
updateWidgetPosition();
RenderView* childRoot = childFrameView ? childFrameView->frame()->contentRenderer() : 0;
ASSERT(!childFrameView || !childFrameView->layoutPending());
ASSERT_UNUSED(childRoot, !childRoot || !childRoot->needsLayout());
}
void RenderIFrame::layout()
{
StackStats::LayoutCheckPoint layoutCheckPoint;
ASSERT(needsLayout());
if (isSeamless()) {
layoutSeamlessly();
} else {
updateLogicalWidth();
updateLogicalHeight();
if (flattenFrame())
layoutWithFlattening(style()->width().isFixed(), style()->height().isFixed());
}
m_overflow.clear();
addVisualEffectOverflow();
updateLayerTransform();
setNeedsLayout(false);
}
}