#include "config.h"
#include "LayoutState.h"
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
#include "DisplayBox.h"
#include "LayoutBox.h"
#include "LayoutContainer.h"
#include "RuntimeEnabledFeatures.h"
#include <wtf/IsoMallocInlines.h>
namespace WebCore {
namespace Layout {
WTF_MAKE_ISO_ALLOCATED_IMPL(LayoutState);
LayoutState::LayoutState(const LayoutTreeContent& layoutTreeContent)
: m_layoutTreeContent(makeWeakPtr(layoutTreeContent))
{
ASSERT(m_layoutTreeContent->rootLayoutBox().establishesFormattingContext());
auto quirksMode = [&] {
auto& document = m_layoutTreeContent->rootRenderer().document();
if (document.inLimitedQuirksMode())
return LayoutState::QuirksMode::Limited;
if (document.inQuirksMode())
return LayoutState::QuirksMode::Yes;
return LayoutState::QuirksMode::No;
};
setQuirksMode(quirksMode());
}
LayoutState::~LayoutState() = default;
Display::Box& LayoutState::displayBoxForRootLayoutBox()
{
return displayBoxForLayoutBox(m_layoutTreeContent->rootLayoutBox());
}
Display::Box& LayoutState::displayBoxForLayoutBox(const Box& layoutBox)
{
return *m_layoutToDisplayBox.ensure(&layoutBox, [] {
return makeUnique<Display::Box>();
}).iterator->value;
}
const Display::Box& LayoutState::displayBoxForLayoutBox(const Box& layoutBox) const
{
ASSERT(hasDisplayBox(layoutBox));
return *m_layoutToDisplayBox.get(&layoutBox);
}
FormattingState& LayoutState::formattingStateForBox(const Box& layoutBox) const
{
auto& root = layoutBox.formattingContextRoot();
RELEASE_ASSERT(m_formattingStates.contains(&root));
return *m_formattingStates.get(&root);
}
FormattingState& LayoutState::establishedFormattingState(const Container& formattingRoot) const
{
ASSERT(formattingRoot.establishesFormattingContext());
RELEASE_ASSERT(m_formattingStates.contains(&formattingRoot));
return *m_formattingStates.get(&formattingRoot);
}
FormattingState& LayoutState::createFormattingStateForFormattingRootIfNeeded(const Container& formattingContextRoot)
{
ASSERT(formattingContextRoot.establishesFormattingContext());
if (formattingContextRoot.establishesInlineFormattingContext()) {
return *m_formattingStates.ensure(&formattingContextRoot, [&] {
if (formattingContextRoot.establishesBlockFormattingContext())
return makeUnique<InlineFormattingState>(FloatingState::create(*this, formattingContextRoot), *this);
auto& parentFormattingState = createFormattingStateForFormattingRootIfNeeded(formattingContextRoot.formattingContextRoot());
auto& parentFloatingState = parentFormattingState.floatingState();
return makeUnique<InlineFormattingState>(parentFloatingState, *this);
}).iterator->value;
}
if (formattingContextRoot.establishesBlockFormattingContext()) {
return *m_formattingStates.ensure(&formattingContextRoot, [&] {
return makeUnique<BlockFormattingState>(FloatingState::create(*this, formattingContextRoot), *this);
}).iterator->value;
}
if (formattingContextRoot.establishesTableFormattingContext()) {
return *m_formattingStates.ensure(&formattingContextRoot, [&] {
return makeUnique<TableFormattingState>(FloatingState::create(*this, formattingContextRoot), *this);
}).iterator->value;
}
CRASH();
}
void LayoutState::setViewportSize(const LayoutSize& viewportSize)
{
if (RuntimeEnabledFeatures::sharedFeatures().layoutFormattingContextIntegrationEnabled()) {
m_viewportSize = viewportSize;
return;
}
ASSERT_NOT_REACHED();
}
LayoutSize LayoutState::viewportSize() const
{
if (RuntimeEnabledFeatures::sharedFeatures().layoutFormattingContextIntegrationEnabled())
return m_viewportSize;
ASSERT_NOT_REACHED();
return { };
}
bool LayoutState::isIntegratedRootBoxFirstChild() const
{
if (RuntimeEnabledFeatures::sharedFeatures().layoutFormattingContextIntegrationEnabled()) {
auto& rootRenderer = m_layoutTreeContent->rootRenderer();
ASSERT(rootRenderer.parent());
return rootRenderer.parent()->firstChild() == &rootRenderer;
}
ASSERT_NOT_REACHED();
return false;
}
}
}
#endif