Bug 1345696 part 7 - Provide @font-face rules for stylo backend. r=heycam
MozReview-Commit-ID: CHPxz7iOLg6
--- a/dom/base/nsDocument.cpp
+++ b/dom/base/nsDocument.cpp
@@ -12948,26 +12948,18 @@ nsIDocument::FlushUserFontSet()
// to not unset our mFontFaceSetDirty bit, so when someone really
// does we'll create it.
}
if (mFontFaceSetDirty) {
if (gfxPlatform::GetPlatform()->DownloadableFontsEnabled()) {
nsTArray<nsFontFaceRuleContainer> rules;
nsIPresShell* shell = GetShell();
- if (shell) {
- // XXXheycam ServoStyleSets don't support exposing @font-face rules yet.
- if (shell->StyleSet()->IsGecko()) {
- if (!shell->StyleSet()->AsGecko()->AppendFontFaceRules(rules)) {
- return;
- }
- } else {
- NS_WARNING("stylo: ServoStyleSets cannot handle @font-face rules yet. "
- "See bug 1290237.");
- }
+ if (shell && !shell->StyleSet()->AppendFontFaceRules(rules)) {
+ return;
}
bool changed = false;
if (!mFontFaceSet && !rules.IsEmpty()) {
nsCOMPtr<nsPIDOMWindowInner> window = do_QueryInterface(GetScopeObject());
mFontFaceSet = new FontFaceSet(window, this);
}
--- a/layout/style/ServoBindingList.h
+++ b/layout/style/ServoBindingList.h
@@ -66,16 +66,19 @@ SERVO_BINDING_FUNC(Servo_StyleSet_FlushS
SERVO_BINDING_FUNC(Servo_StyleSet_NoteStyleSheetsChanged, void,
RawServoStyleSetBorrowed set)
SERVO_BINDING_FUNC(Servo_StyleSet_FillKeyframesForName, bool,
RawServoStyleSetBorrowed set,
const nsACString* property,
nsTimingFunctionBorrowed timing_function,
ServoComputedValuesBorrowed computed_values,
RawGeckoKeyframeListBorrowedMut keyframe_list)
+SERVO_BINDING_FUNC(Servo_StyleSet_GetFontFaceRules, void,
+ RawServoStyleSetBorrowed set,
+ RawGeckoFontFaceRuleListBorrowedMut list)
// CSSRuleList
SERVO_BINDING_FUNC(Servo_CssRules_ListTypes, void,
ServoCssRulesBorrowed rules,
nsTArrayBorrowed_uintptr_t result)
SERVO_BINDING_FUNC(Servo_CssRules_InsertRule, nsresult,
ServoCssRulesBorrowed rules,
RawServoStyleSheetBorrowed sheet, const nsACString* rule,
--- a/layout/style/ServoBindingTypes.h
+++ b/layout/style/ServoBindingTypes.h
@@ -27,32 +27,34 @@ class Element;
class StyleChildrenIterator;
} // namespace dom
struct Keyframe;
struct PropertyStyleAnimationValuePair;
using ComputedKeyframeValues = nsTArray<PropertyStyleAnimationValuePair>;
} // namespace mozilla
class nsCSSValue;
+struct nsFontFaceRuleContainer;
class nsIDocument;
class nsINode;
class nsPresContext;
struct nsTimingFunction;
using mozilla::dom::StyleChildrenIterator;
using mozilla::ServoElementSnapshot;
typedef nsINode RawGeckoNode;
typedef mozilla::dom::Element RawGeckoElement;
typedef nsIDocument RawGeckoDocument;
typedef nsPresContext RawGeckoPresContext;
typedef nsTArray<mozilla::Keyframe> RawGeckoKeyframeList;
typedef nsTArray<mozilla::ComputedKeyframeValues> RawGeckoComputedKeyframeValuesList;
typedef nsTArray<mozilla::PropertyStyleAnimationValuePair> RawGeckoAnimationValueList;
typedef nsStyleAutoArray<mozilla::StyleAnimation> RawGeckoStyleAnimationList;
+typedef nsTArray<nsFontFaceRuleContainer> RawGeckoFontFaceRuleList;
// We have these helper types so that we can directly generate
// things like &T or Borrowed<T> on the Rust side in the function, providing
// additional safety benefits.
//
// FFI has a problem with templated types, so we just use raw pointers here.
//
// The "Borrowed" types generate &T or Borrowed<T> in the nullable case.
@@ -119,16 +121,17 @@ DECL_OWNED_REF_TYPE_FOR(RawGeckoPresCont
DECL_BORROWED_REF_TYPE_FOR(RawGeckoPresContext)
DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoAnimationValueList)
DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoKeyframeList)
DECL_BORROWED_REF_TYPE_FOR(RawGeckoKeyframeList)
DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoComputedKeyframeValuesList)
DECL_BORROWED_REF_TYPE_FOR(RawGeckoStyleAnimationList)
DECL_BORROWED_MUT_REF_TYPE_FOR(nsTimingFunction)
DECL_BORROWED_REF_TYPE_FOR(nsTimingFunction)
+DECL_BORROWED_MUT_REF_TYPE_FOR(RawGeckoFontFaceRuleList)
#undef DECL_ARC_REF_TYPE_FOR
#undef DECL_OWNED_REF_TYPE_FOR
#undef DECL_NULLABLE_OWNED_REF_TYPE_FOR
#undef DECL_BORROWED_REF_TYPE_FOR
#undef DECL_NULLABLE_BORROWED_REF_TYPE_FOR
#undef DECL_BORROWED_MUT_REF_TYPE_FOR
#undef DECL_NULLABLE_BORROWED_MUT_REF_TYPE_FOR
--- a/layout/style/ServoStyleSet.cpp
+++ b/layout/style/ServoStyleSet.cpp
@@ -810,9 +810,16 @@ ServoStyleSet::ResolveStyleLazily(Elemen
computedValues =
Servo_ResolveStyleLazily(aElement, aPseudoTag, mRawSet.get()).Consume();
}
sInServoTraversal = false;
return computedValues.forget();
}
+bool
+ServoStyleSet::AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray)
+{
+ Servo_StyleSet_GetFontFaceRules(mRawSet.get(), &aArray);
+ return true;
+}
+
bool ServoStyleSet::sInServoTraversal = false;
--- a/layout/style/ServoStyleSet.h
+++ b/layout/style/ServoStyleSet.h
@@ -267,16 +267,18 @@ public:
nsTArray<Keyframe>& aKeyframes);
nsTArray<ComputedKeyframeValues>
GetComputedKeyframeValuesFor(const nsTArray<Keyframe>& aKeyframes,
dom::Element* aElement,
const ServoComputedValuesWithParent&
aServoValues);
+ bool AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray);
+
private:
already_AddRefed<nsStyleContext> GetContext(already_AddRefed<ServoComputedValues>,
nsStyleContext* aParentContext,
nsIAtom* aPseudoTag,
CSSPseudoElementType aPseudoType,
dom::Element* aElementForAnimation);
already_AddRefed<nsStyleContext> GetContext(nsIContent* aContent,
--- a/layout/style/StyleSetHandle.h
+++ b/layout/style/StyleSetHandle.h
@@ -19,16 +19,17 @@
namespace mozilla {
class CSSStyleSheet;
class ServoStyleSet;
namespace dom {
class Element;
} // namespace dom
} // namespace mozilla
+struct nsFontFaceRuleContainer;
class nsIAtom;
class nsIContent;
class nsIDocument;
class nsStyleContext;
class nsStyleSet;
class nsPresContext;
struct TreeMatchContext;
@@ -168,16 +169,18 @@ public:
dom::Element* aElement,
mozilla::CSSPseudoElementType aPseudoType,
dom::Element* aPseudoElement,
EventStates aStateMask);
inline void RootStyleContextAdded();
inline void RootStyleContextRemoved();
+ inline bool AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray);
+
private:
// Stores a pointer to an nsStyleSet or a ServoStyleSet. The least
// significant bit is 0 for the former, 1 for the latter. This is
// valid as the least significant bit will never be used for a pointer
// value on platforms we care about.
uintptr_t mValue;
};
--- a/layout/style/StyleSetHandleInlines.h
+++ b/layout/style/StyleSetHandleInlines.h
@@ -270,13 +270,20 @@ StyleSetHandle::Ptr::RootStyleContextRem
{
if (IsGecko()) {
RootStyleContextAdded();
} else {
// Not needed.
}
}
+bool
+StyleSetHandle::Ptr::
+AppendFontFaceRules(nsTArray<nsFontFaceRuleContainer>& aArray)
+{
+ FORWARD(AppendFontFaceRules, (aArray));
+}
+
} // namespace mozilla
#undef FORWARD
#endif // mozilla_StyleSetHandleInlines_h