RenderFrameBase.cpp [plain text]
#include "config.h"
#include "RenderFrameBase.h"
#include "Frame.h"
#include "FrameView.h"
#include "HTMLFrameElementBase.h"
#include "RenderView.h"
namespace WebCore {
RenderFrameBase::RenderFrameBase(HTMLFrameElementBase& element, RenderStyle&& style)
: RenderWidget(element, WTFMove(style))
{
}
inline bool shouldExpandFrame(LayoutUnit width, LayoutUnit height, bool hasFixedWidth, bool hasFixedHeight)
{
if (!width || !height)
return false;
static const unsigned smallestUsefullyScrollableDimension = 8;
if (hasFixedWidth && width < LayoutUnit(smallestUsefullyScrollableDimension))
return false;
if (hasFixedHeight && height < LayoutUnit(smallestUsefullyScrollableDimension))
return false;
return true;
}
void RenderFrameBase::layoutWithFlattening(bool hasFixedWidth, bool hasFixedHeight)
{
view().protectRenderWidgetUntilLayoutIsDone(*this);
peformLayoutWithFlattening(hasFixedWidth, hasFixedHeight);
clearNeedsLayout();
}
RenderView* RenderFrameBase::childRenderView() const
{
if (!childView())
return nullptr;
return childView()->renderView();
}
void RenderFrameBase::peformLayoutWithFlattening(bool hasFixedWidth, bool hasFixedHeight)
{
if (!childRenderView())
return;
if (!shouldExpandFrame(width(), height(), hasFixedWidth, hasFixedHeight)) {
if (updateWidgetPosition() == ChildWidgetState::Destroyed)
return;
childView()->layout();
return;
}
if (updateWidgetPosition() == ChildWidgetState::Destroyed)
return;
bool isScrollable = frameOwnerElement().scrollingMode() != ScrollbarAlwaysOff;
int hBorder = borderLeft() + borderRight();
int vBorder = borderTop() + borderBottom();
if (isScrollable || !hasFixedWidth) {
ASSERT(childRenderView());
setWidth(std::max(width(), childRenderView()->minPreferredLogicalWidth() + hBorder));
if (updateWidgetPosition() == ChildWidgetState::Destroyed)
return;
childView()->layout();
}
ASSERT(childView());
if (isScrollable || !hasFixedHeight || childRenderView()->isFrameSet())
setHeight(std::max<LayoutUnit>(height(), childView()->contentsHeight() + vBorder));
if (isScrollable || !hasFixedWidth || childRenderView()->isFrameSet())
setWidth(std::max<LayoutUnit>(width(), childView()->contentsWidth() + hBorder));
if (updateWidgetPosition() == ChildWidgetState::Destroyed)
return;
ASSERT(!childView()->layoutPending());
ASSERT(!childRenderView()->needsLayout());
ASSERT(!childRenderView()->firstChild() || !childRenderView()->firstChild()->firstChildSlow() || !childRenderView()->firstChild()->firstChildSlow()->needsLayout());
}
}