CSSGridTemplateAreasValue.cpp [plain text]
#include "config.h"
#include "CSSGridTemplateAreasValue.h"
#include "GridArea.h"
#include <wtf/text/StringBuilder.h>
namespace WebCore {
CSSGridTemplateAreasValue::CSSGridTemplateAreasValue(const NamedGridAreaMap& gridAreaMap, size_t rowCount, size_t columnCount)
: CSSValue(GridTemplateAreasClass)
, m_gridAreaMap(gridAreaMap)
, m_rowCount(rowCount)
, m_columnCount(columnCount)
{
ASSERT(m_rowCount);
ASSERT(m_columnCount);
}
static String stringForPosition(const NamedGridAreaMap& gridAreaMap, size_t row, size_t column)
{
Vector<String> candidates;
for (const auto& it : gridAreaMap) {
const GridArea& area = it.value;
if (row >= area.rows.startLine() && row < area.rows.endLine())
candidates.append(it.key);
}
for (const auto& it : gridAreaMap) {
const GridArea& area = it.value;
if (column >= area.columns.startLine() && column < area.columns.endLine() && candidates.contains(it.key))
return it.key;
}
return ".";
}
String CSSGridTemplateAreasValue::customCSSText() const
{
StringBuilder builder;
for (size_t row = 0; row < m_rowCount; ++row) {
builder.append('\"');
for (size_t column = 0; column < m_columnCount; ++column) {
builder.append(stringForPosition(m_gridAreaMap, row, column));
if (column != m_columnCount - 1)
builder.append(' ');
}
builder.append('\"');
if (row != m_rowCount - 1)
builder.append(' ');
}
return builder.toString();
}
bool CSSGridTemplateAreasValue::equals(const CSSGridTemplateAreasValue& other) const
{
return m_gridAreaMap == other.m_gridAreaMap && m_rowCount == other.m_rowCount && m_columnCount == other.m_columnCount;
}
}