RenderPartObject.cpp [plain text]
#include "config.h"
#include "RenderPartObject.h"
#include "Frame.h"
#include "FrameLoaderClient.h"
#include "HTMLEmbedElement.h"
#include "HTMLIFrameElement.h"
#include "HTMLNames.h"
#include "HTMLObjectElement.h"
#include "HTMLParamElement.h"
#include "MIMETypeRegistry.h"
#include "Page.h"
#include "PluginData.h"
#include "RenderView.h"
#include "RenderWidgetProtector.h"
#include "Text.h"
#include "Settings.h"
#if ENABLE(PLUGIN_PROXY_FOR_VIDEO)
#include "HTMLVideoElement.h"
#endif
namespace WebCore {
using namespace HTMLNames;
RenderPartObject::RenderPartObject(Element* element)
: RenderPart(element)
, m_didResizeFrameToContent(false)
{
}
void RenderPartObject::calcWidth()
{
RenderPart::calcWidth();
if (!suggestResizeFrameToContent())
return;
if (!style()->width().isFixed() || static_cast<HTMLIFrameElement*>(node())->scrollingMode() != ScrollbarAlwaysOff)
setWidth(max(width(), static_cast<FrameView*>(widget())->contentsWidth()));
}
void RenderPartObject::calcHeight()
{
RenderPart::calcHeight();
if (!suggestResizeFrameToContent())
return;
if (!style()->height().isFixed() || static_cast<HTMLIFrameElement*>(node())->scrollingMode() != ScrollbarAlwaysOff)
setHeight(max(height(), static_cast<FrameView*>(widget())->contentsHeight()));
}
bool RenderPartObject::suggestResizeFrameToContent() const
{
Document* document = node() ? node()->document() : 0;
return widget() && widget()->isFrameView() && document && node()->hasTagName(iframeTag) && document->frame() &&
document->frame()->settings() && document->frame()->settings()->flatFrameSetLayoutEnabled() &&
!style()->width().isZero() && !style()->height().isZero() &&
(static_cast<HTMLIFrameElement*>(node())->scrollingMode() != ScrollbarAlwaysOff || !style()->width().isFixed() || !style()->height().isFixed());
}
void RenderPartObject::layout()
{
ASSERT(needsLayout());
FrameView* childFrameView;
RenderView* childRoot;
bool shouldResize = suggestResizeFrameToContent();
if (shouldResize) {
childFrameView = static_cast<FrameView*>(widget());
childRoot = childFrameView->frame()->contentRenderer();
if (childRoot && childRoot->prefWidthsDirty())
childRoot->calcPrefWidths();
}
RenderPart::calcWidth();
RenderPart::calcHeight();
adjustOverflowForBoxShadowAndReflect();
if (shouldResize && isPositioned() && containingBlock() == view() && ((x() + width() <= 0) || (y() + height() <= 0)))
shouldResize = false;
if (shouldResize) {
bool scrolling = static_cast<HTMLIFrameElement*>(node())->scrollingMode() != ScrollbarAlwaysOff;
if (childRoot && (scrolling || !style()->width().isFixed()))
setWidth(max(width(), childRoot->minPrefWidth()));
updateWidgetPosition();
do
childFrameView->layout();
while (childFrameView->layoutPending() || (childRoot && childRoot->needsLayout()));
if (scrolling || !style()->height().isFixed())
setHeight(max(height(), childFrameView->contentsHeight()));
if (scrolling || !style()->width().isFixed())
setWidth(max(width(), childFrameView->contentsWidth()));
updateWidgetPosition();
m_didResizeFrameToContent = true;
ASSERT(!childFrameView->layoutPending());
ASSERT(!childRoot || !childRoot->needsLayout());
ASSERT(!childRoot || !childRoot->firstChild() || !childRoot->firstChild()->firstChild() || !childRoot->firstChild()->firstChild()->needsLayout());
} else {
if (m_didResizeFrameToContent && widget()) {
updateWidgetPosition();
static_cast<FrameView*>(widget())->layout();
}
m_didResizeFrameToContent = false;
RenderPart::layout();
}
setNeedsLayout(false);
}
void RenderPartObject::viewCleared()
{
if (node() && widget() && widget()->isFrameView()) {
FrameView* view = static_cast<FrameView*>(widget());
int marginw = -1;
int marginh = -1;
if (node()->hasTagName(iframeTag)) {
HTMLIFrameElement* frame = static_cast<HTMLIFrameElement*>(node());
marginw = frame->getMarginWidth();
marginh = frame->getMarginHeight();
}
if (marginw != -1)
view->setMarginWidth(marginw);
if (marginh != -1)
view->setMarginHeight(marginh);
}
}
}