blob: 181ba5ddb48c552094dba6022e7acf03425a232e [file] [log] [blame]
/**
* (C) 1999-2003 Lars Knoll (knoll@kde.org)
* Copyright (C) 2004, 2005, 2006 Apple Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "CSSProperty.h"
#include "CSSValueList.h"
#include "StylePropertyShorthand.h"
#include "StylePropertyShorthandFunctions.h"
#include <wtf/NeverDestroyed.h>
namespace WebCore {
struct SameSizeAsCSSProperty {
uint32_t bitfields;
void* value;
};
COMPILE_ASSERT(sizeof(CSSProperty) == sizeof(SameSizeAsCSSProperty), CSSProperty_should_stay_small);
CSSPropertyID StylePropertyMetadata::shorthandID() const
{
if (!m_isSetFromShorthand)
return CSSPropertyInvalid;
auto shorthands = matchingShorthandsForLonghand(static_cast<CSSPropertyID>(m_propertyID));
ASSERT(shorthands.size() && m_indexInShorthandsVector >= 0 && m_indexInShorthandsVector < shorthands.size());
return shorthands[m_indexInShorthandsVector].id();
}
void CSSProperty::wrapValueInCommaSeparatedList()
{
auto list = CSSValueList::createCommaSeparated();
list.get().append(m_value.releaseNonNull());
m_value = WTFMove(list);
}
static CSSPropertyID resolveToPhysicalProperty(TextDirection direction, WritingMode writingMode, LogicalBoxSide logicalSide, const StylePropertyShorthand& shorthand)
{
return shorthand.properties()[static_cast<size_t>(mapLogicalSideToPhysicalSide(makeTextFlow(writingMode, direction), logicalSide))];
}
enum LogicalExtent { LogicalWidth, LogicalHeight };
static CSSPropertyID resolveToPhysicalProperty(WritingMode writingMode, LogicalExtent logicalSide, const CSSPropertyID* properties)
{
if (writingMode == TopToBottomWritingMode || writingMode == BottomToTopWritingMode)
return properties[logicalSide];
return logicalSide == LogicalWidth ? properties[1] : properties[0];
}
static const StylePropertyShorthand& borderDirections()
{
static const CSSPropertyID properties[4] = { CSSPropertyBorderTop, CSSPropertyBorderRight, CSSPropertyBorderBottom, CSSPropertyBorderLeft };
static const StylePropertyShorthand borderDirections(CSSPropertyBorder, properties);
return borderDirections;
}
CSSPropertyID CSSProperty::resolveDirectionAwareProperty(CSSPropertyID propertyID, TextDirection direction, WritingMode writingMode)
{
switch (propertyID) {
case CSSPropertyWebkitMarginEnd:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::End, marginShorthand());
case CSSPropertyWebkitMarginStart:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::Start, marginShorthand());
case CSSPropertyWebkitMarginBefore:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::Before, marginShorthand());
case CSSPropertyWebkitMarginAfter:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::After, marginShorthand());
case CSSPropertyWebkitPaddingEnd:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::End, paddingShorthand());
case CSSPropertyWebkitPaddingStart:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::Start, paddingShorthand());
case CSSPropertyWebkitPaddingBefore:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::Before, paddingShorthand());
case CSSPropertyWebkitPaddingAfter:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::After, paddingShorthand());
case CSSPropertyWebkitBorderEnd:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::End, borderDirections());
case CSSPropertyWebkitBorderStart:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::Start, borderDirections());
case CSSPropertyWebkitBorderBefore:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::Before, borderDirections());
case CSSPropertyWebkitBorderAfter:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::After, borderDirections());
case CSSPropertyWebkitBorderEndColor:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::End, borderColorShorthand());
case CSSPropertyWebkitBorderStartColor:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::Start, borderColorShorthand());
case CSSPropertyWebkitBorderBeforeColor:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::Before, borderColorShorthand());
case CSSPropertyWebkitBorderAfterColor:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::After, borderColorShorthand());
case CSSPropertyWebkitBorderEndStyle:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::End, borderStyleShorthand());
case CSSPropertyWebkitBorderStartStyle:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::Start, borderStyleShorthand());
case CSSPropertyWebkitBorderBeforeStyle:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::Before, borderStyleShorthand());
case CSSPropertyWebkitBorderAfterStyle:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::After, borderStyleShorthand());
case CSSPropertyWebkitBorderEndWidth:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::End, borderWidthShorthand());
case CSSPropertyWebkitBorderStartWidth:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::Start, borderWidthShorthand());
case CSSPropertyWebkitBorderBeforeWidth:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::Before, borderWidthShorthand());
case CSSPropertyWebkitBorderAfterWidth:
return resolveToPhysicalProperty(direction, writingMode, LogicalBoxSide::After, borderWidthShorthand());
case CSSPropertyWebkitLogicalWidth: {
const CSSPropertyID properties[2] = { CSSPropertyWidth, CSSPropertyHeight };
return resolveToPhysicalProperty(writingMode, LogicalWidth, properties);
}
case CSSPropertyWebkitLogicalHeight: {
const CSSPropertyID properties[2] = { CSSPropertyWidth, CSSPropertyHeight };
return resolveToPhysicalProperty(writingMode, LogicalHeight, properties);
}
case CSSPropertyWebkitMinLogicalWidth: {
const CSSPropertyID properties[2] = { CSSPropertyMinWidth, CSSPropertyMinHeight };
return resolveToPhysicalProperty(writingMode, LogicalWidth, properties);
}
case CSSPropertyWebkitMinLogicalHeight: {
const CSSPropertyID properties[2] = { CSSPropertyMinWidth, CSSPropertyMinHeight };
return resolveToPhysicalProperty(writingMode, LogicalHeight, properties);
}
case CSSPropertyWebkitMaxLogicalWidth: {
const CSSPropertyID properties[2] = { CSSPropertyMaxWidth, CSSPropertyMaxHeight };
return resolveToPhysicalProperty(writingMode, LogicalWidth, properties);
}
case CSSPropertyWebkitMaxLogicalHeight: {
const CSSPropertyID properties[2] = { CSSPropertyMaxWidth, CSSPropertyMaxHeight };
return resolveToPhysicalProperty(writingMode, LogicalHeight, properties);
}
default:
return propertyID;
}
}
bool CSSProperty::isDescriptorOnly(CSSPropertyID propertyID)
{
switch (propertyID) {
#if ENABLE(CSS_DEVICE_ADAPTATION)
case CSSPropertyMinZoom:
case CSSPropertyMaxZoom:
case CSSPropertyOrientation:
case CSSPropertyUserZoom:
#endif
case CSSPropertySrc:
case CSSPropertyUnicodeRange:
case CSSPropertyFontDisplay:
return true;
default:
return false;
}
}
bool CSSProperty::isDirectionAwareProperty(CSSPropertyID propertyID)
{
switch (propertyID) {
case CSSPropertyWebkitBorderEndColor:
case CSSPropertyWebkitBorderEndStyle:
case CSSPropertyWebkitBorderEndWidth:
case CSSPropertyWebkitBorderStartColor:
case CSSPropertyWebkitBorderStartStyle:
case CSSPropertyWebkitBorderStartWidth:
case CSSPropertyWebkitBorderBeforeColor:
case CSSPropertyWebkitBorderBeforeStyle:
case CSSPropertyWebkitBorderBeforeWidth:
case CSSPropertyWebkitBorderAfterColor:
case CSSPropertyWebkitBorderAfterStyle:
case CSSPropertyWebkitBorderAfterWidth:
case CSSPropertyWebkitMarginEnd:
case CSSPropertyWebkitMarginStart:
case CSSPropertyWebkitMarginBefore:
case CSSPropertyWebkitMarginAfter:
case CSSPropertyWebkitPaddingEnd:
case CSSPropertyWebkitPaddingStart:
case CSSPropertyWebkitPaddingBefore:
case CSSPropertyWebkitPaddingAfter:
case CSSPropertyWebkitLogicalWidth:
case CSSPropertyWebkitLogicalHeight:
case CSSPropertyWebkitMinLogicalWidth:
case CSSPropertyWebkitMinLogicalHeight:
case CSSPropertyWebkitMaxLogicalWidth:
case CSSPropertyWebkitMaxLogicalHeight:
return true;
default:
return false;
}
}
} // namespace WebCore