Bug 719286 - Add support for -moz-objectFillOpacity and -moz-objectStrokeOpacity to CSS parser for SVG glyphs r=dbaron

This commit is contained in:
Edwin Flores 2012-09-06 16:58:46 +12:00
Родитель 00ae723fe4
Коммит f5a2675bcf
11 изменённых файлов: 83 добавлений и 16 удалений

Просмотреть файл

@ -900,6 +900,10 @@ static inline mozilla::css::Side operator++(mozilla::css::Side& side, int) {
#define NS_STYLE_TRANSFORM_STYLE_FLAT 0
#define NS_STYLE_TRANSFORM_STYLE_PRESERVE_3D 1
// object {fill,stroke}-opacity for SVG glyphs
#define NS_STYLE_OBJECT_FILL_OPACITY 0
#define NS_STYLE_OBJECT_STROKE_OPACITY 1
/*****************************************************************************
* Constants for media features. *
*****************************************************************************/

Просмотреть файл

@ -131,7 +131,9 @@ CSS_KEY(-moz-myanmar, _moz_myanmar)
CSS_KEY(-moz-nativehyperlinktext, _moz_nativehyperlinktext)
CSS_KEY(-moz-none, _moz_none)
CSS_KEY(-moz-objectfill, _moz_objectfill)
CSS_KEY(-moz-objectfillopacity, _moz_objectfillopacity)
CSS_KEY(-moz-objectstroke, _moz_objectstroke)
CSS_KEY(-moz-objectstrokeopacity, _moz_objectstrokeopacity)
CSS_KEY(-moz-oddtreerow, _moz_oddtreerow)
CSS_KEY(-moz-oriya, _moz_oriya)
CSS_KEY(-moz-persian, _moz_persian)

Просмотреть файл

@ -3103,8 +3103,8 @@ CSS_PROP_SVG(
FillOpacity,
CSS_PROPERTY_PARSE_VALUE,
"",
VARIANT_HN,
nullptr,
VARIANT_HN | VARIANT_KEYWORD,
kObjectOpacityKTable,
offsetof(nsStyleSVG, mFillOpacity),
eStyleAnimType_float)
CSS_PROP_SVG(
@ -3312,8 +3312,8 @@ CSS_PROP_SVG(
StrokeOpacity,
CSS_PROPERTY_PARSE_VALUE,
"",
VARIANT_HN,
nullptr,
VARIANT_HN | VARIANT_KEYWORD,
kObjectOpacityKTable,
offsetof(nsStyleSVG, mStrokeOpacity),
eStyleAnimType_float)
CSS_PROP_SVG(

Просмотреть файл

@ -1148,6 +1148,12 @@ const int32_t nsCSSProps::kListStyleKTable[] = {
eCSSKeyword_UNKNOWN,-1
};
const int32_t nsCSSProps::kObjectOpacityKTable[] = {
eCSSKeyword__moz_objectfillopacity, NS_STYLE_OBJECT_FILL_OPACITY,
eCSSKeyword__moz_objectstrokeopacity, NS_STYLE_OBJECT_STROKE_OPACITY,
eCSSKeyword_UNKNOWN,-1
};
const int32_t nsCSSProps::kObjectPatternKTable[] = {
eCSSKeyword__moz_objectfill, NS_COLOR_OBJECTFILL,
eCSSKeyword__moz_objectstroke, NS_COLOR_OBJECTSTROKE,

Просмотреть файл

@ -390,6 +390,7 @@ public:
static const int32_t kLineHeightKTable[];
static const int32_t kListStylePositionKTable[];
static const int32_t kListStyleKTable[];
static const int32_t kObjectOpacityKTable[];
static const int32_t kObjectPatternKTable[];
static const int32_t kOrientKTable[];
static const int32_t kOutlineStyleKTable[];

Просмотреть файл

@ -7168,6 +7168,36 @@ SetSVGPaint(const nsCSSValue& aValue, const nsStyleSVGPaint& parentPaint,
}
}
static void
SetSVGOpacity(const nsCSSValue& aValue,
float& aOpacityField, nsStyleSVGOpacitySource& aOpacityTypeField,
bool& aCanStoreInRuleTree,
float aParentOpacity, nsStyleSVGOpacitySource aParentOpacityType)
{
if (eCSSUnit_Enumerated == aValue.GetUnit()) {
switch (aValue.GetIntValue()) {
case NS_STYLE_OBJECT_FILL_OPACITY:
aOpacityTypeField = eStyleSVGOpacitySource_ObjectFillOpacity;
break;
case NS_STYLE_OBJECT_STROKE_OPACITY:
aOpacityTypeField = eStyleSVGOpacitySource_ObjectStrokeOpacity;
break;
default:
NS_NOTREACHED("SetSVGOpacity: Unknown keyword");
}
// Fall back on fully opaque
aOpacityField = 1.0f;
} else if (eCSSUnit_Inherit == aValue.GetUnit()) {
aCanStoreInRuleTree = false;
aOpacityField = aParentOpacity;
aOpacityTypeField = aParentOpacityType;
} else if (eCSSUnit_Null != aValue.GetUnit()) {
SetFactor(aValue, aOpacityField, aCanStoreInRuleTree,
aParentOpacity, 1.0f, SETFCT_OPACITY);
aOpacityTypeField = eStyleSVGOpacitySource_Normal;
}
}
const void*
nsRuleNode::ComputeSVGData(void* aStartStruct,
const nsRuleData* aRuleData,
@ -7201,10 +7231,12 @@ nsRuleNode::ComputeSVGData(void* aStartStruct,
parentSVG->mFill, mPresContext, aContext,
svg->mFill, eStyleSVGPaintType_Color, canStoreInRuleTree);
// fill-opacity: factor, inherit, initial
SetFactor(*aRuleData->ValueForFillOpacity(),
svg->mFillOpacity, canStoreInRuleTree,
parentSVG->mFillOpacity, 1.0f, SETFCT_OPACITY);
// fill-opacity: factor, inherit, initial, objectFillOpacity, objectStrokeOpacity
nsStyleSVGOpacitySource objectFillOpacity = svg->mFillOpacitySource;
SetSVGOpacity(*aRuleData->ValueForFillOpacity(),
svg->mFillOpacity, objectFillOpacity, canStoreInRuleTree,
parentSVG->mFillOpacity, parentSVG->mFillOpacitySource);
svg->mFillOpacitySource = objectFillOpacity;
// fill-rule: enum, inherit, initial
SetDiscrete(*aRuleData->ValueForFillRule(),
@ -7354,9 +7386,11 @@ nsRuleNode::ComputeSVGData(void* aStartStruct,
parentSVG->mStrokeMiterlimit, 4.0f);
// stroke-opacity:
SetFactor(*aRuleData->ValueForStrokeOpacity(),
svg->mStrokeOpacity, canStoreInRuleTree,
parentSVG->mStrokeOpacity, 1.0f, SETFCT_OPACITY);
nsStyleSVGOpacitySource objectStrokeOpacity = svg->mStrokeOpacitySource;
SetSVGOpacity(*aRuleData->ValueForStrokeOpacity(),
svg->mStrokeOpacity, objectStrokeOpacity, canStoreInRuleTree,
parentSVG->mStrokeOpacity, parentSVG->mStrokeOpacitySource);
svg->mStrokeOpacitySource = objectStrokeOpacity;
// stroke-width:
const nsCSSValue* strokeWidthValue = aRuleData->ValueForStrokeWidth();

Просмотреть файл

@ -866,6 +866,8 @@ nsStyleSVG::nsStyleSVG()
mStrokeLinejoin = NS_STYLE_STROKE_LINEJOIN_MITER;
mTextAnchor = NS_STYLE_TEXT_ANCHOR_START;
mTextRendering = NS_STYLE_TEXT_RENDERING_AUTO;
mFillOpacitySource = eStyleSVGOpacitySource_Normal;
mStrokeOpacitySource = eStyleSVGOpacitySource_Normal;
}
nsStyleSVG::~nsStyleSVG()
@ -914,6 +916,8 @@ nsStyleSVG::nsStyleSVG(const nsStyleSVG& aSource)
mStrokeLinejoin = aSource.mStrokeLinejoin;
mTextAnchor = aSource.mTextAnchor;
mTextRendering = aSource.mTextRendering;
mFillOpacitySource = aSource.mFillOpacitySource;
mStrokeOpacitySource = aSource.mStrokeOpacitySource;
}
static bool PaintURIChanged(const nsStyleSVGPaint& aPaint1,
@ -972,7 +976,9 @@ nsChangeHint nsStyleSVG::CalcDifference(const nsStyleSVG& aOther) const
mStrokeDasharrayLength != aOther.mStrokeDasharrayLength ||
mStrokeLinecap != aOther.mStrokeLinecap ||
mStrokeLinejoin != aOther.mStrokeLinejoin ||
mTextAnchor != aOther.mTextAnchor) {
mTextAnchor != aOther.mTextAnchor ||
mFillOpacitySource != aOther.mFillOpacitySource ||
mStrokeOpacitySource != aOther.mStrokeOpacitySource) {
NS_UpdateHint(hint, nsChangeHint_RepaintFrame);
return hint;
}

Просмотреть файл

@ -2168,6 +2168,12 @@ enum nsStyleSVGPaintType {
eStyleSVGPaintType_ObjectStroke
};
enum nsStyleSVGOpacitySource {
eStyleSVGOpacitySource_Normal,
eStyleSVGOpacitySource_ObjectFillOpacity,
eStyleSVGOpacitySource_ObjectStrokeOpacity
};
struct nsStyleSVGPaint
{
union {
@ -2232,6 +2238,11 @@ struct nsStyleSVG {
uint8_t mStrokeLinejoin; // [inherited] see nsStyleConsts.h
uint8_t mTextAnchor; // [inherited] see nsStyleConsts.h
uint8_t mTextRendering; // [inherited] see nsStyleConsts.h
// In SVG glyphs, whether we inherit fill or stroke opacity from the outer
// text object
nsStyleSVGOpacitySource mFillOpacitySource : 2;
nsStyleSVGOpacitySource mStrokeOpacitySource : 2;
};
struct nsStyleSVGReset {

Просмотреть файл

@ -3634,7 +3634,7 @@ var gCSSProperties = {
domProp: "fillOpacity",
inherited: true,
type: CSS_TYPE_LONGHAND,
initial_values: [ "1", "2.8", "1.000" ],
initial_values: [ "1", "2.8", "1.000", "-moz-objectFillOpacity", "-moz-objectStrokeOpacity" ],
other_values: [ "0", "0.3", "-7.3" ],
invalid_values: []
},
@ -3806,7 +3806,7 @@ var gCSSProperties = {
domProp: "strokeOpacity",
inherited: true,
type: CSS_TYPE_LONGHAND,
initial_values: [ "1", "2.8", "1.000" ],
initial_values: [ "1", "2.8", "1.000", "-moz-objectFillOpacity", "-moz-objectStrokeOpacity" ],
other_values: [ "0", "0.3", "-7.3" ],
invalid_values: []
},

Просмотреть файл

@ -2172,7 +2172,8 @@ nsSVGUtils::GetGeometryHitTestFlags(nsIFrame* aFrame)
}
bool
nsSVGUtils::SetupCairoStroke(nsIFrame* aFrame, gfxContext* aContext)
nsSVGUtils::SetupCairoStroke(nsIFrame* aFrame, gfxContext* aContext,
gfxTextObjectPaint *aObjectPaint)
{
if (!HasStroke(aFrame)) {
return false;

Просмотреть файл

@ -22,6 +22,7 @@
#include "nsMathUtils.h"
#include "nsPoint.h"
#include "nsRect.h"
#include "nsStyleStruct.h"
#include "mozilla/Constants.h"
class gfxASurface;
@ -722,7 +723,8 @@ public:
* Set up a cairo context for stroking, including setting up any stroke-related
* properties such as dashing and setting the current paint on the gfxContext.
*/
static bool SetupCairoStroke(nsIFrame* aFrame, gfxContext *aContext);
static bool SetupCairoStroke(nsIFrame* aFrame, gfxContext *aContext,
gfxTextObjectPaint *aObjectPaint = nullptr);
/**
* This function returns a set of bit flags indicating which parts of the