Implement CSS clip property in CSSStyleApplyProperty.

https://bugs.webkit.org/show_bug.cgi?id=74913

Reviewed by Andreas Kling.

No new tests / refactoring only.

* css/CSSPrimitiveValue.h:
* css/CSSPrimitiveValueMappings.h:
(WebCore::CSSPrimitiveValue::convertToLength):
This new function aims to provide a single call for converting many CSSPrimitiveValue
values to Lengths. It is templated to allow the caller to specify which conversions
are appropriate depending on the context in which the value is used.
* css/CSSStyleApplyProperty.cpp:
(WebCore::ApplyPropertyClip::convertToLength):
(WebCore::ApplyPropertyClip::applyInheritValue):
(WebCore::ApplyPropertyClip::applyInitialValue):
(WebCore::ApplyPropertyClip::applyValue):
(WebCore::ApplyPropertyClip::createHandler):
(WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::applyProperty):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@105693 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0fff87c0
2012-01-23 Luke Macpherson <macpherson@chromium.org>
Implement CSS clip property in CSSStyleApplyProperty.
https://bugs.webkit.org/show_bug.cgi?id=74913
Reviewed by Andreas Kling.
No new tests / refactoring only.
* css/CSSPrimitiveValue.h:
* css/CSSPrimitiveValueMappings.h:
(WebCore::CSSPrimitiveValue::convertToLength):
This new function aims to provide a single call for converting many CSSPrimitiveValue
values to Lengths. It is templated to allow the caller to specify which conversions
are appropriate depending on the context in which the value is used.
* css/CSSStyleApplyProperty.cpp:
(WebCore::ApplyPropertyClip::convertToLength):
(WebCore::ApplyPropertyClip::applyInheritValue):
(WebCore::ApplyPropertyClip::applyInitialValue):
(WebCore::ApplyPropertyClip::applyValue):
(WebCore::ApplyPropertyClip::createHandler):
(WebCore::CSSStyleApplyProperty::CSSStyleApplyProperty):
* css/CSSStyleSelector.cpp:
(WebCore::CSSStyleSelector::applyProperty):
2012-01-23 Tom Sepez <tsepez@chromium.org>
decodeEscapeSequences() not correct for some encodings (GBK, Big5, ...).
......@@ -203,6 +203,9 @@ public:
*/
template<typename T> T computeLength(RenderStyle* currStyle, RenderStyle* rootStyle, float multiplier = 1.0f, bool computingFontSize = false);
// Converts to a Length, mapping various unit types appropriately.
template<int> Length convertToLength(RenderStyle* currStyle, RenderStyle* rootStyle, double multiplier = 1.0, bool computingFontSize = false);
// use with care!!!
void setPrimitiveType(unsigned short type) { m_primitiveUnitType = type; }
......
......@@ -36,6 +36,7 @@
#include "FontDescription.h"
#include "FontSmoothingMode.h"
#include "GraphicsTypes.h"
#include "Length.h"
#include "Path.h"
#include "RenderStyleConstants.h"
#include "SVGRenderStyleDefs.h"
......@@ -3673,6 +3674,21 @@ template<> inline CSSPrimitiveValue::operator WrapThrough() const
}
}
enum LengthConversion { UnsupportedConversion = 0, FixedConversion = 1, AutoConversion = 2, PercentConversion = 4, FractionConversion = 8};
template<int supported> Length CSSPrimitiveValue::convertToLength(RenderStyle* style, RenderStyle* rootStyle, double multiplier, bool computingFontSize)
{
if ((supported & FixedConversion) && isLength())
return computeLength<Length>(style, rootStyle, multiplier, computingFontSize);
if ((supported & PercentConversion) && isPercentage())
return Length(getDoubleValue(), Percent);
if ((supported & FractionConversion) && isNumber())
return Length(getDoubleValue() * 100.0, Percent);
if ((supported & AutoConversion) && getIdent() == CSSValueAuto)
return Length(Auto);
ASSERT_NOT_REACHED();
return Length(Undefined);
}
#if ENABLE(SVG)
template<> inline CSSPrimitiveValue::CSSPrimitiveValue(EColorInterpolation e)
......
......@@ -35,6 +35,7 @@
#include "Document.h"
#include "Element.h"
#include "Pair.h"
#include "Rect.h"
#include "RenderObject.h"
#include "RenderStyle.h"
#include "Settings.h"
......@@ -212,6 +213,51 @@ public:
static PropertyHandler createHandler() { return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue); }
};
class ApplyPropertyClip {
private:
static Length convertToLength(CSSStyleSelector* selector, CSSPrimitiveValue* value)
{
return value->convertToLength<FixedConversion | PercentConversion | FractionConversion | AutoConversion>(selector->style(), selector->rootElementStyle(), selector->style()->effectiveZoom());
}
public:
static void applyInheritValue(CSSStyleSelector* selector)
{
RenderStyle* parentStyle = selector->parentStyle();
if (!parentStyle->hasClip())
return applyInitialValue(selector);
selector->style()->setClip(parentStyle->clipTop(), parentStyle->clipRight(), parentStyle->clipBottom(), parentStyle->clipLeft());
selector->style()->setHasClip(true);
}
static void applyInitialValue(CSSStyleSelector* selector)
{
selector->style()->setClip(Length(), Length(), Length(), Length());
selector->style()->setHasClip(false);
}
static void applyValue(CSSStyleSelector* selector, CSSValue* value)
{
if (!value->isPrimitiveValue())
return;
CSSPrimitiveValue* primitiveValue = static_cast<CSSPrimitiveValue*>(value);
if (Rect* rect = primitiveValue->getRectValue()) {
Length top = convertToLength(selector, rect->top());
Length right = convertToLength(selector, rect->right());
Length bottom = convertToLength(selector, rect->bottom());
Length left = convertToLength(selector, rect->left());
selector->style()->setClip(top, right, bottom, left);
selector->style()->setHasClip(true);
} else if (primitiveValue->getIdent() == CSSValueAuto) {
selector->style()->setClip(Length(), Length(), Length(), Length());
selector->style()->setHasClip(true);
}
}
static PropertyHandler createHandler() { return PropertyHandler(&applyInheritValue, &applyInitialValue, &applyValue); }
};
enum ColorInherit {NoInheritFromParent = 0, InheritFromParent};
Color defaultInitialColor();
Color defaultInitialColor() { return Color(); }
......@@ -1745,6 +1791,8 @@ CSSStyleApplyProperty::CSSStyleApplyProperty()
setPropertyHandler(CSSPropertyLetterSpacing, ApplyPropertyComputeLength<int, &RenderStyle::letterSpacing, &RenderStyle::setLetterSpacing, &RenderStyle::initialLetterWordSpacing, NormalEnabled, ThicknessDisabled, SVGZoomEnabled>::createHandler());
setPropertyHandler(CSSPropertyWordSpacing, ApplyPropertyComputeLength<int, &RenderStyle::wordSpacing, &RenderStyle::setWordSpacing, &RenderStyle::initialLetterWordSpacing, NormalEnabled, ThicknessDisabled, SVGZoomEnabled>::createHandler());
setPropertyHandler(CSSPropertyClip, ApplyPropertyClip::createHandler());
setPropertyHandler(CSSPropertyCursor, ApplyPropertyCursor::createHandler());
setPropertyHandler(CSSPropertyCounterIncrement, ApplyPropertyCounter<Increment>::createHandler());
......
......@@ -2791,46 +2791,6 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
case CSSPropertyOrphans:
HANDLE_INHERIT_AND_INITIAL_AND_PRIMITIVE(orphans, Orphans)
return;
// rect
case CSSPropertyClip:
{
Length top;
Length right;
Length bottom;
Length left;
bool hasClip = true;
if (isInherit) {
if (m_parentStyle->hasClip()) {
top = m_parentStyle->clipTop();
right = m_parentStyle->clipRight();
bottom = m_parentStyle->clipBottom();
left = m_parentStyle->clipLeft();
} else {
hasClip = false;
top = right = bottom = left = Length();
}
} else if (isInitial) {
hasClip = false;
top = right = bottom = left = Length();
} else if (!primitiveValue) {
return;
} else if (primitiveValue->isRect()) {
Rect* rect = primitiveValue->getRectValue();
if (!rect)
return;
top = convertToIntLength(rect->top(), style(), m_rootElementStyle, zoomFactor);
right = convertToIntLength(rect->right(), style(), m_rootElementStyle, zoomFactor);
bottom = convertToIntLength(rect->bottom(), style(), m_rootElementStyle, zoomFactor);
left = convertToIntLength(rect->left(), style(), m_rootElementStyle, zoomFactor);
} else if (primitiveValue->getIdent() != CSSValueAuto) {
return;
}
m_style->setClip(top, right, bottom, left);
m_style->setHasClip(hasClip);
// rect, ident
return;
}
// lists
case CSSPropertyContent:
......@@ -3767,6 +3727,7 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value)
case CSSPropertyBorderSpacing:
case CSSPropertyWebkitBorderHorizontalSpacing:
case CSSPropertyWebkitBorderVerticalSpacing:
case CSSPropertyClip:
case CSSPropertyCounterIncrement:
case CSSPropertyCounterReset:
case CSSPropertyLetterSpacing:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment