#include "config.h"
#include "DisplayStyle.h"
#if ENABLE(LAYOUT_FORMATTING_CONTEXT)
#include "BorderData.h"
#include "FillLayer.h"
#include "RenderStyle.h"
#include "ShadowData.h"
#include <wtf/IsoMallocInlines.h>
namespace WebCore {
namespace Display {
static RefPtr<FillLayer> deepCopy(const FillLayer& layer)
{
RefPtr<FillLayer> firstLayer;
FillLayer* currCopiedLayer = nullptr;
for (auto* currLayer = &layer; currLayer; currLayer = currLayer->next()) {
RefPtr<FillLayer> layerCopy = currLayer->copy();
if (!firstLayer) {
firstLayer = layerCopy;
currCopiedLayer = layerCopy.get();
} else {
auto nextCopiedLayer = layerCopy.get();
currCopiedLayer->setNext(WTFMove(layerCopy));
currCopiedLayer = nextCopiedLayer;
}
}
return firstLayer;
}
static std::unique_ptr<ShadowData> deepCopy(const ShadowData* shadow, const RenderStyle& style)
{
std::unique_ptr<ShadowData> firstShadow;
ShadowData* currCopiedShadow = nullptr;
for (auto* currShadow = shadow; currShadow; currShadow = currShadow->next()) {
auto shadowCopy = makeUnique<ShadowData>(*currShadow);
shadowCopy->setColor(style.colorByApplyingColorFilter(shadowCopy->color()));
if (!firstShadow) {
currCopiedShadow = shadowCopy.get();
firstShadow = WTFMove(shadowCopy);
} else {
auto nextCopiedShadow = shadowCopy.get();
currCopiedShadow->setNext(WTFMove(shadowCopy));
currCopiedShadow = nextCopiedShadow;
}
}
return firstShadow;
}
Style::Style(const RenderStyle& style)
: Style(style, &style)
{
}
Style::Style(const RenderStyle& style, const RenderStyle* styleForBackground)
: m_overflowX(style.overflowX())
, m_overflowY(style.overflowY())
, m_fontCascade(style.fontCascade())
, m_whiteSpace(style.whiteSpace())
, m_tabSize(style.tabSize())
, m_opacity(style.opacity())
{
m_color = style.visitedDependentColorWithColorFilter(CSSPropertyColor);
if (styleForBackground)
setupBackground(*styleForBackground);
m_boxShadow = deepCopy(style.boxShadow(), style);
if (!style.hasAutoUsedZIndex())
m_zIndex = style.usedZIndex();
setIsPositioned(style.position() != PositionType::Static);
setIsFloating(style.floating() != Float::No);
setHasTransform(style.hasTransform());
}
void Style::setupBackground(const RenderStyle& style)
{
m_backgroundColor = style.visitedDependentColorWithColorFilter(CSSPropertyBackgroundColor);
m_backgroundLayers = deepCopy(style.backgroundLayers());
}
bool Style::hasBackground() const
{
return m_backgroundColor.isVisible() || hasBackgroundImage();
}
bool Style::hasBackgroundImage() const
{
return m_backgroundLayers && m_backgroundLayers->hasImage();
}
bool Style::backgroundHasOpaqueTopLayer() const
{
auto* fillLayer = backgroundLayers();
if (!fillLayer)
return false;
if (fillLayer->clip() != FillBox::Border)
return false;
if (!fillLayer->next() && !fillLayer->hasImage()) {
if (backgroundColor().isOpaque())
return true;
}
return false;
}
bool Style::autoWrap() const
{
return RenderStyle::autoWrap(whiteSpace());
}
bool Style::preserveNewline() const
{
return RenderStyle::preserveNewline(whiteSpace());
}
bool Style::collapseWhiteSpace() const
{
return RenderStyle::collapseWhiteSpace(whiteSpace());
}
} }
#endif // ENABLE(LAYOUT_FORMATTING_CONTEXT)