mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-27 21:00:50 +00:00
Bug 1276085: stylo: Support creating and setting gradient stops from Servo r=heycam
MozReview-Commit-ID: Gh6CMrf1PE5
This commit is contained in:
parent
f23bd91b8d
commit
e149d9fa0d
@ -333,6 +333,78 @@ Gecko_CopyMozBindingFrom(nsStyleDisplay* aDest, const nsStyleDisplay* aSrc)
|
||||
aDest->mBinding = aSrc->mBinding;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
Gecko_SetNullImageValue(nsStyleImage* aImage)
|
||||
{
|
||||
MOZ_ASSERT(aImage);
|
||||
aImage->SetNull();
|
||||
}
|
||||
|
||||
void
|
||||
Gecko_SetGradientImageValue(nsStyleImage* aImage, nsStyleGradient* aGradient)
|
||||
{
|
||||
MOZ_ASSERT(aImage);
|
||||
aImage->SetGradientData(aGradient);
|
||||
}
|
||||
|
||||
void
|
||||
Gecko_CopyImageValueFrom(nsStyleImage* aImage, const nsStyleImage* aOther)
|
||||
{
|
||||
MOZ_ASSERT(aImage);
|
||||
MOZ_ASSERT(aOther);
|
||||
|
||||
*aImage = *aOther;
|
||||
}
|
||||
|
||||
nsStyleGradient*
|
||||
Gecko_CreateGradient(uint8_t aShape,
|
||||
uint8_t aSize,
|
||||
bool aRepeating,
|
||||
bool aLegacySyntax,
|
||||
uint32_t aStopCount)
|
||||
{
|
||||
nsStyleGradient* result = new nsStyleGradient();
|
||||
|
||||
result->mShape = aShape;
|
||||
result->mSize = aSize;
|
||||
result->mRepeating = aRepeating;
|
||||
result->mLegacySyntax = aLegacySyntax;
|
||||
|
||||
result->mAngle.SetNoneValue();
|
||||
result->mBgPosX.SetNoneValue();
|
||||
result->mBgPosY.SetNoneValue();
|
||||
result->mRadiusX.SetNoneValue();
|
||||
result->mRadiusY.SetNoneValue();
|
||||
|
||||
nsStyleGradientStop dummyStop;
|
||||
dummyStop.mLocation.SetNoneValue();
|
||||
dummyStop.mColor = NS_RGB(0, 0, 0);
|
||||
dummyStop.mIsInterpolationHint = 0;
|
||||
|
||||
for (uint32_t i = 0; i < aStopCount; i++) {
|
||||
result->mStops.AppendElement(dummyStop);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void
|
||||
Gecko_SetGradientStop(nsStyleGradient* aGradient,
|
||||
uint32_t aIndex,
|
||||
const nsStyleCoord* aLocation,
|
||||
nscolor aColor,
|
||||
bool aIsInterpolationHint)
|
||||
{
|
||||
MOZ_ASSERT(aGradient);
|
||||
MOZ_ASSERT(aLocation);
|
||||
MOZ_ASSERT(aIndex < aGradient->mStops.Length());
|
||||
|
||||
aGradient->mStops[aIndex].mColor = aColor;
|
||||
aGradient->mStops[aIndex].mLocation = *aLocation;
|
||||
aGradient->mStops[aIndex].mIsInterpolationHint = aIsInterpolationHint;
|
||||
}
|
||||
|
||||
#define STYLE_STRUCT(name, checkdata_cb) \
|
||||
\
|
||||
void \
|
||||
|
@ -8,6 +8,7 @@
|
||||
#define mozilla_ServoBindings_h
|
||||
|
||||
#include "stdint.h"
|
||||
#include "nsColor.h"
|
||||
#include "mozilla/css/SheetParsingMode.h"
|
||||
#include "nsProxyRelease.h"
|
||||
|
||||
@ -33,6 +34,12 @@ struct ServoNodeData;
|
||||
struct ServoComputedValues;
|
||||
struct RawServoStyleSheet;
|
||||
struct RawServoStyleSet;
|
||||
struct nsStyleList;
|
||||
struct nsStyleImage;
|
||||
struct nsStyleGradientStop;
|
||||
class nsStyleGradient;
|
||||
class nsStyleCoord;
|
||||
struct nsStyleDisplay;
|
||||
|
||||
#define NS_DECL_THREADSAFE_FFI_REFCOUNTING(class_, name_) \
|
||||
static_assert(class_::HasThreadSafeRefCnt::value, \
|
||||
@ -115,16 +122,32 @@ bool Gecko_AtomEqualsUTF8(nsIAtom* aAtom, const char* aString, uint32_t aLength)
|
||||
bool Gecko_AtomEqualsUTF8IgnoreCase(nsIAtom* aAtom, const char* aString, uint32_t aLength);
|
||||
|
||||
// Counter style.
|
||||
struct nsStyleList;
|
||||
void Gecko_SetListStyleType(nsStyleList* style_struct, uint32_t type);
|
||||
void Gecko_CopyListStyleTypeFrom(nsStyleList* dst, const nsStyleList* src);
|
||||
|
||||
// background-image style.
|
||||
// TODO: support url() values (and maybe element() too?).
|
||||
void Gecko_SetNullImageValue(nsStyleImage* image);
|
||||
void Gecko_SetGradientImageValue(nsStyleImage* image, nsStyleGradient* gradient);
|
||||
void Gecko_CopyImageValueFrom(nsStyleImage* image, const nsStyleImage* other);
|
||||
|
||||
nsStyleGradient* Gecko_CreateGradient(uint8_t shape,
|
||||
uint8_t size,
|
||||
bool repeating,
|
||||
bool legacy_syntax,
|
||||
uint32_t stops);
|
||||
|
||||
void Gecko_SetGradientStop(nsStyleGradient* gradient,
|
||||
uint32_t index,
|
||||
const nsStyleCoord* location,
|
||||
nscolor color,
|
||||
bool is_interpolation_hint);
|
||||
|
||||
// Object refcounting.
|
||||
NS_DECL_HOLDER_FFI_REFCOUNTING(nsIPrincipal, Principal)
|
||||
NS_DECL_HOLDER_FFI_REFCOUNTING(nsIURI, URI)
|
||||
|
||||
// Display style.
|
||||
struct nsStyleDisplay;
|
||||
void Gecko_SetMozBinding(nsStyleDisplay* style_struct,
|
||||
const uint8_t* string_bytes, uint32_t string_length,
|
||||
ThreadSafeURIHolder* base_uri,
|
||||
|
@ -682,7 +682,7 @@ struct LengthPercentPairCalcOps : public css::NumbersAlreadyNormalizedOps
|
||||
};
|
||||
|
||||
static void
|
||||
SpecifiedCalcToComputedCalc(const nsCSSValue& aValue, nsStyleCoord& aCoord,
|
||||
SpecifiedCalcToComputedCalc(const nsCSSValue& aValue, nsStyleCoord& aCoord,
|
||||
nsStyleContext* aStyleContext,
|
||||
RuleNodeCacheConditions& aConditions)
|
||||
{
|
||||
@ -966,7 +966,7 @@ SetPairCoords(const nsCSSValue& aValue,
|
||||
|
||||
bool cX = SetCoord(valX, aCoordX, aParentX, aMask, aStyleContext,
|
||||
aPresContext, aConditions);
|
||||
mozilla::DebugOnly<bool> cY = SetCoord(valY, aCoordY, aParentY, aMask,
|
||||
mozilla::DebugOnly<bool> cY = SetCoord(valY, aCoordY, aParentY, aMask,
|
||||
aStyleContext, aPresContext, aConditions);
|
||||
MOZ_ASSERT(cX == cY, "changed one but not the other");
|
||||
return cX;
|
||||
@ -1245,11 +1245,9 @@ static void SetStyleImage(nsStyleContext* aStyleContext,
|
||||
case eCSSUnit_Gradient:
|
||||
{
|
||||
nsStyleGradient* gradient = new nsStyleGradient();
|
||||
if (gradient) {
|
||||
SetGradient(aValue, aStyleContext->PresContext(), aStyleContext,
|
||||
*gradient, aConditions);
|
||||
aResult.SetGradientData(gradient);
|
||||
}
|
||||
SetGradient(aValue, aStyleContext->PresContext(), aStyleContext,
|
||||
*gradient, aConditions);
|
||||
aResult.SetGradientData(gradient);
|
||||
break;
|
||||
}
|
||||
case eCSSUnit_Element:
|
||||
@ -2870,8 +2868,8 @@ nsRuleNode::CalcFontPointSize(int32_t aHTMLSize, int32_t aBasePointSize,
|
||||
nsPresContext* aPresContext,
|
||||
nsFontSizeType aFontSizeType)
|
||||
{
|
||||
#define sFontSizeTableMin 9
|
||||
#define sFontSizeTableMax 16
|
||||
#define sFontSizeTableMin 9
|
||||
#define sFontSizeTableMax 16
|
||||
|
||||
// This table seems to be the one used by MacIE5. We hope its adoption in Mozilla
|
||||
// and eventually in WinIE5.5 will help to establish a standard rendering across
|
||||
@ -2999,7 +2997,7 @@ nsRuleNode::CalcFontPointSize(int32_t aHTMLSize, int32_t aBasePointSize,
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/* static */ nscoord
|
||||
nsRuleNode::FindNextSmallerFontSize(nscoord aFontSize, int32_t aBasePointSize,
|
||||
nsRuleNode::FindNextSmallerFontSize(nscoord aFontSize, int32_t aBasePointSize,
|
||||
nsPresContext* aPresContext,
|
||||
nsFontSizeType aFontSizeType)
|
||||
{
|
||||
@ -3023,9 +3021,9 @@ nsRuleNode::FindNextSmallerFontSize(nscoord aFontSize, int32_t aBasePointSize,
|
||||
indexMin = 0;
|
||||
indexMax = 6;
|
||||
}
|
||||
|
||||
|
||||
smallestIndexFontSize = CalcFontPointSize(indexMin, aBasePointSize, aPresContext, aFontSizeType);
|
||||
largestIndexFontSize = CalcFontPointSize(indexMax, aBasePointSize, aPresContext, aFontSizeType);
|
||||
largestIndexFontSize = CalcFontPointSize(indexMax, aBasePointSize, aPresContext, aFontSizeType);
|
||||
if (aFontSize > smallestIndexFontSize) {
|
||||
if (aFontSize < NSToCoordRound(float(largestIndexFontSize) * 1.5)) { // smaller will be in HTML table
|
||||
// find largest index smaller than current
|
||||
@ -3033,7 +3031,7 @@ nsRuleNode::FindNextSmallerFontSize(nscoord aFontSize, int32_t aBasePointSize,
|
||||
indexFontSize = CalcFontPointSize(index, aBasePointSize, aPresContext, aFontSizeType);
|
||||
if (indexFontSize < aFontSize)
|
||||
break;
|
||||
}
|
||||
}
|
||||
// set up points beyond table for interpolation purposes
|
||||
if (indexFontSize == smallestIndexFontSize) {
|
||||
smallerIndexFontSize = indexFontSize - onePx;
|
||||
@ -3046,9 +3044,9 @@ nsRuleNode::FindNextSmallerFontSize(nscoord aFontSize, int32_t aBasePointSize,
|
||||
largerIndexFontSize = CalcFontPointSize(index+1, aBasePointSize, aPresContext, aFontSizeType);
|
||||
}
|
||||
// compute the relative position of the parent size between the two closest indexed sizes
|
||||
relativePosition = float(aFontSize - indexFontSize) / float(largerIndexFontSize - indexFontSize);
|
||||
relativePosition = float(aFontSize - indexFontSize) / float(largerIndexFontSize - indexFontSize);
|
||||
// set the new size to have the same relative position between the next smallest two indexed sizes
|
||||
smallerSize = smallerIndexFontSize + NSToCoordRound(relativePosition * (indexFontSize - smallerIndexFontSize));
|
||||
smallerSize = smallerIndexFontSize + NSToCoordRound(relativePosition * (indexFontSize - smallerIndexFontSize));
|
||||
}
|
||||
else { // larger than HTML table, drop by 33%
|
||||
smallerSize = NSToCoordRound(float(aFontSize) / 1.5);
|
||||
@ -3065,7 +3063,7 @@ nsRuleNode::FindNextSmallerFontSize(nscoord aFontSize, int32_t aBasePointSize,
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
/* static */ nscoord
|
||||
nsRuleNode::FindNextLargerFontSize(nscoord aFontSize, int32_t aBasePointSize,
|
||||
nsRuleNode::FindNextLargerFontSize(nscoord aFontSize, int32_t aBasePointSize,
|
||||
nsPresContext* aPresContext,
|
||||
nsFontSizeType aFontSizeType)
|
||||
{
|
||||
@ -3090,13 +3088,13 @@ nsRuleNode::FindNextLargerFontSize(nscoord aFontSize, int32_t aBasePointSize,
|
||||
indexMin = 0;
|
||||
indexMax = 6;
|
||||
}
|
||||
|
||||
|
||||
smallestIndexFontSize = CalcFontPointSize(indexMin, aBasePointSize, aPresContext, aFontSizeType);
|
||||
largestIndexFontSize = CalcFontPointSize(indexMax, aBasePointSize, aPresContext, aFontSizeType);
|
||||
largestIndexFontSize = CalcFontPointSize(indexMax, aBasePointSize, aPresContext, aFontSizeType);
|
||||
if (aFontSize > (smallestIndexFontSize - onePx)) {
|
||||
if (aFontSize < largestIndexFontSize) { // larger will be in HTML table
|
||||
// find smallest index larger than current
|
||||
for (index = indexMin; index <= indexMax; index++) {
|
||||
for (index = indexMin; index <= indexMax; index++) {
|
||||
indexFontSize = CalcFontPointSize(index, aBasePointSize, aPresContext, aFontSizeType);
|
||||
if (indexFontSize > aFontSize)
|
||||
break;
|
||||
@ -6323,7 +6321,7 @@ nsRuleNode::ComputeDisplayData(void* aStartStruct,
|
||||
NS_ASSERTION(result, "Malformed -moz-perspective-origin parse!");
|
||||
}
|
||||
|
||||
SetCoord(*aRuleData->ValueForPerspective(),
|
||||
SetCoord(*aRuleData->ValueForPerspective(),
|
||||
display->mChildPerspective, parentDisplay->mChildPerspective,
|
||||
SETCOORD_LAH | SETCOORD_INITIAL_NONE | SETCOORD_NONE |
|
||||
SETCOORD_UNSET_INITIAL,
|
||||
@ -6433,7 +6431,7 @@ nsRuleNode::ComputeVisibilityData(void* aStartStruct,
|
||||
double angle = array->Item(0).GetAngleValueInRadians();
|
||||
visibility->mImageOrientation =
|
||||
nsStyleImageOrientation::CreateAsAngleAndFlip(angle, true);
|
||||
|
||||
|
||||
} else if (orientation->GetUnit() == eCSSUnit_Enumerated) {
|
||||
switch (orientation->GetIntValue()) {
|
||||
case NS_STYLE_IMAGE_ORIENTATION_FLIP:
|
||||
|
@ -228,7 +228,7 @@ public:
|
||||
bool HasCalc();
|
||||
uint32_t Hash(PLDHashNumber aHash);
|
||||
|
||||
NS_INLINE_DECL_REFCOUNTING(nsStyleGradient)
|
||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsStyleGradient)
|
||||
|
||||
private:
|
||||
// Private destructor, to discourage deletion outside of Release():
|
||||
|
Loading…
x
Reference in New Issue
Block a user