Bug 1297064 - stylo: Add bindings for filling nsStyleImageLayers lists; r?heycam
MozReview-Commit-ID: Bstgf23gMRu
--- a/layout/style/ServoBindings.cpp
+++ b/layout/style/ServoBindings.cpp
@@ -15,16 +15,17 @@
#include "nsDOMTokenList.h"
#include "nsIContentInlines.h"
#include "nsIDOMNode.h"
#include "nsIDocument.h"
#include "nsIFrame.h"
#include "nsINode.h"
#include "nsIPrincipal.h"
#include "nsNameSpaceManager.h"
+#include "nsRuleNode.h"
#include "nsString.h"
#include "nsStyleStruct.h"
#include "nsStyleUtil.h"
#include "nsTArray.h"
#include "mozilla/EventStates.h"
#include "mozilla/ServoElementSnapshot.h"
#include "mozilla/ServoRestyleManager.h"
@@ -318,16 +319,22 @@ Gecko_GetServoDeclarationBlock(RawGeckoE
{
const nsAttrValue* attr = aElement->GetParsedAttr(nsGkAtoms::style);
if (!attr || attr->Type() != nsAttrValue::eServoCSSDeclaration) {
return nullptr;
}
return attr->GetServoCSSDeclarationValue();
}
+void
+Gecko_FillAllBackgroundLists(nsStyleImageLayers* aLayers, uint32_t aMaxLen)
+{
+ nsRuleNode::FillAllBackgroundLists(*aLayers, aMaxLen);
+}
+
template <typename Implementor>
static nsIAtom*
AtomAttrValue(Implementor* aElement, nsIAtom* aName)
{
const nsAttrValue* attr = aElement->GetParsedAttr(aName);
return attr ? attr->GetAtomValue() : nullptr;
}
--- a/layout/style/ServoBindings.h
+++ b/layout/style/ServoBindings.h
@@ -256,16 +256,17 @@ void Gecko_ResetStyleCoord(nsStyleUnit*
// Set an nsStyleCoord to a computed `calc()` value
void Gecko_SetStyleCoordCalcValue(nsStyleUnit* unit, nsStyleUnion* value, nsStyleCoord::CalcValue calc);
void Gecko_CopyClipPathValueFrom(mozilla::StyleClipPath* dst, const mozilla::StyleClipPath* src);
void Gecko_DestroyClipPath(mozilla::StyleClipPath* clip);
mozilla::StyleBasicShape* Gecko_NewBasicShape(mozilla::StyleBasicShapeType type);
+void Gecko_FillAllBackgroundLists(nsStyleImageLayers* layers, uint32_t max_len);
NS_DECL_THREADSAFE_FFI_REFCOUNTING(nsStyleCoord::Calc, Calc);
// Style-struct management.
#define STYLE_STRUCT(name, checkdata_cb) \
struct nsStyle##name; \
void Gecko_Construct_nsStyle##name(nsStyle##name* ptr); \
void Gecko_CopyConstruct_nsStyle##name(nsStyle##name* ptr, \
const nsStyle##name* other); \
--- a/layout/style/nsRuleNode.cpp
+++ b/layout/style/nsRuleNode.cpp
@@ -7178,16 +7178,55 @@ FillBackgroundPositionCoordList(
for (uint32_t sourceLayer = 0, destLayer = aItemCount;
destLayer < aFillCount;
++sourceLayer, ++destLayer) {
aLayers[destLayer].mPosition.*aResultLocation =
aLayers[sourceLayer].mPosition.*aResultLocation;
}
}
+/* static */
+void
+nsRuleNode::FillAllBackgroundLists(nsStyleImageLayers& aImage,
+ uint32_t aMaxItemCount)
+{
+ // Delete any extra items. We need to keep layers in which any
+ // property was specified.
+ aImage.mLayers.TruncateLengthNonZero(aMaxItemCount);
+
+ uint32_t fillCount = aImage.mImageCount;
+ FillBackgroundList(aImage.mLayers,
+ &nsStyleImageLayers::Layer::mImage,
+ aImage.mImageCount, fillCount);
+ FillBackgroundList(aImage.mLayers,
+ &nsStyleImageLayers::Layer::mRepeat,
+ aImage.mRepeatCount, fillCount);
+ FillBackgroundList(aImage.mLayers,
+ &nsStyleImageLayers::Layer::mAttachment,
+ aImage.mAttachmentCount, fillCount);
+ FillBackgroundList(aImage.mLayers,
+ &nsStyleImageLayers::Layer::mClip,
+ aImage.mClipCount, fillCount);
+ FillBackgroundList(aImage.mLayers,
+ &nsStyleImageLayers::Layer::mBlendMode,
+ aImage.mBlendModeCount, fillCount);
+ FillBackgroundList(aImage.mLayers,
+ &nsStyleImageLayers::Layer::mOrigin,
+ aImage.mOriginCount, fillCount);
+ FillBackgroundPositionCoordList(aImage.mLayers,
+ &Position::mXPosition,
+ aImage.mPositionXCount, fillCount);
+ FillBackgroundPositionCoordList(aImage.mLayers,
+ &Position::mYPosition,
+ aImage.mPositionYCount, fillCount);
+ FillBackgroundList(aImage.mLayers,
+ &nsStyleImageLayers::Layer::mSize,
+ aImage.mSizeCount, fillCount);
+}
+
const void*
nsRuleNode::ComputeBackgroundData(void* aStartStruct,
const nsRuleData* aRuleData,
nsStyleContext* aContext,
nsRuleNode* aHighestNode,
const RuleDetail aRuleDetail,
const RuleNodeCacheConditions aConditions)
{
@@ -7299,48 +7338,17 @@ nsRuleNode::ComputeBackgroundData(void*
bg->mImage.mLayers,
parentBG->mImage.mLayers,
&nsStyleImageLayers::Layer::mSize,
initialSize, parentBG->mImage.mSizeCount,
bg->mImage.mSizeCount, maxItemCount, rebuild,
conditions);
if (rebuild) {
- // Delete any extra items. We need to keep layers in which any
- // property was specified.
- bg->mImage.mLayers.TruncateLengthNonZero(maxItemCount);
-
- uint32_t fillCount = bg->mImage.mImageCount;
- FillBackgroundList(bg->mImage.mLayers,
- &nsStyleImageLayers::Layer::mImage,
- bg->mImage.mImageCount, fillCount);
- FillBackgroundList(bg->mImage.mLayers,
- &nsStyleImageLayers::Layer::mRepeat,
- bg->mImage.mRepeatCount, fillCount);
- FillBackgroundList(bg->mImage.mLayers,
- &nsStyleImageLayers::Layer::mAttachment,
- bg->mImage.mAttachmentCount, fillCount);
- FillBackgroundList(bg->mImage.mLayers,
- &nsStyleImageLayers::Layer::mClip,
- bg->mImage.mClipCount, fillCount);
- FillBackgroundList(bg->mImage.mLayers,
- &nsStyleImageLayers::Layer::mBlendMode,
- bg->mImage.mBlendModeCount, fillCount);
- FillBackgroundList(bg->mImage.mLayers,
- &nsStyleImageLayers::Layer::mOrigin,
- bg->mImage.mOriginCount, fillCount);
- FillBackgroundPositionCoordList(bg->mImage.mLayers,
- &Position::mXPosition,
- bg->mImage.mPositionXCount, fillCount);
- FillBackgroundPositionCoordList(bg->mImage.mLayers,
- &Position::mYPosition,
- bg->mImage.mPositionYCount, fillCount);
- FillBackgroundList(bg->mImage.mLayers,
- &nsStyleImageLayers::Layer::mSize,
- bg->mImage.mSizeCount, fillCount);
+ FillAllBackgroundLists(bg->mImage, maxItemCount);
}
// Now that the dust has settled, register the images with the document
bg->mImage.TrackImages(aContext->PresContext());
COMPUTE_END_RESET(Background, bg)
}
--- a/layout/style/nsRuleNode.h
+++ b/layout/style/nsRuleNode.h
@@ -1048,16 +1048,21 @@ public:
nsStyleContext* aStyleContext,
nscolor& aResult);
static bool ParentHasPseudoElementData(nsStyleContext* aContext);
static void ComputeTimingFunction(const nsCSSValue& aValue,
nsTimingFunction& aResult);
+ // Fill unspecified layers by cycling through their values
+ // till they all are of lenght aMaxItemCount
+ static void FillAllBackgroundLists(nsStyleImageLayers& aLayers,
+ uint32_t aMaxItemCount);
+
private:
#ifdef DEBUG
// non-inline helper function to allow assertions without incomplete
// type errors
bool ContextHasCachedData(nsStyleContext* aContext, nsStyleStructID aSID);
#endif
// Store style struct on the style context and tell the style context